akhauriyash/Code-Regression huggingface dataset:
import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
a = list(map(int, input().split()))

MOD = 10**9+7

sum_j = 0
for v in a:
    sum_j += v
    sum_j %= MOD

ans = 0
for v in a:
    ans += v * ((sum_j - v) % MOD)
    ans %= MOD

# 重複削除
class FLT:
    """
    フェルマーの小定理
    a^(-1) = a^(m-2) mod p
    """
    def __init__(self, mod=10**9+7):
        self.mod = mod

    def rep_sqr(self, base, k):
        ans = 1
        while k > 0:
            if k & 1:
                ans = ans * base % self.mod
            base = base * base % self.mod
            k >>= 1
        return ans

    def inv(self, a):
        """ 逆元を取る """
        return self.rep_sqr(a, self.mod-2)

flt = FLT()

ans = ans * flt.inv(2)
ans %= MOD
print(ans)

Measured memory_bytes: 93720
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    unsigned int A,B;
    cin >> A >> B;
    cout << (A-1)*(B-1) << endl;
    return 0;
}



Measured memory_bytes: 256
a, b = map(int, input().split())
if a + b >= a + a - 1 and a + b >= b + b - 1:
    print(a+b)
elif a + a - 1 >= a + b and a + a - 1 >= b + b - 1:
    print(a + a - 1)
elif b + b - 1 > a + b and b + b - 1 >= a + a - 1:
    print(b + b - 1)

Measured memory_bytes: 3060
rate = int(input())
k = '1'
if (400 <= rate < 600):
    k = '8'
elif (600 <= rate < 800):
    k = '7'
elif (800 <= rate < 1000):
    k = '6'
elif (1000 <= rate < 1200):
    k = '5'
elif (1200 <= rate < 1400):
    k = '4'
elif (1400 <= rate < 1600):
    k = '3'
elif (1600 <= rate < 1800):
    k = '2'
elif (1800 <= rate < 2000):
    k = '1'
print(k)


Measured memory_bytes: 9192
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
from math import gcd
from itertools import product
from functools import reduce
def resolve():
    n = int(input())
    res = 0
    for i, j, k in product(range(1, n + 1), repeat = 3):
        res += reduce(gcd, (i, j, k))
    print(res)
resolve()

Measured memory_bytes: 74276
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
    int N;
    cin >> N;
    
    double prob[N + 1];
    double dp[N + 1][N + 1], res = 0;
    
    for(int i = 1; i <= N; ++i)
    {
        cin >> prob[i];
    }    
    for(int i = 0; i <= N; ++i) 
    {
        for(int j = 0; j <= N; ++j)
        {
            dp[i][j] = 0;
        }
    }    
    
    //Probability for getting 0 heads using x coins 
    dp[1][0] = 1.0 - prob[1];
    for(int i = 2; i <= N; ++i)
    {
        dp[i][0] = dp[i - 1][0] * (1.0 - prob[i]);
    }    
    
    // Proability of getting a heads using a coins
    dp[1][1] = prob[1];
    for(int i = 2; i <= N; ++i)
    {
        dp[i][i] = dp[i - 1][i - 1] * prob[i];
    }   
    
    for(int i = 1; i <= N; ++i) 
    {
        for(int j = 1; j < i; ++j)
        {
            dp[i][j] = dp[i - 1][j] * (1.0 - prob[i]) + dp[i - 1][j - 1] * prob[i];
        }
    }
    for(int i = N / 2 + 1; i <= N; ++i)
    {
        res += dp[N][i];
    }
    cout << fixed << setprecision(10) << res;
    
	return 0;
}

Measured memory_bytes: 70528
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<ll,ll>P;
const int mod =1e9+7;

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main()
{
    int n;
    cin>>n;
    vector<bool> d(n,true);
    map<ll,ll> dc;
    vector<ll> a(n);
    ll vm=0;
    rep(i,n)
    {
        cin>>a[i];
        vm=max(vm,a[i]);
    }
    vector<int> c(vm+1,0);
    rep(i,n)
    {
        c[a[i]]+=1;
        if(c[a[i]]==1)
        {
            for(int j=2*a[i];j<=vm;j+=a[i])
            {
                c[j]++;
            }
        }
    }
    int ans=0;
    rep(i,n)
    {
        if(c[a[i]]==1)ans++;
        //cout<<i<<":"<<c[i]<<endl;
    }
    cout<<ans;
}


Measured memory_bytes: 8808
use std::io::prelude::*;

fn main() {
    let stdin = std::io::stdin();
    let mut reader = std::io::BufReader::new(stdin.lock());
    let mut s = String::new();
    reader.read_line(&mut s).unwrap();
    let _: usize = s.trim().parse().unwrap();

    let mut s = String::new();
    reader.read_line(&mut s).unwrap();
    let mut a = [0; 100000];
    let a_: Vec<usize> = s.split_whitespace().map(|x| x.parse().unwrap()).collect();
    for i in a_ {
        a[i] += 1;
    }

    let mut max = 0;

    for i in 1..99999 {
        if a[i - 1] + a[i] + a[i + 1] > max {
            max = a[i - 1] + a[i] + a[i + 1];
        }
    }
    println!("{}", max);
}


