akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

vector<P> g[100000];
int ans[100000];

void dfs(int v, int p, int c) {
  ans[v] = c;
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i].first;
    int cost = g[v][i].second;
    if (to == p) continue;
    if (cost % 2 == 0) {
      dfs(to, v, c);
    } else {
      dfs(to, v, c ^ 1);
    }
  }
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    g[u].push_back(P(v, w));
    g[v].push_back(P(u, w));
  }
  dfs(0, -1, 0);
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 11392
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

int main(){
  int h, w, n;
  cin >> h >> w >> n;
  vector<pair<int, int>>xy;
  vector<int>dl(max(h, w), 10000000); //x-yがキー、禁止xの下限
  for(int i=0; i<n; i++){
    int x, y;
    cin >> x >> y;
    if(x>=y)xy.push_back(make_pair(x, y));
  }
  sort(xy.begin(), xy.end());
  int nowl=0; //今の所OKなx-yの下限
  for(int i=0; i<xy.size(); i++){
    if(xy[i].first-xy[i].second==nowl){
      dl[nowl]=xy[i].first;
      nowl++;
    }
  }
  int ret=0;
  for(pair<int, int>p: xy){
    int x=p.first, y=p.second;
    if(x-y>0 && dl[x-y-1]>=x){
      ret=x-1;
      break;
    }
  }
  if(ret==0)ret=h;
  cout << ret;
  return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[]={0,1,3,1,2,1,2,1,1,2,1,2,1};
  int x,y;
  cin >> x >> y;
  string ans;
  if(a[x]==a[y]){
    ans="Yes";
  }
  else{
    ans="No";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin>>N;
  vector<int>A(N),B(N,0),C;
  REP(i,N)cin>>A[i];
  for(int i=N;i>0;i--){
    int sum=0;
    for(int j=i;j<=N;j+=i){
      sum+=B[j-1];
    }
    if(A[i-1]%2!=sum%2){
      B[i-1]=1;
    }
  }
  C.reserve(N);
  int M=0;
  for(int i=0;i<N;i++){
    if(B[i]==1){
      C.push_back(i+1);
      M++;
    }
  }
  cout<<M<<endl;
  if(M!=0){
    for(int i=0;i<M-1;i++){
      cout<<C[i]<<' ';
    }
    cout<<C[M-1]<<endl;
  }
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

int n,m,k[35],a[35][35],v[35],ans;

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m;
    fort (i,n)
    {
        cin >> k[i];
        fort (j,k[i])
        {
            cin >> a[i][j];
            ++v[a[i][j]];
        }
    }
    fort (i,m)
        if (v[i]==n) ++ans;
    cout << ans;
}


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

using ll = long long;

int gcd(int x, int y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (C % gcd(A, B) == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

ll maxVacation(ll arr[][4], ll day, ll flag, ll n, ll dp[][4]){

    if(day == n){
        return 0;
    }

    if(dp[day][flag] != -1)
        return dp[day][flag];

    ll  maxi = INT_MIN;
    if(flag == 0){
        maxi = max(maxi, arr[day][1] + maxVacation(arr, day+1, 1, n, dp));
        maxi = max(maxi, arr[day][2] + maxVacation(arr, day+1, 2, n, dp));
        maxi = max(maxi, arr[day][3] + maxVacation(arr, day+1, 3, n, dp));
    }
    else if(flag == 1){
        maxi = max(maxi, arr[day][2] + maxVacation(arr, day+1, 2, n, dp));
        maxi = max(maxi, arr[day][3] + maxVacation(arr, day+1, 3, n, dp));
    }
    else if(flag == 2){
        maxi = max(maxi, arr[day][1] + maxVacation(arr, day+1, 1, n, dp));
        maxi = max(maxi, arr[day][3] + maxVacation(arr, day+1, 3, n, dp));
    }
    else{
        maxi = max(maxi, arr[day][1] + maxVacation(arr, day+1, 1, n, dp));
        maxi = max(maxi, arr[day][2] + maxVacation(arr, day+1, 2, n, dp));
    }
    return dp[day][flag] = maxi;
}

int main() {

    ll n;
    cin >> n;
    ll arr[n][4] = {0};
    ll dp[n][4];
    memset(dp, -1, sizeof dp);
    for(ll i=0; i<n; i++){
        for(ll j=1; j<=3; j++)
            cin >> arr[i][j];
    }

    cout << maxVacation(arr, 0, 0, n, dp) << endl;

    return 0;
}


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

#define rep(i, N) for(int (i) = 0; (i) < (N); i++)
#define all(v) v.begin(), v.end()
using i64 = int_fast64_t;

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if(A + B + C > 21) cout << "bust" << endl;
    else cout << "win" << endl;
}

Measured memory_bytes: 764
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        k: i64
    }
    // println!("{}", k);

    // aから順番に使っていくだけ
    let mut res = 0;
    let mut unuse_k = k;

    // k <= a の場合
    if  k <= a {
        res = k;
        println!("{}", res);
        return;
    }

    // k <= a + b の場合

    // aの点数を足す
    res += a;
    unuse_k -= a;

    // 残り使える枚数がbの方が多い時
    if unuse_k <= b {
        println!("{}", res);
        return;
    }

    // k <= a + b + c の場合

    unuse_k -= b;

    if unuse_k <= c {
        res -= unuse_k;
        println!("{}", res);
        return;
    }

    res -= c;
    println!("{}", res);

    // kの場合分けしたほうがわかりやすかった気がする
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

void solve(int n,vector<P> J){
    ll time=0;
    rep(i,n)
    {
    time+=J[i].second;
    if(time>J[i].first){
        cout<<"No"<<endl;
        return ;
    }

}
   cout<<"Yes"<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);

int n;
cin>>n;

vector<P>J(n);

rep(i,n){
    ll a,b;
    cin>>a>>b;
    J[i]=make_pair(b,a);
}
sort(J.begin(),J.end());
solve(n,J);
return 0;
}

