akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

int main()
{
    int n,m;
    int s[5];
    int c[10];
    int a,b;
    int ans=0;
    scanf("%d %d",&n, &m);
    for (int i=1; i<=n; i++) {
        s[i]=-1;
    }
    for (int i=1; i<=m; i++) {
        scanf("%d %d",&a, &b);
        if (s[a] != b && s[a] != -1)  ans=-1;
        s[a]=b;
    }
    if (ans==-1)    printf("-1");
    else if (n!=1 && s[1]==0)   printf("-1");
    else {
        for (int i=1; i<=n; i++) {
            ans*=10;
            if (s[i] == -1) {
                if (i==1 && n!=1)   s[i]=1;
                else    s[i]=0;
            }
            ans+=s[i];
        }
        printf("%d",ans);
    }

}


Measured memory_bytes: 128
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	ll d, a; cin >> d >> a;
	vector<pair<ll, ll>> v(n);
	rep(i, n)
	{
		ll x, h; cin >> x >> h;
		v[i] = { x,h };
	}
	sort(all(v));
	ll cnt = 0;
	ll res = 0;
	deque<pair<ll, ll>> q;
	rep(i,n)
	{
		ll x = v[i].first;
		ll h = v[i].second;
		while (!q.empty())
		{
			if (q.front().first > x)break;
			cnt -= q.front().second;
			q.pop_front();
		}
		
		if (a*cnt < h)
		{
			ll r = (h - a * cnt + a - 1) / a;
			res += r;
			cnt += r;
			q.push_back({ x + 2 * d + 1 , r });
		}
	}
	cout << res << endl;
}

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

#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;

lli parent1[200001]; // parent[i]: i が含まれる木の根の番号
lli depth1[200001];  // depth[i] : i は自身が含まれる木のどれくらいの深さにいるか(最低1)
                    //            ただし、根の depth のみが参照される
lli parent2[200001]; // parent[i]: i が含まれる木の根の番号
lli depth2[200001];  // depth[i] : i は自身が含まれる木のどれくらいの深さにいるか(最低1)

void init() {
    REPE(i, 1, 200000) {
        parent1[i] = i;
        depth1[i] = 1;
        parent2[i] = i;
        depth2[i] = 1;
    }
}

lli find1(lli x) {
    if (parent1[x] == x)
        return x;
    else
        return parent1[x] = find1(parent1[x]);
}

void unite1(lli x, lli y) {
    lli x_root = find1(x);
    lli y_root = find1(y);
    if (x_root == y_root)
        return;

    if (depth1[x_root] < depth1[y_root]) {
        parent1[x_root] = y_root;
    }
    else {
        parent1[y_root] = x_root;
        if (depth1[x_root] == depth1[y_root])
            depth1[x_root]++;
    }
}

bool same1(lli x, lli y) {
    return find1(x) == find1(y);
}

lli find2(lli x) {
    if (parent2[x] == x)
        return x;
    else
        return parent2[x] = find2(parent2[x]);
}

void unite2(lli x, lli y) {
    lli x_root = find2(x);
    lli y_root = find2(y);
    if (x_root == y_root)
        return;

    if (depth2[x_root] < depth2[y_root]) {
        parent2[x_root] = y_root;
    }
    else {
        parent2[y_root] = x_root;
        if (depth2[x_root] == depth2[y_root])
            depth2[x_root]++;
    }
}

bool same2(lli x, lli y) {
    return find2(x) == find2(y);
}

int main() {
    init();


    lli n, k, l;
    cin >> n >> k >> l;
    REP(i, 0, k) {
        lli p, q;
        cin >> p >> q;
        unite1(p, q);
    }
    REP(i, 0, l) {
        lli r, s;
        cin >> r >> s;
        unite2(r, s);
    }

    // 頂点をまわり、それぞれの頂点の unit1 と unite2 の根のpairを保存。
    // 根のpairが同じならば unite1 も unite2 も同じということで、どっちの経路でも繋がれる
    map<P, lli> m;
    REPE(i, 1, n) {
        P p = P(find1(i), find2(i));
        auto it = m.find(p);
        lli val = 1;
        if (it != m.end()) {
            val = it->second + 1;
            m.erase(p);
        }
        m.insert(make_pair(P(find1(i), find2(i)), val));
    }
    REPE(i, 1, n) {
        P p = P(find1(i), find2(i));
        auto it = m.find(p);
        //cout << it->first.first << endl;
        cout << it->second << endl;
    }
}


Measured memory_bytes: 18304
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		solve();
	}

	public static void solve() {
  	Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		boolean[] a = new boolean[10];
		for(int i = 0; i < 10; i++) a[i] = false;
		int ans = 0, rest = 0;
		for(int i = 0; i < n; i++){
			int t = sc.nextInt();
			t /= 400;
			if(t >= 8){
				rest++;
				continue;
			}
			if(!a[t]){
				ans++;
				a[t] = true;
			}
		}
		sc.close();

		out.println(Math.max(1,ans) + " " + (ans + rest));
		out.flush();
	}
}