Measured memory_bytes: 6780
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

#define v(T) vector<T>
#define vv(T) v(v(T))

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

char s[4];

int main() {
    scanf("%s", s);
    int a = s[0] - '0';
    int b = s[1] - '0';
    int c = s[2] - '0';
    int d = s[3] - '0';
        
    if (a+b+c+d==7) cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
    else if (a-b+c+d==7) cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
    else if (a+b-c+d==7) cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
    else if (a+b+c-d==7) cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
    else if (a-b-c+d==7) cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
    else if (a-b+c-d==7) cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
    else if (a+b-c-d==7) cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
    else if (a-b-c-d==7) cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
    

    return 0;
}


Measured memory_bytes: 256
/* Life is all about calculated risks.
    But man am I bad at math. */

#include <iostream>
#include<vector>
#include <algorithm>
#define ll long long int
#define INF 1000000000000
#define MOD 1000000007

#define DEBUG(x) cerr<<"> "<< #x << ':' <<x<<endl;

using namespace std;

ll f(ll stone);

ll n,k;
ll h[100100];

vector<ll> dp(100100,-1);

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

    cin>>n;
  	k=2;
    for(ll i=1; i<=n; i++)
    {
        cin>>h[i];
    }

    cout<<f(n)<<endl;

    return 0;
}

ll f(ll stone)
{
    if(dp[stone] != -1)
    {
        return dp[stone];
    }
    if(stone == 1)
    {
        return dp[stone] = 0;
    }

    ll min_sum = INF;
    for(ll i=1; (i<=k) && (stone-i > 0); i++)
    {
        if(f(stone-i) + abs(h[stone] - h[stone-i]) < min_sum)
        {
            min_sum = f(stone-i) + abs(h[stone] - h[stone-i]);
        }
    }   

    return dp[stone] = min_sum;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int count=0;
    int sum=0;
    if(b==1) cout <<"0"<<endl;
    else{
    for(int i=0;i<20;i++){
        sum+=a-1;
        count++;
        if(sum>=b-1) break;
    }
    cout<<count<<endl;
    }   
}

Measured memory_bytes: 3612
S = input()
counters = []
for i in range(0, 26):
	counters.append(0)
ans = '-1 -1'
for i in range(0, len(S)-2):
	lst = [S[i], S[i+1], S[i+2]]
	lst.sort()
	if lst[0] == lst[1] or lst[1] == lst[2]:
		ans = str(i+1) + ' ' + str(i+3)
		break
if len(S) == 2:
	if S[0] == S[1]:
		ans = '1 2'
print(ans)

Measured memory_bytes: 41068
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int,int>
#define pb push_back
#define INF INT_MAX
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define iso ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
int n;
int w;
vector<pair<int,int>>v;
ll dp[100005];
int main()
{
    iso;
    cin>>n>>w;

    for(int i=1;i<=n;i++)
    {    int x,y;cin>>x>>y;
        for(int j=w-x;j>=0;j--)
        {
         dp[j+x]=max(y+dp[j],dp[j+x]);

        }
        //for(int i=0;i<=8;i++)
        //    cout<<dp[i]<<" ";
        //cout<<"\n";
    }
    cout<<dp[w];
}


Measured memory_bytes: 1024
from functools import reduce
from operator import add
n, m = [int(i) for i in input().split()]

lamp = [None] * m
for i in range(m):
    tmp = ['0'] * n
    for k in [int(j) for j in input().split()][1:]:
        tmp[n-k] = '1'
    lamp[i] = int(''.join(tmp), 2)

p = [int(i) for i in input().split()]

ans = 0
for i in range(0, 2**n):
    if all([bin(i & lamp[j]).count("1") % 2 == p[j] for j in range(m)]):
        ans += 1

print(ans)


Measured memory_bytes: 3828
<?php
$index = array();

while ($line = trim(fgets(STDIN))) {
	list($word, $page) = explode(' ', $line);
	if (isset($index[$word])) {
		$index[$word][] = $page;
	} else {
		$index[$word] = array($page);
	}
}

ksort($index, SORT_STRING);

foreach ($index as $word => $list) {
	if ($word) {
		echo "$word\n";
		sort($list);
		echo implode(' ', $list) . "\n";
	}
}

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

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

ufd=UnionFind(n)

for i in range(m):
    b , c = map(int, input().split())
    b-=1
    c-=1
    ufd.union(b,c)

ma = 0
for j in ufd.roots():
    a = ufd.size(j)
    ma=max(ma,a)
print(ma)


