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

typedef unsigned long long Hash;

Hash hashV[500010];
Hash hashSum[500010];


long long MOD = INT_MAX;
struct LazySegmentTree{
	struct NODE{
		Hash val;
		Hash lazy;
		NODE(){
			val = lazy = 0;
		}
	};

	inline void lazy(int k,int a,int b){
		seg[k].val += (hashSum[b] - hashSum[a-1]) * seg[k].lazy;
		if( a != b){
			seg[k*2].lazy += seg[k].lazy;
			seg[k*2+1].lazy += seg[k].lazy;

		}
		seg[k].lazy = 0;
	}
	Hash merge(Hash a,Hash b){
		return a + b;
	}

	int n_;
	vector<NODE> seg;
	LazySegmentTree(int N){
		n_ = 1;
		while( n_ < N ) n_ *= 2;
		seg.resize(2*n_,NODE());
	}
	Hash get(int l,int r,int k,int a,int b){
		lazy(k,a,b);
		if( b < l || r < a ) return 0;
		if( l <= a && b <= r){
			return seg[k].val;
		}
		int m = (a+b)/2;
		return merge(get(l,r,k*2,a,m),get(l,r,k*2+1,m+1,b));
	}
	void add(int l,int r,int v,int k,int a,int b){
		lazy(k,a,b);
		if( b < l || r < a ) return;
		if( l <= a && b <= r ){
			seg[k].lazy = v;
			lazy(k,a,b);
			return;
		}
		int m = (a+b) / 2;
		add(l,r,v,k*2,a,m);
		add(l,r,v,k*2+1,m+1,b);
		seg[k].val = merge(seg[k*2].val,seg[k*2+1].val);
	}
	inline Hash get(int l,int r){
		return get(l,r,1,1,n_);
	}
	inline void add(int l,int r,Hash v){
		add(l,r,v,1,1,n_);
	}
};

int isp(long long n){
	for(long long i = 2 ; i*i <= n ; i++)
		if( n % i == 0 ) return false;
	return true;
}
int main(){
	ios::sync_with_stdio(false);
	int N;
	cin >> N;

	int mod = 1000000009;
	int prime = 1000000009;
	while( !isp(prime)) prime--;
	
	hashV[1] = 1;
	for(int i = 2 ; i <= N ; i++){
		hashV[i] = hashV[i-1] * mod;
	}
	for(int i = 1 ; i <= N ; i++)
		hashSum[i] = hashSum[i-1] + hashV[i];

	LazySegmentTree seg1(N);
	LazySegmentTree seg2(N);
	for(int i = 1 ; i <= N ; i++){
		int x;
		cin >> x;
		x += prime;
		seg1.add(i,i,x);
		seg2.add(N-i+1,N-i+1,x);
	}

	int Q;
	cin >> Q;

	while(Q--){
		int l,r,v;
		cin >> l >> r >> v;
		int L = N - r + 1;
		int R = N - l + 1;
		seg1.add(l,r,v);
		seg2.add(L,R,v);
		if( seg1.get(1,N) == seg2.get(1,N) ){
			cout << 1 << endl;
		}else{
			cout << 0 << endl;
		}
	}

}

Measured memory_bytes: 43492
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	N, K := next(), nextInt()
	n := len(N)

	// dp[i][j][k]: 上からi桁目, nと同じ(1)/未満(0)の数字と確定, 0でない数字がちょうどk個であるものの個数
	dp := make([][2][4]int, n+2)
	dp[1][0][1] = int(N[0]-'0') - 1
	dp[1][0][0] = 1
	dp[1][1][1] = 1
	for i := 1; i < n; i++ {
		ni := int(N[i] - '0')
		if ni == 0 {
			// 0を使う場合
			for k := 0; k <= 3; k++ {
				dp[i+1][0][k] = dp[i][0][k]
				dp[i+1][1][k] = dp[i][1][k]
			}
			// 0以外を使う場合
			for k := 0; k < 3; k++ {
				dp[i+1][0][k+1] += 9 * dp[i][0][k]
			}
		} else {
			// 0を使う場合
			for k := 0; k <= 3; k++ {
				dp[i+1][0][k] = dp[i][0][k] + dp[i][1][k]
			}
			// 0以外を使う場合
			for k := 0; k < 3; k++ {
				dp[i+1][0][k+1] += 9*dp[i][0][k] + (ni-1)*dp[i][1][k]
				dp[i+1][1][k+1] += dp[i][1][k]
			}
		}
	}

	ans := dp[n][0][K] + dp[n][1][K]
	puts(ans)
}


Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;

int main(){
    int sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty;

    int dx = abs(tx-sx);
    int dy = abs(ty-sy);

    REP(i,dy) cout << 'U';
    REP(i,dx) cout << 'R';
    REP(i,dy) cout << 'D';
    REP(i,dx) cout << 'L';

    cout << 'L';
    REP(i,dy+1) cout << 'U';
    REP(i,dx+1) cout << 'R';
    cout << 'D';

    cout << 'R';
    REP(i,dy+1) cout << 'D';
    REP(i,dx+1) cout << 'L';
    cout << 'U';
    cout << endl;
}

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();
		if(N==1) {
			System.out.println("Hello World");
		}
		else{
			int A = in.nextInt();
			int B = in.nextInt();
			System.out.println(A+B);
		}
		
		

	}
}


