akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  int a=0;
  int b=1000000;
  cin >> n;
  int p[n];

  for(int i=0; i<n; i++){
    cin >> p[i];
    if(b>=p[i]){a++; b=p[i];}
  }
  cout << a << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int ans[500][500];

void func(int level, vector<int>& v){

    if((int)v.size() <= 1){
        return;
    }

    if((int)v.size() == 2){
        ans[v[0]][v[1]] = level;
        return;
    }

    vector<int> l;
    vector<int> r;

    for(int i = 0; i < (int)v.size(); i++){
        if(i % 2 == 0){
            l.push_back(v[i]);
            for(int j = 0; j < (int)v.size(); j++){
                if(j % 2 == 1){
                    int big = max(v[i], v[j]);
                    int small = min(v[i], v[j]);
                    ans[small][big] = level;
                }
            }
            
        }
        else{
            r.push_back(v[i]);
        }
    }

    func(level + 1, l);
    func(level + 1, r);

}

int main(){

    int N;
    cin >> N;

    vector<int> v(N);
    for(int i = 0; i < N; i++){
        v[i] = i;
    }

    func(1, v);

    for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j < N; j++){
            cout << ans[i][j];
            if(j == N - 1){
                cout << endl;
            }
            else{
                cout << " ";
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b;
	c = b/a;
	c = c*a;
	if(c == b)
	{
		cout << a+b;
	}else{
		cout << b-a;
	}
	return 0;
}
	 


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using V = vector<int>;
using VV = vector<V>;

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
//~ int A = (1<<2) | (1<<3) | (1<<5) | (1<<7);
//~ for (int bit=A; ; bit=(bit-1)&A){
//~ if (!bit) break;
//~ }
int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
//~ int n=5;
//~ int k=3; // nCkの組み合わせ、ただしk=0には対応してない
//~ int bit=(1<<k)-1; // 1000 -> 0111
//~ for(; bit < (1<<n); bit=nex_combination(bit){
//~ }
bool isPrime(int a) {
    if (a == 2) return true;
    if (a <= 1 || a % 2 == 0) return false;

    for (int i = 3; i * i <= a; i += 2) {
        if (a % i == 0) return false;
    }
    return true;
}
//~ vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
vector<int> aaa;
// index が条件を満たすかどうか
bool isOK(int index, int key) {
    if (aaa[index] >= key)
        return true;
    else
        return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
    int ng = -1;  //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok =
        (int)aaa
            .size();  // 「index =
                      // a.size()-1」が条件を満たさないこともあるので、初期値は
                      // a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//~ int v[100100];
//~ int INF = 1 << 30;
//~ vector<vector<int>> dp(310, vector<int>(310));
//~ ll dp[110][100100];
//~ vector<int> dp(100100, 0));

//~ int seen[110];
//~ int ans[110][2];
//~ ll MOD = 1e9 + 7;

int main() {
    int n;
    cin >> n;

    int ans;
    vector<int> d(n);
    rep(i, n) cin >> d[i];

    sort(d.begin(), d.end());
    ans = d[n / 2] - d[(n / 2) - 1];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3772
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

long long int gcd(long long int a, long long int b) {
    if(a<b) {
        long long int tmp=a;
        a=b;
        b=tmp;
    }

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

int main() {
    int N;
    long long int X;
    cin >> N >> X;
    
    vector<long long int> vec;
    vec.push_back(X);
    
    long long int x;
    for(int i=0; i<N; i++) {
        cin >> x;
        vec.push_back(x);
    }
    
    sort(vec.begin(), vec.end());
    
    long long int ggg = vec[1]-vec[0];
    for(int i=0; i<N; i++) {
        ggg = gcd(ggg, vec[i+1]-vec[i]);
    }
    
    cout << ggg << endl;

    return 0;
    
}

Measured memory_bytes: 1400
#include <iostream>
using namespace std;

int b[10], l, r;

void check(){
    l = r = 0;
    int i;
    for(i = 0; i < 10; i++){
        if( b[i] < l && b[i] < r ) break;
        else if( b[i] < l ){
            r = b[i];
        }else if( b[i] < r ){
            l = b[i];
        }else if( l < r ){
            r = b[i];
        }else{
            l = b[i];
        }
    }
    if( i == 10 ){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

int main(){
    int n;
    cin >> n;
    while(n-- > 0){
        for(int i = 0; i < 10; i++){
            cin >> b[i];
        }
        check();
    }
    return 0;
}

Measured memory_bytes: 1152
N,K = map(int, input().split())
AD = []
D = []
A = []
for i in range(K):
    D_temp = input()
    A_temp = input().split()
    AD.append([[D_temp],[A_temp]])
    D.append(D_temp)
    for i2 in A_temp:
        A.append(i2)
print(N - len(set(A)))


Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<bool> nn(n);
  bool num1 = false;
  
  int count = 0;
  rep(i,n){
    int t;
    cin >> t;
    if(t==1)num1 = true;
    if((!nn[0] && t==1) || (!nn[t-1] && t>1 && nn[t-2])) nn[t-1]=true;
    else count ++;
  }
  if(!num1)cout << -1 << endl;
  else cout << count << endl;
  
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define INF 1LL<<60
#define pi 3.14159265358979323846
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

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

    if(!(a%2 && b%2 && c%2)){cout<<0<<endl;return 0;}

    ll MIN=min(a*b,min(b*c,c*a));

    cout<<MIN<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC target("sse2")
 
    #include <bits/stdc++.h>
    #include <vector> 
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace std;
 
    #define int         long long
    #define ll          long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         vector<pii>
    #define mi          map<int,int>
    #define mii         map<pii,int>
    #define mp          make_pair
    #define all(a)      (a).begin(),(a).end()
    #define FF           first
    #define SS           second
    #define sz(x)       (int)x.size()
    #define endl        '\n'
    #define rep(i,a,b)  for(int i=a;i<b;i++)
     ll hell=1000000007;



   
  
    int solve(){  
      
          int n,x,m;
          cin>>n>>x>>m;
          int sum=0;
          int a[m+1]={0},k=0;
          vi val;
          while(true)
          {  
            if(a[x]==1)break;
            sum+=x;
            k++;
            if(k==n)
                return cout<<sum<<endl,0;
            val.pb(x);
            a[x]=1;
            x=(x*x)%m;
          }
          n-=k;
          int ans=sum;
          sum=0;
          val.clear();
          memset(a,0,sizeof(a));

            while(true)
          {  
            if(a[x]==1)break;
            sum+=x;
            k++;
            if(k==n)
                return cout<<sum<<endl,0;
            val.pb(x);
            a[x]=1;
            x=(x*x)%m;
          }



          int n1=val.size();
          ans+=sum*(n/n1);
          n%=n1;
          rep(i,0,n)ans+=val[i];
          cout<<ans<<endl;




     return 0;
        
        }


    signed main()
    {       


 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0); 
 
    int t=1,k=1;                                                                                                                  
    //cin>>t;
   
    while(t--)
    {
     
     // cout<<"Case #"<<k++<<": ";
     solve();
     //cout<<endl;
    }
    return 0;
    } 

Measured memory_bytes: 4612
#import collections
S = input()
if int(S[:4]) <2019 or (int(S[:4]) ==2019 and int(S[5:7])<4) or (int(S[:4]) ==2019 and int(S[5:7])==4 and int(S[-2:])<=30):
    print('Heisei')
else :
    print('TBD')

Measured memory_bytes: 3060
import java.util.Scanner;

class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int time = sc.nextInt();
		int c[] = new int[n];
		int t[] = new int[n];
		int min = -1;
		for (int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
			t[i] = sc.nextInt();
			if (t[i] <= time && (c[i] < min || min == -1))
				min = c[i];
		}
		System.out.println(min==-1 ? "TLE\n" : min);
	}
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  if ((N * A) >= B) {
    cout << B << endl;
  }
    
  if ((N * A) < B) {
      cout << N * A << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
	int i,len,cnt=0;
  char s[101];
  scanf("%s",s);
  len=strlen(s);
  // printf("%d\n", len);
  for(i=0;i<len/2;i++){
    if(s[i]!=s[len-i-1]){
      cnt++;
    }
  }
  printf("%d\n",cnt );
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,M,Q;
    cin>>N>>M>>Q;
    int A[509][509];
    int B[509][509];
    int s,g;
    for(int i=1;i<=M;i++){
        cin>>s>>g;
        A[s][g]+=1;
    }
    for(int i=1;i<=505;i++){
        for(int j=1;j<=505;j++){
            B[i][j]=B[i][j-1]+A[i][j];
        }
    }
    for(int i=1;i<=Q;i++){
        cin>>s>>g;
        int ans=0;
        for(int j=s;j<=g;j++){
            ans+=B[j][g]-B[j][s-1];
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 2944
import math
n, d = list(map(int, input().split()))
x = []
y = []
for _ in range(n):
    xi, yi = list(map(int, input().split()))
    x.append(xi)
    y.append(yi)
def distance(p, q):
    return math.sqrt(p**2 + q**2)
answer = 0
for i in range(n):
    if distance(x[i], y[i]) <= d:
        answer += 1
print(answer)

Measured memory_bytes: 24948
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;
ll n,m;
ll go(ll x)
{
	ll ans=0;
	for(int i=1;i<=x;i++)
	{
		ll a;
		cin>>a;
		(ans+=(i-1)*a-(x-i)*a)%=mod;
	}
	return ans;
}
int main()
{  fast
cin>>n>>m;
ll x=go(n)%mod;
ll y=go(m)%mod;
cout<<x*y%mod;
}


Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int i;
	for (i = 1; i < 10; i++) {
		printf("%dx1=%d\n%dx2=%d\n%dx3=%d\n%dx4=%d\n%dx5=%d\n%dx6=%d\n%dx7=%d\n%dx8=%d\n%dx9=%d\n",i, 1 * i,i, 2 * i,i, 3 * i,i, 4 * i,i, 5 * i,i, 6 * i,i, 7 * i,i, 8 * i,i, 9 * i);
	}
	return 0;
}

Measured memory_bytes: 524
import sys

s = list(input())
t = list(input())

if s == t: print(0), sys.exit()

"""
cnt = 0
for i in range(len(s)):
    if t[i] != s[i]:
        # t[i] = s[i]  # いらない
        cnt += 1
print(cnt)
"""

#  zip関数での別解
res = len([1 for i, j in zip(s, t) if i != j])
print(res)

Measured memory_bytes: 13644
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> xy_t;

xy_t P[4];

double cross_product(xy_t a, xy_t b){
    return (conj(a)*b).imag();
}

int main(){
    while(true){
        for(int i = 0; i < 4; i++){
            double x, y; cin >> x >> y;
            P[i] = xy_t(x, y);
        }
        if(!cin) break; //
        double a, b, c; //点Pを中心から三角形の各頂点に伸びるベクトルが作る小三角形の符号付き面積×2を格納
        a = cross_product(P[0]-P[3], P[1]-P[3]);
        b = cross_product(P[1]-P[3], P[2]-P[3]);
        c = cross_product(P[2]-P[3], P[0]-P[3]);

        cout << (((a>0 && b>0 && c>0) || (a<0 && b<0 && c<0))? "YES": "NO") << endl;
    }
}


Measured memory_bytes: 3132
n = int(input())

lis = list(map(int, input().split()))

tmp = lis[0]
for i in range(1,n):
    if tmp < lis[i]:
        tmp = lis[i] -1
    elif tmp == lis[i]:
        tmp = lis[i]
    else:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 14224
using System;
using System.Linq;
using System.Collections.Generic;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());

            var total = 0L;
            for(var i = 1L; i <= n; i++){
                for(var j = 1L; j <= n; j++){
                    for(var k = 1L; k <= n; k++){
                        var x = Gcd(i, j);
                        total += Gcd(x, k);
                    }
                }
            }

            Console.WriteLine(total);
        }

        static long Gcd(long m, long n)
        {
	        while (m % n != 0){
        		var temp = n;
		        n = m % n;
		        m = temp;
	        }
        	return n;
        }
    }
}


Measured memory_bytes: 27544
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)

dp = [[[0.0 for _ in range(n+1)] for _ in range(n+1)] for _ in range(n+1)]

for z in range(c[3] + 1):
    for y in range(c[2]+1 + c[3] - z):
        for x in range(n+1 - z - y):
            if x + y + z == 0:
                continue
            ret = 0.0
            if x > 0:
                ret += dp[x-1][y][z] * x
            if y > 0:
                ret += dp[x+1][y-1][z] * y
            if z > 0:
                ret += dp[x][y+1][z-1] * z
            dp[x][y][z] = (ret + n) / (x + y + z)

print(dp[c[1]][c[2]][c[3]])


Measured memory_bytes: 259212
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int s = sc.nextInt();
		int w = sc.nextInt();

		if ( s>w ) {
			System.out.println("safe");
		} else {
			System.out.println("unsafe");
		}
	}
}

