akhauriyash/Code-Regression huggingface dataset:
//Be Name Khoda
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma optimize O3
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
#define RETD(x) { cout << fixed << setprecision(15) << x; exit(0); }
const ll M=2e5+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;

ll n;
vll g[M];

ll dfs(ll x,ll p)
{
    ll res=0;
    for (ll y:g[x])
    {
        if (y==p) continue;
            res^=dfs(y,x)+1;
    }
    return res;
}

int main()
{
	ios::sync_with_stdio(0);
    cin >> n;
    For(i,1,n)
    {
        ll x,y;
        cin >> x >> y;
        x--;
        y--;
        g[x].PB(y);
        g[y].PB(x);
    }
    if (dfs(0,0)) RET("Alice");
    RET("Bob");      	
} 

Measured memory_bytes: 12800
#include <iostream>
#include <utility>
#include <stdint.h>
#include <cmath>

using namespace std;

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

  int X[N][D];
  
  for (int n=0; n<N; ++n) {
    for (int d=0; d<D; ++d) {
      cin >> X[n][d];
    }
  }

  unsigned count=0;
  
  for (int ii=0; ii<N; ++ii) {
    for (int jj=0; jj<ii; ++jj) {
      uint64_t sum = 0;
      for (int d=0; d<D; ++d) {
	int diff = X[ii][d]-X[jj][d];
	sum += diff*diff;
      }
      double sq = sqrt(sum);
      if (sq == (int)sq)
	++count;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
import fractions
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n,x = MAP()

def cal(a,b):
    if a > b:
        aa = a
        a = b
        b = aa
    ref = b//a
    if b%a == 0:
        return a*(2*ref-1)
    return a*2*ref + cal(b%a,a)

print(n + cal(x,n-x))

Measured memory_bytes: 63980
n = int(input())
x = range(n)
dp = [0 for i in x]
h = list(map(int,input().split()))

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,n):
  dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]) , dp[i-2] + abs(h[i-2] - h[i]))
print(dp[n-1])

Measured memory_bytes: 15032
// g++ -std=c++11 -O2 -Wall -Wl,--stack=268435456

#include <bits/stdc++.h>
using namespace std;

typedef long long          ll;
typedef vector<int>        vi;
typedef vector< vi >       vvi;
typedef pair<int, int>     pi;
typedef vector< pi >       vpi;

#define LARGE_INT     1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = (int)(a); i < (int)(b); i++)

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



int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int  n, k;
    cin >> n >> k;
    vi a(n), dp(k+1,0);
    REP(j, 0, n) { cin >> a[j]; }
    REP(i, 0, k+1) {
        if (dp[i] == 0) {
            REP(j, 0, n) {
                if (i+a[j] <= k)   dp[i+a[j]] = 1;
            }
        }
    }
    if (dp[k] == 1)  cout << "First";
    else             cout << "Second";
    return 0;
}

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

int main() {
	double a=0.0, b=0.0, minsum=2000000.0, sum=-1000.0;
	double cnt = 0.0;
	while(scanf("%lf",&a)!= EOF){
	 sum=max(sum,a);
	 minsum=min(minsum,a);
	 }
	printf("%.5f", sum-minsum);
}

Measured memory_bytes: 3204
#include <stdio.h>
#include <math.h>
int main(void)
{
    int n, flag = 1;
    unsigned long long a, mul = 1;
    unsigned long long ulimit = pow(10.0, 18.0);
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%llu", &a);
        if (a == 0) {
            mul = 0;
            flag = 2;
            break;
        }
        if (mul > (ulimit / a)) {
            flag = -1;
        }
        mul *= a;
    }

    if (flag == 0)          printf("0");
    else if (flag == -1)    printf("-1");
    else                    printf("%llu", mul);
    return 0;
}

Measured memory_bytes: 1732
use proconio::input;

