akhauriyash/Code-Regression huggingface dataset:
//#include<atcoder/all>
//using namespace atcoder;

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    int N; cin >> N;
    int pt = 0; int pp[2] = { 0,0 };
    bool ok = true;
    rep(i, N) {
        int t, p[2]; cin >> t >> p[0] >> p[1];
        int d = abs(p[0] - pp[0]) + abs(p[1] - pp[1]);
        if (d > t - pt) ok = false;
        if (d % 2 != (t - pt) % 2) ok = false;
        pt = t; pp[0] = p[0]; pp[1] = p[1];
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
  int count = 0;
  int rating = 0;
  
  int result = 0;
  
  cin >> count >> rating;
  
  if (count < 10) {
    result = rating + (100 * (10 - count));
  } else {
    result = rating;
  }
  
  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(void){
    int sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;
    string s="";
    int ans1x = tx-sx;
    int ans1y = ty-sy;
    rep(i,ans1x) s+='R';
    rep(i,ans1y) s+='U';
    rep(i,ans1x) s+='L';
    rep(i,ans1y) s+='D';
    s+="DR";
    rep(i,ans1x) s+='R';
    rep(i,ans1y+1) s+='U';
    s+='L';
    s+= 'U';
    rep(i,ans1x +1) s+='L';
    rep(i,ans1y+1) s+= 'D';
    s+= 'R';
    cout<<s<<endl;
    
}


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

// warshall_floyd

const int INF = 1e9;
const int MAX_V = 10;
const int MAX_H = 200;
const int MAX_W = 200;
int V = 10, H, W;
int d[MAX_V + 10][MAX_V + 10];
int A[MAX_H + 10][MAX_W + 10];

// O(V^3)
// 全対点最短経路
// 負の閉路が存在するかどうか
bool warshall_floyd (){
    for (int k = 0; k < V; ++k)
        for (int i = 0; i < V; ++i)
            for (int j = 1; j <= V; ++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    for (int i = 0; i < V; ++i)
        for (int j = 0; j < V; ++j) 
            if (d[i][j] < 0) return true;

    return false;
}

int main(){

    cin >> H >> W;
    for (int i = 0; i < V; ++i){
        for (int j = 0; j < V; ++j){
            int c;
            cin >> c;
            if (c == -1) d[i][j] = INF;
            else d[i][j] = c;
        }
    }
    warshall_floyd();

    int ans = 0;
    for (int i = 0; i < H; ++i){
        for (int j = 0; j < W; ++j) {
            int a;
            cin >> a;
            if (a != -1 && a != 1) ans += d[a][1];
        }
    }

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

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

int main()
{
  int K,A,B,ans=0;
  cin >> K >> A >> B;
  for (int i = 0; i < B-A+1; i++)
  {
    if((A+i)%K==0)ans=1;
  }
  if(ans==1)cout << "OK";
  else cout << "NG";
    }


Measured memory_bytes: 3620
#include "bits/stdc++.h"

using namespace std;
int main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a >= c)
	{
		cout << "0" << "\n";
	}
	else if (a < c && a+b >= c)
	{
		cout << (c - a) << "\n";
	}
	else if (a < c && a+b < c)
	{
		cout << "NA" << "\n";
	}
}




Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
    out << '(' << p.first << ',' << p.second << ')';
        return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
    in >> p.first >> p.second;
        return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
    for (T &x : v)
        in >> x;
    return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
    for (const vector<T> &x : v)
        out << x << '\n';
    return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
    for (const T &x : v)
        out << x << ' ';
    return out;
}
 
template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
    for (const T &x : s)
        out << x << ' ';
    return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define epsilon 0.00000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl "\n"
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main()
{
    fast();
    ll n,m,k;
    cin>>n>>m>>k;
    vii row(n,{0,0});
    vii col(m,{0,0});
    for(ll i=0;i<n;i++)
    {
        row[i]={0,i};
    }
    for(ll i=0;i<m;i++)
    {
        col[i]={0,i};
    }
    set <ii> s;
    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin>>x>>y;
        x--;y--;
        row[x].F++;
        col[y].F++;
        s.insert({x,y});
    }
    sort(r_all(row));
    sort(r_all(col));
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        ll r=row[i].S;
        for(ll j=0;j<m;j++)
        {
            ll c=col[j].S;
            ll sum=row[i].F+col[j].F;
            if(s.find({r,c})!=s.end())
            {
                sum--;
                ans=max(ans,sum);
            }
            else
            {
                ans=max(ans,sum);
                break;
            }
        }
    }
    cout<<ans<<nl;
}