Measured memory_bytes: 35768
#include <iostream>

using namespace std;

int main(){

int n;
int ac = 0;
int wa = 0;
int tle = 0;
int re = 0;

cin>>n;

string arr [n];

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

for (int i = 0; i<n; i++){
    if(arr[i] == "AC"){
        ac++;
    } else if(arr[i] == "WA"){
        wa++;
    } else if(arr[i] == "TLE"){
        tle++;
    } else if(arr[i] == "RE"){
        re++;
    }
}

cout<<"AC x "<<ac <<endl;

cout<<"WA x "<<wa <<endl;

cout<<"TLE x "<<tle <<endl;

cout<<"RE x "<<re <<endl;

    return 0;
}

Measured memory_bytes: 6728
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
//using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dh[8] = {0, 0, 1, 1, 1, -1, -1, -1};
const int dw[8] = {1, -1, 0, 1, -1, 0, 1, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
using Graph = vector<vector<int>>;
Graph G;
  
/*------------------------------------------------------------------*/
int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> abs_a(n);
    rep(i, n){
        cin >> a[i];
        abs_a[i] = abs(a[i]);
    }
    vector<pair<int,int>> ans;
    bool hugou; // pos : true, neg : false
    bool abs_max_hugou;
    ll abs_max = 0;
    int pos;

    for(int i = 0; i < n; i++){
        if(abs_max < abs(a[i])){
            abs_max = abs(a[i]);
            pos = i;
        }
    }
    if(a[pos] > 0) abs_max_hugou = true;
    else abs_max_hugou = false;
    if(*max_element(a.begin(), a.end()) == *min_element(a.begin(), a.end())){
        cout << 0 << endl;
        return 0;
    }
    if(*max_element(a.begin(), a.end()) <= 0){
        for(int i = n - 1; i >= 1; i--){
            ans.emplace_back(i + 1, i);
        }
        cout << ans.size() << endl;
        for(auto it : ans){
            cout << it.first << " " << it.second << endl;
        }
        return 0;
    }
    if(*min_element(a.begin(), a.end()) >= 0){
        for(int i = 1; i < n; i++){
            ans.emplace_back(i, i + 1);
        }
        cout << ans.size() << endl;
        for(auto it : ans){
            cout << it.first << " " << it.second << endl;
        }
        return 0;
    }
    

    for(int i = 0; i < n; i++){
        ans.emplace_back(pos + 1, i + 1);
    }
    if(abs_max_hugou){
        for(int i = 1; i < n; i++){
            ans.emplace_back(i, i + 1);
        }
    }else{
        for(int i = n - 1; i >= 1; i--){
            ans.emplace_back(i + 1, i);
        }
    }
    cout << ans.size() << endl;
    for(auto it : ans){
        cout << it.first << " " << it.second << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      String s = sc.next();
      String ans = "No";
      if(s.charAt(2)==s.charAt(3)&&s.charAt(4)==s.charAt(5)){
        ans = "Yes";
      }
      System.out.println(ans);
      
    }
}


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