fn main() {
    input! {
        p: (i32, i32, i32),
    };
    let d = p.0;
    let t = p.1;
    let s = p.2;
    if d <= t * s {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2136
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
    std.typecons, std.math, std.container, std.format, std.numeric;

class SegTree
{
private:
    long[] xs;
    long size;
public:
    this(long size)
    {
        long i = 1;
        while (i <= size)
        {
            i *= 2;
        }
        this.size = size;
        this.xs = new long[](i * 2);
    }

    void add(long i, long x)
    {
        i += this.size;
        xs[i] += x;
        while (true)
        {
            i /= 2;
            if (i == 0)
            {
                break;
            }
            xs[i] = xs[i * 2] + xs[i * 2 + 1];
        }
    }

    long getSum(long l, long r)
    {
        l += this.size;
        r += this.size;

        long ans = 0;
        while (l < r)
        {
            if (l % 2 == 1)
            {
                ans += xs[l];
                l++;
            }
            l /= 2;
            if (r % 2 == 1)
            {
                ans += xs[r - 1];
                r--;
            }
            r /= 2;
        }
        return ans;
    }
}

void main(string[] args)
{
    long n, q, com, x, y;
    readf("%d %d\n", &n, &q);

    auto seg = new SegTree(n);
    foreach (_; 0 .. q)
    {
        readf("%d %d %d\n", &com, &x, &y);
        if (com == 0)
        {
            seg.add(x, y);
        }
        if (com == 1)
        {
            writeln(seg.getSum(x, y + 1));
        }
    }

}



Measured memory_bytes: 4236
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = 10**10
dp = [INF]*N
dp[0] = 0
for i in range(N):
    for j in range(1, K+1):
        if i+j < N:
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
print(dp[N-1])


Measured memory_bytes: 52448
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
    
    string s;
    cin>>s;

    int n = s.length();

    for(int i=0;i<n;i++){
        if(i&1){
            if(s[i] == 'R') {
                cout<<"No";
                return 0;
            }
        }
        else{
            if(s[i] == 'L'){
                cout<<"No";
                return 0;
            }
        }
    }

    cout<<"Yes";
} 

Measured memory_bytes: 256
n = int(input())
prices = []
max_idx = 0
max_price  =0
for i in range(n):
    price = int(input())
    prices.append(int(price))
    if max_price <= price:
        max_price = price
        max_idx = i

prices[max_idx] = prices[max_idx]/2
print(int(sum(prices)))


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
struct data{
	int x,y;
}a[210001];
struct edge{
	int a,b,v;
}g[410001];
ll ans;
int tot,f[210001],i,j,k,n,m,p[210001];
int getfa(int x){
	return (f[x])?f[x]=getfa(f[x]):x;
}
bool merge(int x,int y){
	int i=getfa(x),j=getfa(y);
	if (i==j) return 0;
	f[j]=i;
	return 1;
}
bool cmpx(int x,int y){
	return a[x].x<a[y].x;
}
bool cmpy(int x,int y){
	return a[x].y<a[y].y;
}
bool cmpg(edge x,edge y){
	return x.v<y.v;
}
int main(){
	scanf("%d",&n);memset(f,0,sizeof(f));
	for (i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y),p[i]=i;
	sort(p+1,p+1+n,cmpx);
	for (tot=0,i=1;i<n;i++) g[++tot].a=p[i],g[tot].b=p[i+1],g[tot].v=a[p[i+1]].x-a[p[i]].x;
	sort(p+1,p+1+n,cmpy);
	for (i=1;i<n;i++) g[++tot].a=p[i],g[tot].b=p[i+1],g[tot].v=a[p[i+1]].y-a[p[i]].y;
	sort(g+1,g+1+tot,cmpg);
	for (i=1,k=ans=0;k<n-1;i++){
		if (merge(g[i].a,g[i].b)) k++,ans+=g[i].v;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4608
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n;
	vector<int>a, b, c;
	int l[201] = { 0 };
	cin >> n;
	for (int i = 0; i < n; i++){
		int d, e, f;
		cin >> d >> e >> f;
		a.push_back(d);
		b.push_back(e);
		c.push_back(f);
	}
	for (int i = 0; i < n; i++){
		bool b = true;
		for (int j = 0; j < n; j++) {
			if (j == i)goto a;
			if (a[i] == a[j])b = false;
		a:;
		}
		if (b)l[i] += a[i];
	}
	for (int i = 0; i < n; i++) {
		bool bo = true;
		for (int j = 0; j < n; j++) {
			if (j == i)goto B;
			if (b[i] == b[j])bo = false;
		B:;
		}
		if (bo)l[i] += b[i];
	}
	for (int i = 0; i < n; i++) {
		bool b = true;
		for (int j = 0; j < n; j++) {
			if (j == i)goto C;
			if (c[i] == c[j])b = false;
		C:;
		}
		if (b)l[i] += c[i];
	}
	for (int i = 0; i < n; i++){
		cout << l[i] << endl;
	}
	char cc;
	cin >> cc;
}

Measured memory_bytes: 3132
(N, K), As = readlines.map{_1.split.map(&:to_i)}

cs = Array.new(N + 1, 0)
i, x, y = 1, [], []
until cs[i] == 2
  (cs[i].zero? ? x : y) << i
  cs[i] += 1
  i = As[i - 1]
end
puts K < x.size ? x[K] : y[(K - x.size)%(y.size)]

Measured memory_bytes: 31812
import bisect
n = int(input())
A = [int(input()) for i in range(n)]
# n = 5
# A = [5, 1, 3, 2, 4]
L = [A[0]]
for i in range(n):
    if A[i] > L[-1]:
        L.append(A[i])
    else:
        j = bisect.bisect_left(L, A[i])
        L[j] = A[i]
print(len(L))



Measured memory_bytes: 10352
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

struct UnionFind{
  vector<int> d;
  UnionFind(int n) : d(n, -1){}
  int find(int x){
    if(d.at(x) < 0) return x;
    return d.at(x) = find(d.at(x));
  }
  bool unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return false;
    if(d.at(x) > d.at(y)) swap(x, y);
    d.at(x) += d.at(y);
    d.at(y)= x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d.at(find(x)); }
};

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(snip_i, h) cin >> s.at(snip_i);
  UnionFind uf(h*w);
  int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
  rep(i, h){
    rep(j, w){
      rep(k, 4){
        int ni = i + dy[k], nj = j + dx[k];
        if(nj < 0 || w <= nj || ni < 0 || h <= ni) continue;
        if(s.at(i).at(j) != s.at(ni).at(nj)) uf.unite(i*w+j, ni*w+nj);
      }
    }
  }
  ll ans = 0;
  vector<pair<int, int>> vp(h*w, make_pair(0, 0));
  rep(i, h){
    rep(j, w){
      int r = uf.find(i*w+j);
      if(r < 0) r = i*w+j;
      if(s.at(i).at(j) == '#') vp.at(r).first++;
      else vp.at(r).second++;
    }
  }
  rep(i, vp.size()){
    // cerr << vp.at(i).first << " " << vp.at(i).second << endl;
    ans += (ll)vp.at(i).first * vp.at(i).second;
  }
  cout << ans << endl;
  return 0;
}

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