Measured memory_bytes: 18428
#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};
const int dh[8] = {0, 0, 1, 1, 1, -1, -1, -1};
const int dw[8] = {1, -1, 0, 1, -1, 0, 1, -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));
}
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
Graph G;
  
/*------------------------------------------------------------------*/

int main(){
    int n, x, y; cin >> n >> x >> y;
    x--, y--;

    vector<vector<int>> dis(n, vector<int>(n, -1));
    
    rep(i, n){
        queue<int> que;
        que.push(i);
        dis[i][i] = 0;
        while(!que.empty()){
            auto v = que.front(); que.pop();
            vector<int> vec;
            if(v > 0) vec.push_back(v - 1);
            if(v < n - 1) vec.push_back(v + 1);
            if(v == x) vec.push_back(y);
            if(v == y) vec.push_back(x);
            for(auto it : vec){
                if(dis[i][it] == -1){
                    dis[i][it] = dis[i][v] + 1;
                    que.push(it);
                }
            }
        }
    }
    vector<int> ans(n, 0);
    rep(i, n) _rep(j, i + 1, n) ans[dis[i][j]]++;
    _rep(i, 1, n) cout << ans[i] << endl;
}

Measured memory_bytes: 16000
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2e+3+3;
const int K = 1e+4+3;
const int L = 1e+6+5;

bool f[N][K];
int n,k;
char s[L],ans[K];
int st[N],len[N],m;
bool bz[K],qbz[K];
int nxt[L];
int tr[K];

int better(int x,int y,int i){
	int wx=x+1+tr[x+1],wy=y+1+tr[y+1];
	if (wx!=wy)return wx<wy?x:y;
	if (x<y)swap(x,y);
	int l=nxt[x-y+1];
	if (l==len[i]-(x-y))return x;
	char u=s[st[i]+l],v=s[st[i]+x-y+l];
	return u<v?x:y;
}

int main(){
	n=get();k=get();
	m=0;
	fo(i,1,n){
		scanf("%s",s+m+1);
		len[i]=strlen(s+m+1);
		st[i]=m+1;
		m+=len[i];
	}
	f[n+1][0]=1;
	fd(i,n,1){
		fo(j,0,k){
			f[i][j]=f[i+1][j];
			if (j>=len[i])f[i][j]|=f[i+1][j-len[i]];
		}
	}
	fo(i,1,k)ans[i]='z'+1;
	bz[0]=1;
	fo(i,1,n){
		int w=0,p=0;
		fo(j,2,len[i]){
			nxt[j]=0;
			if (w+p-1>=j)nxt[j]=min(nxt[j-w+1],w+p-j);
			while(j+nxt[j]<=len[i]&&s[st[i]+j+nxt[j]-1]==s[st[i]+nxt[j]])nxt[j]++;
			if (j+nxt[j]>w+p)w=j,p=nxt[j];
		}
		w=0,p=0;
		fo(j,1,k){
			tr[j]=0;
			if (w+p-1>=j)tr[j]=min(nxt[j-w+1],w+p-j);
			while(j+tr[j]<=k&&tr[j]<len[i]&&ans[j+tr[j]]==s[st[i]+tr[j]])tr[j]++;
			if (j+tr[j]>w+p)w=j,p=tr[j];
		}
		fo(j,0,k){qbz[j]=bz[j];bz[j]=0;}
		int key=-1;
		fo(j,0,k)
		if (qbz[j]&&j+len[i]<=k&&f[i+1][k-j-len[i]]){
			if (tr[j+1]<len[i]&&j+tr[j+1]+1<=k&&s[st[i]+tr[j+1]]<ans[j+tr[j+1]+1]){
				if (key==-1)key=j;
				else key=better(key,j,i);
			}
		}
		if (key!=-1){
			fo(j,tr[key+1]+1,len[i])ans[key+j]=s[st[i]+j-1];
			fo(j,key+len[i]+1,k)ans[j]='z'+1;
			fo(j,key+1+tr[key+1],k)qbz[j]=0;
		}
		w=0,p=0;
		fo(j,1,k){
			tr[j]=0;
			if (w+p-1>=j)tr[j]=min(nxt[j-w+1],w+p-j);
			while(j+tr[j]<=k&&tr[j]<len[i]&&ans[j+tr[j]]==s[st[i]+tr[j]])tr[j]++;
			if (j+tr[j]>w+p)w=j,p=tr[j];
		}
		fo(j,0,k)
		if (qbz[j]){
			if (f[i+1][k-j])bz[j]=1;
			if (tr[j+1]==len[i]&&f[i+1][k-j-len[i]])bz[j+len[i]]=1;
		}
	}
	fo(i,1,k)putchar(ans[i]);
	putchar('\n');
	return 0;
}

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

int main() {
    int e[12];
    REP(i,12){
        cin >> e[i];
    }
    sort(e,e+12);
    bool ok = true;
    REP(i,3){
        REP(j,3){
            ok &= e[i*4+j] == e[i*4+j+1];
        }
    }
    cout << (ok?"yes":"no") << endl;
    return 0;
}



