akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(I,N) for (int I=0; I<N; I++)
#define fornd(I,N) for (int I=N-1; I>=0; I--)
#define forab(I,A,B) for (int I=A; I<=B; I++)
#define forabd(I,A,B) for (int I=B; I>=A; I--)
#define FOREACH(I,A) for (__typeof__(A)::iterator I=A.begin(); I<A.end(); I++)
#define pb push_back
#define mp make_pair

typedef long long int ll;

const ll mod = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<int> > edge(N);

  forn(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    edge[a].pb(b);
    edge[b].pb(a);
  }

  vector<bool> added(N);


  int ans = 0;
  forn(i, N) if (!added[i]) {
    ans++;

    vector<int> next;
    added[i] = true;
    next.pb(i);
    int ct = 0;
    while (ct < next.size()) {
      int index = next[ct];
      forn(j, edge[index].size()) {
        if (!added[edge[index][j]]) {
          added[edge[index][j]] = true;
          next.pb(edge[index][j]);
        }
      }
      ct++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6904
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int m=sc.nextInt();
		long[]d=new long[m];
		long[]c=new long[m];
		long ans=-1;
		long sum=0;
		for(int i=0; i<m; i++){
			d[i]=sc.nextLong();
			c[i]=sc.nextLong();
			ans+=c[i];
			sum+=d[i]*c[i];
		}
		System.out.println(ans+((sum-1)/9));
	}
}


Measured memory_bytes: 98980
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll H, ll W) {
  ll res = 1e18;
  if (H % 3 == 0 || W % 3 == 0) chmin(res, 0LL);
  chmin(res, H);
  chmin(res, W);
  REP(i,H+1) {
    const ll a = i * W;
    const ll b = (H - i) * (W / 2);
    const ll c = (H - i) * (W - W / 2);
    chmin(res, max({abs(a - b), abs(b - c), abs(c - a)}));
  }
  swap(H, W);
  REP(i,H+1) {
    const ll a = i * W;
    const ll b = (H - i) * (W / 2);
    const ll c = (H - i) * (W - W / 2);
    chmin(res, max({abs(a - b), abs(b - c), abs(c - a)}));
  }
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll W;
	ll H;
	scanf("%lld", &H);
	scanf("%lld", &W);
	solve(H, W);
	return 0;
}


Measured memory_bytes: 256
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))

def main():
  n,k = readInts()
  D = input().split()
  #print(D)
  #print(list(str(now)))
  #print(set(str(n)) & set(D))
  
  #print({'2','5'} & {'2'})
  while set(str(n)) & set(D):
    n += 1
  print(n)
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
while True:
    n = int(input())
    if n==0:
        break
    else:
        lst=[0]*10
        for i in range(n):
            lst[int(input())] += 1
        for i in range(10): #iはアイスの10種類　リストのn番目=iのアイスが何個売れた
            if lst[i]==0:
                print('-')
            else:
                for j in range(lst[i]):#jはある種類iがlst[i]回であったときforで*表示を回す
                    print('*',end='')#改行に気をつける
                print('')


Measured memory_bytes: 7584
def main():
  n = int(input())
  result = []
  for i in range(n):
    d1, d2 = map(int, input().split())
    result.append(d1 == d2)
  for i in range(n-2):
    if result[i] and result[i+1] and result[i+2]:
      print("Yes")
      return 0
  print("No")
  return 0
    
if __name__ == "__main__":
  a = main()