int n;
string s,t;

int main()
{
	scanf("%d",&n);
	cin >> s >> t;
	for(int i=n;i >= 0;i--)
		if(s.substr(n-i) == t.substr(0,i))
		{	
			printf("%d\n",2*n-i);
			return 0;
		}
}

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

int     main() {
        int M, D;
        cin >>M >>D;
        int S=0;
        for (int m=1; m<=M; m++)
                for (int d=1; d<=D; d++) {
                        int d1=d %10;
                        int d10=d/10;
                        if (d1<2) continue;
                        if (d10<2) continue;
                        if (m==d1*d10)
                                S++;
                }
        cout <<S <<endl;
        return 0;
};

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ if(a>b) a=b;}

struct Bitree {
	typedef ll btT;
	vector<btT> bv;
	Bitree(int n) : bv(n + 3) {}
	btT sum(int i) {
		btT res=0; for(i++; i>0; i -= i & -i) res += bv[i]; return res;
	}
	btT sum(int a, int b) {return sum(b) - (a? sum(a-1): 0);}
	void add(int i, btT x){for(i++; i<(int)bv.size(); i += i & -i) bv[i] += x; }
	void updt(int i, btT x){ add(i, x - sum(i,i));} //replace, update
	//void dsp(){for(auto x:bv) cout<<x<<" ";puts("");}
};

int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll d, a;
	cin >>n >>d >>a;
	vector<VL> x(n, VL(2));
	rep(i, n) cin >>x[i][0] >>x[i][1];
	
	VL xx;
	rep(i, n) xx.push_back(x[i][0]);
	xx.push_back(0); xx.push_back(1LL<<55);
	sort(all(xx));
	xx.erase(unique(all(xx)), xx.end());
	
	VL hs(sz(xx)+2);
	Bitree qq(sz(xx)+2);
	rep(i, n){
		int zx = lower_bound(all(xx), x[i][0]) -xx.begin();
		hs[zx] += x[i][1];
	}
	
	//for(auto x :xx) cerr<<x<<" "; cerr<<"\n";
	ll ans =0;
	rep(i, sz(hs)){
		ll zms = qq.sum(0, i) * a;
		//dbg(i, hs[i], zms);
		if(hs[i] - zms <=0) continue;
		ll su = (hs[i] -zms  + a -1) /a;
		ans += su;
		int ps = lower_bound(all(xx), xx[i]+2LL*d+1) - xx.begin();
		qq.add(i, su);
		qq.add(ps, -su);
		//dbg(i,ps,"vV");
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 15988
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));

		String[] strs = reader.readLine().split(" ");
		int[] nums = new int[strs.length];
		int top = 0;
		for (int i = 0; i < strs.length; i++) {
			switch (strs[i].charAt(0)) {
			case '+':
				top--;
				nums[top-1] = nums[top - 1] + nums[top];
				break;
			case '-':
				top--;
				nums[top-1] = nums[top - 1] - nums[top];
				break;
			case '*':
				top--;
				nums[top-1] = nums[top - 1] * nums[top];
				break;
			default:
				
				nums[top] = Integer.parseInt(strs[i]);
				top++;
				break;
			}
			/*System.out.println(Arrays.toString(nums));*/
		}
		System.out.println(nums[0]);

	}
}

Measured memory_bytes: 17060
#include <bits/stdc++.h>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    int n,l;
    string s[110];
    cin >> n >> l;
    for(int i=0; i<n; i++) cin >> s[i];
    sort(s,s+n);
    for(int i=0; i<n; i++) cout << s[i];
    cout << endl;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc127/tasks/abc127_c
//愚直にやるとO(NM)で死ぬ 先に正解範囲を作ればO(N+M)
#include <bits/stdc++.h>
using namespace std;

int N, M;
vector<int> L, R;

int main() {
    scanf("%d %d", &N, &M);
    L.resize(M); R.resize(M);
    for (int i = 0; i < M; i++) {
        int left, right;
        scanf("%d %d", &left, &right);
        L[i] = left - 1; R[i] = right - 1;
    }

    int ansL = 0, ansR = N-1;
    for (int i = 0; i < M; i++) {
        ansL = max(ansL, L[i]);
        ansR = min(ansR, R[i]);
    }
    int count = 0;
    for (int i = 0; i < N; i++) if (ansL <= i && i <= ansR) count++;
    printf("%d\n", count);
    return 0;

}

Measured memory_bytes: 1024
from bisect import bisect_left

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

inf = 10**11
s = [-inf]+[int(input()) for i in range(a)]+[inf,inf]
t = [-inf]+[int(input()) for i in range(b)]+[inf,inf]
X = [int(input()) for i in range(q)]