Measured memory_bytes: 6528
h,w,k=map(int,input().split())

y1,x1,y2,x2=map(int,input().split())

maze=[list(input()) for _ in range(h)]

from collections import deque
stack=deque([(y1-1,x1-1)])

before=[[0]*w for _ in range(h)]
dic={}
dic[0]=0
dic[(0,1)]=(0,-1)
dic[(0,-1)]=(0,1)
dic[(1,0)]=(-1,0)
dic[(-1,0)]=(1,0)

maze[y1-1][x1-1]=0
#pri(maze)
while len(stack)>0:
    #print(stack)
    (y,x)=stack.popleft()
    if (y,x)==(y2-1,x2-1):
        print(maze[y][x])
        exit()

    #縦横左右
    for (my,mx) in ((1,0),(0,1),(-1,0),(0,-1)):
        #print(my,mx)
        flag=0
        if (my,mx)!=dic[before[y][x]]:
            for kk in range(1,k+1):
                ny=y+my*kk
                nx=x+mx*kk
                if 0<=ny<h and 0<=nx<w:
                    if maze[ny][nx]!="@":
                        if maze[ny][nx]==".":
                            maze[ny][nx]=maze[y][x]+1
                            stack.append((ny,nx))
                            before[ny][nx]=((my,mx))
                        if maze[ny][nx]==maze[y][x]+1:
                            continue
                        else:
                            break
                    else:
                        break
                else:
                    break
    #pri(maze)
print(-1)


Measured memory_bytes: 224692
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#define INF 1000000000
using namespace std;
typedef long long ll;

int D[1010], C[1010];
ll dp[1010][1010];

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

	for (int i = 0; i < N; i++)
		cin >> D[i];
	for (int i = 0; i < M; i++)
		cin >> C[i];

	fill(dp[0], dp[1010], INF);
	dp[0][0] = 0;
	for (int i = 0; i < M; i++) {
		for (int j = 0; j <= N; j++) {
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + D[j] * C[i]);
		}
	}

	cout << dp[M][N] << endl;
	return 0;
}

Measured memory_bytes: 11052
n, k = map(int, input().split())
s = input()

counts = []
tmp = []
for i in range(len(s)):
    if tmp == []:
        tmp = [s[i], 1]
    else:
        if tmp[0] == s[i]:
            tmp[1] += 1
        else:
            counts.append(tmp)
            tmp = [s[i], 1]
if tmp:
    counts.append(tmp)

zero_ints = 0
for char, count in counts:
    if char == '0':
        zero_ints += 1

if counts[0][0] == '0':
    left = 0
else:
    left = 1
right = left - 2

used = 0
l = 0
for char, count in counts:
    if char == '0':
        if used < k:
            used += 1
            right += 2
        else:
            break
    l += count

ans = l
for i in range(zero_ints):
    l = l - counts[left][1]
    if left - 1 >= 0:
        l-= counts[left - 1][1]
    if right + 2 < len(counts):
        l += counts[right + 2][1]
    if right + 3 < len(counts):
        l += counts[right + 3][1]
    ans = max(ans, l)
    left += 2
    right += 2
    # print(left, right, l)
print(ans)