int main(){
    int n, x;
    while(cin >> n >> x){
      if(n == 0 && x == 0) break;
        int count = 0;
        for(int i=1; i<=n ; i++){
            for(int j=i+1; j<=n; j++){
                for(int k=j+1; k<=n; k++){
                    if(i+j+k == x) count++;
                }
            }
        }
     cout << count << endl;

    }
}


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

def cali(string):
    lists=[0 for i in range(n)]
    lists[0]=string[0]
    lists[1]=string[1]
    flag1=False
    flag2=False
    for  _ in range(2,n):
        if s[_-1]=="o" and lists[_-2]=="W" and lists[_-1]=="W":
            lists[_]="S"
            
        elif s[_-1]=="o" and lists[_-2]=="W" and lists[_-1]=="S":
            lists[_]="W"
            
        elif s[_-1]=="o" and lists[_-2]=="S" and lists[_-1]=="W":
            lists[_]="W"
            
        elif s[_-1]=="o" and lists[_-2]=="S" and lists[_-1]=="S":
            lists[_]="S"        
            
        elif s[_-1]=="x" and lists[_-2]=="W" and lists[_-1]=="W":   
            lists[_]="W"
            
        elif s[_-1]=="x" and lists[_-2]=="W" and lists[_-1]=="S":
            lists[_]="S"
        
        elif s[_-1]=="x" and lists[_-2]=="S" and lists[_-1]=="W":
            lists[_]="S"
            
        elif s[_-1]=="x" and lists[_-2]=="S" and lists[_-1]=="S":   
            lists[_]="W"
    

    if s[0]=="o" and lists[0]=="W":
        if lists[1]!=lists[-1]:
            flag1=True

    elif s[0]=="o" and lists[0]=="S":
        if lists[1]==lists[-1]:
            flag1=True
     
    
    elif s[0]=="x" and lists[0]=="W":
        if lists[1]==lists[-1]:
            flag1=True

    elif s[0]=="x" and lists[0]=="S":
        if lists[1]!=lists[-1]:
            flag1=True

    if s[-1]=="o" and lists[-1]=="W":
        if lists[-2]!=lists[0]:
            flag2=True
    elif s[-1]=="o" and lists[-1]=="S":
        if lists[-2]==lists[0]:
            flag2=True

    elif s[-1]=="x" and lists[-1]=="W":
        if lists[-2]==lists[0]:
            flag2=True
    elif s[-1]=="x" and lists[-1]=="S":
        if lists[-2]!=lists[0]:
            flag2=True
    if flag1 and flag2:
         return lists
    else:
          return 0
        