Measured memory_bytes: 31424
import math

D, G = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(D)]

ans = float("inf")

for bit in range(1 << D):
    cnt = 0
    sum = 0
    pids = set(range(D))

    for i in range(D):
        if bit & (1 << i):
            sum += pc[i][0] * (i + 1) * 100 + pc[i][1]
            cnt += pc[i][0]
            pids.discard(i)

    if sum < G:
        pid = max(pids)
        n = min(pc[pid][0], math.ceil((G - sum) / ((pid + 1) * 100)))
        cnt += n
        sum += n * (pid + 1) * 100
        
    if sum >= G:
        ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 9244
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;
int n;
int main() {
	cin >> n;
	vector<ll> a(n);
	rep(i, n) {
		a[i] = i + 1;
	}
	rep(i, n) {
		if ((a[i] % 3) == 0)a[i] = 0;
		if ((a[i] % 5) == 0)a[i] = 0;
		if ((a[i] % 15) == 0)a[i] = 0;
	}
	ll s = 0;
	//rep(i, n) cout << a[i];
	rep(i, n) s += a[i];
	ll ans;
	ans = s;
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 11020
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,t,n,i,c;
    set<long long>s;
    cin>>a>>b;
    while(b--)
    {
        cin>>n;
        long long c;
        for( i=0;i<n;i++)
        {
            cin>>c;
            s.insert(c);
        }
    }
    cout<<a-s.size()<<endl;
}


Measured memory_bytes: 3648
// abc162_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

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

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int K;
    cin >> K;

    ll ans = 0;
    REPN(a, 1, K+1) REPN(b, 1, K+1) REPN(c, 1, K+1){
        int x = gcd(a, b);
        x = gcd(x, c);
        ans += x;
    }

    print(ans);


    return 0;
}


Measured memory_bytes: 3600
A = []
out = []
for x in range(3):
    A.append(list(map(int, input().split())))
    out.append([0, 0, 0])
N = int(input())
b = []
for B in range(N):
    b.append(int(input()))
for pick in b:
    for y in range(3):
        for x in range(3):
            if pick == A[y][x]:
                out[y][x] = 1

bingo = False
for x in range(3):
    if out[x][0] == 1 and out[x][1] == 1 and out[x][2] == 1:
        bingo = True

for x in range(3):
    if out[0][x] == 1 and out[1][x] == 1 and out[2][x] == 1:
        bingo = True

for x in range(3):
    if out[0][0] == 1 and out[1][1] == 1 and out[2][2] == 1:
        bingo = True

    if out[2][0] == 1 and out[1][1] == 1 and out[2][0] == 1:
        bingo = True

if bingo:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,c=0,nxt=1,x;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(x==nxt)
        {
            ++nxt;
            ++c;
        }
    }
    if(c!=0)
    cout<<n-c;
    else
        cout<<-1;
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


int main() {
	int N;
	cin >> N;
	int64_t A[110];
	rep(i, N) cin >> A[i];

	sort(A, A+N);
	int64_t res = A[N-1] - A[0];
	cout << res << endl;
}

Measured memory_bytes: 256
function main(input){
  input = input.split('\n');
  const [N, M, Q] = input[0].split(' ').map(Number);
  const list = input.slice(1, Q+1).map(x=> x.split(' ').map(Number));

  function createA(array) {
    let ret = []
    array.forEach(a => {
      for(let i=a[a.length-1]; i<=M; i++){
        ret.push([...a, i])
      }
    });
    if(ret[0].length === N) return ret;
    return createA(ret);
  }

  const array = []
  for(let i=1; i<=M; i++){
    array.push([i]);
  }
  const AList = createA(array)

  let max = 0;
  AList.forEach(A => {
    let sum = 0;
    list.forEach(x=>{
      if(A[x[1]-1] - A[x[0]-1] === x[2]){
        sum += x[3];
      }
    })
    if(sum > max){
      max = sum;
    }
  });

  console.log(max);
}


main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());


Measured memory_bytes: 109008
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn digs(n: i64) -> i64 {
    if 0 <= n && n < 10 {
        return 1;
    }

    return digs(n / 10) + 1;
}

