akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const int N = 1000;

enum {wait=0,hang,talk,end};

bool sim(int n,int *M,int *L,int *K,int T,int op){
  int now=0,can=op;
  static int event[N],state[N];
  rep(i,n)event[i]=0,state[i]=hang;
  while(now <= T){
    int next=T+1;

    rep(i,n)if(state[i] != end)next=min(next,event[i]);
    
//     cout << now <<" " <<next <<  endl;
//     cout <<"state ";rep(i,n)cout << state[i]<<" ";cout << endl;
//     cout <<"event ";rep(i,n)cout<<event[i]<<" ";cout << endl;

    if (next > T)break;
   
    rep(i,n){
      if (state[i] == talk && event[i] == next){
	state[i]=end;
	can++;
      }
    }
    
    rep(i,n){
      if (state[i] == hang && event[i] == next){
	state[i]=wait;
	event[i]=next+L[i];
      }
    }

    rep(i,n){
      if (state[i] == wait && can > 0){
	state[i]=talk;
	event[i]=next+M[i];
	can--;
      }
    }

    rep(i,n){
      if (state[i] == wait && event[i] == next){
	state[i]=hang;
	event[i]=next+K[i];
      }
    }

    now=next;
  }
  rep(i,n)if (state[i] != end)return false;
  return true;
}

int solve(int n,int *M,int *L,int *K,int T){
  int l=0,r=n-1, mid,ok=n;
  while(l <= r){
    mid=(l+r)/2;
    if (sim(n,M,L,K,T,mid))r=mid-1,ok=mid;
    else l=mid+1;
  }
  
  int ans=ok;
  for(int i=mid-1;i>0 && i >= mid-100;i--){
    if (sim(n,M,L,K,T,i))ans=i;
  }
  return ans;
}

main(){
  int n,t;
  int M[N],L[N],K[N];
  while(cin>>n>>t && n){
    rep(i,n)cin>>M[i]>>L[i]>>K[i];
    cout << solve(n,M,L,K,t) << endl;
  }
  return false;
}

Measured memory_bytes: 884
fun main(args: Array<String>) {
    val L = nextDouble()
    val ans = L * L * L / 27
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun nextLong() = java.lang.Long.parseLong(next())
fun nextLong(offset: Long = 0L) = nextLong() + offset
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }
fun listOfLong() = listOfString().map { java.lang.Long.parseLong(it) }
fun listOfLong(offset: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + offset }
fun listOfDouble() = listOfString().map { it.toDouble() }


Measured memory_bytes: 33656
import heapq
n, m = map(int, input().split())
hq = list(map(lambda x:int(x)*(-1), input().split()))
heapq.heapify(hq)
for i in range(m):
    work = ((-1)*heapq.heappop(hq))//2*(-1)
    heapq.heappush(hq, work)
print((-1)*sum(hq))

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

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        long n=Long.parseLong(s[0]),x=Integer.parseInt(s[1]); int m=Integer.parseInt(s[2]);
        boolean vis[]=new boolean[m];
        ArrayList<Integer> al=new ArrayList<>();
        if(x<m) {vis[(int)x]=true; n--; al.add((int)x);}
        long sum=x,fx=x; int found=-1,i;

        while(n!=0)
        {
            x=x*x%m;
            int t=(int)x;
            if(!vis[t])
            {
                vis[t]=true;
                al.add(t);
                sum+=t;
            }
            else
            {
                found=t;
                break;
            }
            n--;
        }
        if(n==0) {System.out.print(sum); return;}

        long sum1=0,sum2=0; int rem=0;
        for(i=0;i<al.size();i++)
        if(al.get(i)==found) break;
        else
        {
            rem++;
            sum1+=al.get(i);
        }

        for(;i<al.size();i++)
        sum2+=al.get(i);

        n+=al.size()-rem;
        long req=n/(al.size()-rem);
        sum=sum1+req*sum2;
        if(fx>=m) sum+=fx;

        n=n%(al.size()-rem);
        for(i=rem;n!=0;i++,n--)
        sum+=al.get(i);
        System.out.print(sum);
    }
}


Measured memory_bytes: 35112
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
#define vvectorl vector<vector<long long>>
#define vectorl vector<long long>
int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	int r = a % b;
	return gcd(b, r);
}
int squ(int x) {
	return x * x;
}
int di(vectorl x, vectorl y, int i, int j) {
	return squ(x[i] - x[j]) + squ(y[i] - y[j]);
}
int qmmin(int &a, int b) {
	if (a == -1) {
		a = b;
	}
	else {
		a = min(a, b);
	}
	return a;
}
int nex(int a) {
	return (a + 1) % 3;
}
signed main() {
	int h, w;
	cin >> h >> w;
	vector<vector<int>> jo(h + 1, vector<int>(w + 1, 0));
	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < w; j++) {
			if (s[j] == '.') {
				jo[i][j] = 1;
			}
		}
	}
	int p = 1000000000 + 7;
	vector<vector<int>> c(h+1, vector<int>(w+1,0));
	c[0][0] = 1;
	for (int d = 0; d < h + w; d++) {
		for (int i = 0; i <= min(d, h - 1); i++) {
			int j = d - i;
			if (j < w) {
				c[i][j + 1] += jo[i][j+1]*c[i][j];
				c[i + 1][j] += jo[i+1][j]*c[i][j];
				c[i][j + 1] = c[i][j + 1] % p;
				c[i + 1][j] = c[i + 1][j] % p;
			}
		}
	}
	cout << c[h - 1][w - 1] << endl;
}