stri=""
a=cali("WW")
b=cali("WS")
c=cali("SW")
d=cali("SS")

if a!=0:
    for i in range(n):
        stri+=a[i]
    print(stri)

elif b!=0:
        for i in range(n):
            stri+=b[i]
        print(stri)
        
elif c!=0:
        for i in range(n):
            stri+=c[i]
        print(stri)
        
elif d!=0:
        for i in range(n):
            stri+=d[i]
        print(stri)
else:
    print("-1")
    

Measured memory_bytes: 5192
import java.io.*;

class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try{
			String line = reader.readLine();
			int A = Integer.parseInt(line);
			line = reader.readLine();
			int B = Integer.parseInt(line);
			int result = 6 - (A + B);
			System.out.println(result);
		}catch(NumberFormatException e){
			e.printStackTrace();
			System.exit(0);
		}catch(IOException e){
			e.printStackTrace();
			System.exit(0);
		}
	}
}

Measured memory_bytes: 21460
#include <stdio.h>
 
int main(int argc, char *argv){
  int n, u, k, v, g[100][100] = {};
  int i,j;
 
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d%d", &u, &k);
    for(j = 0; j < k; j++){
      scanf("%d", &v);
      g[u-1][v-1] = 1;
    }
  }
  for(i = 0; i < n; ++i){
    for(j = 0; j < n; ++j){ 
      printf(j != 0 ? " %d" : "%d", g[i][j]);
    }
    printf("\n");
  }
 
  return 0;
}

