akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>

using namespace std;

	int w,h,a,ans,tx,ty;
	bool map[62][62];
	
struct Node{
	int x,y,d;
	Node(int a,int b,int c){
		x=a;
		y=b;
		d=c;
	}
};
typedef struct Node node;
static const int dx[]={-1,0,1,0},dy[]={0,-1,0,1};

int main(){
	
	cin>>w;
	cin>>h;
	
	while(w!=0 || h!=0){
		ans=0;
		for(int lop=0;lop<62;lop++){
			for(int lop2=0;lop2<62;lop2++){
				if(lop==0 || lop==61 || lop2==0 || lop2==61|| lop2==w*2 || lop==h*2){
					map[lop][lop2]=1;
				}else{
					map[lop][lop2]=0;
				}
			}
		}
		map[0][1]=0;
		map[h*2][w*2-1]=0;
		
		for(int lop=0;lop<h*2-1;lop++){
			if(lop%2==0 || lop==0){
				for(int lop2=0;lop2<w-1;lop2++){
					cin>>a;
					if(a==1){
						if(map[lop][lop2*2+2]==0){
							map[lop][lop2*2+2]=1;
						}
						if(map[lop+1][lop2*2+2]==0){
							map[lop+1][lop2*2+2]=1;
						}
						if(map[lop+2][lop2*2+2]==0){
							map[lop+2][lop2*2+2]=1;
						}
					}
				}
			}else{
				for(int lop2=0;lop2<w;lop2++){
					cin>>a;
					if(a==1){
						if(map[lop+1][lop2*2]==0){
							map[lop+1][lop2*2]=1;
						}
						if(map[lop+1][lop2*2+1]==0){
							map[lop+1][lop2*2+1]=1;
						}
						if(map[lop+1][lop2*2+2]==0){
							map[lop+1][lop2*2+2]=1;
						}
					}
				}
			}
		}
		
		bool done[62][62]={0};
		queue<node> q;
		q.push(node(1,1,0));
		/*while(q.size()!=0){
			node qq=q.front();
			q.pop();
			
			cout<<qq.x<<' '<<qq.y<<' '<<qq.d<<endl;
			cout<<qq.node.a<<' '<<qq.node.b<<' '<<qq.node.c<<endl;
		}*/
		
		while(q.size()!=0){
			node qq=q.front();
			q.pop();
			
			if(done[qq.y][qq.x]==0){
				done[qq.y][qq.x]=1;
				
				if(qq.x==w*2-1 && qq.y==h*2-1){
					ans=(qq.d+2)/2;
					break;
				}
				
				//cout<<"aaaa"<<endl;
				for(int lop=0;lop<4;lop++){
					
					tx=dx[lop]+qq.x;
					ty=dy[lop]+qq.y;
					
					if(map[ty][tx]==0){
						q.push(node(tx,ty,qq.d+1));
					}
					
				}
			}
		}
		cout<<ans<<endl;
		
		
		/*for(int lop=0;lop<62;lop++){
			for(int lop2=0;lop2<62;lop2++){
				cout<<map[lop][lop2]<<' ';
			}
			cout<<endl;
		}*/
		
		cin>>w;
		cin>>h;
	}
	
	return 0;
}

Measured memory_bytes: 3016
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;

vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];
ll gcd(ll a, ll b)
{
   if (b == 0)
   {
       return a;
   }
    return gcd(b, a%b);
}
void dfs(int now, ll d) {
  visited[now] = true;
  dist[now] = d;
  for (auto p : to[now]) {
    if (visited[p.first]) continue;
    dfs(p.first, d + p.second);
  }
}

int main() {
    int a;
    cin >> a;
    cout << a+(a*a)+(a*a*a) << endl;
    return 0;
}


Measured memory_bytes: 5880
#include<stdio.h>
#include<string.h>
int f(int a,int b){
  if(b==0)return a;
  return f(b,a%b);
}
int main(){
  int a,b,c,t;
  while(scanf("%d %d",&a,&b)!=EOF){
    if(a<b){
      t=a;
      a=b;
      b=t;
    }
    c=f(a,b);
    printf("%d %d\n",c,(a/c)*b);
  }
  return 0;
}
    

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<vector>

using namespace std;

char ground[60][60]={'*'};

void jin_w(int i,int j){
  if(ground[i][j-1]=='.'){
    ground[i][j-1]='w';
    jin_w(i,j-1);
  }
  else if(ground[i][j-1]=='b'){
    ground[i][j-1]='*';
    jin_w(i,j-1);
  }
  if(ground[i+1][j]=='.'){
    ground[i+1][j]='w';
    jin_w(i+1,j);
  }
  else if(ground[i+1][j]=='b'){
    ground[i+1][j]='*';
    jin_w(i+1,j);
  }
  if(ground[i][j+1]=='.'){
    ground[i][j+1]='w';
    jin_w(i,j+1);
  }
  else if(ground[i][j+1]=='b'){
    ground[i][j+1]='*';
    jin_w(i,j+1);
  }
  if(ground[i-1][j]=='.'){
    ground[i-1][j]='w';
    jin_w(i-1,j);
  }
  else if(ground[i-1][j]=='b'){
    ground[i-1][j]='*';
    jin_w(i-1,j);
  } 
}