fn main() {
    input! {
        N: i64,
    }

    let mut ans = 0;
    for n in 1..N + 1 {
        let d = digs(n);
        if d % 2 == 1 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2068
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;

int main(){
  string in;
  cin >> in;
  int n_c=-1;
  int n_f=-1;
  for( int i=0; i<(int)in.size(); i++){
   if( in[i]=='C'&&n_c==-1 ) n_c=i;
   if( in[i]=='F') n_f=i;
  }
  if( n_c!=-1 && n_f!=-1 && n_c < n_f ){
   cout <<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
  return 0;
}


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

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

	int sum = 0 , num;
	for(int i = 0; i < m; i++){
		cin >> num;
		sum += num;
	}
	if(n >= sum){
		cout << n - sum << endl;
	}
	else{
		cout << -1 << endl;
	}
}

Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {

	static final long DIVIDE_NUMBER = 1000000007;

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int x = scan.nextInt();
		int y = scan.nextInt();

		String answer = check(x, y);

		println(answer);
	}

	public static String check(int x, int y) {

		int max = x * 4;

		int min = x * 2;

		if (max < y || y < min || y % 2 == 1) {
			return "No";
		}

		return "Yes";
	}

	public static void println(Object target) {
		System.out.println(target);
	}
}


Measured memory_bytes: 27080
// PCK2018 Yoosen Q4 Heat Strokes
// YAMADA Terushige 2018.10.18
#include <iostream>
using namespace std;

int main(){
  int a,b,x,ans=0;
  cin >> a >> b >> x;

  if(a < b) ans = (x+999)/1000*a;
  else if(a > b*2) ans = (x+499)/500*b;
  else {
    ans = (x/1000)*a;
    x %= 1000;
    if(x > 500){
      ans += a;
    }else if(x >0){
      ans +=b;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int A, B;
  cin >> A >> B;
  if (A >= 13) cout << B << endl;
  else if (A >= 6) cout << B/2 << endl;
  else cout << 0 << endl;
  return 0;
}

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

int main() {
  
  string S;
  cin >> S;
  
  int num0=0, num1=0;
  int fewer=0;
  for(int i=0; i<S.size(); i++){
    if( S.at(i) == '0'){ num0+=1;  }
    else{ num1+=1; }
  }

  fewer = min( num0, num1 );
  cout << 2*fewer << endl;

}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int find_lower_bound_index(vector<long long>& pref,int low, int high,long long val){
	int ans = high+1;
	while(low<=high){
		int mid = (low+high)/2;

		if(pref[mid] >= val){
			ans = min(ans,mid);
			high = mid -1;
		}
		else
		{
			low = mid +1;
		}
	}
	return ans;
}
ll find_ans(vector<ll>& pref,int i,int j,int k,int n){
	if(i<0 || i > j || j > k || k > n-1)
		return LONG_MAX;
	ll p =pref[i];

	ll q = pref[j] - pref[i];

	ll r = pref[k] - pref[j];

	ll s= pref[n-1] - pref[k];
		//cout<<i<<" "<<j<<" "<<k<<endl;
		//cout<<p<<" "<<q<<" "<<r<<" "<<s<<endl;
		return abs( max(max(p,q),max(r,s)) - min(min(p,q),min(r,s)) );
}
int main(){
	int n;
	cin>>n;

	vector<ll> v(n);

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

	vector<ll> pref(n);

	pref[0] = v[0];

	for(int i = 1;i<n;i++){
		pref[i] = pref[i-1] + v[i];
	}

	ll ans = LONG_MAX;
	//fix middle cut
	for(int j =1;j<n-1;j++){
		int i = find_lower_bound_index(pref,0,j-1,(pref[j]+1)/2);
		//if(i == j)
		//	continue;
		int k = find_lower_bound_index(pref,j+1,n-2,(pref[n-1] + pref[j]+1)/2);
		//if(k == n-1)
		//	continue;

		ans  = min(ans,find_ans(pref,i,j,k,n));
		ans  = min(ans,find_ans(pref,i-1,j,k,n));
		ans  = min(ans,find_ans(pref,i,j,k-1,n));
		ans  = min(ans,find_ans(pref,i-1,j,k-1,n));
		
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3328
H,W,A,B = map(int, input().split())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, H+W + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for h in range(1, H-A+1):
    ans += cmb(h-1+B-1, h-1, mod)*cmb(H-h+W-B-1, H-h, mod)
    ans %= mod

print(ans)

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

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> d(n);
  rep(i,k){
    int m;
    cin>>m;
    rep(j,m){
      int a;
      cin>>a;
      d[a-1]=1;
    }
  }
  int ans=0;
  rep(i,n) if(d[i]==0) ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int sdkys(int a,int b){
    if(b==0) return a;
    return sdkys(b,a%b);
}
int sskbs(int a,int b){
    return a*b/sdkys(a,b);
}
int sosu(int a){
    if(a==2){
        return 1;
    }
    for(int i=2;i<sqrt(a)+1;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}
vector<int> v;
int n,m,cnt=0,ans=0,aa[220000],ab[220000];
pair<int,int> pp[220000];
string s,ss[220000];
char ch;
queue<int> que;
signed main(){
    cin>>s;
    rep(i,s.size()){
        cnt+=s[i]-'0';
    }
    if(cnt%9==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 10592
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;

int main() {
  INCANT;
  cin >> N;
  while(N>1000) N-=1000;
  cout << 1000-N << "\n";
  return 0;
}

Measured memory_bytes: 3668
#include<stdio.h>
int main()
{
	char r[5]={'A','B','C','D','E'};
	int s1[5],i,s2[5],m=0,l;
	while(1){
		for(i=0;i<5;i++){
			scanf("%d%d",&s1[i],&s2[i]);
			if(s1[i]==0&&s2[i]==0){
				return 0;
			}
		}
		for(i=0;i<5;i++){
			if(m<s1[i]+s2[i]){
				m=s1[i]+s2[i];
				l=i;
			}
		}
		printf("%c %d\n",r[l],m);
		m=0;
	}
	return 0;
}

Measured memory_bytes: 2680
import unittest


def solve(n, leafs):
    if leafs[0] == 1:
        if n == 0:
            return 1
        else:
            return - 1
    l = 1
    for i in range(min(28, n + 1)):
        if leafs[i] > l:
            return -1
        l *= 2

    usable_node = 1
    usable_nodes = [1]*(n+1)
    for i in range(n):
        if leafs[i] <= usable_node:
            usable_node -= leafs[i]
            usable_node *= 2
            usable_nodes[i+1] = usable_node
        else:
            return - 1
    if leafs[-1] > usable_node:
        return - 1
    usable_node -= leafs[-1]
    if usable_node + leafs[-1] > 2 ** n:
        return - 1

    max_node = [0 for i in range(n + 1)]
    max_node[n] = leafs[n]
    for i in range(n - 1, -1, -1):
        if i > 27:
            max_node[i] = min(usable_nodes[i], leafs[i]+max_node[i+1])
        else:
            max_node[i] = min(2 ** i, usable_nodes[i], leafs[i]+max_node[i+1])

    return sum(max_node)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    result = solve(n, a)
    print(result)


class Test(unittest.TestCase):
    def test_solve_1(self):
        n = 3
        a = [0, 1, 1, 2]
        actual = solve(n, a)
        expected = 7
        self.assertEqual(actual, expected)

    def test_solve_2(self):
        n = 4
        a = [0, 0, 1, 0, 2]
        actual = solve(n, a)
        expected = 10
        self.assertEqual(actual, expected)

    def test_solve_3(self):
        n = 2
        a = [0, 3, 1]
        actual = solve(n, a)
        expected = -1
        self.assertEqual(actual, expected)

    def test_solve_4(self):
        n = 1
        a = [1, 1]
        actual = solve(n, a)
        expected = -1
        self.assertEqual(actual, expected)

    def test_solve_5(self):
        n = 10
        a = [0, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
        actual = solve(n, a)
        expected = 264
        self.assertEqual(actual, expected)

    def test_solve_6(self):
        n = 5
        a = [0, 1, 1, 1, 1, 1]
        actual = solve(n, a)
        expected = 10
        self.assertEqual(actual, expected)

    def test_solve_7(self):
        n = 3
        a = [0, 1, 2, 4]
        actual = solve(n, a)
        expected = -1
        self.assertEqual(actual, expected)

    def test_solve_8(self):
        n = 12
        a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2**12]
        actual = solve(n, a)
        expected = 2**13-1
        self.assertEqual(actual, expected)

    def test_solve_9(self):
        n = 3
        a = [0, 0, 0, 8]
        actual = solve(n, a)
        expected = 15
        self.assertEqual(actual, expected)


if __name__ == "__main__":
    main()


Measured memory_bytes: 687260
n, w = [int(i) for i in input().split()]
wv = [[int(i) for i in input().split()] for _ in range(n)]

# dp[i][j]: i番目までの品物から重さの合計がj以下となるように選んだときの価値の最大値
dp = [[0]*(w+1) for _ in range(n+1)]

for i in range(n):
    w_i, v_i = wv[i]
    for j in range(w+1):
        # i番目の品物を選ぶ
        if j - w_i >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j-w_i] + v_i)
        # i番目の品物を選ばない
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[-1][-1])


Measured memory_bytes: 120940
#include <stdio.h>
#include <stdlib.h>

#define N 100000
#define NIL -1

typedef struct t{
  int id;
  int childnum;
  int parent;
  int depth;
  unsigned int *child;
}Tree;

void depthcalculation(int, int);

Tree T[N];

int main(){
  int treenum, i, id, j;
  
  scanf("%d", &treenum);
  
  //preparation
  for(i = 0; i < treenum; i++){
    T[i].parent = NIL;
    T[i].depth = 0;
  }
  
  //input
  for(i = 0; i < treenum; i++){
    scanf("%d", &id);
    T[id].id = id;
    scanf("%d", &T[id].childnum);
    
    T[id].child = malloc(sizeof(int) * T[id].childnum);
    for(j = 0; j < T[id].childnum; j++){
      scanf("%d", &T[id].child[j]);
      T[ T[id].child[j] ].parent = id;
    }
  }
  //root search
  for(i = 0; i < treenum; i++){
    if(T[i].parent == NIL){
      break;
    }
  }
  
  depthcalculation(i, 0);
  
  //output
  for(i = 0; i < treenum; i++){
    printf("node %d: parent = %d, depth = %d, ", T[i].id, T[i].parent, T[i].depth);

    if(T[i].parent == -1){
      printf("root, ");
    }
    else if(T[i].childnum == 0){
      printf("leaf, ");
    }
    else{
      printf("internal node, ");
    }
    
    printf("[");
    for(j = 0; j < T[i].childnum-1; j++){
      printf("%d, ", T[i].child[j]);
    }
    if(T[i].childnum != 0){
      printf("%d", T[i].child[j]);
    }
    printf("]\n");
    
  }
  
  return 0;
}

void depthcalculation(int t, int d){
  int i;

  T[t].depth = d;
  
  for(i = 0; i < T[t].childnum; i++){
    depthcalculation(T[t].child[i], d+1);
  }
  
}



Measured memory_bytes: 7560
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#define ll long long
using namespace std;
const int INF=1e9+7;
int n,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1,x,j;i<=n;i++)
		scanf("%d",&x),ans=ans^x;
	if(!ans)printf("Yes");
	else printf("No");
}

Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> a(n);
    iota(all(a), 1);
    do {
        rep(i, n) cout << a[i] << (i == n-1 ? '\n' : ' ');
    } while (next_permutation(all(a)));
}



Measured memory_bytes: 3168
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int K = sc.nextInt();

			if(n == 0){
				break;
			}

			int dp[][] = new int[n + 1][m*n + 1];

			for(int i = 1; i <= m; i++){
				dp[1][i] = 1;
			}

			for(int i = 2; i <= n; i++){
				for(int j = i - 1; j <= m*n; j++){
					for(int k = 1; k <= m; k++){
						if(j + k > m*n){
							break;
						}
						dp[i][j + k] += dp[i - 1][j];
					}
				}
			}

			//debug
//			for(int i = 1; i <= n; i++){
//				for(int j = 1; j <= m*n; j++){
//					System.out.print(dp[i][j] + " ");
//				}
//				System.out.println();
//			}

			double result = 0;
			for(int i = n; i <= m*n; i++){
				if(i <= K){
					result += dp[n][i];
				}
				else {
					result += dp[n][i] * (i - K);
				}
			}
			result /= Math.pow(m, n);

			System.out.println(result);
		}
	}

}