Measured memory_bytes: 16000
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 9999999999
const double PI = 3.1415926535897932384626433832795;

ll A[5000003];
ll ans = 0;

void Marge(ll* A, int n, int left, int mid, int right)
{
	int n1 = mid - left;
	dbg(n1);
	int n2 = right - mid;
	dbg(n2);
	
	vector<ll> L;
	REP(i,n1) L.pb(A[left + i]);
	L.pb(INF);
	vector<ll> R;
	REP(i,n2) R.pb(A[mid+i]);
	R.pb(INF);
	
	ll j = 0;
	ll k = 0;
	FOR(i, left, right)
	{
		if (L[j] >= R[k])
		{
			A[i] = R[k];
			k++;
		}
		else
		{
			A[i] = L[j];
			j++;
		}
	}
	ans += right - left;
}

void MargeSort(ll* A, int n, int left, int right)
{
	if (left + 1 < right)
	{
		int mid = (left + right)/2;
		dbg(mid);
		MargeSort(A, n, left, mid);
		MargeSort(A, n, mid, right);
		Marge(A, n, left, mid, right);
	}
}

int main()
{
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	REP (i,n) cin >> A[i];
	MargeSort(A, n, 0 , n);
	REP (i,n-1) cout << A[i] << " ";
	cout << A[n-1] << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11536
n = int(input())
w = list(map(int, input().split()))
abs_diff = float('inf')
idx = 0
for i in range(n):
    if abs(sum(w[:i]) - sum(w[i:])) < abs_diff:
        abs_diff = abs(sum(w[:i]) - sum(w[i:]))
        idx = i
print(abs_diff)


Measured memory_bytes: 9212
import sys
from copy import deepcopy
import itertools
input = sys.stdin.readline

N, T = map(int, input().split())
dish = []
for _ in range(N):
	A, B = map(int, input().split())
	dish.append((A, B))
dish.sort() # sort by time

"""
作戦：最適解が求まっている時、それを食べる順序を（ラストオーダー以外は）変更しても問題なし。
そこで注文順は（ラストオーダー以外）食べる時間が昇順であるとして良い。
具体的には、ラストオーダーkを決める ⇒ 0,...,k-1の中で満足度を最大にする
ここまで落とし込めばあとはナップサック問題。
"""

"""
dp[i][j] = 0~i 番目の料理で j 分以内に完食できる美味しさの合計の最大値
"""

dp = [[0] * T for _ in range(N)]
a_0, b_0 = dish[0]
if a_0 < T:
	for j in range(a_0, T):
		dp[0][j] = b_0

for i in range(1, N):
	a, b = dish[i]
	for j in range(1, T):
		if j >= a:
			dp[i][j] = max(dp[i-1][j], dp[i-1][j-a] + b)
		else:
			dp[i][j] = dp[i-1][j] #ここ忘れてた！

#print(dp)


ans = b_0
for k in range(1, N):
	ans = max(ans, dp[k-1][T-1] + dish[k][1])

print(ans)


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

using namespace std;

int read() {
	int x = 0; char c = getchar();
	while (c > '9' || c < '0') c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
	return x;
}

const int maxn = 1e5 + 10;

long long d[maxn], a[maxn], n, sum, t;

int main() {
	n = read();
	for (int i = 0; i < n; i ++) {
		a[i] = read();
		sum += a[i];
		t += (i + 1);
	}
	if (sum % t) puts("NO");
	else {
		t = sum / t;
		for (int i = 0; i < n; i ++) d[i] = a[(i + 1) % n] - a[i] - t;
		for (int i = 0; i < n; i ++) if (d[i] % n || d[i] > 0) return puts("NO"), 0; 
		puts("YES");
	}
	return 0;
}

Measured memory_bytes: 1792
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
i, j = [], []
for s in range(n):
    num = s+1
    i.append(a[s]+num)
    j.append(num-a[s])
x = Counter(j)
result = 0
for p in range(n-1):
    if i[p] in x:
        result += x[i[p]]
    x[j[p]] += 1 
print(result)

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

public class Main {

	void go(int R, int C, int r, int c) {
		int cx = 0;
		int cy = R * C;
		for (int i = r - 1; i < R; i += r) {
			for (int j = c - 1; j < C; j += c) {
				cx++;
				cy--;
			}
		}
		
		// x > (rc - 1) y
		// cx * x < cy * y
		
		if ((r * c - 1) * cx >= cy) {
			throw new AssertionError();
		}
		
		int x = 2 * cx * (r * c - 1) + 1;
		int y = 2 * cx;
		
		out.println("Yes");
		for (int i = 0; i < R; i++) {
			for (int j = 0; j < C; j++) {
				if (i % r == r - 1 && j % c == c - 1) {
					out.print((-x) + " ");
				} else {
					out.print(y + " ");
				}
			}
			out.println();
		}
	}
	
	void submit() {
		int R = nextInt();
		int C = nextInt();
		int r = nextInt();
		int c = nextInt();
		if (R % r == 0 && C % c == 0) {
			out.println("No");
			return;
		}
		
		go(R, C, r, c);
	}

	void preCalc() {

	}

	void stress() {
		for (int tst = 0;; tst++) {
			int R = rand(1, 500);
			int C = rand(1, 500);
			int r = rand(1, R);
			int c = rand(1, C);
			if (R % r == 0 && C % c == 0) {
				continue;
			}
			go(R, C, r, c);
			System.err.println(tst);
		}
	}

	void test() {
		int R = 500;
		int C = 500;
		int r = 500;
		int c = 499;
		go(R, C, r, c);
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
//		stress();
//		test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


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

namespace Atcoder
{
    class Atcoderrrrrr
    {
        static void Main(string[] args)
        {
            long[] s = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

            if(s[0]+s[1]+1 >= s[2])//解毒可能
            {
                Console.WriteLine(s[1] + s[2]);
            }
            else
            {
                Console.WriteLine(s[2] - (s[2] - (s[0] + s[1] + 1)) + s[1]);
            }
        }
    }
}

Measured memory_bytes: 11348
// デック 両端キュー
#include <bits/stdc++.h>
using namespace std;

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

using ll=long long;

deque<char> v; // 宣言

int main(){
    bool inv=false;
    string s;
    int t,f,q;
    char c;
    cin>>s;
    rep(i,s.size()) v.push_back(s[i]);
    cin>>q;
    rep(i,q){
        cin>>t;
        if(t==1) inv =!inv;
        else{
            cin>>f>>c;
            if(f==1){
                if(!inv) v.push_front(c);
                else v.push_back(c);
            }
            else{
                if(!inv) v.push_back(c);
                else v.push_front(c);            
            }
        }
    }
    if(!inv){
        while(!v.empty()){
            cout<<v.front();
            v.pop_front();
        }
    }
    else{
        while(!v.empty()){
            cout<<v.back();
            v.pop_back();
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 896
//At Coder -> Sum of Digits
//statement : Find number of integers between 1 and K such that sum of digits is multiple of D
//constraints : 1 <= K <= 1e10000   and     1 <= D <= 100
#include<bits/stdc++.h>
using namespace std;
const int MAXD = 102, MOD=1e9+7;
int d, dp_anterior[MAXD][2], dp_atual[MAXD][2];
// 0 => not smaller already
// 1 => smaller already
string k;
int main(){
    cin>>k>>d;
    //BASE CASE
    dp_anterior[0][0] = 1;

    for(int cur_digit=0; cur_digit<(int)k.size(); cur_digit++){
        for(int soma=0; soma<d; soma++){
            for(int candidate=0; candidate<=k[cur_digit]-'0'; candidate++){//for those NOT smaller already
                if(candidate < k[cur_digit]-'0'){//about to become smaller already
                    dp_atual[(soma+candidate)%d][1] = (dp_atual[(soma+candidate)%d][1] + dp_anterior[soma][0])%MOD;
                }else{//remains NOT smaller already
                    dp_atual[(soma+candidate)%d][0] = (dp_atual[(soma+candidate)%d][0] + dp_anterior[soma][0])%MOD;
                }
            }
            for(int candidate=0; candidate<=9; candidate++){//for those smaller already
                    dp_atual[(soma+candidate)%d][1] = (dp_atual[(soma+candidate)%d][1] + dp_anterior[soma][1])%MOD;
            }
        }
        for(int i=0; i<MAXD; i++){
            for(int j=0; j<2; j++){
                dp_anterior[i][j] = dp_atual[i][j];
                dp_atual[i][j] = 0;
            }
        }
    }
    cout << (dp_anterior[0][0]+dp_anterior[0][1] + MOD - 1)%MOD << endl;//excluir 0 da resposta
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define online_judge            freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio                    ios::sync_with_stdio(false);cin.tie(0);
#define ll                      long long
#define pii                     pair<int, int>
#define pli                     pair<ll, int>
#define pil                     pair<int, ll>
#define pll                     pair<ll, ll>
#define vi                      vector<int>
#define vll                     vector<ll>
#define vb                      vector<bool>
#define vd                      vector<double>
#define vs                      vector<string>
#define ff                      first
#define ss                      second
#define pb                      push_back
#define eb                      emplace_back
#define ppb                     pop_back
#define pf                      push_front
#define ppf                     pop_front
#define vpii                    vector<pii>
#define vpll                    vector<pll>
#define umap                    unordered_map
#define all(x)                  x.begin(),x.end()
#define clr(a,b)                memset(a,b,sizeof a)
#define fr(i, n)                for(ll i=0; i<n;++i)
#define fr1(i, n)               for(ll i=1; i<=n; ++i)
#define rfr(i, n)               for(ll i=n-1; i>=0; --i)
#define precise(x)              cout<<fixed<<setprecision(x)
#define wh                      while
#define mp                      make_pair
#define le                      length()
#define endl                    "\n"
#define sf                        scanf    
 
const ll M=1e9+7; 
 
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
ll lcm(ll a,ll b)
{ return (a*b)/__gcd(a,b); }
 
 
ll power(ll x, ll y, ll p)  
{  
    ll res = 1;    
 
    x = x % p;
   
    if (x == 0) return 0;
 
    while (y > 0)  
    {  
       
        if (y & 1)  
            res = (res*x) % p;  
 
       
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
bool inside(ll x,ll y,ll n,ll m)
{
    return(x>=0&&x<n&&y>=0&&y<m);
}  

ll powmod(ll n)
{
    ll ret = 1;
    ll a = 2;
    while (n > 0) {
        if (n & 1) ret = ret * a % M;
        a = a * a % M;
        n >>= 1;
    }
    return ret;
}
 
ll modfact(ll n, ll p)
{
    if (n >= p)
        return 0;
 
    ll result = 1;
    for (int i = 1; i <= n; i++)
        result = (result * i) % p;
 
    return result;
}

long long binpower(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpower(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}

///////////// TEMPLATE END /////////////////////////////////



void solve()
{
	bool c;
	ll n;
	cin>>n;
	c=n;
	
	if(n==1)cout<<"0"<<endl;
	
	else cout<<"1"<<endl;
}



int main()
{
    fastio

//    int t;
//    cin>>t;
//    fr1(i,t)
    {
//        cout<<"Case #"<<i<<": ";
        solve();
    }
   
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF  2000000000
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d); BR;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
#define SUM(a, n) accumulate(a, a+n, 0)
#define VSUM(v) accumulate(ALL(v), 0);
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

ll fn(ll a){
    string s = to_string(a);
    reverse(ALL(s));
    return stol(to_string(a) + s);
}

signed main(){ INIT;
    VAR(int, n, a, b);
    OUTL(min(a * n, b));
RET;}

Measured memory_bytes: 256
def main(argv)
  n = gets.chomp.to_i
  h = gets.chomp.split(' ').map(&:to_i)
  
  x = 0
  c = 0
  n.times do |i|
    if x <= h[i] then
      c += 1
    end
    
    x = [x, h[i]].max
  end
  
  puts c.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
import java.util.Scanner;

class Main{
	static final long MOD = 1000000007;

	static int H, W, K;
	static long[][] dp = new long[110][10];
	static int ans = 0;
	static long n = 0;





	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		String ss = sc.next();
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < 3;i++){
			if(ss.charAt(i) == '1'){
				sb.append("9");
			}else{
				sb.append("1");

			}
		}
		ss = sb.toString();
		System.out.println(ss);

	}
}







	class Pair implements Comparable{
		int from;		//p
		int end;		//y
		int num;
		int bango;
		@Override
		public int compareTo(Object other) {
			Pair otherpair = (Pair)other;

			return end - otherpair.end;
		}
	}



Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std; 
int main() {
	int a ,c;
	scanf("%d", &a) ;
	int b;
	scanf("%d", &b) ;

c=a+b;
if(c<24) 
printf("%d", c);
else
printf("%d", c-24);
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

string func(string message, char type) {
  int m = message.size();
  string res = message;
  if (type == 'J') {
    res = string(1, message[m-1]) + message.substr(0, m-1);
  } else if (type == 'C') {
    res = message.substr(1) + string(1, message[0]);
  } else if (type == 'E') {
    res = message.substr((m+1)/2) + (m%2?string(1, message[m/2]):"") + message.substr(0, m/2);
  } else if (type == 'A') {
    reverse(ALL(res));
  } else if (type == 'P') {
    REP(i, m)
      if (isdigit(message[i]))
        res[i] = (message[i] == '0') ? '9' : message[i]-1;
  } else if (type == 'M') {
    REP(i, m)
      if (isdigit(message[i]))
        res[i] = (message[i] == '9') ? '0' : message[i]+1;
  }
  return res;  
}
int main() {
  int n;
  cin >> n;
  while(n--) {
    string order, message;
    cin >> order >> message;
    for (int i=order.size()-1; i>=0; --i) {
      message = func(message, order[i]);
    }
    cout << message << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){

	int n,start,goal;

	scanf("%d",&n);

	for(int i=0; i < n; i++){
		scanf("%d %d",&start,&goal);

		if(start <= 5){
			if(start < goal){
				printf("%d",start);
				for(int k = start+1; k <= goal; k++){
					printf(" %d",k);
				}
				printf("\n");
			}else{
				printf("%d",start);
				for(int k = start-1; k >= goal; k--){
					printf(" %d",k);
				}
				printf("\n");
			}
		}else{ //start > 6
			if(goal >= 5){  //??´??????????????????
				if(start < goal){
					printf("%d",start);
					for(int k= start+1; k <= goal; k++)printf(" %d",k);

					printf("\n");

				}else{ //start > goal
					printf("%d",start);
					for(int k= start+1; k <= 9; k++)printf(" %d",k);
					if(goal != 5){
						printf(" 5 4 3 2 1 0 1 2 3 4");
					}
					for(int k=5; k <= goal; k++)printf(" %d",k);
					printf("\n");
				}

			}else{ //goal <= 4
				printf("%d",start);
				for(int k=start+1; k <= 9; k++)printf(" %d",k);
				for(int k=5; k >= goal; k--)printf(" %d",k);
				printf("\n");
			}

		}

	}

    return 0;
}

Measured memory_bytes: 2612
n,m,k = map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

asum=[0]
bsum=[0]
for i in range(n):
    asum.append(asum[i]+a[i])
for i in range(m):
    bsum.append(bsum[i]+b[i])

t=0
for i in range(n+1):
    if asum[i]>k:
        break
    now=k-asum[i]
    while bsum[m]>now:
        m-=1
    if t<i+m:
        t=i+m
        
print(t)

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

#include <bits/stdc++.h>

namespace Z_algorithm
{
    std::vector<int> prefix(const std::string &str)
    {
        std::vector<int> pref(str.size());
        for(int i = 1, j = 0; i < (int)str.size(); ++i)
        {
            if(pref[i - j] + i < pref[j] + j)
            {
                pref[i] = pref[i - j];
            }
            else
            {
                int k = std::max(0, pref[j] + j - i);
                while(k + i < (int)str.size() && str[k] == str[k + i])
                    ++k;
                pref[i] = k;
                j = i;
            }
        }
        pref[0] = str.size();
        return pref;
    }

    std::vector<int> prefix(const std::string &str, const std::string &key)
    {
        std::vector<int> pref = prefix(key + str);
        for(int &i : pref)
            i = std::min(i, (int)key.size());
        return std::vector<int>(pref.begin() + key.size(), pref.end());
    }
} // namespace Z_algorithm


main()
{
    int n; cin>>n;
    vector<int> a(n),b(n);
    for(int i=0; i<n; ++i)
    {
        cin>>a[i];
    }
    for(int i=0; i<n; ++i)
    {
        cin>>b[i];
    }
    vector<int> aa(n*2),bb(n);
    for(int i=0; i<n; ++i)
    {
        bb[i]=b[i]^b[(i+1)%n];
    }
    for(int i=0; i<n*2; ++i)
    {
        int ii=i%n;
        aa[i]=a[ii]^a[(ii+1)%n];
    }
    vector<int> cc(bb);
    cc.resize(bb.size()+aa.size());
    copy(aa.begin(),aa.end(),cc.begin()+bb.size());

    vector<int> pref(cc.size());
    for(int i = 1, j = 0; i < (int)pref.size(); ++i)
    {
        if(pref[i - j] + i < pref[j] + j)
        {
            pref[i] = pref[i - j];
        }
        else
        {
            int k = std::max(0, pref[j] + j - i);
            while(k + i < (int)pref.size() && cc[k] == cc[k + i])
                ++k;
            pref[i] = k;
            j = i;
        }
    }
    pref[0] = cc.size();

    for(int k=0; k<n; ++k)
    {
        if(pref[k+bb.size()]>=bb.size())
        {
            cout << k << " " << (b[0]^a[k]) << "\n";
        }
    }

}

Measured memory_bytes: 12016
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int l[10],v1,v2;
	for(;~scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",l,l+1,l+2,l+3,l+4,l+5,l+6,l+7,l+8,l+9,&v1,&v2);){
		int sum=0;
		int i;
		for(i=0;i<10;i++){
			sum+=l[i];
			//cout<<l[i]<<endl;
		}
		int len=0;
		for(i=0;i<10;i++){
			len+=l[i];
			if(len*v2>=(sum-len)*v1){
				cout<<i+1<<endl;
				break;
			}
		}
	}
	return 0;
}

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

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

const long long MOD = 100000000;

int main(){
  int n,d,a;
  cin >> n >> d;
  vector<vector<int>> x(n,vector<int>());
  rep(i,n){
    rep(j,d){
      cin>>a;
      x.at(i).push_back(a);
    }
  }
  int ans=0,t=0;
  double s=0;
  rep(i,n-1){
    for(int j=i+1;j<n;j++){
	  s=0;
      rep(k,d){
      s+=pow(x.at(i).at(k)-x.at(j).at(k),2);
      }
      s=sqrt(s);
      t=(int)s;
      if(s-t==0)ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
int rap[51];
bool sta[51];
int main() {

  int n,k;
  cin >> n >> k;

  for(int i=1;i<=k;i++) {
    int m;
    cin >> m;
    for(int j=0;j<m;j++){
      int a;
      cin >> a;
      rap[a] = i;
    }
  }

  int m;
  cin >> m;
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    if(rap[a] == rap[b]) sta[a] = sta[b] = 1;
  }

  int ans  = 0;
  for(int i=1;i<=n;i++)
    if(sta[i] == 1)ans++;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i,n) for(ll i=0;i<(int)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(int)(n);i++)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<ll,ll> pint;
const long long INF = 1LL<<60;
const ll MOD = 998244353
;
ll gcd(ll a,ll b){
    if(b==0){
        return a;
    }
    else{
        return gcd(b,a%b);
    }
}
#include <iostream>
using namespace std;

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long myPow(long x, long n, long m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}


int main(){
    ll n,m,k;cin>>n>>m>>k;
    ll ans =0;
    COMinit();
    rep(i,k+1){
        //cout<<myPow(m-1,n-i-1,MOD)<<COM(n-1,i)<<endl;
        ans+=m*myPow(m-1,n-i-1,MOD)%MOD*COM(n-1,i)%MOD;
    }
    cout<<ans%MOD<<endl;
}


Measured memory_bytes: 15592
#include <stdio.h>

int main()
{
	int a, b, c;
	int k;
	int n;

	scanf("%d%d%d", &a, &b, &c);
	n = 0;
	for (k = a; k <= b; k++) {
		if (c % k == 0) n++;
	}
	printf("%d\n", n);
	return 0;
}



Measured memory_bytes: 2100
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    string S;
    int K;

    cin >> N;
    cin >> S;
    cin >> K;

    char kth_S = S[K - 1];

    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] != kth_S)
        {
            S[i] = '*';
        }
    }

    cout << S;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var n = int.Parse(spl[0]);
        var k = int.Parse(spl[1]);
        var ary = ToIntArray(input.ReadLine(), n);

        int c = 0;
        n -= k;
        c++;

        while (n > 0) {
            n = n - (k - 1);
            c++;
        }

        return c;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 17248
a = input()
a = a.split()
b = input()
b = b.split()

for i in range(len(a)):
    a[i] = int(a[i])

for i in range(len(b)):
    b[i] = int(b[i])
    
b.sort()
c = 0


for i in range(a[1]):
    c = c + b[i]

print(c)

Measured memory_bytes: 9040
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        x: i64, n: usize,
        p: [i64; n]
    }

    let mut minim = 1<<30;
    let mut ans = -201;
    for y in -200..=200 {
        let dist = (x - y).abs();
        if !p.contains(&y) && dist < minim {
            minim = dist;
            ans = y;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2164
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let v:Vec<i32> = procon_read();
	let d = v[0];
	let x = v[1];
	let mut cnt = x+n;
	for i in 0..n {
		let v:Vec<i32> = procon_read();
		let a = v[0];
		for i in 1.. {
			if i*a+1 > d {
				break;
			}
			cnt += 1;
		}
	}
	println!("{}", cnt);
}

Measured memory_bytes: 4352
/*This is the solution from Ling2Feng1, no matter AC or not.*/
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<vector>
#include<math.h>
#include<time.h>
#include<utility>
#include<cstdlib>
#include<sstream>
#include<fstream>
#include<cstring>
#include<stdio.h>
#include<iomanip>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
priority_queue<pair<int,int> > pq;
int dis[100032];
void dijkstra(){
	for(int i=0;i<100032;i++) dis[i]=1000000007;
	dis[1]=1;
	pq.push(pair<int,int>(-1,1));
	while(pq.size()){
		pair<int,int> p=pq.top();
		pq.pop();
		int u=p.second;
		int w=p.first;
		if(dis[u*10%n]>-w){
			dis[u*10%n]=-w;
			pq.push(pair<int,int>(w,u*10%n));
		}
		if(dis[(u+1)%n]>-w+1){
			dis[(u+1)%n]=-w+1;
			pq.push(pair<int,int>(w-1,(u+1)%n)); 
		}
	}
}
int main(){
	cin>>n;
	dijkstra();
	cout<<dis[0]<<endl;
	return 0;
} 

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

#define req(i,r,k) for(int i=k;i<r;i++)
#define rep(i,r) req(i,r,0)

const int INF = 100000000;

int main() {

    int h,w;

    int m[50][50];

    int dp[51][51] = {INF};

    cin >> h >> w;

    char c;

    rep(i,h){
        rep(j,w){
            scanf(" %c",&c);
            stringstream ss;
            ss << c;
            ss >> m[i][j];
        }
    }

    dp[0][0] = 0;

    rep(i,h-1){
        dp[i+1][0] = dp[i][0] + m[i+1][0];
    }

    rep(j,w-1){
        dp[0][j+1] = dp[0][j] + m[0][j+1];
    }

    req(i,h,0){
        req(j,w,0){
            dp[i+1][j+1] = min(dp[i][j+1],dp[i+1][j]) + m[i+1][j+1];
        }
    }

    cout << dp[h-1][w-1] << endl;

    return 0;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

const ll MOD = 1000000007;


ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  map<ll, ll> mp;

  for(int i = 0; i < N; i++){

    ll num = A[i];

    map<ll, ll> mp1;

    for(ll j = 2; j * j <= num; j++){
      while(num % j == 0){
        mp1[j]++;
        num = num / j;
      }
    }
    if(num != 1LL){
      mp1[num]++;
    }

    for(auto itr = mp1.begin(); itr != mp1.end(); itr++){
      mp[itr->first] = max(itr->second, mp[itr->first]);
    }

  }

  ll mult_A = 1LL;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    ll num = itr->first;
    ll cnt = itr->second;
    while(cnt){
      mult_A = (mult_A * num) % MOD;
      cnt--;
    }
  }

  ll ans = 0;
  for(int i = 0; i < N; i++){
    ans = (ans + (mult_A * modinv(A[i], MOD)) % MOD) % MOD;
  }
  
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 1024
n=int(input())
wl=[input() for i in range(n)]
f=0
if len(wl)==len(set(wl)):
  for i in range(n):
    if i==0:
      pass
    else:
      if wl[i][0]==wl[i-1][-1]:
        pass
      else:
        f=1
else:
  f=1
print("Yes" if f==0 else "No")

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <list>
#include <bitset>
#include <fstream>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(LL i = (a); i < (LL)(n); ++i)
#define REM(i,a,n) for(LL i = (LL(n) - 1); i >= (a); --i)
#define EPS 1e-11
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT fixed << setprecision(16)
const double PI = 3.1415926535897932;

template <class T, class U>
istream& operator >> (istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
//sum, 累積和
// 負のときの割り算に注意
#if 1
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<class T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Suffix_Array.h"
#include "Matrix.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator >> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b == 15) {
		cout << '+' << endl;
	} else if (a * b == 15) {
		cout << '*' << endl;
	} else {
		cout << 'x' << endl;
	}
	return 0;
}


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

int main(){
	int n;cin>>n;
	int a[n];
	int s=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		s+=a[i];
	}
	int ans=0;
	for(int i=0;i<n;i++){
		s-=a[i];
		ans+=a[i]*(s);
	}
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

using pll = pair<ll, ll>;

int main() {
	ll N, X, D;
	cin >> N >> X >> D;
	if (D < 0) X = -X, D = -D;
	
	if (D == 0) {
		if (X == 0) cout << 1 << endl;
		else cout << N + 1 << endl;
		return 0;
	}
	
	map<int, set<pll> > mass;
	for (ll i = 0; i <= N; ++i) {
		ll mn = i * (i - 1) / 2 * D;
		ll mx = (2 * N - i - 1) * i / 2 * D;
		mass[(i * X % D + D) % D].insert(pll(mn + i * X, mx + i * X));
	}
	
	ll ans = 0;
	
	for (auto &cur : mass) {
		set<pll> &ss = cur.se;
		auto it = ss.begin();
		while (it != ss.end()) {
			ll l = it->fi, r = it->se;
			++it;
			while (it != ss.end() && it->fi <= r) {
				chmax(r, it->se);
				++it;
			}
			ans += (r - l) / D + 1;
		}

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


Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(x, it) for(auto it = x.begin(); it != x.end(); it++)
#define pr(x) cout << #x << " = " << x << endl
#define fill(x,y) memset(x,y,sizeof(x))
#define endl "\n"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector< pii > vpii;
typedef vector< pll > vpll;
ld eps = 1e-7;
ll mod = 1000000007;
ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

void solve()
{
	int n, i, x, y;
	cin >> x >> n;
	vi a(n);
	rep(i, 0, n)
		cin >> a[i];
	y = x;
	while(1)
	{
		// pr(x);
		// pr(y);
		if(!count(all(a), x))
		{
			cout << x << endl;
			return;
		}
		if(!count(all(a), y))
		{
			cout << y << endl;
			return;
		}
		x--;
		y++;
	}
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	//cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int sum = 0;
    unordered_map<int, long> counter;
    counter[0]++;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        sum = (sum + a % m) % m;
        counter[sum]++;
    }
    long ans = 0;
    for (auto&& e : counter) {
        ans += e.second * (e.second - 1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  99999999999;

long long  d[110][110],V,E;

int main(){
  cin>>V>>E;
  REP(i,V+1)REP(j,V+1)d[i][j]=INF;
  REP(i,V)d[i][i]=0;
  REP(i,E){
    int s,t,cost;
    cin>>s>>t>>cost;
    d[s][t]=cost;
  }
  REP(k,V){
    REP(i,V){
      REP(j,V){
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  bool cycle=false;
  REP(i,V)if(d[i][i]<0)cycle=true;
  if(cycle)cout<<"NEGATIVE CYCLE"<<endl;
  else {
    REP(i,V){
      if(d[i][0] >INF/2)cout<<"INF";
      else cout<<d[i][0];
      FOR(j,1,V){
        if(d[i][j]>INF/2)cout<<" "<<"INF";
        else cout<<" "<<d[i][j];
      }
      cout<<endl;
    }
  }
}



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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint>PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};

int N;
int a[100010];

signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>N;
    1200>N?puts("ABC"):puts("ARC");
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    t_list = list(map(int, input().split()))
    m = int(input())
    total_time = sum(t_list)

    for _ in range(m):
        p, x = map(int, input().split())
        diff = t_list[p - 1] - x
        print(total_time - diff)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define REP(i, n) for(int i=1; i<=n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;

int main(){
    int a, b, c; cin >> a >> b >> c;
    int k; cin >> k;
    int ans = 0;
    while(a >= b){
        ans++;
        b *= 2;
    }
    while(b >= c){
        ans++;
        c *= 2;
    }
    if(ans <= k) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
// 問題の URL を書いておく
// 

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <numeric>
using namespace std;

//#define ENABLE_PRINT

template<typename T>
T Input()
{
    T v;
    cin >> v;
    return v;
}

template<typename T>
vector<T> InputVector(int n)
{
    vector<T> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    return v;
}

template<typename T>
void InputArray(T* begin, int n)
{
    for(int i = 0; i < n; ++i)
    {
        cin >> begin[i];
    }
}

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

int main(int, const char**)
{
    int64_t a, v;
    cin >> a >> v;
    int64_t b, w;
    cin >> b >> w;
    int64_t t;
    cin >> t;
    
    if(w >= v)
    {
        cout << "NO" << endl;
        return 0;
    }

    auto tt = static_cast<double>(abs(a - b)) / (v - w);
    if(tt <= t)
    {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}


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

using namespace std;

#define N 100002
char s[N], t[N];

int n,m,a[N],b[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> (s+1) >> (t+1);

    n = strlen(s+1);
    m = strlen(t+1);
    for (int i=1; i<=n; i++)
        a[i] = a[i-1] + (s[i] == 'A');
    for (int i=1; i<=m; i++)
        b[i] = b[i-1] + (t[i] == 'A');
    int q; cin >> q;
    while(q--)
    {
        int x,u,y,v; cin >> x >> y >> u >> v;
        int sa = a[y] - a[x-1]; int sb = y-x+1-sa;
        int ta = b[v] - b[u-1]; int tb = v-u+1-ta;
        if (((sa + sb * 2) - (ta + tb*2) % 3 == 0) || ((sa*2 + sb - ta*2 - tb) % 3 == 0)) cout << "YES"; else cout << "NO";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define test int t;cin>>t; while(t--)
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
#define getarr(arr,n) int arr[n];rep(i,0,n)cin>>a[i]
#define getvec(vec,n) vi vec;int x;rep(i,0,n){cin>>x;vec.pb(x);}
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
vi b_v;void bin(unsigned int n) { if (n > 1) bin(n>>1); b_v.pb(n & 1); }
int isPowerof2(int x) { return (x && !(x & x-1)); }

int dp[3000+1][3000+1];

int32_t main(){
    boost;osit;
    string s1,s2;
    cin>>s1>>s2;
    int n1=s1.size();
    int n2=s2.size();
    s1='!'+s1;s2='!'+s2;
    rep(i,1,n1+1){
        rep(j,1,n2+1){
            if(s1[i]==s2[j]){
                dp[i][j]=dp[i-1][j-1]+1;
            }else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    string ans="";
    while(1){
        if(n1==0 || n2==0)break;
        if(dp[n1][n2]==dp[n1-1][n2]){
            n1--;
        }else if(dp[n1][n2]==dp[n1][n2-1]){
            n2--;
        }else{
            ans+=s1[n1];
            n1--;n2--;
        }
    }
    reverse(all(ans));
    cout<<ans;
    return 0;
}

Measured memory_bytes: 70656