Measured memory_bytes: 23252
// https://atcoder.jp/contests/abc107/tasks/abc107_b
#include <bits/stdc++.h>
using namespace std;
using P = pair<double, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W;
    cin >> H >> W;
    vector<string> v(H);
    set<int> sh, sw;
    REP(i, H) {
        cin >> v[i];
        bool flag = false;
        REP(j, W) {
            if (v[i][j] == '#') {
                flag = true;
                break;
            }
        }
        if (!flag) {
            sh.insert(i);
        }
    }
    REP(i, W) {
        bool flag = false;
        REP(j, H) {
            if (v[j][i] == '#') {
                flag = true;
                break;
            }
        }
        if (!flag) {
            sw.insert(i);
        }
    }
    REP(i, H) {
        if (sh.count(i) == 0) {
            REP(j, W) {
                if (sw.count(j) == 0) {
                    cout << v[i][j];
                }
            }
            cout << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 256
N, K, Q = gets.split.map(&:to_i)
As = Array.new(Q) { gets.to_i }

h = As
  .group_by(&:itself)
  .map { |k, v| [k, v.size] }
  .select { |k, v| v > Q - K }
  .to_h

1.upto(N) do |k|
  puts K > Q ? 'Yes' : h[k] ? 'Yes' : 'No'
end


Measured memory_bytes: 22652
def f(a):
    for x in ['o','x']:
        if a[0::4].count(x)==3 or a[2:7:2].count(x)==3:return x
        for i in range(3):
            if a[i*3:i*3+3].count(x)==3 or a[i::3].count(x)==3:return x
    return 'd'

while 1:
    try:print(f(list(input())))
    except:break

Measured memory_bytes: 7492
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


void solve(){
  ll N; cin >>N;
  ll A,B; cin >>A >>B;
  ll res = 0;
  if (A == B){ cout <<1 <<endl; return; }
  if (A > B){  cout <<0 <<endl; return; }
  // A < B
  if (N == 1){ cout <<0 <<endl; return; }
  // N > 1
  // N個のうち、1つはA, 1つはB であることが決まっている。
  // 残りの N-2 個の整数については A ～ B を好きに決めて良い
  ll M = N-2;
  // したがって、以降は N-2 = M 個の整数について考えると、
  // 和は最小 A*M, 最大 B*M となる。
  res = B*M - A*M + 1;
  cout <<res <<endl;
}

int main() {
  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>

const long long int Z = 1000000007;
const long long int INF = 1 << 30;
int flag = 0;
using ll = long long;

 ll gcd(ll a, ll b) {
	 if (b == 0) return a;
	 return gcd(b, a%b);

}
 ll lcm(ll a, ll b) {
	 ll g = gcd(a, b);
	 return a / g * b;
 }

int main() {
	int n, a[200000];
	std::cin >> n;
	std::deque<int>d;
	for (int i = 1;i <= n;i++) {
		std::cin >> a[i];
		if (n % 2 == i % 2) {
			d.push_front(a[i]);
		}
		else {
			d.push_back(a[i]);
		}
	}
	std::for_each(d.begin(), d.end(), [](int x) {
		std::cout << x << ' ';
	});
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 3840
a,b = gets.split.map {|n| n.to_i}
while (a != 0 || b != 0)
  if a < b
    puts a.to_s + " " + b.to_s
  else
    puts b.to_s + " " + a.to_s
  end
  a,b = gets.split.map {|n| n.to_i}
end

Measured memory_bytes: 6100
#include<bits/stdc++.h>
using namespace std;
#define maxn 20
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
int n;
long long a[maxn];
long long dfs(int l,int r,int L,int R)
{
	if(l>r)return 0;
	long long res=1e18;
	for(int i=l;i<=r;i++)
		res=min(res,dfs(l,i-1,L,L+R)+dfs(i+1,r,L+R,R)+a[i]*(L+R));
	return res;
}
int main()
{
	read(n);
	for(int i=1;i<=n;i++)
		read(a[i]);
	printf("%lld\n",a[1]+a[n]+dfs(2,n-1,1,1));
    return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

const int N = 1e3+34;
const long long inf = 2e18;

long long d[N];

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	for (int i = 0; i < N; ++i) d[i] = inf;
}

struct edge {
	int a, b, w;
};

edge g[3*N];
bool negs[N];

void solve() {
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		scanf("%d%d%d", &g[i].a, &g[i].b, &g[i].w);
		--g[i].a; --g[i].b;
		g[i].w *= -1;
	}
	d[0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (d[g[j].a] < inf) {
				if (d[g[j].b] > d[g[j].a] + g[j].w) {
					d[g[j].b] = max(-inf, d[g[j].a]+g[j].w);
					if (i == n-1) negs[g[j].b] = true;
				}
				if (i == n-1 && negs[g[j].a]) negs[g[j].b] = true;
			}
		}
	}
	if (negs[n-1]) {
		puts("inf");
	} else {
		printf("%lld", -d[n-1]);
	}
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int a=Integer.parseInt(scan.next());
    int b=Integer.parseInt(scan.next());

    if(a>b){
      System.out.println("a > b");
    }else if(a<b){
      System.out.println("a < b");
    }else if(a==b){
      System.out.println("a == b");
    }
  }
}


Measured memory_bytes: 26272
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
void rp(int r,char c)
{
	for(int i=0;i<r;i++)printf("%c",c);
}

int main()
{
	int sx,sy,tx,ty,dx,dy;
	scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
	dy=ty-sy;dx=tx-sx;
	rp(dy,'U');
	rp(dx,'R');
	rp(dy,'D');
	rp(dx,'L');
	rp(1,'L');
	rp(dy+1,'U');
	rp(dx+1,'R');
	rp(1,'D');
	rp(1,'R');
	rp(dy+1,'D');
	rp(dx+1,'L');
	rp(1,'U');
	puts("");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
using namespace std;
using ll = long long;
using vi = vector<int>;

int main() {
  string N;
  cin >> N;
  int x = 0;
  for (char c : N) {
    x += (c - '0');
  }
  x %= 9;

  cout << (x == 0 ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 3688
# ABC 100 D
N, M = map(int, input().split())
A = [list(map(int, input().split())) for k in range(N)]

B = sum((sorted([e[0]+e[1]+e[2] for e in A])[::-1])[:M])
C = sum((sorted([e[0]-e[1]+e[2] for e in A])[::-1])[:M])
D = sum((sorted([e[0]+e[1]-e[2] for e in A])[::-1])[:M])
E = sum((sorted([0-e[0]+e[1]+e[2] for e in A])[::-1])[:M])
F = sum((sorted([e[0]-e[1]-e[2] for e in A])[::-1])[:M])
G = sum((sorted([0-e[0]-e[1]+e[2] for e in A])[::-1])[:M])
H = sum((sorted([0-e[0]+e[1]-e[2] for e in A])[::-1])[:M])
I = sum((sorted([0-e[0]-e[1]-e[2] for e in A])[::-1])[:M])

print(max(B,C,D,E,F,G,H,I))

Measured memory_bytes: 3380
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=300000 +117;
const int MM=300000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
int a[NN]={};
int pre[NN]={};
bool chk(int x){
	int mii=0;
	for(int i=2;i<=n;i+=2){
		if(pre[i-1]-mii>=x){
			mii=min(mii,pre[i]);
		}
	}
	return pre[n]-mii>=x;
}
int main(){
	//open();
	n=read();
	int s=0;
	int s1=0;
	int s2=0;
	for(int i=1;i<=n;++i){
		a[i]=read();
		s+=a[i];
		pre[i]=a[i];
		if(i&1){
			s1+=a[i];
		}
		else{
			s2+=a[i];
			pre[i]=-pre[i];
		}
		pre[i]+=pre[i-1];
	}
	int ans=max(s1,s2);
	if(n&1){
		int l=0,r=s;
		while(l!=r){
			int mid=(l+r+1)>>1;
			if(chk(mid)){
				l=mid;
			}
			else r=mid-1;
		}
		ans=max(ans,s2+l);
	}
	printf("%d %d\n",ans,s-ans);
	close();
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
        if (h[i] >= k)
        {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <unistd.h>
#define mod (1e9 + 7)
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

vector<vector<int> > vvi;
int vis[111111][3];

int main(){

  int n,m;
  cin>>n>>m;
  for(int i=0;i<=n;i++){
    vvi.pb(vector<int>());
    vis[i][0]=mod;
    vis[i][1]=mod;
    vis[i][2]=mod;
  }

  int u,v;
  for(int i=0;i<m;i++){
    cin>>u>>v;
    vvi[u].pb(v);
  }
  int s,t;
  cin>>s>>t;

  priority_queue<pii,vector<pii>, greater<pii> > pq;
  pq.push(pii(0,s));

  while(!pq.empty()){
    pii cur_q=pq.top(); pq.pop();

    int cur_c,cur_v;
    cur_c=cur_q.first;
    cur_v=cur_q.second;

    if(cur_c>=vis[cur_v][cur_c%3]) continue;//vis[-1000][-1000]=1000;
    vis[cur_v][cur_c%3]=cur_c;

    // printf("%d %d\n",cur_c,cur_v);
    // sleep(1);
    for(int i=0;i<vvi[cur_v].size();i++){
      if(vis[vvi[cur_v][i]][(cur_c+1)%3]!=mod) continue;
      
      pq.push(pii(cur_c+1,vvi[cur_v][i]));        
    }
  }

  if(vis[t][0]!=mod){
    cout<<vis[t][0]/3<<endl;
  }
  else cout<<-1<<endl;
  
  return 0;
}



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

const int N = 5005;
int lcp[N][N], a[N];

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

    string s;
    cin >> s;
    int k;
    cin >> k;

    int n = s.size();

    for (int i = n - 1; i >= 0; i--) {
        for (int j = n - 1; j >= 0; j--) {
            if (s[i] != s[j]) {
                lcp[i][j] = 0;
            }
            else {
                lcp[i][j] = lcp[i + 1][j + 1] + 1;
            }
        }
    }

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

    sort(a, a + n, [&](int x, int y) {
        return x + lcp[x][y] == n || y + lcp[x][y] < n && s[x + lcp[x][y]] < s[y + lcp[x][y]];
    });

    for (int i = 0; i < n; i++) {
        for (int j = (i == 0 ? 1 : lcp[a[i - 1]][a[i]] + 1); j <= n - a[i]; j++) {
            k--;
            if (k == 0) {
                cout << s.substr(a[i], j) << "\n";
                return 0;
            }
        }
    }

    return 0;   
}

Measured memory_bytes: 98048
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 99999999999999

int N,M;
ll K;

ll* table,*memo;

ll recursive(int index){

	if(index >= N)return 0;

	if(memo[index] != -1)return memo[index];

	ll ret = NUM;
	ll max_orange = -1,min_orange = NUM;

	for(int i = 1; i <= M; i++){
		if(index + i > N)continue;
		max_orange = max(max_orange,table[index+i-1]);
		min_orange = min(min_orange,table[index+i-1]);
		ret = min(ret,recursive(index+i)+i*(max_orange-min_orange)+K);
	}

	return memo[index] = ret;

}


int main(){
	scanf("%d %d %lld",&N,&M,&K);
	table = new ll[N];
	memo = new ll[N];
	for(int i = 0; i < N; i++)memo[i] = -1;

	for(int i = 0; i < N; i++)scanf("%lld",&table[i]);

	printf("%lld\n",recursive(0));

	return 0;
}

Measured memory_bytes: 5412
/*
          Life before Death
          Strength before Weakness
          Journey before Destination
    */
    
    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define rep(i,a,n) for(ll i=a;i<n;i++)
    #define per(i,n,a) for (ll i=n;i>a;i--)
    #define te int t; std::cin >> t; while(t--)
    #define SZ 5011
    //#define M_PI  3.141592653589793238462643383279502884L
    /*------Just DO IT--------------------------------------*/

    int solve(){
      ll n, ans = 0;
      cin >> n;
      ll a[n], b[n], c[n];
      rep(i, 0, n) cin >> a[i] >> b[i], c[i] = a[i]+b[i], ans-=b[i];
      sort(c, c+n, greater<ll>());
      rep(i, 0, n) if(i%2==0) ans+=c[i];
      //if(n%2) ans+=c[n/2];
      cout << ans << endl;
    }
    
   int main() {
       fastio
       solve();
    }

Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
 
int m[3][3];
int cpy[3][3];
 
void input(void){
  int i,j;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      scanf("%d",&m[i][j]);
    }
  }
}
void output(void){
  int i,j;
 for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      printf("%3d",m[i][j]);
      puts("");
    }
 }
}
void copy(int a[3][3],int b[3][3]){
  int i,j;
 for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      a[i][j] = b[i][j];
    }
 }
}
int calc(void){
  int i,sum = 0;
  for(i=0;i<9;i++){
    int a = m[i/3][i%3];
    if(a){
      a--;
      sum += abs(i/3 - a/3)+abs(i%3 - a%3);
    }
  }
  return sum;
}
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
 
