akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

long long n,v[100005],m[100005],m1[100005],p1,p2,vp1,vp2,n1,n2,vn1,vn2;

int main()
{
    scanf("%lld",&n);
    for(int i=0;i<n;i++)
        scanf("%lld",&v[i]);
    for(int i=0;i<n;i+=2)
    {
        m[v[i]]++;
        if(m[v[i]]>p1)
        {
            p1=m[v[i]];
            vp1=v[i];
        }
    }
    for(int i=0;i<n;i+=2)
    {
        if((m[v[i]]>p2)&&(v[i]!=vp1))
        {
            p2=m[v[i]];
            vp2=v[i];
        }
    } ///////////////////////////
    for(int i=1;i<n;i+=2)
    {
        m1[v[i]]++;
        if(m1[v[i]]>n1)
        {
            n1=m1[v[i]];
            vn1=v[i];
        }
    }
    for(int i=1;i<n;i+=2)
    {
        if((m1[v[i]]>n2)&&(v[i]!=vn1))
        {
            n2=m1[v[i]];
            vn2=v[i];
        }
    }
    if(vp1!=vn1)
    {
        printf("%lld",n-p1-n1);
        return 0;
    }
    else //vp1==vn1
    {
        if(n1>p1)
        {
            printf("%lld",n-n1-p2);
            return 0;
        }
        if(n1<p1)
        {
            printf("%lld",n-p1-n2);
            return 0;
        }
        if(n1==p1)
        {
            if(n2>p2)
            {
                printf("%lld",n-p1-n2);
                return 0;
            }
            if(n2<p2)
            {
                printf("%lld",n-p1-p2);
                return 0;
            }
            if(n2==p2)
            {
                printf("%lld",n-p1-p2);
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 6092
#include<bits/stdc++.h>
using namespace std;int N,C,D[2][5001],i,j,*A,*B;
main(){A=D[0],B=D[1];cin>>N;fill_n(*D,1e4+2,1e9);A[1]=B[0]=0;for(;i<N-1&&cin>>C;i++)for(j=N/2;~j;j--)A[j+1]=min(A[j],B[j]+C),B[j]=min(A[j]+C,B[j]);cout<<min(A[N/2],B[N/2])<<endl;}

Measured memory_bytes: 1200
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    ArrayList<Integer>[] tree;
    int[] arr;
    int[] ansArr;
    int n;
    int[] dp;
    ArrayDeque<Integer[]> q = new ArrayDeque<>();

    void run() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        arr = new int[n];
        ansArr = new int[n];
        Arrays.fill(ansArr, -1);
        dp = new int[n + 1];

        Arrays.fill(dp, Integer.MAX_VALUE);
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        tree = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            tree[i] = new ArrayList<>();
        }
        for (int i = 0; i < n - 1; i++) {
            int u = sc.nextInt() - 1;
            int v = sc.nextInt() - 1;
            tree[u].add(v);
            tree[v].add(u);
        }

        dp[0] = arr[0];
        dfs(0);

        PrintWriter _out = new PrintWriter(System.out);
        for (int i = 0; i < n; i++) {
            _out.println(ansArr[i]);
        }
        _out.flush();

    }

    void dfs(int i) {
        ArrayList<Integer> nextIdxList = tree[i];
        int ans = lowerBound(dp, Integer.MAX_VALUE);
        ansArr[i] = ans;

        if (nextIdxList.isEmpty()) {
            return;
        }
        for (int nextIdx : tree[i]) {
            if (ansArr[nextIdx] != -1) {
                continue;
            }
            int next = arr[nextIdx];
            int j = lowerBound(dp, next);

            q.push(new Integer[]{j, dp[j]});
            dp[j] = next;

            dfs(nextIdx);
            Integer[] previous = q.remove();
            dp[previous[0]] = previous[1];
        }
    }


    public int upperBound(int[] array, int value) {
        int left = -1;
        int right = array.length;
        while (right - left > 1) {
            int middle = (right + left) / 2;
            if (array[middle] > value) {
                right = middle;
            } else {
                left = middle;
            }
        }
        return right;
    }

    public int lowerBound(int[] array, int value) {
        int left = -1;
        int right = array.length;
        while (right - left > 1) {
            int middle = (right + left) / 2;
            if (array[middle] >= value) {
                right = middle;
            } else {
                left = middle;
            }
        }
        return right;
    }


    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}



Measured memory_bytes: 121204
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cmath>
#include <set>
#include <vector>
using namespace std;
const int maxn=2000000000;
int n;
int _min=maxn;
int _max=-maxn;
int a;
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a);
        _max=max(_max,a-_min);
        _min=min(_min,a);
    }
    printf("%d\n",_max);

    return 0;
}

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    while(cin>>n&&n){
	int w,h; cin>>w>>h;
	int data[101][101]={};
	for(int i=0;i<n;++i){
	    int x,y; cin>>x>>y;
	    data[y][x]++;
	}
	int s,t; cin>>s>>t;
	int sum=0;
	for(int i=1;i<=t;++i)
	    for(int j=1;j<=s;++j)
		sum+=data[i][j];
	int maxv=sum;
	for(int i=1;i<=h-t+1;++i){
	    int z=sum;
	    for(int j=1;j<=w-s;++j){
		for(int k=0;k<t;++k){
		    z+=data[i+k][j+s];
		    z-=data[i+k][j];
		}
		maxv=max(maxv,z);
	    }
	    if(i!=h-t+1){
		for(int j=1;j<=s;++j){
		    sum+=data[i+t][j];
		    sum-=data[i][j];
		}
		maxv=max(maxv,sum);
	    }
	}
	cout<<maxv<<endl;
    }
    return 0;
}
		
		
		


