Friday, September 20, 2013

Topcoder SRM 589 DIV 2 L1 GooseTattarrattatDiv2

// Topcoder SRM 589 DIV 2 L1 GooseTattarrattatDiv2

import java.util.*;
import java.math.*;

//rename the class name before submitting
public class GooseTattarrattatDiv2 {
public static void main(String[] args) {
GooseTattarrattatDiv2 obj = new GooseTattarrattatDiv2();
System.out.println(
obj.getmin(
""
));
}

public int getmin(String S) {
int[] cnt = new int[26];
for (int i = 0; i < S.length(); i++) {
int c = S.charAt(i) - 'a';
cnt[c] += 1;
}
int maxCnt = 0;
for (int i = 0; i < cnt.length; i++) {
maxCnt = Math.max(maxCnt, cnt[i]);
}
return S.length() - maxCnt;
}
}

Thursday, September 19, 2013

Topcoder SRM 588 DIV 2 L1 KeyDungeonDiv2

// Topcoder SRM 588 DIV 2 L1 KeyDungeonDiv2

import java.util.*;
import java.math.*;

//rename the class name before submitting
public class KeyDungeonDiv2 {
public static void main(String[] args) {
KeyDungeonDiv2 obj = new KeyDungeonDiv2();
System.out.println(
obj.countDoors(
null, null, null
));
}

public int countDoors(int[] doorR, int[] doorG, int[] keys) {
int n = doorR.length;
int cnt = 0;
for (int i = 0; i < n; i++) {
int kwhite = keys[2];
if (keys[0] < doorR[i]) {
kwhite -= doorR[i] - keys[0];
}
if (keys[1] < doorG[i]) {
kwhite -= doorG[i] - keys[1];
}
if (kwhite >= 0)
cnt++;
}
return cnt;
}
}

Monday, September 16, 2013

Topcoder SRM 590 DIV 2 L1 FoxAndGomoku

// Topcoder SRM 590 DIV 2 L1 FoxAndGomoku

import java.util.*;
import java.math.*;

//rename the class name before submitting
public class FoxAndGomoku {
public static void main(String[] args) {
FoxAndGomoku obj = new FoxAndGomoku();
System.out.println(
obj.win(
null
));
}

public String win(String[] board) {
int n = board.length;
for (int y = 0; y < n; y++) {
for (int x = 0; x < n; x++) {
// check hor
if (x + 5 <= n) {
int no = 0;
for (int i = x; i < x + 5; i++) {
if (board[y].charAt(i) == 'o')
no++;
}
if (no == 5)
return "found";
}
// check ver
if (y + 5 <= n) {
int no = 0;
for (int i = y; i < y + 5; i++) {
if (board[i].charAt(x) == 'o')
no++;
}
if (no == 5)
return "found";
}
// check right
if (x + 5 <= n && y + 5 <= n) {
int no = 0;
for (int i = 0; i < 5; i++) {
if (board[x + i].charAt(y + i) == 'o')
no++;
}
if (no == 5)
return "found";
}
// check left
if (x + 5 <= n && y + 5 <= n) {
int no = 0;
for (int i = 0; i < 5; i++) {
if (board[x + i].charAt(y + 4 - i) == 'o')
no++;
}
if (no == 5)
return "found";
}
}
}
return "not found";
}
}

Sunday, September 15, 2013

Topcoder SRM 587 DIV 2 L1 InsertZ

// Topcoder SRM 587 DIV 2 L1 InsertZ

import java.util.*;
import java.math.*;

//rename the class name before submitting
public class InsertZ {
public static void main(String[] args) {
InsertZ obj = new InsertZ();
System.out.println(
obj.canTransform(
"", ""
));
}

public String canTransform(String init, String goal) {
String s = goal.replaceAll("z", "");
if (s.equals(init))
return "Yes";
return "No";
}
}

Topcoder SRM 586 DIV 2 L1 TeamsSelection

// Topcoder SRM 586 DIV 2 L1 TeamsSelection

import java.util.*;
import java.math.*;