Measured memory_bytes: 28188
from collections import deque
n = int(input())
g = [[] for _ in range(n)]
for i in range(n-1):
  u, v, w = map(int, input().split())
  g[u-1].append((v-1,w))
  g[v-1].append((u-1,w))
ds = [-1]*n
dq = deque([0])
ds[0] = 0
while dq:
  t = dq.popleft()
  for i in g[t]:
    if ds[i[0]] == -1:
      ds[i[0]] = ds[t] + i[1]
      dq.append((i[0]))
for i in ds:
  if i%2 == 0:
    print(0)
  else:
    print(1)


Measured memory_bytes: 47864
#include<iostream>
using namespace std;
int main(){
    int h,w;
    while(1){
        cin >> h >>w;
        if(h==0&&w==0)break;
        else{
            int i,j;
            for(i=1;i<=h;i++){
                for(j=1;j<=w;j++){
                    if((i+j)%2==1){
                        cout<<".";
                    }
                    else{
                        cout<<"#";
                    }
                }
                cout<<endl;
            }
            cout<<endl;
        }
    }
    return 0;
} 


Measured memory_bytes: 3104
n = int(input())
listForA=[]

index=0
while index < n:
   listForA.append(int(input()))
   index+=1

listForA.sort()
index2 =0
beforeC=""
count=0
allCount=0
while index2 < n:
    if index2==0:
        beforeC=listForA[index2]
        count=1
    else:
        if beforeC == listForA[index2]:
            count+=1
        else:
            if count%2==1:
                allCount+=1
            beforeC = listForA[index2]
            count=1
    index2+=1