Measured memory_bytes: 648
// E - Coprime
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
vi A;
int N;

int gcd_all(vi &A){int g = 0; for(int a:A) g = gcd(g, a);return g;}

bool is_pairwise(){
	#define MAX_A 1'000'001
	vi C(MAX_A, 0);
	for(int a:A) C[a]++;
	int c = 0;
	for(int j=2; j<MAX_A; j+=2) c += C[j];
	if(c > 1) return false;
	for(int i=3; i<MAX_A; i+=2){
		int c = 0;
		for(int j=i; j<MAX_A; j+=i) c += C[j];
		if(c > 1) return false;
	}
	return true;
}

int solve(){
	if(is_pairwise()) return 0;
	if(gcd_all(A) == 1) return 1;
	return 2;
}

int main(){
	cin>>N;
	A.resize(N); for(int i=0; i<N; ++i) cin>>A[i];
	cout<< vector<string>{"pairwise","setwise","not"}[solve()] <<" coprime\n";
}


Measured memory_bytes: 11056
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge>>G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


ll n, k[100005], mon, ans;
set<ll>s;
vector<ll>v;
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
		mon ^= k[i];
		s.insert((k[i] ^ (k[i] - 1)));
	}
	for (auto i : s) { v.push_back(i); }

	sort(rall(v));

	for (auto i : v) {
		if (mon > (mon ^ i)) {
			mon ^= i;
			++ans;
		}
	}

	if (mon == 0) { cout << ans << endl; return 0; }

	cout << -1 << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    int n;
    cin >> n;
    map<string,int> mp;
    For(i,0,n){
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl; 
    cout << "RE x " << mp["RE"] << endl; 
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
int i,j;

typedef struct{
 char design;
  char number;
}Card;

void bubble(Card A[],int n){
  Card t;
  for(i=0;i<n;i++){
    for(j=n-1;j>=i+1;j--){
      if(A[j].number<A[j-1].number){
	t=A[j];
	A[j]=A[j-1];
	A[j-1]=t;
      }
    }
  }
}
void select(Card A[],int n){
  int min;
  Card t;
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(A[j].number<A[min].number)min=j;//????°??????¨??????????´???°  
    }
    t=A[i];
    A[i]=A[min];
    A[min]=t;
  }
}

int stable(Card c1[],Card c2[],int n){
  for(i=0;i<n;i++){
    if(c1[i].design!=c2[i].design)return -1;
  }

  return 1;
  
}

void print(Card A[],int n){

  for(i=0;i<n;i++){
    printf("%c%c",A[i].design,A[i].number);
    if(i!=n-1)printf(" ");
  }
      printf("\n");
}

int main(){
  int n;
  int i;
  Card c1[100],c2[100];
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf(" %c%c", &c1[i].design, &c1[i].number);
    c2[i].design=c1[i].design;
    c2[i].number=c1[i].number;
  }

  bubble(c1,n);
  select(c2,n);

  print(c1,n);
  printf("Stable\n");
  print(c2,n);

  if(stable(c1,c2,n)==1)printf("Stable\n");
  else printf("Not stable\n");
  return 0;
}



  

  

Measured memory_bytes: 612
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define INF (1LL<<59)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed); cerr.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed); cerr.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	int n,m;
	cin>>n>>m;
	vector<PII> vx;
	if(m & 1)
	{	
		if(m > 1)
		{	
			for(int i=1;i<(m+1)/2;i++)
			vx.pb({i, m-i+1});
		}
		for(int i=1;i<=(m+1)/2;i++)
		vx.pb({m+i, 2*m+2-i});
	}
	else
	{
		for(int i=1;i<=(m+1)/2;i++)
		vx.pb({i, m+2-i});
		for(int i=1;i<=(m+1)/2;i++)
		vx.pb({m+1+i, 2*m+2-i});	
	}		
	for(auto &&u : vx)
	cout<<u.ff<<" "<<u.ss<<"\n";
	return;	
}

int main(void)
{
	FLASH();
	//freopen("cowjog.in", "r", stdin);
	//freopen("cowjog.out", "w", stdout);
	int T;
	T = 1;

#ifndef ONLINE_JUDGE
	time_t time_t1, time_t2;
	time_t1 = clock();
#endif

	//cin>>T;
	while(T--)
	solve(T);

#ifndef ONLINE_JUDGE
	time_t2 = clock();
	SETF();
	cerr<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
	UNSETF();
#endif

	return 0;
}

Measured memory_bytes: 4272
//#include "for_cp.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
using namespace std;
#define FOR(i,m,n) for(int i = m; i < n; i++)

