akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int N,M,Q;
int prev[200000],next[200000];
bool used[200000];
int main(){
    scanf("%d%d%d",&N,&M,&Q);
    for(int i=0;i<N;i++){
        prev[i]=(i+N-1)%N;
        next[i]=(i+1)%N;
    }
    int cur=0;
    while(M--){
        int a;
        scanf("%d",&a);
        if(a&1){
            for(int i=0;i<a;i++)cur=prev[cur];
        }
        else {
            for(int i=0;i<a;i++)cur=next[cur];
        }
        used[cur]=true;
        prev[next[cur]]=prev[cur];
        next[prev[cur]]=next[cur];
        cur=next[cur];
    }
    while(Q--){
        int t;
        scanf("%d",&t);
        puts((used[t]?"0":"1"));
    }
    return 0;
}

Measured memory_bytes: 2924
//#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<pii,int> ppiii ;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
long long int MOD=1000000007;
ll mod=MOD;
ll modpow(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
#define SIZE 200005

int main(){
	string str;
	cin>>str;
	int n=0,w=0,s=0,e=0;
	if(str.find('N')!=string::npos)n++;
	if(str.find('W')!=string::npos)w++;
	if(str.find('E')!=string::npos)e++;
	if(str.find('S')!=string::npos)s++;
	//cout<<n<<w<<e<<s;
	if(n==s&&w==e){
		cout<<"Yes"<<endl;
	}else{cout<<"No"<<endl;
	}
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<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);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

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

  vector<ll> a(n),b(n);
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];

  ll ans=0;
  for(int d = 32; d >= 0; --d){
    REP(i,n) a[i] %= (1LL << (d + 1));
    REP(i,n) b[i] %= (1LL << (d + 1));
    sort(all(b));

    ll cnt = 0;
    ll cur = 1LL << d;
    REP(i,n){
      cnt += lower_bound(all(b), 4*cur-a[i]) - lower_bound(all(b), 3*cur-a[i]);
      cnt += lower_bound(all(b), 2*cur-a[i]) - lower_bound(all(b), cur-a[i]);
    }
    if(cnt % 2 == 1) ans += cur;
  }

  pl(ans)
  return 0;

}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
string S,T;
vector<int> A;
vector<int> B;
//=============================
void input()
{
    cin>>N>>M;

}
//=============================
void func(){}

//=============================
void solve()
{
    vector<int> v;
    while(M){
        v.push_back(M%10);
        M /= 10;
    }
    while(N){
        v.push_back(N%10);
        N /= 10;
    }
    int gk=0;
    rep(i,0,v.size()-1){
        gk += pow(10,i) * v[i];
    }

    bool ans=false;
    rep(i,1,gk/2){
        if (i*i==gk){
            ans=true;
            break;
        }
    }
    cout<<(ans ? "Yes" : "No")<<endl;

}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};



int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	vi x(n),y(n);
	vi c(n),d(n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
		c[i]=x[i],d[i]=y[i];
	}
	sort(c.begin(),c.end());
	c.erase(unique(c.begin(),c.end()),c.end());
	sort(d.begin(),d.end());
	d.erase(unique(d.begin(),d.end()),d.end());
	map<int,int> mp1,mp2;
	for(int i=0;i<c.size();i++) mp1[c[i]]=i;
	for(int i=0;i<d.size();i++) mp2[d[i]]=i;
	int h=c.size(),w=d.size();
	vvi a(h+1,vi(w+1));
	for(int i=0;i<n;i++) a[mp1[x[i]]+1][mp2[y[i]]+1]++;
	for(int i=1;i<=h;i++) for(int j=1;j<=w;j++){
		a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
	}
	for(int i=0;i<m;i++){
		int l,r,L,R;
		cin>>l>>r>>L>>R;
		l=lower_bound(c.begin(),c.end(),l)-c.begin();
		r=lower_bound(d.begin(),d.end(),r)-d.begin();
		L=upper_bound(c.begin(),c.end(),L)-c.begin();
		R=upper_bound(d.begin(),d.end(),R)-d.begin();
		cout<<a[L][R]-a[L][r]-a[l][R]+a[l][r]<<endl;
	}
}


Measured memory_bytes: 101280
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,P; cin>>N>>P;
  vii dp(N+1,vi(2));
  REP(i,1,N){
    int X; cin>>X;
    if(X%2==0){
      dp[i][0]=dp[i-1][0]*2;
      dp[i][1]=dp[i-1][1]*2;
      dp[i][0]++;
    }
    else{
      dp[i][0]=dp[i-1][1]+dp[i-1][0];
      dp[i][1]=dp[i-1][0]+dp[i-1][1];
      dp[i][1]++;
    }
  }
  dp[N][0]++;
  cout<<dp[N][P]<<endl;
  }


Measured memory_bytes: 256
n = gets.to_i
k = gets.to_i

k.times {
    a, b = gets.split.map(&:to_i)
    a -= 1
    b -= 1
    a = n - a - 1 if a > n / 2 
    b = n - b - 1 if b > n / 2 
    p [a, b].min % 3 + 1 
}