void jin_b(int i,int j){
  if(ground[i][j-1]=='.'){
    ground[i][j-1]='b';
    jin_b(i,j-1);
  }
  else if(ground[i][j-1]=='w'){
    ground[i][j-1]='*';
    jin_b(i,j-1);
  }
  if(ground[i+1][j]=='.'){
    ground[i+1][j]='b';
    jin_b(i+1,j);
  }
  else if(ground[i+1][j]=='w'){
    ground[i+1][j]='*';
    jin_b(i+1,j);
  }
  if(ground[i][j+1]=='.'){
    ground[i][j+1]='b';
    jin_b(i,j+1);
  }
  else if(ground[i][j+1]=='w'){
    ground[i][j+1]='*';
    jin_b(i,j+1);
  }
  if(ground[i-1][j]=='.'){
    ground[i-1][j]='b';
    jin_b(i-1,j);
  }
  else if(ground[i-1][j]=='w'){
    ground[i-1][j]='*';
    jin_b(i-1,j);
  } 
}

int main(){
  int w,h;

  while(cin>>w>>h,w,h){
    int cnt_w=0;
    int cnt_b=0;
    
    // fill(begin(ground),end(ground),"*");
      
    for(int i=1;i<h+1;++i){
      for(int j=1;j<w+1;++j){
	cin>>ground[i][j];
      }
    }
    for(int i=1;i<h+1;++i){
      for(int j=1;j<w+1;++j){
	if(ground[i][j]=='W')
	  jin_w(i,j);
	else if(ground[i][j]=='B')
	  jin_b(i,j);
      }
    }
    for(int i=1;i<h+1;++i){
      for(int j=1;j<w+1;++j){
	if(ground[i][j]=='w')
	  cnt_w++;
	else if(ground[i][j]=='b')
	  cnt_b++;
      }
    }
    cout<<cnt_b<<' '<<cnt_w<<endl;

    for(int i=0;i<60;++i){
      for(int j=0;j<60;++j){
	ground[i][j]='*';
      }
    }
    
  }
}

Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		String str =  reader.next();
		int length = (str.length()-1) / 2 * 2;
		int ans = 0;
		for (int i = length; i > 0; i-=2) {
			boolean flag = true;
			for (int j = 0; j < i / 2; j++) {
				if (str.charAt(j) != str.charAt(j+i/2)) {
					flag = false;
					break;
				}
			}
			if (flag) {
				ans = i;
				break;
			}
		}
		System.out.println(ans);
		reader.close();
	}


}





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

using namespace std;

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

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define all(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define tr(container, it) \
	for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 

// #define sz(a) int((a).size())
// #define pb push_back
// #define fill(a,v) memset(a,v,sizeof a)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;

#define trace3(x,y,z) cout<< '>' << #x << ':' << x \
		<< " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;

#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x \
	<< " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;


inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

const double pi = acos(-1);

/////////////////////////////////////////////////////////////////////

// bool sortbysec(const pair<int,int> &a,
//               const pair<int,int> &b)
// {
//     return !(a.first < b.first);
// }

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } // __gcd(0,0) gives exception


const int MAX_N = 1005;
 
int main(){
	int N;
	ll x;
	set<ll> S;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%lld",&x);
		if(S.find(x)==S.end())
			S.insert(x);
		else
			S.erase(x);
	}
	printf("%d\n",(int)S.size());
    return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int main() {
    ll n;
    cin>>n;
    ll m=n;
    ll s=0;
    while(n){
    	s+=n%10;
    	n/=10;
	}
	if(m%s) cout<<"No";
	else cout<<"Yes";
	return 0;
}

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


string s;
int d;
const int mod =1e9+7;

int dp[100009][109] = {-1};

int dfs(int pos, int sum, bool flag) {
    if (pos==s.size()) return sum % d == 0;

    if (!flag && dp[pos][sum]!=-1) {
        return dp[pos][sum];
    }

    int lim = flag ? s[pos] - '0' : 9;

    int ret = 0;

    for (int i = 0; i <= lim; i++) {
        ret += dfs(pos+1, (sum + i)%d, flag&&i==lim);
        ret %= mod;
    }
    
    if(!flag) dp[pos][sum]=ret;
    return ret;
}