Measured memory_bytes: 3048
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int x=in();int k=in();int d=in();
	
	x=abs(x);
	int t=x/d;
	if(k<=t)
	{
		cout<<abs(x-k*d);
		return 0;
	}

	x=abs(x-t*d);
	k-=t;
	//cout<<x<<" "<<k<<" "<<d<<"\n";
	if(k%2==1)
	{
		int ans=min(abs(x-d),abs(x+d));
		cout<<ans;
	}
	else 
	{
		cout<<x;	
	}
	
}

Measured memory_bytes: 3760
#! python3
# dice_i.py

class dice():
    def __init__(self, arr):
        self.top = arr[0]
        self.south = arr[1]
        self.east = arr[2]
        self.west = arr[3]
        self.north = arr[4]
        self.bottom = arr[5]

    def rotate(self, ope):
        if ope == 'S':
            self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
        elif ope == 'N':
            self.top, self.south, self.bottom, self.north = self.south, self.bottom, self.north, self.top
        elif ope == 'E':
            self.top, self.west, self.bottom, self.east = self.west, self.bottom, self.east, self.top
        elif ope == 'W':
            self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top

dc = dice([int(x) for x in input().split(' ')])
opes = list(input())

for op in opes:
    dc.rotate(op)

print(dc.top)


Measured memory_bytes: 5608
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), D = sc.nextInt(), E = sc.nextInt(), F = sc.nextInt();
		ArrayList<Integer> water = new ArrayList<Integer>(); // あり得る水の量を全列挙
		ArrayList<Integer> sugar = new ArrayList<Integer>(); // あり得る砂糖の量を全列挙
		for(int i = 0; 100 * A * i <= F; i++) {
			for(int j = 0; 100 * A * i + 100 * B * j <= F; j++) {
				water.add(100 * A * i + 100 * B * j);
			}
		}
		for(int i = 0; C * i <= F; i++) {
			for(int j = 0; C * i + D * j <= F; j++) {
				sugar.add(C * i + D * j);
			}
		}
		int maxvol = 0, maxsug = 0;
		for(int w : water) {
			for(int s : sugar) {
				if(E * w >= 100 * s && s + w <= F && (maxvol == 0 || s * maxvol >= maxsug * (w + s))) {
					maxvol = w + s;
					maxsug = s;
				}
			}
		}
		System.out.println(maxvol+" "+maxsug);
	}
}

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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

