akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
#define F first
#define S second
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){

    int n;
    cin >> n;
    vector <int> a(n);
    double p = 0;
    REP(i,n){
        cin >> a[i];
        p += (double)a[i];
    }
    p /= n;
    double s = 1000000.0;
    int m = 0;
    REP(i,n){
        double sa = abs(p - (double)a[i]);
        if(s > sa){
            m = i;
            s = sa;
        }
    }
    cout << m << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        long[] h = new long[N];
        
        int cnth = 0;
        for(int i = 0; i < N; i++){
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            h[i] = sc.nextLong();
            if(h[i] > 0){
                cnth++;
            }
        }

        boolean bl = false;
        int ansx = 0;
        int ansy = 0;
        long ansh = 0;
        for(int cx = 0; cx <= 100; cx++){
            for(int cy = 0; cy <= 100; cy++){
                bl = true;
                int index = -1;
                for(int i = 0; i < N; i++){
                    if(h[i] > 0){
                        index = i;
                    }
                }

                long H = h[index] + Math.abs(x[index] - cx) + Math.abs(y[index] - cy);

                for(int i = 0; i < N; i++){
                    if( h[i] != Math.max(0, H -  Math.abs(x[i] - cx) - Math.abs(y[i] - cy))){
                        bl = false;
                        break;
                    }
                }
                if(bl == true){
                    ansx = cx;
                    ansy = cy;
                    ansh = H;
                    break;
                }
            }
        }
        System.out.println(ansx + " " + ansy + " " + ansh);
    }
}


Measured memory_bytes: 24788
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

string str;
int i;
int main()
{
	cin>>str;
	for(i = 0;i<2;i++)
	{
		if(str[i]==str[i+1]&&str[i+1]==str[i+2])
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
 return 0;
}

Measured memory_bytes: 256
A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i

ans = 0

(A+1).times do |i|
  (B+1).times do |j|
    (C+1).times do |k|
      if (i * 500 + j * 100 + k * 50 == X) then
        ans += 1
      end
    end
  end
end
  
puts ans

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

const long INF = 1L << 60;

int a[410];
long dp[410][410];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	auto sum_lr = [&](int l, int r){
					  long sum = 0;
					  for(int i = l; i <= r; i++)
						  sum += a[i];
					  return sum;
				  };
	for(int l = n-1; l >= 0; l--) {
		for(int r = l; r < n; r++) {
			if(l == r) {
				dp[l][r] = 0;
			}else{
				dp[l][r] = INF;
				long sum = sum_lr(l, r);
				for(int i = l; i <= r-1; i++)
					dp[l][r] = min(dp[l][r], dp[l][i] + dp[i+1][r] + sum);
			}
		}
	}
	printf("%ld\n", dp[0][n-1]);
}


Measured memory_bytes: 1536
// LNU_Algotesters
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <fstream>
#include <complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 2000 + 47;
const double EPS = 1e-9;




int main()
{
    
   // freopen("in.txt", "r", stdin);
    //ios::sync_with_stdio(false); cin.tie(0);

    int n, m;
    cin >> n >> m;
    string s;
    int tot = 0;
    FOR(i, 0, n)
    {
        cin >> s;
        FOR(j, 0, m)
        tot += s[j] == '#';
    }
    if (tot == n + m - 1)
        cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n, m = 0;
	cin >> n;
	int arr[100];
	for (int j = 0; j < n; j++) {
		cin >> arr[j];
	}

	for (int i = 0; i < n; i+=2) {
		if (arr[i] % 2 != 0)
			m++;
	}
	cout << m;
}

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