int main()
{
	int H, W;
	while (1)
	{
	cin >> H >> W;
	if (H == 0 && W == 0)break;
	FOR(i, 0, H)
	{
		FOR(j, 0, W)
	{
		if (i % 2 == 0 && j % 2 == 0)
		{
			cout << "#";
			if (j == W - 1)cout << endl;
		}
		else if (i % 2 == 0 && j % 2 != 0)
		{
			cout << ".";
			if (j == W - 1)cout << endl;
		}
		else if (i % 2 != 0 && j % 2 == 0)
		{
			cout << ".";
			if (j == W - 1)cout << endl;
		}
		else if (i % 2 != 0 && j % 2 != 0)
		{
			cout << "#";
			if (j == W - 1)cout << endl;
		}
	}
	}
	cout << endl;
	}
}

Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      String astr = sc.next();
      StringBuffer str = new StringBuffer(astr);
      int q = sc.nextInt();
      while(sc.hasNext()) {
        String program = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        switch (program) {
          case "print":
            System.out.println(str.substring(a,b+1));
            break;
          case "reverse":
            String asubstr = str.substring(a,b+1);
            StringBuffer substr = new StringBuffer(asubstr);
            substr = substr.reverse();
            str = str.delete(a,b+1);
            str = str.insert(a,substr);
            break;
          case "replace":
            String p = sc.next();
            str = str.delete(a,b+1);
            str = str.insert(a,p);
            break;
        }
      }   
    }
}


Measured memory_bytes: 29532
#include "bits/stdc++.h"
using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP(a, b) make_pair(a, b)
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n, m;
vector<pi> s;
int dp[1024];
using namespace std;
using namespace std;
int main() {
 char c1[2],c2[2];
 int h,m,ic[2],f[2],i,k;
 int g[7][7]={{0,300,500,600,700,1350,1650}, {300,0,350,450,600,1150,1500}, {500,350,0,250,400,1000,1350},
 {600,450,250,0,250,850,1300}, {700,600,400,250,0,600,1150}, {1350,1150,1000,850,600,0,500},{1650,1500,1350,1300,1150,500,0}};
 while(true) {
     for (i=0;i<2;i++) {
         cin >> ic[i];
         if (ic[i]==0) return 0;
         ic[i]--;
         cin >> c1 >> c2;
         h=(c1[0]-'0')*10+(c1[1]-'0');
         m=(c2[0]-'0')*10+(c2[1]-'0');
         f[i]=(h==17 && m>29) || (h==18) || (h==19 && m<31);  
         }
     k=g[ic[0]][ic[1]];
     if(k<1350) 
         if (f[0]+f[1]>0) k=k % 100>0 ? k/2+25:k/2;
     cout << k << endl;
 }
return 0;
 }

Measured memory_bytes: 3008
from collections import Counter


class UnionFind:
    def __init__(self, node_size):
        self.node_size = node_size
        self.parent = [i for i in range(self.node_size)]    # parent's number
        self.rank = [0 for i in range(self.node_size)]
        self.size = [1 for i in range(self.node_size)]

    # find root of x
    def root(self, x):
        if self.parent[x] == x:    # x is a root
            return x
        else:
            self.parent[x] = self.root(self.parent[x])    # path compression
            return self.parent[x]

    # judge whether x is connected to y. returns boolian.
    def is_connected(self, x, y):
        return self.root(x) == self.root(y)

    # connects x to y
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
            else:
                self.parent[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
            self.size[x] += self.size[y]
            self.size[y] = self.size[x]

    def get_size(self, x):
        x = self.root(x)
        return self.size[x]


def main():
    N, M = map(int, input().split())    # N islands, M bridges
    bridge_list_a = [0 for i in range(M)]
    bridge_list_b = [0 for i in range(M)]
    for i in range(M):
        bridge_list_a[i], bridge_list_b[i] = map(int, input().split())
    bridge_list_a.reverse()
    bridge_list_a = [a - 1 for a in bridge_list_a]
    bridge_list_b.reverse()
    bridge_list_b = [b - 1 for b in bridge_list_b]

    Islands = UnionFind(N)

    inconvenience = N * (N - 1) // 2
    ans = [inconvenience]

    for ai, bi in zip(bridge_list_a, bridge_list_b):
        if not Islands.is_connected(ai, bi):
            inconvenience -= Islands.get_size(ai) * Islands.get_size(bi)

        ans.append(inconvenience)
        Islands.unite(ai, bi)

    ans.reverse()
    for inconvenience in ans[1:]:
        print(inconvenience)


if __name__ == "__main__":
    main()


Measured memory_bytes: 22768
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int N = 1e5+10;
int a[N];
int main(){
    ll a, b ,n;
    cin >> a >> b >> n;
    n = min(n,b-1);
    cout << a*n / b << '\n';
    return 0;
}

Measured memory_bytes: 3596
n, k = map(int, raw_input().split())

l = map(int, raw_input().split())
flag = False

while flag == False:
	flag = True
	t = n
	while t > 0:
		m = t % 10
		if m in l:
			flag = False
			break
		t = t / 10
	n += 1

print n - 1

Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
int mod = 1000000007;
#define ll long long


int main() {
    ll x,ans=100;
    cin>>x;
    rep(i,3800) {
        if(ans>=x) {
            cout << i <<endl;
            return 0;
        }
        ans+=ans/100;
    }
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 1001
  
int main(void){
  int i,j,n,z[N][N],m,k,l;
  char X[N],Y[N];
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    X[0]='0';
    Y[0]='0';

    scanf("%s%s",X+1,Y+1);
 
  m=strlen(X+1);
  k=strlen(Y+1);
      
  for(l=0;l<=m;l++){
    z[i][0]=0;
  }
  
  for(j=0;j<=k;j++){
    z[0][j]=0;
  }
    
  for(l=1;l<=m;l++){
    for(j=1;j<=k;j++){

      if(X[l]==Y[j]){
         z[l][j]=z[l-1][j-1]+1;
     }
      else if(z[l-1][j]>=z[l][j-1]){
         z[l][j]=z[l-1][j];
     }
      else{
         z[l][j]=z[l][j-1];
      }
    }
  }
  printf("%d\n",z[l-1][j-1]);
 }

  return 0;
}

Measured memory_bytes: 4524
import java.util.Scanner;

public class Main { //クラス名はMain
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
		int a=scanner.nextInt();
		int b=scanner.nextInt();
		int c=scanner.nextInt();
		if(a+b+c<=21) {
			System.out.print("win");
		}
		else if(a+b+c>21) {
			System.out.print("bust");
		}
    }
}

