akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

ll nCr(ll n, ll r) {
	ll ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}

int main() {
    int n;
    cin >> n;
    map<ll, ll> mp;
    REP(i, n){
        int now = i;
        for(int j = 2; j * j <= i; j++){
            while(now % j == 0){
                mp[j]++;
                now /= j;
            }
        }
        if(now != 1)mp[now]++;
    }
    int t=0, f=0, tf=0, of=0, sf=0;
    for(auto x : mp){
        if(x.second >= 2)t++;
        if(x.second >= 4)f++;
        if(x.second >= 24)tf++;
        if(x.second >= 14)of++;
        if(x.second >= 74)sf++;
    }
    
    cout << nCr(f, 2) * (t-2) + tf * (t-1) + of * (f-1) + sf<< endl;
}  

Measured memory_bytes: 256
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        for(int i = N; i < 1000001; i++) {
            if(isPrime(i)) {
                System.out.println(i);
                return;
            }
        }


    }

    public static boolean isPrime(int n) {
        if(n == 2) return true;
        if(n % 2 == 0) return false;

        for(int i = 3; i * i <= n; i += 2) {
            if(n % i == 0) return false;
        }
        return true;
    }
}

Measured memory_bytes: 23124
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
using pii=std::pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); <-- PUT IN main()/solve()!

using namespace std;

int n,W,w[1000005],v[100005],dp[105][100005]={0};
class DKnapsack1 {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> n >> W;
		f(i,0,n)
			in >> w[i] >> v[i];
		f(i,0,n)
			f(j,0,W+1)
			{
				dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
				if(j>=w[i])
					dp[i+1][j-w[i]]=max(dp[i][j]+v[i],dp[i+1][j-w[i]]);
			}