for x in X:
	s_idx = bisect_left(s,x)
	t_idx = bisect_left(t,x)
	sr = s[s_idx]
	sl = s[s_idx-1]
	tr = t[t_idx]
	tl = t[t_idx-1]
	# print(s_idx,t_idx)
	ans1 = max(sr-x,tr-x)
	ans2 = max(x-sl,x-tl)
	ans3 = (x-sl)*2+(tr-x)
	ans4 = (tr-x)*2+(x-sl)
	ans5 = (x-tl)*2+(sr-x)
	ans6 = (sr-x)*2+(x-tl)
	# print(ans1,ans2,ans3,ans4,ans5,ans6)
	print(min(ans1,ans2,ans3,ans4,ans5,ans6))

Measured memory_bytes: 127448
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int n = cin.nextInt();
			int m = cin.nextInt();
			if(n+m==0){
				break;
			}
			ArrayList<Integer> list = new ArrayList<Integer>();
			boolean[] is = new boolean[n];
			for(int i = 0; i < n;i++){
				is[i]=true;
				list.add(i);
			}
			int now = n-1;
			int count=0;
			while(true){
				int cnt=0;
				while(true){
					if(is[(now+1)%n]){
						now = (now+1)%n;
						cnt++;
					}
					else{
						now = (now+1)%n;
					}
					if(cnt==m){
						break;
					}
				}
				is[now]=false;
				count++;
				if(count==n-1){
					break;
				}
			}
			for(int i = 0; i < n;i++){
				if(is[i]){
					System.out.println(i+1);
					break;
				}
			}
		}
	}

}

Measured memory_bytes: 12000
#include <stdio.h>
int main()
{
	int n,i,t;
	scanf("%d",&n);
	int num[n];
	for(i=0;i<n;i++)
	scanf("%d",&num[i]);
	int min=num[0],di=-2000000000;
	for(i=1;i<n;i++)
	{
		if((num[i]-min)>di)
		{
			di=num[i]-min;
		}
		if(num[i]<min)
		{
			min=num[i];
		}
		
	}
	printf("%d\n",di);
	return 0;
}

Measured memory_bytes: 1376
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

class UnionFind:
    __slots__ = ['id','sz']

    def __init__(self, n):
        self.id = [-1] * n
        self.sz = n

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

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

    def union(self, x, y):
        s1, s2 = self.root(x), self.root(y)
        if s1 != s2:
            if self.id[s1] <= self.id[s2]:
                self.id[s1] += self.id[s2]
                self.id[s2] = s1
            else:
                self.id[s2] += self.id[s1]
                self.id[s1] = s2
            self.sz-=1
            return True
        return False


n,m=map(int,input().split())
uf=UnionFind(n)
for i in range(m):
    x,y,z=map(int,input().split())
    uf.union(x-1,y-1)
print(uf.sz)

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

int main()
{
  int n;
  cin >> n;
  
  vector<int> c(n);
  for (int i = 0; i < n; i ++)
    cin >> c.at(i);
  
  sort(c.begin(), c.end(), greater<>{});
  
  int a = 0;
  int b = 0;
  for (int i = 0; i < n; i ++)
  {
    if (i % 2 == 0) a += c.at(i);
    else b += c.at(i);
  }
  
  cout << a - b;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索，次にDP
// 偶奇，逆から，ソート，出現回数，出現位置，DP
// 余事象，包除
// データ構造
// 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

int64_t N, x; cin >> N >> x;
VI a(N); rep(i, 0, N) cin >> a[i];

int64_t ans = 0;
rep(i, 0, N -1){
    if (a[i] > x){
        ans += a[i] - x;
        a[i] = x;
    }
    if (a[i] + a[i + 1] > x){
        int64_t d = x - a[i];
        ans += a[i + 1] - d;
        a[i + 1] = d;
    }
}

cout << ans <<  "\n";
}

// 境界，出力文字列 チェック



Measured memory_bytes: 1024
'use strict'

function main(input) {
  input = input
    .trim()
    .split('\n')
    .map(v => v.split(' ').map(Number))

    const n = input[0][0]
    const k = input[0][1]
    const sticks = input[1].sort((a,b)=>b-a)
    
    const ans = sticks.slice(0, k).reduce((a,b)=>a+b)
    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
//
//  Created by Henry Cafaro
//  Copyright © 2020 Henry Cafaro. All rights reserved.
//

# include <iostream>
# include <string>
# include <vector>
# include <algorithm>
# include <bitset>
# include <queue>
# include <cstring>
# include <map>
# include <set>


#define ll long long

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int t;
    int ct = 0;
    for(int i = 1; i < n+1; i++){
        cin >> t;
        ct += ((t%2)&&(i%2));
    }
    cout << ct << endl;
        
   
    
    
    
    
    
    
    
    
    
    
}


Measured memory_bytes: 3608
import math
a, b, c = map(float, input().split(' '))
c = c / 180 * math.pi
s = a * b * math.sin(c) / 2
l = a + b + pow((pow(a, 2) + pow(b, 2) - 2 * a * b * math.cos(c)), 0.5)
h = b * math.sin(c)
print('{0:.8f}'.format(s) + '\n' + '{0:.8f}'.format(l) + '\n' + '{0:.8f}'.format(h))


Measured memory_bytes: 5708
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

int n,m,q,from,to;
int rank[100000],parent[100000];

int find(int x){
	if(x == parent[x])return x;
	else{
		return parent[x] = find(parent[x]);
	}
}

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

void unite(int x,int y){
	x = find(x);
	y = find(y);

	if(x == y)return;

	if(rank[x] < rank[y]){
		parent[x] = y;
	}else{
		parent[y] = x;
		if(rank[x] == rank[y])rank[x]++;
	}
}

