akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,L;
	while(cin>>N>>L) {
		vector<string>S(N);
		REP(i, N) cin>>S[i];
		sort(ALL(S));
		string ans=accumulate(ALL(S), string(""));
		cout<<ans<<endl;
	}
	
	return 0;
}


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

int main() {
  int m, n, a, b;
  cin >> n >> m;
  vector<int> L(m);
  vector<int> R(m);
  for (int i = 0; i < m; i++) {
    cin >> L.at(i) >> R.at(i);
  }
  a = L.at(0), b = R.at(0);
  for (int i = 1; i < m; i++) {
    if (a < L.at(i)) {
      a = L.at(i);
    }
    if (b > R.at(i)) {
      b = R.at(i);
    }
  }
  if (b - a + 1 < 1) {
    cout << 0 <<endl;
  }
  else {
    cout << b - a + 1 <<endl;
  }
}
      


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

using namespace std;

#define int long long

const double pi = 3.1415926536;

void solve() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double an = 2 * pi * (h + m / 60.0) / 12.0 - 2 * pi * m / 60.0;
    cout.precision(10);
    cout << sqrt((double)a * a + b * b - 2 * a * b * cos(an));
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 4204
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main(){
  double a,b,x;scanf("%lf%lf%lf",&a,&b,&x);
  double c = x/b*2/a;
  double d = (a*a*b-x)/a*2/a;
  if(x*2 <= a*a*b) printf("%lf\n",atan(b/c)*180/M_PI);
  else printf("%lf\n",double(90)-atan(a/d)*180/M_PI);
}