if count%2==1:
    allCount+=1

print(allCount)

Measured memory_bytes: 7388
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
	int n;
	cin >> n;
	if(n % 2 == 0) cout << (double)1/2 << endl;
	else cout << (double)(n+1)/2/(double)n << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define Rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//べき//
ll squ(ll n, ll p, ll m){
	if(p==0) return 1;
	if(p%2==0){
		ll t=squ(n, p/2, m);
		return t*t%m;
	}
	return n*squ(n,p-1,m);
	
}


//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//nが大

ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}

	return k;
}


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


int main() {
ll n;
cin>>n;
ll a[n+1];
for(ll i=1;i<=n;i++){
	cin>>a[i];
}

ll ans=0;

ll pow2[61];
for(ll i=0;i<=60;i++){
	if(i==0){pow2[0]=1;
	continue;}
	pow2[i]=pow2[i-1]*2;
	pow2[i]%=MOD;
}
  
  

ll bitcnt[61];
for(ll i=0;i<=60;i++){
	bitcnt[i]=0;
}
for(ll i=1;i<=n;i++){
for(ll j=0;j<=60;j++){
  ll t=((ll)1<<j);
	if(a[i]&t){
		bitcnt[j]++;
	}
}
}
  
  


ll k;
for(ll i=0;i<=60;i++){
   k=0;
 k=bitcnt[i]*(n-bitcnt[i]);
  k%=MOD;
  k*=pow2[i];
  k%=MOD;
  
  ans+=k;
ans%=MOD;
}

cout<<ans<<endl;
return 0;

}






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