//rename the class name before submitting
public class TeamsSelection {
public static void main(String[] args) {
TeamsSelection obj = new TeamsSelection();
System.out.println(
obj.simulate(
null,
null
));
}

public String simulate(int[] preference1, int[] preference2) {
String result = "";
HashSet<Integer> selected = new HashSet<Integer>();
HashSet<Integer> selectedBy1 = new HashSet<Integer>();
int N = preference1.length;
for (int i = 0; i < N; i++) {
for (int j1 = 0; j1 < N; j1++) {
if (!selected.contains(preference1[j1])) {
selected.add(preference1[j1]);
selectedBy1.add(preference1[j1]);
break;
}
}
for (int j2 = 0; j2 < N; j2++) {
if (!selected.contains(preference2[j2])) {
selected.add(preference2[j2]);
break;
}
}
}
for (int i = 1; i <= N; i++) {
if (selectedBy1.contains(i))
result += "1";
else
result += "2";
}
return result;
}
}

Saturday, September 14, 2013

Topcoder SRM 585 DIV 2 L1 LISNumberDivTwo

// Topcoder SRM 585 DIV 2 L1 LISNumberDivTwo

import java.util.*;
import java.math.*;

//rename the class name before submitting
public class LISNumberDivTwo {
public static void main(String[] args) {
LISNumberDivTwo obj = new LISNumberDivTwo();
System.out.println(
obj.calculate(
null
));
}

public int calculate(int[] seq) {
int cnt = 1;
for (int i = 1; i < seq.length; i++) {
if (seq[i] <= seq[i - 1])
cnt++;
}
return cnt;
}
}

Google Code Jam Round 1C 2013 A Consonants

// Google Code Jam Round 1C 2013 A Consonants

import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

//Google Code Jam
public class GoogleCode1 {
private static MyScanner in;
private static PrintStream out;
private static PrintStream sysout = System.out;
static int caseNum;

private static void solve() throws IOException
{
PreCompute();
int C = in.nextInt();
for (int i = 0; i < C; i++) {
caseNum = i + 1;
out.print("Case #" + caseNum + ": ");
solveCase();
}
}

private static void PreCompute() {
}

private static boolean isConsonant(char c) {
if ("aeiou".contains(Character.toString(c)))
return false;
return true;

}

private static void solveCase() throws IOException {
String s = in.nextString();
int N = in.nextInt();
int lastConsConsIdx = -1;
int nCons = 0;
long nv = 0;
for (int i = 0; i < s.length(); i++) {
if (isConsonant(s.charAt(i)))
nCons++;
else
nCons = 0;
if (nCons >= N) {
int firstCharIdx = i + 1 - N;
long nAfter = s.length() - i;
long nBefore = firstCharIdx - lastConsConsIdx;
if (firstCharIdx == 0)
nBefore = 1;
long cnt = nAfter * nBefore;
nv += cnt;
lastConsConsIdx = firstCharIdx;
}
}

out.println(nv);
}

public static void main(String[] args) throws IOException {
// helpers for input/output
boolean usingFileForIO = true;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("E:\\zin.txt");
out = new PrintStream("E:\\zout.txt");
}
else {
in = new MyScanner();
out = System.out;
}

solve();
}

// =====================================
static class MyScanner {
Scanner inp = null;

public MyScanner() throws IOException
{
inp = new Scanner(System.in);
}

public MyScanner(String inputFile) throws IOException {
inp = new Scanner(new FileInputStream(inputFile));
}

public int nextInt() throws IOException {
return inp.nextInt();
}

public long nextLong() throws IOException {
return inp.nextLong();
}

public double nextDouble() throws IOException {
return inp.nextDouble();
}

public String nextString() throws IOException {
return inp.next();
}

public String nextLine() throws IOException {
return inp.nextLine();
}
}

}

Wednesday, September 4, 2013

Codeforces Round #197 (Div. 2) B Xenia and Ringroad

// Codeforces Round #197 (Div. 2) B Xenia and Ringroad

import java.io.*;
import java.math.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
private static boolean LOCAL_TEST = false;

private static void solve() throws IOException
{
int n = in.nextInt();
int m = in.nextInt();
long time = 0;
int[] a = new int[m];
for (int i = 0; i < a.length; i++) {
a[i] = in.nextInt();
}
for (int i = 0; i < a.length; i++) {
if (i == 0)
time += a[i] - 1;
else {
if (a[i] >= a[i - 1])
time += a[i] - a[i - 1];
else
time += (n - a[i - 1]) + a[i];
}
}
out.println(time);
}

public static void main(String[] args) throws IOException {
// helpers for input/output
out = System.out;
try {
String cname = System.getenv("COMPUTERNAME");
if (!cname.equals(""))
LOCAL_TEST = true;
} catch (Exception e) {
}
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}

solve();
}

