akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main()
{
  int n, k;
  cin >> n;
  cin >> k;
  string s;
  cin >> s;
  
  int gap = 0;
  for (int i = 0; i < n - 1; ++i)
  {
    if (s[i] == 'R' && s[i + 1] == 'L') ++gap;
  }
  
  int eGap = 0;
  if (s[0] == 'L') ++eGap;
  if (s[n-1] == 'R') ++eGap;
  
  int unhappy;
  if (k < gap)
  {
    unhappy = 2 * (gap - k) + eGap;
  }
  else if (k == gap)
  {
    unhappy = eGap == 0 ? 1 : eGap;
  }
  else
  {
    unhappy = 1;
  }
  cout << (n - unhappy) << endl;
  
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>

using namespace std;

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

#define rep(i,x) for(Int i = 0; i < (Int)(x); i++)
#define rrep(i,x) for(Int i = ((Int)(x) - 1); i >= 0; i--)
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back


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

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

Int dx[4] = {1,0,-1,0};
Int dy[4] = {0,1,0,-1};
const Int INF = 1001002003004005006ll;
const Int mod = 1e9 + 7;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//








Int x, y;

Int gao(Int x, Int y){
        if(x <= y) return y-x;
        else return INF;
}

int main(){
        cin >> x >> y;
        cout << min(min(gao(x,y), gao(-x,y)+1), min(gao(-x,-y)+2, gao(x,-y)+1)) << endl;
        return 0;
}















Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)

	A := getInt()
	B := getString()

	for i := 0; i < len(B); i++ {
		if B[i] == '.' {
			B = B[:i] + B[i+1:]
		}
	}

	b, _ := strconv.Atoi(B)
	out(A * b / 100)
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 0x3f3f3f3f;
const ll LINF = 1ll << 55;
const ll MOD = 1e9 + 7;
const ll MAXN = 400 + 5;
const ll MAXK = 1e5 + 10;

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

int main() {
    ll N, M;
    cin >> N >> M;
    if (N == 1 && M == 1) {
        cout << 1 << endl;
    } else if (N == 1) {
        cout << M - 2 << endl;
    } else if (M == 1) {
        cout << N - 2 << endl;
    } else {
        cout << (N - 2) * (M - 2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
while 1:
    n = int(input())
    if n == 0:
        break
    x = {}
    for i in range(n):
        ID,m1,s1,m2,s2,m3,s3,m4,s4 = map(int,input().split())
        r = m1*60+s1 + m2*60+s2 + m3*60+s3 + m4*60+s4
        x[ID] = r
    x = sorted(x.items(), key=lambda i: i[1])
    print(x[0][0])
    print(x[1][0])
    print(x[n-2][0])


Measured memory_bytes: 6436
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
//vvi(n, vector<int>(m, -1))
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(a) (a).begin(), (a).end()
#define out(x) cout << (x) << endl;

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> x >> y;
  f = 0;
  f = max(x+(x-1), x+y);
  f = max(f, y+(y-1));
  out(f);
}

Measured memory_bytes: 256
#include <iostream>
#define int64 long long int
using namespace std;
const int mod = 1e9+7 , MAX = 400009 ;
int64 cnt[MAX] ;
int expo(int a,int n){
    int ret=1;
    while(n>0){
        if(n&1)  ret = (1LL * ret * a)%mod ;
        a = (1LL *a * a)%mod ;
        n>>=1;
    }
    return ret;
}
int main(){
    int n , k  ;
    scanf("%d%d",&n,&k);
    int64 ret =0  ;
    for(int i=k;i;i--){
        cnt[i] = expo(k/i,n);
        for(int j=i+i;j<=k;j+=i){
            cnt[i] += mod-cnt[j];
            cnt[i] %= mod ;
        }
        ret += (1LL * i * cnt[i]);
        ret %= mod ;
    }
    printf("%lld\n",ret);
}

Measured memory_bytes: 4500
import java.util.Arrays;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N;
	static int[][] cost;

	static int solve() {
		PriorityQueue<State> q = new PriorityQueue<State>();
		int[] ord = new int[N];
		for (int i = 0; i < N; ++i) {
			ord[i] = i;
		}
		q.add(new State(0, ord));
		HashSet<State> visited = new HashSet<State>();
		int ans = 0;
		while (!q.isEmpty()) {
			State cur = q.poll();
			if (visited.contains(cur)) continue;
			ans = cur.v;
			visited.add(cur);
			for (int i = 0; i < N; ++i) {
				for (int j = i + 1; j < N; ++j) {
					swap(cur.ord, i, j);
					State next = new State(cur.v + cost[i][j], cur.ord);
					if (!visited.contains(next)) {
						q.add(next);
					}
					swap(cur.ord, i, j);
				}
			}
		}
		return ans;
	}

	static void swap(int[] a, int i, int j) {
		int tmp = a[i];
		a[i] = a[j];
		a[j] = tmp;
	}

	public static void main(String[] args) {
		N = sc.nextInt();
		cost = new int[N][N];
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				cost[i][j] = sc.nextInt();
			}
		}
		System.out.println(solve());
	}

	static class State implements Comparable<State> {
		int v;
		int[] ord;

		State(int v, int[] o) {
			this.v = v;
			this.ord = o.clone();
		}

		public int compareTo(State o) {
			return this.v - o.v;
		}

		public int hashCode() {
			return Arrays.hashCode(ord);
		}

		public boolean equals(Object obj) {
			if (this == obj) return true;
			State other = (State) obj;
			return Arrays.equals(ord, other.ord);
		}

	}

}