namespace Atc_0031
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());

            var s = Console.ReadLine();

            List<double> Nums = new List<double>();

            for (int i = 0; i < N; i++)
            {
                Nums.Add(double.Parse(s.Split(' ')[i]));
            }

            double ret = 0;
            for (int i = 0; i < Nums.Count(); i++)
            {
                ret += 1 / Nums[i];
            }

            Console.WriteLine(1 / ret);

        }
    }
}


Measured memory_bytes: 28616
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

const int MAXN = 200005;

char S[MAXN], T[MAXN];

struct Edge;
struct Node {
    bool e[26];
    int ideg, odeg;
} N[26];

void addEdge(int u, int v) {
    if (!N[u].e[v]) {
        N[u].e[v] = true;
        ++N[u].odeg;
        ++N[v].ideg;
    }
}

bool exist[26];

bool check(int i) {
    if (exist[i]) {
        if (N[i].ideg == 1 && N[i].odeg == 1) return true;
        if (N[i].ideg == 0 && N[i].odeg == 1) return true;
        if (N[i].ideg == 0 && N[i].odeg == 0) return true;
    } else {
        if (N[i].ideg <= 1 && N[i].odeg == 0) return true;
    }
    return false;
}

int main() {
    scanf("%s %s", S, T);
    int n = strlen(S);
    for (int i = 0; i < n; i++) exist[S[i] - 'a'] = true;
    for (int i = 0; i < n; i++) addEdge(S[i] - 'a', T[i] - 'a');

    for (int i = 0; i < 26; i++) if (!check(i)) return puts("No"), 0;
    puts("Yes");
    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long LL;
const int64_t INF=1e18+1;
const int mod = 1000000007;

int T;
map<LL,LL>s;
LL N,a,b,c,d;
LL dfs(LL n){
  	if(n==0)return s[0]=0;
    //if(n==1)return 1;
	if(s[n]>0)return s[n];
	if(1e18/n<=d){s[n]=1e18;}
    else{s[n]=n*d;}
	s[n]=min(s[n],dfs(n/2)+a+(n%2)*d);
	s[n]=min(s[n],dfs(n/3)+b+(n%3)*d);
	s[n]=min(s[n],dfs(n/5)+c+(n%5)*d);
	s[n]=min(s[n],dfs(n/2+1)+a+(2-n%2)*d);
	s[n]=min(s[n],dfs(n/3+1)+b+(3-n%3)*d);
	s[n]=min(s[n],dfs(n/5+1)+c+(5-n%5)*d);
	return s[n];
}

int main(){
  cin>>T;
  for(int i=0;i<T;i++){
    cin>>N>>a>>b>>c>>d;
    s.clear();
    cout<<dfs(N)<<endl;
  }
  return 0;                       
}

Measured memory_bytes: 4796
#MLE注意！ not は使わず !=

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    n,k = map(int, input().split())

    res = 0

    for i in range(k, n+2):
        res += (2*n-i+1)*i//2 - (i-1)*i//2 +1
        res %= mod
    print(res)

if __name__ == '__main__':
    main()

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

constexpr char NL = '\n';
constexpr int MOD = 1e9 + 7;

struct safe_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_set<int> digits;

bool good(int i) {
    while (i != 0) {
        int digit = i % 10;
        if (digits.find(digit) != digits.end()) {
            return false;
        }
        i = i / 10;
    }
    return true;
}


void solve()
{
    int n, k; cin >> n >> k;
    for (int i = 0; i < k; ++i) {
        int digit; cin >> digit;
        digits.insert(digit);
    }
    for (int i = n; i <= 99999; ++i) {
        if (good(i)) {
            cout << i << NL;
            return;
        }
    }
    cout << 0 << NL;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cerr << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()
#define X first
#define Y second
#define pb push_back
#define fast cin.tie(0); ios::sync_with_stdio(false)
#define vi vector<int>
#define vii vector<vector<int>>
struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    void merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};
 
int32_t main(){ fast;
	int n, m; cin>>n>>m;
	dsu a(n);
	while(m--){
		int x, y; cin>>x>>y;
		x--; y--;
		a.merge(x, y);
	}
	
	auto t = a.groups();
	int answer = 0;
	for(auto x: t){
		answer = max(answer, (int)x.size());
	}
	cout<<answer<<endl;
			
}


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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  ll N, X;
  cin >> N >> X;
  ll m[N];
  rep(i,0,N)cin >> m[i];

  sort(m, m+N);
  ll sum = 0;
  rep(i,0,N){
    sum += m[i];
  }
  cout << (X - sum) / m[0] + N << endl;
  return 0;
}