Measured memory_bytes: 59888
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ll a,b,c,d,e,f,g;
	cin >> a>> b>> c>> d>> e>> f >> g;
    
    ll s=min({a,d,e});
    a-=s;
    d-=s;
    e-=s;
    int k = a%2+d%2+e%2;
    if(s==0)k=0;
    int ma = max(k-1,0);
    ll ans=3*s+(a/2)*2+b+(d/2)*2+(e/2)*2+ma;
    cout << ans << endl;
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()
print(' '.join(map(str, A)))
#insertionSort(A, N):
for i in range(1, N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = v
    print(' '.join(map(str, A)))


Measured memory_bytes: 6804
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      	int K = sc.nextInt();
      	int s = 0;
      	for(int i = 0; i < N; i++){
        	int x = sc.nextInt();
        	s += x < K - x ? x * 2 : (K - x) * 2;
        }
		System.out.println(s);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> c(n,-1);
    int ans = 0;
    rep(i,m){
        int s,k;
        cin >> s >> k;
        s--;
        if(c[s]==-1) c[s] = k;
        else{
            if(c[s]==k) continue;
            else{
                ans = -1;
            }
        }
    }
    if(ans == -1){
        cout << ans << endl;
        return 0;
    }
    rep(i,n){
        if(c[i]==-1 && i==0) ans += 1*pow(10,n-1-i);
        if(c[i]==-1) continue;
        else{
            ans += c[i]*pow(10,n-1-i);
        }
    }
    if(m==0 && n==1){
        cout << 0 << endl;
        return 0;
    }
    if(c[0]==0 && n!=1){
        ans = -1;
    }
    cout << ans << endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

int main() {
    ll X, K, D;
    cin >> X >> K >> D;

    X = abs(X);
    // while (abs(X) >= D && K > 0) {
    //     X -= D;
    //     K--;
    // }
    ll q = X / D;
    q = min(q, K);
    K -= q;
    X -= D * q;

    if (K == 0) {
        cout << abs(X) << endl;
    } else if (K % 2 == 0) {
        cout << abs(X) << endl;
    } else {
        cout << min(abs(X - D), abs(X + D)) << endl;
    }

    return 0;
}


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

using ll = long long;
using ld = long double;
using vl = vector<ll>;
using ml = map<ll,ll>;

#define ff first
#define ss second
#define endl '\n'
#define ins insert
#define eb emplace_back
#define sz(c) (ll) c.size()
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define itr(x,c) for(auto &x : c)
#define tc ll t; cin >> t; while (t--)
#define rep(i,a,n) for(ll i = a ; i < n ; ++i)
#define per(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) itr(x,c) cout << x << " "; cout << endl;
#define dm(m) itr(x,m) cout << x.f << "->" << x.s << endl;
#define godspeed cin.tie(0) -> sync_with_stdio(0);

int main() {
    godspeed;
    ll a, b, c, d; cin >> a >> b >> c >> d;
    
    while(true) {
    	c -= b;
    	a -= d;

    	if(c <= 0) {cout << "Yes"; return 0;}
    	if(a <= 0) {cout << "No"; return 0;}
    }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
string s, t;
vector<int> al[26];
int nw = -1;
long long cnt;
int main(){
	cin >> s >> t;
	rep(i,s.size()) al[s[i]-'a'].push_back(i);
	for(char c: t){
		int a = c - 'a';
		if(al[a].size() == 0) return 0*puts("-1");
		auto it = upper_bound(al[a].begin(), al[a].end(), nw);
		if(it == al[a].end()){
			it = al[a].begin();
			cnt++;
		}
		nw = *it;
	}
	printf("%lld\n", cnt * s.size() + nw + 1);
}

Measured memory_bytes: 1216
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int max_ai = 100000;


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

  vector<int> v(max_ai, 0);
  rep(i, n) {
    v[a[i]]++;
    if (a[i] + 1 < max_ai) {
      v[a[i] + 1]++;
    }
    if (a[i] - 1 >= 0) {
      v[a[i] - 1]++;
    }
  }

  int ans = 0;
  rep(i, max_ai) {
    ans = max(ans, v[i]);
  }

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

Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define FOR(i,a,b) for(register int i=(a);i<(b);++i)
#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
#define pi pair<int,int>
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 305;
const int maxm = 200005;
const int inf = 2147483647;
typedef long long ll;
const double eps = 1e-9;
const long long INF = 9223372036854775807ll;
ll qpow(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c;b>>=1;}return ans;}
int n,m,l,g[maxn][maxn];
ll d[maxn][maxn];
void floyd(){
	FOR(k,1,n+1)
	FOR(i,1,n+1)
	FOR(j,1,n+1){
		if(d[i][j]>d[i][k]+d[k][j]){
			d[i][j]=d[i][k]+d[k][j];
		}
		if(d[i][j]<=l)g[i][j]=1;
	}
	FOR(k,1,n+1)
	FOR(i,1,n+1)
	FOR(j,1,n+1)if(g[i][j]>g[i][k]+g[k][j])g[i][j]=g[i][k]+g[k][j];
}
int main(){
	scanf("%d%d%d",&n,&m,&l);
	FOR(i,1,n+1)
	FOR(j,1,n+1)if(i!=j)d[i][j]=INF/4,g[i][j]=inf/4;
	while(m--){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		if(c>l)continue;
		d[a][b]=d[b][a]=min(d[a][b],(ll)c);
	}
	floyd();
	int q;
	scanf("%d",&q);
	while(q--){
		int s,t;
		scanf("%d%d",&s,&t);
		if(g[s][t]==inf/4)printf("-1\n");else printf("%d\n",g[s][t]-1);
	}
}
/*
2 1 4
1 2 5
100
*/

Measured memory_bytes: 4892
str=input()
ls=len(str)
Str=[str[i] for i in range(ls)]
q=int(input())
i=0
while i<q:
    Com=input().split()
    command=Com[0]
    a=int(Com[1])
    b=int(Com[2])
    l=len(Com)
    if l>3:
        rep=Com[3]
        Rep=[rep[i] for i in range(b+1-a)]

    if command=="print":
        print("".join(Str[a:b+1]))
    if command=="reverse":
        temp=Str[a:b+1]
        #bは含まない...b=lのときどうすんのさこれ
        #print(temp)
#In Python, strings are not mutable, which means they cannot be changed.
#You can, however, replace the whole variable with the new version of the string.
        for j in range(b+1-a):
            Str[a+j]=temp[b-a-j]
        #print("".join(Str))

    if command=="replace":
        #print(rep)
        for j in range(b+1-a):
            Str[a+j]=Rep[j]
        #print("".join(Str))
    i+=1



Measured memory_bytes: 5644
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
const int mod=998244353,g=3,invg=998244354/3;
using namespace std;
int a[1200005],n,S,tr[1200005],wk[1200005],ans=0,jc[1200005]={1},ny[1200005]={1},t[1200005],t2[1200005];
int C(int x,int y){
  if(x<y)return 0;
	return 1ll*jc[x]*ny[y]%mod*ny[x-y]%mod;
}
int Power(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		y>>=1,x=1ll*x*x%mod;
	}
	return ret;
}
int jj(int x){
	return 1ll*jc[x]*ny[x/2]%mod*Power(ny[2],x/2)%mod;
}
void GetTr(int l) {
	for(int i=0; i<l; i++)tr[i]=(tr[i>>1]>>1)|((i&1)?(l>>1):0);
}
void NTT(int a[],int n,int flag) {
	for(int i=0; i<n; i++)if(tr[i]<i)swap(a[i],a[tr[i]]);
	for(int i=1; i<n; i<<=1) {
		int w=Power(flag==1?g:invg,(mod-1)/(i<<1));
		wk[0]=1;
		for(int j=1; j<i; j++)wk[j]=1ll*wk[j-1]*w%mod;
		for(int j=0; j<n; j+=(i<<1)) {
			for(int k=0; k<i; k++) {
				int t=1ll*wk[k]*a[i+j+k]%mod;
				a[i+j+k]=(a[j+k]-t+mod)%mod;
				a[j+k]=(a[j+k]+t)%mod;
			}
		}
	}
	if(flag==-1)for(int i=0,t=Power(n,mod-2); i<n; i++)a[i]=1ll*a[i]*t%mod;
}
vector<int> Solve(int l,int r) {
	if(l==r){
		vector<int> ret;
		ret.resize(a[l]/2+1);
		ret[0]=1;
		for(int i=1;i<=a[l]/2;i++)ret[i]=1ll*C(a[l],i*2)*jj(i*2)%mod;
		return ret;
	}
	int mid=(l+r)/2;
	vector<int> a=Solve(l,mid);
	vector<int> b=Solve(mid+1,r);
	int len=1;
	while(len<a.size()+b.size())len<<=1;
	GetTr(len);
	for(int i=0;i<len;i++)t[i]=t2[i]=0;
	for(int i=0;i<a.size();i++)t[i]=a[i];
	for(int i=0;i<b.size();i++)t2[i]=b[i];
	NTT(t,len,1),NTT(t2,len,1);
	for(int i=0;i<len;i++)t[i]=1ll*t[i]*t2[i]%mod;
	NTT(t,len,-1);
	a.resize(len);
	for(int i=0;i<len;i++)a[i]=t[i];
    while(!a.back())a.pop_back();
	return a;
}
int main() {
	scanf("%d",&n);
	int mx=0;
	for(int i=1,x;i<=n*2;i++)scanf("%d",&x),a[x]++,mx=max(mx,x);
	for(int i=1;i<=200000;i++)jc[i]=1ll*jc[i-1]*i%mod;
	ny[200000]=Power(jc[200000],mod-2);
	for(int i=199999;i;i--)ny[i]=1ll*ny[i+1]*(i+1)%mod;
	vector<int> res=Solve(1,mx);
	ans=jj(2*n);
	for(int i=1,o=mod-1;i<res.size()&&i<=n;i++,o=mod-o)ans=(ans+1ll*o*res[i]%mod*jj(2*n-2*i))%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7060
s=list(input())
K=int(input())
alp=["a","b","c","d","e","f","g",
"h","i","j","k","l","m","n",
"o","p","q","r","s","t","u",
"v","w","x","y","z"]

for i in range(len(s)):
    n=alp.index(s[i])
    if n!=0 and n+K>=26:
        s[i]="a"
        K-=26-n
    if i==len(s)-1 and K>0:
        n=alp.index(s[i])
        s[i]=alp[(n+K)%26]

for j in s:
    print(j,end="")
print()

Measured memory_bytes: 9856
#include <algorithm>
#include <string>
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
	int n, m, l, a[100][100], b[100][100]; 
	long long int c[100][100] = {};
	cin >> n >> m >> l; 
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++) {
			cin >> b[i][j];
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < l; k++) {
				c[i][k] += a[i][j] * b[j][k];
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			if (j > 0) cout << " ";
			cout << c[i][j];
		}
		cout << "\n";
	}
}