Measured memory_bytes: 4152
#import sys
#input = sys.stdin.readline
def factors(N): #約数を全て求める。ただし、順不同
    from collections import deque
    ret = deque()
    middle = int( N**(1/2))
    for i in range(1, middle):
        if N%i == 0:
            ret.append(i)
            ret.append(N//i)
            
    if N%middle == 0:
        ret.append(middle)
        if middle != N//middle:
            ret.append(N//middle)
    return ret

def main():
    N, K = map( int, input().split())
    A = list( map( int, input().split()))
    sa = sum(A)
    R = factors(sa)
    l = len(R)
    E = [0]*l
    ans = 0
    for r in R:
        cnt = 0
        E = list( map( lambda x:x%r, A))
        E.sort()
        s = sum(E)
        now = 0
        if s - E[-1] <= K:
            if ans < r:
                ans = r
            continue
        if s == 0:
            continue
        v = 0
        w = N-1
        cnt = 0
        while w-v != 0:
            if E[v] == 0:
                v += 1
                continue
            if E[w] == 0:
                w -= 1
                continue
            if E[v] + E[w] >= r:
                E[v] -= r - E[w]
                cnt += r - E[w]
                E[w] = 0
                w -= 1
            else:
                E[w] += E[v]
                cnt += E[v]
                E[v] = 0
                v += 1
        if cnt <= K:
            if r > ans:
                ans = r
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
def isYaki(S):
    if len(S) < 4:
        return 'No'
    
    answer = 'YAKI'
    for (a, b) in zip(answer, S):
        if a != b:
            return 'No'
    return 'Yes'

if __name__ == '__main__':
    S = input()
    print(isYaki(S))


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

int main(){
  string s;
  cin >> s;
  int sinti = 753;
  int sabun = 10000;

  for(int i=0;i<s.size()-2;++i){
    if(sabun > abs(sinti - atoi(s.substr(i,3).c_str()))) sabun =  abs(sinti - atoi(s.substr(i,3).c_str()));
  }

  cout << sabun << endl;


  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll INF=1e18;
struct edge {int to; ll cap; int rev;} ;

vector<edge> G[200020];
int level[200020];
int iter[200020];

void add_edge(int from, int to, ll cap){
	edge e;
	e.to=to, e.cap=cap, e.rev=G[to].size();
	G[from].push_back(e);
	e.to=from, e.cap=0, e.rev=G[from].size()-1;
	G[to].push_back(e);
}

void bfs(int s){
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(int i=0; i<G[v].size(); i++){
			edge e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}

ll dfs(int v, int t, ll f){
	if(v==t) return f;
	for(int &i=iter[v]; i<G[v].size(); i++){
		edge &e=G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			ll d=dfs(e.to, t, min(f, e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

ll max_flow(int s, int t){
	ll flow=0;
	while(1){
		bfs(s);
		if(level[t]<0) return flow;
		memset(iter, 0, sizeof(iter));
		ll f;
		while((f=dfs(s, t, INF))>0){
			flow+=f;
		}
	}
}
int main()
{
    int n, p[100010], q[100010];
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>p[i];
  }
  for(int i=0; i<n; i++){
    cin>>q[i];
  }
  int x[100010], y[100010];
  fill(x, x+n, -1);
  fill(y, y+n, -1);
  int np=0, nq=0;
  for(int i=0; i<n; i++){
    if(x[i]==-1){
      int t=i;
      while(x[t]==-1){
        x[t]=np;
        t=p[t];
      }
      np++;
    }
  }
  for(int i=0; i<n; i++){
    if(y[i]==-1){
      int t=i;
      while(y[t]==-1){
        y[t]=nq;
        t=q[t];
      }
      nq++;
    }
  }
  int s=np+nq, t=s+1;
  for(int i=0; i<n; i++){
    if(p[i]==i && q[i]==i){
      add_edge(s, x[i], 1);
      add_edge(x[i], t, 1);
    }else if(p[i]==i){
      add_edge(s, y[i]+np, 1);
    }else if(q[i]==i){
      add_edge(x[i], t, 1);
    }else{
      add_edge(x[i], y[i]+np, 1);
      if(p[i]==q[i]) add_edge(y[i]+np, x[i], 1);
    }
  }
  cout<<n-max_flow(s, t)<<endl;
	return 0;
}

Measured memory_bytes: 20224
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	ll H;
	cin>>H;
	ll cnt=0;
	ll sum=0;
	while(H>0){
		H/=2;
		sum+=(ll)pow(2,cnt);
		cnt++;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	list<int> l;

	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		char command[10];
		int key;
		cin >> command;
		if (command[0] == 'i') {
			scanf("%d", &key);
			l.push_front(key);
		}
		else if (command[6] == 'F') {
			l.pop_front();
		}
		else if (command[6] == 'L') {
			l.pop_back();
		}
		else if (command[0] == 'd') {
			scanf("%d", &key);
			for (list<int>::iterator it = l.begin(); it != l.end(); it++) {
				if (*it == key) {
					l.erase(it);
					break;
				}
			}
		}
	}

	for (list<int>::iterator it = l.begin(); it != l.end(); it++) {
		if (it != l.begin())printf(" ");
		printf("%d", *it);
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 32420
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) tsort(v); reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

lint dx[8] = { 0,1,1,1,0,-1,-1,-1 },
	 dy[8] = { 1,1,0,-1,-1,-1,0,1 };

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

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

	lint n, a;
	cin >> n >> a;
	co(n*n - a);
	gc();
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define mod 1000000007
#define int long long
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int bikkuri(int a){
	int res=1;
	rep(i,a){
		res*=(i+1);
		res%=mod;
	}
	return res;
}

signed main(){
	int n,m,ans=0;
	cin>>n>>m;
	if(abs(n-m)>1)cout<<ans<<endl;
	else{
		if(n==m)ans=bikkuri(n)*bikkuri(m)%mod*2%mod;
		else ans=bikkuri(n)*bikkuri(m)%mod;
		cout<<ans<<endl;
	}
	return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {

  int N, A, B;

  cin >> N >> A >> B;

  int ans = (N * A) < B ? (N * A) : B;

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


Measured memory_bytes: 256
#include    <iostream>
#include    <string>
#include    <stack>

using namespace std;

int main() {
    stack<int> operand;
    while(1) {
        int r, l;
        string str;

        cin >> str;
        if(cin.eof())   break;

        if(str == "*") {
            l = operand.top();
            operand.pop();
            r = operand.top();
            operand.pop();
            operand.push(r*l);
        } else if(str == "+") {
            l = operand.top();
            operand.pop();
            r = operand.top();
            operand.pop();
            operand.push(r+l);
        } else if(str == "-") {
            l = operand.top();
            operand.pop();
            r = operand.top();
            operand.pop();
            operand.push(r-l);
        } else {
            operand.push(stoi(str));
        }
    }
    cout << operand.top() << endl;

    return 0;
}


Measured memory_bytes: 3144
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>

using namespace std;
int main(void){
 int N,K;
 long long int a;
 long long int sum=0;
 long long int ans=0;
 long long int bit=1;
 vector<long long int>A;
 vector<long long int>B;

 cin>>N;
 cin>>K;
 for(int i=0; i<N;i++){
  cin>>a;
  A.push_back(a);
 }

 for(int i=0; i<N; i++){
  sum=0;
  sum+=A[i];
  B.push_back(sum);
  for(int j=i+1; j<N; j++){
   sum+=A[j];
   B.push_back(sum);
  }
 } 
 /*
 for(int i=0; i<B.size(); i++){
  std::cout<<"B size "<<B[i]<<std::endl;
 }
 */ 
 for(int i=60; i>=0; i--){
  vector<long long int> C;	
  //std::cout<<"(1<<i)"<< (1<<i) <<std::endl;
  for(int j=0; j<B.size();j++){
   if((B[j] & (bit<<i) )){
    C.push_back(B[j]);
    //std::cout<<" i B[j] "<<i<<" "<<B[j]<<std::endl;
   }
  }
  if(C.size()>=K){
   //std::cout<<" i "<<i<<std::endl;
   ans+=((long long int)1)<<i;
   B=C;
  }
 }
 std::cout<<ans<<std::endl; 
 return 0;
}

Measured memory_bytes: 6524
#ALDS 1-C: Prime Numbers
import math

n = int(input())
c = 0
for i in range(n):
    x = int(input())
    f = 1
    for j in range(2,int(math.sqrt(x))+1):
        if x % j == 0: 
            f = 0
            break
    c = c + f
print(c)



Measured memory_bytes: 5668
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >>H>>W;
  vector<vector<char>>A(H,vector<char>(W));
  for(int i = 0; i < H; i += 1) {
    for(int j = 0; j < W; j += 1) {
      cin>>A.at(i).at(j);
    }
  }
  vector<vector<char>>B(H+2,vector<char>(W+2));
  for(int i = 0; i < H+2; i += 1) {
    for(int j = 0; j < W+2; j += 1) {
      B.at(i).at(j)='#';
    }
  }
  for(int i = 0; i < H; i += 1) {
    for(int j = 0; j < W; j += 1) {
      B.at(i+1).at(j+1)=A.at(i).at(j);
    }
  }
  for(int i = 0; i < H+2; i += 1) {
    for(int j = 0; j < W+2; j += 1) {
      cout<<B.at(i).at(j);
    }
   cout<<endl;
  }
}
  
  
      


Measured memory_bytes: 256
using AtCoderBeginnerContest122.Questions;
using AtCoderBeginnerContest122.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest122.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var s = inputStream.ReadLine();

            var maxLength = 0;
            for (int l = 0; l < s.Length; l++)
            {
                for (int r = l; r < s.Length; r++)
                {
                    var length = r - l + 1;
                    if (s.Substring(l, length).All(c => c == 'A' || c == 'C' || c == 'G' || c == 'T'))
                    {
                        maxLength = Math.Max(maxLength, length);
                    }
                }
            }

            yield return maxLength;
        }
    }
}


namespace AtCoderBeginnerContest122
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest122.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest122.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

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

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

    if ((b - a) % 2 == 1 || n == 2)
        cout << "Borys" << endl;
    else
        cout << "Alice" << endl;
    return 0;
}


Measured memory_bytes: 256
s = list(input())
t = list(input())

# len of strs
n = len(s)
m = len(t)
min_ch = m

for i in range(0,n-m+1):
  diff_ch = 0
  for j in range(m):
    if s[i+j] != t[j]:
      diff_ch += 1
  min_ch = min(min_ch,diff_ch)

print(min_ch)

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

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

  if (a + b == c + d)
    cout << "Balanced" << endl;
  else if (a + b > c + d)
    cout << "Left" << endl;
  else
    cout << "Right" << endl;

}


Measured memory_bytes: 256
from collections import deque

def main():
    n,m = map(int,input().split())

    edges = [[] for _ in range(n)]

    for _ in range(m):
        a,b = map(int,input().split())
        edges[a-1].append(b-1)
        edges[b-1].append(a-1)

    q = deque([0])

    ans = [-1]*n
    ans[0] = 0
    count = 1

    while q:
        l = q.popleft()
        for i in edges[l]:
            if ans[i] == -1:
                ans[i] = l
                count += 1
                q.append(i)
        if count == n:
            break

    if count == n:
        print('Yes')
        for i in ans[1:]:
            print(i+1)
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 94968
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e7;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll l, ll r, ll val){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(start > end or l > start or r < end)
		return ;
	else if(start >= l and r >= end){
		segtree[node] += val;
		if(start != end){
			lazy[left(node)] += val;
			lazy[right(node)] += val;
		}
	}
	else{
		ll mid=(start + end)/2;
		update(left(node), start, mid, l, r, val);
		update(right(node), mid+1, end, l, r, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(right(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll a,b,c;
	cin >> a >> b >> c;
	if(c >= a and b >= c)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}


Measured memory_bytes: 3628
n = int(input())
cnt = []
for _ in range(n):
    S = input()
    c = {chr(i):0 for i in range(97, 97+26)}
    for s in S:
        c[s] += 1
    cnt.append(c)

common = {chr(i):100 for i in range(97, 97+26)}
for c in cnt:
    for k, v in c.items():
        common[k] = min(common[k], v)

result = ''
for k, v in sorted(common.items()):
    result += k * v
print(result)



Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REP(i,a,b) for(ll i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll N,M;
string S;

int main() {
    cin >> N >> M;
    cout << max(N-2*M,0LL) << endl;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<priority_queue<int>> q(n);
    int T;
    cin >> T;
    while (T--) {
        int x; cin >> x;
        if(x==0) {
            int a,b;
            cin >> a >> b;
            q[a].push(b);
        }
        if (x==1) {
            int t;
            cin >> t;
            if (!q[t].empty()) cout << q[t].top() << endl;
        }
        if (x==2) {
            int t;
            cin >> t;
            if (!q[t].empty()) q[t].pop();
        }
    }
    return 0;
}



Measured memory_bytes: 4080
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <map>

int main()
{
    char c;
    int r, n;
    bool cards[52] = {};
    std::map<char, int> suit2num;
    suit2num['S'] = 0;
    suit2num['H'] = 1;
    suit2num['C'] = 2;
    suit2num['D'] = 3;
//    std::map<char, int> suit2num = {{'S', 0}, {'H', 1}, {'C', 2}, {'D', 3}};
    char* num2suit = "SHCD";

    std::cin >> n;
    for (int i = 0; i < n; i++)
    {
        std::cin >> c >> r;
        cards[13 * suit2num[c] + r - 1] = 1;
    }
    for (int i = 0; i < 52; i++)
    {
        if (cards[i] == 0)
        {
            c = i / 13;
            r = i % 13 + 1;
            std::cout << num2suit[(int)c] << ' ';
            std::cout << r << std::endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define lli long long int 
#define ll long long 
#define f(i, n) for(int i=0; i<n; i++)

using namespace std;


void test(){
	int n;
	
	cin>>n;
	
	if(n%1000 == 0){
		cout<<0<<endl;
	}else{
		cout<<(1000 - n%1000)<<endl;
	}
}
int main(){
	
	/*int t;
	cin>>t;
	
	while(t--){
		test();
	}
	*/
	test();
	return 0;

}







Measured memory_bytes: 3616
S = input()
n = 0
if S.find("+",0,1) >= 0:
    n += 1
if S.find("+",1,2) >= 0:
    n += 1
if S.find("+",2,3) >= 0:
    n += 1
if S.find("+",3,4) >= 0:
    n += 1
print(n-(4-n))

Measured memory_bytes: 3060
#Let's go
import sys
import math
import random

sys.setrecursionlimit(100000)

br=dict()

n=int(input())
ar=list(map(int, input().split()))
cr=set(ar)

for i in range(n):
    br[ar[i]]=0
for i in range(n):
    br[ar[i]]=br[ar[i]]+1

ans=0
for xd in cr:
    times = br[xd]
    if(times < xd):
        ans = ans + times
    else:
        ans = ans + times-xd

print(ans)

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

using namespace std;

//////////////////////////////////////////////////
class SegmentTree
{
public:
    typedef long long Int;
    static const Int DEFAULT_VALUE = 0; 
    vector<Int> data;
    Int N;

    inline Int func(Int x, Int y) {
        return x + y;
    }

    inline void updateLeaf(Int v, Int val) {
        data[v] += val;
    }

    SegmentTree(vector<Int> vec) {
        Int x = 1;
        while (x < (Int)vec.size()) {
            x *= 2;
        }
        this->N = x;
        data = vector<Int>(2 * x, DEFAULT_VALUE);
        for (int i = 0; i < (Int)vec.size(); i++) {
            update(i, vec[i]);
        }
    }

    Int get(Int l, Int r) {
        return getSub(l, r, 0, N, 1);
    }

    void update(Int index, Int val) {
        Int v = index + N;
        updateLeaf(v, val);

        v /= 2;
        while (v > 0) {
            data[v] = func(data[2 * v], data[2 * v + 1]);
            v /= 2;
        }
    }

    Int getSub(Int l, Int r, Int myl, Int myr, Int v) {
        if (myr <= l || r <= myl) return DEFAULT_VALUE;
        if (l <= myl && myr <= r) return data[v];

        Int mid = (myl + myr) / 2;
        return func(getSub(l, r, myl, mid, 2 * v),
                   getSub(l, r, mid, myr, 2 * v + 1));
    }
};
//////////////////////////////////////////////////

int main() {
    int n, q;
    cin >> n >> q;
    SegmentTree seg(vector<long long>(n, 0));
    for (int i = 0; i < q; i++) {
        int c, x, y;
        cin >> c >> x >> y;
        if (c == 0) {
            seg.update(x - 1, y);
        } else {
            cout << seg.get(x - 1, y) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6020
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    print(N * N * N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
N = gets.to_i
As = gets.split.map(&:to_i)
M = 10**9 + 7

bs = (0 .. 60).map{|i| As.count{|a| a[i] == 1}}
puts (0 .. 60).inject(0){|s, i| (s + ((bs[i] * (N - bs[i])) << i)) % M}

Measured memory_bytes: 34820
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

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

    int ans = 0;
    if(n % (2 * d + 1) == 0) {
        ans = n / (2 * d + 1);
    } else {
        ans = n / (2 * d + 1);
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
// package abc127.b

import scala.io.StdIn

object Main {

  def main(args: Array[String]) {
    val Array(r, d, x2000) = StdIn.readLine().split(" ").map(e => e.toInt)
      (1 to 10).toList.foldLeft(x2000)((x, i) => {
        val nx = x * r - d
        println(nx)
        nx
      })
  }

}


Measured memory_bytes: 25428
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
 
function main(){
  var read = 0;
  var resultCase = 1;
  while(true){
    var maxWeight = +input[read++];
    if(!maxWeight){
      break;
    }
     
    var treasures = +input[read++];
    var pdp = new Int16Array(maxWeight + 1);
    for(var i = treasures; i--;){
      var c = input[read++].split(",");
      var tv = +c[0];
      var tw = +c[1];
 
      var dp = new Int16Array(maxWeight + 1);
      for(var w = 1; w <= maxWeight; w++){
        var pdpw = pdp[w];
        dp[w] = (w-tw < 0) ? pdpw : max(pdp[w-tw] + tv, pdpw);
      }
      pdp = dp;
    }
 
    var resultWeight = 1001;
    var resultCost = 0;
    for(var i = 0; i <= maxWeight; i++){
      var pdpi = pdp[i];
      if(pdpi > resultCost){
        resultCost = pdpi;
        resultWeight = i;
      }
    }
     
    console.log("Case " + resultCase++ + ":\n" + resultCost + "\n" + resultWeight);
  }
}
 
function max(a, b) {
  var t = a - b;
  return a - (t & (t >> 31));
}

Measured memory_bytes: 12376
#include <stdio.h>
 
int main()
{
    int n, x, a, b, c, ret;
    for (;;) {
        scanf("%d %d", &n, &x);
        if (n == 0 && x == 0) {
            return 0;
        }
        ret = 0;
        for (c = 1; c <= n; c++) {
            for (b = 1; b < c; b++) {
                a = x - c - b;
                if (a < b && a > 0) {
                    ret++;
                }
            }
        }
    printf("%d\n", ret);
    }
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
typedef long long ll;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=1e5+5;
const int maxP=7;
const int mod=1e9+7;
const ll oo=1e18+5;
 
struct UnionFind{
	vector<int> f;
	UnionFind(int sizee){
		f.assign(sizee,-1);
	}
	int find(int k){
		if(f[k]<0) return k;
		return f[k]=find(f[k]);
	}
	int size(int k){
		return -f[find(k)];
	}
	bool unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y) return 0;
		if(f[x]>f[y]) swap(x,y);
		f[x]+=f[y];
		f[y]=x;
		return 1;
	}
};
 
int n,m,k;

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);
	cin>>n>>m>>k;
	UnionFind UF(n);
	vector<ll> numFriend(n),numBlock(n);
	for(int i=0;i<m;++i){
		int x,y;
		cin>>x>>y;
		--x;
		--y;
		UF.unite(x,y);
		++numFriend[x];
		++numFriend[y];
	}
	for(int i=0;i<k;++i){
		int x,y;
		cin>>x>>y;
		--x;
		--y;
		if(UF.find(x)==UF.find(y)){
			++numBlock[x];
			++numBlock[y];
		}
	}
	for(int i=0;i<n;++i){
		int tot=UF.size(i);
		tot-=numBlock[i]+numFriend[i];
		cout<<tot-1<<" ";
	} 
	return 0;
}



Measured memory_bytes: 2816
import java.io.*;
import java.util.*;

class Main {
    public static void main(String args[]) throws IOException {
        Scan sc = new Scan();
        int n = sc.scanInt();
        int[] arr = new int[n+1];
        for(int i = 1; i <= n; ++i)
            arr[i] = sc.scanInt();
        int now = arr[1];
        int id = 1;
        int ct = 0;
        while(true){
            arr[id] = 0;
            id = now;
            now = arr[id];
            ++ct;
            if(id == 2 || now == 0)
                break;
        }
        if(id == 2)
            System.out.println(ct);
        else
            System.out.println(-1);
    }
}

class Scan {
    private byte[] buf=new byte[1024];
    private int index;
    private InputStream in;
    private int total;
    public Scan()
    {
        in=System.in;
    }
    public int scan()throws IOException
    {
        if(total<0)
        throw new InputMismatchException();
        if(index>=total)
        {
            index=0;
            total=in.read(buf);
            if(total<=0)
            return -1;
        }
        return buf[index++];
    }
    public int scanInt()throws IOException
    {
        int integer=0;
        int n=scan();
        while(isWhiteSpace(n))
        n=scan();
        int neg=1;
        if(n=='-')
        {
            neg=-1;
            n=scan();
        }
        while(!isWhiteSpace(n))
        {
            if(n>='0'&&n<='9')
            {
                integer*=10;
                integer+=n-'0';
                n=scan();
            }
            else throw new InputMismatchException();
        }
        return neg*integer;
    }
    public double scanDouble()throws IOException
    {
        double doub=0;
        int n=scan();
        while(isWhiteSpace(n))
        n=scan();
        int neg=1;
        if(n=='-')
        {
            neg=-1;
            n=scan();
        }
        while(!isWhiteSpace(n)&&n!='.')
        {
            if(n>='0'&&n<='9')
            {
                doub*=10;
                doub+=n-'0';
                n=scan();
            }
            else throw new InputMismatchException();
        }
        if(n=='.')
        {
            n=scan();
            double temp=1;
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    temp/=10;
                    doub+=(n-'0')*temp;
                    n=scan();
                }
                else throw new InputMismatchException();
            }
        }
        return doub*neg;
    }
    public String scanString()throws IOException
    {
        StringBuilder sb=new StringBuilder();
        int n=scan();
        while(isWhiteSpace(n))
        n=scan();
        while(!isWhiteSpace(n))
        {
            sb.append((char)n);
            n=scan();
        }
        return sb.toString();
    }
    private boolean isWhiteSpace(int n)
    {
        if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
        return true;
        return false;
    }
}

Measured memory_bytes: 21716
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.Map.Entry;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        arc061_b solver = new arc061_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class arc061_b {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int H = in.Int();
            int W = in.Int();
            int N = in.Int();

            Map<Integer, Map<Integer, Integer>> map = new HashMap<>();
            for (int n = 0; n < N; n++) {
                int a = in.Int() - 1;
                int b = in.Int() - 1;
                for (int i = 0; i < 3; i++) {
                    if (a - i < 0) continue;
                    if (a - i >= H - 2) continue;
                    for (int j = 0; j < 3; j++) {
                        if (b - j < 0) continue;
                        if (b - j >= W - 2) continue;
                        int x = a - i;
                        int y = b - j;
                        if (!map.containsKey(x)) {
                            map.put(x, new HashMap<>());
                        }
                        Map<Integer, Integer> map1 = map.get(x);
                        map1.put(y, map1.getOrDefault(y, 0) + 1);
                    }
                }
            }
            long[] ans = new long[10];
            long sum = 0;
            for (Map.Entry<Integer, Map<Integer, Integer>> e : map.entrySet()) {
                for (Map.Entry<Integer, Integer> ee : e.getValue().entrySet()) {
                    ans[ee.getValue()]++;
                }
                sum += e.getValue().size();
            }
            ans[0] = (H - 2L) * (W - 2L) - sum;
            for (int i = 0; i < 10; i++) {
                out.println(ans[i]);
            }
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



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

int field[1000];

int main()
{
	int n,m;
	while(cin >> n >> m){
		if(!n&&!m)
			break;
		for(int i=0;i<n;i++){
			cin >> field[i];
		}
		int count = 1000000000;
		int pos = 0;
		int cnt = 0;
		for(int i=0;i<m;i++){
			cnt++;
			int a;
			cin >> a;
			pos+=a;
			if(pos < n)
				pos = pos + field[pos];
			if(pos >= n-1 && count > cnt)
					count = cnt;
		}
		cout << count << endl;
	}
	return 0;
}

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

int main() {
  
  int N, X; cin >> N >> X; int minM = 1001;
  
  for (int i = 0; i < N; i++) {
    int M; cin >> M;
    X -= M; minM = min(minM, M);
  }
  
  cout << N + (X / minM) << endl;
  
}

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

int main () {
  int N;
  cin >> N;
  int data[N];
  for (int i = 0; i < N; i++) {
    cin >> data[i];
  }
  
  sort(data, data+N, greater<int>());
  int a = 0, b = 0;
  for (int i = 0; i < N; i++) {
    if (i%2 == 0) {
      a += data[i];
    }
    else {
      b += data[i];
    }
  }
  cout << a-b << endl;
}

Measured memory_bytes: 256
#![allow(unused)]

use std::cmp;
use std::io::{self, BufRead};
use std::iter;

macro_rules! destruct_ {
  ($e: expr, ()) => (
    //assert!($e.next().is_none())
  );
  ($e: expr, ($arg: ident, $( $args: ident )*)) => (
    $arg = $e.next().unwrap();
    destruct_!($e, ($($args)*))
  );
  ($e: expr, ($arg: ident $( $args: ident )*)) => (
    $arg = $e.next().unwrap();
    destruct_!($e, ($($args)*))
  );
}

macro_rules! split {
  ($e: expr, ($($name: ident)*)) => {
    let mut iter = $e.into_iter();
    destruct_!(iter, ($($name)*));
  }
}

macro_rules! gets {
  ($id: ident) => (
    let stdin = io::stdin();
    $id = Vec::new();
    for line in stdin.lock().lines() {
      $id.push(
        line
          .unwrap()
          .split_whitespace()
          .map(|a| a.parse().unwrap())
          .collect()
      );
    }
  )
}

macro_rules! get {
  ($id: ident) => (
    let stdin = io::stdin();
    $id = Vec::new();
    for line in stdin.lock().lines() {
      $id.push(
        line
          .unwrap()
          .parse().unwrap()
      );
    }
  )
}

macro_rules! p {
  ($a: expr) => (
    println!("{}", $a);
  )
}

macro_rules! pp {
  ($a: expr) => (
    println!("{:?}", $a);
  )
}

fn main() {
  let mut argss: Vec<Vec<i64>>;
  let mut args: Vec<i64>;
  let n: i64;
  let m: i64;
  let o = ((10 as u64).pow(9) + 7);
  gets!(argss);
  split!(argss, (args));
  split!(args, (n m));

  if (n - m).abs() >= 2 {
    p!(0);
  } else if (n - m).abs() == 1 {
    p!((fact(n, o) * fact(m, o)) % o);
  } else {
    p!(2 * fact(n, o) * fact(m, o) % o);
  }

}

fn fact(mut n: i64, o: u64) -> u64 {
  let mut nn = 1;
  for i in 1 .. (n + 1) as u64 {
    nn = (nn * i) % o;
  }

  nn
}


Measured memory_bytes: 4352
#include <stdio.h>
typedef long long ll;
int main(void){
  char s[101]={'\0'};
  ll k,i;
  scanf("%s",s);
  scanf("%lld",&k);
  
  for(i=0;i<k;i++){
    if(s[i]=='1') continue;
    else break;
  }
  if(i==k) printf("1");
  else printf("%c",s[i]);
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define PRINT(a)   cout << (a) << endl
#define RALL(v) rbegin(v), rend(v)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int x,y;
  cin >> x >> y;
  REP(i,x+1){
//    cout << i << " " << x - i  << endl;
    if(2*i + 4*(x-i) == y){
      PRINT("Yes");
      return 0;
    }
  }
  PRINT("No");
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const long long mk=100005;
long long arr[mk];
long long n, dp[mk];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout << dp[n-1] << endl;
}

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int a[200] = {};
    for (int i = A; i < B; i++) a[i] = 1;
    int ans = 0;
    for (int i = C; i < D; i++) ans += a[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 1111116
#define next nxt

int n,x[N],y[N],z[N],next[N],p[N],f[N],s[N];
long long ans;

int travel(int x){
	s[x]=1;int mx=0,mn=1e9;
	for (int t=p[x];t;t=next[t])
		if (y[t]!=f[x]){
			f[y[t]]=x;travel(y[t]);
			s[x]+=s[y[t]];
			mx=max(mx,s[y[t]]);
			mn=min(mn,z[t]);
			ans+=2ll*z[t]*min(s[y[t]],n-s[y[t]]);
			if (s[y[t]]*2==n) ans-=z[t];
		}
	mx=max(mx,n-s[x]);
	if (mx*2<n) ans-=mn;
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();
	for (int i=1;i<=n-1;i++){
		x[2*i-1]=y[2*i]=read();
		y[2*i-1]=x[2*i]=read();
		z[2*i-1]=z[2*i]=read();
		next[2*i-1]=p[x[2*i-1]];p[x[2*i-1]]=2*i-1;
		next[2*i]=p[x[2*i]];p[x[2*i]]=2*i;
	}
	travel(1);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 18944
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main(){
	int n,k;
	cin >> n >> k;
	vector <int> canRemove(n);
	for(int i = 0;i < n;i++){
		cin >> canRemove[i];
	}
	vector <int> dp(k+1,0);
	dp[0] = 0;
	for(int i = 1;i <= k;i++){
		int found = 0;
		for(int j = 0;j < n;j++){
			if(i - canRemove[j] >= 0){
				if(dp[i - canRemove[j]] == 0){
					found = 1;
					break;
				}
			}
		}
		dp[i] = found;
	}
	dp[k] ? cout << "First" : cout << "Second";
 	return 0;
}

Measured memory_bytes: 640
// AOJ 1147
#include<iostream>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main() {
  int n;
  while (cin >> n and n) {
    int sum = 0, mxm = -1e5, mnm = 1e5;
    REP(i, n) {
      int s;
      cin >> s;
   
      if (mxm < s) mxm = s;
      if (mnm > s) mnm = s;
   
      sum += s;
    }
   
    cout << (sum - mxm - mnm) / (n - 2) << endl;
  }
}

Measured memory_bytes: 1160
//#include <iostream>
//#include <vector>
//#include <algorithm>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main(){
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int> alive(N,K);
  vector<int> correct(N);
  rep(i,Q){
    int x;
    cin >> x;
    x--;
    correct[x]++;
  }
  rep(i,N){
    if(alive[i]-Q+correct[i]>0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;
const long long INF=1e18;

int main(){
    int v,e;
    cin >> v >> e;
    vector<vector<long long> > dif(101,vector<long long>(101,INF));
    
    for(int i = 0; i < v; i++)    dif[i][i] = 0;
    
    for(int i = 0; i < e; i++){
    	int a,b; cin >> a >> b;
        cin >> dif[a][b]; 
    }
    
    for(int k = 0; k < v; k++){
    	for(int i = 0; i < v; i++){
    		for(int j = 0; j < v; j++){
    			if(dif[i][k] == INF || dif[k][j] == INF) continue;
    			dif[i][j] = min(dif[i][j],dif[i][k] + dif[k][j]);
    		}
    	}
    }
    bool can = false;
    for(int i = 0; i < v; i++){
    	if(dif[i][i] < 0) can = true;
    }
    if(can)  cout << "NEGATIVE CYCLE" << endl;
    else{
    	for(int i = 0; i < v; i++){
    		for(int j = 0; j < v; j++){
    			if(dif[i][j] == INF) 	cout << "INF";
    			else                    cout << dif[i][j];
    			if(j != v-1)  cout << ' ';
    		}
    		cout << endl;
    	}
    }
     return 0;	
}


Measured memory_bytes: 3244