Measured memory_bytes: 256
def xor(n):
    if n % 4 == 0:
        return n
    elif n % 4 == 1:
        return 1
    elif n % 4 == 2:
        return n + 1
    else:
        return 0

A, B = map(int, input().split())
print(xor(A-1)^xor(B))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int dp[n];
    vector<int>v(n);
    for(auto &x : v) cin>>x;
    dp[0] = 0;
    dp[1] = abs(v[1] - v[0]);
    for(int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i-1] + abs(v[i] - v[i-1]), dp[i-2] + abs(v[i] - v[i-2]));
    }
    cout<<dp[n-1];

}

Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>

using namespace std;

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

  int Mt_Max = 0;
  int count = 0;
  for (int i = 0; i < N; ++i)
  {
    int H;
    cin >> H;

    if (Mt_Max <= H)++count;
    if (Mt_Max < H) Mt_Max = H;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

long long Pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret *= x;
        x *= x;
        n >>= 1;
    }
    return ret;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n;
  cin >> n;
  ll ans = 0;
  if (n%2 == 1) cout << 0 << '\n';
  else {
    rep(i,30) {
      ans += n/Pow(5,i+1)/10;
    }
    ans += n/10;
    cout << ans << '\n';
  }
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <sstream>
using namespace std;

#define namefile ""
#define inifile freopen(namefile".inp","r",stdin); freopen(namefile".out","w",stdout)
#define fastio ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef unsigned int uint;
typedef unsigned long ulong;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef vector<int> VI;
typedef vector<long> VL;
typedef vector<string> VS;
typedef vector< VI > VVI;
typedef vector< VL > VVL;
typedef vector< PII > VPII;
typedef vector< PLL > VPLL;
typedef set<int> SETI;
typedef set<long> SETL;
typedef map<int,int> MII;
typedef map<long,long> MLL;

const long long MOD = 1e9+7;
const long long INFMAX = 1e9;
const long long INFMIN = -1e9;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const double epsilon = 1e-9;
const double PI = acos(-1.00);
const int MAXN = 2e5+5;

int n,q;
VVI g;

bool visited[MAXN];
llong c[MAXN],res[MAXN];

void Input()
{
    scanf("%d %d",&n,&q);
    int u,v;
    g.resize(n+5);
    for (int i=1; i<=n-1; i++)
    {
        scanf("%d %d",&u,&v);
        g[u].pb(v);
        g[v].pb(u);
    }
}

void DFSVisit(int u, llong prev)
{
    visited[u] = true;
    res[u] = c[u] + prev;
    for (int i=0; i<g[u].size(); i++)
    {
        int v = g[u][i];
        if (!visited[v]) DFSVisit(v,prev + c[u]);
    }
}