Measured memory_bytes: 3144
N=int(input())
if N>9:
    if N>99:
        if N>999:
            if N>9999:
                if N>99999:
                    print(90909)
                else:
                    print(909+N-9999)
            else:
                print(909)
        else:
            print(9+N-99)
    else:
        print(9)
else:
    print(N)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B;
    cin>>A>>B;
    int count=0;
    for(int i=A;i<=B;i++){
        if(i/10000==i%10 && i/1000-i/10000*10==i/10-i/100*10)count++;
    }
    cout<<count<<endl;   
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

  long long int a, b, r, x, tmp;


  scanf("%lld", &a);

  scanf("%lld", &b);

  x = a * b;

  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  /* 最小公倍数を出力 */
  printf("%lld\n", x/b);

  return 0;
}


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

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

    ll ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        ll toadd = b[i] - ((a[i] + ans) % b[i]);
        if ((a[i] + ans) % b[i] == 0) continue;
        ans += toadd;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var gt int

type P struct {
	name    string
	time    int
	elapsed int
}

func (p *P) Exec(q int) bool {
	need := int(math.Min(float64(p.time-p.elapsed), float64(q)))
	gt += need
	p.elapsed += need
	return p.elapsed >= p.time
}

func (p *P) String() string {
	return fmt.Sprintf("%s %d", p.name, gt)
}

type Q []*P

func (q Q) isEmpty() bool {
	return len(q) == 0
}

func (q *Q) Enqueue(p *P) {
	(*q) = append((*q), p)
}

func (q *Q) Dequeue() *P {
	if q.isEmpty() {
		return nil
	}
	p := (*q)[0]
	(*q) = (*q)[1:]
	return p
}

func scan() []string {
	sc.Scan()
	return strings.Split(sc.Text(), " ")
}

func getNQ() (int, int) {
	l1 := scan()
	n, err := strconv.Atoi(l1[0])
	if err != nil {
		panic(err)
	}
	q, err := strconv.Atoi(l1[1])
	if err != nil {
		panic(err)
	}
	return n, q
}

func main() {
	n, q := getNQ()

	queue := Q(make([]*P, 0, n))
	for i := 0; i < n; i++ {
		p := scan()
		name := p[0]
		time, err := strconv.Atoi(p[1])
		if err != nil {
			panic(err)
		}
		queue.Enqueue(&P{
			name: name,
			time: time,
		})
	}

	p := queue.Dequeue()
	for p != nil {
		if p.Exec(q) {
			fmt.Println(p)
		} else {
			queue.Enqueue(p)
		}
		p = queue.Dequeue()
	}
}


Measured memory_bytes: 8084
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
//focus less on how much problem you should solve within a fixed time and focus more on getting the problem solved and
//learning something from it
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define deba(a) cout << #a << " " << a << endl;
int main()
{
	fast;
#ifndef ONLINE_JUDGE
	freopen("/home/kushagra/Desktop/Kushagra/input.txt", "r", stdin);
	freopen("/home/kushagra/Desktop/Kushagra/output.txt", "w", stdout);
#endif
	string s;
	cin >> s;
	char fl;
	if (s[0] == '0')
		fl = '1';
	else
		fl = '0';
	ll n = s.length(), ans = 0;
	rep(i, 1, n)
	{
		if (fl != s[i])
			ans++, s[i] = fl;
		if (s[i] == '0')
			fl = '1';
		else
			fl = '0';
	}
	cout << ans;
	return 0;
}

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

int main() {
    int n;
    cin>>n;
    int one=0,two=0,three=0;
    for(int i=0 ; i<n ; i++){
        int x;
        cin>>x;
        if(x==1)
        one++;
        else if(x==2)
        two++;
        else
        three++;
    }
    double dp[n+1][n+1][n+1];
    memset(dp,0,sizeof(dp));
    
    // dp[0][0][0]=1;
    for(int i=0 ; i<=three ; i++){
        for(int j=0 ; j<=three+two ; j++){
            for(int k=0 ; k<=n ; k++){
                if(i+j+k<=n && (i!=0 || j!=0 || k!=0)){
                    double p1=k/(double)n;
                    double p2=j/(double)n;
                    double p3=i/(double)n;
                    double p0=1-p1-p2-p3;
                    // cout<<k<<" "<<j<<" "<<i<<" "<<p1<<" "<<p2<<" "<<p3<<endl;
                    dp[k][j][i]+=(k-1>=0?n+k*dp[k-1][j][i]:n);
                    dp[k][j][i]+=(j-1>=0?j*dp[k+1][j-1][i]:0);
                    dp[k][j][i]+=(i-1>=0?i*dp[k][j+1][i-1]:0);
                    dp[k][j][i]/=(i+j+k);
                    // dp[k][j][i]=(1+p1*dp[k+1][j][i] + p2*dp[k-1][j+1][i] + p3*dp[k][j-1][i+1])/(1-p0);
                }
            }
        }
    }
    // cout<<dp[one][two][three]<<" "<<dp[one][two+1][three-1]<<" "<<dp[one+1][two][three-1];//<<" "<<dp[one-3][two][three]<<endl;
    printf("%.10lf",dp[one][two][three]);
    return 0;
}