// =====================================
static class MyScanner {
BufferedReader bufReader;
StringTokenizer strTok;

public MyScanner() throws IOException
{
bufReader = new BufferedReader(new InputStreamReader(System.in));
strTok = new StringTokenizer("");
}

public MyScanner(String inputFile) throws IOException {
bufReader = new BufferedReader(new InputStreamReader(new FileInputStream(
inputFile)));
strTok = new StringTokenizer("");
}

String GetNextToken() throws IOException {
if (!strTok.hasMoreTokens())
strTok = new StringTokenizer(bufReader.readLine());
return strTok.nextToken();
}

public int nextInt() throws IOException {
return Integer.valueOf(GetNextToken());
}

public long nextLong() throws IOException {
return Long.valueOf(GetNextToken());
}

public double nextDouble() throws IOException {
return Double.valueOf(GetNextToken());
}

public String nextString() throws IOException {
return GetNextToken();
}

public String nextLine() throws IOException {
return bufReader.readLine();
}

public int countTokens() {
return strTok.countTokens();
}

public boolean hasMoreTokens() {
return strTok.hasMoreTokens();
}
}

}

Codeforces Round #197 (Div. 2) A Helpful Maths

// Codeforces Round #197 (Div. 2) A Helpful Maths

import java.io.*;
import java.math.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
private static boolean LOCAL_TEST = false;

private static void solve() throws IOException
{
String s = in.nextLine();
int[] nums = new int[4];
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '1')
nums[1]++;
else if (c == '2')
nums[2]++;
else if (c == '3')
nums[3]++;
}
int numAll = nums[1] + nums[2] + nums[3];
String r = "";
int i = 0;
for (int j = 1; j <= 3; j++) {
for (int k = 0; k < nums[j]; k++) {
r += j;
i++;
if (i < numAll)
r += "+";
}
}
out.println(r);
}

public static void main(String[] args) throws IOException {
// helpers for input/output
out = System.out;
try {
String cname = System.getenv("COMPUTERNAME");
if (!cname.equals(""))
LOCAL_TEST = true;
} catch (Exception e) {
}
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}

solve();
}

// =====================================
static class MyScanner {
BufferedReader bufReader;
StringTokenizer strTok;

public MyScanner() throws IOException
{
bufReader = new BufferedReader(new InputStreamReader(System.in));
strTok = new StringTokenizer("");
}

public MyScanner(String inputFile) throws IOException {
bufReader = new BufferedReader(new InputStreamReader(new FileInputStream(
inputFile)));
strTok = new StringTokenizer("");
}

String GetNextToken() throws IOException {
if (!strTok.hasMoreTokens())
strTok = new StringTokenizer(bufReader.readLine());
return strTok.nextToken();
}

public int nextInt() throws IOException {
return Integer.valueOf(GetNextToken());
}

public long nextLong() throws IOException {
return Long.valueOf(GetNextToken());
}

public double nextDouble() throws IOException {
return Double.valueOf(GetNextToken());
}

public String nextString() throws IOException {
return GetNextToken();
}

public String nextLine() throws IOException {
return bufReader.readLine();
}

public int countTokens() {
return strTok.countTokens();
}

public boolean hasMoreTokens() {
return strTok.hasMoreTokens();
}
}

}

Sunday, August 25, 2013

Codeforces Round #195 (Div. 2) A Vasily the Bear and Triangle

// Codeforces Round #195 (Div. 2) A Vasily the Bear and Triangle

import java.io.*;
import java.math.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
private static boolean LOCAL_TEST = false;

private static void solve() throws IOException
{
int x = in.nextInt();
int y = in.nextInt();
int len = Math.abs(x) + Math.abs(y);
int x1;
int y1;
int x2;
int y2;
if (x < 0) {
x1 = -len;
y1 = 0;
x2 = 0;
if (y > 0)
y2 = len;
else
y2 = -len;
}
else {
x1 = 0;
x2 = len;
y2 = 0;
if (y > 0)
y1 = len;
else
y1 = -len;
}
out.println(x1 + " " + y1 + " " + x2 + " " + y2);
}

public static void main(String[] args) throws IOException {
// helpers for input/output
out = System.out;
try {
String cname = System.getenv("COMPUTERNAME");
if (!cname.equals(""))
LOCAL_TEST = true;
} catch (Exception e) {
}
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}

solve();
}