Measured memory_bytes: 3236
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	int x,y,cost;
};
int n;
vector<ll> a,b,c;
ll total=0;
ll d[100001]={};
int main(){

	cin>>n;
	rep(i,n){
		int a2;
		cin>>a2;
		a.push_back(a2);
	}
	rep(i,n){
		int a2;
		cin>>a2;
		b.push_back(a2);
	}
	rep(i,n){
		int a2;
		cin>>a2;
		c.push_back(a2);
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());

	rep(i,n){
		d[i]=lower_bound(a.begin(),a.end(),b[i])-a.begin();
		d[i]+=d[i-1];
	}
	rep(i,n){
		ll A=lower_bound(b.begin(),b.end(),c[i])-b.begin();
		total+=d[A-1];
	}
	cout<<total<<endl;
	return 0;

}




Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL fast(int a,int b,int p)
{
    long long a1=a,t=1;
    while(b>0)
    {
        if(b&1)
            t=(t%p)*(a1%p)%p;
        a1=(a1%p)*(a1%p)%p;
        b/=2;
    }
    return int(t%p);
}
LL n,m,p=1000000007;
LL quick_mod(LL a, LL b)
{
    LL ans = 1;
    a %= p;
    while(b)
    {
        if(b & 1)
        {
            ans = ans * a % p;
            b--;
        }
        b >>= 1;
        a = a * a % p;
    }
    return ans;
}
LL C(LL n, LL m)
{
    if(m > n) return 0;
    LL ans = 1;
    for(int i=1; i<=m; i++)
    {
        LL a = (n + i - m) % p;
        LL b = i % p;
        ans = ans * (a * quick_mod(b, p-2) % p) % p;
    }
    return ans;
}
LL Lucas(LL n, LL m)
{
    if(m == 0) return 1;
    return C(n % p, m % p) * Lucas(n / p, m / p) % p;
}
int main()
{
    int a,b,n;
    if(n==2&&a==1&b==2)
    {
        printf("0");
        return 0;
    }
    LL na,nb,mi,sum;
    cin>>n>>a>>b;
    mi=fast(2,n,p);
    na=Lucas(n,a);
    nb=Lucas(n,b);
    sum=( mi%p+p- ( na+ ( nb +1 )%p )%p)%p;
    printf("%lld",sum);
}


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