Measured memory_bytes: 23764
import sys
sys.setrecursionlimit(10**8)

def find_path(now, par):
    if now == n - 1:
        path.append(n - 1)
        return True
    for to in g[now]:
        if to == par: continue
        if find_path(to, now):
            path.append(now)
            return True
    return False

def dfs1(now, par, color):
    color[now] = "b"
    for to in g[now]:
        if to == par: continue
        if color[to] == "w": continue
        dfs1(to, now, color)

def dfs2(now, par, color):
    color[now] = "w"
    for to in g[now]:
        if to == par: continue
        if color[to] == "b": continue
        dfs2(to, now, color)

n = int(raw_input())
g = [[] for _ in xrange(n)]
for i in xrange(n - 1):
    a, b = map(int, raw_input().split())
    a -= 1; b -=1
    g[a].append(b)
    g[b].append(a)
path = []
find_path(0, -1)
path.reverse()
color = ["bl"] * n
color[0] = "b"
color[n - 1] = "w"
j = 1
k = len(path) - 2
for i in xrange(1, len(path) - 1):
    if i % 2 == 1:
        v = path[j]
        color[v] = "b"
        j += 1
    else:
        v = path[k]
        color[v] = "w"
        k -= 1
dfs1(0, -1, color)
dfs2(n - 1, -1, color)
cntf = 0
cnts = 0
for i in xrange(n):
    if color[i] == "b":
        cntf += 1
    else:
        cnts += 1
if cntf > cnts:
    print "Fennec"
else:
    print "Snuke"


Measured memory_bytes: 151836
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
d.sort()
t.sort()
j = 0
for i in range(m):
    while j<n and d[j]<t[i]:
        j += 1
    if j>=n or d[j]!=t[i]:
        print("NO")
        break
    else:
        j += 1
else:
    print("YES")

Measured memory_bytes: 117968
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
 
using namespace std;

int n, q;
vector<int> edge[200005];
lol sum[200005];
bool isvisited[200005];

void count(int p ,int x){
  if(isvisited[p]) return;
  sum[p] += x;
  isvisited[p] = true;
  rep(i, edge[p].size() ){
    count(edge[p][i] , sum[p]);
  }
  return;
}

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

  memset(sum,0,sizeof(sum));
  cin >> n >> q;
  rep( i , n - 1 ){
    int a, b;
    cin >> a >> b;
    edge[a].pu(b);
    edge[b].pu(a);
  }
  rep( i , q ){
    int p, x;
    cin >> p >> x;
    sum[p] += x;
  }
  count( 1 , 0 );
  reps( i , n - 1 ){
    cout << sum[i] << " ";
  }
  cout << sum[n] << '\n';
  
  return 0;
}


Measured memory_bytes: 24448
<?php 
    fscanf(STDIN, "%d %d %d %d %d", $x1, $x2, $x3, $x4, $x5);

    if ($x1 == 0) {
        echo 1;
    }
    if ($x2 == 0) {
        echo 2;
    }
    if ($x3 == 0) {
        echo 3;
    }
    if ($x4 == 0) {
        echo 4;
    }
    if ($x5 == 0) {
        echo 5;
    }

Measured memory_bytes: 16144
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

int cost[5002];
short pokpos[1002][1002];
char stage[1002][1002];

struct Pos{
	int x;
	int y;
};

class Data{
public:
	int cost;
	int got;
	int x;
	int y;
	Data() : got(0),cost(0),x(0),y(0){}
	Data(int _c,int _g,int _x,int _y){
		cost = _c;
		got = _g;
		x = _x;
		y = _y;
	}
	bool operator>(const Data& d) const{
		return cost > d.cost;
	}
	bool operator<(const Data& d) const{
		return cost < d.cost;
	}
};

