akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int m = Integer.parseInt(st.nextToken());
            int f = Integer.parseInt(st.nextToken());
            int r = Integer.parseInt(st.nextToken());
            if (m == -1 && f == -1 && r == -1) {
                break;
            }
            if (m == -1 || f == -1) {
                System.out.println("F");
            } else if ((m + f) >= 80) {
                System.out.println("A");
            } else if ((m + f) >= 65) {
                System.out.println("B");
            } else if (((m + f) >= 50) || ((m + f) >= 30 && r >= 50)) {
                System.out.println("C");
            } else if ((m + f) >= 30) {
                System.out.println("D");
            } else {
                System.out.println("F");
            }
        }
    }
}

Measured memory_bytes: 24120
#include<bits/stdc++.h>

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int INF = 998244353;
const int maxn = 1e6 + 5;

int n, m, ans = 0;
int f[maxn], g[maxn], pw[maxn], fac[maxn], ifac[maxn];

inline int qpow(int x, int y);
inline int add(int x, int y){ return (x + y) % INF; }
inline int mul(int x, int y){ return 1ll * x * y % INF; }
inline int sub(int x, int y){ return (x - y + INF) % INF; }
inline void uadd(int &x, int y){ (x += y) %= INF; }
inline void usub(int &x, int y){ ((x += INF) -= y) %= INF; }
inline void umul(int &x, int y){ x = 1ll * x * y % INF; }
inline void udiv(int &x, int y){ umul(x, qpow(y, INF - 2)); }

inline int qpow(int x, int y){
	int ret = 1;
	for(; y; y >>= 1){
		if(y & 1)
			umul(ret, x);
		umul(x, x);
	}
	return ret;
}

inline int binom(int x, int y){ return mul(fac[x], mul(ifac[y], ifac[x - y])); }

inline int solve(){
	int ret = 0;
	REP(i, 0, min(n - 1, m)){
		if(n - 1 == m){
			if(i == n - 1)
				f[i] = 1;
			else
				f[i] = 0;
		}
		else if(n - 1 < m)
			f[i] = sub(binom((n - 1) - i + m - (i + 1), m - (i + 1)), binom((n - 1) - (i + 1) + m - i, m - i));
		else{
			f[i] = sub(binom((n - 1) - (i + 1) + m - i, m - i), binom((n - 1) - i + m - (i + 1), m - (i + 1)));
			uadd(ans, mul(mul(f[i], binom(2 * i, i)), n + m - i * 2 - 1));
		}
		g[i] = mul(binom(i * 2, i), i * 2 + 1);
		uadd(g[i], pw[i]);
		udiv(g[i], 2);
		uadd(ret, mul(f[i], g[i]));
	}
	return ret;
}