// =====================================
static class MyScanner {
BufferedReader bufReader;
StringTokenizer strTok;

public MyScanner() throws IOException
{
bufReader = new BufferedReader(new InputStreamReader(System.in));
strTok = new StringTokenizer("");
}

public MyScanner(String inputFile) throws IOException {
bufReader = new BufferedReader(new InputStreamReader(new FileInputStream(
inputFile)));
strTok = new StringTokenizer("");
}

String GetNextToken() throws IOException {
if (!strTok.hasMoreTokens())
strTok = new StringTokenizer(bufReader.readLine());
return strTok.nextToken();
}

public int nextInt() throws IOException {
return Integer.valueOf(GetNextToken());
}

public long nextLong() throws IOException {
return Long.valueOf(GetNextToken());
}

public double nextDouble() throws IOException {
return Double.valueOf(GetNextToken());
}

public String nextString() throws IOException {
return GetNextToken();
}

public String nextLine() throws IOException {
return bufReader.readLine();
}

public int countTokens() {
return strTok.countTokens();
}

public boolean hasMoreTokens() {
return strTok.hasMoreTokens();
}
}

}

Codeforces Round #194 (Div. 2) B Eight Point Sets

// Codeforces Round #194 (Div. 2) B Eight Point Sets

import java.io.*;
import java.math.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
private static boolean LOCAL_TEST = false;

public static class MyPoint implements Comparable<MyPoint> {
public int X;
public int Y;

public int compareTo(MyPoint o) {
if (X != o.X)
return X - o.X;
else
return Y - o.Y;
}
}

private static void solve() throws IOException
{
ArrayList<MyPoint> pp = new ArrayList<MainCodeforces1.MyPoint>();
HashSet<Integer> sx = new HashSet<Integer>();
HashSet<Integer> sy = new HashSet<Integer>();
for (int i = 0; i < 8; i++) {
MyPoint p = new MyPoint();
p.X = in.nextInt();
p.Y = in.nextInt();
pp.add(p);
sx.add(p.X);
sy.add(p.Y);
}
Collections.sort(pp);
MyPoint[] q = pp.toArray(new MyPoint[pp.size()]);
boolean respectable = false;
if (sx.size() == 3 && sy.size() == 3 &&
q[0].X == q[1].X &&
q[1].X == q[2].X &&
q[3].X == q[4].X &&
q[5].X == q[6].X &&
q[6].X == q[7].X &&
q[0].Y == q[3].Y &&
q[0].Y == q[5].Y &&
q[1].Y == q[6].Y &&
q[2].Y == q[4].Y &&
q[2].Y == q[7].Y)
respectable = true;
if (respectable)
out.println("respectable");
else
out.println("ugly");
}

public static void main(String[] args) throws IOException {
// helpers for input/output
out = System.out;
try {
String cname = System.getenv("COMPUTERNAME");
if (!cname.equals(""))
LOCAL_TEST = true;
} catch (Exception e) {
}
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}

solve();
}

// =====================================
static class MyScanner {
BufferedReader bufReader;
StringTokenizer strTok;

public MyScanner() throws IOException
{
bufReader = new BufferedReader(new InputStreamReader(System.in));
strTok = new StringTokenizer("");
}

public MyScanner(String inputFile) throws IOException {
bufReader = new BufferedReader(new InputStreamReader(new FileInputStream(
inputFile)));
strTok = new StringTokenizer("");
}

String GetNextToken() throws IOException {
if (!strTok.hasMoreTokens())
strTok = new StringTokenizer(bufReader.readLine());
return strTok.nextToken();
}

public int nextInt() throws IOException {
return Integer.valueOf(GetNextToken());
}

public long nextLong() throws IOException {
return Long.valueOf(GetNextToken());
}

public double nextDouble() throws IOException {
return Double.valueOf(GetNextToken());
}

public String nextString() throws IOException {
return GetNextToken();
}

public String nextLine() throws IOException {
return bufReader.readLine();
}

public int countTokens() {
return strTok.countTokens();
}

public boolean hasMoreTokens() {
return strTok.hasMoreTokens();
}
}

}

Friday, August 23, 2013

Codeforces Round #194 (Div. 2) A Candy Bags

// Codeforces Round #194 (Div. 2) A Candy Bags

import java.io.*;
import java.math.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
private static boolean LOCAL_TEST = false;

private static void solve() throws IOException
{
int n = in.nextInt();
int n2 = n * n;
int p = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n / 2; j++) {
if (j > 1)
out.print(" ");
out.print(p + " ");
out.print(n2 - p + 1);
p++;
}
out.println();
}
}