int main() {
    memset(dp, -1, sizeof dp);
    cin>>s;
    cin>>d;
    cout<<(dfs(0, 0, true)-1+mod)%mod<<endl;
}

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

int main(){
  int n[8],k,max,min,a;
  char s;
  cin>>a;
  for(int i=0;i<a;i++){
    for(int j=0;j<8;j++){
      cin>>s;
      n[j]=s-'0';
    }
    sort(n,n+8);
    k=1;
    max=0;
    for(int j=0;j<8;j++){
      max+=n[j]*k;
      k*=10;
    }
    reverse(n,n+8);
    k=1;
    min=0;
    for(int j=0;j<8;j++){
      min+=n[j]*k;
      k*=10;
    }
    cout<<max-min<<endl;  
  }
  return 0;
}

Measured memory_bytes: 3016
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())

print(l[k-1])

Measured memory_bytes: 2940
#define rep(i,n) for (int i = 0; i < n; i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

int main() {
	int n; cin >> n;
	vector<int> a;
	int i = 1;
	while (a.size() < n) {
		if (IsPrime(i) && i % 5 == 1) a.push_back(i);
		i++;
	}
	rep(i, n) cout << a[i] << " ";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	char S[3],T[3];
	int count = 0;
	scanf("%s%s", S, T);
	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i]) {
			count++;
		}
	}
	printf("%d", count);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n;
	int a[106];
	rep(i, n) cin >> a[i];
	sort(a, a+n);
	x = a[0];
	sort(a, a+n, greater<int>());
	y = a[0];
	cout << y - x << endl;
}

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


int main (){
    int a, b, c;
    string s, t;
    cin>>s;
    if(s=="Sunny"){
        cout<<"Cloudy"<<endl;
    }
    if(s=="Cloudy"){
        cout<<"Rainy"<<endl;
    }
    if(s=="Rainy"){
        cout<<"Sunny"<<endl;
    }
    
}

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

using namespace std;

//------------------------------- Libraries --------------------------------//

template <class T>
class WeightedUnionFind
{
    vector<int> par;
    vector<T> dist;

public:
    WeightedUnionFind(int n) : par(n, -1), dist(n, 0) {}

    int root(int x)
    {
        if (par[x] < 0)
            return x;
        else
        {
            //rootから降りて足していく
            int r = root(par[x]);
            //親までの累積和は計算し終わっている
            dist[x] += dist[par[x]];
            return par[x] = r;
        }
    }

    //d[y] = d[x] + w
    bool merge(int x, int y, T w)
    {
        //par[y] = x
        w += weight(x) - weight(y);
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
        {
            w = -w;
            swap(x, y);
        }
        par[x] += par[y];
        par[y] = x;
        dist[y] = w;
        return true;
    }

    T weight(int x)
    {
        root(x);
        return dist[x];
    }

    T dis(int x, int y) { return weight(y) - weight(x); }

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

//verified @ https://onlinejudge.u-aizu.ac.jp/solutions/problem/DSL_1_B/review/3922525/sifi_border/C++14

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, m;
    char c;
    while (cin >> n >> m && n)
    {
        WeightedUnionFind<int> wuf(n);
        while (m--)
        {
            int a, b, w;
            cin >> c;
            if (c == '!')
            {
                cin >> a >> b >> w;
                a--, b--;
                wuf.merge(a, b, w);
            }
            else
            {
                cin >> a >> b;
                a--, b--;
                if (wuf.root(a) == wuf.root(b))
                {
                    cout << wuf.dis(a, b) << '\n';
                }
                else
                {
                    cout << "UNKNOWN\n";
                }
            }
        }
    }
}

int main()
{
    solve();
    return 0;
}



Measured memory_bytes: 3604
deck = { :S => ("1".."13").to_a, :H => ("1".."13").to_a, :C => ("1".."13").to_a, :D => ("1".."13").to_a }
gets
while ( card = gets )
  suit, num = card.split
  deck[ suit.to_sym ].delete( num )
end
deck.each do | s, vals |
  vals.each do | n |
    puts s.to_s+" "+n
  end
end

Measured memory_bytes: 6108
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

a,b,k=MI()
u=[]
ans=[]
for i in range(a,a+k):
    u.append(i)
for j in range(b-k+1,b+1):
    u.append(j)
for s in u:
    if a<=s<=b:
        ans.append(s)
printni(sorted(list(set(ans))))