Measured memory_bytes: 23124
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;

int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	ll ans=0;
	if(n>m/2){
		printf("%lld\n",m/2);
	}else{
		printf("%lld\n",n+(m-n*2)/4);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

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

bool f[200005] = {};
ll co[200005] = {};
vector<vector<int>> ki(200005, vector<int>(0));

void dfs(int x) {
  f[x] = 1;
  for (int i = 0; i < ki[x].size(); i++) {
    if (!f[ki[x][i]]) {
      co[ki[x][i]] += co[x];
      dfs(ki[x][i]);
    }
  }
  return;
}
  
int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n -1; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    ki[a].push_back(b);
    ki[b].push_back(a);
  }
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    co[a] += b;
  }
  dfs(0);
  for (int i = 0; i < n; i++) {
    cout << co[i] <<endl;
  }
} 


Measured memory_bytes: 21376
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int K = sc.nextInt();
        sc.nextLine();
        
        RollerCoaster rc = new RollerCoaster(N, K);
        
        for(int i = 0; i < N; i++){
            rc.h[i]  = sc.nextInt();
        }
        
        System.out.println(rc.count());
        
    }
}

class RollerCoaster {
    
    int[] h;
    int N;
    int K;
    
    public RollerCoaster(int N, int K){
        this.N = N;
        this.K = K;
        h = new int[N];
    }
    
    public int count() {
        
        int res = 0;
        
        Arrays.sort(h);
        
        int left = -1;
        int right = N;
        
        while(right - left > 1){
            
            int mid = (left + right) / 2;
            if (isOK(mid)) {
                right = mid;
            } else {
                left = mid;
            }
        }
        
        return N - right;
    }
    
    private boolean isOK(int i){
        return h[i] >= K;
    }
    
}


Measured memory_bytes: 48192
import java.util.*;

class Main {
	  static long mod=1_000_000_007;
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
      String S = sc.next();
      String T = sc.next();
      long ans = 0;
      
      for (int i=0;i<3;i++) {
          if(S.substring(i,i+1).equals(T.substring(i, i+1))) {
        	  ans++;
          }
    	  
      }

      
	  System.out.println(ans);
  }
  
 
}

Measured memory_bytes: 21588
#include <iostream>
#include <cstdlib>
#include <vector>
#include <map>

using namespace std;

using ll = long long;

int main() {
    int k;
    cin >> k;
    
    vector<int> a(k);
    
    for (int i = 0; i < k; i++) {
        cin >> a[i];
    }
 
    ll l = 2, r = 2;
    
    for (int i = k - 1; i >= 0; i--) {
        ll x = (l + a[i] - 1) / a[i] * a[i];
        ll y = r / a[i] * a[i];
        
        if (x <= r && l <= y) {
            l = x;
            r = y + a[i] - 1;
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    
    cout << l << ' ' << r << endl;
    return 0;
}


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

int main() {
  int N;
  int A ;
  cin  >> N;
  cin >> A ;
  
  int x;
  
  x= N % 500 ;
 
  if ( x <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  
  
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,E)> G;
  typedef function<T(E,E)> H;
  int n;
  G g;
  H h;
  T d1;
  E d0;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(){};
  SegmentTree(int n_,G g,H h,T d1,E d0,
	      vector<T> v=vector<T>()):
    g(g),h(h),d1(d1),d0(d0){
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(n,d1);
    laz.clear();
    laz.resize(2*n-1,d0);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i]=v[i];
  }
  void update(int a,int b,E x,int k,int l,int r){
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return;
    }
    update(a,b,x,k*2+1,l,(l+r)/2);
    update(a,b,x,k*2+2,(l+r)/2,r);
  }
  void update(int a,int b,E x){
    update(a,b,x,0,0,n);
  }
  T query(int k){
    T c=dat[k];
    k+=n-1;
    E x=laz[k];
    while(k>0){
      k=(k-1)/2;
      x=h(x,laz[k]);
    }
    return g(c,x);
  }
};
//END CUT HERE
signed main(){
  int n,q;
  cin>>n>>q;
  SegmentTree<int,int> raq(n,
			   [](int a,int b){return a+b;},
			   [](int a,int b){return a+b;},
			   0,0);
  for(int i=0;i<q;i++){
    int c,s,t,x;
    cin>>c;
    if(c){
      cin>>x;
      cout<<raq.query(x-1)<<endl;
    }else{
      cin>>s>>t>>x;
      raq.update(s-1,t,x);
    }
  }
  return 0;
}

/*
  verified on 2017/10/15
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_E&lang=jp
*/

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

struct Node{
    Node *left;
    Node *right;
    Node() { left = NULL, right = NULL; }
};

int findcc(string s) {
    int dd = 0;
    for(int i=0; i<s.length(); ++i) {
        if(s[i] == '(') dd++;
        else if(s[i] == ')') dd--;
        else if(s[i] == ',' && dd == 1) return i;
    }
    return -1;
}

Node* parse(string s) {
    Node *r = new Node();
    int ff = findcc(s);
    if(ff != 1) r->left = parse(s.substr(1,ff-1));
    if(ff != s.length()-2) {
        string tmp = s.substr(ff+1);
        r->right = parse(tmp.substr(0,tmp.length()-1));
    }
    return r;
}