Measured memory_bytes: 9128
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;
#include <stdio.h>

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0){
    if(y%2) res=(x%hell*res%hell)%hell;
    x=(x%hell*x%hell)%hell;
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();


void fastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

/*
  For freq or prime factors

for(auto pri:prime){
  while(k%pri==0){
    pcnt[pri]++;
    k/=pri;
  }
}*/

void solve(){
  int test;
  //cin>>test;
  test=1;
  
  while(test--){
      int n;
      cin>>n;
      
      ll d,a;
      cin>>d>>a;
      
      vector<pair<ll,ll>> vec(n);
      forn(i,0,n)
      cin>>vec[i].F>>vec[i].S;
      
      sort(vec.begin(),vec.end());
      vector<ll> temp(n);
      
      forn(i,0,n)
      temp[i]=vec[i].F;
      
      ll pre[n+1]={0},ans=0;
      
   
      for(int i=0;i<n;i++){
          pre[i+1]+=pre[i];
          
          ll x=vec[i].S-pre[i+1];
          if(x>0){
              ll y=(x+a-1)/a;
              ans+=y;
              
              pre[i+1]+=y*a;
              ll nxt=2*d+vec[i].F;
              
              auto it=upper_bound(temp.begin(),temp.end(),nxt);
              if(it!=temp.end()){
                  int ind=it-temp.begin();
                  pre[ind+1]-=y*a;
              }
          }
      }
      cout<<ans;
  }    
}    

    




///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll a,ll b)
{
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}


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

int main() {
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int X = 0; X <= K; X++) {
    for (int Y = 0; Y <= K; Y++) {
      int Z = S - X - Y;
      if (0 <= Z && Z <= K) ans++;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N, K = map(int, raw_input().split())

ab = [[0, 0]] * N
for i in range(N):
    _a, _b = map(int, raw_input().split())
    ab[i] = [_a, _b]
ab.sort(key=lambda x:x[0])

j = 0
index = 0
while j < K:
    j += ab[index][1]
    if j < K:
        index += 1

print ab[index][0]


Measured memory_bytes: 24308
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define PREP(i, m, n) for(int i = m; i < n; i++)
#define MREP(i, m, n) for(int i = m - 1; i >= n; i--)
using namespace std;

int countPrime(int n, int m){
	int count = 0;
	
	for(int i = n + 1; i <= m; i++){
		bool prime = true;
		if(i == 2) count++;
		if(i % 2 == 0) continue;
		for(int j = 3; j * j <= i; j += 2){
			if(i % j == 0){
				prime = false;
				break;
			}
		}
		if(prime) count++;
	}

	return count;
}


int main(){
	int n = 0;
	while(cin >> n && n != 0){
		cout << countPrime(n, n*2) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
/*	ex9_1
	suzuto	*/

#include <stdio.h>
#include <stdlib.h>
#define SIZE 10

typedef struct stack{ /*入力した文字をスタックとして重ねていくための構造体を作る*/
  int size;
  int count;
  char inp_str[SIZE];
  char *top;
}stack;

/*プロトタイプ宣言*/
void initialize_stack(stack *stack_ptr);
void push(stack *stack_ptr, char add_elem);
char pop(stack *stack_ptr);

int main(void){
  stack inp_stack, res_stack; /*変数の宣言*/
  char inp[SIZE + 1], ins;
  int i;

  initialize_stack(&inp_stack); /*inp_stackを初期化*/
  initialize_stack(&res_stack); /*res_stackを初期化*/

  scanf("%s", &inp); /*入力内容を記憶*/

  for(i = 0; i < SIZE + 1; i++){
    ins = inp[i]; /*i + 1番目の入力取り出し*/
    if(ins == '\0'){ /*末尾の識別*/
      break;
    }
    if(ins == 'B'){ /*バックスペースの時、スタックから一番上=最後に入力した文字を取り出す*/
      pop(&inp_stack);
    }
    else{
      push(&inp_stack, ins); /*文字入力の時、スタックの一番上に追加*/
    }
  }

  while (inp_stack.count > 0){ /*inp_stackの中身を全て(逆順に)res_stackに移し替える*/
    push(&res_stack, pop(&inp_stack));
  }

  while (res_stack.count > 0){ /*res_stackの中身を上から順に取り出していって答えを出力*/
    putchar(pop(&res_stack));
  }
  printf("\n"); /*改行*/
  return 0;
}

void initialize_stack(stack *stack_ptr){ /*スタックを初期化する関数*/
  stack_ptr->count = 0; /*要素の数 = 0*/
  stack_ptr->size = SIZE;
  stack_ptr->top = &(stack_ptr->inp_str[SIZE]); /*スタックの底に頂点を合わせる*/
}

void push(stack *stack_ptr, char add_elem){ /*スタックに要素を追加する関数*/
  if(stack_ptr->count >= stack_ptr->size){ /*スタックをあふれた時のエラー出力*/
    fprintf(stderr, "Error: stack overflow.\n");
    exit(1);
  }else{ /*頂点の位置を1つ上げて、その位置に要素を積む*/
    stack_ptr->top--;
    *(stack_ptr->top) = add_elem;
    stack_ptr->count++;
  }
}

char pop(stack *stack_ptr){
  char output_elem;
  if(stack_ptr->count <= 0){ /*スタックの底が尽きている時には何も取り出さない*/
    return 'B'; /*意味のない仮の出力*/
  }else{ /*一番上の要素を取り出し、頂点を一個下げる*/
    output_elem = *(stack_ptr->top);
    stack_ptr->count--;
    stack_ptr->top++;
    return output_elem;
  }
}


Measured memory_bytes: 1664
S=input()
if len(S)<26:
    for char in range(ord("a"),ord("z")):
        if chr(char) not in S:
            break
    print(S+chr(char))
else:
    stack=list(S[-1])
    for s in S[len(S)-2::-1]:
        if s>stack[-1]:
            stack.append(s)
        else:
            break
    if len(stack)==26:
        print(-1)
    else:
        print(S[:-len(stack)-1]+min(s for s in stack if s>S[-len(stack)-1]))

Measured memory_bytes: 8888
N = int(input())
bL = [int(input()) for _ in range(N)]

time = 1
push = 0
while True:
    
    if bL[push] == 2:
        print(time)
        break
    if time == N:
        print("-1")
        break
    
    push = bL[push]-1
    
    time += 1

Measured memory_bytes: 12984
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;
const int inf = 1e9;

int main(){
    int n,e,t;
    cin >> n >> e >> t;
    t--;
    vector<int> w(n);
    for(int i=0; i<n; i++){
        cin >> w[i];
    }
    vector<vector<vector<int>>> rule(n);
    for(int i=0; i<e; i++){
        int prod,m;
        cin >> prod >> m;
        prod--;
        vector<int> materials(m);
        for(int &mat: materials){
            cin >> mat;
            mat--;
        }
        rule[prod].push_back(materials);
    }

    vector<vector<pair<int,int>>> to(n);
    for(int i=0; i<n; i++){
        for(int j=0; j<(int)rule[i].size(); j++){
            for(int k: rule[i][j]){
                to[k].emplace_back(i, j);
            }
        }
    }
    vector<vector<int>> rulecount(n);
    for(int i=0; i<n; i++){
        for(const auto &v: rule[i]){
            rulecount[i].push_back(v.size());
        }
    }

    vector<int> mincost(n, inf);
    priority_queue<pair<int,int>> wait;
    for(int i=0; i<n; i++){
        if(w[i] == 1){
            mincost[i] = 1;
            wait.push({-1, i});
        }
    }
    while(!wait.empty()){
        int c = -wait.top().first;
        int v = wait.top().second;
        wait.pop();
        if(c > mincost[v]) continue;
        for(auto p: to[v]){
            int nv = p.first;
            int rn = p.second;
            rulecount[nv][rn]--;
            if(rulecount[nv][rn] == 0){
                vector<int> cost;
                for(int mat: rule[nv][rn]){
                    cost.push_back(mincost[mat]);
                }
                sort(cost.begin(), cost.end(), greater<int>());
                int nc = 0;
                for(int i=0; i<(int)cost.size(); i++){
                    nc = max(nc, cost[i] +i);
                }
                if(nc < mincost[nv]){
                    mincost[nv] = nc;
                    wait.push({-nc, nv});
                }
            }
        }
    }
    if(mincost[t] == inf){
        cout << -1 << endl;
    }else{
        cout << mincost[t] << endl;
    }
    return 0;
}


Measured memory_bytes: 3320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
bool cmp(P p1,P p2){
	return (p1.sc)*(p2.fi+p2.sc) < (p2.sc)*(p1.fi+p1.sc);
}
bool dp[3005]; vector<int>vi;
int main(){
	int a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;
	dp[0] = 1; vi.pb(0);
	for(int i=1;i<=3000;i++){
	    if(i>=c && dp[i-c])dp[i]=1;
	    if(i>=d && dp[i-d])dp[i]=1;
	    if(dp[i])vi.pb(i);
	}
	P ans = mp(100*a,0);
	for(int i=0;i<=30;i++){
		for(int j=0;j<=30;j++){
			if(i+j==0) continue;
			if(f < 100*a*i + 100*b*j) continue;
			int W = 100*a*i + 100*b*j;
			int S = min(f-W,W/100*e),T = 0;
			T = vi[POSU(vi,S)-1];
			if(cmp(ans,mp(W,T))) ans = mp(W,T);
		}
	}
	cout<<ans.fi+ans.sc<<" " <<ans.sc<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

public class Magatro
{
    public void Solve()
    {
        int a, b, c;
        string[] s = Console.ReadLine().Split(' ');
        a = int.Parse(s[0]);
        b = int.Parse(s[1]);
        c = int.Parse(s[2]);
        if (b - a == c - b)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

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

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    
    
    return 0;
}


Measured memory_bytes: 3844
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#define int long long
using namespace std;

int MOD = 1000000007;
int N;

vector<int> rev(vector<int> &X) {
	vector<int> res(N);

	for (int i = 0; i < N; i++) {
		res[X[i]] = i;
	}
	return res;
}

vector<int> mul(vector<int> &X, vector<int> &Y) {
	vector<int> res(N);

	for (int i = 0; i < N; i++) {
		res[i] = Y[X[i]];
	}
	return res;
}

vector<int> ID;

vector<int> po(vector<int> &X, int k) {
	if (k == 0) {
		return ID;
	}
	vector<int> res = po(X, k / 2);
	res = mul(res, res);
	if (k % 2 == 1) {
		res = mul(res, X);
	}
	return res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int K;
	cin >> N >> K;
	ID.resize(N);
	for (int i = 0; i < N; i++) {
		ID[i] = i;
	}
	vector<int> revA(N);
	vector<int> revB(N);
	for (int i = 0; i < N; i++) {
		cin >> revA[i];
		revA[i]--;
	}
	for (int i = 0; i < N; i++) {
		cin >> revB[i];
		revB[i]--;
	}
	vector<int> A = rev(revA);
	vector<int> B = rev(revB);
	int X[4] = { 2,-1,-2,1 };
	vector<vector<int> > XX(4);
	XX[0] = B;
	XX[1] = revA;
	XX[2] = revB;
	XX[3] = A;
	vector<int> ALL = ID;
	for (int i = 0; i < 4; i++) {
		ALL = mul(ALL, XX[i]);
	}
	vector<int> Z;
	if (K % 3 == 0) {
		int num = 2 * (K / 3) - 2;
		Z = po(ALL, num / 4);
		for (int i = 0; i < num % 4; i++) {
			Z = mul(Z, XX[i]);
		}
		vector<int> revZ = rev(Z);

		if (K % 2 == 0) {
			Z = mul(Z, revB);
			Z = mul(Z, A);

		} else {
			Z = mul(Z, B);
			Z = mul(Z, revA);
		}
		Z = mul(Z, revZ);
	} else if (K % 3 == 1) {
		int num = 2 * (K / 3) - 1;
		Z = po(ALL, num / 4);
		for (int i = 0; i < num % 4; i++) {
			Z = mul(Z, XX[i]);
		}
		vector<int> revZ = rev(Z);
		if (K % 2 == 0) {
			Z = mul(Z, revA);
		} else {
			Z = mul(Z, A);
		}
		Z = mul(Z, revZ);
	} else {
		int num = 2 * (K / 3);
		Z = po(ALL, num / 4);
		for (int i = 0; i < num % 4; i++) {
			Z = mul(Z, XX[i]);
		}
		vector<int> revZ = rev(Z);
		if (K % 2 == 0) {
			Z = mul(Z, B);
		} else {
			Z = mul(Z, revB);
		}
		Z = mul(Z, revZ);
	}
	Z = rev(Z);
	if (K == 1) Z = revA;
	if (K == 2) Z = revB;
	for (int i = 0; i < N; i++) {
		if (i > 0)cout << " ";
		cout << Z[i] + 1;
	}
	cout << endl;
}

Measured memory_bytes: 10464
def my_reverse(ary, b, e):
    while b < e-1:
        temp = ary[b]
        ary[b] = ary[e-1]
        ary[e-1] = temp
        b += 1
        e -= 1
    return ary


def main():
    input()
    ary = [int(x) for x in input().split(' ')]
    q = int(input())
    for i in range(q):
        b, e = [int(x) for x in input().split(' ')]
        ary = my_reverse(ary, b, e)
    print(' '.join([str(x) for x in ary]))


if __name__ == '__main__':
    main()



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

int main () {
  vector<int> line(4) ;
  
  for (int i = 0 ; i < 4 ; i++ ){
    cin >> line.at(i) ;
  }
  
  sort (line.begin() , line.end() ) ;
  
  if ( line.at(0) == 1 && line.at(1) == 4 && line.at(2) == 7 && line.at(3) == 9) {
    cout << "YES" << endl ;
  } else {
    cout << "NO" << endl ;
  }
}

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

using namespace std;

#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main(void){

    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n+1), b(m+1);
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= m; ++i) cin >> b[i];
    for(int i = 1; i <= n; ++i) a[i] += a[i-1];
    for(int i = 1; i <= m; ++i) b[i] += b[i-1];

    int ans = 0;
    for(int i = 0; i <= n && k - a[i] >= 0; ++i){
        int ng = -1, ok = b.size(), mid = 0;
        while (abs(ok - ng) > 1) {
            mid = (ok + ng) / 2;

            if (k - a[i] < b[mid]) ok = mid;
            else ng = mid;
        }
        ans = max(ans, i + ok - 1);
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 6428
/*
 * 2406.cc: Al dente
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, t, e;
  cin >> n >> t >> e;

  int ans = -1;
  
  for (int i = 0; ans < 0 && i < n; i++) {
    int xi;
    cin >> xi;
    int rem = t % xi;
    if (rem <= e || rem >= xi - e) {
      ans = i + 1;
      break;
    }
  }

  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
int n,v[1<<19];
bool viz[1<<19];
vector<int> a;
int main()
{
    cin>>n;
    for(int i=0;i<(1<<n);i++) cin>>v[i];
    sort(v,v+(1<<n));
    reverse(v,v+(1<<n));
    a.push_back(v[0]);
    viz[0]=1;
    for(int i=0;i<n;i++)
    {
        int k=1;
        for(int j=0;j<(1<<i);j++)
        {
            while(k<(1<<n)&&(v[k]>=a[j]||viz[k])) k++;
            if(k==(1<<n))
            {
                cout<<"No";
                return 0;
            }
            viz[k]=1;
            a.push_back(v[k]);
        }
        sort(a.begin(),a.end());
        reverse(a.begin(),a.end());
    }
    cout<<"Yes";
}


Measured memory_bytes: 2676
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <numeric>

//#include <map>

using namespace std;

void call(int n)
{
	int i = 1;

	while (i <= n)
	{
		int x = i;
		if (x % 3 == 0)
		{
			cout << " " << i;
		}
		else
		{
			while (x)
			{
				if (x % 10 == 3)
				{
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}

		++i;
	}
	cout << endl;
}

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

	return 0;
}

Measured memory_bytes: 3104
#include <cstdio>
char m[22][22];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

void solve(int x,int y){
  m[x][y] = '0';
  for(int i = 0; i < 4; i++){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(0 <= nx && nx < 12 && 0 <= ny && ny < 12 && m[nx][ny] - '0'){
      solve(nx,ny);
    }
  }
}

int main(void)
{
  while(1){
    for(int i = 0; i < 12; i++){
      if(scanf("%s",m[i]) == EOF){
	return 0;
      }
    }

    int ret = 0;
    for(int i = 0; i < 12; i++){
      for(int j = 0; j < 12; j++){
	if(m[i][j] - '0'){
	  solve(i,j);
	  ret++;
	}
      }
    }
    printf("%d\n",ret);
  }
}

Measured memory_bytes: 968
N = int(input())
travel = [0, 0, 0]
flag = True
for i in range(N):
    new_travel =  list(map(int, input().split(' ')))
    change = [new_travel[i] - travel[i] for i in range(3)]
    if abs(change[1]) + abs(change[2]) - change[0] > 0 or\
    ((abs(change[1]) + abs(change[2])) - change[0])%2 !=0:
        print('No')
        flag = False
        break
    travel = new_travel

if flag == True:
    print("Yes")

Measured memory_bytes: 3064
#include<stdio.h>
  int main(void)
{
   double r,S,l;
   scanf("%lf",&r);
     S = r*r*3.141592653589;
     l = r*2*3.141592653589;

   printf("%.6lf %.6lf\n",S,l);
    return 0;
}

Measured memory_bytes: 2700
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    bool ans = true;

    while(ans && !s.empty()) {

        string s5 = (n>=5? s.substr(n-5, 5) : "");
        string s6 = (n>=6? s.substr(n-6, 6) : "");
        string s7 = (n>=7? s.substr(n-7, 7) : "");


        if (s5 == "dream" || s5 == "erase") {
            for (int _ = 0; _<5; _++) s.pop_back();
        } else if (s6 == "eraser") {
            for (int _ = 0; _<6; _++) s.pop_back();
        } else if (s7 == "dreamer") {
            for (int _ = 0; _<7; _++) s.pop_back();
        } else ans = false;


        n = s.size();
    }

    cout << (ans? "YES" : "NO") << endl;
}

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

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

	string str;
	while(cin >> str){
		int joi = 0;
		int ioi = 0;
		if(str.size() > 2){
			for(size_t i = 0; i < str.size() - 2; ++i){
				if(str[i] == 'J' && str[i + 1] == 'O' && str[i + 2] == 'I'){
					++joi;
				}
			}
			for(size_t i = 0; i < str.size() - 2; ++i){
				if(str[i] == 'I' && str[i + 1] == 'O' && str[i + 2] == 'I'){
					++ioi;
				}
			}
		}

		cout << joi << endl;
		cout << ioi << endl;
	}

	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
long long n,W;
long long w[105],v[105];
long long dp[105][100005];
int main()
{
	cin>>n>>W;
	for(int i=1;i<=n;i++) 
		cin>>w[i]>>v[i];
	for(int i=0;i<=n;i++)
		for(int j=0;j<=W;j++)
			dp[i][j]=-1e18;
	dp[0][0]=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<=W;j++)
		{
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(j+w[i+1]<=W) 
				dp[i+1][j+w[i+1]]=max(dp[i+1][j+w[i+1]],dp[i][j]+v[i+1]);
		}
	long long ans=0;
	for(int i=0;i<=W;i++) 
		ans=max(ans,dp[n][i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 80128
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int min(int a,int b){
  if(a<b)return a;
  return b;
}
int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<int>> dp(h,vector<int>(w,0)),a(h,vector<int>(w,1));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      char s;
      cin>>s;
      if(s=='.')a[i][j]=0;
    }
  }
  dp[0][0]=a[0][0];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(i>0&&j>0){
        int x=1,y=1;
        if(a[i-1][j]==a[i][j]||a[i][j]==0)x=0;
        if(a[i][j-1]==a[i][j]||a[i][j]==0)y=0;
      dp[i][j]+=min(dp[i][j-1]+y,dp[i-1][j]+x);
      }
      else{
        if(i>0&&j==0){
          int x=1;
          if(a[i-1][j]==a[i][j]||a[i][j]==0)x=0;
          dp[i][j]+=dp[i-1][j]+x;
        }
        else{
          if(i==0&&j>0){
            int x=1;
            if(a[i][j-1]==a[i][j]||a[i][j]==0)x=0;
           dp[i][j]=dp[i][j-1]+x;
          }
        }
      }
    }
  }
 
 cout<<dp[h-1][w-1]<<endl;
    return 0;
  }
      

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 100005; 
int H,n,cnt,a[N],use[N];
int main(){
	scanf("%d%d",&H,&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		cnt += a[i];
	}
	if(cnt>=H)
		puts("Yes");
	else
		puts("No");
} 

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<pair<int, int>> RL(n);
	for(int i=0;i<n;i++){
		int x,l;
		cin>>x>>l;
		RL[i]={x+l,x-l};	
	}
	sort(RL.begin(),RL.end());
	int ans=0;
	int R=-2e9;
	for(auto&p:RL){
		int r=p.first,l=p.second;
		if(l>=R){
			ans++;
			R=r;
		}
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, buf, a[108], mx, mn;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n;
	memset(a, 0, sizeof(a));
	mx = 1;
	mn = n-1;
	rep(i, 1, n){
		cin >> buf;
		a[buf]++;
		mx = max(buf, mx);
		mn = min(buf, mn);
	}
	bool ans = true;
	if(mx > n-1 || mn < (mx+1)/2){
		ans = false;
	}
	else{
		rep(i, mn+1, mx){
				if(a[i] < 2){
					ans = false;
				}
		}
		if(a[mn] != mx%2+1){
			ans = false;
		}
	}
	
	if(ans){
		print("Possible")
	}
	else{
		print("Impossible")
	}
	return 0;
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class XorSum {
        public static int MOD = 1_000_000_007;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = new long[n];

            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
            }
            long result = 0;
            for (int i = 0; i <= 60; i++) {
                long zero = 0;
                long one = 0;
                for (int j = 0; j < n; j++) {
                    if (((a[j] >> i) & 1) == 1) {
                        one++;
                    } else {
                        zero++;
                    }
                }
                long num = (one * zero) % MOD;
                result += modPow(2, i, MOD) * num % MOD;
                result %= MOD;

            }
            out.println(result);

        }

        static long modPow(long x, long n, long mod) {
            if (n == 0) {
                return 1;
            }
            long result = modPow(x, n / 2, mod);

            if (n % 2 == 0) {
                return (result * result) % mod;
            }
            return (((result * result) % mod) * x) % mod;
        }

    }
}



Measured memory_bytes: 63480
// ref. https://www.youtube.com/watch?v=9MphwmIsO7Q

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

// Morris-Pratt (MP, KMP)
// https://youtu.be/9MphwmIsO7Q?t=7283
template<typename T>
struct MP {
  int n;
  T t;
  vector<int> a;
  MP() {}
  MP(const T& t): t(t) {
    n = t.size();
    a = vector<int>(n+1);
    a[0] = -1;
    int j = -1;
    for (int i = 0; i < n; ++i) {
      while (j != -1 && t[j] != t[i]) j = a[j];
      j++;
      a[i+1] = j;
    }
  }
  int operator[](int i) { return a[i];}
  vector<int> findAll(const T& s) {
    vector<int> res;
    int j = 0;
    for (int i = 0; i < s.size(); ++i) {
      while (j != -1 && t[j] != s[i]) j = a[j];
      j++;
      if (j == n) {
        res.push_back(i-j+1);
        j = a[j];
      }
    }
    return res;
  }
};

// int main(int argc, char** argv) {
//   string t, s;
//   cin >> t;
//   cin >> s;
//
//   // Find all t in s. |t| <= |s|
//   MP<string> mp(t);
//   rep(i, t.size()+1) {
//     cout << mp[i] << ' ';
//   }
//   cout << endl;
//
//   vector<int> ans = mp.findAll(s);
//   for (int i : ans) {
//     cout << i << endl;
//   }
// }

vector<int> f(vector<int>& a) {
  int n = a.size();
  vector<int> res(n);
  rep(i, n) {
    res[i] = a[i]^a[(i+1)%n];
  }
  return res;
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

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

  vector<int> xa = f(a);
  vector<int> xb = f(b);
  xa.insert(xa.end(), xa.begin(), prev(xa.end()));

  // find all xb in (xa+xa[0..n-1))
  MP<vector<int>> mp(xb);
  vector<int> ks = mp.findAll(xa);
  for (int k : ks) {
    int x = a[k]^b[0];
    cout << k << " " << x << endl;
  }
}


Measured memory_bytes: 10736
#!/usr/bin/env python3
import sys
import math


def solve(N: int):
    print(math.floor(math.pow(N,0.5))**2)



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		
		for (;;) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int k = sc.nextInt();

			if ((n | m | k) == 0) {
				break;
			}

			double dp[] = new double[n * m];
			dp[0] = 1;
			for(int i = 0 ; i < n ; i++){
				double nextDP[] = new double[n*m];
				for(int j = 0 ; j < n*m;j++){
					for(int z = 1 ; z <= m ;z++){
						if(j - z >= 0){
							nextDP[j] += dp[j-z]/m;
						}
					}
				}
				dp = nextDP;
			}

			
			double v = 0;
			for (int i = 0; i <= k; i++) {
				v += (k - i + 1) * dp[i];
				
			}
			v += n * (m + 1) / 2.0;
			v -= k;
			System.out.println(v);

		}

	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 12000
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
m = 0
for i in range(n):
    m += a[i] * f[i]
l, r = -1, m
while l + 1 != r:
    m = (l + r) // 2
    tmp = 0
    for i in range(n):
        tmp += max(a[i] - m // f[i], 0)
    if k < tmp:
        l = m
    else:
        r = m
print(r)

Measured memory_bytes: 120652
import java.util.*;
import java.math.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    BigDecimal X = new BigDecimal(sc.next());
    int ans = 0;
    BigDecimal RATE = BigDecimal.valueOf(1.01);
    BigDecimal deposit = BigDecimal.valueOf(100);
    while (deposit.compareTo(X) < 0) {
      deposit = deposit.multiply(RATE).setScale(0, RoundingMode.DOWN);
      ans++;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 36476
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

const int loose = 0;
const int tight = 1;

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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


class UnionFind {
	vector<int> data;
	int num;
public:
	UnionFind(int size) : data(size, -1), num(size) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
			num--;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
	int numSet() {
		return num;
	}
};


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

	ll n, m, k;
	cin >> n >> m >> k;
	Graph g(n);
	Graph gb(n);
	UnionFind uni(n);
	REP(i, m) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		add_edge(g, a, b, 1, true, 1);
		uni.unionSet(a, b);
	}
	REP(i, k) {
		ll c, d;
		cin >> c >> d;
		c--; d--;
		add_edge(gb, c, d, -1, true, -1);
	}

	REP(i, n) {
		ll num = uni.size(i)-g[i].size()-1;
		for (auto e : gb[i]) {
			if (uni.findSet(e.to, i)) {
				num--;
			}
		}
		cout << num << " ";
	}
	cout << endl;

	return 0;
}

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

using namespace std;

#define all(v) (v).begin(), (v).end()

using li = long long;

bool can(li nOps, vector<li> a)
{
    int n = a.size();
    li buffer = 0;
    for (int i = 0; i < (int)a.size(); i++)
    {
        a[i] += nOps;
        if (a[i] >= (n - 1))
            buffer += (a[i] - (n - 1)) / (n + 1) + 1;
        if (buffer >= nOps) return true;
    }
    return buffer >= nOps;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    vector<li> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    unsigned long long answer = 0;
    while (true)
    {
        sort(a.rbegin(), a.rend());
        
        int r = 0;
        while (r + 1 < n && a[0] - a[r + 1] <= n) r++;
        
        // group [0, r] will have cyclic evolutions with period (r+1):
        // down by n-r in (r+1) steps
        
        if (r == n - 1)
        {
            //printf("OK\n");
            li can_steps = a[0] - 1000;
            if (can_steps > 0)
            {
                answer += (can_steps) * (unsigned long long)(r + 1);
                for (int i = 0; i < n; i++)
                    a[i] -= can_steps;
                continue;
            }
        }
        else
        {
            li down = n - r;
            // a[r] - down * steps - 3 * n <= a[r + 1] + steps * (r + 1)
            
            li steps = (a[0] - a[r + 1]) / (down + r + 1);
            steps -= 100;
            //printf("%lld\n", steps * (li)(r + 1));
            
            if (steps > 0)
            {
                for (int i = 0; i <= r; i++)
                    a[i] -= steps * (li)(n - r);
                for (int i = r + 1; i < n; i++)
                    a[i] += steps * (li)(r + 1);
                
                answer += steps * (unsigned long long)(r + 1);
                continue;
            }
        }
        
        if (a[0] < n) break;
        
        a[0] -= n;
        for (int k = 1; k < n; k++)
            a[k]++;
        
        answer++;
    }
    
    cout << answer << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int k = sc.nextInt();
      Queue<String> queue = new LinkedList<>();
      for(int i = 1; i <= 9; i++)
        queue.offer(i + "");
      for(int i = 1 ; i < k; i++) {
        String num = queue.poll();
        char lastChar = num.charAt(num.length() - 1);
        for(int j = -1; j <= 1; j++) {
          int lastNum = lastChar - '0' + j;
          if(lastNum < 0 || lastNum > 9) continue;
          queue.offer(num + lastNum);
        }
      }
      System.out.println(queue.peek());
  }
}

Measured memory_bytes: 57812
s = input()
s=s[::-1]

b_cnt=0
ans=[]
for c in s:
    if c=="B":
        b_cnt+=1
    elif b_cnt==0:
        ans.append(c)
    else:
        b_cnt-=1
        if b_cnt <0:
            b_cnt=0
ans.reverse()

for c in ans:
    print(c,end="")

Measured memory_bytes: 38384
_in =input().split()

#_in = ["10", "21"]
#文字の結合
cont_str = _in[0] + _in[1]

#数字に変換
cont_num = int(cont_str)


#平方数の判定
#総当たり頭悪そう　1<= ab <= 100 なので 4*4~ 100*100
sqrt_flag = False
for i in range(4, 1000):
        sqrt = i * i
        #print(sqrt)
        if cont_num == sqrt:
            sqrt_flag = True
            break
if sqrt_flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin>>n;
  
  vector<int> L(n);
  rep(i,n) cin>>L[i];
  
  sort(ALL(L));
  
  int sum=0;
  rep(i,n-1) sum+=L[i];
  
  if(L[n-1]<sum) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
using namespace std;
int n,m;

vector<int>dp;

vector<vector<int>> edge2;
int dfs(int n)
{
  if(dp[n]>-1)return dp[n];
  int res=0;
  for(int ne:edge2[n])
  {
    res=max(dfs(ne)+1,res);
  }
  dp[n]=res;
  return res;
}

int main()
{
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  dp=vector<int>(n+1,-1);
  edge2=vector<vector<int>>(n+1) ;
  for(int i=0;i<m;i++)
  {
    int a,b;
    cin>>a>>b;
    edge2[b].push_back(a);
  }
  for(int i=1;i<=n;i++)
  {
    if(dp[i]==-1)dfs(i);
  }


  int res;
  res=*max_element(dp.begin(), dp.end());
  cout<<res<<endl;



  return 0;

}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
#define rep(i, n)     for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n)    for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n)    for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n)   for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v)  for (auto &&V : v)
#define all(x)        (x).begin(), (x).end()
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = 1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, l;
  cin >> n >> l;
  int last = l + n - 1;
  int sum  = (l + last) * n / 2;
  if (last < 0) sum -= last;
  if (l > 0) sum -= l;
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    ll n,m;
    std::cin >> n >> m;
    std::vector<std::pair<ll,ll>> ab(n);
    rep(i,n){
        ll ai,bi;
        std::cin >> ai >> bi;
        ab[i] = std::make_pair(ai,bi);
    }

    std::sort(ab.begin(),ab.end());

    ll ans = 0, i=0;
    while(m>0){
        if(m > ab[i].second){
            m -= ab[i].second;
            ans += ab[i].first*ab[i].second;
            i++;
        }else{
            ans += ab[i].first*m;
            m = 0;
        }
    }
    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4800
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll k=in(),a=in(),b=in();
    cout<<((a+k-1)/k*k<=b?"OK":"NG")<<endl;
}


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

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

	int ans = 0;
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b ; j++){
			for(int k = 0; k <= c; k++){
				if(500*i + 100*j + 50*k == x)
					ans++;
			}
		}
	}

	cout << ans << endl;
}

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const int NMAX = 100;
bool flag;

bool comp(int x,int y){
    return abs(0-x)<abs(0-y);
}

signed main(){
    SCIN(s);
    flag=true;
    int cnt=0;
    if(s[0]=='A'){
        RepS(i,1,s.size()){
            if(isupper(s[i])){
                if(i==1||i==s.size()-1||s[i]!='C'){
                    flag=false;
                }
                cnt++;
            }
        }
    }
    if(cnt!=1){
        flag=false;
    }
    printf(flag?"AC":"WA");

    return 0;
}

Measured memory_bytes: 256