akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iomanip>


using namespace std;

int main()
{
    long long n;
    long long b,r;
    cin>>n>>b>>r;

    long long x=n/(b+r);
    long long y=n%(b+r);

    long long amari=(y>=b)?b:y;
    //cout <<y<<" "<<amari;
    cout<<(x*b)+amari;



}






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

using namespace std;

/*
void po( int b[ 10 ][ 5 ] ) {
  for( int i = 0; i < 10; i++) {
    for( int j = 0; j < 5; j++ ) {
      cout << b[ i ][ j ] << " " << flush;
    }
    cout << endl;
  }
  cout << "---" << endl;
}
*/

int del( int b[ 10 ][ 5 ], int h ) {
  int point = 0;
  for( int i = 9; i > 9 - h; i--) {
    int seqv = -1;
    int seqn = 0;
    for( int j = 0; j < 5; j++ ) {
      if( b[ i ][ j ] == seqv ) {
        seqn++;
      } else {
        if( seqn >= 3 ) {
          point += ( seqv * seqn );
          for( int k = 0; k < seqn; k++ ) {
            b[ i ][ j - k - 1 ] = -1;
          }
        }
        seqn = 1;
        seqv = b[ i ][ j ];
      }
    }
    if( seqn >= 3 ) {
      point += ( seqv * seqn );
      for( int k = 0; k < seqn; k++ ) {
        b[ i ][ 5 - k - 1 ] = -1;
      }
    }
  }
  
  for( int i = 9; i > 9 - h; i--) {
    for( int j = 0; j < 5; j++ ) {
//      cout << "I: " << i << " J: " << j << " P: " << point << endl;
//      po( b );
      if( b[ i ][ j ] == -1 ) {
        while( 1 ) {
          if( b[ i ][ j ] == -1 ) {
            for( int k = i; k >= 0; k-- ) {
              b[ k ][ j ] = b[ k - 1 ][ j ];
            }
            b[ 0 ][ j ] = 0;
          } else {
            break;
          }
        }
      }
    }
  }

  return point;
}


int main() {
  while( 1 ) {
    int b[ 10 ][ 5 ] = { 0 };
    int h;
    cin >> h;
    if( h == 0 ) { break; }
    for( int i = 9 - h + 1; i < 10; i++) {
      for( int j = 0; j < 5; j++ ) {
        cin >> b[ i ][ j ];
      }
    }
    int total = 0;
    while( 1 ) {
      int p = del( b, h );
      if( p == 0 ) { break; }
      total += p;
    }

    cout << total << endl;
  }
  return EXIT_SUCCESS;
}

Measured memory_bytes: 1160
N = gets.chomp.to_i
sides=Hash.new{|h,k|h[k]={}}
(N-1).times do |i|
  a, b, c = gets.chomp.split(' ').map(&:to_i)
  # sides[a] ||= {}
  # sides[b] ||= {}
  sides[a][b] = c
  sides[b][a] = c
end

qs = []
Q, K = gets.chomp.split(' ').map(&:to_i)
Q.times do
  qs.push gets.chomp.split(' ').map(&:to_i)
end

cost = []
cost[K] = 0

g = [[K, 0]]
while g.length > 0
  node, dis = g.shift
  sides[node].each do |k, v|
    unless cost[k]
      cost[k] = dis + v
      g.push [k, cost[k]]
    end
  end
end

qs.each do |q|
  print "#{cost[q[0]] + cost[q[1]]}\n"
end

Measured memory_bytes: 64888
#include<stdio.h>
#include<string.h>
int main(){
  int i,j,k,lengths,lengthp;
  char s[100],p[100];

  scanf("%s",s);
  scanf("%s",p);
  lengths=strlen(s);
  lengthp=strlen(p);

  for(i=0;i<lengths;i++){
    j=0;k=0;
    while(s[(i+j)%lengths]==p[k]){j++;k++;}
    if(p[k]=='\0'){printf("Yes\n");return 0;}
  }
  printf("No\n");
  return 0;
}

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

#define pi 3.141592654
#define lit 1000000007
#define endl '\n'
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define _max(a,b) ((a)>(b)?(a):(b))
#define _min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define lbd lower_bound
#define ubd upper_bound
#define ll  long long
#define ull unsigned long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define out(n) cout << n << " "
#define outl(n) cout << n << endl
#define line cout << endl
#define bug(n) {outl(n);return;}
#define debug(arr) cout << #arr << " = [ "; for(auto x : arr) cout << x << ' '; cout <<']' << endl;
#define print(mp) for(auto x : mp){ cout << #mp << " = [ "; cout << x.first << " , " << x.second << " ]" << endl;};
int main()
{
    io;

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    
    ll int n,temp,val=0;
    vector <ll int > v;
    
    cin>>n;
    
    for(int i=0 ; i<n ; i++ )
    {
        cin>>temp;
        v.pb(temp);
        val=val^temp;
    }

    for(int i=0 ; i<n ; i++)
    {
        cout<<(v[i]^val)<<" ";
    }

    return 0;
}

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