int minimumcostsort(int A[],int n){
    pair<int,int> B[n];
    int globalmin=A[0],Check[n]={0}
    ,D[n],sum=0,localsum,localmin,lnum;
    for(int i=0;i<n;i++){
        B[i].second=i;
        B[i].first=A[i];
        globalmin=min(globalmin,A[i]);
    }
    sort(B,B+n);
    for(int i=0;i<n;i++)D[B[i].second]=i;
    for(int i=0;i<n;i++){
        if(Check[i]==0){
            localmin=A[i];
            lnum=1;
            localsum=A[i];
            Check[i]=1;
            int j=D[i];
            while(j!=i){
                localmin=min(localmin,A[j]);
                localsum+=A[j];
                lnum++;
                Check[j]=1;
                j=D[j];
            }
            sum+=min(localsum+(lnum-2)*localmin,localsum+(lnum+1)*globalmin+localmin);
        }
    }
    return sum;
}

int main(){
    int n;cin>>n;
    int A[n];
    for(int i=0;i<n;i++)scanf("%d",&A[i]);
    cout<<minimumcostsort(A,n)<<endl;
}



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

int a[101];
int n;
int go(int m) {
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cnt += (m - a[i]) *(m - a[i]);
	}
	return cnt;
}
int main() {
	// 코틀린 ,문자열 알고리즘 보기, 앳코더, (시간되면 코드포스까지)
	ios_base::sync_with_stdio(false); cin.tie(NULL); //9 90 900 
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	int l = a[0];
	int r = a[n - 1];
	while (l <= r) {
		int m = (l + r) / 2; 
		int cnt = go(m);
		if (cnt > go(m - 1)) {
			r = m - 1;
		}
		else {
			l = m + 1;
		}
	}

	cout << go(r) << '\n';



}