signed main() {
    int N, K;
    cin >> N >> K;

    vector<int> num_list;
    vector<int> div;
    for (int i=1;i*i<=N;i++) {
        div.pb(i);
        div.pb(N/i);
    }
    div.pb(0);
    sort(ALL(div));
    div.erase(unique(ALL(div)), div.end());

    REP(i, SZ(div)-1) {
        num_list.pb(div[i+1] - div[i]);
    }
    int _n = SZ(num_list);

    vector< vector <ll>> dp;
    dp.assign(_n, vector<ll>(K+1, 0));

    REP(i, _n) {
        dp[i][1] = num_list[i];
    }

    FOR(k, 2, K+1) {
        ll sum = 0;
        REP(n, _n) {
            sum += dp[n][k-1];
            sum %= MOD;

            dp[_n-n-1][k] = (dp[_n-n-1][1] * sum) % MOD;
        }
    }

    int ans = 0;
    REP(n, _n) {
        ans += dp[n][K];
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 52604
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
ll s, n, m;
ll f(ll b, ll n) {
    return n < b ? n : f(b, n / b) + n % b;
}
int main() {
    cin >> n >> s; m = sqrt(n) + 1;
    if (s > n) return puts("-1"), 0;
    if (s == n) return printf("%lld\n", s + 1), 0;
    for (ll i = 2; i <= m; ++i)
        if (f(i, n) == s) return printf("%lld\n", i), 0;
    ll b, q, res = 1e11; n -= s;
    for (ll p = 1; p * p <= n; ++p) {
        if (n % p == 0 ) {
            b = n / p + 1; q = s - p;
            if (q >= 0 && b >= 2 && q < b && p < b)
                res = min(res, b);
        }
    } printf("%lld\n", res == 1e11 ? -1 : res);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
#define int long long
#define rc(s) return cout<<s,0
//#define cin fin
//#define cout fout
using namespace std;


const int nmax=1e3+5;
const int mod=1e9+7;
const int mod1=998244353;

double n,k,ans;

void check(double i){
    double x=1;
    x/=2;
    double y=1;
    y/=n;
    if(i>=k) ans+=y;
    else{
        double c=1;
        c/=n;
        while(i<k){
            i*=2;
            c*=x;
        }
        ans+=c;
    }
}

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie();cout.tie();
    cin >> n >> k;
    cout<<fixed<<setprecision(10);
    for(int i=1;i<=n;i++){
        check(i);
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
vector<int>gr[N];
int dp[N+1];
int dfs(int src){
	if(dp[src]!=-1){
		return dp[src];
	}
	bool leaf=1;
	int ans=0;
	for(auto child:gr[src]){
		leaf=0;
		ans=max(ans,dfs(child));
	}
	return dp[src]=leaf?0:1+ans;
}
int main(){
	int n,m;
	cin>>n>>m;
	
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		gr[x].push_back(y);
	}
	memset(dp,-1,sizeof dp);
	int ans=0;
	for(int i=1;i<=n;i++){
		ans=max(ans,dfs(i));
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 11472
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

double calcSurfaceArea( double a, double b, double c )
{
    double cosA = ( b * b + c * c - a * a ) / ( 2 * b * c );
    double sinA = sqrt( 1 - cosA * cosA );
    return 0.5 * c * b * sinA;
}

int main()
{
    int a, l, x;

    while( cin >> a >> l >> x )
    {
        double max = 0;
        for( double i = 0.01; i < l + x; i += 0.01 )
        {
            double s = calcSurfaceArea( i, l, l + x - i );
            if( s > max )
                max = s;
        }
        cout << fixed << setprecision(10) << max + max + calcSurfaceArea( a, l, l ) << endl;
    }

    return 0;
}


Measured memory_bytes: 3324
#include <stdio.h>
#define min(a,b) (a)<=(b)?(a):(b)
int main()
{
    int a,b,c,i,j,k;
    long x,y,ans;
    scanf("%d%d%d%ld%ld",&a,&b,&c,&x,&y);
    if(a+b>=2*c){
        if(x>=y){
            ans=min((2*x*c),(2*y*c+(x-y)*a));
        }else{
            ans=min((2*y*c),(2*x*c+(y-x)*b));
        }
    }else {
        ans=x*a+y*b;
    }
        
    printf("%ld",ans);
    return 0;
}


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

typedef int Capacity;
struct Edge {
    int src, dst;
    Capacity cap;
    Edge(int src_, int dst_, Capacity cap_) :
        src(src_), dst(dst_), cap(cap_) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Capacity> Array;
typedef vector<Array> Matrix;

const int inf = 1e8;

struct FordFulkerson {
    typedef vector<vector<Capacity>> Matrix;
    int n, t;
    vector<bool> vis;
    Matrix cap, flow;
    vector<vector<int>> g;
    FordFulkerson(int n){ *this = FordFulkerson(Graph(n)); }
    FordFulkerson(const Graph &graph)
        : n(graph.size()), cap(n, Array(n)),
          flow(n, Array(n)), g(n, vector<int>()){
        rep(i,n)
            for(const Edge &e : graph[i])
                add_edge(e.src, e.dst, e.cap);
    }
    void add_edge(int u, int v, Capacity c){
        cap[u][v] += c;
        cap[v][u] += c;
        flow[v][u] += c;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    Capacity solve(int s, int t){
        this->t = t;
        Capacity res = 0, f = -1;
        while(f){
            vis.assign(n,false);
            res += (f = augment(s,inf));
        }
        return res;
    }
    Capacity augment(int v, Capacity lim){
        vis[v] = true;
        if(v == t) return lim;
        for(const int &i : g[v]){
            if(vis[i] || flow[v][i] == cap[v][i]) continue;
            Capacity f = augment(i, min(lim, cap[v][i] - flow[v][i]));
            flow[v][i] += f;
            flow[i][v] -= f;
            if(f) return f;
        }
        return 0;
    }
};

int gcd(int a, int b){
    return b == 0 ? a : gcd(b,a%b);
}

int main(){
    int n,m;
    while(cin >> n >> m && n){
        Graph g(1002);
        int s = 1000, t = 1001;
        int a[555], b[555];
        rep(i,n) cin >> a[i];
        rep(i,m) cin >> b[i];
        rep(i,n)rep(j,m){
            if(gcd(a[i],b[j]) != 1){
                g[i].emplace_back(i,j+500,1);
            }
        }
        rep(i,n) g[s].emplace_back(s,i,1);
        rep(i,m) g[i+500].emplace_back(i+500,t,1);
        cout << FordFulkerson(g).solve(s,t) << endl;
    }
}

Measured memory_bytes: 12760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine().Split(' ');
            var k = int.Parse(n[0]);
            var x = int.Parse(n[1]);
            if (500 * k >= x)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

map<pair<ll,ll>,ll> memo;
ll f(ll s,ll x){
    pair<ll,ll> P = make_pair(s,x);
    if(memo.count(P))return memo[P];
    if(s<=3 && x<=3){
        ll ans = 0;
        for(int a=0;a<4;a++)for(int b=0;b<4;b++){
            if((a&b)!=b)continue;
            if(a+b<=s && (a^b)<=x)ans++;
        }
        return memo[P] = ans;
    }else{
        ll ans = (f(s/2,x/2)+f((s-1)/2,(x-1)/2)+f((s-2)/2,x/2)) % 1000000007;
        return memo[P] = ans;
    }
}

int main(void){
    ll n;
    cin>>n;
    ll ans = f(n,n);
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int k, x;
  cin >> k >> x;

  int min = x - (k - 1);
  int max = x + (k - 1);

  for (int i = min; i <= max; i++) {
    if (i == max) {
      cout << i << endl;
    } else {
      cout << i << " ";
    }
  }
  return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,k){
        vector<int> b(n+1);
        rep(j,n){
            int l = max(j-a[j],0);
            int r = min(n, j+a[j]+1);
            b[l]++;
            b[r]--;
        }
        rep(j,n) b[j+1] += b[j];
        b.pop_back();
        if(a==b) break;
        a=b;
    }
    rep(i, n) cout << a[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;

int gcd(int a,int b){
    a=abs(a); b=abs(b);
    if(a==0||b==0) return a+b;
    else if(a>=b) return gcd(a%b,b);
    else return gcd(a,b%a);
}

int main(){
    int n,x; cin>>n>>x;
    int g; cin>>g; g=abs(g-x);
    FOR(i,1,n){
        int a; cin>>a;
        g=gcd(a-x,g);
    }
    co(g);
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
	InitIO() {
		cin.tie(nullptr);
		ios_base::sync_with_stdio(false);
		cout << fixed << setprecision(30);
	}
} init_io;

//main code
int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	// マイナスは大きい方，プラスは小さい方から取り出す
	priority_queue<LL> m;
	priority_queue<LL,vector<LL>, greater<LL>> p;
	LL ans = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a >= 0) {
			p.push(a);
		}
		else {
			m.push(a);
		}
		ans += abs(a);
	}
	if (p.size() == 0) { // 全部マイナス
		p.push(m.top());
		ans += m.top()*2;
		m.pop();
	}
	else if (m.size() == 0) { // 全部プラス
		m.push(p.top());
		ans -= p.top()*2;
		p.pop();
	}
	cout << ans << endl;

	int res = 0;
	if (p.size() == 1) {
		cout << p.top() << " " << m.top() << endl;
		res += p.top() - m.top();
		p.pop();
		m.pop();
		for(;!m.empty(); m.pop()) {
			cout << res << " " << m.top() << endl;
			res -= m.top();
		}
		return 0;
	}
	res = m.top();
	m.pop();
	for (;p.size() > 1; p.pop()) {
		cout << res << " " << p.top() << endl;
		res -= p.top();
	}

	cout << p.top() << " " << res << endl;
	res = p.top() - res;
	p.pop();

	for (;!m.empty(); m.pop()) {
		cout << res << " " << m.top() << endl;
		res -= m.top();
	}

	return 0;
}



Measured memory_bytes: 2804
n = int(input())
A = list(map(int,input().split()))
mod = (10**9) + 7
t = 0
sum = 0
for i in range(1,n):
    sum += A[i]
for i in range(n-1):
    t += (A[i]*sum)%mod
    sum -=  A[i+1]
t = t%mod
print(t)

Measured memory_bytes: 31632
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
   int N;
   cin >> N;
   int a[N];
   for(int i=0;i<N;i++) cin >> a[i];
   int tmp=a[0];
   for(int i=1;i<N;i++){
      tmp=tmp^a[i];
   }
   bool ans=false;
   for(int i=0;i<N;i++){
      int res=tmp^a[i];
      if(res==a[i]){
         ans=true;
      }else{
         ans=false;
         break;
      }
   }
   if(ans){
      cout << "Yes" << endl;
   }else{
      cout << "No" << endl;
   }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll n,arr[200010],a,b,c,ans=1e18,s1,s2,s3,s4;

ll sum( ll l , ll r ){ return arr[r]-arr[l-1]; }

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for(ll i=1; i<=n; i++) cin >> arr[i] , arr[i]+=arr[i-1];

    a = 1;
    c = 3;
    for(b=2; b<n-1; b++){

        while( a+1 < b && abs( sum( 1 , a+1 )-sum( a+2 , b ) ) <= abs( sum( 1 , a ) - sum( a+1 , b ) ) ) a++;
        while( c <= b ) c++;
        while( c+1 < n && abs( sum( b+1 , c+1 )-sum( c+2 , n ) ) <= abs( sum( b+1 , c ) - sum(c+1,n)) ) c++;

        s1 = sum( 1 , a );
        s2 = sum( a+1 , b );
        s3 = sum( b+1 , c );
        s4 = sum( c+1 , n );

        //cout << a << " " << b << " " << c << " " << s1 << " " << s2 << " " << s3 << " " << s4 << "\n";

        ans = min( ans , max( max( s1 , s2 ) , max( s3 , s4 ) ) - min( min( s1 , s2 ) , min( s3 , s4 ) ) );

    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 1792
n=int(input())
a=list(map(int,input().split()))
suma=sum(a)
q=int(input())
b=[]
c=[]
for i in range(q):
  b_,c_=map(int,input().split())
  b.append(b_)
  c.append(c_)

counter=[0]*(10**5+1)
for i in a:
  counter[i]+=1
new_sum=suma
for i in range(q):
  new_sum=new_sum-b[i]*counter[b[i]]+c[i]*counter[b[i]]
  
  counter[c[i]]+=counter[b[i]]
  counter[b[i]]=0
  print(new_sum)

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

int main(){
	int n,w;
	cin>>n>>w;
	vector<vector<long long>>dp(n+1,vector<long long> (w+1));
  vector<pair<int,int>>weights(n);
  for(int i=0;i<n;i++) {
    int x,y;
    cin>>x>>y;
    weights[i]={x,y};
  }

  for(int i=1;i<n+1;i++){
    for(int j=1;j<w+1;j++){
      dp[i][j]=dp[i-1][j];
      if (j-weights[i-1].first>=0){
        dp[i][j]=max(dp[i][j],dp[i-1][j-weights[i-1].first]+weights[i-1].second);
      }
    }
  }
  cout<<dp[n][w]<<endl;
	return 0;
}


Measured memory_bytes: 83036
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>
#include <complex>
  
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
  
const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef complex<double> P;
int n;
  
double cross(P p1,P p2) {
    return (real(p1)*imag(p2) - imag(p1)*real(p2));
}
double calc_S(P p1,P p2,P p3) {
    double ret = 0.0;
    p1 -= p3;
    p2 -= p3;
  
    ret = cross(p1,p2)/2.0;
      
    return abs(ret);
}
  
int main() {
    cin>>n;
    while(n-->0) {
        double x1_,y1_;
        double x2_,y2_;
        double x3_,y3_;
        cin>>x1_>>y1_>>x2_>>y2_>>x3_>>y3_;
        P p1(x1_,y1_);
        P p2(x2_,y2_);
        P p3(x3_,y3_);
        P A = p1-p2;
        P B = p2-p3;
        P C = p1-p3;
        double S = calc_S(p1,p2,p3);
        double R = abs(A)*abs(B)*abs(C)/S;
        R /= 4.0;
          
        P A1 = 2.0*(p2-p1);
        P B1 = 2.0*(p3-p1);
        P C1 = P(norm(p1)-norm(p2),norm(p1)-norm(p3));
        double X = cross(P(imag(A1),imag(B1)),C1)/cross(A1,B1);
        double Y = cross(C1,P(real(A1),real(B1)))/cross(A1,B1);
        printf("%.3lf %.3lf %.3lf\n",X,Y,R);
  
    }
    return 0;
}

Measured memory_bytes: 1252
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

const ll mod = 1000000007;
const ll INF = 100000010000;

ll kai[100010];
ll bit[200010];



/*ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= 200005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

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

ll pow_mod(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2 == 1)
	{
		return x * pow_mod(x, y - 1) % mod;
	}
	else
	{
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x)
{
	return pow_mod(x, mod - 2);
}

ll com(ll x, ll y)
{
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
}

void init()
{
	/*kai[0] = 1;
	for (int i = 1; i <= 10000; i++)
	{
		kai[i] = kai[i - 1] * i % mod;
	}*/
	
}

void output()
{
	
}

void solve()
{
	ll N;
	cin >> N;
	vector<P> vec;
	
	for (int i = 0; i < N; i++)
	{
		ll X, L;
		cin >> X >> L;
		vec.push_back(P(X + L - 1, X - L + 1));
	}
	sort(vec.begin(), vec.end());
	ll ans = 1;
	ll t = vec[0].first;
	for (int i = 1; i < N; i++)
	{
		if (vec[i].second > t + 1)
		{
			ans++;
			t = vec[i].first;
		}
	}
	cout << ans << endl;
}

int main()
{
	init();

	solve();



	output();
	ll N;
	cin >> N;
}


Measured memory_bytes: 2420
//#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>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, a, n) for(ll i = a; i < (ll)(n); ++i)
#define repr(i, a, n) for(ll i = n - 1; (ll)a <= i; --i)
#define ENDL '\n'
typedef pair<int, int> Pi;
typedef pair<ll, ll> PL;
constexpr ll mod = 1000000007;  // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 + 99);
const ld PI = acos((ld)-1);
const vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T, typename U> inline bool chmin(T& t, const U& u) {
  if(t > u) {
    t = u;
    return 1;
  }
  return 0;
}
template <typename T, typename U> inline bool chmax(T& t, const U& u) {
  if(t < u) {
    t = u;
    return 1;
  }
  return 0;
}
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template <typename T, typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(; n; n >>= 1) {
    if(n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template <typename T, typename Y>
ostream& operator<<(ostream& os, const pair<T, Y>& p) {
  return os << "{" << p.fs << "," << p.sc << "}";
}
template <typename T> ostream& operator<<(ostream& os, const V<T>& v) {
  os << "{";
  for(auto e : v) os << e << ",";
  return os << "}";
}
template <typename... Args> void debug(Args&... args) {
  for(auto const& x : {args...}) { cerr << x << ' '; }
  cerr << ENDL;
}

signed main() {
  cin.tie(0);
  cerr.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  rep(i, 0, 28) {
    if(n == (1 << i)) {
      cout << "No" << ENDL;
      return 0;
    }
  }

  cout << "Yes" << ENDL;
  cout << n + 1 << " 2" << ENDL;
  rep(i, 2, n) {
    cout << i << " " << i + 1 << ENDL;
    cout << i + 1 << " " << 1 << ENDL;
    cout << 1 << " " << n + i << ENDL;
    cout << n + i << " " << n + i + 1 << ENDL;
    i++;
  }

  if(n % 2 == 0) {
    ll exp = 0;
    repr(i, 0, 28) {
      if((n + 1) & (1 << i)) {
        exp = i;
        break;
      }
    }
    debug(exp);
    ll x = (1 << exp), y = n + 1 - x;

    cout << n << " " << y << ENDL;
    cout << n + x << " " << 2 * n << ENDL;
  }
}
//! ( . _ . ) !
// CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc085/tasks/abc085_d

"""
import sys
from sys import stdin
from math import ceil
input = stdin.readline


def solve(slashes, throws, H):
    max_slash = max(slashes)
    v_throws = [x for x in throws if x > max_slash]
    v_throws.sort(reverse=True)
    total_throws = sum(v_throws)
    if total_throws > H:
        ans = len(v_throws)
        while total_throws >= H:
            p = v_throws.pop()
            total_throws -= p
            ans -= 1
        return ans + 1

    return ceil((H-total_throws) / max_slash) + len(v_throws)


def main(args):
    slashes = []
    throws = []

    N, H = map(int, input().split())
    for _ in range(N):
        a, b = map(int, input().split())
        slashes.append(a)
        throws.append(b)
    ans = solve(slashes, throws, H)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

int main(void){
    int n, k, q;
    
    cin >> n >> k >> q;
    
    vector<int> a(100001), d(100001);
    vector<string> ans(n);
    
    rep(i, q){
        cin >> a.at(i);
        d.at(a.at(i)-1)++;
    }
    
    rep(i, n){
        if((k - q + d.at(i)) > 0){
            ans.at(i) = "Yes";
        } else {
            ans.at(i) = "No";
        }
        cout << ans.at(i) << endl;
    }
    
    return 0;
}

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

ll N, P;
ll A[60];

int main() {
    cin >> N >> P;
    for (int i = 0; i < N; i++) cin >> A[i];

    bool all_even = true;
    for (int i = 0; i < N; i++) {
        if (A[i] % 2 != 0) {
            all_even = false;
            break;
        }
    }

    if (all_even) {
        if (P % 2 == 0) cout << (ll)pow(2, N) << endl;
        else cout << 0 << endl;
    }
    else {
        cout << (ll)pow(2, N-1) << endl;
    }

    



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
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;
}

#define MAX_N 100001

ll uf_par[MAX_N];  //親
ll uf_rank[MAX_N]; //木の深さ
ll uf_size[MAX_N];  //木のサイズ

//初期化、深さ0のn個の親を作る
void init(ll n)
{
    for (int i = 0; i < n; i++)
    {
        uf_par[i] = i;
        uf_rank[i] = 0;
        uf_size[i] = 1;
    }
}

//木の根を求める find
ll find(ll x)
{
    if (uf_par[x] == x) //親が自分なら根
        return x;
    else //自分の親の親を探しに行く
        return uf_par[x] = find(uf_par[x]);
}

//xとyの集合を併合　union
ll unite(ll x, ll y)
{
    ll num;
    x = find(x);
    y = find(y);
    num = uf_size[x] * uf_size[y];

    if (uf_rank[x] < uf_rank[y]) //深いほうの根を使う
    {
        uf_par[x] = y;
        uf_size[y] = uf_size[y] + uf_size[x];
    }
    else
    {
        uf_par[y] = x;
        uf_size[x] = uf_size[x] + uf_size[y];
        if (uf_rank[x] == uf_rank[y]) //深さが同じなら、併合後に1深くなる
            uf_rank[x]++;
    }
    return num;
}

//xとyが同じ集合かどうか
bool same(ll x, ll y)
{
    return find(x) == find(y);
}

int main()
{
    ll N, M;
    cin >> N >> M;
    ll AB[MAX_N][2];
    REP(i, M)
    {
        cin >> AB[i][0] >> AB[i][1];
    }
    init(N);
    vi ans;
    ans.push_back(N * (N - 1) / 2);
    int A, B;
    for (int i = M - 1; i >= 0; i--)
    {
        A = AB[i][0];
        B = AB[i][1];
        if (same(A, B))
        {
            ans.push_back(ans[ans.size() - 1]);
            continue;
        }
        ans.push_back(ans[ans.size() - 1] - unite(A, B));
    }
    REP(i, M)
    {
        cout << ans[ans.size() - 2 - i] << endl;
    }

    //system("pause");
}

Measured memory_bytes: 6132
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

map<string,int> dp[222222];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	dp[0][s.substr(0,1)]=1;
	for(int i=1;i<s.length();i++)
	{
		for(int j=0;j<2;j++)
		{
			string cur=s.substr(i-j,j+1);
			if(i-j>0)
			{
				for(auto X:dp[i-j-1])
				{
					if(X.fi!=cur)
					{
						dp[i][cur]=max(dp[i][cur],X.se+1);
					}
				}
			}
			else
			{
				dp[i][s.substr(0,i+1)]=1;
			}
		}
	}
	int ans=0;
	for(auto X:dp[int(s.length())-1]) ans=max(ans,X.se);
	cout<<ans<<'\n';
}


Measured memory_bytes: 54676
#include <bits/stdc++.h>
int k, tot;
long long a[100005];
void dfs(long long x) {	
	if (x > 3234566667) return;
	a[++tot] = x;
	int lst = x % 10;
	for (int i = std::max(0, lst - 1); i <= std::min(9, lst + 1); ++i) dfs(x * 10 + i);
}
int main() {
	std::cin >> k;
	for (int i = 1; i <= 9; ++i) dfs((long long)i);
	std::sort(a + 1, a + tot + 1);
	std::cout << a[k] << '\n';
}


Measured memory_bytes: 1024
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut g = vec![vec![]; n];
    for _ in 1..n {
        let a: usize = it.next().unwrap().parse().unwrap();
        let b: usize = it.next().unwrap().parse().unwrap();
        let w: u32 = it.next().unwrap().parse().unwrap();
        g[a].push((b, w));
        g[b].push((a, w));
    }
    let mut r = (0, 0);
    for _ in 0..2 {
        let mut stack = vec![(r.1, r.1, 0)];
        while let Some((v, p, d)) = stack.pop() {
            r = std::cmp::max(r, (d, v));
            for &(u, w) in &g[v] {
                if u != p {
                    stack.push((u, v, d + w));
                }
            }
        }
    }
    println!("{}", r.0);
}

fn main() {
    run();
}



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

using namespace std;

int main(int argc, char const *argv[]) {
  string S;
  cin >> S;
  int length = S.length();
  int count0 = 0;
  int count1 = 0;

  for (int i = 0; i < length; i++) {
    if (S[i] == '0') {
      count0++;
    } else {
      count1++;
    }
  }

  cout << min(count0, count1) * 2 << "\n";
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
 
int main(){
    char s[12] = {0};
    int count;
    int i;
    int m;
    int c=0;
    
    gets(s);
    for(i=0;i<12;i++){
        //printf("%d\n",s[i]);
        if(s[i] == 0){
            count = i-1;
            break;
        }
    }
    if(count%2==1){
        //printf("a\n");
        m = (count-1)/2;
        for(i=0;i<=m;i++){
            if(s[i]=='i'){
                if(s[count-i]=='i'){
                    
                }
                else{
                    c++;
                }
            }
            else if(s[i]=='w'){
                if(s[count-i]=='w'){
                    
                }
                else {
                    c++;
                }
            }
            else if(s[i]=='('){
                if(s[count-i]==')'){
                    
                }
                else {
                    c++;
                }
            }
            else if(s[i]==')'){
                if(s[count-i]=='('){
                    
                }
                else {
                    c++;
                }
            }
            
        }
    }
    else{
        m = count/2;
        for(i=0;i<m;i++){
            if(s[i]=='i'){
                if(s[count-i]=='i'){
                    
                }
                else{
                    c++;
                }
            }
            else if(s[i]=='w'){
                if(s[count-i]=='w'){
                    
                }
                else {
                    c++;
                }
            }
            else if(s[i]=='('){
                if(s[count-i]==')'){
                    
                }
                else {
                    c++;
                }
            }
            else if(s[i]==')'){
                if(s[count-i]=='('){
                    
                }
                else {
                    c++;
                }
            }
        }
        if(s[m]=='('||s[m]==')'){
            c++;
        }
    }
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 944
s = int(input())
MOD = 10**9 + 7
C = [0]*(s + 1)
C[0] = 1
for n in range(3, s+1): # n:[3,s]
    for i in range(3, n+1): # i:[3,n], sum(C[0,n-3])
        C[n] += C[n-i]
        C[n] %= MOD
print(C[s])


Measured memory_bytes: 9128
def main():
    Hit,N = map(int, input().split())
    A = [0]*N
    B = [0]*N
    H = [-1]*(10**5+10000)
    mi = 10**10
    for i in range(N):
        A[i] ,B[i] = map(int, input().split())
    for i in range(N):
        H [A[i]] = B[i] if H[A[i]] == -1 else min(H [A[i]],B[i])
        if A[i] >= Hit:
            mi = min(mi,B[i])
        for j in range(Hit+1):
            if H[j]!=-1:
                H[j+A[i]] = B[i] + H[j] if H[j+A[i]] == -1 else min(H[j+A[i]],B[i]+H[j])
                if j+A[i] >= Hit:
                    mi = min(mi,B[i] + H[j])
    print(mi)






if __name__ == '__main__':
    main()

Measured memory_bytes: 74288
# A - 台形

# 上底の長さが a、下底の長さが b、高さが h の台形があります。

# 台形の面積を求める

# a を標準入力から得る
a = int(input())
# b を標準入力から得る
b = int(input())
# h を標準入力から得る
h = int(input())
# print(a, b, h)

# 台形の面積 = (上辺 + 下辺) * 高さ / 2
answer = int((a + b) * h / 2)

# 面積を出力
print(answer)


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

int main()
{
	int a[3], b[3];
	vector<int> ans(4, 0);
	for (int i = 0; i < 3; ++i)
	{
		cin >> a[i] >> b[i];
		if (a[i] == 1 || b[i] == 1) ++ans[0];
		if (a[i] == 2 || b[i] == 2) ++ans[1];
		if (a[i] == 3 || b[i] == 3) ++ans[2];
		if (a[i] == 4 || b[i] == 4) ++ans[3];
	}
	sort (ans.begin(), ans.end(), greater<int>());
	cout << (ans[0] < 3 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int f=0,m=n;
    while(m>0){
        f+=m%10;
        m/=10;
    }
    if(n%f==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}   


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

using namespace std;

using int64 = long long;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  for(int i = 0; i < K; i++) {
    if(i % 2 == 0) {
      if(A & 1)--A;
      int t = A / 2;
      B += t;
      A -= t;
    } else {
      if(B & 1)--B;
      int t = B / 2;
      A += t;
      B -= t;
    }
  }
  cout << A << " " << B << endl;
}






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

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
//using ll = long long;
//using P = pair<int,int>;

class UnionFind {
public:
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main(){
    int n, q;
    cin >> n >> q;
    
    UnionFind tree(n);
    
    rep(i, q){
        int com, x, y;
        cin >> com >> x >> y;
        
        if(com){
            if (tree.same(x, y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
        else{
            tree.unite(x, y);
        }
    }
}


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

using namespace std;

using int64 = long long;

int main() {
  int N, A[200000];
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] -= i + 1;

  }
  sort(A, A + N);
  int64 ret = 1LL << 60;
  for(int mex = max(0, N / 2 - 2); mex < min(N, N / 2 + 2); mex++) {
    int64 cost = 0;
    for(int i = 0; i < N; i++) {
      cost += abs(A[i] - A[mex]);
    }
    ret = min(ret, cost);
  }
  cout << ret << endl;
}

Measured memory_bytes: 1024
def main():
    N, M = map(int, input().split())
    cnt = [1] * (N+1)
    cand = set([1])
    for _ in range(M):
        x, y = map(int, input().split())
        cnt[x] -= 1
        cnt[y] += 1
        if x in cand:
            cand.add(y)
            if cnt[x] == 0:
                cand.remove(x)
    print(len(cand))


if __name__ == "__main__":
    main()


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

int main(){
	string a, b;
	cin >> a >> b;
	int n = stoi(a + b);
	for(int i=0; i<=1000; i++){
		if(i*i == n){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;	
}


Measured memory_bytes: 256
s = gets.chomp
t = gets.chomp

head = Array.new(26)
tail = Array.new(26)

ans = "Yes"
s.length.times do |i|
  a = s[i].ord - "a".ord
  b = t[i].ord - "a".ord

  if head[a] || tail[b]
    if head[a] != b || tail[b] != a
      ans = "No"
    end
  end
  head[a] = b
  tail[b] = a
end

puts ans

Measured memory_bytes: 2624
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
int a[3][3];
map< int , int > mp;
int n;
bool check(){
	//bool flag = false;
	int cnt;
	for(int i = 0 ; i < 3 ; i++){
		cnt = 0;
		for(int j = 0 ; j < 3 ; j++){
			if(mp[a[i][j]])
				cnt++;
		}
		if(cnt == 3)
			return true;
		cnt = 0;
		for(int j = 0 ; j < 3 ; j++){
			if(mp[a[j][i]])
				cnt++;
		}
		if(cnt == 3)
			return true;
	}
	cnt = 0;
	for(int i = 0 ; i < 3 ; i++){
		for(int j = 0 ; j < 3 ; j++){
			if(i == j  && mp[a[i][j]])
				cnt++;
		}
	}
	if(cnt == 3)
		return true;
	cnt = 0;
	for(int i = 0 ; i < 3 ; i++){
		for(int j = 0 ; j < 3 ; j++){
			if(i + j == 2 && mp[a[i][j]])
				cnt++;
		}
	}
	if(cnt == 3)
		return true;
	return false;
}
int main()
{
	for(int i = 0 ; i < 3 ; i++){
		for(int j = 0 ; j < 3 ; j++){
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		int x;
		cin >> x;
		mp[x]++;
	}
	int flag = check();
	if(flag == true)
		cout << "Yes" << endl;
	else 
		cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int H, A, ans, ans_a;

int main() {
  cin >> H >> A;
  ans = 0;
  ans_a = 0;
  
  ans = H / A;
  ans_a = H % A;
  
  if ( ans_a == 0 ) {
    cout << ans << endl;
  }
  else {
    cout << ans + 1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int A, B, C, D;
    int c = 1;
    scanf("%d %d %d %d", &A, &B, &C, &D);
    
    while(A > 0 && C > 0){
        if(c % 2 == 1)
            C = C - B;
        else
            A = A - D;
        c++;
    }
    if(A <= 0) printf("No\n");
    else printf("Yes\n");
}

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

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

  array<int, 18> pow2;
  vector<double> ns(N);

  int tmp = 1;
  for (auto & x : pow2) {
    x = tmp;
    tmp *= 2;
  }

  // q(n) は サイコロの目が n-1 の確立
  for (int i = 1; i <= N; ++i) {
    for (int j = 0;; ++j) {
      if (K <= i*pow2.at(j))  {
        ns.at(i-1) = (1.0/(double)pow2.at(j));
        break;
      }
    }
  }
  double ans = 0.0;
  for (auto i : ns) {
    ans += i;
  }
  ans /= (double)N;

  cout << fixed << setprecision(9) << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <queue>
using namespace std;

int H,W,C;
int ti[4000][5] = {};
int F[10][10] = {};
int dx[4] = {-1,1,0,0},dy[4] = {0,0,-1,1};
int con[10][10] = {};

bool in(int x,int y){
    return 1<=x && x<=H && 1<=y && y<=W;
}

int main(){
    int cnt = 1;
    for(int a=1;a<=6;a++){
        for(int b=1;b<=6;b++){
            for(int c=1;c<=6;c++){
                for(int d=1;d<=6;d++){
                    ti[cnt][0] = a;
                    ti[cnt][1] = b;
                    ti[cnt][2] = c;
                    ti[cnt][3] = d;
                    cnt++;
                }
            }
        }
    }
    while(true){
        cin >> H;
        if(H==0) break;
        cin >> W >> C;
        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                cin >> F[i][j];
            }
        }
        int ans = 0;
        for(int t=1;t<cnt;t++){
            ti[t][4] = C;
            int now = 1;
            for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) con[i][j] = 0;
            con[1][1] = 1;
            for(int i=1;i<=H;i++){
                for(int j=1;j<=W;j++){
                    if(F[i][j]!=F[1][1]) continue;
                    if(i==1 && j==1) continue;
                    for(int l=0;l<4;l++){
                        int nx = i+dx[l],ny = j+dy[l];
                        if(in(nx,ny) && con[nx][ny]==1 && F[i][j]==F[1][1]){
                            con[i][j] = 1;
                            now++;
                            break;
                        }
                    }
                }
            }
            for(int k=0;k<5;k++){
                queue<pair<int,int>> Q;
                for(int i=1;i<=H;i++){
                    for(int j=1;j<=W;j++){
                        if(con[i][j]==1) Q.push({i,j});
                    }
                }
                while(!Q.empty()){
                    pair<int,int> p = Q.front(); Q.pop();
                    int x = p.first,y = p.second;
                    for(int l=0;l<4;l++){
                        int nx = x+dx[l],ny = y+dy[l];
                        if(in(nx,ny) && F[nx][ny]==ti[t][k] && con[nx][ny]==0){
                            con[nx][ny] = 1;
                            now++;
                            Q.push({nx,ny});
                        }
                    }
                }
            }
            ans = max(ans,now);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3088