public static void main(String[] args) throws IOException {
// helpers for input/output
out = System.out;
try {
String cname = System.getenv("COMPUTERNAME");
if (!cname.equals(""))
LOCAL_TEST = true;
} catch (Exception e) {
}
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}

solve();
}

// =====================================
static class MyScanner {
BufferedReader bufReader;
StringTokenizer strTok;

public MyScanner() throws IOException
{
bufReader = new BufferedReader(new InputStreamReader(System.in));
strTok = new StringTokenizer("");
}

public MyScanner(String inputFile) throws IOException {
bufReader = new BufferedReader(new InputStreamReader(new FileInputStream(
inputFile)));
strTok = new StringTokenizer("");
}

String GetNextToken() throws IOException {
if (!strTok.hasMoreTokens())
strTok = new StringTokenizer(bufReader.readLine());
return strTok.nextToken();
}

public int nextInt() throws IOException {
return Integer.valueOf(GetNextToken());
}

public long nextLong() throws IOException {
return Long.valueOf(GetNextToken());
}

public double nextDouble() throws IOException {
return Double.valueOf(GetNextToken());
}

public String nextString() throws IOException {
return GetNextToken();
}

public String nextLine() throws IOException {
return bufReader.readLine();
}

public int countTokens() {
return strTok.countTokens();
}

public boolean hasMoreTokens() {
return strTok.hasMoreTokens();
}
}

}

Codeforces Round #192 (Div. 2) C Purification

// Codeforces Round #192 (Div. 2) C Purification

import java.io.*;
import java.math.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
private static boolean LOCAL_TEST = false;

private static void solve() throws IOException
{
int n = in.nextInt();
char[][] tiles = new char[n][n];
boolean allEvilsRowExists = false;
for (int i = 0; i < n; i++) {
String s = in.nextLine();
tiles[i] = s.toCharArray();
if (!s.contains("."))
allEvilsRowExists = true;
}
boolean allEvilsColExists = false;
for (int col = 0; col < n; col++) {
int cntEvils = 0;
for (int row = 0; row < n; row++) {
if (tiles[row][col] == 'E')
cntEvils++;
}
if (cntEvils == n)
allEvilsColExists = true;
}
if (allEvilsColExists && allEvilsRowExists)
out.println(-1);
else {
if (allEvilsRowExists) {
for (int col = 0; col < n; col++) {
for (int row = 0; row < n; row++) {
if (tiles[row][col] == '.') {
out.println((row + 1) + " " + (col + 1));
break;
}
}
}
}
else {
for (int row = 0; row < n; row++) {
for (int col = 0; col < n; col++) {
if (tiles[row][col] == '.') {
out.println((row + 1) + " " + (col + 1));
break;
}
}
}

}
}
}

public static void main(String[] args) throws IOException {
// helpers for input/output
out = System.out;
try {
String cname = System.getenv("COMPUTERNAME");
if (!cname.equals(""))
LOCAL_TEST = true;
} catch (Exception e) {
}
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}

solve();
}

// =====================================
static class MyScanner {
BufferedReader bufReader;
StringTokenizer strTok;

public MyScanner() throws IOException
{
bufReader = new BufferedReader(new InputStreamReader(System.in));
strTok = new StringTokenizer("");
}

public MyScanner(String inputFile) throws IOException {
bufReader = new BufferedReader(new InputStreamReader(new FileInputStream(
inputFile)));
strTok = new StringTokenizer("");
}

String GetNextToken() throws IOException {
if (!strTok.hasMoreTokens())
strTok = new StringTokenizer(bufReader.readLine());
return strTok.nextToken();
}

public int nextInt() throws IOException {
return Integer.valueOf(GetNextToken());
}

public long nextLong() throws IOException {
return Long.valueOf(GetNextToken());
}

public double nextDouble() throws IOException {
return Double.valueOf(GetNextToken());
}

public String nextString() throws IOException {
return GetNextToken();
}

public String nextLine() throws IOException {
return bufReader.readLine();
}

public int countTokens() {
return strTok.countTokens();
}

public boolean hasMoreTokens() {
return strTok.hasMoreTokens();
}
}

}

Codeforces Round #192 (Div. 2) B Road Construction

// Codeforces Round #192 (Div. 2) B Road Construction

import java.io.*;
import java.math.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
private static boolean LOCAL_TEST = false;

