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

using namespace std;

void zero_sum_range() {
    int n;
    map<long long, int> m;
    
    cin >> n;

    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    long long total = 0;
    long long count = 0;
    m[total]++;
    for (int i = 0; i < n; i++) {
        total += a[i];
        count += m[total];
        m[total]++;
    }
    
    cout << count << endl;
}

int main()
{
    zero_sum_range();

    return 0;
}

Measured memory_bytes: 14336
#include <iostream>

using namespace std;

int main() {
    int n, d, x;

    cin >> n;
    cin >> d >> x;

    int c = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        for (int j = 0; j <= d; j++) {
            if (j * a + 1 <= d) {
                c++;
            }
        }
    }

    cout << c + x << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  for(int i = 0; i < 100; i++) {
    if(a * i % b == c) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
}


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

int w, h, n, ans, X, Y;

int main()
{
    cin >> w >> h >> n;
    cin >> X >> Y;
    for (int i = 1; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        if ((X - x) * (Y - y) > 0)
            ans += max(abs(X - x), abs(Y - y));
        else
            ans += abs(X - x) + abs(Y - y);
        X = x, Y = y;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3108
#include <stdio.h>
 
int main(void) {
    int N, P, A[55], i, n_e, n_o;
    long long c;
    scanf("%d %d", &N, &P);
    n_e=0; n_o=0;
    for (i=1; i<=N; i++) {
        scanf("%d", &A[i]);
        if ((A[i])%2 == 0) n_e+=1;
        else n_o+=1;
    }
    if (n_o!=0) {
        c=1;
        for (i=1; i<=N-1; i++) {
            c*=2;
        }
    }
    else if (P==1) c=0;
    else {
        c=1;
        for (i=1; i<=N; i++) {
            c*=2;
        }
    }
    printf("%lld\n", c);
    return 0;
}

Measured memory_bytes: 128
/*
  AOJ 2090
  Title:Repeated Subsequences
  @kankichi573
  14/11/7 TLE
*/
#include <stdio.h>
#include <string.h>
#define max(x,y) (((x)>(y))?(x):(y))

short lcs[300][300];

void  output_lcs(char *in1,char *in2,short lcs[300][300],
		int y,int x,char *out)
{
  *out='\0';
  if(y==0 || x==0)
    return;

  //printf("[%d,%d]:%c %c\n",y,x,in1[y],in2[x]);

  if(in1[y-1]==in2[x-1])
    {
      //printf("%c",in1[y-1]);
      *out=in1[y-1];
      out++;
      *out='\0';
      output_lcs(in1,in2,lcs,y-1,x-1,out);
    }
  else
    {
      if(lcs[y-1][x] >= lcs[y][x-1])
	output_lcs(in1,in2,lcs,y-1,x,out);
      else
	output_lcs(in1,in2,lcs,y,x-1,out);
    }

}
void dump_lcs(int len1,int len2,short lcs[300][300])
{
  int i,j;
  for(i=0;i<=len1;i++)
    {
      for(j=0;j<=len2;j++)
	printf("%-2d|",lcs[i][j]);
      printf("\n");
    }
}


int longest_common_subseq(char *in1,int len1,char *in2,int len2,char *out)
{
  int i,j;
  char *p;

  for(i=0;i<len1;i++)
    lcs[i][0]=0;
  for(i=0;i<len2;i++)
    lcs[0][i]=0;
  for(i=0;i<len1;i++)
    for(j=0;j<len2;j++)
      if(in1[i]==in2[j])
	lcs[i+1][j+1]=lcs[i][j]+1;
      else
	lcs[i+1][j+1]=max(lcs[i][j+1],lcs[i+1][j]);
  
  //dump_lcs(len1,len2,lcs);
  output_lcs(in1,in2,lcs,len1,len2,out);
  return(lcs[len1][len2]);
}

void print_result(char *in1,int len1,char *in2,int len2,char *out)
{
  int i;
  for(i=0;i<len1;i++)
    printf("%c",in1[i]);
  printf(" ");
  for(i=0;i<len2;i++)
    printf("%c",in2[i]);
  printf("|");
  printf("%s\n",out);
}
reverse_print(char *r,int len)
{
  int i;
  for(i=len-1;i>=0;i--)
    printf("%c",r[i]);
  printf("\n");
}
main()
{
  char in1[301],in2[301],out[151],result[151];
  int len,len2,max_,i;
#ifdef TEST  
  scanf("%s %s",in1,in2);
  longest_common_subseq(in1,strlen(in1),in2,strlen(in2),out);
  printf("ANS:%s[%d]\n",out,strlen(out));
#else
  while(scanf("%s",in1) && 0!=strcmp("#END",in1))
    {
      *result='\0';
      len=strlen(in1);
      max_=0;
      for(i=max(max_,1);i<len;i++)
	  {
	    len2=longest_common_subseq(in1,i,in1+i,len-i,out);
	    if(max_<len2)
	      {
		max_=len2;
		strcpy(result,out);
	      }
#ifdef DEBUG
	    print_result(in1,i,in1+i,len-i,out);
#endif
	  }
      reverse_print(result,max_);
    }
 #endif
  return(0);
}

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

int main() {
  int a;
  cin >> a;
  int first = a % 10;
  int second = (a / 10) % 10;
  int third = (a / 100) % 10;
  int fourth = (a / 1000) % 10;
  
  if(second == third &&
    	(first == second || third == fourth)
    ) {
    cout << "Yes" << endl; 
  } else {
    cout << "No" << endl;
  }
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n, m; cin >> n >> m;
    V<int> wa(n + 1, 0);
    V<bool> ac(n + 1, false);

    int acn = 0, wan = 0;
    for(int i = 0; i < m; i++){
        int p; cin >> p;
        string s; cin >> s;
        if(ac[p]) continue;
        if(s == "AC"){
            ac[p] = true;
            acn++;
            wan += wa[p];
        }else{
            wa[p]++;
        }
    }
    cout << acn << ' ' << wan << endl;

    return 0;
}


Measured memory_bytes: 3724
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

ll a[4000];

ll sum(ll i,ll j){
    ll s=0;
    for(ll k=i;k<=j;k++) s += a[k];
    return s;
}

int main(){
    ll r,c;
    cin >> r >> c;
    ll a[110][110]={0};
    rep(i,r){
        rep(j,c){
            cin >> a[i][j];
            a[i][c] += a[i][j];
            a[r][j] += a[i][j];
            a[r][c] += a[i][j];
        }
    }
    rep(i,r+1){
        cout << a[i][0];
        for(ll j=1;j<c+1;j++) cout << ' ' << a[i][j];
        cout << endl;
    }
}


Measured memory_bytes: 3192
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    while(1){
        int t, n; cin>>t>>n;
        if(t == 0) return 0;

        vector<vector<bool>> visited(200, vector<bool>(200, false));
        for(int i=0; i<n; i++){
            int a, b; cin>>a>>b;
            visited[b + 100][a + 100] = true;
        }

        int sx, sy; cin>>sx>>sy;

        int ans = 1;
        queue<T> que;
        que.push(T(sy + 100, sx + 100, 0));
        visited[sy + 100][sx + 100] = true;
        while(que.size()){
            int cy, cx, cnt;
            tie(cy, cx, cnt) = que.front();
            que.pop();

            for(int i=0; i<6; i++){
                int ny = cy + dy[i];
                int nx = cx + dx[i];

                if(cnt < t && !visited[ny][nx]){
                    ans++;
                    visited[ny][nx] = true;
                    que.push(T(ny, nx, cnt + 1));
                }
            }
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 3184
def main():
    n = int(input())
    ans = ''
    while n > 26:
        d = n%26
        if d==0:
            d=26
        ans += chr(ord('a')+d-1)
        n = (n-d)//26
    ans += chr(ord('a')+n-1)
    print(ans[::-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long ;
int main()
{
    int n;
    ll ans=0;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int now=a[0];
    for(int i=1;i<n;i++){
        if(a[i]<now){
            ans+=now-a[i];
        }
        else{
            now=a[i];
        }
    }
    cout<<ans;
}

Measured memory_bytes: 4024
#include<iostream>
using namespace std;
int main(){
    int K, S, count = 0, Z;
    cin >> K >> S;
    for(int X = 0; X <= K; X++){
        for(int Y = 0; Y <= K ; Y++){
            Z = S - X - Y;
            if(Z <= K && Z >= 0) count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ARC100C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = new int[N];
            int[] B = new int[N];
            string[] input = Console.ReadLine().Split();
            for (int i = 0; i <N; i++)
            {
                A[i] =int.Parse(input[i])-(i+1);
            }
            Array.Sort(A);
            /*
            for (int i = 0; i < N; i++)
            {
                Console.Write(A[i]+" ");
            }
            Console.WriteLine();
            */
            int mid = 0;
            if (N%2==1)
            {
                mid = A[(N-1)/ 2];
            }
            else
            {
                mid = (A[N / 2] + A[N / 2 - 1]) / 2;
            }
            //Console.WriteLine("mid="+mid);
            long ans = 0;
            for (int i = 0; i < N; i++)
            {
                B[i] = Math.Abs(A[i] - mid);
                ans += B[i];
                //Console.Write(B[i]+" ");
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 29316
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define N 200005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define rev(a,n) reverse(a,a+n)
using namespace std;
int h[N],n,m,f[N],ans;
int main() {
    cin>>n>>m;
    rep(i,0,n) cin>>h[i];
    rep(i,0,m) {
    	int a,b;
        cin>>a>>b;
        if(h[a-1]>h[b-1]) f[b-1]=1;
		else if (h[a-1]<h[b-1]) f[a-1]=1;
        else {
            f[a-1]=1; f[b-1]=1;
        }
    }
    rep(i,0,n) if(f[i]==0) ans++;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4388
# Author: cr4zjh0bp
# Created: Fri Mar 20 22:48:43 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

class WUnionFind:
    def __init__(self, n, sum_unity=0):
        self.n = n
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.diff_weight = [sum_unity for _ in range(n)]
        self._size = [1 for _ in range(n)]
        self._edges = 0

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            r = self.find(self.par[x])
            self.diff_weight[x] += self.diff_weight[self.par[x]]
            self.par[x] = r
            return r
        
    def unite(self, x, y, w):
        w += self.weight(x)
        w -= self.weight(y)
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.diff_weight[x] = -w
            self._size[y] += self._size[x]
            self._edges += 1
        else:
            self.par[y] = x
            self.diff_weight[y] = w
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self._size[x] += self._size[y]
            self._edges += 1

    def weight(self, x):
        self.find(x)
        return self.diff_weight[x]

    def diff(self, x, y):
        return self.weight(y) - self.weight(x)
    
    def size(self, x):
        x = self.find(x)
        return self._size[x]
    
    def trees(self):
        return self.n - self._edges

    def same(self, x, y):
        return self.find(x) == self.find(y)

while True:
    n, m = na()
    if n == 0 and m == 0:
        break
    wuf = WUnionFind(n)
    for i in range(m):
        que = nas()
        if que[0] == '!':
            a, b, w = list(map(int, que[1:]))
            a -= 1
            b -= 1
            wuf.unite(a, b, w)
        elif que[0] == '?':
            a, b = list(map(int, que[1:]))
            a -= 1
            b -= 1
            if wuf.same(a, b):
                print(wuf.diff(a, b))
            else:
                print("UNKNOWN")


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

int main() {
	ll h,n;
  	cin>>h>>n;
  
  	vector<int> a(n);
  rep(i,n){
  		cin>>a[i];
  }
  
  
  rep(j,n){
  	h -=a[j];
  }
  
  if(h<=0){
  	cout<<"Yes"<<endl;
  }
  
  else{
  	cout<<"No"<<endl;
  }
  
  
	
}

Measured memory_bytes: 640
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

#define BLACK 'B'
#define WHITE 'W'

// x : [left, right)
// y : [top, bottom)
int calc(int left, int top, int right, int bottom, const vector<vector<int>>& table)
{
	int a = table[top][left];
	int b = table[top][right];
	int c = table[bottom][left];
	int d = table[bottom][right];

	return d - c - b + a;
}

int main(void)
{
	int N, K;
	cin >> N >> K;
	
	const int k2 = 2 * K;
	const int size = 4*K + 10;
	vector<vector<int>> table(size, vector<int>(size, 0));
	for(int i=0; i<N; i++){
		int x, y;
		char c;
		cin >> x >> y >> c;
		if(c == WHITE)
			x += K;

		x %= k2;
		y %= k2;

		table[y][x]++;
		table[y][x+2*K]++;
		table[y+2*K][x]++;
		table[y+2*K][x+2*K]++;
	}

	vector<vector<int>> imos(size, vector<int>(size, 0));
	for(int i=0; i<size-1; i++){
		for(int j=0; j<size-1; j++){
			imos[i+1][j+1] += table[i][j] + imos[i+1][j];
		}
	}
	for(int i=0; i<size-1; i++){
		for(int j=0; j<size; j++){
			imos[i+1][j] += imos[i][j];
		}
	}
	
	int ret = 0;
	for(int i=0; i<2*K; i++){
		for(int j=0; j<2*K; j++){
			int sum = 0;

			sum += calc(j, i, j+K, i+K, imos);
			sum += calc(j+K, i+K, j+k2, i+k2, imos);

			ret = max(ret, sum);
		}
	}

	cout << ret << endl;

	return 0;
}


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

int ans[1005][1005];

int main(){
	int h,w,a,b;
	cin >> h >> w >> a >> b;
	
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if(i < b && j < a) ans[i][j]++;
			if(i >= b && j >= a) ans[i][j]++;
		}
	}
	
	rep(i,h){
		rep(j,w){
			cout << ans[i][j];
		}
		cout << endl;
	}
	
    return 0;
}



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

using namespace std;

const int N = 123456;

int n, q, t;
long long events[N], answer[N], coef[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  events[++t] = n;
  for (int i = 1; i <= q; ++i) {
    long long x;
    cin >> x;
    while (t && events[t] >= x) {
      --t;
    }
    events[++t] = x;
  }
  coef[t] = 1;
  function<void (long long, long long)> solve = [&] (long long x, long long y) {
    if (x) {
      int p = lower_bound(events + 1, events + 1 + t, x) - events - 1;
      if (!p) {
        answer[1] += y;
        answer[x + 1] -= y;
      } else {
        coef[p] += y * (x / events[p]);
        solve(x % events[p], y);
      }
    }
  };
  for (int i = t; i > 1; --i) {
    coef[i - 1] += coef[i] * (events[i] / events[i - 1]);
    solve(events[i] % events[i - 1], coef[i]);
  }
  answer[1] += coef[1];
  answer[events[1] + 1] -= coef[1];
  for (int i = 1; i <= n; ++i) {
    answer[i] += answer[i - 1];
    cout << answer[i] << '\n';
  }
  return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
signed main() {
  int a, b;
  cin >> a >> b;

  if (a >= 13) {
    cout << b << endl;
  } else if (a >= 6) {
    cout << b / 2 << endl;
  } else {
    cout << 0 << endl;
  }
}


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

int n, m, Ans;
bitset<555> G[555], die, all;

int main(void) {
  scanf("%d%d", &n, &m);
  for(int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    G[x] |= G[y];
    G[y] |= G[x];
    for(int j = 1; j <= n; j++) {
      if(G[j].test(x)) G[j].set(y);
      if(G[j].test(y)) G[j].set(x);
    }
    G[x].set(y);
    G[y].set(x);
  }
  for(int i = 1; i <= n; i++) {
    if(G[i].test(i))
      die[i] = 1;
    all.set(i);
  }
  for(int i = 1; i <= n; i++) if(!die.test(i)) {
    G[i].flip();
    Ans = Ans + (G[i] & (G[i] ^ die) & all).count();
  }
  cout << (Ans - n + die.count()) / 2 << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  ll h, w;
  cin >> h >> w;
  if (h == 1 || w == 1){
    cout << 1 << endl;
    return 0;
  }
  ll a = (h+1) / 2;
  ll b = w / 2;
  ll ans = h * b;
  if(w % 2 == 1){
    ans += a;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

import numpy as np
from numba import njit


@njit('i8(i4[::1],)', cache=True)
def f(A):
    count = np.zeros((A.max() + 1))
    for a in A:
        if count[a] > 1:
            continue
        count[::a] += 1

    ret = 0
    for a in A:
        ret += count[a] == 1

    return ret

N = int(input())
A = np.array(readline().split(), np.int32)

print(f(A))

Measured memory_bytes: 127612
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100;

int n;
vector<int> b;
vector<int> ans;

vector<int> calc(vector<int> want) {
	if(SZ(want)==1) { return want[0]==1?vector<int>(1,1):vector<int>(); }
	int idx=0; FORSZ(i,1,want) if(want[i]>=want[idx]) idx=i;
	int val=want[idx]; if(idx+1<val||val>SZ(want)) return vector<int>();
	vector<int> nwant; REPSZ(i,want) if(i!=idx) nwant.PB(want[i]);
	vector<int> sub=calc(nwant); if(SZ(sub)==0) return sub;
	int t=SZ(want)-1-(idx-(val-1)); assert(t>=0&&t<=SZ(sub));
	vector<int> ret(SZ(sub)+1); ret[t]=val; REPSZ(i,sub) if(i<t) ret[i]=sub[i]; else ret[i+1]=sub[i]; return ret;
}

bool solve() {
	ans=calc(b);
	return SZ(ans)!=0;
}

void run() {
	scanf("%d",&n);
	b=vector<int>(n); REP(i,n) scanf("%d",&b[i]);
	if(!solve()) { printf("-1\n"); return; }
	REPSZ(i,ans) printf("%d\n",ans[i]);
}

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


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

int main() {
    long N;
    cin>>N;
    long ans = 1e13;
    for(long i=1;i<=1e6+10;++i){
        if((N%i==0) & (i+(N/i)-2<ans))ans = i+N/i-2;
    }
    if(ans==1e13)cout<<N-1<<endl;
    else cout<<ans<<endl;
}


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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    int k;
    cin >> s >> k;

    for (int i = 0; i < s.size() && k > 0; ++i) {
        if (i == s.size() - 1) {
            s[i] = (char)('a' + (s[i] - 'a' + k) % 26);
            break;
        }

        if (s[i] == 'a') continue;

        int needed_k = 'z' - s[i] + 1;
        if (k >= needed_k) {
            s[i] = 'a';
            k -= needed_k;
        }
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define oo (long long)1e18
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
void _IOS(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
#define PI 3.14159265359
int sx,sy,tx,ty;
//8c:1a:bf:89:66:b6
struct threeElements{
int _1st,_2nd,_3rd;
};
vector<vector<int>>adj(10);
ll solve(int a,int b)
{
    int f=0,s=0;
    while(a)
    {
        a/=10;
        f++;
    }
    while(b)
    {
        b/=10;
        s++;
    }
    return max(f,s);
}
int main()
{
   // freopen ("jumping.in","r",stdin);
   _IOS();
   //18:52
   string s,t;
   cin>>s>>t;
   int i=0;
   for(i=0;i<s.length()&&i<t.length();i++)
    cout<<s[i]<<t[i];
   while(i<s.length()) {cout<<s[i];i++;}
   while(i<t.length())
    {
        cout<<t[i];
        i++;
    }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b; cin>>a>>b;
	if(abs(a-b)>=2) cout<<max(a,b)*2-1<<"\n";
	else cout<<a+b<<"\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int[] c = new int[6];
		for(int i = 0;i < 9;i++) {
			int a = scn.nextInt();
			if(i < 3) {
				c[2*i]+=a;
				c[2*i+1] += a;
			}else{
				if(i == 3) {
					c[2]+=a;
					c[4]+=a;
				}
				if(i==4) {
					c[0]+=a;
					c[5]+=a;
				}
				if(i == 5) {
					c[1]+=a;
					c[3]+=a;
				}
				if(i == 6) {
					c[3]+=a;
					c[5]+=a;
				}
				if(i == 7) {
					c[1]+=a;
					c[4]+=a;
				}
				if(i == 8) {
					c[0]+=a;
					c[2]+=a;
				}
			}
		}
		boolean ans = true;
		for(int i = 0;i < 6;i++) {
			ans &= (c[i]==c[0]);
		}
		System.out.println(ans?"Yes":"No");
	}

}

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

using namespace std;
#define ll long long
#define cni const int
#define cnl const long long

cni maxn = 1e5+20;
ll dp[maxn][4];
ll inf=1e18+10;
int mod=1e9 + 7;
int ar[maxn][4], maxx[maxn], mxx[maxn];


int main() 
{
	ios_base::sync_with_stdio(0);cin.tie(0);
	
	int n;
	cin >> n;
	
	for(int i=1;i<=n;i++)
		cin >> ar[i][1] >> ar[i][2] >> ar[i][3];
		
	for(int i=1;i<=n;i++)
	{
		dp[i][1]=max(dp[i-1][2],dp[i-1][3])+ar[i][1];
		dp[i][2]=max(dp[i-1][1],dp[i-1][3])+ar[i][2];
		dp[i][3]=max(dp[i-1][2],dp[i-1][1])+ar[i][3];
	}
			
	ll mx=0;
	for(int i=1;i<=3;i++)
		mx=max(mx, dp[n][i]);
		
	cout << mx;
	
}




Measured memory_bytes: 4992
package main

import (
	"fmt"
)

func main() {
	var a, b, x int
	fmt.Scan(&a, &b, &x)
	var l, r int
	if a%x == 0 {
		l = a
	} else {
		l = a - a%x + x
	}
	if b%x == 0 {
		r = b
	} else {
		r = b - b%x
	}
	fmt.Println((r-l)/x + 1)
}


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

// #define double long double
#define int long long

const int MXN = 405;
int n;
int dp[MXN][MXN];
int arr[MXN];

int mcost(int l, int r) {
	if (l == r) return arr[l];
	if (dp[l][r] != -1) return dp[l][r];
	int sall = 0;
	for (int i=l; i<=r; i++) sall += arr[i];
	int mx = LLONG_MAX;
	for (int k=l; k<r; k++) {
		mx = min(mx, mcost(l, k) + mcost(k+1, r));
	}
	return dp[l][r] = mx + sall;
	
}

signed main() {
    
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    for (int i=0; i<MXN; i++) for (int j=0; j<MXN; j++) dp[i][j] = -1;
    
    int small = 0;
    
    cin >> n;
    for (int i=0; i<n; i++) {
		cin >> arr[i];
		small += arr[i];
	}
    
    cout << mcost(0, n-1) - small << endl;
    
}


Measured memory_bytes: 1536
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans = 1
flg = True
for i in range(N):
    ans *= A[i]
    if A[-1] != 0:
        if ans > 10**18:
            flg = False
            break
    if A[-1] == 0:
        ans = 0
        break
if flg == False:
    print(-1)
else:
    print(ans)


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

#define ll long long

void exgcd(int a, int b, int& x, int& y) {
	if (!b) {
		x = 1, y = 0;
	} else {
		exgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
}

int inv(int a, int n) {
	int x, y;
	exgcd(a, n, x, y);
	return (x < 0) ? (x + n) : (x);
}

const int Mod = 998244353;

template <const int Mod = :: Mod>
class Z {
	public:
		int v;

		Z() : v(0) {	}
		Z(int x) : v(x){	}
		Z(ll x) : v(x % Mod) {	}

		friend Z operator + (const Z& a, const Z& b) {
			int x;
			return Z(((x = a.v + b.v) >= Mod) ? (x - Mod) : (x));
		}
		friend Z operator - (const Z& a, const Z& b) {
			int x;
			return Z(((x = a.v - b.v) < 0) ? (x + Mod) : (x));
		}
		friend Z operator * (const Z& a, const Z& b) {
			return Z(a.v * 1ll * b.v);
		}
		friend Z operator ~(const Z& a) {
			return inv(a.v, Mod);
		}
		friend Z operator - (const Z& a) {
			return Z(0) - a;
		}
		Z& operator += (Z b) {
			return *this = *this + b;
		}
		Z& operator -= (Z b) {
			return *this = *this - b;
		}
		Z& operator *= (Z b) {
			return *this = *this * b;
		}
		friend bool operator == (const Z& a, const Z& b) {
			return a.v == b.v;
		} 
};

Z<> qpow(Z<> a, int p) {
	Z<> rt = Z<>(1), pa = a;
	for ( ; p; p >>= 1, pa = pa * pa) {
		if (p & 1) {
			rt = rt * pa;
		}
	}
	return rt;
}

typedef Z<> Zi;

const int N = 1e5 + 5;

Zi base (1000000000000000000ll);
Zi pw[N];

void init_pw(int n) {
	pw[0] = 1;
	pw[1] = base;
	for (int i = 2; i <= n; i++) {
		pw[i] = pw[i - 1] * base;
	}
}

int n;

typedef class Graph {
	public:
		bitset<512> vis;
		int SG[N];
    Zi buk[512];
    vector<int> G[N];

		Zi* solve() {
      int u, v, m;
      scanf("%d", &m);
			while (m--) {
				scanf("%d%d", &u, &v);
			  if (u > v) {
          swap(u, v);
        }
        G[u].push_back(v);
      }
      for (int i = n; i; i--) {
        for (auto e : G[i]) {
          vis.set(SG[e]);
        }
        while (vis.test(SG[i]))
          SG[i]++;
        for (auto e : G[i]) {
          vis.reset(SG[e]);
        }
      }
      for (int i = 1; i <= n; i++) {
        buk[SG[i]] += pw[i];
      }
      return buk;
		}
} Graph;

Graph g1, g2, g3;

void fwt(Zi* f, int n) {
  int N = 1 << n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < N; j++) {
      if ((j >> i) & 1) {
        Zi a = f[j ^ (1 << i)], b = f[j];
        f[j ^ (1 << i)] = a + b;
        f[j] = a - b;
      }
    }
  }
}
void ifwt(Zi* f, int n) {
  fwt(f, n);
  int N = 1 << n;
  Zi invlen = ~Zi(N);
  for (int i = 0; i < N; i++) {
    f[i] *= invlen;
  }
}

int main() {
  scanf("%d", &n);
  init_pw(n);
  Zi* b1 = g1.solve();
  Zi* b2 = g2.solve();
  Zi* b3 = g3.solve();
  fwt(b1, 9);
  fwt(b2, 9);
  fwt(b3, 9);
  for (int i = 0; i < 512; i++) {
    b1[i] = b1[i] * b2[i] * b3[i];
  }
  ifwt(b1, 9);
  printf("%d\n", b1->v);
	return 0;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
  string str;
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int b;
  
  cin >> b;
  cout << a[b-1] << endl;
}
  

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


using namespace std;

typedef long long ll;

ll mod=1000000007;

int main(){

    ll N;
    cin>>N;
    vector<ll> A(N,0);
    vector<ll> B(N,0);
    

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

    ll ans=0;
    B[N-1]=A[N-1];

    for(ll i=0;i<N-1;++i){
        B[N-2-i]=(B[N-1-i]+A[N-2-i])%mod;
    }

/*
    for(int i=0;i<N;++i){
        cout<<B[i]<<" ";
    }
    cout<<endl;
*/
    for(ll i=0;i<N-1;++i){
        //cout<<A[i]<<":"<<B[N-1-i]<<endl;

        ans=(ans+A[i]*B[i+1])%mod;
    }

    cout<<ans<<endl;


    
}

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

using namespace std;

int main(void) {
	int y,m,d;
	string str;
	while (cin >> str,str != "#") {
		cin >> y >> m >> d;
		if (y >= 31) {
			if (y > 31 ||(y == 31 && m >= 5)) {
				cout << "? " << y-30 << " " << m << " " << d << endl;
			}
			else {
				cout << "HEISEI " << y << " " << m << " " << d << endl;
			}
		}
		else {
			cout << "HEISEI " << y << " " << m << " " << d << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3160
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s,d,f;cin>>s>>d>>f;
  if(s[s.size()-1]==d[0]&&d[d.size()-1]==f[0])
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>

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

typedef long long ll;

using namespace std;

const int INF = 1e9;
const int MOD = 1e9+7;
const double PI=3.14159265358979323846;

int main(){
  string s,ans="";
  cin >> s;
  rep(i,s.size()) ans+="x";
  cout << ans << endl;
}


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

using namespace std;

int main() {
    int N, M, c;
    cin >> N >> M;
    int cities[50] = { 0 };
    for(int i = 0; i < M; i++) {
        cin >> c; cities[c-1]++;
        cin >> c; cities[c-1]++;
    }
    for(int i = 0; i < N; i++) {
        cout << cities[i] << "\n";
    }
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    long long ryuka[87];
    ryuka[0] = 2LL;
    ryuka[1] = 1LL;
    for(int i = 2; i <= N; i++) {
        ryuka[i] = ryuka[i-2]+ryuka[i-1];
    }
    cout << ryuka[N] << endl;
}



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

using namespace std;

int main()
{
    int K,N,i,A[200005],Max=0;
    cin>>K>>N;
    for(i=1;i<=N;i++)
        scanf("%d",&A[i]);
    for(i=1;i<=N;i++)
    {
        if(i==1)
            Max=K-(A[N]-A[1]);
        else if(A[i]-A[i-1]>Max)
            Max=A[i]-A[i-1];
    }
    cout<<K-Max<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
double dp[2][3001]={},ar[3001],to=0;
int main()
{
	int n;cin>>n;
	for (int i=0;i<n;i++) {cin>>ar[i];}
	dp[0][0]=1;
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<=n;j++)
		{
			dp[i%2][j] = (dp[(i-1)%2][j-1] * ar[i-1]) + (dp[(i-1)%2][j] * (1-ar[i-1])); 
		}
	}
	for (int j=n/2+1;j<=n;j++)
	{
		to+=dp[n%2][j];
	}
	cout<<setprecision(9)<<to<<endl;
	//printf("%.9lf\n",to);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    mp::cpp_dec_float_100 x,y = 2.0f;
    cin>>x>>y;

    cout<<mp::cpp_dec_float_50(mp::floor(x*y)).str()<<endl;

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 3696
#include <stdio.h>

int main(void){

	int i, j,a,b;
	while(1){
		scanf("%d %d", &a,&b);
		if(a==0 && b==0)
			break;
		
		for(i=1;i<=a;i++){
			for(j=1;j<=b;j++){
		if(i==1 || i==a || j==1 || j==b)
			printf("#");
		else
			printf(".");
		}
		printf("\n");
	}
	printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
// In God We Trust


# include <bits/stdc++.h>

# define INF 1 << 31 - 1
# define pb push_back
# define fi first
# define se second
#include <algorithm>


using namespace std;


int gcd(long long a, long long b) 
{ 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a % b, b); 
    return gcd(a, b % a); 
}


signed main()
{
  long long a, b;
  cin >> a >> b;
  cout << a * b / gcd(a, b) << endl;
  
}

 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int num=0;
    char ch=getchar();
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) num*=10,num+=ch-48,ch=getchar();
    return num;
}
int a[1000003];
int tree[2000003];
void add(int l,int r,int x,int i,int t)
{
	if(l==r) 
	{
		tree[i]=max(tree[i],t); return ;
	}
	int mid=(l+r)/2;
	if(x<=mid) add(l,mid,x,i<<1,t); else add(mid+1,r,x,(i<<1)+1,t);
	tree[i]=max(tree[(i<<1)],tree[(i<<1)+1]);
}
int query(int l,int r,int L,int R,int i)
{
	//printf("%d %d %d %d\n",l,r,L,R);
	if(L<=l && r<=R) return tree[i];
	if(R<l || L>r) return 0;
	int mid=(l+r)/2;
	return max(query(l,mid,L,R,i<<1),query(mid+1,r,L,R,(i<<1)+1));
}
signed main()
{
	int n=read(),k=read();
	for(int i=1; i<=n; i++) a[i]=read()+1;
	for(int i=1; i<=n; i++) 
	add(1,300001,a[i],1,query(1,300001,max(1,a[i]-k),min(300001,a[i]+k),1)+1);
	printf("%d\n",query(1,300001,1,300001,1));
	return 0;
}

Measured memory_bytes: 9032
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          firstn
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define puts(n)		cout<<n;
#define fr(i,l,u) 	for(i=l;i<=u;i++)
#define bk(i,l,u)	for(i=l;i>=u;i--)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
ll posx[]={1,-1,0,0};
ll posy[]={0,0,1,-1};

void solve()
{
    string s,t;
    ll i,j,l1,l2;
    cin>>s>>t;
    l1=s.length();
    l2=t.length();
    ll dp[l1+1][l2+1];
    mset(dp,0);
    for(i=1;i<=l1;i++)
    {
        for(j=1;j<=l2;j++)
        {
            if(s[i-1]==t[j-1])
            dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
            else
            dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
        }
    }
    stack<char>st;
    i=l1,j=l2;
    while(i>0 and j>0)
    {
        if(s[i-1]==t[j-1])
        {
            st.push(s[i-1]);
            i--;
            j--;
            continue;
        }
        else
        {
            if(dp[i][j]==dp[i-1][j])
            i--;
            else
            j--;
        }
    }
    while(!st.empty())
    {
        cout<<st.top();
        st.pop();
    }
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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

	int X;
	cin >> X;
	if(X == 3 || X == 5 || X == 7) cout << "YES" << endl;
	else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

_, k = gets.split.map(&:to_i)
r, s, p = gets.split.map(&:to_i)
h = { 'r' => p, 's' => r, 'p' => s }
t = gets.chomp
score = 0

t.chars.group_by.with_index { |_, index| index % k }.each_value do |i|
  pred = nil

  i.each do |j|
    if pred != j
      score += h[j]
      pred = j
    else
      pred = nil
    end
  end
end

puts score

Measured memory_bytes: 16380
#include<stdio.h>

void swap(int *x, int *y){
    int z;
    z = *x;
    *x = *y;
    *y = z;
}

int main(void){
    int X, Y, Z;
    scanf("%d %d %d",&X, &Y, &Z);

    swap(&X, &Y);
    swap(&X, &Z);

    printf("%d %d %d\n",X, Y, Z);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repll(i, a, b) for(ll i=(a); i<(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define COUT(a) cout << a << endl
#define ALL(a) (a).begin(),(a).end()
const long long int mod = 1e9 + 7;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n); vector<ll> nowVec; 
    repll(i,0,n){
        cin >> a[i];
        a[i]--;
    }
    ll now = 0; ll end = 0; ll start = 0;
    nowVec.pb(0);
    map<ll, ll> mp; mp[0] = 1;
    repll(i,0,k){
        //cout << "now" << now+1 << endl;
        if(mp[a[now]] == 0) mp[a[now]] = i+2;
        else{
            start = mp[a[now]]-1;
            end = i+1;
            break;
        }
        now = a[now];
        nowVec.pb(now);
    }
    ll delta = end - start;
    ll res = 0; ll ans = 0;
    if(delta!=0){
        res = (k-start)%delta;
        ans = nowVec[start + res]+1;
        //cout << "res" << res << ", delta "<< delta<<endl; 
        //cout << "start " << start << "end" << end << endl;
    }
    else ans = nowVec[nowVec.size()-1]+1;
    COUT(ans);
}

Measured memory_bytes: 15964
n = input()
total=0
op_cnt = len(n) - 1 
for i in range(2 ** op_cnt):
    op = ["+"] * op_cnt  
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "" 
    formula = ""
    for p_n, p_o in zip(n, op + [""]):  
        formula += (p_n + p_o)
    
    total+=eval(formula)
print(total)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  ll n;
  cin >> n;
  P((n - 1) * n / 2);
  return 0;
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
# a, b, c = 20, 2, 5
my_sum = 0
for x in range(1, a + 1):
    # print(x)
    sum1 = 0
    y = x
    while y >= 1:
        sum1 = sum1 + y % 10
        y = y // 10
    # print(x, sum1)
    if c >= sum1 >= b:
        my_sum = my_sum + x
        # print("my sum {}".format(my_sum))
print(my_sum)


Measured memory_bytes: 39536
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll X;
    cin >> X;
    cout << X / 500 * 1000 + X % 500 / 5 * 5 << "\n";
}

Measured memory_bytes: 256
import sys

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


def main():
    x, y, z = map(int, readline().split())

    rem = x - z
    ans = 0
    while rem >= (y + z):
        rem -= (y + z)
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()


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

int main() {

  ll K;
  string S;
  cin >> K >> S;

  if(S.size() <= K){
    cout << S << endl;
  }else{
    for(ll i=0;i<K;i++){
      cout << S[i];
    }
    cout << "..." << endl;
  }




}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>s>>a;
      rep(i,Size(s)){
        if((s[i]-'0')==1)cnt++;
        else break;
      }
      if(cnt>=a)Cout(1);
      else{
        rep(i,Size(s)){
          if((s[i]-'0')!=1){
            pos=s[i]-'0';
            Cout(pos);
            return 0;
          }
        }
      }
     

       
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

ll memory[1000011];

ll fn(ll x){
    if(x==0) return 9999;
    if(memory[x]>=0) return memory[x];
    if(x%2==1) return memory[x]=0;
    return memory[x]=fn(x/2)+1;
}

int main(){
    rep(i,1000011) memory[i]=-1;
    REP(i,1,1000011) fn(i);
    ll N; cin>>N;
    vec d;
    ll Gu=2;
    string S; cin>>S;
    rep(i,N){
        ll x=S.at(i)-'0';
        x--; d.pb(x);
        if(x==1) Gu=1;
    }
    if(Gu==2) rep(i,N) d.at(i)/=2;
    //rep(i,N) cout<<d.at(i)<<endl;
    ll ans=0; 
    ll count=0;
    rep(i,N){
        if(count==0) ans+=d.at(i);
        ll A=N-i-1, B=i+1;
        if(i<N-1) {count+=fn(A); count-=fn(B);}
        //cout<<A<<' '<<fn(A)<<' '<<B<<' '<<fn(B)<<' '<<count<<' '<<ans<<endl;
    }
    ans=ans%2;
    cout<<ans*Gu<<endl;
    

}

Measured memory_bytes: 19704
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>

using namespace std;

struct Node {
	int key;
	Node *bef, *next;
};

Node *nil;

Node* listSearch(int key){
	Node *cur = nil->next;
	while( cur != nil && cur->key != key){
		cur = cur->next;
	}
	return cur;
}

void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->bef = nil;
	nil->next = nil;
}
void printList(){
	Node *cur = nil->next;
	int isf = 0;
	while(1){
		if(cur == nil) break;
		if(isf++ > 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}
void deleteNode(Node *t){
	if(t == nil) return;
	t->bef->next = t->next;
	t->next->bef = t->bef;
	free(t);
}
void deleteFirst(){
	deleteNode(nil->next);
}
void deleteLast(){
	deleteNode(nil->bef);
}
void deleteKey(int key){
	deleteNode( listSearch(key));
}
void insert(int key){
	Node *x = (Node *) malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->bef = x;
	nil->next = x;
	x->bef = nil;
}

int main(){
	char c[200];
	int n;
	init();
	scanf("%d", &n);
	for(int _=0;_<n;_++){
		int res = scanf(" %s", c);
		if(res == EOF) break;
		if(strcmp(c, "insert")==0){
			int d;
			scanf(" %d",&d);
			insert(d);
		} else if(strcmp(c, "delete")==0){
			int d;
			scanf("%d",&d);
			deleteKey(d);
		} else if(strcmp(c, "deleteFirst")==0){
			deleteFirst();
		} else if(strcmp(c, "deleteLast")==0){
			deleteLast();
		}
	}
	printList();
	return 0;
}

Measured memory_bytes: 32364
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		String a=sc.next();
		String b=sc.next();
		String c=sc.next();

		//各文字列の最初の文字と最後の文字を所得
		char a_final=a.charAt(a.length()-1);
		char b_ini=b.charAt(0);
		char b_final=b.charAt(b.length()-1);
		char c_ini=c.charAt(0);

		String ans;

		//しりとりになっているかの確認
		if (a_final==b_ini && b_final==c_ini) ans="YES";
		else ans="NO";
		
		System.out.println(ans);	
	}
	
} 

Measured memory_bytes: 23764