Measured memory_bytes: 256
n, q = [ int( val ) for val in input( ).split( " " ) ]
ps = [0]*n
t = [0]*n
for i in range( n ):
	ps[i], t[i] = input( ).split( " " )


output = []
qsum = 0
while t:
	psi = ps.pop( 0 )
	ti = int( t.pop( 0 ) )
	if ti <= q:
		qsum += ti	
		output.append( psi+" "+str( qsum ) )
	else:
		t.append( ti - q )
		ps.append( psi )
		qsum += q

print( "\n".join( output ) )

Measured memory_bytes: 17580
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;

int main()
{

    int k,n;
    cin>>k>>n;
    int a[n];
    int i;
    for(i=0;i<n;i++)
        cin>>a[i];
    int big=k-a[n-1]+a[0];
    for(i=1;i<n;i++)
        big=big>(a[i]-a[i-1])?big:(a[i]-a[i-1]);
    cout<<k-big<<endl;
    return 0;
}

Measured memory_bytes: 1024
#n = int(input())
import math
n,d = map(int,input().split())
#a_L = list(map(int,input().split()))
count = 0
for i in range(n):
    x,y = map(int,input().split())
    dis = math.sqrt(x**2+y**2)
    if dis <=d:
        count += 1

print(count)


Measured memory_bytes: 9176
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

ll N,K;
ll table[SIZE];

int main(){

	scanf("%lld %lld",&N,&K);
	for(int i = 0; i < SIZE; i++){

		table[i] = 0;
	}

	ll a,b;
	for(ll i = 0; i < N; i++){

		scanf("%lld %lld",&a,&b);
		table[a] += b;
	}

	ll sum = 0;
	for(int i = 0; i < SIZE; i++){
		if(table[i] == 0)continue;

		sum += table[i];
		if(sum >= K){

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

	return 0;
}


Measured memory_bytes: 4616
from itertools import permutations as p
N=int(input())
l=list(p(range(1,N+1)))

A=tuple(map(int, input().split()))
B=tuple(map(int, input().split()))

fa=True
fb=True
for i in range(len(l)):
  if l[i]==A and fa:
    idx_a=i
    fa=False
  if l[i]==B and fb:
    idx_b=i
    fb=False
  if (not fa) and (not fb):
    break
print(abs(idx_a-idx_b))
  


Measured memory_bytes: 8052
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//




int main() {

    int N; cin >> N;
    int ans = 0;
    for (int a = 1; a <= N; ++a) {
        ans += N / a;
        if (N%a == 0) --ans;
    }

    out(ans);


    return 0;
}





Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

ll mod=1e9+7;

//繰り返し二乗法
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b&1)res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}

struct perm{
private:
    int sz;
    vector<ll> p,invp;
public:
    perm(int n){
        sz=n+1;
        p.resize(sz),invp.resize(sz);
        p[0]=1;
        for(int i=1;i<=sz-1;i++){
            p[i]=p[i-1]*i%mod;
        }
        invp[sz-1]=power(p[sz-1],mod-2);
        for(int i=sz-2;i>=0;i--){
            invp[i]=invp[i+1]*(i+1)%mod;
        }
    }
    ll comb(ll x,ll y){
        if(x<y||y<0)return 0;
        return (p[x]*invp[x-y]%mod)*invp[y]%mod;
    }
};
perm p(1<<20);