Measured memory_bytes: 213248
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	int N=n,t=0;
	while(N){
		t+=N%10;
		N/=10;
	}
	if(n%t==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
 	int a,b,c;
  	cin >> a >> b >> c;
  	int ans = 1e9;
  	ans = min(ans, abs(b-a)+abs(c-b));
  	ans = min(ans, abs(c-a)+abs(b-c));
    ans = min(ans, abs(b-a)+abs(c-a));
  	ans = min(ans, abs(b-c)+abs(c-a));
  	ans = min(ans, abs(c-a)+abs(b-a));
  	ans = min(ans, abs(c-b)+abs(b-a));
 	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
//Optimizations
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
//save time
#define endl '\n'
#define db(x) cerr << "> " << #x << ": " << x << endl
typedef long long ll;
 
//for sorting
#define all(a) a.begin(),a.end()
 
//Constants
#define PI   3.141592653593
#define MOD  1000000007LL
#define EPS  0.000000001
#define INF  0X3f3f3f3f
 
//loops
#define REP(i,n) 	    for(int i=0;i<(n);++i)
#define FOR(i,a,b)      for(int i=(a);i<(b);++i)
#define DFOR(i,a,b)     for(int i=(a);i>=(b);--i)
 
//vectors
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int,int>>
#define vlll vector<pair<ll,ll>>
#define pb 	push_back
 
//pairs
#define pi pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define F first
#define S second
 
//fast I/O
#ifndef _WIN32
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define gc getchar
#define pc putchar
 
//If using cin and cout
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(NULL);cout.tie(NULL)
 
//queue
#define di deque<int>
#define dll deque<ll>
#define qi queue<int>
#define PQ priority_queue
 
//general
#define E empty()
 
//Declare all variables and methods needed between this comment and the next one(OCD lol)


const int MAXN=10e4;
const int mx = 10e5;

//int who;
int main(){
 
vi dp(3, 0);
int n ;
    cin >> n ;
    REP(day, n){
        vi ndp(3,0);
        int cost[3];
        REP(i, 3)
        cin >> cost[i];
        REP(i, 3){
            REP(j, 3){
                if(i!=j)
                ndp[i] = max(ndp[i], dp[j]+cost[i]);//, cout << ndp[] << " " << i << " " << j << endl;
            }
        }
        dp  = ndp;
    }
    cout << max({dp[0], dp[1], dp[2]});

}

Measured memory_bytes: 3604
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)


int main() {
    int n,m;
    cin >> n;
    cin >> m;
    vector<vector<int>> link(n);
    rep(i, m) {
        int k;
        cin >> k;
        rep(j, k) {
            int s;
            cin >> s;
            link[s-1].push_back(i);
        }
    }
    vector<int> p(m);
    rep(i, m) cin >> p[i];
    int c = 0;
    for (uint b = 0; ((b >> n) & 1) != 1; ++b) {
        vector<int> sum(m);
        rep(i, m) sum[i] = 0;
        for (int i = 0; i < n; ++i) {
            if (((b >> i) & 1) == 1) rep(j, link[i].size()) sum[link[i][j]]++;
        }
        rep(i, m) if (sum[i] % 2 != p[i]) goto END;
        c++;
    END:
        continue;
    }
    cout << c << endl;
    return 0;
}



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

int top;
int bottle[150];

void push(int u)
{
	top++;
	bottle[top] = u;
}

int pop(){

    top=top-1;
	
	return bottle[top+1];
	
}

int main(void){
    int a,b;
	top=0;
	int result;
	char box[150];
    while( scanf("%s",box) != EOF){
    	
		if(box[0]=='+'){
		a=pop();
		b=pop();
		result = a+b;
		push(result);	
		}
		else if(box[0]=='-'){
	    a=pop();
		b=pop();
		result= b-a;
		push(result);	
		}
		
	    else if(box[0] == '*'){
		a=pop();
		b=pop();
		result=b*a;
		push(result);
		}
		else{
			
	    	push(atoi(box));
		}
	}
	printf("%d\n", pop());



return 0;
}



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

int main() {
    string s,t;
    cin>>s>>t;
    int cnt=0;
    rep(i,3){
        if(s[i]==t[i]) cnt++;
    }
    cout<<cnt<<endl;
}


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