void clear( priority_queue<Data,vector<Data>,greater<Data> > &q )
{
	priority_queue<Data,vector<Data>,greater<Data> > empty;
	swap( q, empty );
}

int main(){
	int w,h;
	while(~scanf("%d %d",&w,&h)){
		if(w==h && h==0) break;
		int sx,sy;
		int gx,gy;
		int count = 0;
		map<int,vector<P> > pokemon;

		Pos pos[5002];
		for(int y=0;y<h;y++){
			char buf[1024];
			scanf("%s",buf);
			for(int x=0;x<w;x++){
				stage[y][x] = buf[x];
				if(buf[x]=='S'){
					sx = x;
					sy = y;
					pokpos[y][x]=count;
					pos[count].x = x;
					pos[count].y = y;
					count++;
				}

				else if(buf[x]=='G'){
					gx = x;
					gy = y;
					pokpos[y][x]=count;
					pos[count].x = x;
					pos[count].y = y;
					count++;
				}
				else if(isdigit(buf[x])){
					pokemon[buf[x]-'1'].push_back(P(x,y));
					pokpos[y][x]=count;
					pos[count].x = x;
					pos[count].y = y;
					count++;
				}
			}
		}


		int res_pk=-1;
		int res_step = INF;


		for(int pk=0;pk<=4;pk++){
			priority_queue<Data,vector<Data>,greater<Data> > que;

			que.push(Data(0,pk,sx,sy));
			memset(cost,0x3f,sizeof(cost));
			cost[pokpos[sy][sx]] = 0;

			while(!que.empty()){
				Data d = que.top();
				que.pop();

				int target = (d.got + 1) % 5;

				if(target == pk){
					int c = abs(gx - d.x) + abs(gy - d.y);
					if(res_step <= d.cost + c) continue;
					res_step = d.cost + c;
					res_pk = pk;
				}

				else{

					int size = pokemon[target].size();
					for(int i=0;i<size;i++){
						int dx = pokemon[target][i].first;
						int dy = pokemon[target][i].second;

						int c = abs(dx - d.x) + abs(dy - d.y);             	

						if(cost[pokpos[dy][dx]] <= d.cost + c) continue;

						cost[pokpos[dy][dx]] = d.cost + c;

						que.push(Data(d.cost+c,target,dx,dy));
					}
				}
			}
		}

		if(res_pk == -1) printf("NA\n");
		else printf("%d %d\n",res_pk+1,res_step);
	}
	return 0;
}

Measured memory_bytes: 4372
n = int(input())
s_list = [input() for _ in range(n)]
res_ab = 0
res_ba = 0
res_a = 0
res_b = 0
for s in s_list:
    res_ab += s.count('AB')
    if s[0]=='B' and s[-1]=='A':
        res_ba += 1
    elif s[0]=='B':
        res_a += 1
    elif s[-1] == 'A':
        res_b += 1

if res_ba == 0:
    print(res_ab+min(res_a,res_b))
else:
    if res_a+res_b > 0:
        print(res_ab+res_ba+min(res_a,res_b))
    else:
        print(res_ab+res_ba-1)


Measured memory_bytes: 44248
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



int N, M, Q;
int cnt[505][505];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> Q;
    rep(i, 0, M) {
        int L, R; cin >> L >> R;
        cnt[L][R]++;
    }
    rep(L, 1, N + 1) rep(R, 2, N + 1) cnt[L][R] += cnt[L][R - 1];
    rep(_, 0, Q) {
        int p, q; cin >> p >> q;
        int ans = 0;
        rep(L, p, q + 1) ans += cnt[L][q];
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}

ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}




int main() {
ll N;
  ll M;
    cin >>N>>M;
  vl a(N);
  rep(i,N) {
cin >>a.at(i);
  }
ll c=0;
  ll sum=0;
  rep(i,N) {
sum+=a.at(i);
  }

  if(N-sum<0) {
cout<<-1<<endl;
  }
else {
cout<<N-sum<<endl;
}

}
  

Measured memory_bytes: 11144
#include <bits/stdc++.h>
using namespace std;
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
  const char* delimiter = "";
  for(const auto& x:v) cout << exchange(delimiter, ",") << x;
  return os;
}
// ALDS1_10_C: 最長共通部分列 (LCS)
int32_t main(){
  size_t q; cin>>q;
  for(size_t p=0; p<q; ++p){
    string s,t; cin>>s>>t;
    vector<vector<size_t>> dp(s.size()+1,vector<size_t>(t.size()+1));
    // i=0
    for(auto&& x:dp[0]) x=0;
    for(size_t i=1; i<dp.size(); ++i){
      // j=0
      dp[i][0]=0;
      for(size_t j=1; j<dp[i].size(); ++j){
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        if(s[i-1]==t[j-1]) dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
      }
    }
    cout<<dp.back().back()<<endl;
  }
}



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

string s , t , u;
int a , b;

int main(){
    migmig
    cin >> s;
    for (int i = 0 ; i < s.size() ; i ++){
        cout << 'x';
    }


    return(0);
}


//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Measured memory_bytes: 256