Measured memory_bytes: 57000
N, X, Y = map(int, input().split())
ans = [0]*(N-1)

def cal_dis(i, j):
    return min(j-i, abs(i-X)+abs(j-Y)+1)

for i in range(1, N+1):
    for j in range(i+1, N+1):
        k = cal_dis(i, j)
        ans[k-1] += 1

print('\n'.join(map(str, ans)))



Measured memory_bytes: 74468
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" <<; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	// 入力
	ll H, W;
	cin >> H >> W;

	vector<string> S(H);

	REP(i, H) {
		cin >> S[i];
	}

	ll ans = 0;

	mat w(H, vec(W, 0));
	mat h(H, vec(W, 0));

	REP(i, H) {
		ll st = 0;
		ll wtemp = 0;
		REP(j, W) {
			if (S[i][j] == '#') {
				w[i][j] = 0;
				if (st < j) {
					FOR(k, st, j) {
						w[i][k] = wtemp;
					}
					wtemp = 0;
				}
				st = j + 1;

			} else {	//='.'
				wtemp++;
			}

		}
		if (wtemp > 0) {
			FOR(k, st, W) {
				w[i][k] = wtemp;
			}
		}
	}

	REP(j, W) {
		ll st = 0;
		ll htemp = 0;
		REP(i, H) {
			if (S[i][j] == '#') {
				h[i][j] = 0;
				if (st < i) {
					FOR(k, st, i ) {
						h[k][j] = htemp;
					}
					htemp = 0;
				}
				st = i + 1;

			} else {	//='.'
				htemp++;
			}

		}
		if (htemp > 0) {
			FOR(k, st, H) {
				h[k][j] = htemp;
			}
		}
	}

	REP(i, H) {
		REP(j, W) {
			ans = max(ans, h[i][j] + w[i][j] - 1);
		}
	}

	// mdebug(w);
	// mdebug(h);


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 67072
#!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
INF = float("inf")


def solve(A: "List[int]"):
    A.sort()
    print(A[2]-A[0])
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [int(next(tokens)) for _ in range(3)]  # type: "List[int]"
    solve(A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4064
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
ll n,m;
ll dp[6500][6500]={0};
void solve(ll *s, ll *t){
    memset(dp, 0,sizeof dp);
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            if(s[i-1]==t[j-1])
                dp[i][j] = (1 + dp[i-1][j]%mod + dp[i][j-1]%mod)%mod;
            else
            dp[i][j] = ((dp[i-1][j]%mod + dp[i][j-1])%mod - dp[i-1][j-1]%mod + mod) %mod;
        }
    }
    // return dp[n][m];
}
int main() {
    cin>>n>>m;
    ll s[n],t[m];
    for(ll i=0;i<n;i++)cin>>s[i];
    for(ll i=0;i<m;i++)cin>>t[i];
    solve(s,t);
    cout<< (dp[n][m] + 1) %mod;
    return 0;
}

Measured memory_bytes: 330368
N = int(input())
W=[]
for i in range(N):
    A, B = list(map(int, input().split()))
    W.append([A, B])
W.sort(key=lambda x:x[1])
Sum = 0
f = 0
for i in range(N):
    Sum = Sum+W[i][0]
    if Sum > W[i][1]:
        print("No")
        f = f+1
        break
if f == 0:
    print('Yes')

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    int x,n,m=INF;
    cin>>x>>n;
    if(n==0){
        cout<<x<<endl;
        return 0;
    }
    map<int,bool> mp;
    vi l;
    rep(i,n){
        int p;
        cin>>p;
        mp[p]=true;
    }
    rep(i,102){
        if(!mp[i])l.pb(i);
    }
    for(auto y:l){
        //cout<<y<<endl;
        if(abs(x-m)>abs(x-y)){
            m=y;
        }
    }
    cout<<m<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define ld long double