Node *intersect(Node *r1,Node *r2) {
    Node *ret = new Node();
    if(r1->left != NULL && r2->left != NULL)
        ret->left = intersect(r1->left,r2->left);

    if(r1->right != NULL && r2->right != NULL)
        ret->right = intersect(r1->right,r2->right);

    return ret;
}

Node* uni(Node *r1,Node *r2) {
    if(r1 == NULL && r2 == NULL) return NULL;

    Node *ret = new Node();
    ret->left = uni(((r1 == NULL)?NULL:r1->left),(r2 == NULL)?NULL:r2->left);
    ret->right = uni(((r1 == NULL)?NULL:r1->right),(r2 == NULL)?NULL:r2->right);
    return ret;
}

string toStr(Node *tree) {
    string res = "(";
    if(tree->left != NULL) res += toStr(tree->left);
    res += ",";
    if(tree->right != NULL) res += toStr(tree->right);
    res += ")";
    return res;
}

void treedel(Node *node) {
    if(node->left != NULL) treedel(node->left);
    if(node->right != NULL) treedel(node->right);
    delete node;
    return;
}

int main() {
    string op,t1,t2;
    while(cin>>op>>t1>>t2) {
        Node *r1 = parse(t1);
        Node *r2 = parse(t2);
        Node *ans;
        if(op == "i") ans = intersect(r1,r2);
        else if(op == "u") ans = uni(r1,r2);

        cout<<toStr(ans)<<endl;
        treedel(r1); treedel(r2); treedel(ans);
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long k;
    int n,q,A[100005],a;
    cin>>n>>k>>q;
    for(int i=0;i<n;i++) A[i]=k-q;
    for(int i=0;i<q;i++){
        cin>>a;
        A[a-1]++;
    }
    for(int i=0;i<n;i++){
        if(A[i]>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define MOD 1000000007
typedef long long LL;
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << max(A*B,C*D) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <cmath>
using namespace std;

int rot[24][6] = {
	{0,1,2,3,4,5}, {0,2,4,1,3,5}, {0,4,3,2,1,5}, {0,3,1,4,2,5},
	{1,5,2,3,0,4}, {1,2,0,5,3,4}, {1,0,3,2,5,4}, {1,3,5,0,2,4},
	{2,5,4,1,0,3}, {2,4,0,5,1,3}, {2,0,1,4,5,3}, {2,1,5,0,4,3},
	{3,4,5,0,1,2}, {3,5,1,4,0,2}, {3,1,0,5,4,2}, {3,0,4,1,5,2},
	{4,0,2,3,5,1}, {4,2,5,0,3,1}, {4,5,3,2,0,1}, {4,3,0,5,2,1},
	{5,4,2,3,1,0}, {5,2,1,4,3,0}, {5,1,3,2,4,0}, {5,3,4,1,2,0}
};

vector<vector<int> > cond[8] = {
	{},
	{{3,0,2}},
	{{1,1,4}},
	{{1,0,4},{2,2,3}},
	{{0,3,5}},
	{{0,2,5},{3,4,2}},
	{{0,1,5},{4,5,1}},
	{{0,0,5},{2,6,3},{4,4,1}}
};

struct State { int id, r; };
State pz[8];

string dice[8];
bool used[8];

string solve(int x) {
	if (x == 8) return "YES";
	for (int i=1; i<8; ++i) {
		if (used[i]) continue;
		for (int j=0; j<24; ++j) {
			pz[x].id = i;
			pz[x].r = j;
			bool ok = true;
			for (int k=0; k<(int)cond[x].size(); ++k) {
				int bloc1 = x;
				int face1 = rot[pz[bloc1].r][cond[x][k][0]];
				int bloc2 = cond[x][k][1];
				int face2 = rot[pz[bloc2].r][cond[x][k][2]];
				if (abs(dice[pz[bloc1].id][face1] - dice[pz[bloc2].id][face2]) != 32) {
					ok = false; break;
				}
			}
			if (ok) {
				used[i] = true;
				if (solve(x+1) == "YES") return "YES";
				used[i] = false;
			}
		}
	}
	return "NO";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	while (cin >> dice[0], dice[0] != "0") {
		for (int i=1; i<8; ++i) cin >> dice[i];
		memset(used, false, sizeof used);
		used[0] = true;
		pz[0].id = 0;
		string res = "NO";
		for (int i=0; i<24; ++i) {
			pz[0].r = i;
			if (solve(1) == "YES") {
				res = "YES"; break;
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		while(true){
			int n = stdIn.nextInt();
			if(n==0){
				return;
			}
			int[] a = new int[n];
			for(int i=0;i<n;i++){
				a[i] = stdIn.nextInt();
			}
			boolean first = false;
			for(int i=0;i<n;){
				int start = a[i];
				int goal = a[i];
				int j;
				for(j=i+1;j<n;j++){
					if(goal+1==a[j]){
						// OK
						goal = a[j];
					}
					else{
						// NG
						break;
					}
				}
				if(first){
					System.out.print(" ");
				}
				first = true;
				if(goal!=start){
					System.out.print(start+"-"+goal);
				}
				else{
					System.out.print(start);
				}
				i = j;
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 26692
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int N;cin >> N;
  vector<vector<int> > t;
  rep(i, N) {
    vector<int> xs;
    rep(_, 3) {
      int a;
      cin>>a;
      xs.pb(a);
    }
    sort(all(xs));
    t.pb(xs);
  }
  sort(all(t));
  uniq(t);
  cout << N-t.size() << "\n";
  return 0;
}

Measured memory_bytes: 3284
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskC   {
public void solve(int testNumber, Scanner in, PrintWriter out) {
        int N = in.nextInt();
        int ve[] = new int[N/2];
        int vo[] = new int[N/2];
        for (int i=0; i<N/2; i++) {
            ve[i] = in.nextInt();
            vo[i] = in.nextInt();
        }
        Arrays.sort(ve);
        Arrays.sort(vo);
        int idx1 = 0;
        int idx2 = 0;
        int oi1 = 0;
        int ei1 = 0;
        int oi2 = 0;
        int ei2 = 0;
        int nume = 0;
        int numo = 0;
        while (idx2 != N/2){
            while(ve[idx1] == ve[idx2]){
                idx2++;
                if(idx2 == N/2) break;
            }
            if(ei1 <= idx2 - idx1){
                ei2 = ei1;
                ei1 = idx2 - idx1;
                nume = ve[idx1];
            } else {
                ei2 = Math.max(ei2, idx2 - idx1);
            }
            idx1 = idx2;
        }
        idx1 = 0;
        idx2 = 0;
        while (idx2 != N/2){
            while(vo[idx1] == vo[idx2]){
                idx2++;
                if(idx2 == N/2) break;
            }
            if(oi1 <= idx2 - idx1){
                oi2 = oi1;
                oi1 = idx2 - idx1;
                numo = vo[idx1];
            } else {
                oi2 = Math.max(oi2, idx2 - idx1);
            }
            idx1 = idx2;
        }
        if(nume != numo) out.println(N - oi1 - ei1);
        else out.println(Math.min(N - oi1 - ei2, N - oi2 - ei1));
    }

}
}



Measured memory_bytes: 50724
#include<iostream>
using namespace std;
int main(){
  int N,X,T,tem=0;
  cin>>N>>X>>T;
  while(N>=X)
  {
    N=N-X;
    tem=tem+T;
  }
  if(N==0){
  cout<<tem<<endl;
  }
    else
      cout<<tem+T;
  return 0;
}


Measured memory_bytes: 3532
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;


int main(void){
  int n,i,a;
  set<int> s;
  
  cin >> n;
  for (i=0;i<n;i++){
    cin >> a;
    s.insert(a);
  }
  
  if (s.size()==n) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}

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

std::vector<int> to[212345];
std::vector<int> ans;

void dfs(int v, int p = -1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u, v);
  }
}

int main() {
  int n, q;
  std::cin >> n >> q;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    std::cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  for (int i = 0; i < q; ++i) {
    int p, x;
    std::cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  for (int i = 0; i < n; ++i) {
    std::cout << ans[i] << std::endl;
  }
  return 0;
}


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

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

  double ans = 0;
  for (int i = 1; i <= n; i++) {
    int x = i;
    double a = 1.0 / n;
    while (x < k) {
      x *= 2;
      a /= 2;
    }
    ans += a;
  }

  cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll n=s.size();
    string s1=s.substr(0,(n-1)/2);
    string s2=s.substr((n+3)/2-1,(n-(n+3)/2+1));
    //cout<<s1<<" "<<s2<<endl;
    bool f=true;
    for(int i=0,j=s.size()-1;i<s.size();i++,j--){
        if(s[i]!=s[j]){
            f=false;
            break;
        }
    }
    for(int i=0,j=s1.size()-1;i<s1.size();i++,j--){
        if(s1[i]!=s1[j]){
            f=false;
            break;
        }
    }
    for(int i=0,j=s2.size()-1;i<s2.size();i++,j--){
        if(s2[i]!=s2[j]){
            f=false;
            break;
        }
    }
    if(f){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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

int main() {
  array<int, 32> n {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51} ;
  int k;
  cin >> k;
  cout << n[k-1] << endl;
  return 0;
}


Measured memory_bytes: 256
n, k, l = map(int, input().split(" "))

def find(list_path, x):
  if list_path[x] != x:
    list_path[x] = find(list_path, list_path[x])
  return list_path[x]

def union(list_path, x, y):
  x = find(list_path, x)
  y = find(list_path, y)
  if x != y:
    list_path[x] = min(x, y)
    list_path[y] = list_path[x]

list_road = [i for i in range(n)]
for _ in range(k):
  p, q = map(int, input().split(" "))
  union(list_road, (p - 1), (q - 1))
list_rail = [i for i in range(n)]
for _ in range(l):
  r, s = map(int, input().split(" "))
  union(list_rail, (r - 1), (s - 1))

dict_num_connect = {}
for i in range(n):
  dict_num_connect[list_road[i], list_rail[i]] = dict_num_connect.get(
      (find(list_road, i), find(list_rail, i)), 0) + 1

print(" ".join(str(dict_num_connect[list_road[i], list_rail[i]]) 
               for i in range(n)))  

Measured memory_bytes: 55052
s = input()
n = len(s)
ans = 0
c = [0]*(n+1)
for i in range(n):
    if s[i]=='<':
        c[i+1] = c[i]+1
for i in range(n-1,-1,-1):
    if s[i]=='>':
        c[i] = max(c[i],c[i+1]+1)
print(sum(c))


Measured memory_bytes: 23336
#include<bits/stdc++.h>
using namespace std;
int main(){
  double a,b,c,d,e,f;
  while(cin>>a>>b>>c>>d>>e>>f){
    double y=(c*d-a*f)/(b*d-a*e);
    double x=(c-b*y)/a;
    printf("%.3lf %.3lf\n",x,y);
  }
  return 0;
}



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

using namespace std;

int main(){
    int n;cin>>n;
    map <string,int> mapa;
    string x;
    for(int i=0;i<n;i++){
        cin >>x;
        mapa[x]++;
    }
    cout << "AC x "<<mapa["AC"]<<endl;
    cout << "WA x "<<mapa["WA"]<<endl;
    cout << "TLE x "<<mapa["TLE"]<<endl;
    cout << "RE x "<<mapa["RE"]<<endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e5;
#define fo(int )
int main(){
  int a,b;
  int n;
  cin>>n>>a>>b;
  int x,y;
  x = n - a + 1;
  y = n - b + 1;
  cout<<x*y<<endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
num = [0] * n

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i - 1)
            if i != n // i:
                divisors.append(n//i - 1)

    return divisors

box = []
for i in range(n - 1, -1, -1):
    ind = make_divisors(i + 1)
    if num[i] % 2 != a[i]:
        for j in ind:
            num[j] += 1
        box.append(i + 1)
print(len(box))
print(*box)


Measured memory_bytes: 70112
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;

int main(){
    int N,K;
    cin >> N;
    int count=0;
    for (int i=1;i<=N;i++){
        if(i%2 == 1){
            count ++;
        }
    }
    
    cout << fixed << setprecision(10) << double(count) / N;

    
}

Measured memory_bytes: 256
N = int(input())

arr = [int(input()) for i in range(N) ]

import math
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)  
  
print(lcm_list(arr))


Measured memory_bytes: 5076
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    int n;
    cin >> n;

    vector<ll> v(n);
    REP(i, n) cin >> v[i];

    if (v[0] != 0) {
        print(-1);
        return 0;
    }

    ll ans = 0;
    FOR(i, 1, n) {
        if (v[i] - v[i - 1] > 1) {
            print(-1);
            return 0;
        }

        if (i > 0 && v[i] - 1 == v[i - 1]) {
            ans += 1;
        } else {
            ans += v[i];
        }
    }

    print(ans);
}


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

int n;
int a[100007];
int ans[100007];

int main() {
    cin >> n;
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    sum /= 2;
    for (int i = 2; i <= n; i += 2) {
        sum -= a[i];
    }
    ans[1] = sum;
    cout << ans[1] * 2 << ' ';
    for (int i = 2; i <= n; i++) {
        ans[i] = a[i - 1] - ans[i - 1];
        cout << ans[i] * 2 << ' ';
    }
    cout << endl;;
    return 0;
}


Measured memory_bytes: 4400
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s="";
	if(n==0){
		cout<<0<<endl;
		return 0;
	}
	while(n!=0){
		if(n%2==0){
			s+='0';
			n=n/-2;
		}
		else if(n%2!=0){
			s+='1';
			n=(n-1)/-2;
		}
	}
	for(int i=s.size()-1;i>=0;i--){
		cout<<s[i];
	}
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int main(){
  long long N, A, B;
  cin>>N>>A>>B;
  if (A == 0) {
    cout<<0<<'\n';
  }else{
   	long long groups = N/(A+B);
    long long remain = min(N%(A+B), A);
    long long res = groups * A + remain;
    cout<<res<<'\n';
  }
  
  return 0;
}

Measured memory_bytes: 256
//----------------------JUGNU:LET YOUR LIGHT SHINE---------------------------//
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pf push_front
#define sz size
#define mk make_pair
#define ln length
#define F first
#define D second
#define fr(i,a,b) for(i=a;i<b;i++)
#define fre(i,a,b) for(i=a;i<=b;i++)
#define frr(i,a,b) for(i=a;i>=b;i--)
#define sc(a) scanf("%d", &a)
#define sm(a, b) scanf("%d%d", &a, &b)
#define pr(a) printf("%d\n", a)
#define pm(a, b) printf("%d %d\n", a, b)
#define cn(a) cin >> a
#define cm(a, b) cin >> a >> b
#define ct(a) cout << a << endl
#define ctm(a, b) cout << a << " " << b << endl
#define isset(x,i) ((x>>i)&1)
#define MAXN 200005
#define INF 1000000007
#define fastScan ios_base::sync_with_stdio(0); cin.tie(NULL);

#define trace1(x)       cerr << #x << " : " << x << endl;
#define trace2(x, y)    cerr << #x << " : " << x << " | " << #y << " : " << y << endl;
#define trace3(x, y, z) cerr << #x << " : " << x << " | " << #y << " : " << y << " | " << #z << " : " << z << endl;
#define cline cout << "----------------------" << endl;
using namespace std;

int roadComp[MAXN], railComp[MAXN], roadCompNum = 0, railCompNum = 0, visited[MAXN][2];
vector<int> graph[MAXN][2];
void dfs(int node, int type){
	if(type == 0) roadComp[node] = roadCompNum;
	if(type == 1) railComp[node] = railCompNum;
	int i, temp;
	fr(i, 0, graph[node][type].sz()){
		temp = graph[node][type][i];
		if(visited[temp][type] == 0){
			visited[temp][type] = 1;
			dfs(temp, type);
		}
	}
	return;
}

typedef pair<int, int> pii;
map<pii, int> M;

int main()
{
	int i, j, t, n, m, k, l, r, temp, mini, maxi, flag, cnt = 0, type, q;
	sc(n);
	sm(k, m);
	fr(i, 0, k){
		sm(l, r);
		graph[l][0].pb(r);
		graph[r][0].pb(l);
	}
	fr(i, 0, m){
		sm(l, r);
		graph[l][1].pb(r);
		graph[r][1].pb(l);
	}
	fre(i, 1, n){
		if(visited[i][0] == 0){
			visited[i][0] = 1;
			roadCompNum++;
			dfs(i, 0);
		}
		if(visited[i][1] == 0){
			visited[i][1] = 1;
			railCompNum++;
			dfs(i, 1);
		}
	}
	fre(i, 1, n) M[mk(roadComp[i], railComp[i])]++;
	fre(i, 1, n) printf("%d ", M[mk(roadComp[i], railComp[i])]);
	printf("\n");
return 0;
}

Measured memory_bytes: 29440
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	string S, T;
	cin >> S >> T;

	int ans = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i]) {
			ans++;
		}
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 200001;
const int MOD = 1000000007;
//
int 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;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
signed d[100000],c[100000],oya[100000],ans[200000],ban[100000],n,m;
char iro[100000];
char find(signed ue,signed i){
        if(iro[i]!='a')return iro[i];
        if(oya[i]==ue)return iro[i]='W';
        if(d[i]<d[oya[i]])return iro[i]='F';
        if(d[i]==d[oya[i]]){
                ans[ban[i]]=d[i];
                switch(find(i,oya[i])){
                        case 'W':return iro[i]='B';
                        case 'B':return iro[i]='W';
                        case 'F':return iro[i]='F';
                }
        }
        ans[ban[i]]=d[i]-d[oya[i]];
        return iro[i]=find(i,oya[i]);
}
        signed main() {
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>d[i];
    fill(c,c+n,1000000001);fill(ans,ans+m,1000000000);
    int u,v;
    for(int i=0;i<m;i++){
            cin>>u>>v;u--;v--;
            if(c[u]>=d[v]){
                    c[u]=d[v];
                    oya[u]=v;
                    ban[u]=i;
            }
            if(c[v]>=d[u]){
                    c[v]=d[u];
                    oya[v]=u;
                    ban[v]=i;
            }
    }
    fill(iro,iro+n,'a');
    for(int i=0;i<n;i++){
            if(find(-1,i)=='F'){
                    cout<<-1;return 0;
            }
    }
    for(int i=0;i<n;i++)cout<<iro[i];
    cout<<endl;
    for(int i=0;i<m;i++)cout<<ans[i]<<endl;

      }


        


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

vector<string> G(55);
vector<vector<bool>> visited(55, vector<bool>(55));
vector<vector<int>> dist(55, vector<int>(55));
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
int h, w;

void bfs(int X, int Y) {
  queue<pair<int, int>> que;
  que.push(make_pair(X, Y));
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    int x = p.first, y = p.second;
    rep(i, 4) {
      if (x + dx[i] < 0 || x + dx[i] >= h || y + dy[i] < 0 || y + dy[i] >= w)
        continue;
      if (visited[x + dx[i]][y + dy[i]]) continue;
      if (G[x + dx[i]][y + dy[i]] == '#') continue;
      visited[x + dx[i]][y + dy[i]] = true;
      dist[x + dx[i]][y + dy[i]] = dist[x][y] + 1;
      que.push(make_pair(x + dx[i], y + dy[i]));
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  cin >> h >> w;
  rep(i, h) cin >> G[i];
  int black = 0;
  rep(i, h) rep(j, w) if (G[i][j] == '#') black++;
  visited[0][0] = true;
  bfs(0, 0);
  if (dist[h - 1][w - 1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << h * w - black - dist[h - 1][w - 1] - 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    string s;
    cin>>s;
    int conse=0;
    bool rain=false;
    for(int i=0;i<s.length()-1;i++)
    {
        if(s[i]=='R'||s[i+1]=='R')
        rain=true;
        if(s[i]=='R'&&s[i]==s[i+1]){
            
            conse++;
        }
    }
    conse=conse==0?rain?1:0:conse+1;
    cout<<conse<<endl;
}

Measured memory_bytes: 3568
import math
K =int(input())
sum_num = 0
for i in range(K):
    for j in range(i+1):
        temp_gcd = math.gcd(i+1,j+1)
        if i != j:
            same = False
        else:
            same = True
        for k in range(j+1):
            temp_num = math.gcd(temp_gcd,k+1)
            if same:
                if i != k and j != k:
                    sum_num += temp_num * 3
                else:
                    sum_num += temp_num 
            else:
                if i != k and j != k:
                    sum_num += temp_num * 6
                else:
                    sum_num += temp_num * 3

                
                
print(sum_num)
        
        


Measured memory_bytes: 9200
class in{struct It{int it;const bool rev;explicit constexpr It(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(It& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const It i,n;public:explicit constexpr in(int n):i(0),n(n<0?0:n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const It& begin(){return i;}const It& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    for(auto& x : a) cin >> x;
    int ma = -1, num = 0;
    map<int, int, greater<int>> mp;
    for(int i : in(n - 1, -1)) {
        int x = a[i];
        if(ma > x) mp[ma - x] += num;
        else if(ma == x) ++num;
        else {
            ma = x;
            num = 1;
        }
    }
    if(!mp.empty()) {
        auto it = mp.begin();
        cout << it->second << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
 
 
 
 
int main(){
 
    int A,B,C;
 
    scanf("%d %d %d",&A,&B,&C);
 
    int ans = C,left = 0,right= C,mid = (left+right)/2;
 
    while(left <= right){
 
        if(mid*A+mid/7*B >= C){
 
            ans = mid;
            right = mid-1;
 
        }else{
 
            left = mid+1;
        }
        mid = (left+right)/2;
    }
 
    printf("%d\n",ans);
 
    return 0;
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  string s1,s2;
  cin>>s1>>s2;
  vector<int>A(N,0);
  for(int i=0;i<N;i++){
  if(s1.at(i)==s2.at(i))
    A.at(i)=1;
  }
  if(A.at(0)==1){
   int64_t ans=3;
    int a=1;
    int x=0;
    for(int i=0;i<N;i+=a){
     if(A.at(i)==1) a=1; 
      else a=2;
      if(x==0 && A.at(i)==0)
        ans=(3*ans)%1000000007;
      else if(x==1)
        ans=(2*ans)%1000000007;
      else ans=ans;
       x=A.at(i);
    }cout<<ans<<endl;
  
  }else{
   int64_t ans=2;
    int a=2;
    int x=0;
    for(int i=0;i<N;i+=a){
     if(A.at(i)==1) a=1; 
      else a=2;
      if(x==0 && A.at(i)==0)
        ans=(3*ans)%1000000007;
      else if(x==1)
        ans=(2*ans)%1000000007;
      else ans=ans;
       x=A.at(i);
    }cout<<ans<<endl;
  }
   return 0;
}

Measured memory_bytes: 256
using System;
class Program{
    static void Main(){
        string[] s = Console.ReadLine().Split(' ');
        int a,b,c;
        a = int.Parse(s[0]);
        b = int.Parse(s[1]);
        c = int.Parse(s[2]);
        if(b > c){
            int tmp = c;
            c = b;
            b = tmp;
        }
        if(a > b){
            int tmp = b;
            b = a;
            a = tmp;
        }
        if(b > c){
            int tmp = c;
            c = b;
            b = tmp;
        }
        Console.WriteLine(a+" "+b+" "+c);
    }
}



Measured memory_bytes: 15932
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=998244353;
const ll MAX_N=500010;
const ll INF=100100100100100;
int dp[100100];

int solve(int now, vector<vector<int> > &G){
    if(dp[now]>0) return dp[now];
    int res=0;
    for(int to:G[now]){
        res=max(res, solve(to,G)+1);
    }
    dp[now]=res;
    return res;
}

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int> > G(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--; b--;
        G[a].push_back(b);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        ans=max(ans,solve(i,G));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 10480
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 c = sc.nextInt();

		System.out.println(b - a == c - b ? "YES" : "NO");

		sc.close();

	}

}

Measured memory_bytes: 35692
#include<bits/stdc++.h>                          
using namespace std;                          
const int MAX=0x3f3f3f3f;
int ch[200],ans[200];                       
int main(){
	int n;
	cin>>n;      
	string s; 
	memset(ans,MAX,sizeof(ans));
	for(int i=0;i<n;i++)
	{		
	    cin>>s;        
	    memset(ch,0,sizeof(ch));
		for(int i=0;i<s.size();i++)
		{
		    ch[s[i]]++;	
		}  
		for(int i='a';i<='z';i++)
		{
	    	ans[i]=min(ans[i],ch[i]);
		}
    }   
	for(int i='a';i<='z';i++)
	{
		for(int j=0;j<ans[i];j++)
		{
			cout<<(char)i;
		}
	}    
	return 0;
}                       

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int count = 0;
    for(int i = 0; i < s.length(); i++){
        if(s.charAt(i) == s.charAt(s.length()-1-i)){
        }else{
            count++;
        }
    }

    System.out.println(count/2);
    
    
	}
}

Measured memory_bytes: 35608
count_char = list(0 for i in range(26))
while True :
    try :
        str_org = str(input())
        str_org = str_org.lower()
        for i in range(len(str_org)) :
            num_org = ord(str_org[i])
            if num_org > 96 and num_org < 123 :
                count_char[num_org - 97] += 1
    except EOFError :
        break
for i in range(97, 123) :
    print(chr(i), ":", count_char[i-97])


Measured memory_bytes: 5568
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n;
	while(cin>>n)
	{
		vector<long long> a(n);
		for(int i=0;i<n;i++)
			cin >> a[i];
		sort(a.begin(),a.end());
		long long ans=0;
		for(int i=0;i<n;i++)
			ans+=(a[i]*(n-i));
		cout << ans << endl;
	}




}



Measured memory_bytes: 3148
#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 A,P;
  cin >> A >> P;
  P += A*3;
  cout << P/2 << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
  fscanf(STDIN,"%d%d%d",$a,$b,$c);
  $i=0;
  $amari = [];
  while(1){
      $i++;
      $cal = ($a*$i)%$b;
      if(isset($amari[$cal])){
          echo "NO";
          break;
      }
      if($cal == $c){
          echo "YES";
          exit;
      }
      $amari[$cal] = 1;
  }

Measured memory_bytes: 4984
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;//for StringBuilder
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var list = new string[n];
        for (int i = 0; i < n; i++)
        {
            list[i] = string.Join("", Console.ReadLine().OrderBy(f => f));
        }
        Array.Sort(list, StringComparer.Ordinal);
        long ans = 0;
        long cnt = 1;
        for (int i = 1; i < n; i++)
        {
            if (list[i] == list[i - 1]) cnt++;
            else
            {
                ans += cnt * (cnt - 1) / 2;
                cnt = 1;
            }
        }
        Console.WriteLine(ans + cnt * (cnt - 1) / 2);
    }
}


Measured memory_bytes: 24852
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>


#define ll long long
#define ull unsigned long long
//#define int ll
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

typedef pair < int , int > pii ;
typedef pair < long long  , long long > pll ;

const int N = 3e5 + 1 ;
int n , k;
int a[N];
map < int , int > cnt;
main(){
	scanf("%d%d" , &n , &k);
//	cnt[0-1+1]++;
	ll ans = 0;
	//if(i - j + 1 == k)
	//i - k + 1
	for(int i = 1 ; i <= n; i++){
		scanf("%d" , a + i);
		a[i] += a[i - 1];
		a[i] %= k;
		//12345
		//
		//6 - 2 + 4 = 0
		if(i - k + 1 >= 1){
			int j = i - k + 1;
			cnt[(a[j - 1] - j%k + 1 + k)%k]--;
		}
		cnt[(a[i - 1] - i%k + 1 + k) % k]++;		
		ans += cnt[(a[i] - i%k + k)%k];
    }
	printf("%lld" , ans);
	// pr[r] - pr[l - 1] = r - l + 1
	// pr[r] - r = pr[l-1] - l + 1
	
}

Measured memory_bytes: 10368
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(0, 0); }
	V<V<pin>> qab(2);
	int sz = ab.size();
	qab[0].reserve(sz);
	qab[1].reserve(sz);
	for (pin& x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2)); }
	}
	int c = 0;
	for (pin& x : qab[0]) {
		int qc = 2 * x.first + x.second+1;
      	qc = (qc & (int)(0xffffffff)) + ((qc & (0x7fffffff00000000)) >> 32);
	qc = (qc & (int)(0xffffffff)) + ((qc & (int)(0x100000000)) >> 32);
	qc = (qc & (0xffff)) + ((qc & (int)(0xffff0000)) >> 16);
	qc = (qc & (0xffff)) + ((qc & (0x10000)) >> 16);
	qc = (qc & (0xff)) + ((qc & (0xff00)) >> 8);
	qc = (qc & (0xff)) + ((qc & (0x100)) >> 8);
	qc = (qc & (0xf)) + ((qc & (0xf0)) >> 4);
	qc = (qc & (0xf)) + ((qc & (0x10)) >> 4);
	qc = (qc & 3) + ((qc & 12) >> 2);
	qc = (qc & 3) + ((qc & 4) >> 2);
		c ^= qc;
	}
	if (!c) {
		pin ans = solve(qab[1], ex - 1);
		ans.first *= 2; ans.second *= 2; ans.second++;
		return ans;
	}
	pin ans = solve(qab[0], ex - 1);
	c = 0;
	int d = 0;
	for (pin& x : qab[1]) {
		int w = ans.second - x.second - 1;
		if ((w & x.first) == w) { c ^= 1; }
      	w++;
      	if ((w & x.first) == w) { d ^= 1; }
	}
  	ans.first *= 2; ans.second *= 2;
	ans.first+=(c|d); ans.second -= c;
	return ans;
}
signed main() {
	cin.tie(0); ios::sync_with_stdio(false);
	long long inf = 1e17;
	int n; cin >> n;
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; cin >> a >> b;
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 59);
	cout << ret.first - inf << " " << ret.second - inf << "\n";
}


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

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int prev=0;
		int ans=1;
		int it=0;
		for(int i=1;i<=n;i++)
		{
			int t=in.nextInt();
			if(t!=i&&prev==0)
			{
				it=t;
				prev=i;
			}
			else if(t!=i&&(it!=i||prev!=t))
			{
				ans=0;
			}
		}
		if(ans==1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}
	

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

int main() {
	int n, m;
	cin >> n >> m;
	int k[30], a[30][30];
	int p[31] = { 0 };
	for (int i = 0; i < n; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> a[i][j];
			p[a[i][j]]++;
		}
	}
	int count = 0;
	for (int i = 1; i <= m; i++)
		if (p[i] == n)
			count++;
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
A,B,C = [],[],[]
for i in range(n):
    a,b,c = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(c)
dp = [[0]*3 for i in range(n)]
dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

for i in range(1,n):
    dp[i][0] = max(dp[i][0] ,max(dp[i-1][1],dp[i-1][2]) + A[i])
    dp[i][1] = max(dp[i][1] ,max(dp[i-1][2],dp[i-1][0]) + B[i])
    dp[i][2] = max(dp[i][2] ,max(dp[i-1][0],dp[i-1][1]) + C[i])
print(max(dp[-1]))

Measured memory_bytes: 79320