int main(){
    ll n,m,k; cin >> n >> m >> k;
    ll ans=0;
    for(int i=1;i<=n-1;i++){
        ll cnt=m*m%mod*(n-i)%mod;
        ll add=cnt*i%mod*p.comb(n*m-2,k-2)%mod;
        (ans+=add)%=mod;
    }
    swap(n,m);
    for(int i=1;i<=n-1;i++){
        ll cnt=m*m%mod*(n-i)%mod;
        ll add=cnt*i%mod*p.comb(n*m-2,k-2)%mod;
        (ans+=add)%=mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 16640
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////




int main() {

	ll N, M, Q;
	cin >> N >> M >> Q;

	ll L[MAX], R[MAX];
	repn(i, M) cin >> L[i] >> R[i];

	ll t[600][600] = {};
	repn(i, M) t[L[i]][R[i]]++;

	ll sum[600][600] = {};
	repn(i, N)repn(j, N) sum[i][j] = sum[i][j - 1] + t[i][j];

	repn(k, Q) {

		ll p, q;
		cin >> p >> q;

		ll ans = 0;
		for (ll i = p; i <= q; i++) {
			ans += sum[i][q];
		}

		cout << ans<<endl;
	}

	
	system("PAUSE");
}

Measured memory_bytes: 13816
#include<bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define vpi vector<pii>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)
#define modd 998244353
#define umap unordered_map<ll,ll>
#define mmap map<ll,ll>
#define mm 100000000


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


    
    ll t;
    t=1;
    // cin>>t;
    while(t--){
      string s;
      cin>>s;

      ll sum=0;

      fori(0,s.size()){
        ll n = s[i]-'0';
        sum += n;
        sum%=9;
      }

      if(sum==0)cout<<"Yes";
      else cout<<"No";


      
  
    }





return 0;
}     



Measured memory_bytes: 3704
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mp make_pair
  #define pb push_back
  #define inf INT_MAX
  #define f first
  #define s second
  #define all(v) v.begin(), v.end()
  #define mod INT_MAX 
  //direction arrays
  int dx[8]={0,0,-1,+1,+1,-1,+1,-1};
  int dy[8]={+1,-1,0,0,+1,-1,-1,+1};
  
  int32_t main()
  { 
    /*#ifndef ONLINE_JUDGE
       freopen("in.txt","r",stdin);
       freopen("out.txt","w",stdout);
    #endif*/
    
    IOS
    int n,k;
    cin>>n>>k;
    vector<bool> v(n+1,false);
    for(int i=1;i<=k;i++)
    {
      int d;
      cin>>d;
      for(int i=1;i<=d;i++)
      {
        int x;
        cin>>x;
        if(!v[x]) v[x]=true;
      }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
      if(!v[i])
        ans++;
    }
   cout<<ans;
    return 0;
  }
    

Measured memory_bytes: 3656
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto N = RD;
	auto L = RDA;

	L.sort!"a > b";
	long ans;
	foreach (i; 0..N)
	{
		foreach (j; i+1..N)
		{
			if (L[i] == L[j]) continue;
			foreach (k; j+1..N)
			{
				if (L[j] == L[k]) continue;
				if (L[j]+L[k] > L[i])
					++ans;
			}
		}
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}

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

int main()
{ 
  int x1, y1, x2, y2 ;
  cin >> x1 >> y1 >> x2 >> y2 ;

  int x = x2 - x1 ;
  int y = y2 - y1 ;

  cout << x2 - y << " " << y2 + x << " " <<  x1 - y << " " << y1 + x << endl ;
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int,input().split()))


hanntei = 0 

for i in range(N):
    ch1 = A[i] % 2
    ch2 = A[i] % 3
    ch3 = A[i] % 5
    if ch1 == 0 and ch2 != 0 and ch3 != 0:
        hanntei = 1
        break

if hanntei == 1:
    print("DENIED")
else:
    print("APPROVED")

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


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(Math.min(a * n, b));
    }

}

Measured memory_bytes: 23764
using System;
class Program {
    static void Main (string[] args) {
        long N = long.Parse (Console.ReadLine ());
        string[] input = Console.ReadLine ().Split (' ');
        long[] array = new long[N];
        long[] numHash = new long[N];

        for (long i = 0; i < N; i++) {
            array[i] = long.Parse (input[i]);
            numHash[array[i] - 1]++;
        }

        long numSameAll = 0;
        for (long i = 0; i < N; i++) {
            numSameAll += (numHash[i] * (numHash[i] - 1) / 2);
        }

        for (long i = 0; i < N; i++) {
            Console.WriteLine (numSameAll - numHash[array[i] - 1] + 1);
        }
    }
}

Measured memory_bytes: 33484
import sys
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    if a[i]%2 == 1:
        continue
    else:
        if a[i]%3 != 0 and a[i]%5 != 0:
            print("DENIED")
            sys.exit()
print("APPROVED")

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int cur=0,mx=0;
    for(int i=0;i<n;i++){
        if(s.at(i) == 'I') cur++;
        else cur--;
        mx = max(cur, mx);
    }
    cout << mx << endl;
}

Measured memory_bytes: 256
using System;