int main(){

	scanf("%d %d",&n,&m);

	for(int i = 0; i < n; i++){
		rank[i] = 0;
		parent[i] = i;
	}

	for(int i = 0; i < m; i++){
		scanf("%d %d",&from,&to);

		if(isSame(from,to))continue;
		unite(from,to);
	}

	scanf("%d",&q);

	int left,right;

	for(int i = 0; i < q; i++){
		scanf("%d %d",&left,&right);

		if(isSame(left,right))printf("yes\n");
		else{
			printf("no\n");
		}
	}
	return 0;
}



Measured memory_bytes: 3296
#include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            #define pi 3.14159265358979323846
            #define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                lli i,j,t,k,n,m,f,g,q;
                lli a,b,c;
                cin>>a>>b>>c;
                t=0;
                for(i=min(a,b);i>0;i--){
                    if(a%i==0&&b%i==0){
                        t++;
                        if(t==c){
                            cout<<i<<endl;
                            return 0;
                        }
                    }
                }

                return 0;

            }



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
int main() {
  int64_t n;
  cin>>n;
  if(n>1){
 cout<<((n-1)*n)/2;
  }
  else{
    cout<<0;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int N, T, A[3333], B[3333], dp[3333][3333][2];


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::cin >> N >> T;

  for (int i = 0; i < N; i ++)
    std::cin >> A[i] >> B[i];

  memset(dp, -1, sizeof(dp));

  dp[0][0][0] = 0;

  for (int i = 0; i < N; i ++)
    for (int j = 0; j < 3333; j ++)
      for (int k = 0; k < 2; k ++) {
        if (dp[i][j][k] < 0)
          continue;

        dp[i + 1][j][k] = std::max(dp[i][j][k], dp[i + 1][j][k]);	// skip

        if (k == 0) {
          if (j + A[i] < T)
            dp[i + 1][j + A[i]][0] = std::max(dp[i][j][0] + B[i], dp[i + 1][j][0]);

          dp[i + 1][j][1] = std::max(dp[i][j][0] + B[i], dp[i + 1][j][1]);
        }
        else {
          if (j + A[i] < T)
            dp[i + 1][j + A[i]][k] = std::max(dp[i][j][k] + B[i], dp[i + 1][j][k]);
        }
      }

  int sp = 0;

  for (int i = 0; i < 3333; i ++)
    for (int j = 0; j < 3333; j ++)
      sp = std::max(dp[i][j][1], sp);

  std::cout << sp << std::endl;

  return 0;
}


Measured memory_bytes: 87040
def cross(a: complex, b: complex) -> float:
    return a.real * b.imag - a.imag * b.real


def cross_point(c: complex, d: complex) -> complex:
    global lt, lv
    vec = d - c
    v1 = cross(lv, vec)
    v2 = cross(lv, lt - c)
    return c + v2 / v1 * vec


if __name__ == "__main__":
    n = int(input())
    points = [complex(*map(int, input().split())) for _ in range(n)]
    point0 = points.pop(0)
    points.append(point0)

    q = int(input())
    while q:
        x1, y1, x2, y2 = map(int, input().split())
        ls, lt = (x1 + 1j * y1, x2 + 1j * y2)
        lv = lt - ls

        area = 0.0
        prev = point0
        prev_flag = 0 <= cross(lv, prev - ls)
        cp1, cp2 = None, None
        for p in points:
            curr_flag = 0 <= cross(lv, p - ls)
            if prev_flag and curr_flag:
                area += cross(prev, p)
            elif prev_flag != curr_flag:
                cp = cross_point(prev, p)
                if prev_flag:
                    area += cross(prev, cp)
                    cp1 = cp
                else:
                    area += cross(cp, p)
                    cp2 = cp
            prev, prev_flag = p, curr_flag
        if cp1 is not None and cp2 is not None:
            area += cross(cp1, cp2)
        print(area / 2)
        q -= 1



Measured memory_bytes: 5644
#include<stdio.h>
int main()
{
    int n;
    double sum=0;
    scanf("%d",&n);
    int ara[n],i;
    for(i=0;i<n;i++){
        scanf("%d",&ara[i]);
    }
    for(i=0;i<n;i++){
        sum=sum+(1/(double)ara[i]);
    }
    printf("%lf\n",1/sum);
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class A
{
	public static void Main()
	{
		string[] args = Console.ReadLine().Split(' ');
		int A = Int32.Parse(args[0]);
		int B = Int32.Parse(args[1]);
		int result = 0;
		if(A > B)
		{
			result += A;
			A--;			
		}
		else
		{
			result += B;
			B--;
		}
		if(A > B)
		{
			result += A;
			A--;			
		}
		else
		{
			result += B;
			B--;
		}
			
		Console.WriteLine(result);
	}	
}





Measured memory_bytes: 11092
#include<bits//stdc++.h>
using namespace std;
int main(){
    long long a[99];
	a[0]=2;
    a[1]=1;
    a[2]=3;
    for(int i=3;i<90;i++){
        a[i]=a[i-1]+a[i-2];
    }
    int b;
    cin>>b;
    cout<<a[b]<<endl;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define REP(i, x, y) for(int i = (int)x; i <= (int)y; i ++)
#define FOR(i, x, y) for(int i = (int)x; i <  (int)y; i ++)
#define PER(i, x, y) for(int i = (int)x; i >= (int)y; i --)
#define trace(x) cerr << #x << " " << x << endl;
#define dprintf(...) fprintf(stderr, __VA__ARGS__)
#define dln()        fprintf(stderr, "\n")
using namespace std;
typedef double db;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<PII> VPI;
typedef vector<long long> VL;
const	int N = 100005;
const	int P = 1e9 + 7;
const	int inf = 1e9;
const	LL Inf = 1e18;

inline int IN(){
	char ch = getchar(); int x = 0, f = 0;
	while(ch < '0' || ch > '9') ch = getchar(), f = (ch == '-');
	while(ch >= '0' && ch <= '9'){
		x = (x << 1) + (x << 3) + ch - 48;
		ch = getchar();
	}
	return f ? (-x) : x;
}

inline int Pow(int x, int y, int p){
	int an = 1;
	for(; y; y >>= 1, x = (LL)x * x % p) if(y & 1) an = (LL)an * x % p;
	return an;
}

void renew(int &x, int y){
	x += y;
	if(x < 0) x += P;
	else if(x >= P) x -= P;
}

void setIO(string a){
#ifndef LOCAL
	freopen((a + ".in").c_str(), "r", stdin);
	freopen((a + ".out").c_str(), "w", stdout);
#endif
}

template<typename T> inline void chkmin(T &a, const T &b) {if(a > b) a = b;}
template<typename T> inline void chkmax(T &a, const T &b) {if(a < b) a = b;}

int f[105][3505],n,k;

int main(){
#ifdef LOCAL
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
#endif
	
	scanf("%d%d",&n,&k);
	f[n][0]=1;
	PER(i,n,1){
		REP(j,0,3500)if(f[i][j]){
			REP(x,0,k){
				int nj=(x>i?j:(j+(x+j)/(i)));
				assert(nj<=3500);
				f[i-1][nj]=(f[i-1][nj]+f[i][j])%P;
			}
		}
	}

	int cf=Pow(k+1,n-1,P),ans=0;
	REP(i,1,n) REP(j,0,k) ans=(ans+(LL)j*cf)%P;

	REP(j,0,3500) ans=(ans+(LL)(P-j)*f[0][j])%P;

	printf("%d\n",ans);

	return 0;
}






















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

#define ll long long
#define mod 1000000007
#define inf 1000000000000000000
#define fr first
#define sc second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll,ll>
#define vll vector<ll>
#define umap unordered_map<ll,ll>
#define lpq priority_queue<ll,vector<ll>,greater<ll>>
ll globe=0;
ll powe(ll n,ll r){if(!r)return 1;else if(r%2==0)return powe(n*n,r/2);else return n*powe(n*n,(r-1)/2);}

ll digitDP(vector<vector<vll>> &dp,ll x,ll y,ll p,string &s,ll val){
	if(x>=s.size()){
		if(y%val==0)
			return 1;
		else
			return 0;
	}
	if(dp[x][y][p]!=-1)
		return dp[x][y][p];
	ll ans=0;
	if(p==0){//string till x is equal
		for(ll i=0;i<s[x]-'0';i++){
			ans+=digitDP(dp,x+1,(y+i)%val,1,s,val)%mod;
		}
		ans+=digitDP(dp,x+1,(y+s[x]-'0')%val,0,s,val)%mod;
	}
	else{
		for(ll i=0;i<10;i++){
			ans+=digitDP(dp,x+1,(y+i)%val,1,s,val)%mod;
		}
	}
	return dp[x][y][p]=ans%mod;
}

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

	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll t=1;
	//cin>>t;
	while(t--){
		string s;
		ll val;
		cin>>s>>val;
		ll y=0;
		vector<vector<vll>> dp(s.size(),vector<vll> (val,vll (2,-1)));
		ll ans=digitDP(dp,0,y,0,s,val)%mod;
		//cout<<dp[15][4][0]<<endl;
		cout<<(ans-1+mod)%mod<<endl;
	}

	return 0;

}

Measured memory_bytes: 56448
#define ALL(obj) (obj).begin(), (obj).end()

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>

using namespace std;
typedef long long ll;
const ll INF = 1e18;

ll a;
ll b;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> a >> b;
    string s1;
    string s2;
    
    for(ll i=0; i<b; i++) {
        s1.append(to_string(a));
    }

    for(ll i=0; i<a; i++) {
        s2.append(to_string(b));
    }
    
    char c1[1024000];
    char c2[1024000];
    strcpy(c1, s1.c_str());
    strcpy(c2, s2.c_str());

    if (strcmp(c1, c2) <= 0) {
        cout << s1 << endl;
    } else {
        cout << s2 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 888
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

struct UnionFind{
    v: Vec<usize>
}

impl UnionFind{
    fn new(n: usize) -> UnionFind{
        let mut v: Vec<usize> = Vec::new();
        for i in 0..n{
         v.push(i);
        }
        UnionFind{v:v}
    }

    fn find(&mut self, i: usize) -> usize{
        if self.v[i] == i{
            i
        }else{
            let ni = self.v[i];
            self.v[i] = self.find(ni);
            self.v[i]
        }
    }

    fn union(&mut self, i: usize, j: usize){
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.v[root_i] = root_j;
    }

}

struct CombMod{
    fac: Vec<u64>,
    inv: Vec<u64>,
    finv: Vec<u64>,
    mmod: u64,
}

impl CombMod{
    pub fn new(max: u64, m: u64) -> CombMod{
        let max: usize = max as usize;
        let mut fac: Vec<u64> = vec![0;max+1];
        let mut finv: Vec<u64> = vec![0;max+1];
        let mut inv: Vec<u64> = vec![0;max+1];

        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;

        for i in 2..max+1{
            fac[i] = fac[i-1] * i as u64 % m;
            inv[i] = m - inv[m as usize %i] * (m/(i as u64)) % m;
            finv[i] = finv[i-1] * inv[i] % m;
        }

        CombMod{
            fac: fac,
            finv: finv,
            inv: inv,
            mmod: m,
        }
    }

    fn get(&self, n: u64, m: u64) -> u64{
        assert!(n >= m && n != 0 && m != 0);
        self.fac[n as usize] * self.finv[m as usize] % self.mmod
            * self.finv[(n-m) as usize] % self.mmod
    }
}

fn main(){
    let s = read_as_string().chars().collect::<Vec<char>>();
    let ws_pos: usize = s.iter().position(|elem| *elem== ' ').unwrap();

    for i in ws_pos+1..s.len(){
        print!("{}", s[i]);
    }

    for i in 0..ws_pos{
        print!("{}", s[i]);
    }
    println!("");
}


Measured memory_bytes: 4352
N, K, *XY = [int(_) for _ in open(0).read().split()]
XY = sorted(zip(XY[::2], XY[1::2]))
ans = float('inf')
for i in range(N):
    for j in range(i + K - 1, N):
        xlen = XY[j][0] - XY[i][0]
        Y = sorted(y for x, y in XY[i:j + 1])
        ylen = min(y2 - y1 for y1, y2 in zip(Y, Y[K - 1:]))
        ans = min(ans, xlen * ylen)
print(ans)


Measured memory_bytes: 9204
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

const int N = 5001;
const int K = 5001;

bool needed(const vint &a, int n, int k, int t) {
  static bool dp[N][K];
  REP(i,n+1) REP(j,k+1) dp[i][j] = false;
  dp[0][0] = true;
  REP(i,n) REP(j,k) {
    if (i != t && j + a[i] < k) dp[i+1][j+a[i]] = dp[i+1][j+a[i]] || dp[i][j];
    dp[i+1][j] = dp[i+1][j] || dp[i][j];
  }
  FOR(j,max(0,k-a[t]),k) if (dp[n][j]) return true;
  return false;
}

typedef int int_nk[N][K];
typedef bool bool_nk[N][K];

void DP(const vint &a, int n, int k, bool_nk dp, int_nk sum) {
  REP(i,n+1) REP(j,k+1) dp[i][j] = false;
  dp[0][0] = true;
  REP(i,n) REP(j,k) {
    if (j + a[i] < k) dp[i+1][j+a[i]] = dp[i+1][j+a[i]] || dp[i][j];
    dp[i+1][j] = dp[i+1][j] || dp[i][j];
  }
  REP(i,n+1) REP(j,k+1) {
    sum[i][j] = dp[i][j];
    if (j) sum[i][j] += sum[i][j-1];
  }
}

int main() {
  int n, k;
  while (cin >> n >> k) {
    vint a(n);
    REP(i,n) cin >> a[i];

    static bool_nk dp1, dp2;
    static int_nk sum1, sum2;
    DP(a, n, k, dp1, sum1);
    reverse(ALL(a));
    DP(a, n, k, dp2, sum2);
    reverse(ALL(a));
    int result = 0;
    REP(i,n) {
      bool *head = &dp1[i][0];
      int *tail = &sum2[n-i-1][0]; // tail[i] = sum[*][0] .. sum[0][i] (inclusive)
      bool needed = false;
      auto sum = [&](int n) { return n < 0 ? 0 : tail[n]; };
      REP(j,k) if (head[j] && sum(k-1-j) != sum(k-1-j-a[i])) {
        needed = true;
      }
      if (!needed) {
        // cout << "no-needs " << i << ' ' << a[i] << endl; 
        ++result;
      }
    }
    cout << result << endl;
  }
}


Measured memory_bytes: 246400
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>

using namespace std;
typedef long long ll;

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

const 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(nullptr);
  ios::sync_with_stdio(false);
  int N;
  string S;
  cin>>N>>S;
  REP(i,S.length()){
    cout<<char((((S[i]-'A')+N)%26)+'A');
  }
  cout<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    char words[2];
    //iがAの時はA,Bの時はBが管理
    //区間間が違う会社の時はバス
    scanf("%s",words);
    if(words[0]==words[1] && words[1]==words[2]){
        printf("No");
    }else{
        printf("Yes");
    }

    return 0;
}

Measured memory_bytes: 128
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S, T = LIST()
A, B = MAP()
U = input()

if U == S:
    A = A - 1
elif U == T:
    B = B - 1
print(str(A) + ' ' + str(B))


Measured memory_bytes: 5188
#include<stdio.h>
int main(void){
	int i=0,x[3000],y[3000];
	do{
		scanf("%d %d",&x[i],&y[i]);
		i++;
	}while(x[i-1]!=0||y[i-1]!=0);
	for(i=0;x[i]!=0||y[i]!=0;i++){
		if(x[i]<=y[i]){
			printf("%d %d\n",x[i],y[i]);
		}else{
			printf("%d %d\n",y[i],x[i]);
		}
	}
	return 0;
}


Measured memory_bytes: 2032
using namespace std;
#include <iostream>
#include<bits/stdc++.h>
#define pb push_back
#define MAX 300
#define pi 3.1415926536
#define ip pair<int,int>
#define mp make_pair
#define ss second
#define ff first
#define ull unsigned long long
#define ll long long
#define MOD 1000000000
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fn(i,n) for (ll i=0; i<n; i++)
#define endl "\n"
#define Endl endl
#define int long long
#define EN cout<<endl;
#define inp(n) int n; cin>>n;
#define TEST int t; cin>>t; while(t--)
ll power(ll x, ll y, ll p) { int res = 1; x = x % p;  while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;} return res; } 
ll PO(ll a, ll n) { ll val=1; fn(i,n) val*=a; return val;  }
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { return (a.second < b.second); }
 
signed main ()
{
    int n,m; cin>>n>>m;
    int f[100006]={0};
    ll cnt=0;
    priority_queue <int> g;
    vector<int> v[100005];
    for (int i=0; i<n; i++)
    {
        inp(x); inp(y);
        v[x].pb(y);
    }

    for (int i=1; i<=m; i++)
    {
        if (v[i].size()>0)
        {
            for (int j=0; j<v[i].size(); j++)
                g.push(v[i][j]);
        }
        if (!g.empty())
        {
            cnt+=g.top();
            g.pop();
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 5632
# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

N, X = map(int, input().split())
L = [int(x) for x in input().split()]

ans = 1
s = 0
for i in range(N):
    s += L[i]
    ans += s <= X

print(ans)


Measured memory_bytes: 3444
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>
#include<numeric>

using namespace std;


int main()
{
  string S;
  cin >> S;

  if(S[0] == '7' || S[1] == '7' || S[2] == '7') cout << "Yes" << endl;
  else  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
	ll res=1;
	if(x==0)return 1;
	if(x==1)return y;
	res=kissme(x/2,y);
	res=res*res%mod;
	if(x%2==1)res=res*y%mod;
	return res;
}
int n;
signed main()
{
	Very_fast;
	string s;
	cin>>s;
	if(s=="ABC")cout<<"ARC";
	else cout<<"ABC";
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

bool dpx[8008][20000], dpy[8008][20000];

#define dpx(i,j) dpx[i][j + 10000]
#define dpy(i,j) dpy[i][j + 10000]
int status = 0; // 0 or 1

int main()
{
    string s;
    cin>>s;
    s += "T";
    int x, y;
    cin>>x>>y;

    int xmove = 0, ymove = 0;
    int size = s.size();
    dpx(0,0) = true;
    dpy(0,0) = true;
    bool flag = true;
    int dist = 0;
    REP(i,size) {
        if (s[i] == 'F') {
            dist++;
        } else {
            if (dist > 0) {
                //cout<<dist<<" "<<status<<endl;
                if (status == 0) {
                    if (flag) {
                        dpx(1,dist) = true;
                        xmove++;
                        dist = 0;
                        status = (status + 1) % 2;
                        flag = false;
                        continue;
                    }
                    FOR(j,-i-1,i+2) {
                        if (j - dist > -8008) dpx(xmove+1,j) |= dpx(xmove,j-dist);
                        if (j + dist < 8008) dpx(xmove+1,j) |= dpx(xmove,j+dist);
                    }
                    xmove++;
                } else {
                    FOR(j,-i-1,i+2) {
                        if (j - dist > -8008) dpy(ymove+1,j) |= dpy(ymove,j-dist);
                        if (j + dist < 8008) dpy(ymove+1,j) |= dpy(ymove,j+dist);
                    }
                    ymove++;
                }
            }
            dist = 0;
            status = (status + 1) % 2;
            flag = false;
        }
    }

    if (dpx(xmove,x) & dpy(ymove,y)) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    };

    return 0;
}


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

vector<long long> a[32];
int b[32];
int count_tail_zero(long long t){
  int ans = 0;
  while(t % 2 == 0){ t /= 2; ans++; }
  return ans;
}
int top_one(long long t){
  int ret = -1;
  for(int i = 0; i < 32; i++){
    if(t & 1 == 1)
      ret = i;
    t /= 2;
  }
  return ret;
}
int main(){
  int N;
  cin >> N;
  long long p = 0;
  for(int i = 0; i < N; i++){
    long long t;
    cin >> t;
    int k = count_tail_zero(t);
    a[k].push_back(t);
    b[k]++;
    p ^= t;
  }
  int ans = 0;
  while( p != 0 ){
    int k = top_one( p );
    if( b[k] == 0 ){
      puts("-1");
      return 0;
    }else{
      b[k]--;
      p ^= (1 <<  (k+1)) - 1;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 1528
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        int[] nck = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] t = Enumerable.Repeat(0, nck[0]).Select(_ => int.Parse(Console.ReadLine())).OrderBy(x => x).ToArray();

        int count = 0;
        int busfinish = -1;
        int buscapa = nck[1];
        for (int i = 0; i < t.Length; i++)
        {
            if (t[i] <= busfinish && 0 < buscapa)
            {
                buscapa--;
            }
            else
            {
                count++;
                busfinish = t[i] + nck[2];
                buscapa = nck[1] - 1;
            }
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 20700