int N;
int p[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    p[i]--;
  }  
  int ans = 0;
  for (int i = 0; i + 1 < N; i++) {
    if (p[i] == i) {
      ans++;
      swap(p[i], p[i + 1]);
    }
  }
  if (p[N - 1] == N - 1) ans++;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int N;
    cin >> N;
    string S, T;
    cin >> S;
    cin >> T;
    for(int i=0;i<N;++i){
        cout << S[i] << T[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
import pdb

def main():
    param = list(map(int, input().split()))

    n = param[0]
    m = param[1]
    c = param[2]

    b = list(map(int, input().split()))
    
    data = []
    for i in range(n):
        param = list(map(int, input().split()))
        data.append(param)

    ans = 0
    for source in range(n):
        count = 0
        for tokucho in range(m):
            count += data[source][tokucho] * b[tokucho]
            
        if count + c > 0:
            ans += 1
            

    print(ans)
    
    return

        
if __name__ == '__main__':
    main()


Measured memory_bytes: 5672
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main(void)
{
    ll x, y;
    cin >> x >> y;
    ll ans = 0;
    while(x<=y){
        ans++;
        x *= 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;

// ユークリッドの互除法により最大公約数（Greatest Common Factor）を求める
int calcGCF(int a, int b) {
	if (b > a) swap(a, b);
	if (b == 0) return a;
	return calcGCF(b, a % b);
}

void swap(int &a, int &b) {
	int tmp = a;
	a = b;
	b = tmp;
}

int main(void) {
	int N, X;
//	int x[10010];
	scanf("%d %d", &N, &X);
	int *x = new int[N + 1];
	for (int i = 0; i < N; i++) {
		scanf("%d", &x[i]);
		x[i] = abs(x[i] - X);
	}

	int gcf = x[0];
	for (int i = 1; i < N; i++) {
		gcf = calcGCF(x[i], gcf);
	}
	printf("%d", gcf);

	return 0;
}


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

typedef long double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long> vl;
typedef vector<double> vd;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

#define pi 3.14159265358979
#define eps 1e-9
#define inf 1<<30
#define MOD 1000000007 // 1e9+7

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

  vi sv(s.size());
  for( int i=0; i<s.size(); i++ ){
    sv[i] = s[i] - '0';
  }
  int ret = 999;
  for( int i=0; i<s.size()-2; i++ ){
    int val = 753 - (sv[i]*100 + sv[i+1]*10 + sv[i+2]);
    ret = min( ret, abs(val) );
  }

  cout << ret << endl;

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#define INF_INT 999999999
#define INF_INT64 INT64_C(99999999999999999)

int N, M, K, S;
int P, Q;
int C[114514];
int A[271828], B[271828];

int edgeCounts[114514];
int* edges[114514];

void addEdge(int from, int to) {
	int* count = &edgeCounts[from];
	int** list = &edges[from];
	int* newList = realloc(*list, sizeof(**list) * (*count + 1));
	if (newList == NULL) exit(2);
	newList[(*count)++] = to;
	*list = newList;
}

int saitan[114514];
int queue_start, queue_end;
int queue[114514];

int64_t dijkstra_best[114514];
char dijkstra_kakutei[114514];

struct status_t {
	int node;
	int64_t best;
};

int heapCount, heapCapacity;
struct status_t* heap;

void heapAdjust(int idx) {
	for (;;) {
		int minIdx = idx;
		int i;
		for (i = 1; i <= 2; i++) {
			int cidx = idx * 2 + i;
			if (cidx < heapCount && heap[cidx].best < heap[minIdx].best) minIdx = cidx;
		}
		if (minIdx != idx) {
			struct status_t temp = heap[idx];
			heap[idx] = heap[minIdx];
			heap[minIdx] = temp;
			idx = minIdx;
		} else {
			if (idx == 0) break; else idx = (idx - 1) / 2;
		}
	}
}

void heapAdd(int node, int64_t best) {
	if (heapCount >= heapCapacity) {
		heapCapacity = heapCount + 1;
		struct status_t* newHeap = realloc(heap, sizeof(*heap) * heapCapacity);
		if (newHeap == NULL) exit(2);
		heap = newHeap;
	}
	heap[heapCount].node = node;
	heap[heapCount].best = best;
	heapCount++;
	heapAdjust(heapCount - 1);
}

struct status_t heapGet(void) {
	struct status_t ret;
	if (heapCount <= 0) exit(3);
	ret = heap[0];
	if (heapCount > 1) heap[0] = heap[heapCount - 1];
	heapCount--;
	if (heapCount > 0) heapAdjust(0);
	return ret;
}

int main(void) {
	int i;
	if (scanf("%d%d%d%d", &N, &M, &K, &S) != 4) return 1;
	if (scanf("%d%d", &P, &Q) != 2) return 1;
	for (i = 0; i < K; i++) {
		if (scanf("%d" ,&C[i]) != 1) return 1;
	}
	for (i = 0; i < M; i++) {
		if (scanf("%d%d", &A[i], &B[i]) != 2) return 1;
		addEdge(A[i], B[i]);
		addEdge(B[i], A[i]);
	}

	for (i = 1; i <= N; i++) saitan[i] = INF_INT;
	queue_start = queue_end = 0;
	for (i = 0; i < K; i++) {
		saitan[C[i]] = 0;
		queue[queue_end++] = C[i];
	}
	while (queue_start < queue_end) {
		int node = queue[queue_start++];
		for (i = 0; i < edgeCounts[node]; i++) {
			int next = edges[node][i];
			if (saitan[next] > saitan[node] + 1) {
				saitan[next] = saitan[node] + 1;
				queue[queue_end++] = next;
			}
		}
	}

	for (i = 1; i <= N; i++) dijkstra_best[i] = INF_INT64;
	dijkstra_best[1] = 0;
	heapAdd(1, 0);
	while (heapCount > 0) {
		struct status_t status = heapGet();
		if (dijkstra_kakutei[status.node]) continue;
		dijkstra_kakutei[status.node] = 1;
		for (i = 0; i < edgeCounts[status.node]; i++) {
			int next = edges[status.node][i];
			int cost = (next == 1 || next == N) ? 0 : (saitan[next] <= S ? Q : P);
			if (saitan[next] > 0 && dijkstra_best[status.node] + cost < dijkstra_best[next]) {
				dijkstra_best[next] = dijkstra_best[status.node] + cost;
				heapAdd(next, dijkstra_best[next]);
			}
		}
	}
	printf("%" PRId64 "\n", dijkstra_best[N]);

	return 0;
}



Measured memory_bytes: 9548
N, X = map(int, input().split())
L = list(map(int, input().split()))

output_list = [0] * (N + 1)
D = [0] * (N + 1)
D[0] = 0
output_list[0] = 0
for i in range(1, N + 1):
    D[i] = D[i - 1] + L[i - 1] 
    output_list[i] = D[i]
output = [x for x in output_list if x <= X]

print(len(output))

Measured memory_bytes: 3064
#include <iostream>
#include <complex>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    int mx = A.back();
    A.pop_back();
    vector<int> orgA = A;
    for (int i = 0; i < A.size(); i++) {
        if (A[i] * 2 >= mx) A[i] = mx - A[i];
    }
    int mx2 = *max_element(A.begin(), A.end());
    cout << mx << " ";
    if (binary_search(orgA.begin(), orgA.end(), mx2)) {
        cout << mx2;
    } else {
        cout << mx - mx2;
    }
    cout << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#define S 2000000000
 
int comp = 0;
 
int Merge(int ar[], int l, int m, int r){
 
  int n1 = m - l,n2 = r - m;
  int i,j,k;
  int L[n1+1],R[n2+1];
 
  for(i=0;i<=n1-1;i++)
    L[i]=ar[l+i];
  for(i=0;i<=n2-1;i++)
    R[i]=ar[m+i];
  L[n1]=S;
  R[n2]=S;
  i = j = 0; 
  for(k=l; k<=r-1; k++){
    if(L[i]<=R[j]){
      ar[k]=L[i];
      i=i+1;
      comp++;
    }
    else {
      ar[k]=R[j];
      j=j+1;
      comp++;
    }
  }
}
 
int MergeS(int ar[], int l, int r){
 
  int m;
 
  if(l+1<r){
    m=(l+r)/2;
    MergeS(ar, l, m);
    MergeS(ar,m, r);
    Merge(ar, l, m, r);
  }
 
}

int main(){
 
  int n,i,a[500000];
 
  scanf("%d", &n);
  for(i=0; i<n; i++)
    scanf("%d", &a[i]);
 
  MergeS(a, 0, n);
 
  for(i = 0; i < n - 1; i++)
    printf("%d ", a[i]);
  printf("%d\n",a[n - 1]);
  printf("%d\n", comp);
 
  return 0;
   
}

Measured memory_bytes: 4504
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
	char toshi[256];
	int hyouka;
	int x;
}house;

void scan(house *data);
int cmp(house* data1, house* data2);
int print(house* data);

int main(void) {
	int i,j;
	int N;

	scanf("%d", &N);
	
	house data[N];
	
	for (i = 0;i < N;i++) {

		scan(&data[i]);
		data[i].x = i+1;

	}

	printf("\n");
	for (j = 0;j < N - 1;j++) {
		for (i = 0;i < N - 1;i++) {
			cmp(&data[i], &data[i + 1]);
		}
	}

	for (i = 0;i < N;i++) {
		print(&data[i]);
	};
	
	return 0;
}

void scan(house *data) {
	
	scanf("%s%d",data->toshi,&data->hyouka);

	return ;
}

int print(house* data) {
	printf("%d\n",data->x);

	return 0;
}

int cmp(house *data1,house *data2){
	char evalue[256];
	int value;
	int xc;


	if ((strcmp(data1->toshi, data2->toshi) < 0)) {
		
	}
	else if ((strcmp(data1->toshi,data2->toshi)==0)) {
		if(data1->hyouka>data2->hyouka){
		}
		else if (data1->hyouka < data2->hyouka) {
			strcpy(evalue, data1->toshi);
			strcpy(data1->toshi, data2->toshi);
			strcpy(data2->toshi, evalue);

			value = data1->hyouka;
			data1->hyouka = data2->hyouka;
			data2->hyouka = value;

			xc = data1->x;
			data1->x = data2->x;
			data2->x = xc;
		}
	}
	else if ((strcmp(data1->toshi, data2->toshi) > 0)) {
		strcpy(evalue, data1->toshi);
		strcpy(data1->toshi, data2->toshi);
		strcpy(data2->toshi, evalue);

		value = data1->hyouka;
		data1->hyouka = data2->hyouka;
		data2->hyouka = value;

		xc = data1->x;
		data1->x = data2->x;
		data2->x = xc;
	}

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define maxn 240000
using namespace std;
typedef long long LL;
int h[maxn], N;
LL a[maxn], f[maxn];
void add(int x, LL v){
	for(; x <= N; x += x & -x) f[x] = max(f[x], v);
}
LL ask(int x){
	LL ret = 0;
	for(; x; x -= x & -x) ret = max(ret, f[x]);
	return ret;
}
int main(){
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i = 1; i <= N; i += 1) cin >> h[i];
	for(int i = 1; i <= N; i += 1) cin >> a[i];
	for(int i = 1; i <= N; i += 1)
		add(h[i], ask(h[i] - 1) + a[i]);
	cout << ask(N);
}

Measured memory_bytes: 4480
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int a,b;
    cin>>a>>b;
    int cnt=0;
    for(int i=a;i<=b;i++){
        string res=to_string(i);
        bool flag=true;
        int j=0, k=res.length()-1;
        while(j<k){
            if(res[j]!=res[k]){
                flag=false;
                break;
            }
            j++,k--;
        }
        if(flag) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 256
/*       _________
        /|______/ \
        ||  _|_|\  |
        || |_|   | /
        ||    _ / |
        ||  _| \\  \    
        ||_|_|\ || |
        |/_|/ | /|_/
              /__/      Written by: Rishabh Roshan
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int            	long long
#define integer        	int32_t
#define mod         	1000000007
#define vint        	vector<int>
#define pint        	pair<int, int>
#define umint        	unordered_map<int, int>
#define mint        	map<integer, integer>
#define in(x)        	int x; cin>>x
#define setbits(x)    	__builtin_popcountll(x)
#define zerobits(x)    	__builtin_ctzll(x)
#define w(x)        	int x; cin>>x; while(x--)
#define sp(x, y)    	fixed<<setprecision(y)<<x
#define poll(x)        	x.front(); x.pop()
#define f(x)        	for(int i=0; i<x; i++)
#define fj(x)			for(int j=0; j<x; j++)
#define fn(n, x)		for(int i=n; i<x; i++)
#define endl         	'\n'
#define inf         	1e9 
#define order_set     	tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

void om_shree_ganeshaya_namah(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int32_t main() {

    om_shree_ganeshaya_namah();

    in(n); in(x); in(t);
    int m = n/x;
    if(n%x)
        m++;
    int ans = m*t;
    cout<<ans;
}

Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;

int main() {
    int n, r;
    while(cin >> n >> r, n) {
        vector<int> v(n);
        for(int i=0; i<n; ++i) {
            v[i] = n-i;
        }
        
        for(int i=0; i<r; ++i) {
            vector<int> tmp;
            int p, c;
            cin >> p >> c;
            tmp.insert(tmp.begin(), v.begin()+p-1, v.begin()+p+c-1);
            v.erase(v.begin()+p-1, v.begin()+p+c-1);
            v.insert(v.begin(), tmp.begin(), tmp.end());
        }
        cout << v[0] << endl;
    }
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 305 * 2;
char g[N][N];
const int P = 52127, M = 1010101333;
ll pw[N], hr[N][N], hc[N][N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> g[i];
        copy_n(g[i],n-1,g[i]+n);
    }
    for (int i = n; i < 2*n-1; ++i)
        copy_n(g[i-n],2*n-1,g[i]);
    pw[0] = 1;
    for (int i = 1; i < N; ++i)
        pw[i] = pw[i-1] * P % M;
    for (int i = 1; i <= 2*n-1; ++i)
        for (int j = 1; j <= 2*n-1; ++j) {
            hr[i][j] = (hr[i][j-1] * P % M + g[i-1][j-1] - 'a') % M;
            hc[j][i] = (hc[j][i-1] * P % M + g[i-1][j-1] - 'a') % M;
        }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) {
            bool ok = 1;
            for (int k = 0; k < n && ok; ++k)
                ok = (hr[i+k][j+n-1] + (M - hr[i+k][j+k-1] * pw[n-k] % M)) % M == (hc[j+k][i+n-1] + (M - hc[j+k][i+k-1] * pw[n-k] % M)) % M;
            ans += ok;
        }
    cout << ans << endl;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vector<int>> vvi;

ll rec(ll SS, vi& dp)
{
    ll ans = 0;

    if(SS == 0)
    return 1;
    if(SS < 0)
    return 0;

    if(dp[SS] != -1)
    return dp[SS];

    for(ll i = 3 ; i <= SS ; i++)
    ans += rec(SS-i,dp) % 1000000007 ;

    return dp[SS] = ans;
}

int main()
{
    ll S;    
    cin >> S;
    vi dp(S+1,-1);
    cout << rec(S,dp) % ( 1000000007 );

    // for(auto x : dp)
    // cout << x << " ";
}

Measured memory_bytes: 3652
H,W = map(int,input().split(" "))
picture = []

for i in range(H):
    picture.append(list(input()))

for i in range(H):
    for j in range(W):
        if picture[i][j] == "#":
            if i == 0:
                if (j == 0)and(picture[0][1] == ".")and(picture[1][0]):
                    print("No")
                    exit()
                elif (j == W-1)and(picture[0][j-1] == ".")and(picture[1][j] == "."):
                    print("No")
                    exit()
                else:
                    if (picture[i][j-1] == ".")and(picture[i+1][j] == ".")and(picture[i][j+1] == "."):
                        print("No")
                        exit()
            elif i == H-1:
                if (j == 0)and(picture[i-1][j] == ".")and(picture[i][j+1] == "."):
                    print("No")
                    exit()
                elif (j == W-1)and(picture[i-1][j] == ".")and(picture[i][j-1] == "."):
                    print("No")
                    exit()
                else:
                    if (picture[i][j-1] == ".")and(picture[i-1][j] == ".")and(picture[i][j+1] == "."):
                        print("No")
                        exit()
            elif j == 0:
                if (picture[i+1][j] == ".")and(picture[i][j+1] == ".")and(picture[i-1][j] == "."):
                    print("No")
                    exit()
            elif j == W-1:
                if (picture[i-1][j] == ".")and(picture[i][j-1] == ".")and(picture[i+1][j] == "."):
                    print("No")
                    exit()
            else:
                if (picture[i+1][j] == ".")and(picture[i-1][j] == ".")and(picture[i][j+1] == ".")and(picture[i][j-1] == "."):
                    print("No")
                    exit()
print("Yes")


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

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

  if ((n.at(0) == n.at(1) && n.at(1) == n.at(2)) || (n.at(1) == n.at(2) && n.at(2) == n.at(3)))
    cout << "Yes";
  else
  {
    cout << "No";
  }
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[200100],pre[200100],aft[200100],rp[200100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++){
		pre[i]=pre[i-1]+a[i]-1;
	}
	for(int i=n;i>=1;i--){
		aft[i]=aft[i+1]+a[i]-1;
	}
	for(int i=1;i<=n;i++)
		rp[i]=rp[i-1]+a[i];
	long long t=rp[n],p;
	long long ans=1e18;
	for(int i=1;i<n;i++){//cut:ith notch
		p=rp[i];
		long long candidate=1e18;
		if(p*2==t){//half
			cout<<0<<endl;
			return 0;
		}
		if(p*2<t){//<half
			//前增 
			candidate=min(candidate,t-p*2);
		}
		if(p*2>t){//<half
			//后增 
			candidate=min(candidate,p*2-t);
		}
		ans=min(ans,candidate); 
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6528
o = input()
e = input()
z = []
if len(o) == len(e):
	for i in range(len(o)):
		z.append(o[i])
		z.append(e[i])

else:
	for i in range(len(e)):
		z.append(o[i])
		z.append(e[i])
	z.append(o[-1])

print(''.join(z))


Measured memory_bytes: 3060
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if b - a > k:
    print(":(")
elif c - a > k:
    print(":(")
elif d - a > k:
    print(":(")
elif e - a > k:
    print(":(")
elif c - b > k:
    print(":(")
elif d - b > k:
    print(":(")
elif e - b > k:
    print(":(")
elif d - c > k:
    print(":(")
elif e - c > k:
    print(":(")
elif e - d > k:
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 3064
#include<stdio.h>

int main(void)
{
   int a,b;
   int c = 0;
   int i,q,z;
   
   while(c == 0){
   
      scanf("%d", &a);   scanf("%d", &b);
      
      if(a==0){
         if(b==0){
            break;}}
            
      for(i=1;i<=a;i++){
         for(q=1;q<=b;q++){
            
            if(i%2==q%2){
               printf("#");}
            else{
               printf(".");}
         }
         printf("\n");
      }
      printf("\n");
   }
   return 0;
}


Measured memory_bytes: 2020
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node{int parent, left, right;};

Node Tree[MAX];
int n, Depth[MAX];

void print(int index){
    int i, child;
    cout << "node " << index << ": ";
    cout << "parent = " << Tree[index].parent << ", ";
    cout << "depth = " <<  Depth[index] << ", ";

    if(Tree[index].parent == NIL) cout << "root, ";
    else if(Tree[index].left == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";
    for(i=0, child=Tree[index].left; child != NIL; i++, child = Tree[child].right){
        if(i) cout << ", ";
        cout << child;
    }
    cout << "]" << endl;
}

void setDepth(int index, int currentDepth){
    Depth[index] = currentDepth;
    if(Tree[index].right != NIL) setDepth(Tree[index].right, currentDepth);
    if(Tree[index].left != NIL) setDepth(Tree[index].left, currentDepth+1);
}

int main(void){
    int d, vertex, in, left, right;
    cin >> n;
    for(int i=0;i<n;i++) Tree[i].parent = Tree[i].left = Tree[i].right = NIL;

    for(int i=0;i<n;i++){
        cin >> vertex >> d;
        for(int j=0;j<d;j++){
            cin >> in;
            if(j==0) Tree[vertex].left = in;
            else Tree[left].right = in;
            left = in;
            Tree[in].parent = vertex;
        }
    }

    for(int i=0;i<n;i++)
        if(Tree[i].parent == NIL) right=i;
    setDepth(right, 0);

    for(int i=0;i<n;i++) print(i);

    return 0;
}


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

int main()
{
    int A, B;

    cin >> A >> B;

    int a = min(A, B), b = max(A, B);

    for (int i = a; i > 1; i--)
    {
        if (a % i == 0 && b % i == 0)
            a /= i;

        if (a == 1)
            break;
    }

    cout << (long long)a * b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
typedef pair<string,int> psi;
#define repeat(i,n) for (int i = 0; i < (n); ++i)
#define MAX_N 10
string substitute(const string & s, const string & a, const string & b) {
    string dest;
    int i = 0;
    while (i < (int)s.length() - (int)a.length() + 1) {
        if (s.substr(i,a.length()) == a) {
            dest += b;
            i += a.length();
        } else {
            dest += s[i];
            ++ i;
        }
    }
    while (i < (int)s.length()) {
        dest += s[i];
        ++ i;
    }
    return dest;
}
int N;
string a[MAX_N], b[MAX_N], g, d;
bool input() {
    cin >> N;
    if (N == 0) return false;
    repeat (i,N) cin >> a[i] >> b[i];
    cin >> g >> d;
    return true;
}
int solve() {
    queue<psi> q;
    q.push(psi(g,0));
    while (not q.empty()) {
        string s = q.front().first;
        int    m = q.front().second;
        q.pop();
        repeat (i,N) {
            string t = substitute(s, a[i], b[i]);
            if (t != s) {
                if (t == d) {
                    return m+1;
                } else if (t.length() < d.length()) {
                    q.push(psi(t,m+1));
                }
            }
        }
    }
    return -1;
}
int main() {
    while (input()) cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 1320
from collections import deque
import sys
sys.setrecursionlimit(1000000)
h, w = map(int, input().split())
start_y = 0
start_x = 0
goal_y = h - 1
goal_x = w - 1
field = []
for _ in range(h):
    field.append(list(input()))

# '#'の数を数える
black_count = 0
for i in range(h):
    for j in range(w):
        if field[i][j] == '.':
            black_count += 1

dy = [1, -1, 0, 0]
dx = [0, 0, 1, -1]
distance = [[-1] * w for i in range(h)]
que = deque([])
que.append([start_y, start_x])
distance[start_y][start_x] = 0

while que:
    q = que.popleft()
    if q[0] == goal_y and q[1] == goal_x:
        break
    for i in range(4):
        now_y = q[0] + dy[i]
        now_x = q[1] + dx[i]
        if now_y < 0 or now_y >= h or now_x < 0 or now_x >= w or field[now_y][now_x] == '#':
            continue
        if distance[now_y][now_x] != -1:
            continue
        que.append([now_y, now_x])
        distance[now_y][now_x] = distance[q[0]][q[1]] + 1

if distance[goal_y][goal_x] == -1:
    result = -1
else:
    result = black_count - (distance[goal_y][goal_x] + 1)
print(result)

Measured memory_bytes: 3316
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];
	const n = parseInt(line0, 10);

	var AC = 0;
	var WA = 0;
	var TLE = 0;
	var RE = 0;
	for (var i = 1; i <= n; i++) {
		const line = inputLines[i];
		if (line === "AC") {
			AC += 1;
		}
		if (line === "WA") {
			WA += 1;
		}
		if (line === "TLE") {
			TLE += 1;
		}
		if (line === "RE") {
			RE += 1;
		}
	}
	console.log("AC x " + AC);
	console.log("WA x " + WA);
	console.log("TLE x " + TLE);
	console.log("RE x " + RE);


	// tmp = input[1].split(" ");
	// //文字列から10進数に変換するときはparseIntを使います
	// var a = parseInt(input[0], 10);
	// var b = parseInt(tmp[0], 10);
	// var c = parseInt(tmp[1], 10);
	// var s = input[2];

	//出力
	// console.log('%d %s',a+b+c,s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)


Measured memory_bytes: 37292
#include <bits/stdc++.h>
using namespace std;
int func(int n) {
  int sum = 0;
  while (n > 0) { 
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(){
  int N;
  cin >> N;  
  int tma = 0, tmb = 0, sum = 0;
  int f = 72;  
  
  for (int i = 0; i < N - 1 ;i++){
    int a = i + 1;
    int b = N - a;
    tma = func(a);
    tmb = func(b);
    f = min(tma + tmb, f);
  }
  cout << f;
}

Measured memory_bytes: 256
N=int(input())
B=["*"]+list(map(int,input().split()))

X=[]
for t in range(N):
    p=-1
    for k in range(1,(N-t)+1):
        if B[k]==k:
            p=k

    if p>=1:
        X.append(p)
        del B[p]
    else:
        print(-1)
        exit()

print("\n".join(map(str,X[::-1])))


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

int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  
  for(int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    sum += (r - l + 1);
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <climits>
#include <cstdio>
#include <cstdint>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

using i32 = int32_t;
using u32 = uint32_t;
using f32 = float;
using f64 = double;
using i64 = int64_t; 
using u64 = uint64_t; 

#define SELECTER(_1, _2, _3, _4, _5, _6, _7, _8, SELECT, ...) SELECT

#define _FC1(func, type, _1)      func(type, _1);
#define _FC2(func, type, _1, ...) func(type, _1); _FC1(func, type, __VA_ARGS__);
#define _FC3(func, type, _1, ...) func(type, _1); _FC2(func, type, __VA_ARGS__);
#define _FC4(func, type, _1, ...) func(type, _1); _FC3(func, type, __VA_ARGS__);
#define _FC5(func, type, _1, ...) func(type, _1); _FC4(func, type, __VA_ARGS__);
#define _FC6(func, type, _1, ...) func(type, _1); _FC5(func, type, __VA_ARGS__);
#define _FC7(func, type, _1, ...) func(type, _1); _FC6(func, type, __VA_ARGS__);
#define _FC8(func, type, _1, ...) func(type, _1); _FC7(func, type, __VA_ARGS__);

#define _FCN(func, type, ...) SELECTER(__VA_ARGS__, _FC8, _FC7, _FC6, _FC5, _FC4, _FC3, _FC2, _FC1)(func, type, __VA_ARGS__);

constexpr const char *type2fmt(const char *fmt) {
  if(strcmp(fmt, "i32")) return "%d";
  if(strcmp(fmt, "u32")) return "%u";
  if(strcmp(fmt, "f32")) return "%f";
  if(strcmp(fmt, "f64")) return "%lf";
  if(strcmp(fmt, "i64")) return "%lld";
  if(strcmp(fmt, "u64")) return "%llu";
  if(strcmp(fmt, "char*")) return "%s";
  return "";
}

#define _R(type, _1) type _1; { type _t; scanf(type2fmt(#type), &_t); _1 = _t; }
#define _P(type, _1) { const type _t = (_1); printf(type2fmt(#type), _t); putchar('\n'); }

#define RI(...)   _FCN(_R, i32, __VA_ARGS__);
#define RUI(...)  _FCN(_R, u32, __VA_ARGS__);
#define RF(...)   _FCN(_R, f32, __VA_ARGS__);
#define RD(...)   _FCN(_R, f64, __VA_ARGS__);
#define RLL(...)  _FCN(_R, i64, __VA_ARGS__);
#define RULL(...) _FCN(_R, u64, __VA_ARGS__);

#define PI(...)   _FCN(_P, i32, __VA_ARGS__);
#define PUI(...)  _FCN(_P, u32, __VA_ARGS__);
#define PF(...)   _FCN(_P, f32, __VA_ARGS__);
#define PD(...)   _FCN(_P, f64, __VA_ARGS__);
#define PLL(...)  _FCN(_P, i64, __VA_ARGS__);
#define PULL(...) _FCN(_P, u64, __VA_ARGS__);
#define PS(...)   _FCN(_P, char*, __VA_ARGS__);

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

const u64 mod = 1000000007;

int main() {
  i32 d;
  scanf("2017/01/%d", &d);
  printf("2018/01/%02d\n", d);
}


Measured memory_bytes: 256
#!/usr/bin/python3
# coding: utf-8

# 整数 > 整数型
def I(): return int(input())

# 整数列 '1 2 3 4' > 整数型リスト
def IsIl(): return list(map(lambda x: int(x), input().split()))

# 改行挟む整数列　'1/n 2/n 3/n' > 整数型りすと
def InIl(n): return [input() for i in range(n)]

# 整数列 '1 2' > 整数型タプル
def IsIt(): return map(lambda x: int(x), input().split())

# 改行挟む整数列　'1\n 2\n 3\n' > 整数型たぷる
def InIl(n): return map(input() for i in range(n))

# 文字列 'abcd' > 文字型リスト
def SsSl(): return list(map(lambda x: x, input()))

# 整数 '1234' > 整数型リスト

# 文字列 'aba' > 辞書（文字型:個数）{'a':2,'b':1}
def SSd():
    from collections import defaultdict
    A = input() # [int(i) for i in input().split()]
    dd=defaultdict(int)
    for a in A:
        dd[a]+=1
    return dd

n,m=IsIt()

if 1 <= n and n <= 9 and 1 <= m and m <= 9:
    print(n*m)
else:
    print(-1)



Measured memory_bytes: 3064
def conv(s):
    s = list(s)
    s.reverse()
    ret = 0
    for i in range(len(s)):
        ret += int(s[i]) * (-2)**i
    return ret

n = int(input())
if n == 0:
    print(0)
    exit()

s = ''
d = 2
while abs(n) > 0:
    if n % d == 0:
        s = '0' + s
    else:
        s = '1' + s
    n -= conv(s[0]+'0'*(len(s)-1))
    d *= 2

print(s)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 99999999;
const long long MOD = 1e9 + 7;
const double pi = 3.1415926535897932384626;

long long n, a, b, tak, ao;
int main() {
	cin >> n;
	vector<pair<long long, pair<long long, long long>>>v;
	for (int i = 0; i < n; ++i) {
		cin >> a >> b;
		v.push_back(make_pair(a + b, make_pair(a, b)));
	}
	sort(v.rbegin(), v.rend());
	for (int i = 0; i < n; ++i) {
		if (i % 2 == 0) { tak += v[i].second.first; }
		else { ao += v[i].second.second; }
	}
	cout << tak - ao << endl;
}

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

int main(){
  int H,W;
  cin>>H>>W;

  vector<string> a(H);
  vector<int> c={0};
  vector<vector<bool>> memo(H,vector<bool>(W,0));
  queue<int> qx;
  queue<int> qy;
  int i,j;
  for(i=0;i<H;i++){
    cin>>a.at(i);
    for(j=0;j<W;j++){
      if(a.at(i).at(j)=='#'){
        qx.push(i);
        qy.push(j);
        c.at(0)++;
        memo.at(i).at(j)=1;
      }
    }
  }

  int cnt=0;
  int k=0;
  int cnt2=0;
  int cnt3=0;
  while(!(qx.empty())){
    int x=qx.front();
    int y=qy.front();

    vector<int> dx={-1,0,1,0};
    vector<int> dy={0,1,0,-1};

    bool judge=0;
    for(i=0;i<4;i++){
      int nx=x+dx.at(i);
      int ny=y+dy.at(i);

      if(nx<0||ny<0||nx>=H||ny>=W)
      continue;
      if((a.at(nx).at(ny)=='.')&&!(memo.at(nx).at(ny))){
        qx.push(nx);
        qy.push(ny);
        cnt2++;//pushの数
        a.at(nx).at(ny)='#';
        memo.at(nx).at(ny)=1;
        judge=1;
      }

    }


    // for(i=0;i<H;i++)
    // cout<<a.at(i)<<endl;
    // cout<<cnt<<endl;

    qx.pop();
    qy.pop();
    cnt3++;//popの数
    if(cnt3==c.at(k)){
      c.push_back(cnt2);
      k++;
      cnt++;
      cnt2=0;
      cnt3=0;
    }

  }
  cnt--;
  cout<<cnt<<endl;


}


Measured memory_bytes: 9728
#include "bits/stdc++.h"
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 

#define PI 3.14159265

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)5e5 + 7;
const int inf = (int)1e9 + 7;
//const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
 
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

const int mod = 998244353;

struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}
};



int main(){
	int n; cin>>n;
	string s; cin>> s; 
	for(int i =0 ; i < (int)s.size(); i++){
		if(s[i] + n <= 'Z')
			s[i] = s[i] + n;
		else{
			s[i] = (s[i] + n - 'Z') + ('A' - 1);
		}
	}
	cout<<s;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print((a-1)*(b-1))
    return

#B
def B():
    def est(n):
        res = 0
        for i in range(1, int(n ** 0.5) + 1):
            if not n % i:
                res += 2
        res -= float.is_integer(n ** 0.5)
        return res == 8
    n = II()
    ans = 0
    for i in range(1, n + 1, 2):
        ans += est(i)
    print(ans)
    return

#C
def C():
    s = S()
    k = II()
    for i in range(k):
        if s[i] != "1":
            print(s[i])
            return
    print(s[k-1])
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 39280
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#define ll long long
#define INF 0x3f3f3f3f
#define N 1005
using namespace std;



int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	int ans=b-a+1;
	if(ans<0) ans=-ans;
	if(ans%2==0) puts("Borys");
	else puts("Alice");
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN (300006)
#define MAXK 26
#define MAXX 15000006
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, A[MAXN], r, l, K, allzero, allone,ans;
int main()
{
	string s;cin>>s;
	n=siz(s);
	FOR(i,1,n+1)A[i]=s[i-1]-48;
	K=1; ll co = n; ans=K; allzero = 1, allone = 1;
	// i+K>n, && i<=k
	while(1) {
		// slide co down, update allzero & allone on the way
		K ++; if(K>n) break;
		-- co;
		if(K>=co) {
			allzero &= (A[K] == 0);
			allzero &= (A[co] == 0);
			allone &= (A[K] == 1);
			allone &= (A[co] == 1);
		}
		if(allzero||allone)ans=K;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define clr(A, x) memset(A, x, sizeof(A))
#define cpy(A, B) memcpy(A, B, sizeof(B))
#define g(s) getline(cin, s) ///ai grija la fin/cin ///
#define FASTIO ios_base::sync_with_stdio(0)
const long long INFLL = 2 * 1e18 + 100;
const int INFINT = 2 * 1e9 + 100;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
//ifstream fin("input.txt");
//ofstream fout("output.txt");
void die()
{
    cout << "-1";
    exit(0);
}
const int NMAX = 1e5 + 5;
const int MOD = 1e9 + 7; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;



int main()
{
    FASTIO;
    int a, b, c;
    cin >> a >> b >> c;
    if((b * 10 + c) % 4 == 0) cout << "YES"; else cout << "NO";

    return 0;
}


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

using namespace std;

int main(void) {
    int n;
    vector<int> h(101);

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

    int sum = 0;

    for (int i = 0; i < n; ++i) {
        bool is_view = true;
        for (int j = 0; j < n - 1 && j != i; ++j) {
            if (h[j] > h[i]) { is_view = false; }
        }
        if (is_view) { sum++; }
    }

    cout << sum << endl;
}


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

points = []
for i in range(n):
	temp =  list(map(int, input().split()))
	points.append(temp)

points.sort(key = lambda x: x[0]+x[1], reverse=True)

print(
	sum([x[0] for x in points[0::2]] )
	-
	sum([x[1] for x in points[1::2]] )
	)


Measured memory_bytes: 32224
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
using namespace std;  
int n,a[100005],i;  
bool ch()  
{  
    long long s=0;  
    for (int i=1;i<=n;i++) s+=a[i];  
    s*=2;  
    if (s%((long long)n*(n+1))!=0) return 0;  
    s/=n;s/=(n+1);  
    for (int i=1;i<n;i++)  
    {  
        long long s1=a[i]-a[i+1]+s;  
        if (s1<0||s1%n!=0) return 0;  
    }  
    long long s1=a[n]-a[1]+s;  
    if (s1<0||s1%n!=0) return 0;  
    return 1;  
}  
int main()  
{  
    cin>>n;  
    for (i=1;i<=n;i++) scanf("%I64d",&a[i]);  
    if (ch()) printf("YES");  
    else printf("NO");  
    return 0;  
}  

Measured memory_bytes: 640
import math
import collections


S = input()


N = len(S)
P = 2019
ans = 0
juu = 1
S = S[::-1]
amari = 0
amaris = [0] * (P) #あまりの配列
if P == 2 or P == 5:
    for i,c in enumerate(S):
        n = int(c)
        if n % P == 0:
            ans += N - i
else:


    for c in S:
        i = int(c)
        amari += (i * juu)
        amari %= P
        amaris[amari] += 1
        juu *= 10
        juu %= P


    amaris[0] += 1
    for temp in amaris:
        ans += temp * (temp - 1) //2
print(ans)

Measured memory_bytes: 9656
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

ll N;
ll dp[4][4][4][110];

int main() {
  cin >> N;
  rep(i, 0, 4) {
    rep(j, 0, 4) {
      rep(k, 0, 4) { dp[i][j][k][2] = 1; }
    }
  }
  dp[0][2][1][2] = 0;
  dp[0][1][2][2] = 0;
  dp[2][0][1][2] = 0;

  rep(cur, 3, N) {
    rep(i, 0, 4) {
      rep(j, 0, 4) {
        rep(k, 0, 4) {
          if (i == 0 && j == 2 && k == 1) continue;
          if (i == 0 && j == 1 && k == 2) continue;
          if (i == 2 && j == 0 && k == 1) continue;

          rep(l, 0, 4) {
            if (l == 0 && j == 2 && k == 1) continue;
            if (l == 0 && i == 2 && k == 1) continue;
            dp[i][j][k][cur] += dp[l][i][j][cur - 1];
            dp[i][j][k][cur] %= MOD;
          }
        }
      }
    }
  }

  ll ans = 0;
  rep(i, 0, 4) {
    rep(j, 0, 4) {
      rep(k, 0, 4) {
        ans += dp[i][j][k][N - 1];
        ans %= MOD;
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 3688
#include<stdio.h>

int dp[50];
 int fib(int n){
     if(n == 0 || n == 1)
  return dp[n] = 1;
     if (dp[n] != -1)
  return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
 int main(){
   int n,i;
    for (i = 0; i < 50; i++)
    dp[i] = -1;

    scanf("%d",&n);
    printf("%d\n",fib(n));
   
   return 0;
} 

Measured memory_bytes: 1848
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
int p[10010],mn[10010];
ll a[510][510];
int n,tot;
void euler(int n)
{
	tot=0;
	for(int i=2;i<=n;i++){
		if(!mn[i])p[++tot]=i,mn[i]=tot;
		for(int j=1;j<=mn[i]&&i*p[j]<=n;j++)
			mn[i*p[j]]=j;
	}
}
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main()
{
	n=read();
	if(n==2){
		printf("4 7\n23 10\n");
		return 0;
	}
	euler(10000);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if((i+j)&1){
				int x=(i-j+n+1)/2,y=(i+j+1)/2;
				a[i][j]=p[x]*p[n+y];
			}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(!((i+j)&1)){
				ll cur=1;
				if(i>1)cur=cur/gcd(cur,a[i-1][j])*a[i-1][j];
				if(j>1)cur=cur/gcd(cur,a[i][j-1])*a[i][j-1];
				if(i<n)cur=cur/gcd(cur,a[i+1][j])*a[i+1][j];
				if(j<n)cur=cur/gcd(cur,a[i][j+1])*a[i][j+1];
				a[i][j]=cur+1;
			}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
			writesp(a[i][j]);
		putchar('\n');
	}
	return 0;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

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

    vector<ll> s(n + 1, 0LL);
    REP(i, n) s[i + 1] = s[i] + a[i];

    ll sum = s[n];

    int index = 0;
    ll tmp = 0;
    REP(i, n) {
        tmp += a[i];
        if (tmp >= sum / 2) {
            index = i;
            break ;
        }
    }

    ll l = abs((s[index] - s[0]) - (s[n] - s[index]));
    ll r = abs((s[index + 1] - s[0]) - (s[n] - s[index + 1]));

    cout << min(l, r) << '\n';
    return 0;
}

Measured memory_bytes: 3328