int main()
{
    ll ans = 0;
    string s;
    cin >> s;

    rep(i, 0, 1 << s.size())
    {
        if (!(i & 1)) continue;
        ll sum = 0;
        ll cur = 0;
        rep(j, 0, s.size())
        {
            cur *= 10;
            cur += s[j] - '0';

            if ((1 << (s.size() - 1 - j)) & i)
            {
                sum += cur;
                cur = 0;
            }
            // cout << sum << ' ' << cur << endl;
        }
        // cout << sum << endl;
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}

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

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

const ll MOD_VERYBIG = 1e15;
const ll MOD_VERYBIG2 = 1e13;


int main(void){
    ll k;
    string s;
    cin >> k;
    cin >> s;
    if(s.length() <= k){
        cout << s << endl;
    }else{
        cout << s.substr(0,k) << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

/*
a op b
 */
int a,b;
char op;

int main(){
  cin>>a;
  cin>>op;
  cin>>b;

  if(op=='+')
    cout << a+b << endl;
  else
    cout << a-b << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int c = s.indexOf("C");
		int f = s.substring(c+1).indexOf("F");
		
		System.out.println(c>=0 && f>=0 ? "Yes" : "No");
		
		sc.close();
	}
}


Measured memory_bytes: 9556
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;
int l,m,n,i,j,k,a,b,c,u,v,x,y,move,rem,cnt;


struct UnionFind{
  std::vector<int> par;
  std::vector<int> sizes;
  //std::vector<int> rank;

  //initial
  UnionFind(int n) : par(n), sizes(n) {
    //std::vector<int> rank;
    for(i=0; i<n; i++){
      par[i]=i;
      sizes[i]=1;
      //rank[i]=0;
    }
  }

  int root(int x){
    return par[x]==x ? x : par[x]=root(par[x]);
  }

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

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

  void unite(int x, int y){
    x=root(x);
    y=root(y);
    if (x==y) return;

    par[x]=y;
    sizes[y] += sizes[x];
    return;
  }
};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::vector<long> back_and_reachable;
  std::vector<pair<int, int> > edges;

  long long n,m;

  cin >> n >> m;

  UnionFind tree(n);

  for(i=0; i<m; i++){
    cin >> u >> v;
    edges.push_back(pair<int, int>(u-1,v-1));
  }

  back_and_reachable.push_back(0);

  for(i=0; i<m-1; i++){
    pair<int, int> p=edges[m-1-i];
    u=p.first;
    v=p.second;

    if(tree.same(u,v)==true){
      back_and_reachable.push_back(back_and_reachable[i]);
    }else{
      back_and_reachable.push_back(back_and_reachable[i] + tree.size(u)*tree.size(v));
      tree.unite(u,v);
    }

  }

  long long a=(n*(n-1))/2;

  for(i=0; i<m; i++){
    cout << a-back_and_reachable[m-i-1] <<endl;
  }

  return 0;
}

/*


  vector<int> vc;
  while(n--){
    int x;
    cin >> x;
    vc.push_back(x);
  }

  sort(vc.begin(), vc.end());

  int x;
  cin >> x;
  if(binary_search(vc.begin(), vc.end(), x))
    cout << "I found " <<x<<"\n";
  vector<int>::iterator lit=lower_bound(vc.begin(), vc.end(), x);
  vector<int>::iterator uit=upper_bound(vc.begin(), vc.end(), x);

  if(lit != vc.end() && lit != uit){
    cout << uit-lit << "\n";
  }
}

string str;
str ="I like an apple";
str[3]='o';
str[4]='v';

if(str.length() >=5)
  cout << str <<"\n";

if(str.find("an") != string::npos)
  cout << str.find("an") <<"\n";

  map<char, int> mp;
  mp['a']=1;
  mp['b']=2;
  cout<<mp['a']<<" "<<mp['b']<<"\n";

  mp.insert(map<char, int>::value_type('c', 3));
  if(mp.find('c') != mp.end())
    cout<<mp['c']<<"\n";
}

  vector<int> vc;

  int x;
  cin >> x;

  while(x--){
    int y;
    cin >> y;
    vc.push_back(y);
  }

  x=vc.size()/2;

  if(vc[x]==vc.at(x))
    cout << x << "\n";
}
*/


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

int main(){
	int n;
	int result = 0;
	scanf("%d", &n);
	while(n > 0){
		result += n;
		n--;
	}
	printf("%d\n", result);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
long long N;
long long A[100001];
int main(){
	cin>>N;
	REP(i,N){
	   cin>>A[i];
	}
	long long a=1;
	long long count=0;
	REP(i,N){
	    //cout<<i<<" "<<count<<" "<<a<<endl;;
	    if(i==0){
	       count+=A[i]-1;
	       a++;
	       continue;
	    }
	    if(A[i]<a){
	       continue;
	    }
	    if(A[i]==a){
	       a++;
	       continue;
	    }
	    count+=(A[i]-1)/a;
	}
        cout<<count<<endl;
	return(0);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
    int n, k, sum=0;
    cin >> n >> k;
    rep(i, n){;
        int x, a=0, b=0;
        cin >> x;
        a = x*2;
        b = (k-x)*2;
        if(a > b) sum += b;
        else sum += a;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    int w, h, x, y;
    cin >> w >> h >> x >> y;
    ld ar = 1.0*w*h/2.0;
    cout << setprecision(10) << fixed << ar << " ";
    if(2*x == w && 2*y == h)
        cout << "1";
    else
        cout << "0";    
    return 0;
}

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

using namespace std;
int main(){
    int n,m,counter=0;
    double sum=0,base;
    cin >> n >> m;
    array<int,1000> ai;
    //総得票数を数える
    for(int i = 0; i < n; i++){
        cin >> ai[i];
        sum += ai[i];
    }

    base = sum /((double)4*(double)m);
    //条件を満たしている要素をカウントする
    for(int i = 0; i<n; i++){
        if((double)ai[i] >= base){
            counter++;
        }

    }
    if(counter >= m){
        cout << "Yes";
    }else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			int[] wx = new int[n];
			int[] wy = new int[n];
			int[] r  = new int[n];
			for(int i = 0; i < n; i++) {
				wx[i] = sc.nextInt();
				wy[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}
			
			int m = sc.nextInt();
			int[] tx = new int[m];
			int[] ty = new int[m];
			int[] sx = new int[m];
			int[] sy = new int[m];
			for(int i = 0; i < m; i++) {
				tx[i] = sc.nextInt();
				ty[i] = sc.nextInt();
				sx[i] = sc.nextInt();
				sy[i] = sc.nextInt();
			}
			
			IN:for(int i = 0; i < m; i++) {
				for(int j = 0; j < n; j++) {
					if(judgeHitScopeLine(tx[i],ty[i],sx[i],sy[i],wx[j],wy[j],r[j])) {
						System.out.println("Safe");
						continue IN;
					}
				}
				System.out.println("Danger");
			}
		}
	}
	static boolean check(int x, int y, int r, int x1, int y1) {
		return Math.pow(x - x1, 2) + Math.pow(y - y1, 2) < r * r ? true : false;
	}
	static int product(int x1 ,int y1, int x2, int y2) {
		return (( x1 * x2 ) + ( y1 * y2 ));
	}

	static public boolean judgeHitScopeLine(int tx, int ty, int sx, int sy,int x, int y, int r) {
		if(check(x,y,r,tx,ty) && check(x,y,r,sx,sy)) return false;
		if(check(x,y,r,tx,ty) || check(x,y,r,sx,sy)) return true;
		int Vx = tx - sx;
		int Vy = ty - sy;
		int Cx = x - sx;
		int Cy = y - sy;
		int n1,n2,n3;
		
		n1 = product(Vx,Vy,Cx,Cy);
		n2 = product(Vx,Vy,Vx,Vy);
		n3 = product(Cx,Cy,Cx,Cy);
		
		if (n1 < 0 || n1 > n2) {
		    return false;
		}
		return (n3 - (n1 * n1 / n2) <= Math.pow(r, 2)) ? true : false;

	}
	

}

Measured memory_bytes: 25844
using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cassert>
#define N 310
#define mo 1000000007
#define ll long long
int n;
int bz[N*2];
int f[N*2][N][N];
inline void add(int &a,ll b){a=(a+b)%mo;}
int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	scanf("%d",&n);
	for (int i=n;i>=1;--i){
		int x,y;
		scanf("%d%d",&x,&y);
		if (x!=-1 && y!=-1)
			bz[x]=-1,bz[y]=-1;
		else if (x!=-1)
			bz[x]=1;
		else if (y!=-1)
			bz[y]=1;
	}
	int tmpn=n;
	n=0;
	for (int i=1;i<=tmpn*2;++i)
		if (bz[i]!=-1)
			bz[++n]=bz[i];
	n>>=1;
	f[2*n+1][0][0]=1;
	for (int i=2*n+1;i>1;--i)
		for (int j=0;j<=2*n-i+1 && j<=n;++j)
			for (int k=0;j+k<=2*n-i+1 && k<=n;++k){
				ll tmp=f[i][j][k];
				if (!tmp)
					continue;
				if (bz[i-1]==1){
					add(f[i-1][j][k+1],tmp);
					if (j)
						add(f[i-1][j-1][k],tmp);
				}
				else{
					add(f[i-1][j+1][k],tmp);
					if (j)
						add(f[i-1][j-1][k],tmp);
					if (k)
						add(f[i-1][j][k-1],tmp*k);
				}
			}
	int cnt=0;
	ll ans=1;
	for (int i=1;i<=2*n;++i) 
		if (bz[i]==1)
			cnt++;
	for (int i=1;i<=n-cnt;++i)
		ans=ans*i%mo;
	ans=ans*f[1][0][0]%mo;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 227072
N = int(input())
hon=[2,4,5,7,9]
pon=[0,1,6,8]
bon=[3]

if N < 10:
  if N in hon:
    print('hon')
  elif N in pon:
    print('pon')
  else:
    print('bon')
elif N < 100:
  amari=N%10
  if amari in hon:
    print('hon')
  elif amari in pon:
    print('pon')
  else:
    print('bon')
else:
  amari=N%100
  amari=amari%10
  if amari in hon:
    print('hon')
  elif amari in pon:
    print('pon')
  else:
    print('bon')


Measured memory_bytes: 9152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{

		int su1[][] = new int [3][10];
		int su2[][] = new int [3][10];
		int su3[][] = new int [3][10];
		int su4[][] = new int [3][10];

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int count = Integer.parseInt(br.readLine());

		int bill = 0;
		int floor = 0;
		int room = 0;
		int person = 0;

		for(int i = 0; i < count; i++){
			String str = br.readLine();
			String[] s = str.split(" ");

			bill = Integer.parseInt(s[0]);
			floor = Integer.parseInt(s[1]);
			room = Integer.parseInt(s[2]);
			person = Integer.parseInt(s[3]);


			if(bill == 1){
				su1[floor - 1][room - 1] += (person);
			}else if(bill == 2){
				su2[floor - 1][room - 1] += (person);
			}else if(bill == 3){
				su3[floor - 1][room - 1] += (person);
			}else if(bill == 4){
				su4[floor - 1][room - 1] += (person);
			}
		}
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 10; j++){
				System.out.print(" "+su1[i][j]);
			}
			System.out.println();
		}
		System.out.println("####################");
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 10; j++){
				System.out.print(" "+su2[i][j]);
			}
			System.out.println();
		}
		System.out.println("####################");
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 10; j++){
				System.out.print(" "+su3[i][j]);
			}
			System.out.println();
		}
		System.out.println("####################");
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 10; j++){
				System.out.print(" "+su4[i][j]);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 24788
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <iomanip>
typedef long long LL;
using namespace std;
typedef pair<int, int> Pii;
typedef pair<LL, LL> PLL;
const int maxn = 2E5 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string S, T;
	cin >> S >> T;
	int len = S.length();
	int mp[maxn];
	bool ok = true;
	memset(mp, -1, sizeof(mp));
	for(int i = 0; i <= len - 1; i++){
		if(mp[S[i]] == -1){
			mp[S[i]] = T[i];
		}else{
			if(T[i] != mp[S[i]]){ puts("No"); return 0;}
		}
	}
	memset(mp, -1, sizeof(mp));
	for(int i = 0; i <= len - 1; i++){
		if(mp[T[i]] == -1){
			mp[T[i]] = S[i];
		}else{
			if(S[i] != mp[T[i]]){ puts("No"); return 0;}
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1684
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 111;
int M[MAXN];
int sum[MAXN];
vi C[MAXN];
int now[MAXN];

string solve(int n, int d) {
    memset(sum, 0, sizeof(sum));
    memset(now, 0, sizeof(now));
    int need = 0;
    for (int i = 0; i < n; i++) {
        C[i].clear();
        cin >> M[i];
        need += M[i];
        C[i].resize(M[i]);
        for (int j = 0; j < M[i]; j++) {
            cin >> C[i][j];
            sum[i] += C[i][j];
        }
        reverse(C[i].begin(), C[i].end());
    }
    for (int t = 0; t < need; t++) {
        int index = -1;
        for (int i = 0; i < n; i++) {
            if (now[i] == M[i]) continue;
            sum[i] -= C[i][now[i]];
            if ((*max_element(sum, sum+n)) - d <= sum[i]) {
                index = i;
            }
            sum[i] += C[i][now[i]];
        }
        if (index == -1) return "No";
        sum[index] -= C[index][now[index]++];
    }
    return "Yes";
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, d;
    while (cin >> n >> d) {
        if (n==0 &&d==0) break;
        cout << solve(n, d) << endl;
    }
    return 0;
}

Measured memory_bytes: 3212
import Foundation
#if os(OSX) || os(iOS)
    import Darwin
#elseif os(Linux)
    import Glibc
#endif
var n = 0, m = 0, a = 0, b = 0
withUnsafeMutablePointer(&n){withVaList([COpaquePointer($0)]){vscanf("%d",$0)}}
withUnsafeMutablePointer(&m){withVaList([COpaquePointer($0)]){vscanf("%d",$0)}}
var sx = UnsafeMutablePointer<Bool>.alloc(n+1)
var xe = UnsafeMutablePointer<Bool>.alloc(n+1)
memset(sx, 0, n+1)
memset(xe, 0, n+1)
for i in 0..<m {
    withUnsafeMutablePointer(&a){withVaList([COpaquePointer($0)]){vscanf("%d",$0)}}
    withUnsafeMutablePointer(&b){withVaList([COpaquePointer($0)]){vscanf("%d",$0)}}
    if a == 1 {
       sx.advancedBy(b).memory = true
    } else if b == n {
       xe.advancedBy(a).memory = true
    }
}
var ans = "IMPOSSIBLE"
for i in 0..<n {
    if sx.advancedBy(i).memory && xe.advancedBy(i).memory {
        ans = "POSSIBLE"
        break
    }
}
print(ans)
sx.dealloc(n+1); xe.dealloc(n+1)

Measured memory_bytes: 1408
#include <stdio.h>

int main() {

	int i;
	int j;
	int H;
	int W;

	while (true) {

		scanf("%d%d", &H, &W);

		if (H == 0 && W == 0) {
			break;
		}

		for (i = 0; i < H; i++) {

			for (j = 0; j < W; j++) {

				if ( ( i + j )%2 == 0 ) {

					printf("#");

				}

				else {

					printf(".");

				}

			}

			printf("\n");

		}
		printf("\n");
	}

	return 0;

} 


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

int main() {
    string str;
    int k;
    cin>>k;
    cin.ignore();
    getline(cin,str);
    if(str.length()<=k)
    {
        cout<<str;
    }
    else
    {
        cout<<str.substr(0,k)<<"...";
    }
    
	// your code goes here
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)n;i++)
using ll = long long;

constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 510000;

long long mod_pow(long long n, long long p, long long m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        long long t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}

long long modinv(long long a, long long mod) {
    return mod_pow(a, mod - 2, mod);
}

ll fact[MAX], inv[MAX];

void COM_init() {
    fact[0] = fact[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fact[i] = fact[i - 1] * (ll)i % MOD;
    }
    inv[MAX - 1] = mod_pow(fact[MAX - 1], MOD - 2, MOD);
    for (int i = MAX - 1; i > 0; i--) {
        inv[i - 1] = inv[i] * (int)i % MOD;
    }
}

ll nPk(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fact[n] * inv[n - k] % MOD;
}

ll nCk(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return nPk(n, k) * inv[k] % MOD;
}

int main() {
    // comination 前計算
    COM_init();
    int n, m;
    cin >> n >> m;
    ll ans = 0;
    rep(i, n + 1) { // i = かぶり
        ll res = nCk(n, i) * nPk(m, i) % MOD * nPk(m - i, n - i) % MOD * nPk(m - i, n - i) % MOD;
        if (i % 2 == 0) ans += res;
        else ans -= res;
        ans %= MOD;
    }
    if (ans < 0) ans += MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11612
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int[] ms = new int[10];
    for (int ii = 0; ii < 10; ii++) {
      ms[ii] = scanner.nextInt();
    }
    java.util.Arrays.sort(ms);
    System.out.println(ms[9]);
    System.out.println(ms[8]);
    System.out.println(ms[7]);
  }
}

Measured memory_bytes: 17164
#include <iostream>
#include <vector>
#include <cmath>
 
using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    
    int kard[3] = {A, B, C};
    int number[3] = {1, 0, -1};
    int sum=0;
    for(int i=0; i<3; i++){
        if(K-kard[i]>0){
            sum=sum+kard[i]*number[i];
            K=K-kard[i];
        }else{
            sum=sum+K*number[i];
            break;
        }
    }
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int main(){
  int a, b, q; cin >> a >> b >> q;
  vector<ll> s(a), t(b), x(q);
  rep(i, a) cin >> s[i];
  rep(i, b) cin >> t[i];
  rep(i, q) cin >> x[i];
  s.push_back(INF);
  s.push_back(-INF);
  t.push_back(INF);
  t.push_back(-INF);
  sort(all(s));
  sort(all(t));

  rep(i, q){
    int la=0, ra=a+1;
    while(ra-la > 1){
      int ma = (la+ra)/2;
      if(x[i] >= s[ma]) la = ma;
      else ra = ma;
    }
    int lb=0, rb=b+1;
    while(rb-lb > 1){
      int mb = (lb+rb)/2;
      if(x[i] >= t[mb]) lb = mb;
      else rb = mb;
    }

    ll res = INF;
    chmin(res, max(abs(s[la]-x[i]), abs(t[lb]-x[i])));
    chmin(res, max(abs(s[ra]-x[i]), abs(t[rb]-x[i])));
    chmin(res, min(abs(s[la]-x[i]), abs(t[rb]-x[i])) + abs(t[rb]-s[la]));
    chmin(res, min(abs(s[ra]-x[i]), abs(t[lb]-x[i])) + abs(t[lb]-s[ra]));

    cout << res << endl;
  }

  return 0;
}


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

int main() {
  
  int H, W; cin >> H >> W; char table[H][W];
  
  vector<int> vecH, vecW;
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> table[i][j];
    }
  }
  
  for (int i = 0; i < H; i++) {
    int tmp = 0;
    for (int j = 0; j < W; j++) {
      if (table[i][j] == '.') tmp++;
    }
    if (tmp == W) vecH.push_back(i);
  }
  
  for (int i = 0; i < W; i++) {
    int tmp = 0;
    for (int j = 0; j < H; j++) {
      if (table[j][i] == '.') tmp++;
    }
    if (tmp == H) vecW.push_back(i);
  }
  
  for (int i = 0; i < H; i++) {
    
    bool lineFlag = true; bool Hflag = true;
    
    for (int x : vecH) {
      if (x == i) {
        Hflag = false;
        lineFlag = false;
      }
    }
    
    if (Hflag) {
    
      for (int j = 0; j < W; j++) {
        
        bool Wflag = true;
        
        for (int y : vecW) {
          if (y == j) Wflag = false;
        }
        
        if (Wflag) cout << table[i][j];
        
      }
      
    }
    
    if (lineFlag) cout << endl;
    
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  string s; 
  cin >> s;
  s.push_back('T');

  int x, y;
  cin >> x >> y;

  bool xy = true;
  int cnt = 0;
  vector<int> X, Y;
  REP(i, s.size()){
    if(s[i] == 'F'){
      cnt++;
    }else{
      if(xy) X.emplace_back(cnt);
      else Y.emplace_back(cnt);
      cnt = 0;
      xy = !xy;
    }
  }

  int N = 10000;
  vector<vector<bool>> dp1(X.size()+1, vector<bool>(2*N, false));
  vector<vector<bool>> dp2(Y.size()+1, vector<bool>(2*N, false));
  dp1[0][N] = true;
  dp2[0][N] = true;

  REP(i, X.size()) REP(j, 2*N){
    if(!dp1[i][j]) continue;
    dp1[i+1][j+X[i]] = true;
    if(i != 0) dp1[i+1][j-X[i]] = true;
  }
  REP(i, Y.size()) REP(j, 2*N){
    if(!dp2[i][j]) continue;
    dp2[i+1][j+Y[i]] = true;
    dp2[i+1][j-Y[i]] = true;
  }

  if(dp1[X.size()][N+x] && dp2[Y.size()][N+y]) Yes;
  else No;

  return 0;
}