		int ans=0;
		f(i,0,W+1)
			ans=max(dp[n][i],ans);
		out << ans << "\n";

	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	DKnapsack1 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 81536
#include <stdio.h>

#define MAP_J 0
#define MAP_O 1
#define MAP_I 2

char map[1000][1001];
int map_sum[1001][1001][3];

int selmap(char c) {
	if(c=='J')return MAP_J;
	if(c=='O')return MAP_O;
	if(c=='I')return MAP_I;
	return 0;
}

int main(void) {
	int M,N;
	int K;
	int sx,sy,dx,dy;
	int i,j;
	scanf("%d %d",&M,&N);
	scanf("%d",&K);
	for(i=0;i<M;i++) {
		scanf("%s",map[i]);
	}
	for(i=1;i<=M;i++) {
		for(j=1;j<=N;j++) {
			map_sum[j][i][MAP_J]=
				map_sum[j-1][i][MAP_J]+map_sum[j][i-1][MAP_J]-
				map_sum[j-1][i-1][MAP_J];
			map_sum[j][i][MAP_O]=
				map_sum[j-1][i][MAP_O]+map_sum[j][i-1][MAP_O]-
				map_sum[j-1][i-1][MAP_O];
			map_sum[j][i][MAP_I]=
				map_sum[j-1][i][MAP_I]+map_sum[j][i-1][MAP_I]-
				map_sum[j-1][i-1][MAP_I];
			map_sum[j][i][selmap(map[i-1][j-1])]++;
		}
	}
	for(i=0;i<K;i++) {
		scanf("%d %d %d %d",&sy,&sx,&dy,&dx);
		printf("%d %d %d\n",
			map_sum[dx][dy][MAP_J]-map_sum[dx][sy-1][MAP_J]-
			map_sum[sx-1][dy][MAP_J]+map_sum[sx-1][sy-1][MAP_J],
			map_sum[dx][dy][MAP_O]-map_sum[dx][sy-1][MAP_O]-
			map_sum[sx-1][dy][MAP_O]+map_sum[sx-1][sy-1][MAP_O],
			map_sum[dx][dy][MAP_I]-map_sum[dx][sy-1][MAP_I]-
			map_sum[sx-1][dy][MAP_I]+map_sum[sx-1][sy-1][MAP_I]);
	}
	return 0;
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int ans;
string s; 
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>s;
	int len=s.size();
	for(int i=1;i<len-1;i++) 
	{
		ans++;
	}
	cout<<s[0]<<ans<<s[len-1];

	return 0;
}


Measured memory_bytes: 256
open Printf
open Scanf

let () =
  let n, q = scanf "%d %d\n" (fun x y -> (x, y)) in
  let queue = Queue.create () in
  let rec init_q x =
    if x = 0 then () else
      let d = scanf "%s %d\n" (fun a b -> (a, b)) in
      Queue.push d queue; init_q (x-1) in
  let rec iter ct =
    if Queue.is_empty queue then ()
    else begin
        let (n, t) = Queue.pop queue in
        if t <= q then begin
            printf "%s %d\n" n (ct + t);
            iter (ct + t)
          end
        else begin
            Queue.push (n, t - q) queue;
            iter (ct + q)
          end
      end
  in
  init_q n;
  iter 0

Measured memory_bytes: 12684
#include <stdio.h>
int main(void){
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    
    int max = (a>b)? b : a;
    int min = (a + b -n < 0)? 0 : a + b -n;
    
    printf("%d %d\n", max, min);
    
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N;
    ll x, y;
    cin >> N;
    x = N * 800;
    y = (N / 15) * 200;
    cout << x - y << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<n; i++)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;

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

int main() {
    int N;
    cin >> N;
    int X[N];
    for (int i = 0; i < N; i++)
    {
        cin >> X[i];
    }
    sort(X, X+N);
    int ans = 100000000;
    for (int i = 0; i < 100; i++)
    {
        int total = 0;
        for (int j = 0; j < N; j++)
        {
            total +=(X[j]-i)*(X[j]-i);
        }
        chmin(ans, total);
    }
    cout << ans << endl;
    
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int n, f, s, ans = 0; cin >> n >> f >> s;

    REPI(i, n - 2){
        int x; cin >> x;
        if((f <= s && s < x) || (x <= s && s < f)) ans++;
        f = s;
        s = x;
    }cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll a[n];
  rep(i,n) R a[i];
  REP(i,m,n) {
    if(a[i-m]<a[i]) pr("Yes");
    else pr("No");
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 5220
# 1
# https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_a
if False:
    N,K=map(int,input().split())
    print('YES' if N-K-(K-1)>=0 else 'NO')

# 2
# https://atcoder.jp/contests/exawizards2019/tasks/exawizards2019_b
N=int(input())
S=input()
print('Yes' if S.count('R')>S.count('B') else 'No')


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

int max(int a, int b){
	return a >= b ? a : b;
}

int main(){
	int A, B, C;
	scanf("%d%d%d", &A, &B, &C);
	printf("%d\n", 9 * max(A, max(B, C)) + A + B + C);
	return 0;
}

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

int n,m;

int main(){
  int i,j;
  int a,b,c;

  scanf("%d%d%d",&a,&b,&c);
  if(c<=a+b)printf("Yes\n");
  else printf("No\n");
  

  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <stack>
#include <map>
#include <cmath>
#include <algorithm>

int main(int argc, char *argv[]){
    int N;
    std::cin >> N;
    long int H[N];
    for(auto &h : H){
        std::cin >> h;
    }

    long int dist;
    for(int i=N-2; i>=0; --i){
        dist = H[i]-H[i+1];
        if(dist > 1){
            std::cout << "No" << std::endl;
            return 0;
        }else if(dist == 1){
            --H[i];
        }
    }
    std::cout << "Yes" << std::endl;
    return 0;
}


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


int main(){
    long long n,m,a,b,c=0,a1=0,max=0;
    cin>>n>>m;
    if(m<=n)cout<<0<<endl;
    else{
    long long x[m],s[m-1];
    for (int i=0; i<m; i++) {
        cin>>x[i];
    }
    sort(x,x+m);
    for (int i=1; i<m; i++) {
        s[i-1]=x[i]-x[i-1];
        a1+=s[i-1];
    }
    sort(s, s+m-1);
    reverse(s, s+m-1);
    for (int i=0; i<n-1; i++) {
        a1-=s[i];
    }
    cout<<a1<<endl;
    }
}


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

using namespace std;

#define forn(i, n) for (int i = 0; i < n; i++)
#define sz(a) (int)a.size()
#define re return
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

typedef long long ll;
typedef vector<int> vi;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll ma = 131072, inf = 10LL * ((ll)1e9);
ll n, m, ans[200000], cnt[200000];

int main() {
	iostream::sync_with_stdio(0), cin.tie(0);
	//freopen("a.in", "r", stdin);
	//freopen(".out", "w", stdout);
	cin >> n >> m;
	ans[0] = 1;
	forn (i, n)
		cnt[i] = 1;
	forn (i, m) {
		int x, y;
		cin >> x >> y;
		x--; 
		y--;
		if (ans[x]) {
			if (cnt[x] == 1)
				ans[x] = 0;
			ans[y] = 1;
		}
		cnt[x]--;
		cnt[y]++;
	}
	int an = 0;
	forn (i, n)
		an += ans[i];
	cout << an;
	re 0;
}




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

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    vector<int> m;
    int n, a, p = 0, q = 0;
    cin >> n >> a;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        m.emplace_back(x-a);
    }
    vector<vector<ll>> v(2, vector<ll>(10001, 0));
    v[0][5000] = 1;
    for (int i = 0; i < n; ++i) {
        int prv = i % 2, now = prv^1;
        int b = m[i];
        v[now].assign(10001, 0);
        for (int j = p; j <= q; ++j) {
            v[now][5000+j+b] += v[prv][5000+j];
            v[now][5000+j] += v[prv][5000+j];
        }
        p = min(p, p+b); q = max(q, q+b);
    }
    cout << v[n%2][5000]-1 << "\n";
    return 0;
}


Measured memory_bytes: 512
#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 main() {
    int n;
    cin >> n;
    int odd = n/2;
    if(n%2)odd++;
    int even = n/2;
    cout << odd*even << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#define enter putchar('\n')
#define space putchar(' ')
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define eps 1e-7
#define MAXN 1000005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {putchar('-');x = -x;}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,K,L[2005];
char s[2005][10005];
bool vis[2005][10005];
int dp[10005],tot;
pii que[8005],tmp[8005];
char ans[10005];
void Init() {
    read(N);read(K);
    for(int i = 1 ; i <= N ; ++i) {
	scanf("%s",s[i] + 1);
	L[i] = strlen(s[i] + 1);
    }
    vis[N + 1][0] = 1;
    for(int i = N ; i >= 1 ; --i) {
	for(int j = K ; j >= 0 ; --j) {
	    vis[i][j] |= vis[i + 1][j];
	    if(j >= L[i]) vis[i][j] |= vis[i + 1][j - L[i]];
	}
    }
    for(int i = 1 ; i <= K ; ++i) dp[i] = N + 1;
}
void Solve() {
    for(int i = 1 ; i <= K ; ++i) {
	int t = 26;
	for(int j = dp[i - 1] + 1 ; j <= N ; ++j) {
	    if(K - L[j] - i + 1 >= 0 && vis[j + 1][K - L[j] - i + 1]) {
		t = min(t,s[j][1] - 'a');
	    }
	}
	for(int j = 1 ; j <= tot ; ++j) {
	    t = min(t,s[que[j].fi][que[j].se + 1] - 'a');
	}
	ans[i] = 'a' + t;
	int tp = 0;
	for(int j = dp[i - 1] + 1 ; j <= N ; ++j) {
	    if(K - L[j] - i + 1 >= 0 && vis[j + 1][K - L[j] - i + 1]) {
		if(s[j][1] - 'a' == t) {
		    if(L[j] == 1) dp[i] = min(dp[i],j);
		    else tmp[++tp] = mp(j,1);
		}
	    }
	}
	for(int j = 1 ; j <= tot ; ++j) {
	    if(s[que[j].fi][que[j].se + 1] - 'a' == t) {
		if(que[j].se + 1 == L[que[j].fi]) dp[i] = min(dp[i],que[j].fi);
		else tmp[++tp] = mp(que[j].fi,que[j].se + 1);
	    }
	}
	random_shuffle(tmp + 1,tmp + tp + 1);
	tot = min(tp,3 * N);
	for(int j = 1 ; j <= tot ; ++j) que[j] = tmp[j];	
    }
    for(int i = 1 ; i <= K ; ++i) {
	putchar(ans[i]);
    }
    enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
}


Measured memory_bytes: 39296
#include <iostream>

using namespace std;

int main()
{
	int n, max, min;

	long long sum = 0;

	int a[10001];

	cin >> n;

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

		if (i == 1)
		{
			max = a[i];
			min = a[i];
		}
		else
		{
			if (a[i] > max)
			{
				max = a[i];
			}

			if (a[i] < min)
			{
				min = a[i];
			}
		}

		sum += a[i];
	}

	cout << min << ' ' << max << ' ' << sum << endl;

	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include <vector>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin>>n;
  int t[n],x[n],y[n];
  REP(i,n){
    cin>>t[i]>>x[i]>>y[i];
  }
  
  bool b = true;
  REP(i,n){
    int dt = i==0?t[i]:(t[i]-t[i-1]);
    int kyori = i==0?(abs(x[i])+abs(y[i])):(abs(x[i]-x[i-1])+abs(y[i]-y[i-1]));
    if(dt<kyori){
      b = false;
    }else if((dt-kyori)%2 != 0){
	  b = false;
    }
  }
  if(b){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
int a,b,c;
   cin>>a>>b>>c;
  if((b*10+c)%4==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>


typedef long double ld;
typedef long long ll;
using namespace std;
const ll MX=5e6+9;
const ld pi = acos(-1);
const ll mod = 1e8;

//bool cmp ( int a,int b ) { return a>b; }

ll po ( ll a , ll b )
{
    if ( b==0 ) { return 1; }
    ll x = po ( a , b/2 );
    x *= x%mod;
    if ( b%2 ) { x*=a%mod; }
    return x%mod;
}

ll gcd (  ll a , ll b )
{
    if ( b==0 ) return a;
    else { gcd( b , a%b ); }
}
bool cmp ( int a , int b ) { return (a>b); }
int dx[]={ 0 , 0 , -1 , 1 , 1 , -1 , -1 , 1 };
int dy[]={ 1 , -1 , 0 , 0 , 1 , -1 , 1 , -1 };
ll a[MX],b[MX],c[MX];
int n,m,l;


ll bs ( ll x , ll id )
{
    ll st,en,mid;
    if ( id==2 )
    {
        st=0,en=m;
    }
    else { st=0,en=l; }
    ll ans=0;
    if ( id==2 ){
    ans=m-1;
    while ( st<=en )
    {
        mid = st+(en-st)/2;
        if ( b[mid]>=x ) { ans=mid; en=mid-1; }
        else { st=mid+1; }
    }
    }
    else
    {
    ans=l-1;
    while ( st<=en )
    {
        mid = st+(en-st)/2;
        if ( c[mid]>=x ) { ans=mid; en=mid-1; }
        else { st=mid+1; }
    }
    }
    return ans;



}

int main()
{
    int x,y,s,e;
    cin>>x>>y>>s>>e;
    string ans;

    int xx=x,yy=y;

    while ( xx<s ) { ans += "R"; xx++; }
    while ( yy<e ) { ans += "U"; yy++; }

    for ( int i=0 ; i<ans.length() ; i++ )
    {
        if ( ans[i]=='U' ) { ans+= "D"; }
        if ( ans[i]=='R' ) { ans+= "L"; }
    }

    ans += "D";
    xx = x;
    yy = y-1;

    while ( xx<=s ) { ans += "R"; xx++; }
    while ( yy<e ) { ans += "U"; yy++; }

    ans += "L";
    ans += "U";

    xx = s;
    yy = e+1;

    while ( xx>=x ) { ans += "L"; xx--; }
    while ( yy>y  ) { ans += "D"; yy--; }

    ans += "R";

    cout<<ans;



	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int[][] hopeBlack = new int[2*k][2*k];
		int[][] hopeWhite = new int[2*k][2*k];
		for(int i=0;i<n;i++) {
			int x = in.nextInt()%(2*k);
			int y = in.nextInt()%(2*k);
			if(in.next().equals("B")) hopeBlack[x][y]++;
			else hopeWhite[x][y]++;
		}
		in.close();
		int[][] sumB = new int[2*k][2*k];
		int[][] sumW = new int[2*k][2*k];
		for(int i=0;i<2*k;i++) {
			for(int j=0;j<k;j++) {
				sumB[i][0] += hopeBlack[i][j];
				sumW[i][0] += hopeWhite[i][j];
			}
			for(int j=1;j<2*k;j++) {
				sumB[i][j] = sumB[i][j-1] + hopeBlack[i][(j-1+k)%(2*k)] - hopeBlack[i][j-1];
				sumW[i][j] = sumW[i][j-1] + hopeWhite[i][(j-1+k)%(2*k)] - hopeWhite[i][j-1];
			}
		}
		int[][] sumB2 = new int[2*k][2*k];
		int[][] sumW2 = new int[2*k][2*k];
		for(int i=0;i<2*k;i++) {
			for(int j=0;j<k;j++) {
				sumB2[0][i] += sumB[j][i];
				sumW2[0][i] += sumW[j][i];
			}
			for(int j=1;j<2*k;j++) {
				sumB2[j][i] = sumB2[j-1][i] + sumB[(j-1+k)%(2*k)][i] - sumB[j-1][i];
				sumW2[j][i] = sumW2[j-1][i] + sumW[(j-1+k)%(2*k)][i] - sumW[j-1][i];
			}
		}
		int ans = 0;
		for(int i=0;i<k;i++) {
			for(int j=0;j<2*k;j++) {
				ans = Math.max(ans, sumB2[i][j]+sumB2[i+k][(j+k)%(2*k)]+sumW2[i+k][j]+sumW2[i][(j+k)%(2*k)]);
			}
		}
		System.out.println(ans);
		

	}

}


Measured memory_bytes: 165184
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int[] foods = new int[M];
        
        for(int i = 0; i < N; i++){
            
            int K = sc.nextInt();
            for(int j = 0; j < K; j++){
                int A = sc.nextInt() - 1;
                foods[A]++;
            }
        }
        
        int ans = 0;
        for(int i = 0; i < M; i++){
            if( foods[i] == N ) ans++;
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include <iostream>

using namespace std;

const int MOD = 1000003;
const int N_MAX =  1000003;

typedef long long ll;

ll inv[N_MAX],fac[N_MAX],finv[N_MAX];

void init(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(ll) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

int main(){
    init();
    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        ll x, d, n;
        cin >> x >> d >> n;
        ll m = (x*inv[d])%MOD;
        if(d == 0){
            ll powx = 1;
            ll tmp = x;
            for(int j = 0; j <= 30; j++){
                if(n&(1<<j)){
                    powx *= tmp;
                    powx %= MOD;
                }
                tmp = (tmp*tmp);
                tmp %= MOD;
            }
            cout << powx << endl;
        }else if(m == 0 || m+n-1 >= MOD || x == 0){
            cout << 0 << endl;
        }else{
            ll ans = (fac[m+n-1]*finv[m-1])%MOD;
            ll tmp = d;
            ll powd = 1;
            for(int j = 0; j <= 20; j++){
                if(n&(1<<j)){
                    powd *= tmp;
                    powd %= MOD;
                }
                tmp = (tmp*tmp);
                tmp %= MOD;
            }
            ans *= powd;
            ans %= MOD;
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 24320
#include <vector>
#include <iostream>
#include <queue>
#include <deque>

using namespace std;


int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<vector<int>> g(n);
  deque<int> ans;
  vector<int> used(n);
  int from, to;
  scanf("%d%d", &from, &to);
  --from; --to;
  ans.push_back(from);
  ans.push_back(to);
  g[from].push_back(to);
  g[to].push_back(from);
  used[from] = 1;
  used[to] = 1;
  for (int i = 1; i < m; ++i) {
    scanf("%d%d", &from, &to);
    --from; --to;
    g[from].push_back(to);
    g[to].push_back(from);
  }
  while (true) {
    int one = ans[0];
    int flag = 0;
    for (size_t j = 0; j < g[one].size(); ++j) {
      to = g[one][j];
      if (!used[to]) {
        flag = 1;
        ans.push_front(to);
        used[to] = 1;
        break;
      }
    }
    if (!flag) {
      break;
    }
  }
  while (true) {
    int one = ans[ans.size() - 1];
    int flag = 0;
    for (size_t j = 0; j < g[one].size(); ++j) {
      to = g[one][j];
      if (!used[to]) {
        flag = 1;
        ans.push_back(to);
        used[to] = 1;
        break;
      }
    }
    if (!flag) {
      break;
    }
  }
  printf("%zu\n", ans.size());
  for (auto& el : ans) {
    printf("%d ", el + 1);
  }
  printf("\n");
}


Measured memory_bytes: 7040
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a1 = scanner.nextInt();
		int b1 = scanner.nextInt();
		int a2 = scanner.nextInt();
		int b2 = scanner.nextInt();
		int a3 = scanner.nextInt();
		int b3 = scanner.nextInt();

		int[] number = new int[4];
		number[a1 - 1]++;
		number[b1 - 1]++;
		number[a2 - 1]++;
		number[b2 - 1]++;
		number[a3 - 1]++;
		number[b3 - 1]++;

		int count = 0;
		for (int x : number) {
			if (x > 2 || x == 0) {
				System.out.println("NO");
				return;
			}

			if (x == 2) {
				if (++count == 3) {
					System.out.println("NO");
					return;
				}
			}
		}
		if (count == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

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

int main() {
  string s,t;
  cin >> s >> t;
  for(int i=0; i<s.size(); i++) {
    cout << s[i];
    if(i<t.size()) cout << t[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

		int n, k;
		cin >> n >> k;
		if(n%2==0){
			if(n/2+1<=k){
				cout << "NO" << endl;
			} else {
				cout << "YES" << endl;
			}
		} else {
			if(n/2+2<=k){
				cout << "NO" << endl;
			} else {
				cout << "YES" << endl;
			}
		}

	return 0;
}

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> va(A), vb(B), vm(M);
  for (int i = 0; i < A; i++) {
    cin >> va.at(i);
  }
  for (int i = 0; i < B; i++) {
    cin >> vb.at(i);
  }
  
  for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    vm.at(i) = va.at(x - 1) + vb.at(y - 1) - c;
  }


  sort(va.begin(), va.end());
  sort(vb.begin(), vb.end());
  sort(vm.begin(), vm.end());
  int v = va.at(0) + vb.at(0);
  
  cout << min(vm.at(0), v) << endl;
  
  

}

Measured memory_bytes: 1408
INF = 10 ** 6
n = gets.to_i
nums = gets.split.map(&:to_i).sort
tally = nums.tally
dp = Array.new(INF + 1, true)

ans = 0
nums.each do |num|
  next unless dp[num]
  tmp = num
  while tmp < INF + 1
    dp[tmp] = false
    tmp += num
  end
  ans += 1 if tally[num] == 1
end
puts ans


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

int val[100010], l[100010], r[100010];
queue<int> wl;
vector<int> graph[100010];
int n, u, v, k, p;
bool had_val[100010];

int main() {
    memset(r, 63, sizeof(r));
    memset(l, -63, sizeof(l));
    scanf("%d", &n);
    for(int i = 1; i < n; i++) {
        scanf("%d%d", &u, &v);
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    scanf("%d", &k);
    for(int i = 0; i < k; i++) {
        scanf("%d%d", &v, &p);
        val[v] = l[v] = r[v] = p;
        had_val[v] = true;
        wl.push(v);
    }
    while(not wl.empty()) {
        u = wl.front(); wl.pop();
        for(int v : graph[u]) {
            if(l[v] < l[u] - 1) wl.push(v);
            l[v] = max(l[v], l[u]-1);
        }
    }
    for(int i = 1; i <= n; i++) {
        if(l[i] > r[i]) return !printf("No");
        if(had_val[i]) wl.push(i);
    }
    while(not wl.empty()) {
        u = wl.front(); wl.pop();
        for(int v : graph[u]) {
            if(r[v] > r[u] + 1) wl.push(v);
            r[v] = min(r[v], r[u] + 1);
        }
    }
    for(int i = 1; i <= n; i++) {
        if(l[i] == r[i]) had_val[i] = true, val[i] = l[i];
        if(had_val[i]) wl.push(i);
    }
    while(not wl.empty()) {
        u = wl.front(); had_val[u] = true; wl.pop();
        for(int v : graph[u]) {
            if(had_val[v] && abs(val[v] - val[u]) < 2 && abs(val[v] - val[u]) % 2 == 0) return !printf("No");
            else if(not had_val[v]) {
                int L = val[u]-1, R = val[u]+1;
                if(l[v] <= L && L <= r[v]) val[v] = L;
                else if(l[v] <= R && R <= r[v]) val[v] = R;
                wl.push(v);
            }
        }
    }
    printf("Yes\n");
    for(int i = 1; i <= n; i++) printf("%d\n", val[i]);
}


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

int main()
{
  int N;
  int res=0;
  cin >> N;

  int num = N;
  int fN = 0;
  while(num>0){
    fN += num%10;
    num /= 10;
  }

  if(N%fN==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
    int a, b, i = 0, j = 0, d[20000];
    double r, f;
    string op;
    while (op != "?") {
        cin >> a >> op >> b;
        if (op == "+")    d[i] = a + b;
        else if (op == "-")   d[i] = a - b;
        else if (op == "*")    d[i] = a * b;
        else if (op == "/")    d[i] = a / b;
        i++;
    }
    while (j != i-1) {
        cout << d[j] << endl;
        j++;
    }

    return 0;
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
inline vector<int> solve_all_one(int n) {
	vector<int> res(2 * n);
	for (int i = 0, c = 1; i < 2 * n; i += 4, c += 2) {
		res[i] = res[i + 2] = c;
		res[i + 1] = res[i + 3] = c + 1;
	}
	return res;
}
inline vector<int> solve_sum_4k(int n, int sum, vector<pair<int, int> > vs) {
	vector<int> res(2 * n, 0), tv = solve_all_one(sum / 2);
	int c = sum / 2 + 1, lst = 0, pos = 0;
	for (auto P : vs) {
		res[(P.first - 1 + 2 * n) % (2 * n)] = lst;
		res[P.second] = c;
		lst = c++;
		for (int i = P.first; i != P.second; i = (i + 1) % (2 * n)) {
			res[i] = tv[pos++];
		}
	}
	res[(vs[0].first - 1 + 2 * n) % (2 * n)] = lst;
	for (int i = 0, f = 0; i < 2 * n; i++)
		if (!res[i]) {
			res[i] = c + f / 2;
			f++;
		}
	return res;
}
int n;
char S[200005];
int main() {
	scanf("%d %s", &n, S + 1);
	S[0] = '1';
	int all_one = 1;
	for (int i = 0; i < 2 * n; i++) if (S[i] == '0') { all_one = 0; break; }
	if (all_one) {
		if (n & 1) {
			puts("No");
			return 0;
		}
		vector<int> ans = solve_all_one(n);
		puts("Yes");
		for (int i = 0; i < 2 * n; i++)
			printf("%d%c", ans[i], " \n"[i == 2 * n - 1]);
		return 0;
	}
	vector<pair<int, int> > vs;
	for (int i = 0, l = -1; i <= 2 * n; i++) {
		if (S[i] != '1') {
			if (l == -1) continue;
			vs.push_back(make_pair(l, i - 1));
			l = -1;
		} else if (l == -1) l = i;
	}
	if (vs.size() > 1 && vs[0].first == 0 && vs.back().second == 2 * n - 1) {
		vs[0].first = vs.back().first;
		vs.pop_back();
	}
	int sum = 0, g1 = 0;
	for (auto P : vs) {
		int x = (P.second - P.first + 1 + 2 * n) % (2 * n);
		if (x > 1) g1++;
		sum += x - 1;
	}
	if (sum & 1) {
		puts("No");
		return 0;
	}
	if (sum % 4 == 0) {
		vector<int> ans = solve_sum_4k(n, sum, vs);
		puts("Yes");
		for (int i = 0; i < 2 * n; i++)
			printf("%d%c", ans[i], " \n"[i == 2 * n - 1]);
		return 0;
	}
	if (g1 >= 2) {
		int p1 = -1, p2 = -1;
		for (int i = 0; i < (int)vs.size(); i++) {
			pair<int, int> P = vs[i];
			int x = (P.second - P.first + 1 + 2 * n) % (2 * n);
			if (x > 1) {
				if (p1 == -1) p1 = i;
				else {
					p2 = i;
					break;
				}
			}
		}
		vs[p1].second = (vs[p1].second - 1 + 2 * n) % (2 * n);
		vs[p2].second = (vs[p2].second - 1 + 2 * n) % (2 * n);
		sum -= 2;
		vector<int> ans = solve_sum_4k(n, sum, vs);
		swap(ans[vs[p1].second], ans[vs[p2].second]);
		swap(ans[vs[p1].second], ans[(vs[p1].second + 1) % (2 * n)]);
		swap(ans[vs[p2].second], ans[(vs[p2].second + 1) % (2 * n)]);
		if (ans[vs[p1].second] != ans[vs[p2].second]) {
			for (int i = 0; i < 2 * n; i++)
				if (i != vs[p1].second && ans[i] == ans[vs[p1].second]) {
					swap(ans[i], ans[vs[p2].second]);
					break;
				}
		}
		puts("Yes");
		for (int i = 0; i < 2 * n; i++)
			printf("%d%c", ans[i], " \n"[i == 2 * n - 1]);
		return 0;
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 2936
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		for(int z=0;z<n;z++){
			int x = sc.nextInt();
			int y = sc.nextInt();
			int[][] dp = new int[y+2][x+2];
			boolean[][] xx = new boolean[y+2][x+2];
			boolean[][] yy = new boolean[y+2][x+2];
			int p = sc.nextInt();
			int[] a = new int[4];
			int b;
			for(int i=0;i<p;i++){
				for(int j=0;j<4;j++) a[j] = sc.nextInt()+1;
				if(a[0]==a[2]){
					b = Math.max(a[1], a[3]);
					yy[b][a[0]] = true;
				}else{
					b = Math.max(a[0], a[2]);
					xx[a[1]][b] = true;
				}
			}
			
			dp[1][0] = 1;
			for(int i=1;i<=y+1;i++){
				for(int j=1;j<=x+1;j++){
					if(yy[i][j]==false) dp[i][j]+=dp[i-1][j];
					if(xx[i][j]==false) dp[i][j]+=dp[i][j-1];
				}
			}
			
			b = dp[y+1][x+1];
			if(b==0) System.out.println("Miserable Hokusai!");
			else System.out.println(b);
		}
	}	
}

Measured memory_bytes: 26112
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  auto result = unique(all(a));
  a.erase(result, a.end());
  rep(i, a.size()) cout << a[i] << (i == a.size() - 1 ? "\n" : " ");
  return 0;
}



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int N,A,B,C;
vector<int> L;

int dfs(int a, int b, int c, int n){
    if (n == N){//末端の処理
        if(a!=0 && b!=0 && c!=0){
            return abs(A-a) + abs(B-b) + abs(C-c) - 30;
        }else{
            return INF;
        }
    }

    int pass = dfs(a,b,c,n+1);//選ばない
    int choice_a = dfs(a+L[n],b,c,n+1) + 10;//Aに使用
    int choice_b = dfs(a,b+L[n],c,n+1) + 10;//Aに使用
    int choice_c = dfs(a,b,c+L[n],n+1) + 10;//Aに使用

    return min({pass, choice_a, choice_b, choice_c});
}

int main() {
    cin >> N >> A >> B >> C;
    L.assign(N,0); REP(i,N) cin >> L[i];

    cout << dfs(0,0,0,0) << endl;

    return 0;
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

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

	int ans = 0;
	stack<char> st;
	for(int i = 0; i < (int)s.size(); i++){
		if(st.size() == 0 || st.top() == s[i])
			st.push(s[i]);
		else{
			ans += 2;
			st.pop();
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
/*c++11*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

void print_0(vector<pair<int, int> > *target,
    multimap<int,int> *table){
  cout<<"target: ";
  for(auto ix=target->begin();ix!=target->end();ix++)
    cout<<"("<<ix->first<<","<<ix->second<<")";
  cout<<endl;

  cout<<"table: ";
  for(auto ix=table->begin();ix!=table->end();ix++)
    cout<<"("<<ix->first<<","<<ix->second<<")";
  cout<<endl;
  cout<<endl;

}

int main(int args, char *argc[]){

  int n,m;
  vector<pair<int,int> > target;
  multimap<int,int> table;
  //log(10^7)=20*log(10)=23
  while(cin>>n,n){
    //initial
    target.clear();
    table.clear();
    //INPUT
    int a,b,c,d;
    cin>>a>>b;
    for(int i=1;i<n;i++)
      cin>>c>>d,
        target.push_back(make_pair(c-a,d-b));

    cin>>m;
    for(int i=0;i<m;i++)
      cin>>c>>d,
        table.insert(make_pair(c,d));

    //print_0(&target,&table);

    //PROCESS
    bool flag;
    bool fflag;
    for(auto ix=table.begin();ix!=table.end();ix++){
      flag=true;
      for(auto iy=target.begin();iy!=target.end();iy++){
        fflag=false;
        for(auto iz=table.lower_bound(ix->first+iy->first);iz!=table.upper_bound(ix->first+iy->first);iz++){
          if(iz->second == ix->second+iy->second){
            fflag=true;
            break;
          }
        }
        //not the same pattern
        if(fflag==false){
          flag=false;
          break;
        }
      }//for range of target
      if(flag==true){
        c=ix->first,
          d=ix->second;
        break;
      }
    }

    if(flag)
      cout<<(c-a)<<" "<<(d-b)<<endl;

  }//while

  return 0;
}


Measured memory_bytes: 3024
#include<iostream>

using namespace std;

int cnt;

void insertSort(int a[], int n, int g){
    for(int i = g + 1; i <= n; ++i){
        int j = i - g, k = a[i];
        while(j > 0 && k < a[j]) { a[j + g] = a[j]; j -= g; ++cnt;}
        if(j != i - g) a[j + g] = k;
    }
}

void shellSort(int a[], int n){
    cnt = 0;
    int m = 0, x = 1, g[101];
    do{ g[++m] = x; x = 3 * x + 1; }while(x < n);
    cout << m << endl;
    for(int i = m; i > 1 ; --i) { cout << g[i] << " "; insertSort(a, n, g[i]); }
    cout << g[1] << endl; insertSort(a, n, g[1]);
}

int main(){
    int n;  cin >> n;
    int a[n + 5];
    for(int i = 1; i <= n; ++i) cin >> a[i];
    shellSort(a, n);
    cout << cnt << endl;
    for(int i = 1; i <= n; ++i) cout << a[i] << endl;
    return 0;
}


Measured memory_bytes: 7012
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var kotlin=scan.nextLine().toInt()
    if((kotlin%2==0 || kotlin%10 == 5))
        println("-1")
    else {
        var r = 0
        var i = 0
        do {
            r = ((r * 10 + 7) % kotlin).toInt()
            i++
        } while (r != 0)
        println(i)
    }
}


Measured memory_bytes: 36192
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]


table = {}
for Ai in A:
    table[str(Ai)] = 0
for Bi, Ci in BC:
    table[str(Ci)] = 0
    
for Ai in A:
    table[str(Ai)] += 1

for Bi, Ci in BC:
    table[str(Ci)] += Bi

table2 = [(int(key), value) for key, value in table.items()]
table2.sort(key=lambda x: -x[0])

ans = ans_cnt = 0
for key, value in table2:
    # print("#", key, value, ans_cnt, ans)
    if ans_cnt + value >= N:
        ans += key * (N - ans_cnt)
        break
    else:
        ans_cnt += value
        ans += key * value

print(ans)

Measured memory_bytes: 89604
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, q;
    cin >> n >> q;
    int a,b;
    vector<vector<int>> v(n+1);
    for(int i=0;i<n-1;i++)
    {
        cin >> a >> b;
        v[a].push_back(b);
    }
    // for(int i=1;i<=n;i++)
    // {
    //     for(auto j : v[i])
    //     {
    //         cout << j << ' ';
    //     }
    // }
    int p,x;
    int arr[n+5];
    memset(arr, 0, sizeof arr);
    while(q--)
    {
        cin >> p >> x;
        arr[p]+=x;
    }
    for(int i=1;i<=n;i++)
    {
        for(auto j : v[i])
        {
            arr[j]+=arr[i];
        }
    }
    for(int i=1;i<=n;i++)
    {
        cout << arr[i] << ' ';
     }
    return 0;
}

Measured memory_bytes: 14080
#include<bits/stdc++.h>
using namespace std;
const int nmm=(1<<19);
int n,v[nmm],w[nmm],dp[(1<<9)+(1<<8)][101010];
int ask(int x,int vl)
{
	if(x<=(1<<9))
	{
		return dp[x][vl];
	}
	else
	{
		if(w[x]<=vl)
		{
			return max(ask(x/2,vl),ask(x/2,vl-w[x])+v[x]);
		}
		else
		{
			return ask(x/2,vl);
		}
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>v[i]>>w[i];
	}
	for(int i=1;i<=min(n,1<<9);i++)
	{
		for(int j=0;j<101000;j++)
		{
			dp[i][j]=dp[i/2][j];
		}
		for(int j=w[i];j<=101000;j++)
		{
			dp[i][j]=max(dp[i][j],dp[i/2][j-w[i]]+v[i]);
		}
	}
	int q;
	cin>>q;
	while(q--)
	{
		int x,vl;
		cin>>x>>vl;
		cout<<ask(x,vl)<<endl;
	}
	return 0;
}

Measured memory_bytes: 207712
n = int(input())
ls = [(0, 0)] * n
for i in range(n):
    x, ln = map(int, input().split())
    l = x - ln
    r = x + ln
    ls[i] = (l, r)
#print(ls)

ls.sort(key=lambda x: x[1])
#print(ls)
last = -float('inf')
count = 0
for i in ls:
    if last <= i[0]:
        count += 1
        last = i[1]
print(count)

Measured memory_bytes: 23856
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }
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;
}

#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


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

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


    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    REP(i,X) cin >> A[i];
    REP(i,Y) cin >> B[i];
    REP(i,Z) cin >> C[i];

    vector<ll> AB;
    REP(i,X)REP(j,Y) AB.emplace_back(A[i]+B[j]);
    sort(ALL(AB),greater<>());

    vector<ll> ABC;
    REP(i,min(K,(int)AB.size()))REP(j,Y) ABC.emplace_back(AB[i]+C[j]);
    sort(ALL(ABC),greater<>());

    REP(i,K){
        cout << ABC[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 43368
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		long ans = 0;
		for(int i = 0; i < 1 << (S.length()-1); i++) {
			String T = "";
			for(int j = 0; j < S.length()-1; j++) {	
				T += S.charAt(j);
				if((1 & i >> j) == 1)
					T += "/+";
			}
			T += S.charAt(S.length()-1);
			String[] t = T.split("/+");
			for(int k = 0; k < t.length; k++)
				ans += Long.parseLong(t[k]);
		}
		System.out.println(ans);
	}

}

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

int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;
  
  int64_t amari, syou, ans;
  syou = N/(A+B);
  amari = N%(A+B);
  
  if(amari > A)ans = syou*A + A;
  else ans = syou * A + amari;
  
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
using namespace std;


pair<int, int> R(int ah, int aw, int bh, int bw){
    int ar = ah * ah + aw * aw;
    int br = bh * bh + bw * bw;
    if (ar < br) {
        return {ah, aw};
    }
    if (ar > br) {
        return {bh, bw};
    }
    
    if (ar == br) {
        if (ah < bh) {
            return {ah, aw};
        }else{
            return {bh, bw};
        }
    }
    return {0,0};
}

int main(){
    
    for (; ;) {
        int h,w;
        cin >>h >>w;
        if(h==0 and w==0) break;
        int ans_h=250, ans_w=250;
        for (int i=2; i<=w+h; i++) {
            for (int j=1; j < i ; j++) {
                pair<int, int> check = R(h, w, j, i);
                if ((i > w || j > h) and check.first == h and check.second == w) {
                    pair<int, int> res = R(j, i, ans_h, ans_w);
                    //cout << res.first << " "<<res.second<<endl;
                    ans_h = res.first;
                    ans_w = res.second;
                }
            }
        }
        cout << ans_h << " " << ans_w << endl;
    }
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int x = sc.nextInt();

		int percent = 100 * x / (a * a * b);

		double ans = 0;
		if(percent >= 50) {
			double volume = a * a * b - x;
			double angle = Math.atan(volume / a * 2 / a / a) / Math.PI * 180;
			ans = angle;
		} else {
			double volume = x;
			double angle = Math.atan(volume / a * 2 / b / b) / Math.PI * 180;
			ans = 90 - angle;
		}
		System.out.println(ans);
	}
}

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

int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }

  for (int i = -1; i < w+1; i++) {
      cout << '#';
  } cout << endl;  

  for (int i = 0; i < h; i++) {
    cout << '#';
    for (int j = 0; j < w; j++) {
      cout << s[i][j];
    }
    cout << '#' << endl;
  }

  for (int i = -1; i < w+1; i++) {
      cout << '#';
  } cout << endl;  
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
//?¶????????????????????????????????????§??????????????????????¢????????????????
constexpr int INF = 2000000000;
const double PI = acos(-1);

int main() {
	int n;
	while (cin >> n&&n) {
		int count = 1;
		int i = 0;
		int ans = 0;
		while (i+count<=n) {
			i += count;
			if (count != 1 && (n - i) % count == 0)ans++;
			count++;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3048
import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

public class Main {

	public static void main(String[] args) throws Exception {
		int r = in.i();
		int D = in.i();
		int x = in.i();

		for (int i = 2001; i <= 2010; i++) {
			x = r*x - D;
			out.println(x);
		}
	}

	static PrintStream out = System.out;
	static FastReader in = new FastReader();
}

class FastReader {
	final private int BUF_SIZE = 1 << 16;
	private DataInputStream din = new DataInputStream(System.in);
	private byte[] buffer = new byte[BUF_SIZE];
	private int bufferPointer, bytesRead;

	String s() throws IOException {
		return s(64);
	}

	String s(int capacity) throws IOException {
		byte[] buf = new byte[capacity];
		int cnt = 0, c;
		while ((c = c()) != -1) {
			if (c == '\n') break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	int i() throws IOException {
		int ret = 0;
		byte c = c();
		while (c <= ' ') c = c();
		boolean neg = (c == '-');
		if (neg) c = c();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = c()) >= '0' && c <= '9');
		return neg ? -ret : ret;
	}

	long l() throws IOException {
		long ret = 0;
		byte c = c();
		while (c <= ' ') c = c();
		boolean neg = (c == '-');
		if (neg) c = c();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = c()) >= '0' && c <= '9');
		return neg ? -ret : ret;
	}

	double d() throws IOException {
		double ret = 0, div = 1;
		byte c = c();
		while (c <= ' ') c = c();
		boolean neg = (c == '-');
		if (neg) c = c();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = c()) >= '0' && c <= '9');
		if (c == '.')
			while ((c = c()) >= '0' && c <= '9')
				ret += (c - '0') / (div *= 10);
		return neg ? -ret : ret;
	}

	private void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUF_SIZE);
		if (bytesRead == -1) buffer[0] = -1;
	}

	byte c() throws IOException {
		if (bufferPointer == bytesRead) fillBuffer();
		return buffer[bufferPointer++];
	}
}



Measured memory_bytes: 21332
N, K = map(int, input().split())
S = input()

if S[K-1] == 'A':
    print(S[:K-1]+'a'+S[K:])
elif S[K-1] == 'B':
    print(S[:K-1]+'b'+S[K:])
else:
    print(S[:K-1]+'c'+S[K:])


Measured memory_bytes: 2940
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def unite(x, y):
    p = find(x)
    q = find(y)
    if p == q:
        return None
    if p > q:
        p,q = q,p
    par[p] += par[q]
    par[q] = p
def same(x, y):
    return find(x) == find(y)
def size(x):
    return -par[find(x)]
n, m = map(int, input().split())
par = [-1 for i in range(n)]
a, b = [], []
for i in range(m):
    a_, b_ = map(int, input().split())
    a.append(a_ - 1)
    b.append(b_ - 1)
ans = [0] * m
ans[-1] = (n - 1) * n // 2
for i in range(m - 1, 0, -1):
    if same(a[i], b[i]):
        ans[i - 1] = ans[i]
    else:
        ans[i - 1] = ans[i] - size(a[i]) * size(b[i])
        unite(a[i], b[i])
print(*ans, sep="\n")

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

using namespace std;

using ll = long long;

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

const double EPS = 1e-5;
const int MOD = 1e9+7;

const int N = 1e5;
const int A = 1e9;
const int B = 1e9;

int x[N];

int main(){
  int n;
  ll a,b;

  cin >> n >> a >> b;

  repn(i,n){
    scanf("%d",x + i);
  }

  ll res = 0;
  repn(i,n-1){
    res = res + min(b, (x[i + 1] - x[i]) * a);
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 640