private static void solve() throws IOException
{
int n = in.nextInt();
int m = in.nextInt();
boolean[] forbid = new boolean[n + 1];
for (int i = 0; i < m; i++) {
int a = in.nextInt();
int b = in.nextInt();
forbid[a] = true;
forbid[b] = true;
}
int center = -1;
for (int i = 1; i <= n; i++) {
if (!forbid[i])
center = i;
}
out.println(n - 1);
if (center >= 0) {
for (int i = 1; i <= n; i++) {
if (i != center) {
out.println(center + " " + i);
}
}
}
}

public static void main(String[] args) throws IOException {
// helpers for input/output
out = System.out;
try {
String cname = System.getenv("COMPUTERNAME");
if (!cname.equals(""))
LOCAL_TEST = true;
} catch (Exception e) {
}
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}

solve();
}

// =====================================
static class MyScanner {
BufferedReader bufReader;
StringTokenizer strTok;

public MyScanner() throws IOException
{
bufReader = new BufferedReader(new InputStreamReader(System.in));
strTok = new StringTokenizer("");
}

public MyScanner(String inputFile) throws IOException {
bufReader = new BufferedReader(new InputStreamReader(new FileInputStream(
inputFile)));
strTok = new StringTokenizer("");
}

String GetNextToken() throws IOException {
if (!strTok.hasMoreTokens())
strTok = new StringTokenizer(bufReader.readLine());
return strTok.nextToken();
}

public int nextInt() throws IOException {
return Integer.valueOf(GetNextToken());
}

public long nextLong() throws IOException {
return Long.valueOf(GetNextToken());
}

public double nextDouble() throws IOException {
return Double.valueOf(GetNextToken());
}

public String nextString() throws IOException {
return GetNextToken();
}

public String nextLine() throws IOException {
return bufReader.readLine();
}

public int countTokens() {
return strTok.countTokens();
}

public boolean hasMoreTokens() {
return strTok.hasMoreTokens();
}
}

}

Codeforces Round #192 (Div. 2) A Cakeminator

// Codeforces Round #192 (Div. 2) A Cakeminator
import java.io.*;
import java.math.*;
import java.util.*;

//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
private static boolean LOCAL_TEST = false;

private static void solve() throws IOException
{
int r = in.nextInt();
int c = in.nextInt();
char[][] cc = new char[r][c];
for (int i = 0; i < r; i++) {
String s = in.nextString();
cc[i] = s.toCharArray();
}

int cnt = 0;
for (int i = 0; i < r; i++) {
boolean hasStrawberry = false;
for (int j = 0; j < c; j++) {
if (cc[i][j] == 'S') {
hasStrawberry = true;
break;
}
}
if (hasStrawberry)
continue;
for (int j = 0; j < c; j++) {
if (cc[i][j] == '.') {
cnt++;
cc[i][j] = '-';
}
}
}

for (int j = 0; j < c; j++) {
boolean hasStrawberry = false;
for (int i = 0; i < r; i++) {
if (cc[i][j] == 'S') {
hasStrawberry = true;
break;
}
}
if (hasStrawberry)
continue;
for (int i = 0; i < r; i++) {
if (cc[i][j] == '.') {
cnt++;
cc[i][j] = '-';
}
}
}
out.println(cnt);
}

public static void main(String[] args) throws IOException {
// helpers for input/output
out = System.out;
try {
String cname = System.getenv("COMPUTERNAME");
if (!cname.equals(""))
LOCAL_TEST = true;
} catch (Exception e) {
}
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}

solve();
}

// =====================================
static class MyScanner {
BufferedReader bufReader;
StringTokenizer strTok;

public MyScanner() throws IOException
{
bufReader = new BufferedReader(new InputStreamReader(System.in));
strTok = new StringTokenizer("");
}

public MyScanner(String inputFile) throws IOException {
bufReader = new BufferedReader(new InputStreamReader(new FileInputStream(
inputFile)));
strTok = new StringTokenizer("");
}

String GetNextToken() throws IOException {
if (!strTok.hasMoreTokens())
strTok = new StringTokenizer(bufReader.readLine());
return strTok.nextToken();
}

public int nextInt() throws IOException {
return Integer.valueOf(GetNextToken());
}

public long nextLong() throws IOException {
return Long.valueOf(GetNextToken());
}

public double nextDouble() throws IOException {
return Double.valueOf(GetNextToken());
}

public String nextString() throws IOException {
return GetNextToken();
}

public String nextLine() throws IOException {
return bufReader.readLine();
}

public int countTokens() {
return strTok.countTokens();
}

public boolean hasMoreTokens() {
return strTok.hasMoreTokens();
}
}

}