void swap(int *a, int *b){
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}
int in(int a,int b){
  return 0<=a&&a<3&&0<=b&&b<3;
}
int df(int a,int b,int p,int d,const int lim){
  int i , h=calc();
  if(h == 0)return d;
  if(d+h > lim)return -1;
 
  for(i=0;i<4;i++){
    int x= a+dx[i],y=b+dy[i];
    int res;
    if(~p && i == (p+2)%4)continue;
    if(!in(x,y))continue;
    swap(&m[b][a],&m[y][x]);
    res = df(x,y,i,d+1,lim);
    if(~res)return res;
    swap(&m[b][a],&m[y][x]);
  }
  return -1;
}
 
void empty(int *a, int *b){
  int i,j;
   for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(!m[i][j]){
    *a = j;
    *b = i;
    return;
      }
    }
   }
}
int s(void){
  int a,b,lim,x;
  empty(&a,&b);
  for(lim = 0;lim < 50;lim++){
    copy(cpy,m);
    if((x = df(a,b,-1,0,lim)) != -1)return x;
    copy(m,cpy);
  }
  return -1;
}
int main(){
  input();
  printf("%d\n",s());
 
  return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int SIZEN = 200010;
typedef long long LL;
LL A[SIZEN] = {0};
int main(){
	int N;scanf("%d",&N);
	for(int i = 1;i <= N;i++)scanf("%lld",&A[i]),A[i] += A[i-1];
	LL ans = 0x3f3f3f3f3f3f3f3f;
	for(int i = 1;i < N;i++){
		ans = min(ans,abs(A[N]-A[i]-A[i]));
	}
	printf("%lld\n",ans);
}

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

int main(void)
{
    int a, b, d, g, count =0;

    cin >> a >> b;
     vector<ll >A(a);
     vector<bool >B(a, true);
     

     for (int i = 0; i < a; i++)
     {
         cin >> A[i];
         
     }

     for (int i = 0; i < b; i++)
     {
         cin >> d >> g;
         if (A[d - 1] < A[g - 1])
         {
             B[d-1] = false;
         }
         else if (A[d - 1] > A[g - 1])
         {
             B[g - 1] = false;
         }
         else
         {
             B[d - 1] = false;
             B[g - 1] = false;
         }
         
     }

     for (int i = 0; i < a; i++)
     {
         if (B[i])
             count++;
     }
         cout << count << endl;

     
    
}

    

Measured memory_bytes: 3948
N = int(input())
a = [0] + list(map(int,input().split()))
ans = [0]*(N+1)
for k in range(N,0,-1):
    temp = 0
    l = k
    while l <= N:
        temp += ans[l]
        l += k
    if a[k] == 1 and temp%2 == 0:
        ans[k] = 1
    elif a[k] == 0 and temp%2 == 1:
        ans[k] = 1
b = []
for k in range(1,N+1):
    if ans[k] == 1:
        b.append(k)
print(len(b))
print(*b)


Measured memory_bytes: 98948
#include <bits/stdc++.h>
using namespace std;
const long long INF = 123456789;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

int main()
{
    cin >> s;
    vs st;
    st.push_back("AKIHABARA");
    st.push_back("AKIHABAR");
    st.push_back("AKIHABRA");
    st.push_back("AKIHABR");
    st.push_back("AKIHBARA");
    st.push_back("AKIHBAR");
    st.push_back("AKIHBRA");
    st.push_back("AKIHBR");

    st.push_back("KIHABARA");
    st.push_back("KIHABAR");
    st.push_back("KIHABRA");
    st.push_back("KIHABR");
    st.push_back("KIHBARA");
    st.push_back("KIHBAR");
    st.push_back("KIHBRA");
    st.push_back("KIHBR");
    REP(i, st.size())
    {
        if (s == st[i])
        {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
n,x=map(int,input().split())
a=list(map(int,input().split()))
dp=[-1]*n
dp[0]=0
if n<=x:
    x=n-1
for i in range(1,x+1):
    dp[i]=abs(a[i]-a[0])

for i in range(x+1,n):
    min1=10**9
    for j in range(i-(x),i):  
        if min1>dp[j]+abs(a[j]-a[i]):               
            min1=dp[j]+abs(a[j]-a[i])
    dp[i]=min1
print(dp[-1])


Measured memory_bytes: 52448
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

constexpr int Nmax = 100000;
int N, M, S[2];
int U[Nmax], V[Nmax];
vector<int> to[100000];
lint C[2][Nmax], d[2][Nmax];

int main()
{
    cin >> N >> M >> S[0] >> S[1];
    S[0]--;
    S[1]--;
    REP(e, M)
    {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        U[e] = u - 1;
        V[e] = v - 1;
        C[0][e] = a;
        C[1][e] = b;
        to[u - 1].push_back(e);
        to[v - 1].push_back(e);
    }

    REP(i, 2)
    {
        REP(j, N) d[i][j] = 1E15;
        d[i][S[i]] = 0;
        priority_queue<plint, vector<plint>, greater<plint>> pq;
        for (auto e : to[S[i]]) pq.push(plint(C[i][e], U[e] + V[e] - S[i]));

        while (!pq.empty())
        {
            auto pa = pq.top();
            pq.pop();
            int now = pa.second;
            if (d[i][now] > pa.first)
            {
                d[i][now] = pa.first;
                for (auto e : to[now])
                {
                    int nxt = U[e] + V[e] - now;
                    if (d[i][nxt] > d[i][now] + C[i][e]) pq.push(plint(d[i][now] + C[i][e], nxt));
                }
            }
        }
    }

    lint ans[Nmax];
    lint tmp_cost = 1E15;
    IREP(i, N)
    {
        tmp_cost = min(tmp_cost, d[0][i] + d[1][i]);
        ans[i] = tmp_cost;
    }
    REP(i, N) printf("%lld\n", (lint)1E15 - ans[i]);
}


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

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll mod(ll val, ll m) {
	ll res = val % m;
  if (res < 0) res += m;
  return res;
}

int main() {
	ll n; cin >> n;
    ll a, b, c;
    a =  modpow(10, n, MOD);
    b =  modpow(9, n, MOD);
    c =  modpow(8, n, MOD);
    ll ans = mod(((a+c)%MOD - 2*b%MOD)%MOD, MOD);
  
  cout << ans << endl;
   return 0;
}


Measured memory_bytes: 3668
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;
using LL = long long;

int Par[1200001];
int Rank[1200001];

void init(int n) {
	for (int i = 0; i < n; i++) {
		Par[i] = i;
		Rank[i] = 0;
	}
}

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

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

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

int main() {
	int n, k, l;
	cin >> n >> k >> l;
	init(n * 2 + 2);
	int a, b;
	for (int i = 0; i < k; i++) {
		cin >> a >> b;
		unite(a, b);
	}
	for (int i = 0; i < l; i++) {
		cin >> a >> b;
		unite(n + a, n + b);
	}
	pair<int, int> p[1200001];
	map<pair<int, int>, int> m;
	for (int i = 1; i <= n; i++) {
		p[i] = make_pair(find(i), find(i + n));
	}
	for (int i = 1; i <= n; i++) {
		m[p[i]] ++;
	}
	for (int i = 1; i <= n; i++) {
		if(i!=n)cout << m[p[i]] << " ";
		else cout << m[p[i]] << endl;
	}
}

Measured memory_bytes: 27008
// AtCoder ABC121: D - XOR World
// 2019.9.9 bal4u
// Template for Online Contest

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

typedef long long ll;

#define gc() getchar()
#define pc(c) putchar(c)

int in() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

ll inL() {  // long long 整数の入力
	ll n = 0; int c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n) { // 整数の表示
	int i; char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

void outL(ll n) { // 整数の表示
	int i; char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

int ins(char *s) { // 文字列の入力
	char *p = s--;
	do *++s = gc();
	while (*s > ' ');
	*s = 0;
	return s - p;
}

void outs(char *s) {  // 文字列の表示
	while (*s) pc(*s++);
}

#define MIN(a,b)  ((a)<=(b)?(a):(b))
#define MAX(a,b)  ((a)>=(b)?(a):(b))
#define ABS(a)    ((a)>=0?(a):-(a))
inline static int chmax(int *a, int b) { if (*a < b) *a = b; }
inline static ll  chmaxL(ll *a, int b) { if (*a < b) *a = b; }
inline static int chmin(int *a, int b) { if (*a > b) *a = b; }
inline static ll  chminL(ll *a, int b) { if (*a > b) *a = b; }

int main()
{
	ll A, B, ans;
	
	A = inL(), B = inL();
	if (B == 0) puts("0");
	else if (A == B) outL(B);
	else {
		ans = 0;
		if (A & 1) ans = A, A++;
		if ((B & 1) == 0) ans ^= B--;
		ans ^= ((B-A)/2+1) & 1;
		outL(ans);
	}
	return 0;
}


Measured memory_bytes: 128
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

x,n=map(int,input().split())
p=[int(i) for i in input().split()]
ans=0
ansc=100000
for i in range(-200,200):
    if i not in p:
        #print(i,abs(i-x))
        if ansc>abs(i-x):
            ans=i
            ansc=abs(i-x)
        elif ansc==abs(i-x):
            if ans>i:
                ans=i
print(ans)

Measured memory_bytes: 9200
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
  int i,ans,n,a,b,c,aa,bb,cc,amax=0,bmax=0,cmax=0;
  cin>>n;
  
  for(i=0;i<n;i++)
  {
    cin>>a>>b>>c;
    aa=a+max(bmax,cmax);
    bb=b+max(amax,cmax);
    cc=c+max(amax,bmax);
    amax=aa;
    bmax=bb;
    cmax=cc;
  }
  ans=max({amax,bmax,cmax});
  cout<<ans<<endl;
  
  
}

Measured memory_bytes: 3548
PROGRAM ATCODER

implicit none
integer :: n, i
integer, allocatable :: h(:), dp(:)

read(*,*) n
allocate(h(n), dp(n))
read(*,*) (h(i), i=1,n)

dp = 10**9
dp(1) = 0
dp(2) = dp(1) + abs(h(1)-h(2))

do i = 3, n
	call chmin(dp(i), dp(i-1)+abs(h(i)-h(i-1)))
    call chmin(dp(i), dp(i-2)+abs(h(i)-h(i-2)))
end do

write(*,'(i0)') dp(n)

END PROGRAM ATCODER

subroutine chmin(dp,x)
implicit none
integer :: dp, x

if (dp > x) then
	dp = x
	return
end if

end subroutine

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int beki[29];
int N;
int a[200010];
int b[200010];

ll sub(vector<int> A, vector<int> B, int index) {
    B.push_back(-1);
    int border = beki[index];
    ll a_index = 0;
    ll b_index = 0;
    ll ret = 0;
    while(a_index < A.size()) {
        if(A[a_index] + B[b_index] >= border) {
            b_index++;
            continue;
        }
        ret += b_index;
        ret %= 2;
        a_index++;
    }
    return ret;
}

ll solve(int index) {
    vector<int> A[2];
    vector<int> B[2];
    for(int i = 1; i <= N; i++) {
        if((a[i] >> index) & 1) A[1].push_back(a[i] % beki[index]);
        else A[0].push_back(a[i] % beki[index]);
        if((b[i] >> index) & 1) B[1].push_back(b[i] % beki[index]);
        else B[0].push_back(b[i] % beki[index]);
    }
    /*
    cerr << index << endl;
    for(int i = 0; i < A[0].size(); i++) {
        cerr << A[0][i] << " ";
    }
    cerr << endl;
    */
    sort(A[0].begin(), A[0].end());
    sort(A[1].begin(), A[1].end());
    sort(B[0].begin(), B[0].end(), greater<int>());
    sort(B[1].begin(), B[1].end(), greater<int>());
    ll ans = 0;
    ans += sub(A[0], B[0], index);
    ans += sub(A[1], B[1], index);
    ans += (A[0].size() * B[1].size()) - sub(A[0], B[1], index);
    ans += (A[1].size() * B[0].size()) - sub(A[1], B[0], index);
    return ans;
}

int main() {
    //cout.precision(10);
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> a[i];
    }
    for(int i = 1; i <= N; i++) {
        cin >> b[i];
    }
    beki[0] = 1;
    for(int i = 1; i <= 28; i++) {
        beki[i] = beki[i - 1] * 2;
    }
    ll ans = 0;
    for(int i = 0; i <= 28; i++) {
        ll now = solve(i);
        if(now % 2 == 1) ans += beki[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5776
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
       int S=scanner.nextInt();
       int s=S%60;
       int M=S/60;
       int m=M%60;
       int h=M/60;
        System.out.println(h+":"+m+":"+s);
        
              
              
       
    }

}

Measured memory_bytes: 26068
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int nax = 1e5 + 5;
vector<int> edges[nax];
int in_degree[nax]; // the number of edges going to 'b'
int dist[nax];
bool visited[nax];

void dfs(int a) {
    assert(!visited[a]);
    visited[a] = true;
    for(int b : edges[a]) {
        dist[b] = max(dist[b], dist[a] + 1);
        --in_degree[b];
        if(in_degree[b] == 0) {
            dfs(b);
        }
    }
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    while(m--) {
        int a, b;
        scanf("%d%d", &a, &b);
        edges[a].push_back(b);
        ++in_degree[b];
    }
    for(int i = 1; i <= n; ++i) {
        if(!visited[i] && in_degree[i] == 0) {
            dfs(i);
        }
    }
    int answer = 0;
    for(int i = 1; i <= n; ++i) {
        answer = max(answer, dist[i]);
    }
    printf("%d\n", answer);
}

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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int r, g; cin >> r >> g;

  cout << g * 2 - r << endl;
  
  return (0);
}

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

#define esp 1e-9

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n;
	cin>>n;
	vector<long long int> indx;
	indx.push_back(0);
	vector<long long int> b;
	b.push_back(0);
	vector<long long int> c;
	c.push_back(0);
	long long int t=n,tt=n-1;
	while(n--){
		long long int x;
		cin>>x;
		indx.push_back(x);
	}
	while(t--){
		long long int x;
		cin>>x;
		b.push_back(x);
	}
	while(tt--){
		long long int x;
		cin>>x;
		c.push_back(x);
	}
	long long int ans=0;
	for(long long int i=1;i<indx.size();i++){
		long long int xx=indx[i];
		ans+=b[xx];
		if(indx[i-1]==xx-1){
			ans+=c[xx-1];
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3640
import sys
def input():
    return sys.stdin.readline()[:-1]
n,m=map(int,input().split())
xyz=[list(map(int,input().split())) for i in range(n)]
plmi=[-1,1]
ans=0
for i in plmi:
    for j in plmi:
        for k in plmi:
            xyz.sort(key=lambda x:i*x[0]+j*x[1]+k*x[2])
            # print(xyz)
            tmpans=[0,0,0]
            for l in range(m):
                tmpans[0]+=xyz[l][0]
                tmpans[1]+=xyz[l][1]
                tmpans[2]+=xyz[l][2]
            ans=max(ans,abs(tmpans[0])+abs(tmpans[1])+abs(tmpans[2]))
print(ans)

Measured memory_bytes: 40432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll mod = 1000000007;

void solve()
{
	int n; cin >> n;
	set<char> s;
	rep(i, n) 
	{
		char t;
		cin >> t;
		s.insert(t);
	}
	if(sz(s)==3)cout << "Three" << endl;
	else cout << "Four" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int x = 0, y = 0;
    rep(i,n){
        if('A' <= s[i] && s[i] <= 'M')x++;
        if('N' <= s[i] && s[i] <= 'Z')x--;
        if('a' <= s[i] && s[i] <= 'm')y++;
        if('n' <= s[i] && s[i] <= 'z')y--;
    }
    string ans = "";
    while(x > 0){
        x--;
        ans += "A";
    }
    while(x < 0){
        x++;
        ans += "Z";
    }
    while(y > 0){
        y--;
        ans += "a";
    }
    while(y < 0){
        y++;
        ans += "z";
    }
    cout << ans.size() << endl;
    cout << ans << endl;
}



Measured memory_bytes: 3332
from sys import stdin
from collections import deque

readline = stdin.readline

def main():
    N, Q = map(int, input().split())

    # 木構造を記録（親も子も関係なく繋がっている節を結ぶ）
    tree = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, readline().split())
        tree[a - 1].append(b - 1)
        tree[b - 1].append(a - 1)

    # 素の状態の節のカウントを求める
    cou = [0] * N
    for _ in range(Q):
        p, x = map(int, readline().split())
        cou[p - 1] += x


    # 頂点から順に節を見ていく
    # que(node, parent) node = 現在の節,    parent = 親の節
    # 初期値に頂点（親はなし）を追加
    que = deque([[0, -1]])

    while len(que) > 0:
        node, parent = que.pop()

        # 現在の節から繋がっている節を全て確認
        for child in tree[node]:
            # 繋がっている節が親なら無視
            if child == parent:
                continue
            # 繋がっている節が子なら、現在の節のカウントを増やす
            else:
                cou[child] += cou[node]
                # 子の節を起点に再帰的に処理
                que.appendleft([child, node])
    
    # くぅ～疲れました！これにて完です！
    print(*cou)


if __name__ == '__main__':
    main()

Measured memory_bytes: 65460
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        var list = Console.ReadLine().Split(' ');
        var n = int.Parse(list[0]);
        var k = int.Parse(list[1]);

        Console.WriteLine(n - k + 1);
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int i,j,n,k,c,h,w,b,a;
int main(){
  cin>>a>>b;
  if(b==1)return cout<<0,0;
  if(a>=b)return cout<<1,0;
  b-=a;c=b/(a-1);
  cout<<(b%(a-1)==0?c+1:2+c);  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, 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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

ll f(vector<pair<ll, ll>> p){
    ll n = p.size();
    vector<vector<ll>> vec(n+1);
    rep(i, n){
        if(p[i].first > n) p[i].first = n;
        vec[p[i].first].push_back(p[i].second);
    }
    ll res = 0;
    priority_queue<ll> pq; 
    for(ll i = n; i >= 1; i--){
        rep(j, vec[i].size()){
            pq.push(vec[i][j]);
        }
        if(!pq.empty()){
            res += pq.top();
            pq.pop();
        }
    }
    return res;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll t; cin >> t;

    rep(T, t){
        ll ans = 0;
        ll n; cin >> n;
        vector<pair<ll, ll>> pl;
        vector<pair<ll, ll>> pr;
        rep(i, n){
            ll k, l, r; cin >> k >> l >> r;
            ll m = min(l, r);
            l -= m; r -= m;
            if(l > 0){
                pl.emplace_back(k, l);
            }else{
                pr.emplace_back(n-k, r);
            }
            ans += m;
        }

        ans += f(pl); ans += f(pr);
        cout << ans << endl;

    }

}

Measured memory_bytes: 14280
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
    int to;
    T cost;
    Edge() {};
    Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
    int n;
    bool directed;
    vector<vector<Edge<T>>> edges;
public:

    Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)){};
    Graph() {};

    void add(int from,int to, T cost) {
        edges[from].emplace_back(to, cost);
        if(!directed){
            edges[to].emplace_back(from,cost);
        }
    }

    int size() {
        return n;
    }
};


int main() {

    int S,W;

    cin >> S >>W;

    if(W>=S){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
/*	AtCoder AGC020 B Ice Rink Game
	1st Edition:2018.1.15 Monday
	Algorithm:Simulation
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cctype>
using namespace std;

#define is_lower(c) (c>='a' && c<='z')
#define is_upper(c) (c>='A' && c<='Z')
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c>='0' && c<='9')
#define stop system("PAUSE")
#define ForG(a,b,c) for(int (a)=c.head[b];(a);(a)=c.E[a].nxt)
#define For(a,b,c) for(int (a)=(b);(a)<=(c);++a)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define shl(x,y) ((x)<<(y))
#define shr(x,y) ((x)>>(y))
#define mp make_pair
#define pb push_back
#ifdef ONLINE_JUDGE
#define hash rename_hash
#define next rename_next
#define prev rename_prev
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef double db;
const ll inf=2000000007LL;
const double EPS=1e-10;
const ll inf_ll=(ll)1e18;
const ll maxn=100005LL;
const ll mod=1000000007LL;

int n;
ll a[maxn];

int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%lld",a+i);
	reverse(a+1,a+n+1);
	ll lb=2,ub=2,flag=0;
	For(i,1,n){
		ll now=a[i];
		ll l=(lb-1)/now*now+now,r=ub/now*now;
		if(l>ub){flag=1;break;}
		lb=l;ub=r+now-1;
	}
	if(flag) puts("-1");
	else printf("%lld %lld\n",lb,ub);
	return 0;
}

/*
4
3 4 3 2

5
3 4 100 3 2

10
2 2 2 2 2 2 2 2 2 2

*/

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int x,y,z;
  cin >> x >> y >> z;

  int t = x / (y+z);
  if(x-t*(y+z) < z) cout << t-1 << endl;
  else cout << t << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int Hi,HMAX,h,w,N,n,m,dp[1009][1<<12],A[22];
vector<int>sum;
map<char,int>M;
string s[1111];
int main(){
    while(cin>>Hi>>HMAX,Hi){
        sum.clear();
        int X=0,Y=0;
        M.clear();
        cin>>h>>w;
        r(i,h)cin>>s[i];
        cin>>m;
        r(i,m){
            char c;
            int x;
            cin>>c>>x;
            M[c]=x;
        }
        cin>>N;
        r(i,N){
            char c;
            int x;
            cin>>c>>x;
            while(x--){
                if(c=='U')Y--;
                if(c=='D')Y++;
                if(c=='R')X++;
                if(c=='L')X--;
                sum.push_back(M[s[Y][X]]);
            }
        }
        cin>>n;
        r(i,n){
            cin>>A[i];
        }
        memset(dp,0,sizeof(dp));
        dp[0][0]=Hi;
        for(int i=0;i<sum.size();i++){
            for(int j=0;j<(1<<n);j++){
                if(dp[i][j]<=0)continue;
                for(int k=0;k<n;k++){
                    if((1<<k)&j)continue;
                    dp[i][j|(1<<k)]=max(dp[i][j|(1<<k)],min(HMAX,dp[i][j]+A[k]));
                }
            }
            for(int j=0;j<(1<<n);j++){
                dp[i+1][j]=dp[i][j]-sum[i];
            }
        }
        bool ANS=0;
        r(i,(1<<n)){
            if(dp[sum.size()][i]>0)ANS=1;
        }
        cout<<(ANS?"YES":"NO")<<endl;
    }
}


Measured memory_bytes: 19256