akhauriyash/Code-Regression huggingface dataset:
s = input()
q = int(input())

tcount = 0
rlist = ""
llist = ""

for i in range(q):
    qret = input()
    if qret[0] == "1":
        tcount += 1
        # ans = ans[::-1]
    else:
        f = qret[2]
        c = qret[4]
        if f == "1":
            if tcount % 2 == 0:
                llist = c + llist
            else:
                rlist += c
        else:
            if tcount % 2 == 0:
                rlist += c
            else:
                llist = c + llist

if tcount % 2 == 0:
    print(llist + s + rlist)
else:
    print(rlist[::-1] + s[::-1] + llist[::-1])

Measured memory_bytes: 4440
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n, k, r, s, p;cin>>n>>k>>r>>s>>p;
  string t;cin>>t;
  int ans=0;
  rep(i, k){
    char pre='x';
    for(int j=i;j<n;j+=k){
      if(t[j]==pre){
        pre='x';
      }else{
        if(t[j]=='r')ans+=p;
        else if(t[j]=='s')ans+=r;
        else if(t[j]=='p')ans+=s;
        pre=t[j];
      }
    }
  }
  cout<<ans<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const ll INF = 1e9+5;
ll h,w;
vector< vector<ll> > mat(82,vector<ll>(82));
ll dp[82][82][13800];

ll hp(ll i,ll j,ll s){
	if(i==h && j==w){
		return s;
	}
	if(dp[i][j][s]!=-1){
		return dp[i][j][s];
	}
	ll a = INF,b = INF,c = INF,d = INF;
	if(i<h){
		a = hp(i+1,j,abs(s-mat[i+1][j]));
		b = hp(i+1,j,abs(s+mat[i+1][j]));
	}
	if(j<w){
		c = hp(i,j+1,abs(s-mat[i][j+1]));
		d = hp(i,j+1,abs(s+mat[i][j+1]));
	}
	dp[i][j][s] = min(min(a,b),min(c,d));
	return min(min(a,b),min(c,d));
	
}

int main(){
	fastio;
	
	cin>>h>>w;
	vector< vector<ll> > a(h,vector<ll>(w)),b(h,vector<ll>(w));
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			cin>>a[i][j];
		}
	}
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			cin>>b[i][j];
		}
	}
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			mat[i+1][j+1] = abs(a[i][j]-b[i][j]);
		}
	}
	memset(dp,-1,sizeof(dp));
	ll p = hp(1,1,mat[1][1]);
	cout<<p<<"\n";
}

Measured memory_bytes: 725376
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printde(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    int h, w;
    cin >> h >> w;
    int n; cin >> n;
    vector<vector<int>> ans(h, vector<int> (w));
    int color = 1, y = 0, x = 0;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        for(int j = 0; j < a; j++){
            ans[y][x++] = color;
            if(x == w){
                y++;
                x = 0;
            }
        }
        color++;
    }
    for(int i = 0; i < h; i++){
        if(i & 1){
            reverse(ans[i].begin(), ans[i].end());
        }
        for(int j = 0; j < w; j++){
            cout << ans[i][j] << ' ';
        }
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))

adic=dict()

for ai in a:
    if ai in adic:
        adic[ai]+=1
    else:
        adic[ai]=1
        
q=int(input())
b=[0]*(q)
c=[0]*(q)
bc=[[0]*2 for i in range(q)]
for i in range(q):
    bc[i]=map(int,input().split())
    
asum=0
for i,ad in adic.items():
    asum+=i*ad
    
#print(adic)    
for bi,ci in bc:
    if bi in adic and ci in adic:
        asum-=bi*adic[bi]
        adic[ci]=adic[ci]+adic[bi]
        asum+=ci*adic[bi]
        del adic[bi]
    elif bi in adic and (not ci in adic):
        asum-=bi*adic[bi]
        adic[ci]=adic[bi]
        asum+=ci*adic[bi]
        del adic[bi]
#    print(i,adic)
    print(asum)

Measured memory_bytes: 62716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define endl '\n'
#define mod 1000000007
#define modd 998244353
#define PI 3.1415926535897932384626
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

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