int main() {
    int a, b, c; cin >> a >> b >> c;
    int d, e, f; cin >> d >> e >> f;
    int g, h, i; cin >> g >> h >> i;
    int x1 = 0, x2, x3, y1, y2, y3;
    y1 = a - x1, y2 = b - x1, y3 = c - x1;
    x1 = a - y1, x2 = d - y1, x3 = g - y1;
    bool ok = e == x2 + y2 && f == x2 + y3 && h == x3 + y2 && i == x3 + y3;
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i,l,r) for(int i=l;i<=r;i++)
signed main()
{   //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string x,y;
    cin>>x>>y;
    int n=x.size();
    int m=y.size();

    int lcs[n+1][m+1];


    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(i==0 || j==0)
                lcs[i][j]=0;
            else if(x[i-1]==y[j-1])
                lcs[i][j]=lcs[i-1][j-1]+1;
            else lcs[i][j]=max(lcs[i][j-1],lcs[i-1][j]);
        }
    }

    string ans;
   int len = lcs[n][m];

   while(ans.length()<len)
   {
      if(x[n-1]==y[m-1])
      {ans.push_back(x[n-1]);
        n--;
        m--;
      }
      else if(lcs[n-1][m]>lcs[n][m-1])
        {n--;}
       else m--;
   }

   reverse(ans.begin(),ans.end());
   cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll rt<<1