Measured memory_bytes: 3316
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main(){
    ll h, w;
    cin >> h >> w;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
    }

    ll pos = 0;
    for(int i = 0; i < h; ++i){
        vector<ll> tmp(w);
        for(int j = 0; j < w; ++j){
            if(i % 2 == 0){
                tmp.at(j) = pos;
            }else{
                tmp.at(w - j - 1) = pos;
            }
            a.at(pos)--;
            if(a.at(pos) == 0){
                pos++;
            }
        }
        for(int j = 0; j < w; ++j){
            cout << tmp.at(j) + 1;
            if(j < w - 1){
                cout << ' ';
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int F[50];
int fibonacci(int n){
if(n==0 || n==1) return F[n]=1;
if(F[n]!=-1) return F[n];
else return F[n]=fibonacci(n-1)+fibonacci(n-2);
}
void makefc(){
  int i;
for(i=0;i<50;i++)F[i]=-1;
}
int main(){
  int i,n;
  makefc();
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
}



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

int main(){
  int X,A,B;
  cin >> X >> A >> B;
  if(A >= B){
    cout << "delicious" <<endl;
  }
  else if(A+X >= B){
    cout << "safe" << endl;
  }
  else {
  cout << "dangerous"<<endl;
  }
}


Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

dx, dy = x2 - x1, y2 - y1
dx, dy = -dy, dx

x3, y3 = x2 + dx, y2 + dy
dx, dy = -dy, dx

x4, y4 = x3 + dx, y3 + dy

print(x3, y3, x4, y4)

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 1001001001;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
const int mod = 1000000007;
int dp[100005][2];

int main() {
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    rep(i, n) {
        {
            if (s[i] == '0') {
                dp[i + 1][0] = dp[i][0];
                dp[i + 1][1] = dp[i][1];
            } else {
                dp[i + 1][1] = (dp[i][0] + dp[i][1]) % mod;
            }
        }
        {
            if (s[i] == '0') {
                (dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
            } else {
                (dp[i + 1][0] += dp[i][0] * 2 % mod) %= mod;
                (dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
            }
        }
    }
    int ans = (dp[n][0] + dp[n][1]) % mod;
    cout << ans << endl;
}



Measured memory_bytes: 1280
S = input()
l = int((len(S)-1)/2)
a = 0
for i in range(l):
  if S[i] == S[2*l-i] and S[i] == S[l-1-i] and S[i+l+1] == S[2*l-i]:
    a = a + 1
  
if a == l:
  print("Yes")
else:
  print("No")



Measured memory_bytes: 2940
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
long long
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 金額 - 取得
	int li1Val[4];
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d%d%d", &li1Val[0], &li1Val[1], &li1Val[2], &li1Val[3]);

	// 金額 - 調整
	int liVal;
	for (i = 1; i < 4; i++) {
		liVal = li1Val[i - 1] * 2;
		if (li1Val[i] > liVal) {
			li1Val[i] = liVal;
		}
	}

	// 必要量 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &liVal);

	// 必要金額 - 取得
	long long llVal = (liVal % 2) * li1Val[2];
	llVal += (long long)(liVal / 2) * (long long)li1Val[3];

	return llVal;
}

// １回実行
int
fOne(
)
{
	long long llRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	llRet = fMain();

	// １行出力
	sprintf(lc1Buf, "%lld\n", llRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 128
#include <iostream>

using namespace std;
struct data
{
    long long int a,b,c;
};
data a[100001],s[100001];
long long int n,i;
int main()
{
    cin >>n;
    for (i=1;i<=n;i++)
    {
        cin >>a[i].a>>a[i].b>>a[i].c;
    }
    s[1].a=a[1].a,s[1].b=a[1].b,s[1].c=a[1].c;
    for (i=2;i<=n;i++){
        s[i].a=max(s[i-1].b+a[i].a,s[i-1].c+a[i].a);
        s[i].b=max(s[i-1].a+a[i].b,s[i-1].c+a[i].b);
        s[i].c=max(s[i-1].a+a[i].c,s[i-1].b+a[i].c);
    }
    cout <<max(s[n].a,max(s[n].b,s[n].c));
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    rep(i, n) {
        if (a[i]%2==0) {
            if (a[i]%3!=0 && a[i]%5!=0) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;

    return 0;
}

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

void Main() {
  int r;
  cin >> r;
  cout << 3 * r * r << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

using ll = long long;
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()
int main(){
    int N;
    cin >> N;
    long long L[87]= {0};
    L[0] = 2, L[1] = 1;
    for(int i = 2; i <= N; i++){
        L[i] = L[i -1] + L[ i - 2];
    }
    cout << L[N] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

struct UnionFindTree {
    size_t n;
    vector<int> tree;
    UnionFindTree(size_t n): n(n) {
        tree = vector<int>(n, -1);
    }
    int find_root(size_t v) {
        if (tree[v] < 0) return v;
        return tree[v] = find_root(tree[v]);
    }
    bool unite(size_t x, size_t y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return false;
        if (rank(x) < rank(y)) swap(x, y);
        tree[x] += tree[y];
        tree[y] = x;
        return true;
    }
    bool has_same_root(size_t x, size_t y) {
        return find_root(x) == find_root(y);
    }
    size_t rank(size_t v) {
        return -tree[find_root(v)];
    }
};

int main() {
    size_t n, m;
    scanf("%zu %zu", &n, &m);

    UnionFindTree tree(n);
    for (size_t i=0; i<m; ++i) {
        size_t s, t;
        scanf("%zu %zu", &s, &t);

        tree.unite(s, t);
    }

    size_t q;
    scanf("%zu", &q);

    for (size_t i=0; i<q; ++i) {
        size_t s, t;
        scanf("%zu %zu", &s, &t);

        printf("%s\n", tree.has_same_root(s, t)? "yes":"no");
    }

    return 0;
}    

Measured memory_bytes: 2692
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7
const double c_PI = 3.14159265358979323846264338327950288;

int main() {
	int N, A[100005];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}


	int next = A[1 - 1];
	for (int i = 0; i < N; i++) {

		if (next == 2) {
			printf("%d\n", i + 1);
			return 0;
		}

		next = A[next - 1];




	}

	printf("-1\n");






}




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


int a[3];

void Main() {
  rep(i, 3) {
    cin >> a[i];
  }

  int sum = 0;
  rep(i, 3) {
    sum += a[i];
  }

  if (sum >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
}

int main() {
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

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

int main() {
  int n, m;
  while (cin >> n >> m, n) {
    vector<string> str(n), str2(m);
    vector<int> r(n), c(n), s(n), d(n), res(m), r2(m), c2(m), s2(m);
    rep (i, n) cin >> str[i];
    rep (i, m) cin >> str2[i];
    r[0] = c[0] = s[0] = 0;
    rep (i, n - 1) {
      r[i + 1] = r[i];
      c[i + 1] = c[i];
      s[i + 1] = s[i];
      rep (j, str[i].size()) {
	if (str[i][j] == '(') ++r[i + 1];
	if (str[i][j] == ')') --r[i + 1];
	if (str[i][j] == '{') ++c[i + 1];
	if (str[i][j] == '}') --c[i + 1];
	if (str[i][j] == '[') ++s[i + 1];
	if (str[i][j] == ']') --s[i + 1];
      }
    }
    r2[0] = c2[0] = s2[0] = 0;
    rep (i, m - 1) {
      r2[i + 1] = r2[i];
      c2[i + 1] = c2[i];
      s2[i + 1] = s2[i];
      rep (j, str2[i].size()) {
	if (str2[i][j] == '(') ++r2[i + 1];
	if (str2[i][j] == ')') --r2[i + 1];
	if (str2[i][j] == '{') ++c2[i + 1];
	if (str2[i][j] == '}') --c2[i + 1];
	if (str2[i][j] == '[') ++s2[i + 1];
	if (str2[i][j] == ']') --s2[i + 1];
      }
    }
    rep (i, n) {
      d[i] = str[i].size();
      rep (j, str[i].size()) if (str[i][j] != '.') {
	d[i] = j;
	break;
      }
    }
    bool f = true;
    rep (i, 21) rep (j, 21) rep (k, 21) if (i && j && k) {
      bool ok = true;
      rep (t, n) if (r[t]  * i + c[t] * j + s[t] * k != d[t]) ok = false;
      if (ok) {
	if (f) {
	  rep (t, m) res[t] = r2[t] * i + c2[t] * j + s2[t] * k;
	  f = false;
	} else {
	  rep (t, m) {
	    int dot = r2[t] * i + c2[t] * j + s2[t] * k;
	    if (res[t] != dot) res[t] = -1;
	  }
	}
      }
    }
    rep (i, m) cout << (i > 0 ? " " : "") << res[i];
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    
    if (u == s)
        a--;
    else
        b--;

    cout << a << " " << b << endl;
    
    return 0;
}


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

int cnt = 0;

void display(int m, vector<int> g, int *a, int n){
	printf("%d\n", m);
	for(int i = m - 1; i > 0; i--)
		printf("%d ", g[i]);
	printf("%d\n", g[0]);
	printf("%d\n", cnt);
	for(int i = 0; i < n; i++)
		printf("%d\n", a[i]);
}

void insertionSort(int *a, int n, int g){
	for(int i = g; i < n; i++) {
		int v = a[i];
		int j = i - g;
		while(j >= 0 && a[j] > v) {
			a[j+g] = a[j];
			j -= g;
			cnt++;
		}
		a[j+g] = v;
	}
}

void shellSort(int *a, int n){
	int t = 1;
	vector<int> g;
	while(t <= n) {
		g.push_back(t);
		t = 3*t + 1;
	}
	for(int i = g.size() - 1; i >= 0; i--)
		insertionSort(a, n, g[i]);
	display(g.size(), g, a, n);
}

int main(){
	int n;
	scanf("%d", &n);
	int a[1000010];
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	shellSort(a, n);
}



Measured memory_bytes: 7072
import collections

n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

c = collections.Counter(a)

p = [k-q] * n
for i in list(c.keys()):
    p[i-1] += c[i]

for i in p:
    print('Yes' if i > 0 else 'No')

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


int main(){
    long n,w;
    cin>>n>>w;
    long m[n][w+1];
    long g[n],v[n];
    for (long i=0;i<n;i++)
        cin>>g[i]>>v[i];
    for (long i=0;i<n;i++){
       for (long j=0;j<=w;j++){
            if (i==0&&j>=g[i])
               m[i][j]=v[i];
            else if (i==0)
               m[i][j]=0;
            else{
                if (j>=g[i])
                m[i][j]=max(m[i-1][j],m[i-1][j-g[i]]+v[i]);
                else
                m[i][j]=(m[i-1][j]);
              }
            //  cout<<m[i][j]<<" ";
              }
            //  cout<<endl;
              }

       cout<<m[n-1][w]<<endl;
    return 0;
}

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

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << "\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

const int N = 3e3 + 5;

double dp[N][N];
double p[N];
int n;

void solve(){
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> p[i];

    memset(dp, 0, sizeof dp);
    dp[0][0] = 1;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            dp[i+1][j+1] += p[i] * dp[i][j];
            dp[i+1][j] += (1.0-p[i]) * dp[i][j];
        }
    }

    double res = 0.0;
    for(int j = n/2+1; j <= n; ++j)
        res += dp[n][j];

    cout << fixed << setprecision(10) << res << "\n";
}

int main()
{
    Fast;
    //louisfghbvc{
        solve();
    //}
    return 0;
}


Measured memory_bytes: 74364
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

ll p(ll m, ll n) {
	if (n <= 0) { return 1; }
	return m * p(m,n - 1);
}


int main() {
	
	string S;
	cin >> S;

	ll n = S.size();

	ll ans = 0;

	rep(i, n) {
		ll x = S[i] - '0';

		rep(j, n - i) {
			ans += p(2, i)*p(2,n-2-i-j)*p(10,j)*x;
		}

	}

	cout << ans;

	system("PAUSE");
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) begin(n),end(n)

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

#define DEBUG

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

	if(n / 100 == n % 10) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
// Let's bring the sky down :)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e4 + 5;
const int M = 1e9 +  7;
ll dp[N][102][2];
string k;
int n, m;
int solve(int idx, int mod, int flag){
    if(idx == n){
        return(mod == 0);
    }
    if(dp[idx][mod][flag] != -1)
        return dp[idx][mod][flag];
    int ans = 0;
    int curDig = (int)(k[idx] - '0');
    if(!flag){
        for(int i = curDig; i >= 0; i--){
            ans = ans + solve(idx + 1, (mod + i) % m, (i < curDig));
            if(ans >= M)
                ans -= M;
        }
    }
    else{
        for(int i = 0; i < 10; i++){
            ans = ans + solve(idx + 1, (mod + i) % m, flag);
            if(ans >= M)
                ans -= M;
        }
    }
    return dp[idx][mod][flag] = ans;
}
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> k;
    n = (int)k.size();
    cin >> m;
    memset(dp, -1, sizeof(dp));
    cout << (solve(0, 0, 0) - 1 + M) % M;
return 0;
}


Measured memory_bytes: 17152
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);



int main(){
    FIN;
    vector<int> a(5);
    int min_i=100,min_iti=100;
    rep(i,0,5){
        cin >> a[i];
        int iti  = a[i]%10;
        if(iti < min_iti && iti != 0){
            min_iti = iti;
            min_i = i;
        }
    }

    int ans = 0;
    rep(i,0,5){
        if(i == min_i) ans += a[i];
        else if(a[i]%10 == 0) ans += a[i];
        else ans += a[i] + (10-a[i]%10);
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
    // Here your code !
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String N = br.readLine();

    int sum = 0;
    String key;
    HashMap<String, Boolean> hash = new HashMap<>();
    while((key = br.readLine()) != null) {
	  if (hash.get(key) == null) {
        sum += 1;
        hash.put(key, true);
      } else {
        sum -= 1;
        hash.put(key, null);
      }
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 32828
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/22/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll MOD = 998244353;

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

  int N,S; cin>>N>>S;
  vector<ll> A(N); for(auto& a : A) cin>>a;

  ll ans = 0;
  vector<ll> dp(S+1);
  for (int i = 0; i < N; i++) {
    dp[0] = i+1;
    for (int s = S-A[i]; s >= 0; s--) {
      (dp[s+A[i]] += dp[s]) %= MOD;
    }
    (ans += dp[S]) %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
s = input()
k = int(input())

#s = "11111"
#k = 5

not1 = len(s)
for i in range(len(s)):
    if s[i] != "1":
        not1 = i
        first_not1 = s[i]
        break

if k <= not1:
    print(1)
else:
    print(first_not1)

Measured memory_bytes: 3060
import java.util.*;
class Main{
    Scanner sc=new Scanner(System.in);
    void main(){
	int a=sc.nextInt();
	int b=sc.nextInt();
	int c=sc.nextInt();
	int ans=0;
	for(int i=a;i<=b;i++)if(c%i==0)ans++;
	System.out.println(ans);
    }
    public static void main(String[]ag){
	new Main().main();
    }
}

Measured memory_bytes: 26412
#include <stdio.h>

int main() {
    int a, b, c, d;
    scanf("%d%d%d%d",&a, &b, &c, &d);
    
    while(a != 0 && c != 0) {
        c -= b;
        if(c <= 0) {
            break;
        }
        a -= d;
        if(a <= 0) {
            break;
        }
  }

  if(a > 0) {
      printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 1620
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class A {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int N, R;
        Input(out N, out R);
        if(N >= 10) {
            Console.WriteLine(R);
        } else {
            Console.WriteLine(R + 100 * (10 - N));
        }
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
 
#define int long long
 
signed main()
{
	int N, K, D[1000000], ans, copy[10];
	scanf("%d %d", &N, &K);
	for(int i=0; i<K; i++){
		scanf("%d", &D[i]);
	}
	while(1){
		bool flag=true;
		int i=0;
		ans = N;
		while(1){
			copy[i] = ans%10;
			if(ans/10==0 && ans%10!=0){
				break;
			}
			ans=ans/10;
			i++;
		}
		for(int j=0; j<=i; j++){
			for(int k=0; k<K; k++){
				if(copy[j]==D[k]){
					flag = false;
				}
			}
		}
		if(flag){
			break;
		}
		N++;
	}
	printf("%d\n", N);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

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

int main() {
    int H, W; cin >> H >> W;
    vector<vector<char>> g(H, vector<char> (W));
    vector<vector<int>> seen(H, vector<int>(W, -1));
    queue<pair<int, int>> q;
    rep(i, H) {
        rep(j, W) {
            char c; cin >> c;
            if(c == '#') {
                q.push(make_pair(i, j));
                seen[i][j] = 0;
            }
            g[i][j] = c;
        }
    }
    while(q.size()) {
        pair<int, int> now = q.front();
        q.pop();
        rep(i, 4) {
            int nh = now.first + dh[i];
            int nw = now.second + dw[i];
            if(nh < 0 || H <= nh || nw < 0 || W <= nw) continue;
            if(g[nh][nw] == '#') continue;
            if(seen[nh][nw] != -1) continue;
            seen[nh][nw] = seen[now.first][now.second] + 1;
            q.push(make_pair(nh, nw));
        }
    }
    int ans = 0;
    rep(i, H) rep(j, W) chmax(ans, seen[i][j]);
    cout << ans << endl;
}


Measured memory_bytes: 16164
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int N;
vector <int> tree[2010];

int X;
int L[2010][2010],R[2010][2010],order[2010][2010]; // root, node -> rank
set <int> s[2010];

void pre_dfs(int r, int p, int x){
	L[r][x] = X;
	order[r][X] = x;
	X++;
	
	int i;
	REP(i,tree[x].size()){
		int y = tree[x][i];
		if(y != p) pre_dfs(r, x, y);
	}
	
	R[r][x] = X;
}

bool is_child(int r, int x, int y){ // is y grandchildren of x?
	return (L[r][y] >= L[r][x] && R[r][y] <= R[r][x]);
}

bool exist(int x, int y){
	return (s[x].find(L[x][y]) != s[x].end());
}

int find_parent(int x, int y){
	__typeof(s[x].begin()) itr = s[x].lower_bound(L[x][y]);
	if(itr == s[x].begin()) return -1;
	itr--;
	return order[x][(*itr)];
}

vector <int> find_children(int x, int y){
	vector <int> ans;
	__typeof(s[x].begin()) itr = s[x].lower_bound(L[x][y]);
	
	while(itr != s[x].end()){
		int z = order[x][(*itr)];
		if(!is_child(x, y, z)) break;
		ans.push_back(z);
		itr++;
	}
	
	return ans;
}

void erase(int x, int y){
	s[x].erase(L[x][y]);
	s[y].erase(L[y][x]);
}

void add_direct(int x, int y){
	s[x].insert(L[x][y]);
	s[y].insert(L[y][x]);
}

void add(int s, int t){
	int i;
	
	if(s == t) return;
	
	if(exist(s, t)) return;
	
	{
		int u = find_parent(s, t);
		if(u != -1 && is_child(s, u, t)){
			add(u, t);
			return;
		}
	}
	
	swap(s, t);
	
	{
		int u = find_parent(s, t);
		if(u != -1 && is_child(s, u, t)){
			add(u, t);
			return;
		}
	}
	
	vector <int> v = find_children(s, t);
	vector <int> w = find_children(t, s);
	
	add_direct(s, t);
	
	REP(i,v.size()){
		int u = v[i];
		erase(s, u);
	}
	
	REP(i,w.size()){
		int u = w[i];
		erase(t, u);
	}
	
	REP(i,v.size()){
		int u = v[i];
		add(t, u);
	}
	
	REP(i,w.size()){
		int u = w[i];
		add(s, u);
	}
}

vector <int> graph[2010];
bool used[2010];

void dfs(int r, int x){
	int i;
	
	if(used[x]) return;
	used[x] = true;
	
	REP(i,graph[x].size()){
		int y = graph[x][i];
		if(is_child(r, x, y)) dfs(x, y);
	}
}

int main(void){
	int M,i,j,ss,t;
	
	cin >> N >> M;
	REP(i,N-1){
		cin >> ss >> t;
		ss--; t--;
		tree[ss].push_back(t);
		tree[t].push_back(ss);
	}
	
	REP(i,N){
		X = 0;
		pre_dfs(i, -1, i);
	}
	
	REP(i,M){
		cin >> ss >> t;
		ss--; t--;
		add(ss, t);
	}
	
	REP(i,N) REP(j,N) if(s[i].find(L[i][j]) != s[i].end()) graph[i].push_back(j);
	
	int ans = 0;
	REP(i,N){
		REP(j,N) used[j] = false;
		dfs(i, i);
		REP(j,N) if(j != i && used[j]) ans++;
	}
	
	cout << ans / 2 << endl;
	
	return 0;
}


Measured memory_bytes: 48384
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion

//ABC 156 -C
int main(void) {
	int  i, n, x[101];
	float p,t = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &x[i]);
		t += x[i];
	}
	
	p = round(t/n);

    t = 0;
    for (i = 0; i < n; i++) 
 		t += pow(x[i] - p, 2);
	printf("%d", (int)t);
	return 0;
}

Measured memory_bytes: 384
import sys, math
from sys import stdin, stdout

rem = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 6)
take = lambda: map(int, stdin.readline().split())

def help(arr):
    global i,j,k
    a,b,c=arr
    return a*i+b*j+c*k



n,m=take()
arr=[]
for i in range(n):
    arr.append(take())
ans=0
all=[-1,1]
for i in all:
    for j in all:
        for k in all:
            arr=sorted(arr,key=help,reverse=True)
            a,b,c=[0,0,0]
            for p in range(m):
                a+=arr[p][0]
                b+=arr[p][1]
                c+=arr[p][2]
            ans=max(ans,abs(a)+abs(b)+abs(c))

print(ans)




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

int main()
{
    int a; cin >> a;
    int b; cin >> b;
    int s_b = 0;
    for (int i=1; i<=b-a; ++i){
        s_b += i;
    }
    cout << s_b - b << endl;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
S = [0]*(H+2)
S[0] = '#'*(W+2)
S[H+1] = '#'*(W+2)
path_c = 0
for i in range(1,H+1):
  S[i] = '#'+input()+'#'
  path_c += S[i].count('.')
#print(S)
visited = [[False]*(W+2) for _ in range(H+2)]
import queue
q = queue.Queue()
q.put((1,1,1))
visited[1][1]=True
dh = [1,0,-1,0]
dw = [0,1,0,-1]
ans = -1
while not q.empty():
  h,w,c = q.get()
  for i in range(4):
    y,x = h+dh[i],w+dw[i]
    #print(y,x)
    if y == H and x == W:
      c += 1
      ans = path_c-c
      break
    if S[y][x]=='.' and visited[y][x]==False:
      #print(y,x,c)
      q.put((y,x,c+1))
      visited[y][x]=True
  else:
      continue
  break
print(ans)

Measured memory_bytes: 4080
using System;


public class C{
	
	public static void Main(){
	
		string str = Console.ReadLine();
		long k = Int64.Parse( Console.ReadLine() );
		
		int[] number = new int[str.Length];
		for( int i = 0; i < str.Length; i++ ){
			number[i] = Int32.Parse( str.Substring(i,1) );
		}
		
		long sum = 0;
		for( int i = 0; i < str.Length; i++ ){
			if( number[i] == 1 ){
				sum++;
				if( sum >= k ){
					Console.WriteLine(1);
					break;
				}
				
			}else{
				Console.WriteLine(number[i]);
				break;
				
			}
		}

	}

}

Measured memory_bytes: 13140