akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=55,mod=1e9+7;
int C[maxn][maxn],f[maxn][maxn];
inline void add(int &x,int y){
	x+=y;
	x=(x>=mod?x-mod:x);
}
int main(){
	int n=read();
	f[1][0]=f[1][1]=n;
	REP(i,0,n){
		C[i][i]=C[i][0]=1;
		REP(j,1,i-1) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	REP(i,1,n-1) REP(j,0,i) if(f[i][j]) REP(k,0,n-i) REP(l,0,n-i-k)
		if(k+l && !((k+l+j)&1) && k+l>=j)
			add(f[i+k+l][abs(l-k+j)/2],(ll)f[i][j]*C[n-i][k+l]%mod*C[k+l][k]%mod);
	printf("%d\n",f[n][0]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


int main() {
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    int n=s.size(),cnt=1;
    ll ans=0;
    invrep(i,n) {
        if (s[i]=='B') {
            ans+=(n-cnt)-i;
            ++cnt;
        }
    } 
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 720
def count(x, y, N):
    l = len(str(N)) # Nの桁数
    a = int(str(N)[0]) # Nの最上桁
    b = int(str(N)[-1]) # Nの最下桁

    if l == 1:
        if x == y and a >= x:
            return 1
        else:
            return 0
    elif l == 2:
        res = 0
        if x == y:
            res += 1
        if a >= x and b >= y:
            res+=1
        return res
    elif l >=3:
        res = 0
        if x == y:
            res += 1 # 1桁
        res += 1 # 2桁        
        for i in range(1, l - 2): # 3桁 ~ l-1桁
            res += 10 ** i
        if a > x:
            res += 10 ** (l - 2) # l桁
        elif a == x and b >= y:
            res += int(str(N)[1:-1]) + 1
        elif a == x and b < y:
            res += int(str(N)[1:-1])
        return res

N = int(input())
ans = 0
for x in range(1, 10):
    for y in range(1, 10):
        # print(x, y, N, count(x,y,N), count(y,x,N))
        ans += count(x, y, N) * count (y, x, N)

print(ans)


Measured memory_bytes: 3064
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const n = parseInt(args[0][0], 10)
	const a = parseInt(args[0][1], 10)
	const b = parseInt(args[0][2], 10)
	console.log(Math.min(a * n, b))
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	long long N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	--A;
	--B;
	--C;
	--D;

	string s;
	cin >> s;

	if (C < D) {
		for (int i = A; i < D; ++i) {
			if (s[i] == '#' && s[i - 1] == '#') {
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}
	else if (D < C) {
		for (int i = A; i < D; ++i) {
			if (s[i] == '#' && s[i - 1] == '#') {
				cout << "No" << endl;
				return 0;
			}
		}

		for (int i = B + 1; i <= D + 1; ++i) {
			if (s[i] == '.' && s[i - 1] == '.' && s[i - 2] == '.') {
				cout << "Yes" << endl;
				return 0;
			}
		}
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main()
{
	int i;
	int a[3], b[3];
	scanf("%d%d", &a[0], &b[0]);
	scanf("%d%d", &a[1], &b[1]);
	scanf("%d%d", &a[2], &b[2]);

	int count[4];
	for (i = 0; i < 4; i++) {
		count[i] = 0;
	}

	for (i = 0; i < 3; i++) {
		if (a[i] == 1) {
			count[0] += 1;
		} else if (a[i] == 2) {
			count[1] += 1;
		} else if (a[i] == 3) {
			count[2] += 1;
		} else if (a[i] == 4) {
			count[3] += 1;
		} 
        if (b[i] == 1) {
            count[0] += 1;
        } else if (b[i] == 2) {
            count[1] += 1;
        } else if (b[i] == 3) {
            count[2] += 1;
        } else if (b[i] == 4) {
            count[3] += 1;
        }
	}

	int flag=0;
	for (i = 0; i < 4; i++) {
		if (count[i] == 2) {
			flag += 1;
		}
	}
	if (flag == 2) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}
	return 0;
}


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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

///////////////////////////////////
///// for any code taken from cheatsheet

/////
int A[100003];


int main()
{
	// freopen("input.in", "r", stdin);
	

	int n, k, s;
	scanf("%d %d %d", &n, &k, &s);
	
	for(int i = 0; i < k; i++)
		A[i] = s;

	for(int i = k; i < n; i++)
	{
		A[i] = (s == 1000000000)? 1 : s+1;
	}
	for(int i = 0; i < n; i++) printf("%d%c", A[i], (i == n-1)? '\n' : ' ');
}

Measured memory_bytes: 1664
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int A,B,C;
  cin >> A >> B >> C;
  if(C >= A && C <= B)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        int i = 1;
        list.add(s);
        while(true){
            i ++;
            if(s % 2 == 0){
                s /= 2;
            }else {
                s = s * 3 + 1;
            }
            if(list.contains(s)){
                System.out.println(i);
                break;
            }
            list.add(s);
        }

    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
int n;pair<int,int>a[2<<17];
main()
{
	cin>>n;
	for(int i=0;i<2*n;a[i].second=i<n,i++)cin>>a[i].first;
	sort(a,a+2*n);
	long ans=1,m=1e9+7,c=1,p=0;
	for(int i=1;i<2*n;i++)
	{
		if(a[p].second!=a[i].second)ans=ans*c--%m;
		else c++;
		if(c==0)p=i+1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var digits = input[0].split('');

    var a = parseInt(digits[0], 10);
    var b = parseInt(digits[1], 10);
    var c = parseInt(digits[2], 10);
    var d = parseInt(digits[3], 10);

    if (a + b + c + d == 7) {
        console.log(a + '+' + b + '+' + c + '+' + d + '=7');
    }
    else if (a + b + c - d == 7) {
        console.log(a + '+' + b + '+' + c + '-' + d + '=7');
    }
    else if (a + b - c + d == 7) {
        console.log(a + '+' + b + '-' + c + '+' + d + '=7');
    }
    else if (a + b - c - d == 7) {
        console.log(a + '+' + b + '-' + c + '-' + d + '=7');
    }
    else if (a - b + c + d == 7) {
        console.log(a + '-' + b + '+' + c + '+' + d + '=7');
    }
    else if (a - b + c - d == 7) {
        console.log(a + '-' + b + '+' + c + '-' + d + '=7');
    }
    else if (a - b - c + d == 7) {
        console.log(a + '-' + b + '-' + c + '+' + d + '=7');
    }
    else {
        console.log(a + '-' + b + '-' + c + '-' + d + '=7');
    }

    return 0;
}



Measured memory_bytes: 21192
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'
 
let lines: string[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
 
reader.on('line', function (line: string) {
    lines.push(line);
});
reader.on('close', function () {
    let n = parseInt(lines[0])
    let a = lines[1].split(' ').map( _ => parseInt(_))
    let ans = BigInt(1)

    for(let i = 0; i < n; i++) {
        if(a[i] == 0) {
            console.log(0)
            return
        }
    }

    for(let i = 0; i < n; i++) {
        ans = ans * BigInt(a[i])
        if(ans > 10**18) {
            console.log(-1)
            return
        }
    }

    console.log(String(ans))

});

Measured memory_bytes: 51064
#include<bits/stdc++.h>
using namespace std;
int n,min1=1000,max1=-1,x;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		min1=min(min1,x);
		max1=max(max1,x);
	}
	printf("%d\n",max1-min1);
	return 0;
}

Measured memory_bytes: 764
#include<iostream>
using namespace std;
int main()
{
	long long i,j,k,s=0,p,ss=5555555,q,r;
	string t,l;
	cin>>t>>l;
	q=t.size();
	r=l.size();
	for(i=0;i<=(q-r);i++)
	{
		s=0;
		p=i;
		for(j=0;j<r;j++)
		{
			if (t[p]!=l[j])s++;
			
			p++;
		}
		if (s<ss)ss=s;
	}
	cout<<ss;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long x,n;
    cin>>x>>n;
    vector<long long>v(n);
    for(int i=0;i<n;i++)
    	cin>>v[i];
    int mx=0,start_pos,dist;
    for(int i=1;i<=n;i++)
    {
    	if(i==n)
    	{
			dist=abs(x-v[n-1]+v[0]);
			if(dist>mx)
				start_pos=0;
			break;
		}

    	dist=abs(v[i]-v[i-1]);
    	if(dist>mx)
		{
			start_pos=i;
			mx=dist;
		}
    }
    long long res=0;
    if(start_pos==0)
    {
    	for(int i=1;i<n;i++)
    		res+=abs(v[i]-v[i-1]);
    	cout<<res<<endl;

    }
    else
    {
    	for(int i=n-1;i>start_pos;i--)
    		res+=abs(v[i]-v[i-1]);
    	res+=abs(x-v[n-1]+v[0]);
    	for(int i=1;i<start_pos;i++)
    		res+=abs(v[i]-v[i-1]);
    	cout<<res<<endl;
    }

    return 0;
}

Measured memory_bytes: 1792
# A - RGB Cards

# 赤、緑、青色のカードを持っている
# それぞれのカードには 1以上9以下の整数が書かれている

# 赤色のカード r
# 緑色のカード g
# 青色のカード b

# 3つのカード を 左から r g b と並べて、左から整数を読む
# 4の倍数である場合 YES そうでない場合 NO と出力

# r g b を標準入力から得る
r, g, b = map(int, input().split(maxsplit=3))
# print(r, g, b)

# 整数を計算する
# r * 100, g * 10
integer_rgb = (r * 100) + (g * 10) + b
# print(integer_rgb)

# 4で割った余りが 0　の時　YES
# それ以外は NO

if integer_rgb % 4 == 0:
    answer = "YES"
else:
    answer = "NO"

# 結果を出力
print(answer)


Measured memory_bytes: 9188
#include<cstdio>
#include<vector>

using namespace std;

vector<int>g[100001];
int a[100001],ans;
void dfs(int u,int f){
	int z=0;
	for(int i=0;i<g[u].size();i++)
		if(g[u][i]!=f){
			dfs(g[u][i],u);
			z+=!a[g[u][i]];
			a[u]|=a[g[u][i]];
		}
	if(z>1)ans+=z-1,a[u]=1;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u++;v++;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int o=1;
	while(o<=n&&g[o].size()!=1)o++;
	if(o>n){
		printf("1\n");
		return 0;
	}
	dfs(o,0);
	int haha=ans+1;
	for(int i=1;i<=10;i++){
		o++;
		while(o<=n&&g[o].size()!=1)o++;
		if(o>n)break;
		ans=0;
		for(int i=1;i<=n;i++)a[i]=0;
		dfs(o,0);
		haha=min(haha,ans+1);
	}
	printf("%d\n",haha);
}


Measured memory_bytes: 13952
open System

[<EntryPoint>]
let main argv =
    let [|M1; D1;|] = stdin.ReadLine().Split() |> Array.map int
    let [|M2; D2;|] = stdin.ReadLine().Split() |> Array.map int
    let ret = if (D2 = 1) then 1 else 0
    printfn "%d" ret
    0

Measured memory_bytes: 14040
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    vector<int> mul(100001, 1), cum(100001, 0);
    for (int i = 2; i <= 100000; ++i) {
        for (int j = 2 * i; j <= 100000; j += i) if (!cum[j]) {
            mul[j] *= i;
            if (mul[j] >= 2 * j) cum[j] = 1;
        }
    }
    for (int i = 2; i <= 100000; ++i) {
        cum[i] += cum[i - 1];
    }
    int Q;
    cin >> Q;
    REP (i, Q) {
        int N;
        cin >> N;
        cout << cum[N] << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


Measured memory_bytes: 4312
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int K;
  cin>>K;
  int tmp = 7;
  int ans=-1;
  for(int i=0;i<K;++i) {
    if(tmp%K==0) {
      ans = i+1;
      break;
    }
    tmp *= 10;
    tmp += 7;
    tmp %= K;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
  	cin>>n>>m;
  	int a,b;
  	if(n<=1){
    	a=0;
    }
  	else{
    	a=(n*(n-1))/2;
    }
  	if(m<=1){
    	b=0;
    }
  	else{
    	b=(m*(m-1))/2;
    }
  	cout<<a+b<<endl;
  

}

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

int main(){
double c,b;
cin>>c>>b;
int a,flag=1;
vector<int>arr;
for(int i=0;i<b;i++){
    cin>>a;
    arr.push_back(a);
}
sort(arr.begin(),arr.end());
reverse(arr.begin(),arr.end());
for(int i=0;i<arr.size();i++){
    if(c-arr[i]>0)
        c=c-arr[i];
    else{flag=0;
        break;}
}
if(flag==1)
    cout<<"No"<<endl;
else
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 892
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int res = 0;
        Scanner s = new Scanner(System.in);
        String text = s.nextLine();

        if (text.length()%2 == 0){
            for (int i=0; i<text.length()/2; i++){
                if (text.charAt(i)!=text.charAt(text.length()-1-i))
                    res += 1;
                else
                    continue;
            }
        }else{
            for (int i=0; i<text.length()/2; i++){
                if (text.charAt(i)!=text.charAt(text.length()-1-i))
                    res += 1;
                else
                    continue;
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 25044
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
int ansx, ansy;
int bj1, bj2;
int ji[8005], ou[8005];
queue<int> q[2];
int ha[16005][2];
int main() {
	char s[8005];
	cin >> s;
	cin >> ansx >> ansy;
	int temp = 0, temp1 = 0;
	int ls = strlen(s), dbj = 0;
	s[ls] = 'T';
	for(int i = 0; i <= ls; i++)
		if(s[i] == 'F')
			temp ++;
		else if(s[i] == 'T') {
			if(temp1 == 0)
				ji[++ji[0]] = temp;
			else
				ou[++ou[0]] = temp;
			temp1 ++;
			temp1 %= 2;
			temp = 0;
		}
	q[0].push(ji[1] + 8000);
	ha[ji[1] + 8000][0] = 1;
	for(int i = 2; i <= ji[0]; i++) {
		while(!q[i % 2].empty()) {
			ha[q[i % 2].front()][i % 2] = 0;
			if(ha[q[i % 2].front() - ji[i]][(i + 1) % 2] == 0)
				ha[q[i % 2].front() - ji[i]][(i + 1) % 2] = 1, q[(i + 1) % 2].push(q[i % 2].front() - ji[i]);
			if(ha[q[i % 2].front() + ji[i]][(i + 1) % 2] == 0)
				ha[q[i % 2].front() + ji[i]][(i + 1) % 2] = 1, q[(i + 1) % 2].push(q[i % 2].front() + ji[i]);
			q[i % 2].pop();
		}
	}
	if(ha[ansx + 8000][(ji[0] + 1) % 2] == 0) {
		cout << "No" << endl;
		return 0;
	}
	while(!q[0].empty())
		q[0].pop();
	while(!q[1].empty())
		q[1].pop();
	memset(ha, 0, sizeof ha);
	q[1].push(8000);
	ha[8000][1] = 1;
	for(int i = 1; i <= ou[0]; i++) {
		while(!q[i % 2].empty()) {
			ha[q[i % 2].front()][i % 2] = 0;
			if(ha[q[i % 2].front() - ou[i]][(i + 1) % 2] == 0)
				ha[q[i % 2].front() - ou[i]][(i + 1) % 2] = 1, q[(i + 1) % 2].push(q[i % 2].front() - ou[i]);
			if(ha[q[i % 2].front() + ou[i]][(i + 1) % 2] == 0)
				ha[q[i % 2].front() + ou[i]][(i + 1) % 2] = 1, q[(i + 1) % 2].push(q[i % 2].front() + ou[i]);
			q[i % 2].pop();
		}
	}
	if(ha[ansy + 8000][(ou[0] + 1) % 2] == 0) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 27 03:05:21 2020

@author: liang
"""

N ,T = map(int,input().split())

time = [int(x) for x in input().split()]

ans = 0
for i in range(N-1):
    ans += min(T, time[i+1]-time[i])
ans += T
print(ans)

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

int main() {
  int N, M,count=0;
  cin >>N >> M;
  for(int i=0;i<M;i++){
    int A; cin >>A;
    count +=A;
  }
  if (count>N){
    cout <<-1 <<endl;
  }
  else {
    cout <<N-count<<endl;
  }
  
    
}


Measured memory_bytes: 3568
use std::io;


fn read_line() -> String {
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("Failed to read line");
    return line;
}
fn to_i(s: &str) -> i64 {
    return s.trim().parse()
        .expect("Please type a number!");
}
fn read_nums() -> Vec<i64>
{
    let line = read_line();
    let items: Vec<&str> = line.split(' ').collect();

    let mut nums: Vec<i64> = Vec::new();

    for item in items {
        nums.push(to_i(item));
    }
    return nums;
}


fn main() {

    let abc = read_nums();
    let a = abc[0];
    let b = abc[1];
    let c = abc[2];

    let  mut ret = "No";
    if (a<c && c<b) || (b<c && c<a) {
        ret = "Yes";
    }

    print!("{}", ret);
}   

Measured memory_bytes: 4352
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  const int l = getInt();
  const int t = getInt();

  vector<int> x(n);
  vector<int> w(n);

  REP(i,n){
    x[i] = getInt();
    w[i] = getInt();
  }

  int k = 0;
  while(k != n && w[k] != 1) k++;

  if(k == n){
    REP(i,n){
      int p = (x[i] - t) % l;
      if(p < 0) p += l;
      printf("%d\n", p);
    }
    return 0;
  }

  int cnt = 0;

  REP(i,n) if(w[(k + i) % n] == 2){
    int xx = x[(k + i) % n];
    if(xx < x[k]) xx += l;

    int diff = xx - x[k];
    int dt = diff / 2 + diff % 2;

    if(dt < t) {
      cnt++;

      int rest = t - dt;
      cnt += 2 * (rest / l);

      if(diff % 2 == 0 && rest % l == 0) cnt--;

      const int r = rest % l;

      if(l - diff % 2 == 0){
        if(r + r > l - diff % 2) cnt++;
      }else{
        if(r + r >= l - diff % 2) cnt++;
      }
    }else if(dt == t && diff % 2 == 1){
      cnt++;
    }
  }

  // printf("%d %d\n", k, cnt);
  vector<int> ans(n);
  int kp = 0;
  REP(i,n){
    const int idx = (k + i) % n;
    int xx = (x[idx] + (w[idx] == 2 ? -t : t)) % l;
    if(xx < 0) xx += l;
    ans[i] = xx;
    if(i == 0) kp = xx;
  }

  sort(ans.begin(), ans.end());
  int idx = 0; while(ans[idx] != kp) idx++;
  int zidx = (idx - k - cnt) % n;
  if(zidx < 0) zidx += n;
  // printf("%d %d %d %d\n", k, cnt, kp, idx);

  REP(i,n) printf("%d\n", ans[(zidx + i) % n]);

  return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
  
/*------------------------------------------------------------------*/
  
int main(){
    string s; cin >> s;
    int n = s.length();
    while(true){
        s.erase(n - 2, 2);
        n = s.length();
        string t = s.substr(0, n / 2);
        string u = s.substr(n / 2, n / 2);
        if(t == u){
            cout << n << endl;
            return 0;
        }
        //cout << s << endl;
    }
}


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

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

using namespace std;
typedef pair<int,int> pii;

const int INF = 0x3fffffff;

class Flow{
	public:
		int N;
		vector< vector<int> > F, C, edge;
		Flow(int n, int e): F(n,vector<int>(n)), C(n,vector<int>(n)), N(n), edge(n) {}
		void addEdge(int f, int t, int c){
			F[f][t] = C[f][t] = c;
			edge[f].push_back(t);
			edge[t].push_back(f);
		}
		int flow(int n, int c, int T, vector<bool> &bf){
			if( n == T ) return c;
			bf[n] = true;
			for(int i: edge[n]) if( F[n][i] > 0 && !bf[i] ){
				int f = flow(i, min(c, F[n][i]), T, bf);
				F[n][i] -= f;
				F[i][n] += f;
				if( f > 0 ) return f;
			}
			return 0;
		}
		int maxFlow(int S, int T){
			int ret = 0;
			vector<bool> bf(N);
			for(int add; add = flow(0, INF, T, bf); bf.assign(N,0)) ret += add;
			return ret;
		}
		void clear(){ rep(i,N) rep(j,N) F[i][j] = C[i][j]; }
};

int main(){
	int V, E;
	cin >> V >> E;
	Flow fl(V,E);
	for(int i=1; i<=E; i++){
		int u, v, c;
		cin >> u >> v >> c;
		fl.addEdge( u, v, c );
	}

	cout << fl.maxFlow(0, V-1) << endl;

	return 0;
}

Measured memory_bytes: 3224
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solveMulti(sc: Scanner, pw: java.io.PrintWriter) {
        for (t in 1..sc.next().toInt()) {
            solve(sc, pw)
        }
    }

    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val M = sc.next().toInt()
        val way = Array(N) { mutableListOf<Int>() }
        repeat(M) {
            val A = sc.next().toInt() - 1
            val B = sc.next().toInt() - 1
            way[A].add(B)
            way[B].add(A)
        }
        val ans = IntArray(N) { -1 }
        ans[0] = 0
        val q = LinkedList<Int>()
        q.add(0)
        while (q.isNotEmpty()) {
            val i = q.pop()
            way[i].forEach { j ->
                if (ans[j] < 0) {
                    ans[j] = i + 1
                    q.addLast(j)
                }
            }
        }

        if (ans.contains(-1)) {
            pw.println("No")
        } else {
            pw.println("Yes")
            for (i in 1 until N) {
                pw.println(ans[i])
            }
        }
    }
}


Measured memory_bytes: 77584
open Printf
       
type point = {x:float; y:float}

let add p1 p2 = {x = p1.x +. p2.x; y = p1.y +. p2.y}
let sub p1 p2 = {x = p1.x -. p2.x; y = p1.y -. p2.y}
let mul k p = {x = k *. p.x; y = k *. p.y}
let rot60 v = let sqrt32 = (sqrt 3.0) /. 2.0 in {x = 0.5 *. v.x -. sqrt32 *. v.y; y = sqrt32 *. v.x +. 0.5 *. v.y}
let print_points ps =
  List.iter (fun x -> printf "%.8f %.8f\n" x.x x.y) ps

let () =
  let n = read_int () in
  let koch_curve n =
    let rec loop n p1 p2 ls =
      if n = 0 then p2 :: ls
      else let s = add (mul (2.0 /. 3.0) p1) (mul (1.0 /. 3.0) p2) in
           let t = add (mul (1.0 /. 3.0) p1) (mul (2.0 /. 3.0) p2) in
           let u = add s (rot60 (sub t s)) in
           let l1 = loop (n-1) t p2 ls in
           let l2 = loop (n-1) u t l1 in
           let l3 = loop (n-1) s u l2 in
           let l4 = loop (n-1) p1 s l3 in
           l4
    in
    let p1 = {x = 0.0; y = 0.0} in
    let p2 = {x = 100.0; y = 0.0} in
    p1 :: (loop n p1 p2 [])
  in
  print_points @@ koch_curve n

Measured memory_bytes: 4568
#include <stdio.h>
#include <algorithm>
typedef long long ll;

int main(void) {
  ll i, n, q, cnt = 0, x, y, t;
  scanf("%lld", &n);
  ll a[n], b[n];
  bool flg[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]), b[i] = a[i];
  std::sort(b, b + n);
  for(i = 0; i < n; ++i) {
    if(a[i] == b[i]) flg[i] = true;
    else flg[i] = false, cnt++;
  }
  if(!cnt) {
    printf("0\n");
    return 0;
  }
  scanf("%lld", &q);
  for(i = 0; i < q; ++i) {
    scanf("%lld%lld", &x, &y);
    x--, y--;
    if(!flg[x]) --cnt, flg[x] = true;
    if(!flg[y]) --cnt, flg[y] = true;
    t = a[x], a[x] = a[y], a[y] = t;
    if(a[x] != b[x]) ++cnt, flg[x] = false;
    if(a[y] != b[y]) ++cnt, flg[y] = false;
    if(!cnt) {
      printf("%lld\n", i +1);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}


Measured memory_bytes: 7780
import math
[A,B,H,M] = list(map(int,input().split()))

tm = 60*H + M
#print('time', tm)
#進んだ距離
Dji = 0.5 * tm
Dhu = 6 * tm
#print('1', Dji,Dhu)
'''
#げんじつ感のある角度に
Dji2 = Dji % 180
Dhu2 = Dhu % 180
#print('2', Dji2,Dhu2)

#間の角度
kaku = abs(Dji2 - Dhu2)
#print('kakudo',kaku)
'''
Dji2 = Dji % 360
Dhu2 = Dhu % 360
#print('2', Dji2,Dhu2)

if abs(Dji2 - Dhu2) <=180:
    kaku = abs(Dji2 - Dhu2)
else:
    kaku = 360 - abs(Dji2 - Dhu2)


#余弦定理
if kaku ==0:
    out = B - A

if kaku == 180:
    out = B + A
else:
    out = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(kaku)))


print(out)

Measured memory_bytes: 62596
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int hap[n][3];
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            cin >> hap[i][j];
        }
    }
    int dp[n][3];
    dp[0][0] = hap[0][0];
    dp[0][1] = hap[0][1];
    dp[0][2] = hap[0][2];
    for (int i = 1; i < n; ++i) 
    {
        for (int j = 0; j < 3; ++j)
        {
            if (j == 1) 
            {
                dp[i][j] = hap[i][j] + max(dp[i - 1][j - 1], dp[i - 1][j + 1]);
            } else if (j == 0) 
            {
                dp[i][j] = hap[i][j] + max(dp[i - 1][j + 1], dp[i - 1][j + 2]);
            } else
            {
                dp[i][j] = hap[i][j] + max(dp[i - 1][j - 1], dp[i - 1][j - 2]);
            }           
        }
    }
    // for (int i = 0; i < n; ++i) {
    //     for (int j = 0; j < 3; ++j) {
    //         cout << dp[i][j] << "  ";
    //     }
    //     cout << endl;
    // }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n -1][2])) << endl;
    return 0;
}

Measured memory_bytes: 2560
/******************************************************************************

                         بسم الله الرحمن الرحيم
                     Author: Mst: Mhamuda Khatun
                               RUCSE27

*******************************************************************************/

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define MAX 1000000000000
#define N 305

int main()
{
    fastio;
    int n,m,i,sum=0;
    cin>>n>>m;

    for(i=n-1;i>0;i--)
        sum+=i;

    for(i=m-1;i>0;i--)
        sum+=i;

    cout<<sum;
    cout<<"\n";
    return 0;   //:D
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char A;
  cin >> A;
  if(A == 'a' || A == 'i' || A == 'u' || A == 'e' || A == 'o'){
  	cout << "vowel" << endl;
  }else{
  	cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vll a(n+1);
    vint v(n+2,0LL);
    REP(i,n){
        cin >> a[i+1];
        v[max(0LL,i+1-a[i+1])]++;
        v[min(n+1,i+2+a[i+1])]--;
    }
    REP(i,k){
        ll now = v[0];
        bool f = true;
        for(ll j=1;j<=n;++j){
            now += v[j];
            a[j] = now;
            if(a[j]<n) f=false;
            v[j]=0;
        }
        v[0] = 0;
        v[n+1] = 0;
        for(ll j=1;j<=n;++j){
            v[max(0LL,j-a[j])]++;
            v[min(n+1,j+1+a[j])]--;
        }
        if(f) break;
    }
    for(ll j=1;j<=n-1;++j){
        cout << a[j] << " ";
    }
    cout << a[n] << endl;
    return 0;
}

Measured memory_bytes: 5564
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	
	cin >> a >> b;
	
	if ((a * b) % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}
	
	return (0);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N=2e5+20;
int n,a[N];
vector <int> m[N],ans;
int main()
{

	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);

	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j+=i)
			m[i].push_back(j);

	for(int i=n;i>=1;i--)
	{
		int s=0;
		for(auto j:m[i]) s+=a[j],s%=2;
		if(s==a[i])
		{
			if(a[i]==0) continue;
			else ans.push_back(i);
		}
		else
		{
			if(a[i]==1) a[i]=0;
			else a[i]=1,ans.push_back(i);
		}
	}

	printf("%d\n",(int)ans.size());
	for(auto i:ans) printf("%d ",i);
}

Measured memory_bytes: 23924
#include <stdio.h>

int main(){
  char S[4];
  int d[4]={1,1,1},c=1;
  scanf("%s",S);
  for(int i=0;i<3;i++){
    if(d[S[i]-'a']!=1)
      c=0;
    d[S[i]-'a']--;
  }
  if(c==1) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

using ll = long long;
using quad = tuple<int, int, int, int>;
const int N = 1e5 + 5;

int A[N];
int ans = 0;

vector<quad> qs;
void build(int i, int n, int m, int last) {
    if (i == n+1) {
        int cur = 0;
        for (auto& [a,b,c,d] : qs) {
            if (A[b] - A[a] == c)
                cur += d;
        }
        ans = max(ans, cur);
        return;
    }

    for (int x = last; x <= m; x++) {
        A[i] = x;
        build(i+1, n, m, x);
    }
}

int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, m, q;
    cin >> n >> m >> q;

    qs.resize(q);
    for (auto& [a, b, c, d] : qs) cin >> a >> b >> c >> d;

    build(1, n, m, 1);

    cout << ans << endl;

    return 0;
%>

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
// #define MOD 998244353
#define VL vector<ll>

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

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



template< typename T >
struct edge {
	int src, to;
	T cost;

	edge(int to, T cost) : src(-1), to(to), cost(cost) {}

	edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

	edge &operator=(const int &x) {
		to = x;
		return *this;
	}

	operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
/*
WeightedGraph<ll> g(V);
g[a].emplace_back(b, c);
*/
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

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

	ll t = N % 10;
	if (t == 3) {
		PRINT("bon");
	} else if (t == 0 || t == 1 || t == 6 || t == 8) {
		PRINT("pon");
	} else {
		PRINT("hon");
	}
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	ll n,ma,mb; cin>>n>>ma>>mb;
	vector<vector<ll>> s;
	rep(i,n){
		VL t(3); cin>>t[0]>>t[1]>>t[2]; s.PB(t);
	}
	ll dp[n+1][420][420]; memset(dp,INF,sizeof(dp));
	dp[0][0][0]=0;
	// cerr << "start" << endl;
	rep(i,n){
		rep(j,401){
			rep(k,401){
				if(dp[i][j][k]==INF) continue;
				chmin(dp[i+1][j][k],dp[i][j][k]);
				chmin(dp[i+1][j+s[i][0]][k+s[i][1]],dp[i][j][k]+s[i][2]);
			}
		}
		// cerr << i << endl;
	}
	ll ans = INF;
	reps(a,400){
		reps(b,400){
			if(a*mb==b*ma) chmin(ans,dp[n][a][b]);
		}
	}
	if(ans!=INF) cout<<ans<<endl;
	else cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 56832
// C - Bridge
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> V;
vector<int> vis;
int a, b;

void dfs(int f){
	if(vis[f]) return;
	vis[f] = 1;
	for(int t:V[f]) if(f!=a || t!=b) dfs(t);
}

int main(){
	int N, M; cin>>N>>M;
	V.resize(N);
	vis.resize(N);
	vector<pair<int,int>> E;
	for(int i=0; i<M; ++i){
		cin>>a>>b; --a, --b;
		E.emplace_back(a, b);
		V[a].push_back(b);
		V[b].push_back(a);
	}
	int ans = 0;
	for(auto [u,v]:E){
		a = u, b = v;
		for(auto& x:vis) x = 0;
		dfs(a);
		if(!vis[b]) ans++;
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
int main (){
    int a,b,c,d,e,f;
    while (cin>>a>>b){
        c=a+b;
        d=a-b;
        e=a*b;
        f=max(c,d);
        cout<<max(e,f)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
"""


Memo = []
def solve(data):
    global Memo
    for d in data:
        if d in Memo:
            Memo.remove(d)
        else:
            Memo.append(d)
    return len(Memo)


def solve2(data):
    from collections import Counter
    c = Counter(data).most_common()
    remaining = [x for x in c if x[1]%2==1]
    return len(remaining)


def main():
    N = int(input())
    data = [int(input()) for _ in range(N)]
    result = solve2(data)
    print(result)


if __name__ == '__main__':
    main()
    

Measured memory_bytes: 21260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	ll l,r,d;
	cin>>l>>r>>d;


	cout<< r/d - (l-1)/d << "\n";			
}

Measured memory_bytes: 3636
#両端を食べるのは非効率なので、両端はx個まで食べたうえで真ん中を食べる
N,x=(int(_) for _ in input().split())
a=[int(_) for _ in input().split()]
eat=0
if a[0]>x:
    eat+=a[0]-x
    a[0]=x
for i in range(0,N-1):
    wa=a[i]+a[i+1]
    if wa>x:
        a[i+1]=x-a[i]
        eat+=wa-x
print(eat)



Measured memory_bytes: 14060
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int main() {
	int n;
	cin >> n;
	double v[n+1];
	for (int i=1; i<=n; i++) {
		cin >> v[i];
	}
	double dp[n+1][n+1];
	for (int i=0; i<=n; i++) {
		dp[0][i] = 0;
	}
	dp[1][0] = 1-v[1];
	dp[1][1] = v[1];
	for (int i=2; i<=n; i++) {
		dp[1][i] = 0;
	}

	for (int i=2; i<=n; i++) {
		for (int j=0; j<=n; j++) {
			dp[i][j] = 0;
			if (j > i)
				dp[i][j] = 0;
			else {
				if (j >= 1)
					dp[i][j] = dp[i-1][j-1]*v[i];
				dp[i][j] += dp[i-1][j]*(1-v[i]);
			}
		}
	}
	double ans = 0;
	/*for (int i=0; i<=n; i++) {
		for (int j=0; j<=n; j++) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	for (int i=(n/2)+1; i<=n; i++) {
		ans += dp[n][i];
	}
	printf("%.10lf\n", ans);
	return 0;
}


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

using namespace std;

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

int main(){
    int h, w;
    cin >> h >> w;
    h += 2; w += 2;
    string s[h];
    string a = "";
    rep(i, w){
        a += '#';
    }
    s[0] = a;
    s[h-1] = a;
    for (int i = 1; i < h - 1; i++){
        string t;
        cin >> t;
        s[i] = "#";
        s[i] += t;
        s[i] += '#';
    }
    rep(i, h){
        cout << s[i] << endl;
    } 

}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<long long> vecll;
typedef vector<unsigned long long> vecull;

int N;
string S;

int main(void) {
    stack<char> st;
    int r_cnt = 0;
    cin >> N >> S;

    rep(i, N) {
        if (S[i] == '(') {
            st.push(S[i]);
            continue;
        }
        else {
            if (st.empty())
            {
                r_cnt++;
            }
            else {
                st.pop();
            }
        }
    }

    S = string(r_cnt, '(') + S + string(st.size(), ')');

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <assert.h>
using namespace std;

const int DSIZE = 26;



int solve() {
    string S;
    cin >> S;
    bool d[DSIZE] = {false};
    for (int i = 0; i < S.length(); i++) {
        d[S[i]-'a'] = true;
    }
    
    for (int i = 0; i < DSIZE; i++) {
        if (!d[i]) {
            cout << S << char('a'+i) << endl;
            return 0;
        }
    }
    
    for (int i = S.length()-1; i >= 1 ; i--) {
        if (S[i] > S[i-1]) {
            char nextminc = 'z'+1;
            for (int j = S.length()-1; j >= i; j--) {
                if (S[i-1] < S[j]) nextminc = min(S[j], nextminc);
            }
            cout << S.substr(0, i-1) << nextminc << endl;
            return 0;
        }
    }
    
    
    cout << "-1" << endl;
    return 0;
}

int main() {
    //while (true) {
        solve();
    //}
}


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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
        int n, k, q; cin >> n >> k >> q;
        vector<int> a(q), res(n, k);
        for (int i = 0; i < q; ++i)
        {
                cin >> a[i];
                res[a[i] - 1]++;
        }
        for (int i = 0; i < n; ++i)
        {
                res[i] -= q;
                if (res[i] <= 0) cout << "No" << endl;
                else cout << "Yes" << endl;
        }
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


Measured memory_bytes: 3972
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

int V, all, mini;
int used[4], ans[4], rel[4];
vector< int > p(4);

bool check(int *used, int sum) {
    int tmp[4];
    tmp[0] = sum / 500; sum %= 500;
    tmp[1] = sum / 100; sum %= 100;
    tmp[2] = sum / 50;  sum %= 50;
    tmp[3] = sum / 10;
    for(int i = 0; i < 4; i++)
        if(tmp[i] && used[i]) return false;
    return true;
 }

int remain(int v) {
    int ret = 0;
    ret += v / 500; v %= 500;
    ret += v / 100; v %= 100;
    ret += v / 50;  v %= 50;
    ret += v / 10;
    return ret;
}

void Update(int *used, int sum) {
    int coins = (all - (used[0] + used[1] + used[2] + used[3])) + remain(sum - V);
    if(coins < mini && check(used, sum - V)) {
        for(int i = 0; i < 4; i++)
            ans[i] = used[i];
        mini = coins;
    }
}

void rec(int idx, int sum) {
    //cout << idx << " " << sum << endl;
    if(sum >= V) {
        Update(used, sum);
    }
    if(idx > 3) return;
    rec(idx + 1, sum);
    for(int i = 1; i <= p[idx]; i++) {
        used[idx] += i;
        rec(idx + 1, sum + rel[idx] * i);
        used[idx] -= i;
    }
}

int main() {

    bool enter = false;
    rel[0] = 500, rel[1] = 100, rel[2] = 50, rel[3] = 10;
    while(cin >> V, V) {
        if(enter) cout << endl;
        enter = true;
        memset(used, 0, sizeof(used));
        mini = INF, all = 0;
        for(int i = 3; i >= 0; i--) {
            cin >> p[i]; all += p[i];
        }
        rec(0, 0);

        for(int i = 3; i >= 0; i--)
            if(ans[i]) cout << rel[i] << " " << ans[i] << endl;
    }
}

Measured memory_bytes: 1196
def _calc_today_max(today, Ci, Sdi, last_day):
    today_total_bad_value = \
        sum([Ci[contest] * (today + 1 - last_day[contest]) for contest in range(26)])

    max_value = -99999999999999999
    max_context = 0
    for contest in range(26):
        today_contest_value = Sdi[today][contest]
        today_bad_value = today_total_bad_value - (Ci[contest] * (today + 1 - last_day[contest]))
        today_value = today_contest_value - today_bad_value
        if max_value < today_value:
            max_value = today_value
            max_context = contest

    return max_context


def _main(D, Ci, Sdi):
    last_day = [0] * 26
    for today in range(D):
        max_contest = _calc_today_max(today, Ci, Sdi, last_day)
        print(max_contest + 1)
        last_day[max_contest] = today + 1


def _execute():
    D = int(input())
    Ci = list(map(int, input().split()))
    Sdi = []
    for i in range(D):
        Sdi.append(list(map(int, input().split())))
    _main(D, Ci, Sdi)


if __name__ == "__main__":
    _execute()


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

#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()  
{ 
    FAST_INP;
    long long n;
    cin >> n;
	int arr[10000]; 
    int i=0; 
    // convert n to base 26
    while(n){ 
        arr[i]=n%26; 
        n=n/26; 
        i++; 
    } 
    // cant have 0 as A starts at 1
    // remove 0 
    // e.g 100 (base 26) -> 25 26 (base 26)
    for (int j=0; j<i-1; j++) { 
        if (arr[j]<=0) { 
            // borrow 26
            arr[j]+=26; 
            // substract 1 from next significant bit
            arr[j+1]=arr[j+1]-1; 
        } 
    } 
    // 25 26 (base 26) -> YZ
    for (int j=i; j>= 0; j--) { 
        if (arr[j]>0)  cout << char('a'+arr[j]-1); 
    } 
    cout << endl; 
    return 0;
} 

Measured memory_bytes: 3584
s = gets.chomp.split('')
check = 0
s.size.times do |i|
  check = 1 if s[i] == 'R' && (i+1).even?
  check = 1 if s[i] == 'L' && (i+1).odd?
end

check.zero? ? (puts 'Yes') : (puts 'No')

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

using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	bool flag = false;
	set<int> s;
	vector<int> vet;
	for(int i=0; i<m; i++){
		int u,v;
		cin >> u >> v;
		if(u == 1) s.insert(v);
		if(v == n) vet.push_back(u);
	}
	for(int i=0; i<vet.size(); i++){
		if(s.count(vet[i])) flag = true;
	}
	if(flag) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 5368
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define VV(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
	while(true) {
		int n = 2;
		vi v(n); rep(i, 0, n) cin >> v[i];
		if (v[0] == 0 && v[1] == 0) break;
		sort(all(v));
		cout << v[0] << " " << v[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3212