void Solve()
{
    int u,x;
    for (int i=1; i<=q; i++)
    {
        scanf("%d %d",&u,&x);
        c[u] += x;
    }

    DFSVisit(1,0);
}

void Output()
{
    for (int i=1; i<=n; i++) printf("%lld ",res[i]);
}

int main()
{
    Input();
    Solve();
    Output();
    return 0;
}


Measured memory_bytes: 25856
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    ll x;
    cin >> x;

    if(x%11 == 0){
        cout << x/11*2 << endl;
    }else if(x%11 <= 6){
        cout << x/11*2 + 1 << endl;
    }else if(x%11 > 6){
        cout << x/11*2 + 2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <stdexcept>
using namespace std;

int main() {
  int N, A, B;
  cin >> N;
  if(N==1)
    cout << "Hello World" << endl;
  else {
    cin >> A>>B;
    cout << A+B << endl;
  }
}


Measured memory_bytes: 256
using System;
class p
{
  static void Main()
  {
    string[] ipt = Console.ReadLine().Split(' ');
    int N = int.Parse(ipt[0]);
    int T = int.Parse(ipt[1]);
    ipt = Console.ReadLine().Split(' ');
    int[] arr = new int[N];
    for (int i = 0; i < N; i++) {
      arr[i] = int.Parse(ipt[i]);
    }
    int time = T;
    for (int i = 1; i < N; i++) {
      time += (T <= arr[i] - arr[i-1]) ? T : T - (arr[i-1] + T - arr[i]);
    }
    Console.WriteLine(time);
  }
}

Measured memory_bytes: 26208
s = input()

n = len(s)

def K(x):
    l = len(x)
    for i in range(l):
        if x[i] != x[l-1-i]:
            return False
    return True

if K(s) and K(s[:(n-1)//2]) and K(s[(n+3)//2 -1 :]):
    print("Yes")
else:
    print("No")

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

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int cnt=0;
    int a=0;
    int b=0;
    int c=0;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        int l=s.size();
        for(int i = 1; i < l; i++) if(s[i-1]=='A'&&s[i]=='B') cnt++;
        if(s[0]=='B') b++;
        if(s[l-1]=='A') a++;
        if(s[0]=='B' && s[l-1]=='A') c++;
    }
    a-=c;
    b-=c;
    if(c>1){
        cnt+=c-1;
        c=1;
    }
    if(c==1){
        if(a>0){
            a--;
            cnt++;
        }
        if(b>0){
            b--;
            cnt++;
        }
    }
    cnt+=min(a,b);
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 3644
def binary_search(n, k, lw):
    left = 0
    right = max(lw) * n

    while left <= right:
        mid = (left + right)//2
        if is_underweight(n, k, lw, p=mid):
            right = mid - 1
        else:
            left = mid + 1

    if is_underweight(n, k, lw, p=right):
        return right
    else:
        return left

def is_underweight(n, k, lw, p):
    i = 0
    w = 0
    ck = 1
    while i < n:
        if lw[i] > p:
            return False
        rest = p - w
        if lw[i] <= rest:
            w += lw[i]
            i += 1
        else:
            w = 0
            ck += 1
    return ck <= k

def main():
    n, k = map(int, input().split())
    lw = []
    for _ in range(n):
        lw.append(int(input()))

    p = binary_search(n, k, lw)

    print(p)

if __name__ == '__main__':
    main()



Measured memory_bytes: 9512
int main(int argc,const char * argv[]){
    int x[3000];
    int y[3000];
    int i,t;
    
    for(i=0;;i++){
        scanf("%d %d",&x[i],&y[i]);
        if(x[i]==0 && y[i]==0){
            break;
        }
    }
    for(i=0;;i++){
        if(x[i]==0 && y[i]==0){
            break;
        }
        if(x[i]>y[i]){
            t = x[i];
            x[i] = y[i];
            y[i] = t;
        }
    }
    
    for(i=0;;i++){
        if(x[i]==0 && y[i]==0){
            break;
        }
        printf("%d %d\n",x[i],y[i]);
    }
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
//const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x; 
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}com(200005);
mint choose(int n,int a){
  mint x = 1,y=1;
  rep(i,a){
    x*= n-i;
    y*= i+1;
  }
  return x/y;
}

int main(){
  int n,m,k;cin>>n>>m>>k;
  mint ans =0;
  mint c = m;
  for(int i = 0;i<n;i++){
    mint now =c;
    now *= com(n-1,i);
    if(n-i-1<=k)ans+=now;
    c*=m-1;
  }
  cout<<ans.x<<endl;
}

Measured memory_bytes: 6232