int main() {
	io();
	
	vector<int> x(5);
	int ans=0;
	for(int i=0;i<5;i++) {
		cin>>x[i];
		if(x[i]==0) ans=i+1;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 14:36:38 2020

@author: shinba
"""

w,a,b = map(int,input().split())

if b + w < a:
    print(a-b-w)
elif a <= b+w <= a+w or a <= b <= a+w:
    print(0)
else:
    print(b-a-w)


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

int main(){
	while(true){
		vector<unsigned int> taro,hana;
		unsigned int n,m,tarosum=0,hanasum=0,tarocur,hanacur,cursum=-1;
		cin>>n>>m;
		if(n==0)break;
		taro.resize(n);
		hana.resize(m);
		for(unsigned int i=0;i<n;i++){
			unsigned int tmp;
			cin>>tmp;
			taro[i]=tmp;
			tarosum+=tmp;
		}
		for(unsigned int i=0;i<m;i++){
			unsigned int tmp;
			cin>>tmp;
			hana[i]=tmp;
			hanasum+=tmp;
		}
		for(unsigned int i=0;i<n;i++){
			for(unsigned int j=0;j<m;j++){
				if(tarosum-taro[i]+hana[j]==hanasum+taro[i]-hana[j]){
					if(taro[i]+hana[j]<cursum){
						cursum=taro[i]+hana[j];
						tarocur=taro[i];
						hanacur=hana[j];
					}
				}
			}
		}
		if(cursum==-1){
			cout<<-1<<endl;
		}else{
			cout<<tarocur<<' '<<hanacur<<endl;
		}
	}
	return 0;
}

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

using namespace std;

const int MOD = 10007;

int joi(char c)
{
	if(c=='J') return 1;
	if(c=='O') return 2;
	return 4;
}

int main()
{
	int dp[8][1000]={};
	int n;
	string s;
	cin >> n;
	cin >> s;
	for(int i=0;i<8;i++)
		if((joi(s[0])&i)&&(1&i)) dp[i][0]=1;
	for(int i=1;i<n;i++)
		for(int j=0;j<8;j++)
		{
			for(int k=0;k<8;k++)
			{
				if((joi(s[i])&j)&&(j&k))
				{
					dp[j][i]=(dp[j][i]+dp[k][i-1])%MOD;
				}
			}
		}
	int res=0;
	for(int i=0;i<8;i++)
		res = (res+dp[i][n-1])%MOD;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1244
#include<stdio.h>
#define ll long long
#define mod 1000000007
int sumx[400010],sumy[400010],lazx[400010],lazy[400010],*laz,*sum,n;
ll a[100010];
void pushdown(int x){
    if(laz[x]){
        laz[x<<1]=laz[x<<1|1]=1;
        sum[x<<1]=sum[x<<1|1]=0;
        laz[x]=0;
    }
}
int query(int L,int R,int l,int r,int x){
    if(L<=l&&r<=R)return sum[x];
    pushdown(x);
    int mid=(l+r)>>1,ans=0;
    if(L<=mid)ans=(ans+query(L,R,l,mid,x<<1))%mod;
    if(mid<R)ans=(ans+query(L,R,mid+1,r,x<<1|1))%mod;
    return ans;
}
void modify(int pos,int v,int l,int r,int x){
    if(l==r){
        sum[x]=(sum[x]+v)%mod;
        return;
    }
    pushdown(x);
    int mid=(l+r)>>1;
    if(pos<=mid)
        modify(pos,v,l,mid,x<<1);
    else
        modify(pos,v,mid+1,r,x<<1|1);
    sum[x]=(sum[x<<1]+sum[x<<1|1])%mod;
}
int queryx(int L,int R){
    laz=lazx;
    sum=sumx;
    return query(L,R,0,n-1,1);
}
void modifyx(int pos,int v){
    laz=lazx;
    sum=sumx;
    modify(pos,v,0,n-1,1);
}
int queryy(int L,int R){
    laz=lazy;
    sum=sumy;
    return query(L,R,0,n-1,1);
}
void modifyy(int pos,int v){
    laz=lazy;
    sum=sumy;
    modify(pos,v,0,n-1,1);
}
int main(){
    int i,l,r,mid,x,t1,t2;
    ll A,B;
    scanf("%d%lld%lld",&n,&A,&B);
    for(i=1;i<=n;i++)scanf("%lld",a+i);
    a[0]=-4223372036854775807ll;
    modifyx(0,1);
    modifyy(0,1);
    for(i=1;i<n;i++){
        l=0;
        r=i-1;
        while(l<=r){
            mid=(l+r)>>1;
            if(a[i+1]-a[mid]>=B){
                x=mid;
                l=mid+1;
            }else
                r=mid-1;
        }
        t1=queryx(0,x);
        l=0;
        r=i-1;
        while(l<=r){
            mid=(l+r)>>1;
            if(a[i+1]-a[mid]>=A){
                x=mid;
                l=mid+1;
            }else
                r=mid-1;
        }
        t2=queryy(0,x);
        if(a[i+1]-a[i]<A){
            sumx[1]=0;
            lazx[1]=1;
        }
        if(a[i+1]-a[i]<B){
            sumy[1]=0;
            lazy[1]=1;
        }
        modifyy(i,t1);
        modifyx(i,t2);
    }
    printf("%d",(queryx(0,n-1)+queryy(0,n-1))%mod);
}

Measured memory_bytes: 6400
import java.io.*
import java.util.*


fun solve(N: Int, A: LongArray){
    A.sort()
    val mA = A.filter{ it < 0L }
    val pA = A.filter{ it >= 0L }
    if (mA.size == 0){println(A.sum()); return}
    if (mA.size % 2 == 0){
        println(A.sum() - 2*mA.sum())
        return
    }
    if (pA.size == 0){
        println(2L*mA.last() - mA.sum())
        return
    }
    if(mA.last() + pA.first() < 0L ){
        println(A.sum() - 2L*mA.sum() - 2L*pA.first())
        return
    }else{
        println(A.sum() - 2L*mA.sum() + 2L*mA.last())
        return
    }
}

// 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)
fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val A = LongArray(N)
    for(i in 0 until N){
        A[i] = sc.next().toLong()
    }
    solve(N, A)
}




Measured memory_bytes: 48348
//SILENT KILLER
              //HARD WORK BEATS TALENT WHEN TALENT DOESNOT WORK HARD
#include<bits/stdc++.h>
//typedef long long ll;

using namespace std;
int main()
  {
    int n, l;
   cin >> n >> l;
   vector<string> s(n);
   for (int i=0; i<n; i++) cin >> s.at(i);

   sort(s.begin(), s.end());

   for (int i=0 ; i<n; i++) cout << s.at(i);
   cout << endl;
  }














Measured memory_bytes: 3644
#include <stdio.h>
#include <string.h>
int main(void) {
  char s[10];
  scanf("%s", s);
  if (strcmp(s, "Sunny") == 0)
    puts("Cloudy");
  else if (strcmp(s, "Cloudy") == 0)
    puts("Rainy");
  else if (strcmp(s, "Rainy") == 0)
    puts("Sunny");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
	auto a = vector<int>(5);
	int k;
	for(auto& b : a){
		cin >> b;
	}
	cin >> k;
	bool ans = true;
	for(auto i = 0; i < 5; ++i){
		for(auto j = i + 1; j < 5; ++j){
			if(abs(a[i] - a[j]) > k){
				ans = false;
				break;
			}
		}
		if(!ans) break;
	}
	cout << (ans ? "Yay!" : ":(") << endl;
	return 0;
}

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

using namespace std;

int64_t Cost(const vector<int64_t> &vec, int64_t point)
{
    int64_t cost = 0;
    for (const auto &num : vec) {
        cost += abs(num - point);
    }
    return cost;
}

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

    vector<int64_t> vec(n);
    for (int i = 0; i < n; i += 1) {
        cin >> vec[i];
        vec[i] -= (i + 1);
    }
    sort(vec.begin(), vec.end());

    int64_t res = Cost(vec, vec[n / 2]);
    if (n % 2 == 0) {
        res = min(res, Cost(vec, vec[n / 2 - 1]));
    }

    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#define N 500000

int parent(int );
int left(int );
int right(int );
void buildMaxHeap(int *);
void maxHeapify(int *,int );

int n;

main(){
  int i,k[N];
  
  scanf("%d",&n);
  
  for(i=1; i<=n; i++)
    scanf("%d",k+i);
 

    buildMaxHeap(k);
  
 
    for(i=1; i<=n; i++)
      printf(" %d",k[i]); 

  printf("\n");


  return 0;
}

  
  
int parent(int i){
  return floor(i/2);
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}


void buildMaxHeap(int *k){
  int i;
  for(i=parent(n); i>0; i--)
    maxHeapify(k,i);
}


void maxHeapify(int *k, int i){

  int l,r,largest,tmp;

  l=left(i);
  r=right(i);

  if(l<=n && k[l]>k[i])
    largest=l;

  else
    largest=i;

  if(r<=n && k[r]>k[largest])
    largest=r;
 
  if(largest!=i){
    tmp=k[i];
    k[i]=k[largest];
    k[largest]=tmp;

    maxHeapify(k,largest);
  }
}

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

int main() {
  int64_t N,M;
  cin >> N >> M;
  if(N-M>1 || M-N >1){
    cout << 0 << endl;
    return 0;
  }
  
  int64_t waru=1000000000+7;
  int64_t ans=1;
  if(N==M){
    for(int i=1; i<=N; i++){
      ans *= i;
      ans %= waru;
    }
    ans = ans*ans*2%waru;
    cout << ans << endl;
  }
  else{
    for(int i=1; i<=N; i++){
      ans *= i;
      ans %= waru;
    }
    for(int i=1; i<=M; i++){
      ans *= i;
      ans %= waru;
    }
    cout << ans << endl;
  }
    
}

// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));

  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
    //}
  //}

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

#define mem( arr, i ) fill( arr, arr + sizeof (arr), i )
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
const lli I_MAX = 1LL << 60;
const lli mod = 1000000007;


void solve() {
	lli n, m, q, k;
	cin >> n;
	
	m = n/100;
	
	if ( n <= m*111 ) cout << m*111 << '\n';
	else cout << (m+1)*111 << '\n';
}

int main() {
	int t = 1;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
//#include<bits/stdc++.h>
#include<cmath>
#include<string>
#include<cstdio>
#include<cstring>
#include<queue>
#define pq priority_queue
#define Pi acos(-1.0)
using namespace std;
#define MOD 1000000007
int dp[405][405];
int main()
{
    int n,ma,mb,ans=6666666,xa,xb,xc;
    cin>>n>>ma>>mb;
    for(int i=0;i<=400;i++)
        for(int j=0;j<=400;j++)
            dp[i][j]=ans;
    dp[0][0]=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d%d",&xa,&xb,&xc);
        for(int x=400;x>=xa;x--)
            for(int y=400;y>=xb;y--)
                dp[x][y]=min(dp[x][y],dp[x-xa][y-xb]+xc);
    }
    for(int i=1;i<=400;i++)
    {
        if(i%ma==0 && i/ma*mb<=400)
            ans=min(ans,dp[i][i/ma*mb]);
    }
    if(ans==6666666)
        printf("-1\n");
    else
        printf("%d",ans);
    return 0;
}


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

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

  vector<int> X(M);
  rep(i, M) cin >> X[i];

  sort(X.begin(), X.end());

  vector<int> d(M);
  rep(i, M - 1) d[i + 1] = abs(X[i + 1] - X[i]);

  sort(d.rbegin(), d.rend());
  rep(i, min(M, N - 1)) d[i] = 0;

  int ans = 0;
  rep(i, M) ans += d[i];
  cout << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<pair<int,int>> W(N,pair<int,int>(0,0));
  for(int i=0;i<N;i++){
    cin >> W.at(i).second >> W.at(i).first;
  }
  sort(W.begin(),W.end());
  ll T=0;
  for(int i=0;i<N;i++){//Can work[i] be finished by its dead end?
    T = T + W.at(i).second;
    if(T>W.at(i).first){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1792
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [W, H, x, y] = string_to_int(inputs[0])
    max = (W * H) / 2
    is_multi = 0
    if x == W / 2 and y == H / 2:
        is_multi = 1

    return "%.6f %d" % (max, is_multi)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3064
import sys
import heapq
push = heapq.heappush
pop = heapq.heappop
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
 
H,W = map(int,readline().split())
sh,sw = map(int,readline().split())
gh,gw = map(int,readline().split())
sh,sw = sh-1,sw-1
gh,gw = gh-1,gw-1
maze = []
for _ in range(H):
    maze.append(readline().rstrip().decode())
visited = [[10**6]*W for _ in range(H)] #必要な最小ワープ回数
hp = []
push(hp,(0,sh,sw))
visited[sh][sw] = 0
while hp:
    rp,h,w = pop(hp)
    if visited[h][w] < rp:
        continue
    if h == gh and w == gw:
        print(rp)
        exit()
    for i in range(5):
        for j in range(5):
            if i == 2 and j == 2:
                continue
            if 0 <= h+i-2 < H and 0 <= w+j-2 < W:
                if maze[h+i-2][w+j-2] == ".":
                    if abs(i-2)+abs(j-2) <= 1:
                            if visited[h+i-2][w+j-2] > rp:
                                push(hp,(rp,h+i-2,w+j-2))
                                visited[h+i-2][w+j-2] = rp
                    else:
                        if visited[h+i-2][w+j-2] > rp+1:
                            push(hp,(rp+1,h+i-2,w+j-2))
                            visited[h+i-2][w+j-2] = rp+1
print(-1)


Measured memory_bytes: 121124
n, m = map(int, input().split())

if n > 1 and m > 1:
    ans = (n - 2) * (m - 2)
elif n > 1 and m == 1:
    ans = n - 2
elif n == 1 and m > 1:
    ans = m - 2
else:
    ans = 1
print(ans)

Measured memory_bytes: 3060
import fractions
def kansu(x, c, d):
  c_baisu = x//c
  d_baisu = x//d
  l = (c * d) // fractions.gcd(c, d)
  juhuku = x//l
  return x - c_baisu - d_baisu + juhuku
  
a, b, c, d = (int(i) for i in input().split())
print(kansu(b,c,d)-kansu(a-1,c,d))

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


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define pb push_back
#define mp make_pair
#define bitcount __builtin_popcount
#define ispresent(c, x) ((c).find(x) != (c).end())
#define watch(x) cout<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printV(vector<T>& a, int n) { rep(i, 0, n) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}


// constants
const long double eps = 1e-9;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;

string s, t;
string lcs;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    s+='.', t+='.';
    string stmp, ttmp;
    cin>>stmp>>ttmp;
    s+=stmp;
    t+=ttmp;
	int n1=s.size()-1;
	int n2=t.size()-1;
	vector<vector<int>> dp(n1+1, vector<int>(n2+1));
	vector<vector<pair<int, int>>> nx(n1+1, vector<pair<int, int>>(n2+1));
	
	for(int i=1; i<=n1; i++) {
		for(int j=1; j<=n2; j++) {
			
			if(s[i]==t[j]) {
				dp[i][j]=1+dp[i-1][j-1];
				nx[i][j]={i-1, j-1};
			}
			else {
				if(dp[i-1][j]>dp[i][j-1]) {
					dp[i][j]=dp[i-1][j];
					nx[i][j]={i-1, j};
				}
				else {
					dp[i][j]=dp[i][j-1];
					nx[i][j]={i, j-1};
				}
			}
		}
	}
	function<void(int, int)> printlcs = [&](int x, int y)
	{
		if(x<=0 or y<=0) return;
		if(s[x]==t[y] and nx[x][y]==make_pair(x-1, y-1)) {
			lcs+=s[x];
		}
		int newx=nx[x][y].first;
		int newy=nx[x][y].second;
		printlcs(newx, newy);
	};
	printlcs(n1, n2);
	//~ for(int i=0; i<sz(nx); i++) {
		//~ for(int j=0; j<sz(nx[i]); j++) {
			//~ cout<<nx[i][j].first<<" "<<nx[i][j].second<<"\n";
		//~ }
	//~ }
	reverse(all(lcs));
	cout<<lcs<<"\n";
    return 0;
}



Measured memory_bytes: 106240
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

int main()
{
	int h,w,n;
	cin >> h>> w >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];

	int itr = 0;

	rep(i,h)
	{
		vector<int> out (w);
		if(i%2)
		{
			for(int j = w-1;j>=0;j--)
			{
				out[j]= itr+1;
				a[itr]--;
				if(a[itr]==0)itr++;

			}
		}
		else
		{
			for(int j = 0; j<w;j++)
			{
				out[j]= itr+1;
				a[itr]--;
				if(a[itr]==0)itr++;
			}
			
		}
		rep(jj,w)cout<<out[jj]<<" ";cout<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64

// n:10^4
int n;
vector<int> state[10101];
vector<int> in(10101, 0);
vector<int> c;
vector<int> ans;

void dfs(int s){
  vector<bool> visited(n, false);
  stack<int> st;
  st.push(s);
  int i = 0;

  while(!st.empty()){
    int fr=st.top(); st.pop();
    visited[fr] = true;
    ans[fr] = c[i++];
    for(int i=0;i<state[fr].size();++i){
      if (visited[state[fr][i]]) continue;
      st.push(state[fr][i]);
    }
  }
}

signed main() {
  cin>>n;
  for(int i=0;i<n-1;++i){
    int a,b;cin>>a>>b;--a;--b;
    state[a].emplace_back(b);
    state[b].emplace_back(a);
    ++in[a]; ++in[b];
  }

  c.resize(n);
  for(int i=0;i<n;++i) cin>>c[i];
  sort(c.begin(), c.end(), greater<int>());
  
  int root = 0;
  for(int i=0;i<n;++i){
    if(in[root] > in[i]){
      root = i;
    }
  }

  ans.resize(n);
  dfs(root);
  int m = accumulate(c.begin()+1, c.end(), 0);
  cout<<m<<endl;
  for(int i=0;i<n;++i){
    if (i>0) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}


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

int main() {
    string s;
    char t;
    cin >> t;
    int n = t-'a';
    //int m = 'z'-'a';
    int l = n+1;
    char o = l+'a';
    cout << o << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = gets.split.map &:to_i
P = gets.split.map &:to_i
XY =
  (1..M).map do
    x, y = gets.split.map &:to_i
  end

class UnionFind
  attr :parent
  def initialize(n)
    @parent = (0...n).to_a
  end

  def union(i, j)
    i = root(i)
    j = root(j)

    return if i==j
    if rand(2)==0
      @parent[j] = i
    else
      @parent[i] = j
    end
  end

  def find(i, j)
    root(i)==root(j)
  end

  def root(i)
    if @parent[i]==i
      i
    else
      @parent[i] = root(@parent[i])
    end
  end

  def group_by_roots
    (0...@parent.size).group_by {|i|
      root(i)
    }
  end
end

uf = UnionFind.new(N)
XY.each do |x, y|
  uf.union(x-1, y-1)
end

require 'set'
puts uf.group_by_roots.map {|root, group|
  ps = group.map {|i| P[i]-1 }
  (Set.new(group) & Set.new(ps)).size
}.inject(&:+)


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

//#define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond) if(cond) break; else

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

const int INF = 1 << 29;

signed main() {
	int n;
	while (cin >> n && n) {
		int t, l, b; cin >> t >> l >> b;
		vector<int> stage(n + 1);
		rep(i, l) {
			int lose; cin >> lose;
			stage[lose] = 1;
		}
		rep(i, b) {
			int back; cin >> back;
			stage[back] = 2;
		}
		vector<vector<double>> dp(t + 1, vector<double>(n + 1));
		dp[0][0] = 1;
		rep(i, t) rep(j, n) rep(d, 6) {
			int next = j + d + 1;
			if (next > n) next = n - (next % n);
			double val = dp[i][j] * (1. / 6.);
			if (stage[next] == 1 && i + 2 <= t) {
				dp[i + 2][next] += val;
			} else if (stage[next] == 2) {
				dp[i + 1][0] += val;
			} else {
				dp[i + 1][next] += val;
			}
		}
		double ans = 0;
		rep(i, t + 1) ans += dp[i][n];
		printf("%.8f\n", ans);
	}
}

Measured memory_bytes: 3116
N = int(input())
A = []
for _ in range(2):
    s = list(map(int, input().split()))
    A.append(s)


#0で降りるか、1で降りるか、2で降りるか....どこで降りたとしてもそれまでは全習得

ans = []

count = 0
for i in range(N):
    baselis = A[0]
    groundlis = A[1]
    count = 0
    count = count + sum(baselis[0:i+1]) + sum(groundlis[i:N+1])
    ans.append(count)

print(max(ans))    

Measured memory_bytes: 3064
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	string s;
	cin >> s;
	int cnt = 0;
	for (auto i : s) {
		if (i == '(')cnt++;
		else if (i == ')')cnt--;
		else N += cnt;
	}
	cout << N << endl;
}


Measured memory_bytes: 3216
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;

long long n, m;
vector<int> x, y;

class Data {
public:
	int ball = 1;
	bool red = false;
	Data(bool a) {
		red = a;
	}
};

vector<Data> dt;

int main() {
	cin >> n >> m;
	dt.emplace_back(true);
	for (int i = 1; i < n; i++)
		dt.emplace_back(false);
	x.resize(m);
	y.resize(m);
	for (int i = 0; i < m; i++) {
		cin >> x[i] >> y[i];
	}

	for (int i = 0; i < m; i++) {
		dt[x[i] - 1].ball--;
		dt[y[i] - 1].ball++;
		if (dt[x[i] - 1].red)
			dt[y[i] - 1].red = true;
		if (dt[x[i] - 1].ball == 0)
			dt[x[i] - 1].red = false;
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (dt[i].red)
			ans++;
	}
	cout << ans << endl;
	//cin >> n;
	return 0;
}

Measured memory_bytes: 1780
n, k = map(int, input().split())
h = list(map(int, input().split()))

h = sorted(h)
sum_of_k = 0
if k >= n:
    print(0)
    exit()
for i in range(k):
    sum_of_k += h[len(h)-i-1]
ans = sum(h)-sum_of_k
print(ans if ans >=0 else 0)


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

using namespace std;

typedef unsigned long long ull;

ull gcd(ull x, ull y);
ull lcm(ull x, ull y);

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ull a, b, c, d;
	cin >> a >> b >> c >> d;
	a-=1;
	ull ca = a - a/c - a/d + a/(lcm(c,d));
	ull cb = b - b/c - b/d + b/(lcm(c,d));
	cout <<  cb - ca;
	return 0;
}

ull gcd(ull x, ull y){
	while (x){
		y%=x;
		swap(x,y);
	}
	return y;
}

ull lcm(ull x, ull y){
	return x*y / gcd(x,y);
}

	

Measured memory_bytes: 256
n = int(input())
i,j = [int(e) for e in input().split()]
#print(n,i,j)

a = i // n
b = j // n
ans = 'NG'
if a < b:
  ans = 'OK'
else:
  if i % n == 0:
    ans = 'OK'

print(ans)


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, m, q;
string s[2000];

int c[2001][2001];
int v[2001][2001];
int h[2001][2001];

int main() {
	cin >> n >> m >> q;
	inc(i, n) { cin >> s[i]; }
	
	inc1(i, n) {
	inc1(j, m) {
		c[i][j] = s[i - 1][j - 1] - '0';
		v[i][j] = (j < 2 ? 0 : s[i - 1][j - 1] == '1' && s[i - 1][j - 2] == '1');
		h[i][j] = (i < 2 ? 0 : s[i - 1][j - 1] == '1' && s[i - 2][j - 1] == '1');
	}
	}
	inc1(i, n) {
	inc1(j, m) {
		c[i][j] += c[i - 1][j];
		v[i][j] += v[i - 1][j];
		h[i][j] += h[i - 1][j];
	}
	}
	inc1(i, n) {
	inc1(j, m) {
		c[i][j] += c[i][j - 1];
		v[i][j] += v[i][j - 1];
		h[i][j] += h[i][j - 1];
	}
	}
	
	inc(qq, q) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		x1--;
		y1--;
		
		#define R(a, x1, y1, x2, y2) (a[x2][y2] - a[x1][y2] - a[x2][y1] + a[x1][y1])
		int C = R(c, x1    , y1    , x2, y2);
		int V = R(v, x1    , y1 + 1, x2, y2);
		int H = R(h, x1 + 1, y1    , x2, y2);
		
		cout << (C - V - H) << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 52864
#include <stdio.h>
#include <vector>
using namespace std;
const int Cv=1<<18, C=210001;
typedef long long ll;

int n, a[C];
ll val[2*Cv], x, v, am;

void insert (int a, ll w){
	for(a+=Cv;a>0;a/=2)	val[a]=max(val[a], w);
}

ll query(int l){
	ll ww=0;
	for (l+=Cv;l>1;l/=2)		if (l%2==1)	ww=max(ww, val[l-1]);
	return ww;
}

int main(){
	int i;
	scanf ("%d", &n);
	for (i=0;i<n;i++)	scanf ("%d", &a[i]);
	for (i=0;i<n;i++){
		scanf ("%lld", &v);
		x=query(a[i]);
		if (x+v>am)	am=x+v;
		insert(a[i], x+v);
	}
	printf ("%lld\n", am);
	
return 0;}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    set<int> st;
    int N, K; cin >> N >> K;
    int A[N]; rep(i, N) cin >> A[i];
    int g = 0;
    rep(i, N) g = __gcd(g, A[i]);
    sort(A, A+N);
    bool res = false;
    //if K + n*g \in st -> true
    rep(i, N){
        int val = A[i]-K;
        if(val >= 0 && val%g == 0) res = true;
    }
    if(res) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 4000
(defun solve (s &optional flag ans)
  (cond
    ((null s) (concatenate 'string (reverse ans)))
    ((null flag) (solve (rest s) t (cons (first s) ans)))
    (t           (solve (rest s) nil ans))))

(let ((s (concatenate 'list (read-line))))
     (princ (solve s)))

Measured memory_bytes: 28996
import javax.xml.crypto.Data;
import java.util.*;
import java.io.*;

public class Main {
    public static int n;
    public static int MAX = 500000;
    public static long a[] = new long[MAX + 1];

    public static void main(String[] args) throws IOException {

        //??\???
        /*
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        */
        Scanner sc = new Scanner(System.in);
        PriorityQueue<Long> PQ = new PriorityQueue<Long>(Collections.reverseOrder());

        while (true) {
            String S = sc.next();
            if(S.equals("insert")) {
                long m = sc.nextLong();
                PQ.add(m);
            }
            if(S.equals("extract")) {
                System.out.println(PQ.poll());
            }
            if(S.equals("end")) break;
        }

        //??????
    }

}

Measured memory_bytes: 599156
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e5 + 5;



int main()
{
    FAST
  int n;
  cin>>n;
  ll sum=0;
  for(ll i=1;i<=n;i++)
  {
      if((i%3==0 && i%5==0) || i%3==0 || i%5==0)
        continue;
      else
        sum+=i;
  }
  cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	int ans = 0;

	for (int i = 1; i <= a; i++) {
		for (int j = 1; j <=12; j++) {
			if (i == a)
				if(j > b) break;
			if (i == j) ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


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

// (target, length)
vector<pair<pair<int, int>, int>> G;
vector<int> G2[2505], G2R[2505];
ll dist[2505];
bool cr[2505], v[2505], cr2[2505], v2[2505];

void dfs(int x) {
  if (v[x]) return;
  v[x] = true;
  cr[x] = true;
  for (auto p : G2R[x]) dfs(p);
}

void dfs2(int x) {
  if (v2[x]) return;
  v2[x]=true;
  cr2[x]=true;
  for (auto p:G2[x]) dfs2(p);
}

int main() {
  int n, m, p; cin >> n >> m >> p;
  for (int i = 0; i < m; i++) {
    int a, b, c; cin >> a >> b >> c;
    c = -(c - p);
    G.push_back({{a, b}, c});
    G2[a].push_back(b); G2R[b].push_back(a);
  }
  for (int i = 1; i <= n; i++)
    dist[i] = 0x3f3f3f3f3f3f3f3fll;
    dist[1] = 0;
  dfs(n);
  dfs2(1);
  for (int i = 0; i < n + 1; i++) {
    for (auto p : G) {
      if (dist[p.first.first] + p.second < dist[p.first.second]) {
        dist[p.first.second] = dist[p.first.first] + p.second;
      }
    }
  }
  for (auto p : G) {
    // cout << p.first.first << " " << p.first.second << " " << cr[p.first.first] << cr[p.first.second] << cr2[p.first.first] << cr2[p.first.second] << endl;
    if (dist[p.first.first] + p.second < dist[p.first.second] && 
      cr[p.first.second] && 
      cr[p.first.first] &&
      cr2[p.first.first] &&
      cr2[p.first.second]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << max(0ll, -dist[n]) << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mod 1000000007
#define vll vector<ll>
#define inf 1e9 +7
#define pll pair<ll,ll>
#define ff first 
#define ss second 
#define PI acos(-1)
#define endl '\n'
using namespace std;
int main()
{
    fastio; 
    ll T=1;
    //cin>>T; 
    ll ff=T;
    while(T--)
    {
    	ll n;
    	cin>>n;
    	string s;
    	map<string , ll> m;
    	for(ll i=0;i<n;i++)
    	{
    		cin>>s;
    		m[s]++;
		}
		cout<<"AC x "<<m["AC"]<<endl;
		cout<<"WA x "<<m["WA"]<<endl;
		cout<<"TLE x "<<m["TLE"]<<endl;
		cout<<"RE x "<<m["RE"]<<endl;
	}
}



Measured memory_bytes: 3632
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <chrono>
using namespace std;

const int typeNum = 26;

void solve(long long D, std::vector<long long> c, std::vector<std::vector<long long> > s){
    std::chrono::system_clock::time_point  start, end; // 型は auto で可
    start = std::chrono::system_clock::now(); // 計測開始時間
    end = std::chrono::system_clock::now(); 
    double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();

    // initial t
    vector<long long> t = vector<long long>(D);
    int i=0;
    for (auto &tt : t) {
      tt = i + 1;
      i = (i + 1) % typeNum;
    }

    long long pastSut = 0;
    long long iterator = 0;

    while (elapsed < 1960) {
    //  while (iterator < 10000) {
        // change id and value
        long long changedIndex = iterator % D;
        long long randomValue = iterator % typeNum + 1;
        long long pastValue = t[changedIndex];
        t[changedIndex] = randomValue;

        // current sutisfuction
        long long sut = 0;

        // make table
        vector<vector<long long> > table;
        for (int i=0;i<typeNum;++i) {
            table.push_back(vector<long long>(D));

            for (int j=0;j<D; ++j) {
                table[i][j] = -1;
            }
        }

        for (int i=0; i<D; ++i) {
            vector<long long> &target = table[t[i] - 1];
            for (int j=i; j<target.size() ;++j) {
                target[j] = i;
            }
        }

        for (int d = 0; d < D; ++d) {
            sut += s[d][t[d] - 1];

            // minus
            for (int i=0;i<typeNum;++i) {
                sut -= c[i] * (d - table[i][d]);
            }

            // todays sutisfuction
            //cout << sut << endl;
        }

        if (sut > pastSut) {
          // change
          pastSut = sut;
        }else{
          // cancel
          t[changedIndex] = pastValue;
        }

        iterator++;

        end = std::chrono::system_clock::now(); 
         elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
    }

    for (long long &tt : t) {
      cout << tt << endl;
    }

    // result sutisfuction
    //cout << pastSut << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long D;
    scanf("%lld",&D);
    std::vector<long long> c(26);
    for(int i = 0 ; i < 26 ; i++){
        scanf("%lld",&c[i]);
    }
    std::vector<std::vector<long long> > s(D, std::vector<long long>(26));
    for(int i = 0 ; i < D ; i++){
        for(int j = 0 ; j < 26 ; j++){
            scanf("%lld",&s[i][j]);
        }
    }
    solve(D, std::move(c), std::move(s));
    return 0;
}


Measured memory_bytes: 3472
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif*/
	int n;
	cin>>n;
	double ans=(n*n*n*1.0)/27;
	printf("%0.12lf",ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e9
typedef long long ll;
typedef pair<ll,ll> P;
unsigned long long popCount64bitB(unsigned long long x) 
{ 
    x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) 
      +  (x & 0x5555555555555555UL); 
    x = ((x & 0xccccccccccccccccUL) >> 2) 
      +  (x & 0x3333333333333333UL); 
    x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) 
      +  (x & 0x0f0f0f0f0f0f0f0fUL); 
    x = ((x & 0xff00ff00ff00ff00UL) >> 8) 
      +  (x & 0x00ff00ff00ff00ffUL); 
    x = ((x & 0xffff0000ffff0000UL) >> 16) 
      +  (x & 0x0000ffff0000ffffUL); 
    x = ((x & 0xffffffff00000000UL) >> 32) 
      +  (x & 0x00000000ffffffffUL); 
    return x; 
} 

int num[100010];
bool red[100010];
int x[100010],y[100010];

int main(void){
    ll n,m,ans=0;
    cin>>n>>m;
    for(int i=0;i<m;i++)cin>>x[i]>>y[i];
    for(int i=1;i<=n;i++){
        num[i]=1;
        red[i]=false;
    }
    red[1]=true;
    for(int i=0;i<m;i++){
        if(red[x[i]])red[y[i]]=true;
        num[x[i]]--;
        num[y[i]]++;
        if(num[x[i]]==0)red[x[i]]=false;
    }
    for(int i=1;i<=n;i++){
        if(red[i])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <algorithm>
#include <vector>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> x(N+1);
  for (size_t i=0; i<N; ++i)
    scanf("%d", &x[i]);

  int res=0;
  for (size_t i=0; i<N; ++i) {
    size_t j=i;
    while (x[i] == x[i+1]) ++i;
    res += (i-j+1)/2;
  }
  printf("%d\n", res);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
 ll gcd( ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}

int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
    ll n;
    cin>>n;
     ll a[n];
    for(int i=0;i<n;i++)
    {
      cin>>a[i];
    }
    ll ans=a[0];
    for(int i=1;i<n;i++)
    {
     // ans=(1ll*ans*a[i])///gcd(1ll*ans,1ll*a[i]);
      ll temp=gcd(1ll*ans,a[i]);
      ans=a[i]/temp*ans;
     //ans=ans/temp;
      //cout<<"Ans = "<<ans<<endl;
    }
   cout<<ans<<endl;
}
return 0;
}

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

bool isPrime(ll X) {
    FOR(i, 2, X) {
        if(X % i == 0) return false;
    }
    return true;
}

int main() {
    ll X;
    cin >> X;

    while(!isPrime(X)) X++;
    cout << X << endl;

    return 0;
}

Measured memory_bytes: 3616
n=int(input())
if n>81:
    print('No')
else:
    mod=(1,2,3,4,5,6,7,8,9)
    for i in mod:
        if n%i==0 and n//i<=9:
            print('Yes')
            break
        else:
            if i==9:
                print('No')
                break
            else:
                continue

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main (void)
{
    int n, m;
    cin >> n >> m;

    char **image = (char **)malloc(sizeof(char *) * n);
    char **temp = (char **)malloc(sizeof(char *) * m);

    for (int i = 0; i < n; i++) {
        image[i] = (char *)malloc(sizeof(char) * n);
        scanf("%s", image[i]);
    }
    for (int i = 0; i < m; i++) {
        temp[i] = (char *)malloc(sizeof(char) * m);
        scanf("%s", temp[i]);
    }
    
    bool exist;
    for (int i = 0; i <= n - m; i++) {
        for (int j = 0; j <= n - m; j++) {
            exist = true;
            for (int k = 0; k < m; k++) {
                for (int l = 0; l < m; l++) {
                    if (image[i + k][j + l] != temp[k][l]) {
                        exist = false;
                    }
                }
            }
            if (exist) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    for (int i = 0; i < n; i++) {
        free(image[i]);
    }
    for (int i = 0; i < m; i++) {
        free(temp[i]);
    }
    free(image);
    free(temp);

    return 0;
}

Measured memory_bytes: 256