int main(){
	scanf("%d%d", &n, &m);
	fac[0] = 1;
	FOR(i, 1, maxn)
		fac[i] = mul(fac[i - 1], i);
	ifac[maxn - 1] = qpow(fac[maxn - 1], INF - 2);
	for(int i = maxn - 2; i >= 0; --i)
		ifac[i] = mul(ifac[i + 1], i + 1);
	pw[0] = 1;
	FOR(i, 1, maxn)
		pw[i] = mul(pw[i - 1], 4);

	uadd(ans, solve());
	swap(n, m);
	uadd(ans, solve());

	REP(i, 0, min(n, m)){
		uadd(ans, mul(binom(i * 2 - 1, i), binom(n + m - 2 * i, n - i)));
	}
	udiv(ans, binom(n + m, m));
	
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 19464
N=int(input())
s=input()
t=input()
ans=10**9
for i in range(N+1):
    for j in range(N+1):
        u=s[:i]+t[j:]
        if len(u)<N:
            continue
        if u[:N]==s and u[-N:]==t:
            ans=min(ans,len(u))
print(ans)

Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;

int N;
string S;

long long solve(char R,char G,char B){
	vector<int> countB(N,0);
	for(int i=1;i<N;i++)countB[i]=countB[i-1]+((S[i]==B)?1:0);
	
	long long ret=0;
	for(int i=0;i<N;i++)for(int j=i+1;j<N;j++){
		if(S[i]==R && S[j]==G){
			ret+=countB[N-1]-countB[j];
			if(2*j-i<N && S[2*j-i]==B)ret--;
		}
	}
	return ret;
}

int main(){
	cin >> N >> S;
	long long ans=0;
	ans+=solve('R','G','B');
	ans+=solve('R','B','G');
	ans+=solve('G','R','B');
	ans+=solve('G','B','R');
	ans+=solve('B','R','G');
	ans+=solve('B','G','R');
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>

using namespace std;

const double PI = acos(-1);

int main(int argc, char *argv[]) {
  cin.sync_with_stdio(false);
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  if (x1 > x2) {
    swap(x1, x2), swap(y1, y2);
  }
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  if (y1 > y2) {
    y1 = -y1;
    y2 = -y2;
    for (int i = 0; i < n; i++) {
      a[i].second = -a[i].second;
    }
  }
  vector<pair<int, int>> b;
  for (auto e : a) {
    if (e.first >= x1 && e.first <= x2 && e.second >= y1 && e.second <= y2) {
      b.push_back(e);
    }
  }
  sort(b.begin(), b.end());
  vector<int> st;
  for (auto e : b) {
    if (st.empty() || e.second > st.back()) {
      st.push_back(e.second);
    } else {
      *lower_bound(st.begin(), st.end(), e.second) = e.second;
    }
  }
  int len = min(x2 - x1, y2 - y1);
  int k = st.size();
  if (len + 1 == k) {
    double ans = (x2 - x1 + y2 - y1) * 100.0 - 20.0 * k + 5.0 * PI * (k + 1);
    printf("%.12f\n", ans);
  } else {
    double ans = (x2 - x1 + y2 - y1) * 100.0 - 20.0 * k + 5.0 * PI * k;
    printf("%.12f\n", ans);
  }
  return 0;
}


Measured memory_bytes: 5232
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {
    string s;
    cin >> s;
    cout << s[0] << (s.size() - 2) << s[s.size()-1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<queue>

typedef long long ll;
using namespace std;

#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 
 
int A,B;
int main()
{
	IOS;
	 cin>>A>>B;
  cout<<max(A-2*B,0);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

ll gcd(ll a, ll b) {
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}


int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    ll p = lcm(c, d);
    ll x = (b / c) - ((a-1) / c);
    ll y = (b / d) - ((a-1) / d);
    ll z = (b / p) - ((a-1) / p);

    cout << b - a + 1 - x - y + z << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define A first
#define B second

using namespace std;

typedef pair<int,int> P;
int dp[102][4][3];

int main(void){
	
	int n,k;
	
	cin >> n >> k;
	
	vector<P>v(k);
	
	for(int i=0;i<k;i++)cin >> v[i].A >> v[i].B;
	sort(v.begin(),v.end());
	
	for(int i=1;i<4;i++)dp[1][i][1]=1;
	
	int p=0;
	for(int i=1;i<=n;i++){
		for(int k=1;k<4;k++){
			for(int l=1;l<3;l++){
				if(i==v[p].A){
					if(v[p].B==k && l<2)dp[i+1][k][l+1]+=dp[i][v[p].B][l]%10000;
					else if(v[p].B!=k)dp[i+1][k][1]+=dp[i][v[p].B][l]%10000;
					continue;
				}
				
				for(int j=1;j<4;j++){
					if(j==k && l<2)dp[i+1][k][l+1]+=dp[i][j][l]%10000;
					else if(j!=k)dp[i+1][k][1]+=dp[i][j][l]%10000;
				}
			}
		}
		if(v[p].A==i)p++;
	}
	
	int ans=0;
	if(n==v[p-1].A){
		for(int j=1;j<3;j++){
			ans+=dp[n][v[p-1].B][j];
			ans%=10000;
		}
	}
	else {
		for(int i=1;i<4;i++){
			for(int j=1;j<3;j++){
				ans+=dp[n][i][j];
				ans%=10000;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N;

    //入力
    cin >> N;

    int L[N];
    int ans = 0;
    for(int i=0;i<=N-1;i++) cin >> L[i];
    //昇順
    sort(L, L+N);
    reverse(L,L+N);
    //ループ
    for(int i=0; i<=N-3; i++){
        for(int j=i+1; j<=N-2; j++){
            for(int k=j+1; k<=N-1; k++){
                if(L[i]!=L[j]&&L[j]!=L[k]){
                    if(L[i]<L[j]+L[k]){
                        ans = ans + 1;
                    }
                }
            }
        }
    }


    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <list>
#include <math.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  
  for(int i = 1; i < 10; i++) {
    for(int j = 1; j < 10; j++) {
      if(i*j == N) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
 
    int x, ans = 0;
 
    int a[10005] = {};
 
    cin >> x;
 
    for(int b = 0; b < x; b++){
 
          cin >> a[b];
 
          while(true){
 
                  int t = a[b];

                  a[b] /= 2;
 
                  if(a[b] * 2 != t) break;
 
                  ans++;
 
           }
 
    }
 
    cout << ans << endl;
 
    return 0;
 
}  


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	string a, b;
	cin >> a >> b;
	if (a.size() > b.size()) {
		puts("GREATER");
		return 0;
	}
	if (a.size() < b.size()) {
		puts("LESS");
		return 0;
	}
	if (a.size() == b.size()) {
		ff(i, 0, a.size()) {
			if (a.at(i) > b.at(i)) {
				puts("GREATER");
				return 0;
			}
			if (a.at(i) < b.at(i)) {
				puts("LESS");
				return 0;
			}
		}
		puts("EQUAL");
		return 0;
	}
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		Console.WriteLine(ri() / 3);
	}

	public Sol(){
		
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
import 'dart:io';

main(){
  var d = Data.readN();
  print((1000-(d.n%1000))%1000);
}

class Data {
  int n;
  List<num> _a;
  List<String> s;
  num get a => _a[0];
  Data.readN(){
    n = int.parse(stdin.readLineSync());
  }

  readNum() => _a.add(num.parse(stdin.readLineSync()));

  readNums(){
    for(int i = 0; i < n; i++){
      readNum();
    }
  }

  readString(){
    s.add(stdin.readLineSync());
  }

  readStrings(){
    for(int i = 0; i < n; i++){
      readString();
    }
  }
}

input( a){
  stdin.readLineSync();
}

Measured memory_bytes: 13044
import java.util.Scanner;

public class Main {
   public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
       int[] a = new int[10000];
       for(int i=0;i<10000;i++){
           a[i] = sc.nextInt();
           if(a[i]==0){
               break;
           }else{
               System.out.println("Case "+(i+1)+": "+a[i]);
           }
       }
       sc.close();
   } 
}


Measured memory_bytes: 42408
import java.util.*;
import static java.lang.Math.*;
import java.io.*;
public class Main {
	static   boolean[] ans= new boolean[10];
	static int[] temp;
	static int[] temp2;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		PrintWriter pr=new PrintWriter(System.out);
		while(sc.hasNext()){
			char[] cha=sc.next().toCharArray();
			temp=new int[10];
			for(int i=0;i<13;i++)temp[(int)cha[i]-(int)'0']++;
			ArrayList<Integer> ans=new ArrayList<Integer>();
			temp2=new int[10];

			for(int i=1;i<10;i++){
				for(int j=1;j<10;j++){
					if(temp[i]<4){
						temp2 = temp.clone();
						temp2[i]++;
						temp2[j]-=2;
						for(int k=1;k<8;k++){
							if(temp2[k]<0){
								temp2[9]=-1;
								break;
							}
							if(temp2[k]==1 || temp2[k]==4){
								temp2[k]--;
								temp2[k+1]--;
								temp2[k+2]--;
							}else if(temp2[k]==2){
								temp2[k]-=2;
								temp2[k+1]-=2;
								temp2[k+2]-=2;
							}
						}
						if(temp2[8]>=0&&temp2[8]%3==0&&temp2[9]>=0&&temp2[9]%3==0){
							ans.add(i);
							break;
						}
					}
				}
			}



			if(ans.size()==0)pr.println(0);            
			else {
				for(int i=0;i<ans.size();i++){
					if(i!=0)pr.print(" ");
					pr.print(ans.get(i));
				}
				pr.println();
			}
		}
		pr.flush();
	}
}

Measured memory_bytes: 17220
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
 int N;
 cin>>N;
 int sum=0;
 int d[N];
 for(int i=0; i<N; i++){
     cin>>d[i];
 }
 sort(d,d+N);
 for(int j=0; j<N; j++){
     if(d[j]!=d[j+1]&&j!=N-1){
         sum++;
     }
 }
 cout<<sum+1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int p[111];
int dp[101][50100];

int main(){
	cin.sync_with_stdio(false);
  while(1){
    cin>>n;
    if(n==0)break;
    rep(i,n)cin>>p[i];
    rep(j,101)rep(k,50100)dp[j][k]=INF;
    dp[0][0]=0;
    rep(i,n)for(int j=100;j>=0;j--)for(int k=50000;k>=0;k--){
      if(dp[j][k]==INF)continue;
      if(p[i]%1000>500&&k>=(p[i]%1000-500)){
        minch(dp[j+1][k-(p[i]%1000-500)],dp[j][k]+p[i]);
      }else if(p[i]%1000==0&&k>=500){
        minch(dp[j+1][k-500],dp[j][k]+p[i]);
      }
      int rest=(1000000-p[i])%1000;
      minch(dp[j+rest/500][rest%500+k],dp[j][k]+p[i]);
    }
    int resa=0,resb=INF;
    rep(j,101)rep(k,50100){
      if(dp[j][k]!=INF&&resa<j){
        resa=j;
        resb=dp[j][k];
      }else if(resa==j)minch(resb,dp[j][k]);
    }
    printf("%d %d\n", resa,resb);
  }
	return 0;
}

Measured memory_bytes: 22952
#include<bits/stdc++.h>
using namespace std;
int prime[303]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,
149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,
317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,
509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,
719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,
937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,
1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,
1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,
1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597,1601,1607,1609,1613,1619,1621,1627,1637,1657,
1663,1667,1669,1693,1697,1699,1709,1721,1723,1733,1741,1747,1753,1759,1777,1783,1787,1789,1801,1811,1823,1831,1847,1861,1867,
1871,1873,1877,1879,1889,1901,1907,1913,1931,1933,1949,1951,1973,1979,1987,1993,1997,1999},n,k,cnt[303],xx[10003];
long long C(long long x,long long y){
	y=min(y,x-y);
	long long ans=1;
	for(int i=0;i<y;i++)xx[i]=x-i;
	for(int i=1;i<=y;i++){
		long long tmp=i;
		for(long long xxx=0;xxx<303&&tmp!=1;xxx++)
			while(tmp%prime[xxx]==0)
				tmp/=prime[xxx],
				cnt[xxx]++;
	}
	for(long long i=0;i<y;i++)
		for(long long xxx=0;xxx<303;xxx++)
			while(cnt[xxx]&&xx[i]%prime[xxx]==0)
				cnt[xxx]--,
				xx[i]/=prime[xxx];
	for(long long i=0;i<y;i++)ans=(ans*xx[i])%1000000007;
	return ans;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++)
		if(i+1<=n-k+2)
			printf("%lld\n",(C(k-1,i-1)*C(n-k+1,i))%1000000007);
		else
			printf("0\n");
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
using namespace std;
typedef pair<int,int> P;
const int INF = ~(1<<31) / 2;

int main(){
    int k;
    cin >> k;
    for(int j=0;j<k;j++){
        int n[80];
        string a,b;
        cin >> a >> b;
        int n_a = a.size(),n_b = b.size();
        if(n_a>80||n_b>80){cout << "overflow" << endl;continue;}

        fill(n,n+80,0);
        bool is_over = false;
        for(int i=0;i<max(n_a,n_b);i++){
            int ai,bi;
            if (i<n_a) ai = a[n_a-i-1]-'0';
            else ai = 0;
            if (i<n_b) bi = b[n_b-i-1]-'0';
            else bi = 0;
            n[i] += ai + bi;
            if (n[i]>=10){
                if(i+1 == 80){
                    is_over = true;
                    break;
                }else{
                    n[i+1] += n[i]/10;
                    n[i] = n[i]%10;
                }
            }
        }
        if (is_over){
            cout << "overflow" << endl;
        }else{
            bool started = false;
            for(int i=79;i>=0;i--){
                if(!started && n[i]>0){
                    started = true;
                }
                if(started || (!started&&i==0)){
                    cout << n[i];
                }
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#define rep(i,m,n) for(int i=m; i<(n); i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;
ll inf=1LL<<60;
double eps=1e-14;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int mx = (n-1)*(n-2)/2;
    if(mx < k)
    {
        cout << -1 << endl;
        return 0;
    }
    vector<pii> ans;
    rep(i,0,n-1)
    {
        ans.push_back(pii(i+1, n));
    }
    int add = mx - k;
    vector<pii> edge;
    rep(i,0,n-1)rep(j,0,i) edge.push_back(pii(i+1, j+1));
    rep(i,0,add) ans.push_back(edge[i]);
    cout << ans.size() << endl;
    rep(i,0,ans.size())
    {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
    using namespace std;
	typedef long long int ll; 
     
    int main() { 
      
      int m=1000;
      int M=0; 
      
      for(int i=0; i<5; i++){
        int A;
        cin>> A;
        m= min( A, m );
        M= max( A, M );  
      }
      
      int k;
      cin >> k;
      
      if(M-m>k){
        cout<< ":(" << endl;
      }else{
        cout<< "Yay!" << endl;
      }
           
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = 1000000007;
ll mpow(ll a,ll b){ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
/*template*/

int main()
{
  ll n;cin>>n;
  string ans;
  switch(n%10){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
    ans="hon";break;
    case 0:
    case 1:
    case 6:
    case 8:
    ans="pon";break;
    default:
    ans="bon";break;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>

using namespace std;

void solve()
{
    int n;
    cin>>n;

    int res=n%10;

    if(res==2||res==4||res==5 ||res==7 ||res==9)
        cout<<"hon\n";
    else if(res==0 || res==1 || res==6 ||res==8)
        cout<<"pon\n";
    else
        cout<<"bon\n";
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);

    solve();
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    ll sum = 0;
    rep(i, m) {
        int a;
        cin >> a;
        sum += a;
    }

    if (sum > n) {
        cout << -1 << endl;
    } else {
        cout << n - sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
using namespace std;

typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
typedef vector<vector<lli> > vvi;
typedef vector<ii> vii;

#define EB emplace_back
#define PB push_back
#define MP make_pair
#define FF first
#define SS second

const int mod = 1e9 +7;
lli n, dp[4194304], a[21][21];
int solve(int man, int mask)
{
	if(man>=n) return 1;
	else if(dp[mask]!=-1)return dp[mask];
	else
	{
		bool flag=0;
		lli ans=0;
		for(int i=0; i<n; i++)
			if(!((mask>>i)&1) && a[man][i]==1)
				ans=(ans+solve(man+1, mask^(1LL<<i)))%mod;
		return dp[mask]=ans;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	for(int i=0; i<4194304; i++)dp[i]=-1;
	cin>>n;
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			cin>>a[i][j];
	cout<<solve(0,0);
}

Measured memory_bytes: 36436
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int n = s.length();
  bool found = false;
  for (int i = 0; i + 2 <= n; ++i) {
    if (s.substr(i, 2) == "AC") {
      found = true;
    }
  }
  if (found) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s; cin >> s;
    bool isEven = (s.size()%2==0? true:false);
    bool isSame = (s[0]==s.back()? true:false);

    if(isEven^isSame) cout << "Second" << endl;
    else cout << "First" << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String [] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		if(n<m){
			System.out.println(0);
		}else{
			System.out.println(n-m);
		}
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>

#define fst first
#define snd second
#define INF 0x3FFFFFFF
#define PI (2*acos(0))

using namespace std;

typedef long long ll;
typedef complex<double> pt;

bool tfits(string &s, string &t, int idx) {
  if (idx + t.size() - 1 >= s.size()) return false;
  for (int i = idx, j = 0; j < (int)t.size(); i++, j++) {
    if (s[i] == '?' || s[i] == t[j]) {

    } else return false;
  }
  for (int i = idx, j = 0; j < (int)t.size(); i++, j++) {
    s[i] = t[j];
  }
  return true;
}

int main() {
  string s, t;
  cin >> s >> t;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (tfits(s, t, i)) {
      for (char c : s) {
        if (c == '?') cout << "a";
        else cout << c;
      }
      cout << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
  double x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  double dist = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
  printf("%lf\n", dist);
  return 0;
}



Measured memory_bytes: 3188
n = int(input())
s = input()

nums = tuple(str(i) for i in range(10))

ans = 0
for i in nums:
    pi = s.find(i)
    if pi == -1:
        continue

    for j in nums:
        pj = s.find(j, pi + 1)
        if pj == -1:
            continue

        for k in nums:
            pk = s.find(k, pj + 1)
            if pk == -1:
                continue

            ans += 1

print(ans)


Measured memory_bytes: 3060
h,w=map(int,input().split())
b=[[1]*(w+2)]
for i in range(h):
  bb=[1]
  s=input()
  for j in range(w):
    if s[j]=="#":bb.append(1)
    else:bb.append(0)
  bb.append(1)
  b.append(bb)
b.append([1]*(w+2))

ans=0
d=[[-1,0],[1,0],[0,-1],[0,1]]
for si in range(1,h+1):
  for sj in range(1,w+1):
    if b[si][sj]:continue
    visited={(si,sj)}
    Q=[(si,sj)]
    count=-1
    while Q:
      P=[]
      for i,j in Q:
        for di,dj in d:
          if b[i+di][j+dj]:continue
          if (i+di,j+dj)in visited:continue
          visited.add((i+di,j+dj))
          P.append((i+di,j+dj))
      Q=P
      count+=1
    ans=max(ans,count)
print(ans)

Measured memory_bytes: 45532
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

N,Q = map(int,input().split())
to = [[] for _ in range(N+1)]
ans = [0 for _ in range(N+1)]

for _ in range(N-1):
    a,b=map(int,input().split())
    to[a].append(b)
    to[b].append(a)
for _ in range(Q):
    px = list(map(int,input().split()))
    ans[px[0]] += px[1]

def dfs(v, p):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)
dfs(1, -1)
print(*ans[1:])


Measured memory_bytes: 230928
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A,B;
  cin >> A >> B;
  if(B==1){
    cout << 0 << endl;
    return 0;
  }
  if(A==B || B<A){
    cout << 1 << endl;
    return 0;
  }
  int ans=B-A;
  if(ans%(A-1)==0)
    cout << 1+ans/(A-1) << endl;
  else
    cout << 2+ans/(A-1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
  int n, m;cin>>n>>m;
  vector<vector<int>> s(m);
  for(int i=0;i<m;i++){
    int k;cin>>k;
    vector<int> tmp(k);
    for(int j=0;j<k;j++){
      cin>>tmp[j];
    }
    s[i]=tmp;
  }
  int ans=0;
  vector<int> p(m);
  for(int i=0;i<m;i++)cin>>p[i];
  for(int b=0;b<1<<n;b++){
    bool light=true;
    for(int i=0;i<m;i++){
      int count=0;
      for(int x:s[i]){
        x--;
        count+=(b>>x)&1;
      }
      if(count%2!=p[i]){
        light=false;
        break;
      }
    }
    if(light)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<vector>
int main() {
	int w = 0;
	int k = 0;
	std::vector<int> v(10);
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < 10; ++j) {
			std::cin >> v[j];
		}
		std::sort(v.begin(), v.end());
		if (i == 0) {
			w = v[9] + v[8] + v[7];
		}
		if (i == 1) {
			k = v[9] + v[8] + v[7];
		}
	}
	std::cout << w << " " << k << std::endl;
	return 0;
}

Measured memory_bytes: 3016
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long int64;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

int main () {
    ios_base::sync_with_stdio(0);
//  freopen("_input.txt", "rt", stdin);
//  freopen("_output.txt", "wt", stdout);

    int tc;
    cin >> tc;
    for (int ti = 0; ti < tc; ++ti) {
        int n;
        cin >> n;

        vector<long long> a(n);
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }

        string s;
        cin >> s;

        bool key = true;
        vector<long long> b;
        for (int i = n - 1; i >= 0; --i) {
            long long cur = a[i];
            for (int j = 0; j < sz(b); ++j) {
                cur = min(cur, cur ^ b[j]);
            }

            if (cur == 0) {
                continue;
            }

            if (s[i] == '1') {
                key = false;
                break;
            }

            for (int j = 0; j < sz(b); ++j) {
                b[j] = min(b[j], b[j] ^ cur);
            }
            b.pb(cur);
        }

        cout << (key ? 0 : 1) << "\n";
    }

    return 0;
}


Measured memory_bytes: 3564
class Dice:
    def __init__ (self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]
        
    def roll(self, c):
        if c in ["N", "S"]:
            if c == "N":
                self.y.append(self.y.pop(0))
            elif c == "S":
                self.y.insert(0, self.y.pop())
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
        else:
            if c == "E":
                self.x.insert(0, self.x.pop())
            elif c == "W":
                self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]
            
    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]
        
p = [ int(n) for n in input().split() ]
s = input()

dice = Dice(p)

for c in s:
    dice.roll(c)
print(dice.num(1))


Measured memory_bytes: 5608
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	a, b, c := getString(), getString(), getString()

	ans := "NO"
	if a[len(a)-1] == b[0] && b[len(b)-1] == c[0] {
		ans = "YES"
	}

	fmt.Println(ans)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i,a,b) for(int i=a;i<=b;i++)
int n,m,k,l,r;
LL f[505][505];
int main()
{
	cin>>n>>m>>k;
	rep(i,1,m)
	{
		cin>>l>>r;
		f[l][r]++;
	}
	rep(i,1,500)rep(j,1,500)f[i][j]+=f[i][j-1]+f[i-1][j]-f[i-1][j-1];
	rep(i,1,k)
	{
		cin>>l>>r;
		l--;
		cout<<f[r][r]-f[l][r]-f[r][l]+f[l][l]<<endl;
	}
}


Measured memory_bytes: 2944
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n = int(input())
l = [int(x) for x in input().split()]
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            a, b, c = l[i], l[j], l[k]
            if abs(b - c) < a < b + c and abs(a - b) < c < a + b and abs(c - a) < b < c + a and a != b and b != c and a != c:
                cnt += 1
               
print(cnt)

Measured memory_bytes: 74300
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int MOD = 1000000007;

int n, k, r1, r2, res, tab[2005], i, j;

int main() {
scanf("%d %d", &n, &k);
r1 = (((k - 1) * 1LL * k) / 2) % MOD;
r2 = (((k + 1) * 1LL * k) / 2) % MOD;
res = 0;
for (i=0;i<n;i++) scanf("%d", &tab[i]);
for (i=0;i<n;i++) for (j=i+1;j<n;j++) if (tab[i] != tab[j]) {
	if (tab[i] < tab[j]) res = (res + r1) % MOD; else res = (res + r2) % MOD;
}
printf("%d\n", res);
return 0;
}

Measured memory_bytes: 256
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
a.insert(0, [0, 0, 0])
dp = [[0, 0, 0] for _ in range(N+1)]
for i in range(1, N + 1):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j] = max(dp[i][j], a[i][j] + dp[i - 1][k])
print(max(dp[-1]))

Measured memory_bytes: 50032
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int A,B,C;
  cin >> A >> B >> C;
  if ((A==5&&B==5&&C==7)||(A==5&&B==7&&C==5)||(A==7&&B==5&&C==5))
  cout << "YES" << endl;
  else 
  cout << "NO" << endl;
}

Measured memory_bytes: 256
// by newbiechd
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl

const int N_MAX = 2003;
int a[N_MAX], b[N_MAX], c[N_MAX];
long long dp[N_MAX];
int que[N_MAX], head, tail;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n, m;
  cin >> n >> m;
  int mnIdx = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] < a[mnIdx])
      mnIdx = i;
  }
  for (int i = mnIdx; i <= n; ++i)
    b[i - mnIdx + 1] = a[i];
  for (int i = 1; i < mnIdx; ++i)
    b[i + n - mnIdx + 1] = a[i];
  long long ans = 0x3f3f3f3f3f3f3f3f;
  memcpy(c + 1, b + 1, sizeof(b[0]) * n);
  for (int l = 1; l <= n; ++l) {
    long long temp = 0;
    for (int i = 1; i <= n; ++i)
      temp += c[i];
    ans = std::min(1ll * m * (l - 1) + temp, ans);
    for (int i = l + 1; i <= n; ++i)
      c[i] = std::min(b[i - l], c[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static int bottommost(int[] num1, int n){
    int[] num2 = new int[n-1];
    int ans;
    int numTemp = 0;
    for (int i = 0; i < n-1; i++) {
      numTemp = num1[i] + num1[i+1];
      if(numTemp >= 10) {
        numTemp -= 10;
      }
      num2[i] = numTemp;
    }
    if(n == 2) {
      ans = num2[0];
    }
    else {
      ans = bottommost(num2,n-1);
    }
    return ans;
  }

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      String str = sc.next();
      char[] charArr = str.toCharArray();
      int n = charArr.length;
      int[] arr = new int[n];
      for (int i = 0; i < n; i++) {
        arr[i] = charArr[i] - '0';
      }
      int ans = bottommost(arr,n);
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 250001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int H, W;
  scanf("%d %d", &H, &W);

  int a[501][501];
  rep(hi, 0, H) {
    rep(wi, 0, W) {
      scanf("%d", &a[hi][wi]);
    }
  }

  int x[MAX], y[MAX], xp[MAX], yp[MAX];
  int n = 0;
  rep(yi, 0, H) {
    rep(xi, 0, W) {
      if (xi < W - 1) {
        if (a[yi][xi] % 2 == 0) continue;
        a[yi][xi + 1]++;
        x[n] = xi + 1; y[n] = yi + 1;
        xp[n] = x[n] + 1; yp[n] = y[n];
        n++;
      } else {
        if (yi == H - 1) continue;
        if (a[yi][xi] % 2 == 0) continue;
        a[yi + 1][xi]++;
        x[n] = xi + 1; y[n] = yi + 1;
        xp[n] = x[n]; yp[n] = y[n] + 1;
        n++;
      }
    }
  }

  printf("%d\n", n);
  rep(i, 0, n) {
    printf("%d %d %d %d\n", y[i], x[i], yp[i], xp[i]);
  }
  return 0;
}


Measured memory_bytes: 6912
object Main extends App {
  override def main(args: Array[String]): Unit = {
    import scala.io.{StdIn => in}
    Iterator
      .continually(in.readLine())
      .takeWhile(_ != "0 0")
      .map(str =>
        for (x <- 1 to str.split(" ")(0).toInt) yield in.readLine()
      ).map(new Solver(_).solve).foreach(println)
  }
}

class Solver(input: Seq[String]) {
  val h = input.size
  val w = input(0).size
  val arr = Array.ofDim[Char](h, w)
  for (i <- 0 until h; j <- 0 until w) arr(i)(j) = input(i)(j)

  def solve: String = {
    val list = makeAllList.sorted
    val ans = list.zip(list.drop(1)).map(s => getDuplicate(s._1, s._2)).max(new StringComparator)
    if (ans.size < 2) "0" else ans
  }

  def getDuplicate(str1: String, str2: String): String = str1.zip(str2).takeWhile(c => c._1 == c._2).map(_._1).mkString("")

  class StringComparator extends Ordering[String] {
    override def compare(x: String, y: String) = if (x.length != y.length) x.length.compare(y.length) else y.compareTo(x)
  }

  def makeAllList: Seq[String] = {
    val direction = List((0, 1), (1, 0), (-1, 0), (0, -1), (1, 1), (1, -1), (-1, 1), (-1, -1))
    for (starti <- 0 until h; startj <- 0 until w; d <- direction) yield {
      val head = arr(starti)(startj)
      val initPosition = (starti, startj)
      val left = Iterator
        .iterate(movePointer(initPosition, d))(pos => movePointer(pos, d))
        .takeWhile(_ != (starti, startj))
        .map(pos => arr(pos._1)(pos._2))
        .mkString("")
      head + left
    }
  }

  def movePointer(pos: (Int, Int), direction: (Int, Int)): (Int, Int) = (((pos._1 + direction._1 + h) % h), ((pos._2 + direction._2 + w) % w))
}

Measured memory_bytes: 270524
import java.util.ArrayList;

import java.util.Scanner;

public class Main {
	public static int getParent (int indexOfArray) {
		int result = (indexOfArray - 1)/2;
		return result;
	}
	public static int getLeftChild (int indexOfArray) {
		int result = indexOfArray * 2 + 1;
		return result;
	}
	public static int getRightChild (int indexOfArray) {
		int result = indexOfArray * 2 + 2; 
		return result;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int size =Integer.parseInt(sc.nextLine());
		String[] arrStr = sc.nextLine().split(" ");
		ArrayList<Integer> arr = new ArrayList<Integer>();
		for(int i = 0; i < size; i += 1) {
			arr.add(Integer.parseInt(arrStr[i]));
			
		}
		for(int i = 0; i < size; i += 1) {
			int iOfL = getLeftChild(i);
			int iOfR = getRightChild(i);
			System.out.print("node "+ (i+1) +": key = " + arr.get(i) + ", ");
			if(i != 0) {
				System.out.print("parent key = "+ arr.get(getParent(i))+ ", ");
			}
			if(size > iOfL) {
				System.out.print("left key = "+ arr.get(iOfL)+ ", ");
			}
			if(size > iOfR) {
				System.out.print("right key = "+ arr.get(iOfR)+ ", ");
			}
			System.out.println("");
		}
		
		
	}

}


Measured memory_bytes: 27404
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <map> 
#include <set>
#include <vector>
#include <list>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define ll long long
#define debug cout << __FILE__ << ":" << __LINE__ << endl;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    if (v.empty()) {
        ostr << "{ }";
        return ostr;
    }
    ostr << "{" << v.front();
    for (auto itr = ++v.begin(); itr != v.end(); itr++) {
        ostr << ", " << *itr;
    }
    ostr << "}";
    return ostr;
}

int gcd(int a, int b) {
    if (a < b) a, b = b, a;
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

void solve() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a + b + c >= 22) {
        cout << "bust" <<endl;
    } else {
        cout << "win" << endl;
    }
}

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    cout.precision(20);
    cout << fixed;

    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

const string YES = "Yes";
const string NO = "No";
bool solve(int64_t X) { return X >= 30; }

// generated by online-judge-template-generator v4.4.0
// (https://github.com/kmyk/online-judge-template-generator)
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  constexpr char endl = '\n';
  int64_t X;
  cin >> X;
  auto ans = solve(X);
  cout << (ans ? YES : NO) << endl;
  return 0;
}


Measured memory_bytes: 3588
# -*- coding: utf-8 -*-

import sys
from itertools import product

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
S = input()
S += S[0]

def check(a, b):
    res = [a, b]
    # 自分と1つ前がS,Wどっちかと、自分の発言のo,xが分かれば、次が定まる
    for i in range(1, N+1):
        # 隣が同じで発言がo,違ってxなら羊
        if res[i-1] == res[i] and S[i] == 'o' \
                or res[i-1] != res[i] and S[i] == 'x':
            res.append('S')
        # 隣が同じで発言がx,違ってoなら狼
        else:
            res.append('W')
    # 1周して矛盾していないか
    if res[0] == res[N] and res[1] == res[N+1]:
        return res
    else:
        return []

# 1,2番目がS,Wどっちかの4通り試す
for a, b in product(['S', 'W'], repeat=2):
    res = check(a, b)
    if res:
        print(''.join(res[:N]))
        exit()
print(-1)


Measured memory_bytes: 4964
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
using namespace std;

int main(){
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int A,P;
    cin >>A>>P;
    int sum=A*3+P;
    int N=sum/2;
    cout << N <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#define ll long long
#define MOD 1000000007
#define MAX 10000000
using namespace std;

ll dp[110][4][4][4];
int main(){
    int n; cin >> n;
    dp[0][3][3][3]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                for(int l=0;l<4;l++){
                    for(int a=0;a<4;a++){
                        if(k==0 && l==1 && a==2) continue;
                        if(k==0 && l==2 && a==1) continue;
                        if(k==2 && l==0 && a==1) continue;
                        if(j==0 && k==2 && a==1) continue;
                        if(j==0 && l==2 && a==1) continue;
                        (dp[i+1][k][l][a]+=dp[i][j][k][l])%=MOD;
                    }
                }
            }
        }
    }
    ll ans = 0;
    for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                for(int l=0;l<4;l++){
                    (ans += dp[n][j][k][l]) %= MOD;
                }
            }
    }
    cout << ans;
    return 0;
}

   

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <string>
#include<string.h>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
    string s;
    string t="AC";
    cin>>s;
    if(s.find(t)!=-1) printf("Yes\n");
    else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;

//D
int main(){
string s; cin>>s;
string t; cin>>t;

int ans = 0;
for(int i=0;i<3;i++){
  if(s[i] == t[i]) ans++;
}
cout<<ans<<endl;
    return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  cin >> N;
  int A[30] ={}; int B[30]={}; int C[30]={};
  for (int i = 1; i <= N; i++) cin >> A[i];
  for (int i = 1; i <= N; i++) cin >> B[i];
  for (int i = 1; i < N; i++) cin >> C[i];
  int ans = 0;
  for (int i = 1; i <= N; i++) ans += B[i];
  for (int i = 1; i < N; i++) {
    if (A[i+1]==A[i]+1){
      ans += C[A[i]];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
n1 = int(input())
s = (input()).split()
n2 = int(input())
t = (input()).split()
m = []

for i in range(0, n2):
      key = t[i]
      for j in range(0, n1):
            if s[j] == t[i]:
                  m.append(s[j])
                  break
print(len(m))

Measured memory_bytes: 8188