#define mod 1000000007ll
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.begin(), v.end(), greater<ll>()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#define Debug(x) cout << x << "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
int main() {
    ll n, k;
    cin >> n >> k;
    vl a(n);
    for(auto &it: a) cin >> it;
    sort(all(a));
    ll ans = 0;
    for(int i = 0; i < k; ++i)
        ans += a[i];
    cout << ans;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#define F(i) for(int i=0;i<101;i++)
using namespace std;
int main(){
int n,m,g[101][101],h[101][101],a,b,c,x=0,t;
cin>>n>>m;F(i)F(j)g[i][j]=1e9;
while(m--){cin>>a>>b>>c;g[a][b]=g[b][a]=c;}
F(i)F(j)h[i][j]=g[i][j];
F(k)F(i)F(j)g[i][j]=min(g[i][k]+g[k][j],g[i][j]);
F(i)F(j)if(h[i][j]!=1e9&&g[i][j]<h[i][j])x++;
cout<<x/2;
}

Measured memory_bytes: 384
import sys

def propare():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    r = int(next(tokens))

    solve(r)

def solve(r: int):
    print(int(r*r/1))
    return


 
if __name__ == "__main__":
    propare()

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

int main(){
    int n;
    cin >> n;

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

    a[n] = a[n-1];
    int b[100010] = {};
    int cnt = 0;
    char k = 0;
    int ans = 0;

    for(int i = 0;i < n;i++){
        if(cnt == 0){
            cnt++;
            k = 0;
            ans++;
        }
        if(k == 0){
            if(a[i] < a[i+1]){
                k = 1;
            }else if(a[i] > a[i+1]){
                k = 2;
            }
        }

        if(a[i] < a[i+1] && k == 2){
            cnt = 0;
        }
        if(a[i] > a[i+1] && k == 1){
            cnt = 0;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 640
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000

int n;
long c;
long x[MAXN], y[MAXN];
long v[MAXN];
long left[MAXN+1], right[MAXN+1];
long lmax[MAXN+1], rmax[MAXN+1];

int input() {
	if (scanf("%d %ld", &n, &c) < 0) return 0;
	for (int i=0; i<n; i++)
		scanf("%ld %ld", &x[i], &v[i]);
	return 1;
}

void init() {
}

void calc(long *x, long *v, long *r, long *m) {
	long s = 0;
	r[0] = m[0] = 0;
	for (int i=0; i<n; i++) {
		s += v[i];
		r[i+1] = s-x[i];
		m[i+1] = max(m[i], r[i+1]);
	}
}

long solve() {
	calc(x, v, right, rmax);
	reverse(v, v+n);
	for (int i=0; i<n; i++)
		y[i] = c-x[n-1-i];
	calc(y, v, left, lmax);

	long r = 0;
	for (int i=0; i<=n; i++) {
		r = max(r, right[i] + lmax[n-i] - (i? x[i-1]:0));
		r = max(r, left[i]  + rmax[n-i] - (i? y[i-1]:0));
	}
	return r;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 5632
#include <bits/stdc++.h>
using ll = long long;
constexpr int MOD = 1000000007;
constexpr ll INF = 1000100010001000;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<ll> s(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s[i] = i == 0 ? a[i] : s[i-1] + a[i];
  }

  ll min = INF;
  for (int i = 0; i < a.size() - 1; i++) {
    ll cost = abs((s.back() - s[i]) - s[i]);
    if (cost < min)
      min = cost;
  }
  cout << min << endl;
  
  return 0;
}

Measured memory_bytes: 2688
def fun(X_high, X_low, K, line):
    X = (X_high + X_low) // 2
    cnt = 0
    for tree in line:
        if tree <= X:
            continue
        else:
            q, r = divmod(tree, X)
            if r == 0:
                q -= 1
            cnt += q
    if cnt > K:
        X_low = X
    else:
        X_high = X
    return X_high, X_low

N, K = map(int, input().split(" "))
line = list(map(int, input().split(" ")))

X_high = max(line)
X_low = 0

while (X_high - X_low) > 1:
    X_high, X_low = fun(X_high, X_low, K, line)
    
print(X_high)

Measured memory_bytes: 30968
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

struct Bipartite_Matching
{
  vector< vector< int > > G;    // 隣接リスト
  vector< int > match, used;
  int timestamp;

  Bipartite_Matching(int n)
  {
    timestamp = 0;
    G.resize(n);
    match.assign(n, -1);
    used.assign(n, 0);
  }
 
  void add_edge(int u, int v)
  {
    G[u].push_back(v);
    G[v].push_back(u);
  }

  // 増加路が見つかればTrue
  bool dfs(int v)
  {
    used[v] = timestamp;
    REP(i, G[v].size()) {
      int u = G[v][i], w = match[u];
      if(w == -1 || (used[w] != timestamp && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return true;
      }
    }
    return false;
  }

  int bipartite_matching()
  {
    int res = 0;
    REP(i, G.size()) {
      if(match[i] == -1) {
        ++timestamp;
        res += dfs(i);
      }
    }
    return res;
  }
};

int gcd(int m, int n)
{
    if (n == 0) return m;
    return gcd(n, m%n);
}

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

    int m, n;
    cin >> m >> n;
    while(!(m == 0 && n == 0)){
        Bipartite_Matching BM(n+m);
        vector<int> b(m);
        REP(i, m) cin >> b[i];
        vector<int> r(n);
        REP(i, n) cin >> r[i];
        
        REP(i, m)REP(j, n){
            if(gcd(b[i], r[j]) != 1){
                BM.add_edge(i, m+j);
            }
        }

        cout << BM.bipartite_matching() << "\n";
        cin >> m >> n;
    }
    return 0;
}


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

using namespace std;

int main() {
	int r;
	cin >> r;
	if (r < 1200) {
		cout << "ABC" << endl;
	} else
	if (r < 2800) {
		cout << "ARC" << endl;
	} else {
		cout << "AGC" << endl;
	}
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
 
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
 
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))
 
// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD
 
int n,d;
int a[252521];
 
int dat[252521];
vi vs[252521];
int root(int x){
  return dat[x]<0 ? x : dat[x]=root(dat[x]);
}
bool unite(int a, int b){
  a=root(a);b=root(b);
  if(a==b)return false;
  if(a!=b){
    if(dat[a]>dat[b])swap(a,b);
    dat[a] += dat[b]; dat[b] = a;
    for(int x : vs[b]){
      vs[a].push_back(x);
    }
    vs[b].clear();
  }
  return true;
}
 
const int N = 1<<18;
const ll INF = 1ll<<60;
struct segtree{
  vector<pll> seg;
  segtree(){seg.assign(2*N-1, pll(INF,INF));}
  void set(int x, ll v){
    seg[x+N-1] = pll(v, x);
    x += N-1;
    while(x>0){
      x = (x-1)/2;
      seg[x] = min(seg[2*x+1], seg[2*x+2]);
    }
  }
  pll qmin(int l, int r, int a, int b, int k){
    if(r<=a || b<=l)return pll(INF,INF);
    if(l<=a && b<=r)return seg[k];
    int m = (a+b)/2;
    return min(qmin(l,r,a,m,2*k+1), qmin(l,r,m,b,2*k+2));
  }
  pll qmin(int l, int r){return qmin(l,r,0,N,0);}
};
 
int main(){
  scanf("%d%d",&n,&d);
  REP(i,n)scanf("%d",a+i);
  
  fill(dat,dat+n,-1);
  REP(i,n)vs[i].push_back(i);
 
  segtree seg1, seg2;
  REP(i,n)seg1.set(i,(ll)a[i] - (ll)i*d);
  REP(i,n)seg2.set(i,(ll)a[i] + (ll)i*d);
 
  ll ans = 0;
  while(-dat[root(0)] != n){
    vector<pair<pii,ll>> es;
    REP(i,n)if(root(i)==i){
      pii e = pii(-1,-1);
      ll minv = INF*4;
      for(int x : vs[i]){
        seg1.set(x,INF);
        seg2.set(x,INF);
      }
      for(int x : vs[i]){
        pll P = seg1.qmin(0,x);
        ll v = P.first + a[x] + (ll)x*d;
        if(v < minv){
          minv = v;
          e = pii(x,P.second);
        }
        P = seg2.qmin(x+1,n);
        v = P.first + a[x] - (ll)x*d;
        if(v < minv){
          minv = v;
          e = pii(x,P.second);
        }
      }
      for(int x : vs[i]){
        seg1.set(x,(ll)a[x] - (ll)x*d);
        seg2.set(x,(ll)a[x] + (ll)x*d);
      }
      es.push_back(make_pair(e,minv));
    }
    for(auto PP : es){
      pii P = PP.first;
      ll v = PP.second;
      if(unite(P.first, P.second)){
        ans += v;
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 39828
a, b = map(int, input().split())
if a <= 0 and b >= 0:
    print("Zero")
elif a > 0:
    print("Positive")
elif b < 0:
    if (b - a) % 2:
        print("Positive")
    else:
        print("Negative")
else:
    if a % 2:
        print("Negative")
    else:
        print("Positive")

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

int main() {
	int count = 0;
	string S, X = "CODEFESTIVAL2016";
	cin >> S;
	for (int i = 0; i < 16; i++) {
		if (S[i] != X[i]) count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <numeric>
typedef long long int ll;
using namespace std;

int main(){
	string S;
	cin>>S;
	if(S[2]==S[3] and S[4]==S[5]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
	"sort"

)

func main() {
	solve(os.Stdin, os.Stdout)
}

type inInfo struct {
	in    int
	after int
}

type inInfoSorter []inInfo

func (a inInfoSorter) Len() int      { return len(a) }
func (a inInfoSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a inInfoSorter) Less(i, j int) bool {
	switch {
	case a[i].in > a[j].in:
		return true
	case a[i].in < a[j].in:
		return false
	case a[i].after > a[j].after:
		return true
	default:
		return false
	}
}

func sum(w []int) int {
	s := 0
	for _, v := range w {
		s += v
	}
	return s
}

type ptr []int

func (x ptr) top(i int) int {
	ptrs := []int(x)
	var his []int
	cur := i
	for ; cur >= 0 && ptrs[cur] != cur; cur = ptrs[cur] {
		his = append(his, cur)
	}
	for _, v := range his {
		ptrs[v] = cur - 1
	}
	if cur >= 0 {
		ptrs[cur] = cur - 1
	}
	return cur
}

func solve(stdin io.Reader, stdout io.Writer) {
	var n, m int
	var infos []inInfo
	//reader := bufio.NewScanner(stdin)
	fmt.Fscanln(stdin, &n, &m)

	for i := 0; i < n; i++ {
		var info inInfo
		//fmt.Fscanln(stdin, &info.after, &info.in)
		/*
			reader.Scan()
			var s = strings.Fields(reader.Text())
			info.after, _ = strconv.Atoi(s[0])
			info.in, _ = strconv.Atoi(s[1])
		*/
		fmt.Fscanf(stdin, "%d%d\n", &info.after, &info.in)
		infos = append(infos, info)
	}

	sort.Sort(inInfoSorter(infos))

	var ans = make([]int, m)
	var p = make([]int, m)
	for i := range p {
		p[i] = i
	}
	ptrs := ptr(p)

	for _, w := range infos {
		i := ptrs.top(m - w.after)
		if i >= 0 {
			ans[i] = w.in
		}
	}

	fmt.Fprintln(stdout, sum(ans))

}



Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define mod 1000000007
#define ss second
#define ff first
#define vpii vector<pii>
#define vvi vector<vi>
#define pb push_back
#define vs vector<string>
#define all(x) x.begin(),x.end()
#define mii map<int,int>
const int inf=0x3f3f3f3f3f3f3f3f;
void print(vi &v){
    for(int i=0;i<v.size();i++)cout<<v[i]<<" ";
    cout<<endl;
}
int power(int a,int b){
    int res = 1;
    while(b!=0){
        if(b&1){
            res *= a; 
        }
        a = (a * a);
        b = (b / 2);
    }
    return res;
}
int gcd(int a,int b,int c){
	return __gcd(a,__gcd(b,c));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t = 1;
    while(t--){
        int k,i,j,l;
        int sum = 0;
        cin>>k;
        for(i=1;i<=k;i++){
        	for(j=1;j<=k;j++){
        		for(l=1;l<=k;l++)sum+=gcd(i,j,l);
        	}
        }
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 3652
import bisect
from operator import itemgetter
import math
import collections
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
xy = [IL() for i in range(N)]

if N == 1 or N == 2:
  print(1)
else:
  data = []
  cnt = 0
  for i in itertools.combinations(xy,2):
    rex,rey = i[0]
    x,y = i[1]
    if rex > x:
      rex,rey,x,y = x,y,rex,rey
    if rex == x:
      if rey > y:
        rex,rey,x,y = x,y,rex,rey
    data.append(str(x-rex)+str(y-rey))
  else:
    d = collections.Counter(data)
    cnt = max(cnt,d.most_common()[0][1])
  
  print(N-cnt)

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


int main(){


    int n,k;
    cin>>n>>k;

    vector<int>vec;

    for(int i=0;i<n;i++){
        int x;
        cin>>x;

        vec.push_back(x);
    }

    sort(vec.begin(),vec.end());

    long long s=0;
    for(int i=0;i<k;i++){
        s+=vec[i];

    }

    cout<<s<<endl;




    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
    ll n, l;
    cin >> n >> l;
    vector<ll> apple(n);
    ll moto = 0;
    REP(i, n){
        apple[i] = l + i;
        moto += apple[i];
    }
    ll ans = INF, sa = INF;
    REP(i, n){
        ll sum = 0;
        REP(j, n){
            if(i == j) continue;
            sum += apple[j];
        }
        if(abs(moto - sum) < sa){
            sa = abs(moto - sum);
            ans = sum;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

typedef long long ll;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define DBGV(v,n) forn(i,n) cout << v[i] << " "; cout << endl
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl

struct block
{
	ll w, s, v;
};

bool compare(block &a, block &b)
{
	return a.w + a.s < b.w + b.s;
}

int main()
{
	FIN;
	
	int n;
	cin >> n;
	vector <block> v(n);
	forn(i,n) cin >> v[i].w >> v[i].s >> v[i].v;
	sort(all(v),compare); 
	
	//for(auto u : v) cout << u.w << " " << u.s << " " << u.v << "\n"; 
	
	int MAXS = 40000;
	
	vector <ll> dp(MAXS,0);
	
	for(auto u : v)
	{
		for(int i = min(u.s,MAXS-u.w); i>=0; i--)
		{
			dp[i+u.w] = max(dp[i+u.w],dp[i]+u.v);
		}
	}
	
	ll ans = 0;
	for(auto u : dp)
	{
		ans = max(ans,u);
	}
	
	cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
typedef vector<int> vi;
#define pb push_back
vi a;
vi b;
int n,m,x,y;
map<char,int> frq;
map<char,int> frq1;
int main() {
string x,y;
cin>>x>>y;
for(int i=0;i<x.size();i++)
{
    frq1[x[i]]++;
}
for(int i=0;i<y.size();i++)
{
    frq[y[i]]++;
}
if(frq.size()>frq1.size()){cout<<"No";exit(0);}
int temp=true;
for(map<char,int>::iterator it=frq.begin();it!=frq.end();it++)
{
    int t=0;
    for(map<char,int>::iterator it1=frq1.begin();it1!=frq1.end();it1++)
{
    if(it->first==it1->first && it->second==it1->second)
    {
        t++;
    }else if(it->first!=it1->first && it->second>=1  && it->second==it1->second)
    {
         t++;

    }
    else
    {
        t--;
    }
}
if(t==-frq1.size()){temp=false;break;}
}
if(temp==1)cout<<"Yes"<<endl;
else cout<<"No"<<endl;


    return 0;
}




Measured memory_bytes: 776
#include <iostream>
#include <bits/stdc++.h>
#define mod 998244353
typedef long long ll;

using namespace std;

void Fastio(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) ;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

long double  NCR(int n, int m){
    long double res = 1;
    m = min(m, n - m);
    for(int i = 0; i < m; i++){
        res = res * ( n - i) / (i + 1);
 }
    return res;
}
ll tol(string a){
    ll res=0;
    while(a[0]=='0'){
        a.erase(a.begin());
    }
    if(a=="")a="0";
    for(int i=0; i<a.size(); i++){
        res*=10; res+=a[i]-'0';
    }
    return res;
}
int check(string a, string b){
    for(int i=0; i<a.size(); i++){
        if(a[i]>b[i])return 1;
        if(b[i]>a[i])return -1;
    }
    return 0;
}
class data{
public:
    ll v,d,p;
    data(){}
    data(ll vv, ll dd, ll pp){
        v=vv;  d=dd; p=pp;
    }
};

int primeFactors(int n)
{
    ll c=0;
    while (n % 2 == 0)
    {
        c++;
        n = n/2;
    }
    for (int i = 3; i*i <= n; i = i + 2)
    {
        while (n % i == 0)
        {
            c++;
            n = n/i;
        }
    }
    if (n > 2)
        c++;
    return c;
}

int main()
{
    Fastio();
    int n,k; cin>>n>>k;
    int arr[n];
    for(int i=0; i<n; i++){cin>>arr[i];}
    ll dp[n]={0};
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2; i<n; i++){
        ll ans=1e18;
        for(int y=1; y<=k; y++){
            if(y<=i)ans=min(abs(arr[i]-arr[i-y])+dp[i-y], ans);
        }
        dp[i]=ans;
    }
    cout<<dp[n-1]<<'\n';

    return 0;
}


Measured memory_bytes: 1408
def s():
 n,m=map(int,input().split())
 P=[[]for _ in[0]*n]
 C=[0]*n
 k=0
 for _ in[0]*m:
  s,t=map(int,input().split());P[s]+=[t];P[t]+=[s]
 for i in range(n):
  k+=1
  if C[i]<1:
   s=[i];C[i]=k
   while s:
    u=s.pop()
    for v in P[u]:
     if C[v]<1:C[v]=k;s+=[v]
 for _ in[0]*int(input()):
  a,b=map(int,input().split())
  print(['no','yes'][C[a]==C[b]])
if'__main__'==__name__:s()


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

using namespace std;

int main() {
  long long N, A, B;
  
  cin >> N >> A >> B;
  
  if (B < A) {
    cout << 0 << endl;
    
    return 0;
  }
  
  long long min = A * (N - 1) + B;
  long long max = A + B * (N - 1);
  
  cout << (max - min + 1 > 0 ? (max - min + 1) : 0) << endl;
  
  return 0;
}

Measured memory_bytes: 3668
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
int main() {
  ll N; scanf("%llu",&N);
  int ans=1000000000;
  ll MAX_ANS = (long long)sqrtl(N)+1;
  for (int i=1;i<MAX_ANS;i++){
    if (N%i==0){
      ans = min(max((int)log10((double)(N/i))+1, (int)log10((double)i)+1), ans);
    }
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,long long> pi;
int maxn = 40;
long long unit = 1;
long long bits_on[45];
long long bits_off[45];
long long dp[50];
vector<long long>xbit;
long long f(int b){
	if(b<0) return 0;
	long long &ret = dp[b];
	if(~ret) return ret;
	ret = 0;
	long long absolute = unit<<b;
	ret = bits_on[b]*absolute+f(b-1);
	ret = max(ret,bits_off[b]*absolute+f(b-1));
	return ret;
}
int main(){
	int n;
	memset(dp,-1,sizeof(dp));
	long long k;
	cin>>n>>k;
	for(int i=0; i<n; i++){
		long long a;
		cin>>a;
		for(int i=0; i<=maxn; i++){
			if((unit<<i)&a) bits_on[i]++;
			else bits_off[i]++;
		}
	}
	while(k){
		xbit.push_back(k%2);
		k/=2;
	}
	long long psum = 0;
	long long ret = 0;
	int l = maxn-xbit.size();
	for(int i=0; i<l; i++) xbit.push_back(0);
	for(int i=xbit.size()-1; i>=0; i--){
		if(xbit[i]){
			long long temp = psum;
			temp+=bits_on[i]*(unit<<i);
			temp+=f(i-1);
			ret = max(ret,temp);
			psum+=bits_off[i]*(unit<<i);
		}
		else{
			psum+=bits_on[i]*(unit<<i);
		}
	}
	ret = max(ret,psum);
	cout<<ret;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N, K, S;
    cin >> N >> K >> S;
    
    for(int i = 0; i < N; i++) {
        if (i < K) cout << S << " ";
        else {
            if (S == 1e9) 
                cout << 1 << " ";
            else 
                cout << S+1 << " ";
        }
    }

    cout << endl;

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

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

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

    if(x == 1 || x == 2*n-1){
        printf("No\n");
        return 0;
    }

    vector <int> ans(2*n-1);
    iota(ans.begin() ,ans.end() ,1);
    set <int> st{ans.begin() ,ans.end()};
    ans[n-2] = x-1;
    ans[n-1] = x;
    ans[n] = x+1;
    st.erase(x-1);
    st.erase(x);
    st.erase(x+1);

    for(int i=0; i<2*n-1; i++){
        if(i==n-2||i==n-1||i==n)
            continue;
        ans[i] = *st.begin();
        st.erase(st.begin());
    }

    printf("Yes\n");
    for(int&i : ans)
        printf("%d\n",i);
}


Measured memory_bytes: 11648
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
#define N 100001
using namespace std;



int main()
{   IOS;
cout.precision(30);
   ll n,k;
   cin >> n >> k;
   for(int i=0;i<n;i++)
   {
       ll x;
       cin >> x;
   }
   if(n==3)
   {
       cout << 1;
       return 0;
   }
   ll res=1;
   n=n-k+1;

   while(n>1)
   {

       res++;
       n=n-k+1;
   }
   cout << res;

    return 0;
}


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

using namespace std;

struct Frog {
    int x, y, area;
};

struct Sprinkler {
    int x, y;
};

Sprinkler spr[10];
int graph[10][10];
int dx[] = {-1, 0, 1, 2, 2, 2, 1, 0, -1, -2, -2, -2};
int dy[] = {-2, -2, -2, -1, 0, 1, 2, 2, 2, 1, 0, -1};

void update(int area) {
    for(int i = spr[area].y - 1; i <= spr[area].y + 1; ++i) {
        for(int j = spr[area].x - 1; j <= spr[area].x + 1; ++j) {
            if(i >= 0 && i <= 9 && j >= 0 && j <= 9) {
                graph[i][j] = area;
            }
        }
    }
}

int main() {

    int x, y, n;

    while(cin >> x >> y, x | y) {

        cin >> n;

        for(int i = 0, spx, spy; i < n; ++i) {
            cin >> spr[i].x >> spr[i].y;
        }

        int alive = 0;
        queue<Frog> q;

        q.push((Frog){x, y, 0});
        memset(graph, -1, sizeof(graph));

        while(!q.empty()) {

            Frog now = q.front(); q.pop();

            if(now.area == n) {
                alive = 1;
                break;
            }

            update(now.area);

            for(int i = 0; i < 12; ++i) {
                Frog next = now;
                next.x += dx[i];
                next.y += dy[i];
                next.area++;
                if(next.x >= 0 && next.x <= 9 && next.y >= 0 && next.y <= 9) {
                    if(graph[next.y][next.x] == now.area) {
                        graph[next.y][next.x] = -1;
                        q.push(next);
                    }
                }
            }

        }

        cout << (alive ? "OK" : "NA") << endl;

    }

}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
set <lld> visit;
map <lld, lld> counter;
void dfs (vector <lld> V[], lld x)
{
	visit.insert(x);
	for(lld i = 0; i < V[x].size();i++){
		if (!visit.count(V[x][i])){
			counter[V[x][i]] += counter[x];
			dfs(V , V[x][i]);
		}
	}
}
int main ()
{
	FastIO
	lld n, q;
	cin >> n;
	cin >> q;
	lld i;
	vector <lld> V[n+1];
	foi(i , n-1) {
		lld x, y;
		cin >> x;
		cin >> y;
		V[x].push_back(y);
		V[y].push_back(x);
	}
	foi(i,q){
		lld r, x;
		cin >> r;
		cin >> x;
		counter[r] += x;
	}
	dfs(V,1);
	foi(i,n){
		cout << counter[i+1] << " ";
	}
	return 0;
}

Measured memory_bytes: 54016
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        while(true){
            int x = sc.nextInt();
        	int y = sc.nextInt();
            
            if(x == 0 && y == 0){
                break;
            }
            System.out.println(Math.min(x, y) + " " + Math.max(x, y));
        }
        sc.close();
    }
}



Measured memory_bytes: 35340
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	valstr := sc.Text()
	n, _ := strconv.Atoi(valstr)

	max := -99999999999
	min := 99999999999

	for i := 0; i < n; i++ {
		sc.Scan()
		valstr := sc.Text()
		val, _ := strconv.Atoi(valstr)

		delta := val - min
		if max < delta {
			max = delta
		}

		if min > val {
			min = val
		}
	}

	fmt.Println(max)
}



Measured memory_bytes: 4092
s=input()
l=len(s)
dp=[[0]*13 for i in range(l+1)]
dp[0][0]=1
for i in range(1,l+1):
    if s[i-1]=='?':
        for k in range(13):
           for j in range(10):
                dp[i][(k*10+j)%13]+=dp[i-1][k]
                dp[i][(k*10+j)%13]%=10**9+7
    else:
        idx=int(s[i-1])
        for j in range(13):
            dp[i][(j*10+idx)%13]=dp[i-1][j]
print(dp[-1][5]%(10**9+7))

Measured memory_bytes: 63888
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

#include<unistd.h>
struct Buffer{
    enum { chunk = 1 << 16 };
    int idx;
    char buf[chunk];
    Buffer(){ init(); }
    void init(){ idx = 0; read(0, buf, chunk); }
    void check(){ if(idx == chunk){ init(); } }
    int next(){
        static char notDigits[256] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1, 0,0,0,0,0,0,0,0,0,0,};
        int ret = 0, sign = 1;
        while(check(), notDigits[(int)buf[idx]]){ idx++; }
        if(check(), buf[idx] == '-'){ sign = -1; idx++; }
        while(check(), !notDigits[(int)buf[idx]]){ ret = ret * 10 + buf[idx++] - '0'; }
        return sign * ret;
    }
};
struct FastInput {
    Buffer buf;
    template <class T>
    FastInput& operator >> (T& num) { num = buf.next(); return *this; }
    void tie(int){ }
    template <class S, class T>
    friend FastInput& operator >> (FastInput& in, pair<S, T>& p){ return in >> p.first >> p.second; }
    template <class T>
    friend FastInput& operator >> (FastInput& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
};
FastInput fin;
#define cin fin

int main(){
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> accs(n, vector<int>(n));
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        l--; r--;
        for(int i = 0; i <= l; i++){
            accs[i][r]++;
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 1; j < n; j++){
            accs[i][j] += accs[i][j - 1];
        }
    }
    for(int i = 0; i < q; i++){
        int p, q;
        cin >> p >> q;
        p--; q--;
        cout << accs[p][q] << '\n';
    }
}


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

class Dot{
public:
  bool d[4];
  Dot() {
    d[0] = d[1] = d[2] = d[3] = false;
  }
};

int main() {
  Dot data[5][5];
  for(int i = 0; i < 9; i++) {
    string str;
    getline(cin, str);
    int y = i/2;
    if(i % 2 == 0) {
      for(int j = 0; j < 4; j++) {
	if(str[j] == '1') {
	  data[y][j].d[0] = data[y][j+1].d[2] = true;
	}
      }
    } else {
      for(int j = 0; j < 5; j++)  {
	if(str[j] == '1') {
	  data[y][j].d[1] = data[y+1][j].d[3] = true;
	}
      }
    }
  }

  int d[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
  int x = 0;
  int y = 0;
  int dir = 0;
  while(1) {
    for(int i = 0; i < 4; i++) {
      int t = (dir+i+3)%4;
      if(data[y][x].d[t]) {
	dir = t;
	x += d[t][0];
	y += d[t][1];
	switch(t) {
	case 0: cout << 'R'; break;
	case 1: cout << 'D'; break;
	case 2: cout << 'L'; break;
	case 3: cout << 'U'; break;
	}
	break;
      }
    }
    if(x == 0 && y == 0) {
      cout << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	vector<ll> x(n, 0);
	rep(i, n) cin >> a[i];
	rep(i, n)
	{
		int incr = (i % 2 == 0) ? a[i] : -a[i];
		x[0] += incr;
	}
	rep1(i, n - 1)
	{
		x[i] = 2 * a[i - 1] - x[i - 1];
	}
	rep(i, n)cs(x[i]);
	return 0;
}


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

long long mod = 1000000000 + 7;

long long power(long long x, long long n) {
  long long ans = 1;
  x = x%mod;
  while(n) {
    if (n & 1) ans = ((ans%mod)*(x%mod))%mod;
    x = ((x%mod)*(x%mod))%mod;
    n >>= 1;
  }
  return ans;
}

long long ncrer(long long n, long long r) {
  long long x = 1;
  long long y = 1;
  for (int i = 1; i <= r; i++) {
    x = ((x%mod) * ((n-(i-1))%mod)) % mod;
    y = ((y%mod) * ((r-(i-1))%mod)) % mod;
  }

  return (x*power(y, mod-2))%mod;
}

void solver() {
  long long n, a, b;
  cin >> n >> a >> b;

  long long ans = (power(2, n)%mod) - 1 - (ncrer(n, a)%mod) - (ncrer(n, b)%mod);

  while(ans < 0) ans = (ans + mod)%mod;

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

int main() {
  solver();
  return 0;
}


Measured memory_bytes: 256
n,*A=map(int,open(0).read().split())
ans = 0
while 1:
    A.sort(reverse=1)
    if A[0] > A[-1]+n:
        p = (A[0] - A[-1]) // (n+1)
        for j in range(n):
            A[j] += p
        A[0] -= p*(n+1)
        ans += p
    else:
        break
if max(A) >= 2*n:
    ans += (max(A) - 2*n)*n
    ma = max(A) - 2*n
    for i in range(n):
        A[i] -= ma
while max(A) >= n:
    for i in range(n):
        A[i] += 1
    A[A.index(max(A))] -= n+1
    ans += 1
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int[][][] c=new int[5][4][11];
for(int x=1;x<5;x++){
for(int y=1;y<4;y++){
for(int z=1;z<11;z++){
c[x][y][z]=0;
}
}
}
for(int b=0;b<a;b++){
int d=scan.nextInt();
int e=scan.nextInt();
int f=scan.nextInt();
int g=scan.nextInt();
c[d][e][f]=c[d][e][f]+g;
}
for(int x=1;x<5;x++){
for(int y=1;y<4;y++){
for(int z=1;z<11;z++){
System.out.print(" "+c[x][y][z]);
}
System.out.println();
}
if(x!=4)
System.out.println("####################");
}
}
}

Measured memory_bytes: 30152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;cin>>x;
    for(ll a=-2000; a<=2000; a++){
        for(ll b=-2000; b<2000; b++){
            if(a*a*a*a*a - b*b*b*b*b == x){
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }
}

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

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

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

int main()
{
  vector<int> d(5);
  REP(i, 5)
  cin >> d[i];
  int ans = INT32_MAX;
  REP(i, 5)
  REP(j, 5)
  REP(k, 5)
  REP(l, 5)
  REP(m, 5)
  {
    if (i == j || i == k || i == l || i == m || j == k || j == l || j == m || k == l || k == m || l == m)
      break;
    vector<int> vc(5);
    vc[i] = d[0];
    vc[j] = d[1];
    vc[k] = d[2];
    vc[l] = d[3];
    vc[m] = d[4];
    int tmp = 0;
    REP(n, 5)
    {
      while (tmp % 10 != 0)
        tmp++;
      tmp += vc[n];
    }
    if (tmp < ans)
      ans = tmp;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256