#define rr rt<<1|1
#define PI acos(-1)
#define MM int m=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) ((x+mo_num)%mo_num)
#define vc vector
#define vct vector<int>
#define fa(i,V) for(auto i:V)
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
//#define P pair<int,int>
using namespace std;
const int INF=LLONG_MAX;
const int maxn=1e6+5;
const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn];
double ans;
int32_t main()
{
    IOS
    cin>>n;
    fun(i) {
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    fu(i,1,n)
    {
       if(i==1){
           ans=a[i];
       }else{
           ans=(double)(ans+a[i])/(double)2;
       }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2304
/*
** Vishal Raj Roy
** Indian Institute of Technology Kharagpur
*/

#include <bits/stdc++.h>

using namespace std;

#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define gcd(X,Y) __gcd(X,Y)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define ifpresent(CON,VAL) (CON.find(VAL) != CON.end())
#define all(x) x.begin(),x.end()
#define at(X,N) get<N>(X)
#define ins insert
#define xx first
#define yy second
#define sz(x) ((int)x.size())
#define count_ones __builtin_popcountl
#define nl cout<<"\n";
#define name(X) (#X)
#define watch(X) cout << (#X) << " is " << (X) << "\n"
#define sqr(x) ((x)*(x))
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mem(x,val) memset((x),(val),sizeof(x))
#define rite(X) freopen(X,"w",stdout)
#define read(X) freopen(X,"r",stdin)
//FOR(i,1,10) gives 1,2,3,....,9 and FOR(i,10,1) gives 9,8,....,1 also FOR(it, end(v), begin(v)) and FOR(it, begin(v), end(v))
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define SEL(X,C) for( auto & X : C )
#define ima INT_MAX
#define imi INT_MIN
#define lma LLONG_MAX
#define lmi LLONG_MIN
using st = string; typedef long long int li; typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef tuple<int,int> i2; typedef tuple<int,int,int> i3; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<i2> vi2; typedef vector<i3> vi3; typedef vector<iii> viii; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef pair<li, li> ll; typedef pair<li, ll> lll; typedef tuple<li,li> l2; typedef tuple<li,li,li> l3; typedef vector<li> vl; typedef vector<ll> vll; typedef vector<l2> vl2; typedef vector<l3> vl3; typedef vector<lll> vlll; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef double db; typedef complex<db> cd; typedef vector<cd> vcd; template <class S> using ve = vector<S>; template <class S> using gr = greater<S>; template <class S> using le = less<S>;

const double pi = 2 * acos(0.0);
const int oo = 0x3f3f3f3f; // don't use for long long
const double inf = 1.0/0.0;

int MinimumNumIncreasingSubsequences( vi & A ) {
    int n = sz(A);
	int lis = 0; int L[n];
	for( int i = n-1; i >= 0; i-- ) {
		int pos = upper_bound(L,L+lis,A[i])-L;
		L[pos] = A[i];
		lis = max(lis,pos+1);
	} return lis;
}

int main() {
    ios_base::sync_with_stdio(0);
    // read("rr.txt");
    int n; cin>>n; vi v(n,0); FOR(i,0,n) cin>>v[i]; cout<<MinimumNumIncreasingSubsequences(v)<<"\n";
    return 0;
}


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

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

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

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

vector<vector<P>> g(1010);
vector<bool> visited(1010);
vector<bool> visited2(1010);
vector<int> cost(1010);
priority_queue<P> que;

void dfs(int cv, int depth){
    visited[cv] = true;

    bool haveChild = false;

    for(auto nv : g[cv]){
        int nnv = nv.first;
        if(!visited[nnv]){
            haveChild = true;
            dfs(nnv, depth + 1);
        }
    }

    if(!haveChild){
        que.push(P(depth, cv));
        //cout << cv << " " << depth << endl;
    }
}

int main(){
    int n; cin>>n;
    vector<int> c(n-1);
    for(int i=0; i<n-1; i++) cin>>c[i];
    for(int i=0; i<n-1; i++){
        int u, v, p; cin>>u>>v>>p;
        g[u].eb(P(v, p));
        g[v].eb(P(u, p));
    }

    dfs(0, 0);

    int ans=0;

    while(que.size()){
        int cv, depth;
        tie(depth, cv) = que.top();
        que.pop();

        
        if(visited2[cv]) continue;
        visited2[cv] = true;

        //cout << cv << " " << depth << " " << cost[cv] << endl;

        for(auto i : g[cv]){
            int nv = i.first;
            int dist = i.second;

            if(!visited2[nv]){
                if(c[cv-1] == 0){
                    //cout << dist << " " << cost[cv] << endl; 
                    cost[nv] += min(dist, cost[cv]);
                    que.push(P(depth-1, nv));
                }
                else{
                    cost[nv] += dist;
                    que.push(P(depth-1, nv));
                }
            }
        }
    }

    cout << cost[0] << endl;
}


Measured memory_bytes: 3176
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int a[2222];
ll cnt[2222];

int main(void){
	int n,i,j;
	ll k,ans=0ll,tmp=0ll;
	cin >> n >> k;
	for(i=0; i<n; ++i){
		cin >> a[i];
		tmp = 0ll;
		for(j=a[i]; j<2000; ++j){
			tmp += cnt[j];
		}
		mul_mod(tmp,k);
		add_mod(ans,tmp);
		--a[i];
		++cnt[a[i]];
	}
	mul_mod(k,k-1);
	mul_mod(k,(MOD+1)/2);
	for(i=0; i<n; ++i){
		tmp = 0ll;
		for(j=0; j<a[i]; ++j){
			tmp += cnt[j];
		}
		mul_mod(tmp,k);
		add_mod(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}


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

struct Tree{
  int num;
  Tree* lhs;
  Tree* rhs;
};

int get_val(string& s,int& i){
  int res=0;
  while(isdigit(s[i])){
    res*=10;
    res+=s[i]-'0';
    i++;
  }
  return res;
}

Tree* build_tree(string&s ,int &i){

  assert(0<=i && i<s.size());
  if(s[i]==')'){
    return nullptr;
  }
  i++;
  Tree* lef=build_tree(s,i);
  assert(s[i]==')');
  i++;
  assert(s[i]=='[');
  i++;
  int val=get_val(s,i);

  assert(s[i]==']');
  i++;//]
  assert(s[i]=='(');
  i++;//(
  Tree* rig=build_tree(s,i);
  assert(s[i]==')');
  i++;
  Tree* res=new Tree();

  res->num=val;

  res->lhs=lef;
  res->rhs=rig;
  return res;
}

Tree* sum(Tree* a_tree,Tree* b_tree){
  if(a_tree==nullptr||b_tree==nullptr){
    return nullptr;
  }

  Tree* res=new Tree();
  res->num=(a_tree->num)+(b_tree->num);
  res->lhs=sum(a_tree->lhs,b_tree->lhs);
  res->rhs=sum(a_tree->rhs,b_tree->rhs);
  return res;
}

string code(Tree* tree){
  if(tree==nullptr){
    return "";
  }
  string res="(";
  res+=code(tree->lhs);
  res+=")";
  res+="[";
  res+=to_string((tree->num));
  res+="]";
  res+="(";
  res+=code(tree->rhs);
  res+=")";
  return res;
}

int main(){
  string a,b;
  cin>>a>>b;
  int i=0;
  Tree* a_tree=build_tree(a,i);
  i=0;
  Tree* b_tree=build_tree(b,i);
  Tree* c_tree=sum(a_tree,b_tree);
  string res=code(c_tree);
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3280
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

    int N;
    cin >> N;

    vector<int> x(N);
    vector<int> y(N);
    vector<int> h(N);
    REP(i, N) cin >> x[i] >> y[i] >> h[i];

    int ansx = -1;
    int ansy = -1;
    int H = -1;
    REP(cx, 101) {
        REP(cy, 101) {
            H = -1;
            REP(i, N) {
                if (h[i] == 0) continue;

                int th = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
                if (th < 1) {
                    H = -1;
                    break;
                }

                if (H != -1 && th != H) {
                    H = -1;
                    break;
                }
                H = th;
            }
            if (H < 1) continue;
            REP(i, N) {
                if (h[i] > 0) continue;
                int th = H - abs(x[i] - cx) - abs(y[i] - cy);
                if (th > 0) {
                    H = -1;
                    break;
                }
            }
            if (H < 1) continue;

            ansx = cx;
            ansy = cy;
            break;
        }
        if (H >= 1) {
            break;
        }
    }
    cout << ansx << " " << ansy << " " << H << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
count = dict(Counter(A))

if len(count) > 3:
    print("No")
    exit(0)
if N%3 == 0 and len(count) == 3:
    a, b, c = list(count.keys())
    la, lb, lc = list(count.values())
    if a ^ b == c and b ^ c == a and c ^ a == b and la == lb and lb == lc:
        print("Yes")
    else:
        print("No")
elif N%3 == 0 and len(count) == 2:
    a, b = list(count.keys())
    la, lb = list(count.values())
    if (a == 0 and la*2 == lb) or (b == 0 and lb*2 == la):
        print("Yes")
    else:
        print("No")
elif len(count)==1 and list(count.keys())[0] == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 16928
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

  int n;
  cin >> n;

  cout << ("ABC" + to_string(n)) << endl;

  return 0;
}


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

using namespace std;

int n,c,b,tot;
int p[10],q[10],v[10],a[10];

inline void dfs(int dep){
	if(dep==n){
		tot++;
		int flag1=1,flag2=1;
		for(int i=1;i<=n;i++){
			if(a[i]!=p[i]) flag1=0;
			if(a[i]!=q[i]) flag2=0;
		}
		if(flag1) c=tot;
		if(flag2) b=tot;
		return;
	}
	for(int i=1;i<=n;i++){
		if(v[i]) continue;
		v[i]=1;
		a[dep+1]=i;
		dfs(dep+1);
		v[i]=0;
	}
}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>p[i];
	for(int i=1;i<=n;i++) cin>>q[i];
	dfs(0);
	cout<<abs(c-b)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}

int main(){
fastio();



    int n,k;
    cin>>n>>k;
    int arr[n];

    for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n);

    int sum=0;
    for(int i=0;i<k;i++) sum+=arr[i];
    cout<<sum<<endl;









return 0;
}



Measured memory_bytes: 3660
//******************************************************************************
// File Name: C.cpp
// Author: Shili_Xu
// E-Mail: shili_xu@qq.com
// Created Time: Sat 29 Sep 2018 08:03:59 PM CST
//******************************************************************************

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int MAXN = 1e5 + 5;

int n;
int aa[MAXN], a[MAXN], v[MAXN];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
    int ans = 0x3f3f3f3f, x = 0, y = 0, p = 0, q = 0;
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i += 2) a[v[i]]++;
    for (int i = 1; i <= 1e5; i++)
        if (a[i] > a[x]) {
            y = x;
            x = i;
        }
        else{
            if (a[i] > a[y]) y = i;
        }
    memset(aa, 0, sizeof(aa));
    for (int i = 2; i <= n; i += 2) aa[v[i]]++;
    for (int i = 1; i <= 1e5; i++)
        if (aa[i] > aa[p]) {
            q = p;
            p = i;
        }
        else {
            if (aa[i] > aa[q]) q = i;
        }
    if (x != p) ans = min(ans, n / 2 - a[x] + n / 2 - aa[p]);
    if (x != q) ans = min(ans, n / 2 - a[x] + n / 2 - aa[q]);
    if (y != p) ans = min(ans, n / 2 - a[y] + n / 2 - aa[p]);
    if (y != q) ans = min(ans, n / 2 - a[y] + n / 2 - aa[q]);
    if (ans == 0x3f3f3f3f) ans = min(n / 2 - a[x], n / 2 - aa[p]);
    printf("%d\n", ans);
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod(long long a, long long b) { return (a%b+b)%b; }
long long gcd(long long x, long long y) { return __gcd(x, y); }
long long lcm(long long x, long long y) { return x * 1ll * y / gcd(x, y); }
 
 
const long long MAXN = 1e9 + 9;
const long long SIZE = 2e5 + 5;
const long long MOD = 1e9 + 7;


int res = 1001;
string s, t;

int main() { speedhack()

	cin >> s >> t;
	
	int N = s.size() - t.size();

	for (int i = 0; i <= N; i++) {
		int cur = 0;
		for (int j = 0; j < t.size(); j++)
			if (s[i + j] != t[j])
				++cur;
		res = min (res, cur);
	}
	
	cout << res;

	return 0;
}

Measured memory_bytes: 3608
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
#include <math.h>
#include <numeric>
#include <stack>
#include <map>
using namespace std;

const int N_MAX = 100001;
int N;
int H[N_MAX];
int min_tmp;
bool flag = true;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	min_tmp = H[0];
	for (int i = 1; i < N; i++) {
		if (H[i - 1] > H[i]) {
			flag = false;
			break;
		}
		else if (H[i - 1] == H[i]) {
			min_tmp = H[i - 1];
		}
		else if (H[i - 1] < H[i]) {
			H[i] -= 1;
			min_tmp = H[i];
		}
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
string s;
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>s;
    ll n=s.size();
    string t=s;
    bool ans=s==t&&s.substr(0,(n-1)/2)==t.substr((n+1)/2);
    cout<<(ans?"Yes":"No")<<"\n";
}


Measured memory_bytes: 256