Measured memory_bytes: 20096
//2017-11-5
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

#define pb push_back
#define Set(a, v) memset(a, v, sizeof(a))
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)

#define N (100000+5)
const int oo = 0x3f3f3f3f;

struct node{
	int v, w;
};

int n, dis[N];
vector<node> G[N];
bool inq[N];

void Add(int u, int v, int w){
	G[u].pb((node){v, w});
}

void Spfa(int st){
	queue<int> q;
	Set(dis, oo);
	
	int now, v, w;
	q.push(st); dis[st] = 1; inq[st] = true;
	
	while(!q.empty()){
		now = q.front(); q.pop(); inq[now] = false;
		
		For(i, 0, G[now].size()-1){
			v = G[now][i].v; w = G[now][i].w;
			
			if(dis[v] > dis[now]+w){
				dis[v] = dis[now] + w;
				if(!inq[v]){q.push(v); inq[v] = true;}
			}
		}
	}
}

int main(){
	scanf("%d", &n);
	
	For(i, 0, n-1){
		Add(i, (i+1)%n, 1);
		
		int tmp = i*10 % n;
		Add(i, tmp, 0);
	}

	Spfa(1);
	printf("%d\n", dis[0]);

	return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    int a, b, x;
    cin >> a >> b >> x;
    puts(0 <= x-a && x-a <= b ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 256
use std::cmp;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let ab = (0..n)
        .map(|_| (sc.read(), sc.read()))
        .collect::<Vec<(u64, u64)>>();
    let a_sum = ab.iter().map(|&(a, _)| a).sum::<u64>();
    let b_sum = ab.iter().map(|&(_, b)| b).sum::<u64>();

    println!("{}", cmp::min(cmp::min(a_sum, b_sum), solve(ab)));
}

fn solve(ab: Vec<(u64, u64)>) -> u64 {
    let n = ab.len();

    let mut v = vec![];
    for (i, (a, b)) in ab.into_iter().enumerate() {
        v.push((a, true, i));
        v.push((b, false, i));
    }
    v.sort();

    let mut count = vec![0; n];
    let mut sum = 0;
    for &(x, _, i) in v.iter().take(n) {
        count[i] += 1;
        sum += x;
    }
    if count.into_iter().any(|c| c == 2) {
        sum
    } else {
        let first = v
            .iter()
            .rev()
            .skip(n)
            .filter(|&&(_, _, i)| i != v[n].2)
            .map(|&(x, _, _)| x)
            .next()
            .unwrap();
        let second = v
            .iter()
            .rev()
            .skip(n)
            .filter(|&&(_, _, i)| i != v[n + 1].2)
            .map(|&(x, _, _)| x)
            .next()
            .unwrap();
        cmp::min(sum - first + v[n].0, sum - second + v[n + 1].0)
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 15044
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n;
int w[1010], s[1010], v[1010];
int order[1010];
LL dp[1010][20202];
 
int main(){
    cin >> n;
    REP(i, n)cin >> w[i] >> s[i] >> v[i];
    REP(i, n)order[i] = i;
    sort(order, order + n, [&](int a, int b){return w[a] + s[a] < w[b] + s[b];});
    REP(i, n){
        int cur = order[i];
        REP(j, 20202)dp[i + 1][j] = dp[i][j];
        for(int j = 0;j <= s[cur];j++){
            if(j + w[cur] < 20202)dp[i + 1][j + w[cur]] = max(dp[i + 1][j + w[cur]], dp[i][j] + v[cur]);
        }
    }
    LL ans = 0;
    REP(i, 20202)ans = max(ans, dp[n][i]);
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
#define INF (1<<29)
#define INFF 0x7fffffff
#define LINF (1ll<<60)
#define LINFF 0x7fffffffffffffff
#define PI 3.14159265359
#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'

ll dp[110][100005] = {};

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

    int n, W;cin>>n>>W;
    pair<ll, ll>item[110];
    for(int i = 0;i < n;i++){
        ll w, v;cin>>w>>v;
        item[i] = mp(w, v);
    }

    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= W;j++){
            if (i*j == 0) dp[i][j] = 0;
            else{
                ll w = item[i-1].first;
                ll v = item[i-1].second;
                if (j-w >= 0) dp[i][j] = max(dp[i-1][j], v+dp[i-1][j-w]);
                else dp[i][j] = dp[i-1][j];
            }
        }
    }

    cout << dp[n][W] << endl;

    return 0;
}


Measured memory_bytes: 80128
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef short SHORT;
typedef unsigned short USHORT;
typedef int INT;
typedef unsigned int UINT;
typedef long long LLONG;
typedef unsigned long long ULLONG;

#define LengthOf(x)    (sizeof(x) / sizeof(x[0]))

#if 1
//後から解く
//No.4
int main()
{
	//2019 = 3 * 673
	CHAR* S = new char[200000 + 1];
	//string S;		//stringに200000文字ぶち込むとエラーが出るらしい。
	cin >> S;
	int length = strlen(S);

	map<int, int> mod2019;	//value, count
	mod2019.insert(pair<int, int>(0, 1));	//最後の桁まで使って2019で割れる場合のペア。

	LLONG ten = 1;
	LLONG number = 0;
	for (int i = 0; i < length; ++i) {
		number = (S[length - 1 - i] - '0') * ten + number;
		//cout << number << " % 2019 = " << number % 2019 << endl;

		int mod = number % 2019;
		if (mod2019.find(mod) == mod2019.end()) {
			//追加
			mod2019.insert(pair<int, int>(mod, 1));
		}
		else {
			mod2019[mod] += 1;	//カウント追加
		}

		ten *= 10;
		ten %= 2019;
	}

	LLONG count = 0;
	for (pair<int, int> mod : mod2019) {
		count += mod.second * (mod.second - 1) / 2;
	}

	cout << count;

	return 0;
}
#endif

Measured memory_bytes: 3836
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int r,g,b;
    cin>>r>>g>>b;
    if((r*100+g*10+b)%4==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
string str;
vector<int> pos[2];
vector<string> vec;
string work(int l, int r)
{
	int x = -1, y = -1;
	for (int i = 0; i < (int)pos[0].size(); i++) {
		if (l <= pos[0][i] && pos[0][i] <= r) {
			if (-1 == x) {
				x = i;
			}
			y = i;
		}
	}
	string res;
	if (pos[0][x] < pos[1][x]) {
		int lst = l - 1;
		for (int i = x; i <= y; i++) {
			if (pos[0][i] > lst) {
				res += "ab";
				lst = pos[1][i];
			}
		}
		return res;
	}
	for (int i = x; i <= y; i++) {
		string tmp;
		for (int j = l; j <= r; j++) {
			if (j >= pos[str[j] - 'a'][i]) {
				tmp += str[j];
			}
		}
		res = max(res, tmp);
	}
	return res;
}
int main()
{
	// freopen("AGC026-E.in", "r", stdin);
	int n;
	cin >> n >> str;
	for (int i = 0; i < n << 1; i++) {
		pos[str[i] - 'a'].pb(i);
	}
	int cur = 0, lst = 0;
	for (int i = 0; i < n << 1; i++) {
		cur += str[i] == 'a' ? 1 : -1;
		if (!cur) {
			vec.pb(work(lst, i));
			lst = i + 1;
		}
	}
	string ans;
	for (int i = vec.size() - 1; i >= 0; i--) {
		ans = max(ans, vec[i] + ans);
	}
	cout << ans << endl;
	return 0;
}


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

int main(void){
  while(true){
    int n, r;
    cin >> n >> r;
    if(n == 0 && r == 0){ break; }

    int p, c;
    vector<int> hanafuda(n);
    for(int i = 0; i < n; i++){ hanafuda[i] = n - i; }
    for(int i = 0; i < r; i++){
      cin >> p >> c;
      --p;
      vector<int> tmp;
      for(int j = p; j < p + c; j++){ tmp.push_back(hanafuda[j]); }
      for(int j = p - 1; j >= 0; j--){ hanafuda[j + c] = hanafuda[j]; }
      for(int j = c - 1; j >= 0; j--){ hanafuda[j] = tmp[j];}
    }
    cout << hanafuda[0] << endl;
  }
  return 0;
}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    string S;
    cin >> S;
    ll K;
    cin >> K;
    char ans = '1';
    for(int i = 0; i < min((ll)S.length(), K); i++) {
        if(S[i] != '1') {
            ans = S[i];
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

ls = []

for i in range(n):
  s, p = map(str,input().split())
  sp = [s,int(p)]
  sp.append(i+1)
  ls.append(sp)
  
ls_sort = sorted(ls, key=lambda x: (x[0],-x[1]))

for i in ls_sort:
  print(i[2])

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<string>> S(H, vector<string>(W));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> S.at(i).at(j);
      cout << S.at(i).at(j) << endl;
      cout << S.at(i).at(j) << endl;
    }
  }
}

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


int main(){


    int n, i;

    string s;

    double a = 0;

    double b;


    cin >> n;


    for( i = 1 ; i <= n ; i = i + 1 ){

         cin >> b >> s;

         if( s == "BTC" ) b = b * 380000.0;

         a += b;

         }


    cout << a << endl;

    return 0;

    }


Measured memory_bytes: 256
readlines.each do |l|
	l1 = l2 = Array.new
	l.chomp.each_char{|c| l1 << c.to_i}
	9.times do
		0.upto(l1.size-2) do |i|
			l2[i] = (l1[i] + l1[i+1]) % 10
		end
		l1 = l2
	end
	puts l2.first
end

Measured memory_bytes: 6100
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

using ll = long long;

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

    cout << max(c - (a - b), 0) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
                 
        class Main{
            public static void main(String[] args) {
                
                try(Scanner sc = new Scanner(System.in)){
         
                    String str = sc.next();
                    String str3 = str.substring(2, 3);
                    String str4 = str.substring(3, 4);
         
                    String str5 = str.substring(4, 5);
                    String str6 = str.substring(5, 6);
         
                    if(str3.equals(str4) && str5.equals(str6))System.out.println("Yes");
                    else System.out.println("No");
                    
                }catch(Exception e){
                    e.printStackTrace();
                }        
            }
        }

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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

ll func(ll H)
{
    if (H == 1)
    {
        return 1;
    }
    else
    {
        return 2 * func(floor(H / 2)) + 1;
    }
}

int main()
{

    double H;
    ll ans = 0;
    cin >> H;
    ll tmp = 0;

    cout << func(H) << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

ll q, h, s, d;
ll n;

int main() {
	cin >> q >> h >> s >> d;
	cin >> n;
	n *= 4;
	int eight = 0, four = 0, two = 0;
	while (n - 8 >= 0) {
		++eight;
		n -= 8;
	}
	while (n - 4 >= 0) {
		++four;
		n -= 4;
	}
	while (n - 2 >= 0) {
		++two;
		n -= 2;
	}
	ll ans = eight*min({ 8 * q, 4 * h, 2 * s, d });
	ans += four*min({ 4 * q, 2 * h, s });
	ans += two*min({ 2 * q, h });
	ans += n*q;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n, x, m = map(int, input().split())
mn = min(n, m)
P = [] # value of pre & cycle
sum_p = 0 # sum of pre + cycle
X = [False] * m # for cycle check
for _ in range(mn):
    if X[x]:
        pre_len = P.index(x)
        cyc_len = len(P) - pre_len
        nxt_len = (n - pre_len) % cyc_len
        cyc_num = (n - pre_len) // cyc_len
        cyc = sum(P[pre_len:])
        remain = sum(P[:pre_len + nxt_len])
        print(cyc * cyc_num + remain)
        exit()
    X[x] = True
    P.append(x)
    sum_p += x
    x = x*x % m
print(sum_p)


Measured memory_bytes: 12052
import java.util.*;
public class Main {
	public static void main(String[] args){
    	int x=0;
        int b;
    	Scanner sc = new Scanner(System.in);
    	String a = sc.next();
    	String data[] = a.split("");
      		for(int i= 0; i < data.length; i++){
                b=Integer.parseInt(data[i]);
      			if(b==1){
        			x=x+1;
      			}
    		}
    System.out.println(x);
    }
}

Measured memory_bytes: 24916
# import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int,ipti().split()))
    color = [0] * 8
    over_3199 = 0

    for i in range(n):
        c = a[i]//400
        if c < 8:
            color[c] = 1
        else:
            over_3199 += 1

    color_sum = sum(color)
    ans_min = max(color_sum, 1)
    ans_max = color_sum + over_3199

    print(ans_min, ans_max)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
vector<int>graph[MAX];
int ans,n,m;
void dfs(int src,int used[],int tot)
{
    for(int i=0;i<graph[src].size();i++){
        int child=graph[src][i];
        if(used[child]==0){
            used[child]=1;
            dfs(child,used,tot+1);
            used[child]=0;
        }
    }
    if(tot==n)
        ans++;

}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>n>>m;
    while(m--)
    {
        int u,v;
        cin>>u>>v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    int used[20]={0};
    used[1]=1;
    dfs(1,used,1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 27048
#! /usr/bin/python3
from collections import Counter
import sys

def debug(*f):
    print(*f, file=sys.stderr)

def f(odd, even, N):
    debug(N, odd, even)


def main(N, V):
    debug("N=",N)
    debug("V=",V)
    N = int(N)
    V = [int(x) for x in V.split(" ")]

    odd = Counter(V[0::2]).most_common()
    even = Counter(V[1::2]).most_common()

    if odd[0][0] != even[0][0]: # 異なる文字
        return N - odd[0][1] - even[0][1]
    else:
        if odd[0][1] > even[0][1]:
            return N - odd[0][1] - even[1][1]
        elif odd[0][1] < even[0][1]:
            return N - odd[1][1] - even[0][1]
        elif odd[0][1] == N // 2:
            return N // 2
        else:
            return N - odd[0][1]  - max(odd[1][1], even[1][1])



if 0==1:
    import sys
    assert main("4", "3 1 3 2") == 1
    assert main("4", "1 1 1 1") == 2
    assert main("6", "105 119 105 119 105 119") == 0
    assert main("14", "1 1 1 1 1 1 2 2 2 2 3 4 3 5") == 9

    print("OK", file=sys.stderr)


N = input()
V = input()
print(main(N, V))


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

int main() {
  int L, R, A, B, C, D;
	cin >> A >> B;
	cin >> C >> D;

	L = A + B;
	R = C + D;

	if (L == R){
		cout << "Balanced" << endl;
	} 
  else if (L > R){
	  cout << "Left" << endl;
	}
  else if (L < R){
	  cout << "Right" << endl;
	}
}


Measured memory_bytes: 256