Measured memory_bytes: 6104
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

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

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> p(n);
  rep(i, n) cin >> p[i];
  rep(i, n) p[i] /= 2;

  ll lcm = p[0];
  for(int i=1;i<n;i++){
    lcm = calcLCM(lcm, p[i]);
  }
  if (lcm > m){
    cout << 0 << endl;
    return 0;
  }
  rep(i, n){
    if ((lcm / p[i]) % 2 == 0){
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = m / lcm;
  ans = (ans + 1) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main(){
	fast;
	ll n,k,r,s,p;
	string str;
	cin>>n>>k>>r>>s>>p;
	cin>>str;
	ll dp[3][n];
	memset(dp,0,sizeof(dp));
	for(int i=0;i<k;i++)
	{
		for(int j=i;j<n;j+=k)
		{
			if(i==j)
			{
				if(str[j]=='r')
				{
					dp[0][j]=0;
					dp[1][j]=0;
					dp[2][j]=p;
				}
				else if(str[j]=='s')
				{
					dp[0][j]=r;
					dp[1][j]=0;
					dp[2][j]=0;
				}
				else
				{
					dp[0][j]=0;
					dp[1][j]=s;
					dp[2][j]=0;
				}
				continue;
			}
            
            if(str[j]=='r')
				{
                
			for(int z=0;z<3;z++)
			{
				
					if(z==0)
					{
						dp[0][j]=max(dp[1][j-k],dp[2][j-k]);
					}
					else if(z==1)
					{
						dp[1][j]=max(dp[0][j-k],dp[2][j-k]);
					}
					else
					{
						dp[2][j]=p+max(dp[0][j-k],dp[1][j-k]);
					}
				}
            }
				else if(str[j]=='s')
				{
                    
                    for(int z=0;z<3;z++)
                    {
                    
                        if(z==0)
                        {
                            dp[0][j]=r+max(dp[1][j-k],dp[2][j-k]);
                        }
                        else if(z==1)
                        {
                            dp[1][j]=max(dp[0][j-k],dp[2][j-k]);
                        }
                        else
                        {
                            dp[2][j]=max(dp[0][j-k],dp[1][j-k]);
                        }
                    }
                }
                    else
                    {

                for(int z=0;z<3;z++)
                {

                        if(z==0)
                        {
                            dp[0][j]=max(dp[1][j-k],dp[2][j-k]);
                        }
                        else if(z==1)
                        {
                            dp[1][j]=s+max(dp[0][j-k],dp[2][j-k]);
                        }
                        else
                        {
                            dp[2][j]=max(dp[0][j-k],dp[1][j-k]);
                        }
                   }
			}
		}
	}
	ll ans=0;
	for(int i=n-1;i>=n-min(n,k);i--)
	{
		ll maxx = -INF;
		for(int z=0;z<3;z++)
		{
			maxx=max(maxx,dp[z][i]);
		}
		ans+=maxx;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 2768
// new day,new strength,new thougts
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define F first
#define S second
#define sz(c) int((c).size())
#define REP(i,n)  for(int i=0;i<int(n);i++)
#define REPD(i,n) for(int i=int(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);i++)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);i--)
#define all(s) (s).begin(),(s).end()
#define bit(num,i) ((num>>i)&1)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll inf=4e18;
const ll maxn=2e5+10;
const ll mod=1e9+7;

int main(){
    ll a,b;cin>>a>>b;
    if(a+b==15)
	cout<<"+";
    else if(a*b == 15)
	cout<<"*";
    else
	cout<<"x";
}


Measured memory_bytes: 256
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

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

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

string s;
int cnt[26];

int main(){
  cin >> s;
  int ans = inf;
  for(char i = 'a'; i <= 'z'; ++i){
    string t = s;
    int cur = 0;
    while(true){
      set < char > st;
      for(char i : t) st.insert(i);
      if(sz(st) == 1){
        break;
      }
      ++cur;
      for(int j = 0; j + 1 < sz(t); ++j){
        if(t[j + 1] == i){
          t[j] = i;
        }
      }
      t.pop_back();
    }
    ans = min(ans, cur);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=10000000000;


//main
int main() {
    
    //入力
    long N;
    cin>>N;
    
    //計算
    if(N==0){
        cout<<0<<endl;
        return 0;
    }
    vector<long> ans(0);
    long p=1;
    while(N!=0){
        if(abs(N)%2!=0){
            ans.push_back(1);
            N-=p;
        }else{
            ans.push_back(0);
        }
        N/=2;
        p*=(0-1);
    }
    
    
    
    //出力
    for(int i=ans.size()-1;i>=0;i--){
        cout<<ans.at(i);
    }
    cout<<endl;
}

Measured memory_bytes: 256
using System;


class Program {
    static void Main (string[] args) {
        

        string[] a1 = Console.ReadLine ().Split (' ');
        int a = int.Parse(a1[0]);
        int b = int.Parse(a1[1]);
        int rtn = 0;
        if(a >= b){
            rtn = 10;
        }else{
            rtn = 0;
        }

        Console.WriteLine(rtn);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
const ll INF=99999999999999999;
ll a,b,c,d,e,f,ans=0;
int main(){
    ll n;
    cin>>n;
 
    if(n%2==0){
      cout<<n*(n-2)/2<<endl;
        for(int i=1;i<n+1;i++){
            for(int j=i+1;j<n+1;j++){
                if(i+j!=n+1)cout<<i<<" "<<j<<endl;
            }
        }
    }
 
    if(n%2==1){
      cout<<(n-1)*(n-3)/2+(n-1)<<endl;
        for(int i=1;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(i+j!=n)cout<<i<<" "<<j<<endl;
            }
        }
 
        for(int i=1;i<n;i++){
            cout<<i<<" "<<n<<endl;
        }
    }
 
}

Measured memory_bytes: 256
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
t = defaultdict(int)
ans = 0
for x in combinations(l, 3):
    if x[0]!=x[1] and x[0]!=x[2] and x[1]!=x[2]:
        if x[0] + x[1] > x[2]:
            ans+=1
print(ans)

Measured memory_bytes: 9372
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,A,B,C = map(int,input().split())
L = [int(input()) for _ in range(N)]
 
from itertools import product
ans = float("inf")

# 全パターン試す
# 0 : 使わない
# 1,2,3 : A,B,Cとして使う
for p in product(range(4),repeat=N):
    a = [L[i] for i in range(N) if p[i]==1]
    b = [L[i] for i in range(N) if p[i]==2]
    c = [L[i] for i in range(N) if p[i]==3]
 
    if a==[] or b==[] or c==[]:
        continue
    
    t = 0
    for x in [a,b,c]:
        # 複数要素あるなら合成魔法を使って1つに
        if len(x)>=2:
            t += (len(x)-1)*10
    sumA = sum(a)
    sumB = sum(b)
    sumC = sum(c)
    # 目標との差分を 延長魔法or短縮魔法 で埋める
    t += abs(A-sumA) + abs(B-sumB) + abs(C-sumC)
 
    ans = min(ans,t)
 
print(ans)

Measured memory_bytes: 3064
n, m = list(map(int, input().split()))
num = [0 for i in range(n)]

flag = False
for i in range(m):
    s, c = list(map(int, input().split()))

    if (s == 1) and (c == 0) and (n > 1):
        flag = True
    elif num[s-1] == 0:
        num[s-1] = c
    else:
        if num[s-1] != c:
            flag = True

if flag:
    print(-1)
else:
    if (n > 1) and (num[0] == 0):
        num[0] = 1

    print("".join(list(map(str, num))))

Measured memory_bytes: 9156
#include <stdio.h>

#define SHARP 0
#define DOT 1

int main(void)
{
	int h,w;
	int i,j;
	char flag;
	
	while(1)
	{
		scanf("%d %d",&h,&w);
		
		if(h==0&&w==0) break;
		
		for(i=1;i<=h;i++)
		{
			if(i%2==1)
			{
				flag = SHARP;
			}
			else
			{
				flag = DOT;
			}
			
			for(j=1;j<=w;j++)
			{
				if(flag == SHARP)
				{
					printf("#");
					flag = DOT;
				}
				else
				{
					printf(".");
					flag = SHARP;
				}
			}
			
			printf("\n");
		}
		
		printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int ans=700;
int n;
int main(){
	string a;
	cin>>a;
	for(int i=0;i<3;i++){
		if(a[i]=='o') n++;
		
	}
	cout<<ans+n*100<<endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::*;
use std::cmp::min;

const K: i64 = 10;

fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };

    let mut score = 0;
    let mut lasts = [-1; 26];
    let mut t = vec![26; d];
    let depth = 2;
    for i in 0..d {
        let mut max_score = -10000000;
        for j in 0..26 {
            let tmp = search(i, j, &c, &s, &mut lasts, depth, d, 0);
            if tmp > max_score {
                max_score = tmp;
                t[i] = j;
            }
        }
        score += max_score;
        lasts[t[i]] = i as i64;
    }

    for &a in &t {
        println!("{}", a + 1);
    }
}

fn eval_score(
    i: usize,
    j: usize,
    c: &Vec<i64>,
    s: &Vec<Vec<i64>>,
    lasts: &mut [i64; 26],
    d: usize,
) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    let k = min(i as i64 + K - 1, d as i64);
    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        let sub = (c[j] * (i - last) + c[j] * (k - last)) * (k - i + 1);
        res -= sub;
    }

    lasts[j] = tmp;
    res
}

fn search(
    i: usize,
    t: usize,
    c: &Vec<i64>,
    s: &Vec<Vec<i64>>,
    lasts: &mut [i64; 26],
    depth: usize,
    d: usize,
    cscore: i64,
) -> i64 {
    if depth == 0 || i == d - 1 {
        return eval_score(i, t, &c, &s, lasts, d) + cscore;
    }

    let mut max_score = -1000000;
    let tmp_last = lasts[t];
    lasts[t] = i as i64;
    let tmp_score = eval_score(i, t, &c, &s, lasts, d);
    for j in 0..26 {
        let tmp = search(i + 1, j, &c, &s, lasts, depth - 1, d, cscore + tmp_score);

        if tmp > max_score {
            max_score = tmp;
        }
    }

    lasts[t] = tmp_last;
    max_score + cscore
}


Measured memory_bytes: 2304
{-# OPTIONS_GHC -Wall #-}

readInt :: String -> Int
readInt = read

solve :: Int -> Int -> Int
solve n k = if n `mod` k == 0 then 0 else 1

main :: IO ()
main = do
    [n,k] <- fmap (map readInt . words) getLine

    let ans = solve n k

    print ans


Measured memory_bytes: 508
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
using namespace std;

const int N=5005;
const int mod=1000000007;

int n,ans,m;
int dp[N][N];
char s[N];

int quickpow(int x,int y){
	int s=1;
	for (;y;y>>=1,x=1ll*x*x%mod)
		if (y&1) s=1ll*s*x%mod;
	return s;
}

void add(int &x,int y){
	x+=y;
	(x>=mod)?x-=mod:0;
}

int main(){
	int i,j;
	scanf("%d",&n);
	scanf("%s",s+1); m=strlen(s+1);
	dp[0][0]=1;
	for (i=1;i<=n;i++){
		for (j=0;j<=5000;j++){
			if (j) add(dp[i][j],2*dp[i-1][j-1]%mod);
			else add(dp[i][j],dp[i-1][j]);
			add(dp[i][j],dp[i-1][j+1]);
		}
	}
	ans=dp[n][m];
	for (i=1;i<=m;i++) ans=1ll*ans*quickpow(2,mod-2)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 98048
#include <stdio.h>

int main(void)
{
  int i, j, n, a[1000], v, k;
  scanf("%d", &n);
  for (i = 0; i < n; i++)  {
    scanf("%d", &a[i]);
  }
  for (i = 0; i < n; i++)  {
    v = a[i];
    j = i - 1;
    while (j >= 0 && a[j] > v)  {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = v;
    for (k = 0; k < n - 1; k++)  {
      printf("%d ", a[k]);
    }
    printf("%d\n", a[n - 1]);
  }

  return 0;
}

Measured memory_bytes: 600
#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++)


int main(){
    int n; cin >> n;
    vector<int64_t> l(87);
    l.at(0) = 2LL;
    l.at(1) = 1LL;
    rep2(i, 2, n + 1)l.at(i) = l.at(i-2) + l.at(i-1);
    cout << l.at(n) << endl;
}

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

using namespace std;

int main() {

	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;

	if (a + b + 1 != s.size()) { cout << "No" << endl; return 0; }
	else {
		for (int i = 0; i < a + b + 1;i++) {
			if (i != a && (s[i]<'0' || s[i]>'9')) {
				cout << "No" << endl; return 0;
			}
			else if (s[a] != '-') {
				cout << "No" << endl; return 0;
			}
		}
	}
	cout << "Yes" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
ll const MOD=1000000007;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    int M;
    cin>>N>>M;
    priority_queue<int> A;
    int a;
    REP(i,N){
        cin>>a;
        A.push(a);
    }
    int top;
    REP(i,M){
        top=A.top();
        A.pop();
        A.push(top/2);
    }
    ll sum=0;
    REP(i,N){
        sum+=A.top();
        A.pop();
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 892
#include<stdio.h>
#define length 100000
int head,tail;

typedef struct {
  char name[100];
  int t;
}QU;

QU Q[length];

void enque(QU x){
  Q[tail]=x;//?¨?????????????????????£???????????????????°?????????\
  tail=(tail+1)%length;

}
QU deque(){
  QU x =Q[head];
  head=(head+1)%length;
  return x;
}

int main(){
  int n,q;
  int i,j,all_T=0,c;
  QU u;
  scanf("%d %d",&n,&q);

  for(i=1;i<=n;i++){
    scanf("%s %d",Q[i].name,&Q[i].t);
  }
  head=1;
  tail=n+1;
  while(head!=tail){
    u=deque();
    if(u.t<q){all_T+=u.t;u.t=0;}
    else {u.t-=q; all_T+=q;}
    if(u.t>0)enque(u);
    else {
      printf("%s %d\n",u.name,all_T);
    }
  }
  return 0;
}

Measured memory_bytes: 10756
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
/*
time:
wa:
反省:
考察:
*/
int main() {
    int n; cin >> n;
    vector<int>b(n-1);
    vector <int>a(n);
    for(int i = 0; i < n-1; i++) cin >> b[i];
    a[0] = b[0];
    a[1] = b[0];
    for(int i = 1; i < n-1; i++){
        a[i+1] = b[i];
        if(b[i] < max(a[i+1], a[i])){
            a[i] = b[i];
        } 
    }
    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += a[i];
    }
    cout << sum << endl;

    return 0;
}

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

int main(){
  ll x, k, d;
  cin >> x >> k >> d;
  x = abs(x);

  ll straight = min(k, x/d);
  k -= straight;
  x -= straight*d;

  if(k%2 == 0){
    cout << x << endl;
  }
  else{
      cout << d-x << endl;
  }
return 0;
}

Measured memory_bytes: 3644
/**
 *    author:  tourist
 *    created: 10.05.2020 20:22:00       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  long long ans = 0;
  long long take = min(a, k);
  ans += take;
  k -= take;
  take = min(b, k);
  ans += 0;
  k -= take;
  ans -= k;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3692
// Java program For handling Input/Output 
import java.io.*;
import java.util.*;
import java.math.*;
//import java.awt.*;

public class Main {
    BufferedReader br;
    StringTokenizer st;

    int max = -1;
    final long P = 998244353;

    HashSet<String> set = new HashSet<>();
    HashMap<Integer, Integer> map = new HashMap<>();

    // actual logic
    void solve() throws IOException {
        int n = ni();
        int a[] = new int[n];
        long sum = 0;

        for (int i = 0; i < n; i++) {
            a[i] = ni();
            map.put(a[i], map.getOrDefault(a[i], 0) + 1);
            sum += a[i];
        }

        int q = ni();
        for (int i = 0; i < q; i++) {
            int b = ni();
            int c = ni();

            int x = map.getOrDefault(b, 0);
            map.put(b, 0);
            map.put(c, x + map.getOrDefault(c, 0));

            sum -= (long) x * (long) b;
            sum += (long) x * (long) c;
            pl(sum);
        }

    }

    // constructor
    Main() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                System.out.println(e);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    Main(String s) {
        try {
            br = new BufferedReader(new FileReader(s));
            st = new StringTokenizer(br.readLine());
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    // main metohd
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    // Utility methods

    String ns() {
        if (!st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                System.out.println(e);
            }
        }
        return st.nextToken();

    }

    int ni() {
        return Integer.parseInt(ns());
    }

    long nl() {
        return Long.parseLong(ns());
    }

    double nd() {
        return Double.parseDouble(ns());
    }

    void pl(String s) {
        System.out.println(s);
    }

    void pl(long s) {
        System.out.println(s);
    }
}


Measured memory_bytes: 64796
#include <iostream>
#include <cstdio>
using namespace std;
char a[100005],b;
int m,n,c;
int main(){
	while((b=getchar())!='\n'){
		m++;
		a[m]=b;
	}
	for(int i=m;i>=1;i--){
		c++;
		if(a[i]=='d'){
		if(a[m-i+1]=='b'){
			n++;
		}
	}
		if(a[i]=='b'){
		if(a[m-i+1]=='d'){
			n++;
		}
	}
		if(a[i]=='p'){
		if(a[m-i+1]=='q'){
			n++;
		}
	}
		if(a[i]=='q'){
		if(a[m-i+1]=='p'){
			n++;
		}				
		}
	}
	if(n==c){
		cout<<"Yes";
	}
	else{	
	if(n!=c||m%2!=0){
		cout<<"No"; 
	}
	}
	//cout<<endl<<"c="<<c<<endl;
	//cout<<"m="<<m<<endl;
	//cout<<"n="<<n<<endl;
	return 0;
}


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

const int MAX = 1e5 + 2;

int main()
{
    ll sum = 0;
    int n, q;
    cin >> n;
    vector<int> a(MAX);
    rep(i, n) {
        int b;
        cin >> b;
        sum += b;
        a[b]++;
    };
    cin >> q;
    rep(i, q) {
        int b, c;
        cin >> b >> c;
        sum += (c - b) * a[b];
        a[c] += a[b];
        a[b] = 0;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3740
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner = new Scanner(System.in);
	    int N = scanner.nextInt();
	    
	    for(int i=0;i<N;i++) {
		    int A = scanner.nextInt();
		    if(A%2==0 && A%3!=0 && A%5!=0) {
	    		System.out.println("DENIED");
	    		System.exit(0);
		    }
	    }
    	System.out.println("APPROVED");
	  
  		scanner.close();
	}

}

Measured memory_bytes: 22868
#include <iostream>
#include <algorithm>
#include <cmath>
#define int long long
using namespace std;
signed main() {
	int n;
	while (cin >> n, n) {
		if (n == 1) {
			cout << "deficient number\n";
			continue;
		}
		int sum = 1;
		for (int i = 2; i <= sqrt(n); i++) {
			if (n % i == 0)sum += i + (n / i);
			if (i*i == n)sum -= i;
		}
		if (n == sum)cout << "perfect number\n";
		else cout << (n < sum ? "abundant number\n" : "deficient number\n");
	}
}


Measured memory_bytes: 3032
#include <cstdio>
#include <queue>
#include <utility>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
 
using P = std::pair<int, int>;
using PP = std::pair<P, int>;
 
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
 
int H, W;
char s[51][51];
int ans;
bool used[51][51];
 
int main()
{
  scanf( "%d%d", &H, &W );
 
  ans = H*W;
 
  rep( i, H )
  {
    scanf( "%s", s[i] );
 
    rep( j, W ) if( s[i][j] == '#' )
      --ans;
  }
 
  std::queue<PP> que;
  que.push( PP( P( 0, 0 ), 1 ) );
  used[0][0] = true;
 
  bool fl = false;
 
  while( !que.empty() )
  {
    PP pp = que.front(); que.pop();
    P pos = pp.first;
    int dist = pp.second;
 
    if( pos.first == H-1 && pos.second == W-1 )
    {
      ans -= dist;
      fl = true;
     
      break;
    }
 
    rep( i, 4 )
    {
      int nx = pos.first+dx[i], ny = pos.second+dy[i];
 
      if( nx >= 0 && nx < H && ny >= 0 && ny < W && !used[nx][ny] && s[nx][ny] != '#' )
      {
        que.push( PP( P( nx, ny ), dist+1 ) );
        used[nx][ny] = true;
      }
    }
  }
 
  if( !fl )
    puts("-1");
  else
    printf( "%d\n", ans );
 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
int main() 
{
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout); 
    ios;
    int ar[26]={0};
    string s;
    cin>>s;
    f(i,0,4)
    {
    	ar[s[i]-'A']++;
	}
	int c=0;int flag=0;
	f(i,0,26)
	{
	  if(ar[i]>0&&ar[i]==2)
	   {  
	    c++;
	    continue;
		   }	
	else if(ar[i]>0)
	  {
	  	 cout<<"No";flag=1;
	  	 break;
	  }	   
	}
	if(c==2&&flag==0)
	 cout<<"Yes";
	 else if(flag==0)
	  cout<<"No";
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int k = sc.nextInt();
    ArrayList<String> ss = new ArrayList<>();
    int n = s.length();
    for(int i=0; i<n; i++) {
      for(int j=1; j<=k; j++) {
        if(i + j <= n) {
          ss.add(s.substring(i, i + j));
        }
      }
    }
    List<String> us = ss.stream().sorted().distinct().collect(Collectors.toList());
    System.out.println(us.get(k-1));
  }
}

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

int main(){

    ll a,b;
    cin >> a >> b;

    ll mid = (a+b)/2;

    if (abs(a-mid)!=abs(b-mid))
        cout << "IMPOSSIBLE" << endl;
    else
        cout << mid << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i = l; i < (n); i++)
#define INF 1e9+7
using namespace std;
using ll = long long;
int main() {
  int n,W;
  scanf("%d %d", &n,&W);
  ll dp[n+1][100001];
  ll w[n+1] = {},v[n+1] = {}; 
  rep(i,1,n+1) scanf("%d %d",&w[i],&v[i]);
  rep(i,0,n+1)rep(j,0,100001) dp[i][j] = INF;
  dp[0][0] = 0;
  rep(i,1,n+1)rep(j,0,100001) {
    if(j >= v[i]) dp[i][j] = min(dp[i-1][j-v[i]]+w[i],dp[i-1][j]);
    else dp[i][j] = dp[i-1][j];
  }
  ll ans = 100000;
  while(dp[n][ans] > W) ans--;
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 79104
#include <vector>
#include <string>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <sstream>
#include <algorithm>
#include <map>
#define INF 2000000005
using namespace std;
typedef pair<int,int> P;
struct edge{
	int t,cost;
	edge(){}
	edge(int tt,int cc){
		t=tt;
		cost=cc;
	}	
};

struct eel{
	int v,cost,tra;
	eel(){}
	eel(int vv,int cc,int tt){
		v=vv;
		cost=cc;
		tra=tt;
	}
	bool operator<(const eel &e)const{
		if(cost==e.cost)return tra>e.tra;
		return cost>e.cost;
	}
};


int n,t;
int all;
int id[100001];
bool transfer[100001];
P dist[100001];
vector<int> same[100001];
vector<edge> G[100001];
map<string,int> data;

P dijk(int start,int goal){
	priority_queue<eel> que;
	memset(transfer,false,sizeof(transfer));
	for(int i=0;i<all;i++){
		dist[i].first=INF;
		dist[i].second=INF;
	}
	for(int i=0;i<same[start].size();i++){
		que.push(eel(same[start][i],0,0));
		dist[same[start][i]]=P(0,0);
	}
	transfer[start]=true;
	while(que.size()){
		eel q=que.top();
		que.pop();
		if(dist[q.v].first<q.cost || dist[q.v].second<q.tra)continue;
		if(id[q.v]==goal)return P(q.cost,q.tra);
		for(int i=0;i<G[q.v].size();i++){
			edge e=G[q.v][i];
			if(dist[e.t].first>q.cost+e.cost || (dist[e.t].first==q.cost+e.cost && dist[e.t].second>q.tra)){
				dist[e.t]=P(q.cost+e.cost,q.tra);
				que.push(eel(e.t,q.cost+e.cost,q.tra));
			}
		}
		if(!transfer[id[q.v]]){
			transfer[id[q.v]]=true;
			for(int i=0;i<same[id[q.v]].size();i++){
				int next=same[id[q.v]][i];
				if(next==q.v)continue;
				dist[next]=P(q.cost+t,q.tra+1);
				que.push(eel(next,q.cost+t,q.tra+1));
			}
		}
	}
	return P(-1,-1);
}

int main(void){
	scanf("%d%d%*c",&n,&t);
	string str;
	string A;
	string B;
	getline(cin,str);
	istringstream stream(str);
	getline(stream,A,' ');
	getline(stream,B);
	for(int i=0;i<n;i++){
		int a;
		scanf("%d%*c",&a);
		int prev=all;
		getline(cin,str);
		istringstream stream(str);
		string name;
		while(getline(stream,name,' ')){
			if(data.find(name)==data.end()){
				int next=data.size();
				data[name]=next;
			}
			id[all]=data[name];
			same[data[name]].push_back(all);
			all++;
		}
		for(int j=0;j<a-1;j++){
			int tt;
			scanf("%d%*c",&tt);
			G[prev+j].push_back(edge(prev+j+1,tt));
			G[prev+j+1].push_back(edge(prev+j,tt));
		}
	}
	P res=dijk(data[A],data[B]);
	if(res.first==-1)printf("-1\n");
	else printf("%d %d\n",res.first,res.second);
	return 0;
}

Measured memory_bytes: 19788
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
int n, a[100];
ll money = 1000; 
int main() {
  cin >> n;
  rep(i,n) cin >> a[i];

  rep(i,n-1) {
    ll stock = 0;
    if (a[i] < a[i+1]) stock = money / a[i];
    money += (a[i+1]-a[i]) * stock;
  }
  cout << money << endl;
  return 0;
}

Measured memory_bytes: 3592
//--------ROMAN ITERATION -------------
#include <bits/stdc++.h>
#define ll  long long int
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i :c)
#define pii pair< int,int >
#define Fast_IO() ios_base::sync_with_stdio(false);cin.tie(0)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
#define fix( x ) cout << fixed << setprecision( x ) ;
const int MOD = 1000 * 1000 * 1000 + 7; // odd modulus
const int eps = 1e-9;
using namespace std;
clock_t time_p=clock();
void dem()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
int main()
{
    Fast_IO();
     int  n ;
     cin >> n ;
    vi vv ( n , 0 ) ;
     vector<pii>v ;
     for ( int i = 0 ; i < n ; ++ i )
     {
         int  x  ;
         cin >> x ;
         v.pb( {x , i  });
         vv[i] = x ;
     }
    sort(rall(v));
    pii x = v[0] ;
    pii y = v[1] ;
    for ( int i = 0 ; i < n ; ++i )
    {
        if ( vv[i] == x.ff && i==x.ss )cout << y.ff ;
        else
            cout << x.ff ;
        br
    }


}



Measured memory_bytes: 4080
#include<stdio.h>
#include<string.h>
void sort(char x[])
{
	int i,j,n;
	char t;

	n=strlen(x);
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			if(x[i]>x[j]){
				t=x[i];
				x[i]=x[j];
				x[j]=t;
			}
}

void tros(char x[])
{
	int i,j,n;
	char t;

	n=strlen(x);
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			if(x[i]<x[j]){
				t=x[i];
				x[i]=x[j];
				x[j]=t;
			}	
}

int main()
{
	char s[111],t[111];

	scanf("%s%s",s,t);

	sort(s);
	tros(t);
	printf("%s",(strcmp(s,t)<0)?"Yes":"No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

int H, W;
char s[50][50];

int main() {
    cin >> H >> W;
    rep(i, H)rep(j, W) cin >> s[i][j];

    for (int i = 0; i <= H - 1; i++) {
        for (int j = 0; j <= W - 2; j++) {
            if (s[i][j] == '.') continue;

            // 以降 #
            // 横
            if (s[i][j] == s[i][j + 1] || (j > 0 && s[i][j] == s[i][j - 1])) continue;

            // 上
            if (i - 1 >= 0 && s[i - 1][j] == s[i][j]) continue;

            // 下
            if (i + 1 <= H - 1 && s[i + 1][j] == s[i][j]) continue;

            // printf("i: %d j: %d\n", i, j);
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
int board[20][21], w, h;
int ans;
void dfs(int X, int Y, int d) {
	if (d >= 10) return;
	for (int i = 0; i < 4; i++) {
		int x = X, y = Y;
		while (1) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (0 > nx || nx >= w || 0 > ny || ny >= h) break;
			if (board[ny][nx] == 3) {
				ans = min(ans, d + 1);
				return;
			}
			if (board[ny][nx] == 1) {
				if (x != X || y != Y) {
					board[ny][nx] = 0;
					dfs(x, y, d + 1);
					board[ny][nx] = 1;
				}
				break;
			}
			x = nx;
			y = ny;
		}
	}
}
int main() {
	while (cin >> w >> h, w) {
		int sx, sy;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> board[i][j];
				if (board[i][j] == 2) sx = j, sy = i;
			}
		}
		ans = 1 << 30;
		dfs(sx, sy, 0);
		if (ans == 1 << 30) cout << -1 << endl;
		else cout << ans << endl;
	}
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  string N;
  cin>>N;
  
  long long sum=0;
  
  
  for(int i=0;i<N.size();i++){
    int y=N[i]-'0';
    sum=(sum+(y%9))%9;
  }
  
  if(sum%9==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3748
class Node{
  constructor(id, parent, children) {
    this.id = id;
    this.parent = parent;
    this.children = children;
  }
  get type() {
    if (this.parent === null) return 'root';
    if (this.children.length === 0) return 'leaf';
    return 'internal node';
  }
  get depth() {
    const getDepth = (node, i) => {
      return node.parent === null ? i : getDepth(node.parent, i + 1);
    };
    return getDepth(this, 0);
  }
  toString() { return `node ${this.id}: parent = ${this.parent !== null ? this.parent.id : -1}, depth = ${this.depth}, ${this.type}, [${this.children.map(n => n.id).join(', ')}]`; }
};

class Tree {
  constructor(n) { this.nodes = []; }
  add(id, childrenIds) {
    let node = this.find(id);
    childrenIds.forEach((cid) => {
      let c = this.find(cid);
      c.parent = node;
      c.id = cid;
      node.children.push(c);
    })
  }
  find(id) { return this.nodes[id] || (this.nodes[id] = new Node(id, null, []));}
  print() { console.log(this.nodes.sort((a, b) => a.id - b.id).map(n => n.toString()).join('\n')); }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  let tree = new Tree(n);
  let id;
  lines.map(l => l.split(' ').map(Number)).forEach(function(line) {
    id = line.shift();
    line.shift();
    tree.add(id, line);
  });
  tree.print();
})();



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

import sys
from math import sqrt

x = int(''.join([e for e in raw_input().split()]))
#print x

ans = 'No'
if x == int(sqrt(x))**2:
    ans = 'Yes'
    
sys.stdout.write('%s\n' % (ans))
sys.stdout.flush()


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

using namespace std;
using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;

class UnionFind {
 public:
  vector<int> parent;

  UnionFind(int n) : parent(n, -1) {}

  int root(int x) {
    if (parent[x] < 0) {
      return x;
    } else {
      return parent[x] = root(parent[x]);
    }
  }

  bool issame(int x, int y) { return root(x) == root(y); }

  int size(int x) { return -parent[root(x)]; }

  bool unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if (rx == ry) return false;
    if (parent[rx] > parent[ry]) swap(rx, ry);
    parent[rx] += parent[ry];
    parent[ry] = rx;
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K, L;
  cin >> N >> K >> L;
  vector<UnionFind> uf(2, UnionFind(N));
  for (int i = 0; i < K; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    uf[0].unite(a, b);
  }
  for (int i = 0; i < L; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    uf[1].unite(a, b);
  }
  map<pair<int, int>, int> mp;
  for (int i = 0; i < N; i++) {
    mp[make_pair(uf[0].root(i), uf[1].root(i))]++;
  }
  for (int i = 0; i < N; i++) {
    cout << mp[make_pair(uf[0].root(i), uf[1].root(i))]
         << (i == N - 1 ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 13584
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

int main()
{
	int N;
	string S;

	cin >> N;
	cin >> S;

	long long r = 0, g = 0, b = 0;

	int i, j;

	int mi=0;

	for (i = 0; i < N; ++i) {
		if (S[i] == 'R') { ++r; }
		if (S[i] == 'G') { ++g; }
		if (S[i] == 'B') { ++b; }
	}

	for (i = 0; i < N - 2; ++i) {
		for (j = 1; j <= floor((N - i - 1) / 2); ++j) {
			if (S[i] != S[i + j] && S[i + j] != S[i + 2 * j] && S[i + 2 * j] != S[i]) { ++mi; }
		}
	}

	cout << r*g*b - mi << endl;

}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;

int main(){
	ll N;
	cin>>N;
	vector<ll> age(N);
	rep(i,N)cin>>age[i];
	map<ll,ll> data;
	for(ll i = 0; i<N; ++i){
		data[(i+1LL)-age[i]] ++;
	}
	ll ans = 0;
	for(ll i = 0; i<N; ++i){
		ll tar = i + 1LL + age[i];
		ans += data[tar];
		data[(i+1LL)-age[i]]--;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 27304
#include<bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)
 
signed main(){
  long double A,B,C;
  cin>>A>>B>>C;
  string ans="No";
  if(sqrt(A)+sqrt(B)+1.0e-14<sqrt(C)){
    ans="Yes";
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 1e6;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
  string s; cin >> s;
  int ans = 0;
  for(auto c : s) {
    if(c == '2') ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256