namespace ABC070B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            var c = int.Parse(input[2]);
            var d = int.Parse(input[3]);

            var begin = Math.Max(a, c);
            var end = Math.Min(b, d);
            var answer = begin < end ? end - begin : 0;
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 27156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

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

    int N, M;
    cin >> N >> M;

    string s(N,'a');

    rep(i,M){
        int t;
        char c;
        cin >> t >> c;
        --t;
        if(s[t] == 'a' || s[t] == c ){
            s[t] = c;
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    
    if(s[0] == '0' && N > 1){
        cout << -1 << endl;
        return 0;
    }

    rep(i,N){
        if(s[i] == 'a'){
            if(i || N == 1){
                s[i] = '0';
            }else{
                s[i] = '1';
            }
        }
    }

    cout << s << endl;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto abc = readln.split.to!(long[]);
    auto A = abc[0];
    auto B = abc[1];
    auto C = abc[2];

    int r;
    foreach (_; 0..1000) {
        if (A%2 == 1 || B%2 == 1 || C%2 == 1) {
            writeln(r);
            return;
        }
        ++r;
        auto a = (B+C)/2;
        auto b = (A+C)/2;
        auto c = (A+B)/2;
        A = a;
        B = b;
        C = c;
    }
    writeln(-1);
}

Measured memory_bytes: 256
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!(iter, $($r)*)
    };
}

use std::collections::HashSet;

fn main() {
  input! {
    n: usize,
  }
  let x = n % 10;
  let hon: HashSet<usize> = [2,4,5,7,9].iter().cloned().collect();
  let pon: HashSet<usize> = [0,1,6,8].iter().cloned().collect();
  let bon: HashSet<usize> = [3].iter().cloned().collect();
  if hon.contains(&x) { println!("hon"); }
  if pon.contains(&x) { println!("pon"); }
  if bon.contains(&x) { println!("bon"); }
}



Measured memory_bytes: 2184
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

ll modpow(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y & 1)ans *= x;
		x *= x;
		ans %= MOD;
		x %= MOD;
		y /= 2;
	}
	return ans;
}

ll res[100010];

int main() {
	int N, K;
	cin >> N >> K;
	ll ans = 0, cnt;
	for (int i = 0;i < 100010;i++)res[i] = 0;
	for (ll i = K;i >= 1;i--) {
		cnt = modpow(K / i, N);
		for (int j = i;j <= K;j += i) {
			cnt -= res[j];
			if (cnt < 0)cnt += MOD;
		}
		res[i] = cnt;
		ans += cnt * i;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4412
#include <iostream>
#include <algorithm>
using namespace std;
int c[100050],d[100050];
int gcd(int a,int b) {
    return (b==0?a:gcd(b,a%b));
}
int main() {
    int n,x;
    cin >> n >> x;
    for (int i=0;i<n;i++) cin >> c[i];
    c[n] = x;
    sort (c,c+n+1);
    for (int i=1;i<=n;i++) {
        d[i-1] = c[i]-c[i-1];
    }
    int g;
    for (int i=0;i<n;i++) {
        if (i==0) g = d[i];
        else g = gcd(g,d[i]);
    }
    cout << g << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

void solve() {
  int h, w;
  cin >> h >> w;
  vstr board(h);
  rep(i, h) cin >> board[i];

  queue<pair<int, int>> q;
  vector<vi32> dist(h, vi32(w, 1e9));
  rep(i, h) rep(j, w) {
    if (board[i][j] == '#') {
      q.emplace(i, j);
      dist[i][j] = 0;
    }
  }
  int ans = 0;
  while (q.size()) {
    int x, y;
    tie(x, y) = q.front(); q.pop();
    rep(i, 4) {
      int fx = x + dx[i];
      int fy = y + dy[i];
      if (fx < 0 || fx >= h || fy < 0 || fy >= w) continue;
      if (dist[fx][fy] != 1e9) continue;
      q.emplace(fx, fy);
      dist[fx][fy] = dist[x][y] + 1;
      amax(ans, dist[fx][fy]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 13584
#include <bits/stdc++.h>
using namespace std;
#define sz int(1e5+1)
int main()
{
    string s1, s2;

    cin>>s1>>s2;
    s1='0'+s1;
    s2='0'+s2;
    int n=s1.size(), m=s2.size();
    
    vector < vector<int> > dp(n+1,vector<int>(m+1,0));

    for(int i=1;i<n;i++){
        for(int j=1;j<m;j++){
            if(s1[i]==s2[j]){
                dp[i][j]=1+dp[i-1][j-1];
            }else{
                dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
            }
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    int y=n-1,x=m-1;
    string s = "";
    while(dp[y][x]){
        int mxx = max(dp[y-1][x-1], max(dp[y-1][x], dp[y][x-1]));
        if(mxx!=dp[y][x]){
            s=s1[y]+s;
            y--, x--;
        }else{
            if(dp[y-1][x]==dp[y][x])
                y--;
            else if (dp[y-1][x-1]==dp[y][x]){
                y--, x--;
            }else{
                x--;
            }
        }
    }

    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 35584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

int main(){
    int n, k;
    ll ans = 0;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];

    sort(h.begin(), h.end());
    rep(i,n-k) ans += h[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024