akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define LL long long int

using namespace std;

int main(){
    int n;
    cin>> n;
    vector<int> h(n);
    for(int&x: h)
        cin>> x;
    int dp[n+1];
    dp[1] = 0;
    dp[2] = abs(h[1] - h[0]);
    for(int i = 3;i <=n;i++){
        dp[i] = min(abs(h[i - 1] - h[i-2]) + dp[i-1],dp[i-2] + abs(h[i-1] - h[i-3]));
        //cout<<dp[i]<<endl;
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <complex>
#include <vector>
using namespace std;
const double eps = 1e-10;
#define EQ(a, b) (abs((a) - (b)) < eps)
using P = complex<double>;      // position
struct L : vector<P> {
    L(const P &a = P(), const P &b = P()) {
        emplace_back(a); emplace_back(b);
    }
};
double dot(const P &a, const P &b) { return real(conj(a) * b); }
double cross(const P &a, const P &b) { return imag(conj(a) * b); }

P project(const L &l, const P &p) {
    double t = dot(p - l[0], l[0] - l[1]) / norm(l[0] - l[1]);
    return l[0] + t * (l[0] - l[1]);
}

#include <iostream>
#include <iomanip>
int main() {
    cout << fixed << setprecision(10);
    int a, b, c, d; cin >> a >> b >> c >> d;
    L l(P(a, b), P(c, d));
    int q; cin >> q;
    while (q--) {
        int x, y; cin >> x >> y;
        P p = project(l, P(x, y));
        cout << p.real() << " " << p.imag() << endl;
    }
    return 0;
}


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

int main(){
	vector<double> h;
	double n;
	while(cin >> n){
		h.push_back(n);
	}
	
	sort(h.begin(),h.end());
	
	double height = h.back() - h.front();
	cout << height << endl;
	
	return 0;
}

Measured memory_bytes: 1304
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
#include "atcoder/all"

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int k;
    cin >> k;
    rep(i, k) {
        cout << "ACL";
    }
    cout << endl;
}


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

class BNode{
public:
	int value;
	BNode *right,*left;
};

class BTree{
	BNode *root;
	void Inorder(BNode *cur){
		if(cur){
			Inorder(cur->left);
			cout << " " << cur->value;
			Inorder(cur->right);
		}
	}
	void Preorder(BNode *cur){
		if(cur){
			cout << " " << cur->value;
			Preorder(cur->left);
			Preorder(cur->right);
		}
	}
public:
	BTree(){
		root = NULL;
	}
	void Insert(int v){
		BNode *cur = root;
		BNode *prt = NULL;
		BNode *node = new BNode();
		node->value = v;
		
		while(cur){
			prt = cur;
			if(cur->value < v){
				cur = cur->right;
			}else{
				cur = cur->left;
			}
		}
		if(prt){
			if(prt->value > v){
				prt->left = node;
			}else{
				prt->right = node;
			}
		}
		if(!root){
			root = node;
		}
	}
	void PrintInorder(){
		Inorder(root);
		cout<<endl;
	}
	void PrintPreorder(){
		Preorder(root);
		cout<<endl;
	}
	void Find(int v){
		BNode *cur = root;
		
		while(cur){
			if(cur->value == v){
				cout<<"yes"<<endl;
				return;
			}else if(cur->value > v){
				cur = cur->left;
			}else{
				cur = cur->right;
			}
		}
		cout<<"no"<<endl;
	}
	BNode* Next(BNode *cur){
		cur = cur->right;
		while(cur->left){
			cur = cur->left;
		}
		return cur;
	}
	void Delete(int v){
		BNode *cur = root;
		BNode *prt = NULL;
		
		while(cur){
			if(cur->value == v){
				if(cur->left==NULL && cur->right==NULL){
					if(prt){
						if(prt->value > v){
							prt->left = NULL;
						}else{
							prt->right = NULL;
						}
					}else{
						root = NULL;
					}
				}else if(cur->left!=NULL && cur->right==NULL){
					if(prt){
						if(prt->value > v){
							prt->left = cur->left;
						}else{
							prt->right = cur->left;
						}
					}else{
						root = cur->left;
					}
				}else if(cur->left==NULL && cur->right!=NULL){
					if(prt){
						if(prt->value > v){
							prt->left = cur->right;
						}else{
							prt->right = cur->right;
						}
					}else{
						root = cur->right;
					}
				}else{
					int temp = Next(cur)->value;
					Delete(temp);
					cur->value = temp;
				}
				return;
			}else if(cur->value > v){
				prt = cur;
				cur = cur->left;	
			}else{
				prt = cur;
				cur = cur->right;
			}
		}
	}
};

int main() {
	BTree bt;
	int m, v;
	string com;
	
	cin>>m;
	for(int i=0;i<m;++i){
		cin>>com;
		if(com=="insert"){
			cin>>v;
			bt.Insert(v);
		}else if(com=="print"){
			bt.PrintInorder();
			bt.PrintPreorder();
		}else if(com=="find"){
			cin>>v;
			bt.Find(v);
		}else if(com=="delete"){
			cin>>v;
			bt.Delete(v);
		}
	}
	
	return 0;
}

Measured memory_bytes: 13708
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_set>
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[s.size()-1]!='s'){
        s = s+"s";
    }else{
        s = s+"es";
    }
    cout << s << endl;
}

Measured memory_bytes: 3040
# Aizu Problem 0077: Run Length
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def run_length(string):
    out = ""
    k = 0
    while k < len(string):
        char = string[k]
        if char != '@':
            out += char
            k += 1
        else:
            cnt = int(string[k+1])
            char = string[k+2]
            out += char * cnt
            k += 3
    return out


for line in sys.stdin:
    print(run_length(line.strip()))

Measured memory_bytes: 7844
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

fact = [1] *(N+1)
for i in range(1,N+1):
    fact[i] = fact[i-1] *i
a = 1
b = 1
P2 = sorted(P)
Q2 = sorted(Q)
for i,(p,q) in enumerate(zip(P,Q)):
    a += P2.index(p)*fact[N-i-1]
    b += Q2.index(q)*fact[N-i-1]
    P2.remove(p)
    Q2.remove(q)
print(abs(b-a))



Measured memory_bytes: 3064
from heapq import*
import sys
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0;H=[(0,S)]
 while H:
  c,u=heappop(H)
  if u==G:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:F[v]=t;heappush(H,(t,v))
 return-1
def s(n,k):
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r()
  if'0'==f[0]:print(g(n,E,*map(int,f[2:].split())))
  else:c,d,e=map(int,f[2:].split());E[c]+=[[e,d]];E[d]+=[[e,c]]
for e in iter(r,'0 0\n'):s(*map(int,e.split()))


Measured memory_bytes: 6304
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner (System.in);
		String X = sc.next();
		int L = X.length();
		int S = 0;
		for(int i=0;i<L;i++) {
			if(X.charAt(i) == 'S') {
				S++;
			}else {
				if(S>=1) {
					S--;
				}
			}
		}
		System.out.println(2 * S);
	}
}

Measured memory_bytes: 26148
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_D&lang=ja

n, m, l = map(int, input().split())

A = [list(map(int, input().split())) for _ in range(n)]
B = [list(map(int, input().split())) for _ in range(m)]
C = [[0]*l for _ in range(n)]

# print(A)
# print(B)
# print(C)

for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]

for i in range(n):
    print(" ".join(map(str, C[i])))



Measured memory_bytes: 6904
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int people[10];

int main() {
	int n;
	while(n=in()){
		memset(people,0,sizeof(people));
		for(;n--;){
			int old=in();
			if(old>=70)people[6]++;
			else people[old/10]++;
		}
		for(int i=0;i<7;i++){
			cout<<people[i]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 884
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

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

int main()
{
  i64 K;
  cin >> K;
  priority_queue<i64, vector<i64>, greater<i64>> que;
  for (i64 i = 1; i < 10; i++)
    que.push(i);
  for (i64 i = 0; i < K - 1; i++)
  {
    i64 p = que.top();
    que.pop();
    if (p % 10 != 0)
      que.push(p * 10 + p % 10 - 1);
    que.push(p * 10 + p % 10);
    if (p % 10 != 9)
      que.push(p * 10 + p % 10 + 1);
  }
  cout << que.top() << endl;
  return 0;
}


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

int main(){
    int N,K;
    cin >> N >> K;
    double ans = 0;
    for(int i = 1;i < N+1;i++){
        double r = 1.0/N;
        int cnt = 0;
        int p = i;
        while(p < K){
            p *= 2;
            cnt ++;
        }
        for(int i = 0;i < cnt;i++){
            r *= 1/2.0;
        }
        ans += r;
    }
    
    cout << setprecision(16) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
class Dice {
private:
  int dice[6];
  //  int tmp;
 public:
  Dice(int a, int b, int c, int d, int e, int f) {
	dice[0] = a;
	dice[1] = b;
	dice[2] = c;
	dice[3] = d;
	dice[4] = e;
	dice[5] = f;
  }
  void move(char ch) {
	if(ch == 'N') {
	  moveN();
	}
	else if(ch == 'E') {
	  moveE();
	}
	else if(ch == 'S') {
	  moveS();
	}
	else {
	  moveW();
	}
  }
  void moveN() {
	swap(dice[0], dice[1]);
	swap(dice[1], dice[5]);
	swap(dice[5], dice[4]);
  }
  void moveS() {
	swap(dice[0], dice[4]);
	swap(dice[4], dice[5]);
	swap(dice[5], dice[1]);
  }
  void moveE() {
	swap(dice[0], dice[3]);
	swap(dice[3], dice[5]);
	swap(dice[5], dice[2]);
  }
  void moveW() {
	swap(dice[0], dice[2]);
	swap(dice[2], dice[5]);
	swap(dice[5], dice[3]);
  }
  int top() {
	return dice[0];
  }
};
/*
void print(Dice d1) {
    for(int i = 0; i < 6; ++i) {
	  cout << "i:" << i << endl;
	  cout << "\tdice:" << d1.dice[i] << endl;
	}
}
*/
int main() {
  char ch;
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  Dice d1(a, b, c, d, e, f);

  while(cin >> ch) {
	d1.move(ch);
	//	print(d1);
  }
  cout << d1.top() << endl;

  return 0;
}

Measured memory_bytes: 3084
#include<stdio.h>
void main(void)
{
    int n;
    scanf("%d",&n);
    if(n/100==7)
    {
        printf("Yes");
        return;
    }
    n = n - (n/100)*100;
    if(n/10==7)
    {
        printf("Yes");
        return;
    }
    n = n - (n/10)*10;
    if(n==7)
    printf("Yes");
    else
    {
        printf("No");
    }
    
}

Measured memory_bytes: 1684
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353

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

int main() {
	int N; cin >> N;
	vector<ll> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	vector<bool> p(a[N - 1] + 1, true);
	
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (!p[a[i]]) continue;
		for (int j = 2; a[i]*j <= a[N-1]; j++) {
			p[a[i] * j] = false;
			//cout << a[i] * j << " ";
		}
	}

	for (int i = 0; i < N; i++) {
		if (i + 1 < N && a[i] == a[i + 1]) {
			p[a[i]] = false;
		}
		if (p[a[i]]) {
			cnt++;
			//cout << a[i] << " ";
		}
	}
	//cout << endl;
	cout << cnt << endl;
}


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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    int sum = 0;
    int x = n;
    while (x) {
        sum += x % 10;
        x /= 10;
    }

    if (n % sum == 0) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
// abc136d.cpp : Gathering Children
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl

int ix_search(int s_ix, int g_ix){
  int ix;
  if(s_ix%2){
    if(g_ix%2) ix = g_ix; else ix = g_ix - 1;
  }
  else{
    if(g_ix%2) ix = g_ix - 1; else ix = g_ix;
  }
  return ix;
}

int main(){
  string S; cin>>S;
  int n = S.length();
  vi o(n), divpoint, group;

  char R = 'R', L = 'L';
  char HI = 'H', LW = 'L';
  char high_low = LW;
  up(i,0,n,1){
    char s = S[i];
    if(s==R && high_low==LW){ // ↑
      high_low = HI;
      divpoint.push_back(i); // グループの切れ目
    }
    else if(s==L && high_low==HI){ // ↓
      group.push_back(i); // グループの集合場所（L側）
      high_low = LW;
    }
  }
  divpoint.push_back(n);

  // ot("div [");for(auto e:divpoint)cout<<e<<" ";ote("]");//
  // ot("grp [");for(auto e:group)cout<<e<<" ";ote("]");//

  up(i,0,group.size(),1){
    int group_ix = group[i];
    up(j,divpoint[i],divpoint[i+1],1){
      o[ ix_search(j, group_ix) ]++;
    }
  }

  ot(o[0]); up(i,1,n,1) cout<<" "<<o[i]; ote("");

}

Measured memory_bytes: 1532
#include <iostream>

using namespace std;

int main() {
	int a, b, n, sum;
	while (1) {
		cin >> a >> b >> n;
		if (cin.eof())
			break;

		sum = 0;
		while (n-->0) {
			a *= 10;
			sum += (a / b) % 10;
			a %= b;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
//
//  main.cpp
//  B
//
//  Created by Yoshinao Itakura on 2020/08/02.
//  Copyright © 2020 Yoshinao Itakura. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
using namespace std;

int main(int argc, const char * argv[]) {
    long long N,D;
    cin>>N>>D;
    long X[N], Y[N];
    for (int i=0;i<N;++i){
        cin>>X[i]>>Y[i];
    }
    int count=0;
    for (int i=0;i<N;++i){
        if(X[i]*X[i]+Y[i]*Y[i]<=D*D) ++count;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 6692
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
  long long INF = 1000000000;
  int N, K; cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H[i];

  vector<long long> DP(N, INF);
  DP[0] = 0;
  for (int i = 1; i < N; i++) {
    for (int k = 1; k <= K; k++) {
      if (i - k < 0) continue;
      int cost = abs(H[i] - H[i - k]) + DP[i - k];
      if (cost < DP[i]) DP[i] = cost;
    }
  }

  cout << DP[N - 1] << endl;
}


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

int n, a[100005], ans;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 2){
            ans++;
        }
    }
    if(ans % 2){
        printf("NO\n");
    }
    else {
        printf("YES\n");
    }

    return 0;
}


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

#define ll long long int
#define mp make_pair 
#define pb push_back
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define ff first
#define ss second
#define MOD  1000000007
#define ll_MAX 922337203685477999
#define endl "\n"
inline ll absdiff(ll a,ll b) {return (a>b)?a-b:b-a;}
ll fast_expo(ll x,ll p){if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll gcd(ll a,ll b){if(a==0||b==0) return a+b;  else return gcd(b%a,a); }

ll Stree[1000000],lazy[1000000];


void Build(ll pos,ll s,ll e,vector<pair<ll,ll>>& arr)
{
    if(s>e) return;
    
    //Leaf node
    if(s==e){
        Stree[pos]=arr[s].ss;
        return;
    }

    Build(2*pos,s,(s+e)/2,arr);
    Build(2*pos+1,(s+e)/2+1,e,arr);
    Stree[pos] = Stree[2*pos]+Stree[2*pos+1];
}

ll query(ll x,ll y,ll l,ll r,ll pos)
{
    if(x>y) return 0;

    if(lazy[pos]!=0){
        if(l!=r){
            lazy[2*pos] += lazy[pos];
            lazy[2*pos+1] += lazy[pos];
        }
        Stree[pos] += lazy[pos]*(r-l+1);
        lazy[pos] = 0;
    }

    if(x<=l&&r<=y)
        return Stree[pos];

    if(y<l||x>r) return 0;

    ll temp1 = query(x,y,l,(l+r)/2,2*pos);
    ll temp2 = query(x,y,(l+r)/2+1,r,2*pos+1);
    return temp1+temp2;
}

void update(ll x,ll y,ll l,ll r,ll pos,ll val)
{
    if(x>y) return;
    if(lazy[pos]!=0){
        if(l!=r){
            lazy[2*pos] += lazy[pos];
            lazy[2*pos+1] += lazy[pos];
        }
        Stree[pos] += lazy[pos]*(r-l+1);
        lazy[pos] = 0;
    }

    if(x<=l&&r<=y){
        Stree[pos] += (r-l+1)*val;
        if(l!=r){
            lazy[2*pos] += val;
            lazy[2*pos+1] += val;
        }
        return;
    }

    if(y<l||x>r) return;

    update(x,y,l,(l+r)/2,2*pos,val);
    update(x,y,(l+r)/2+1,r,2*pos+1,val);
    Stree[pos] = Stree[2*pos]+Stree[2*pos+1];
}

int main()
{
    // fast
    ll t_c;t_c = 1;
    // cin>>t_c;
    for (ll ti = 0; ti < t_c; ++ti)
    {   
        ll n,d,a;cin>>n>>d>>a;
        vector<pair<ll,ll>> arr;
        arr.pb(mp(INT_MIN,INT_MIN));
        for(ll i=1;i<=n;++i){
            ll x,y;cin>>x>>y;
            arr.pb(mp(x,y));
        }
        sort(arr.begin(),arr.end());

        Build(1,1,n,arr);
      	ll val=10000000000000;

        ll ans=0;
        for(ll i=1;i<=n;++i){
            ll curr=query(i,i,1,n,1);

            if(curr<=0) continue;
            if(curr%a==0){
                ans+=curr/a;
                ll upto=upper_bound(arr.begin(),arr.end(),mp(arr[i].ff+2*d,val))-arr.begin();
                update(i,upto-1,1,n,1,-1*(curr/a)*a);
            }
            else{
                ans+=curr/a+1;
                ll upto=upper_bound(arr.begin(),arr.end(),mp(arr[i].ff+2*d,val))-arr.begin();
                update(i,upto-1,1,n,1,-1*(curr/a+1)*a);
            }
        }
        cout<<ans;
    }
    return 0;
}   

Measured memory_bytes: 16492
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)
ll modi = 1000000007;

bool cp(ll n){
    if(n == 1)return false;
    else if(n == 2)return true;
    else if(n ==3)return true;
    for(int i  = 2; i*i<=n; i++){
        if(n%i == 0){
            return false;
        }
    }
    return true;
}
void SforPrime(int n)
{
	bool prime[n+1];
	memset(prime, true, sizeof(prime));

	for (int p=2; p*p<=n; p++)
	{
		if (prime[p] == true)
		{
			for (int i=p*p; i<=n; i += p)
				prime[i] = false;
		}
	}
}
ll calPower(ll val, ll n){
    ll i = 1;
    ll ind = 1;
    ll prev = val;
    while(val<=n){
        if(n%val == 0)ind = i;
        val  = val*prev;
        i++;
    }
    return i-1;
}
bool check(ll val, int vec[]){
    while(val != 0){
        ll rem = val %10;
        if(vec[rem] == 1)return false;
        val /= 10;
    }
    return true;
}
int main(){
    //130016239756757
    ll val; ll n;
    cin>>val>>n;
    int vec[10];
    memset(vec, 0, sizeof(vec));
    for(int i = 0; i<n; i++){
        int temp;
        cin>>temp;
        vec[temp] = 1;
    }
    bool checky = check(val, vec);
    for(int i = 1; !checky; i++){
        val = val + 1;
        checky = check(val, vec);
    }
    cout<<val<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

main()
{
  int a;
  int b;
  scanf("%d %d",&a,&b);
  if(a < b){
    a = a + b;
    b = a - b;
    a = a - b;
  }
  int c;
  while(b != 0)
    {
      c = a % b;
      a = b;
      b = c;
    }
  printf("%d\n",a);
  return 0;
}

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

int main(){
	int a,b;
	cin >> a >> b;
	
	if(a>=13){
		cout << b << endl;
	} else if (6 <= a && a <= 12 ){
		cout << b/2 << endl;
	} else {
		cout << 0 << endl;
	}
    return 0;
}



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

const int MXN = 1e5 + 20;
int n, dp[MXN];
vector <int> h;

int main () {
	cin >> n;
	for (int i = 0 ; i < n; i++) {
		int tmp;
		cin >> tmp;
		h.push_back(tmp);
	}
	dp[2] = abs(h[0] - h[1]);
	for (int i = 3; i <= n; i++) {
		dp[i] += min(dp[i - 1] + abs(h[i - 1] - h[i - 2]), dp[i - 2] + abs(h[i - 1] - h[i - 3]));
	}
	cout << dp[n] << endl;
	return 0;
}


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

int main() {
  string S;
  bool ans=1;
  cin >> S;

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

  if(ans)cout << "Good" << endl;
  else cout << "Bad" << endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner scn = new Scanner(System.in);
		int block = scn.nextInt();
		int[] a = new int[block];
		int count = 1, tmp=1, breakcount = 0;
		for(int i = 0;i<block;i++){
			a[i] = scn.nextInt();
		}
		while(tmp<=block){
			if(a[tmp-1] == count){
				count++;
			}
			else breakcount++;
			tmp++;
		}
		if((count-1)==block)System.out.println("0");
		else if(breakcount==block)System.out.println("-1");
		else System.out.println(breakcount);
	}
}


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

#define M 1046527

typedef long long ll;

char H[M][20];

int getChar(char ch) {
    if (ch == 'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G') return 3;
    else if (ch == 'T') return 4;
    else return 0;
}

ll getKey(char str[]) {
    ll sum = 0, p = 1, i;
    for (int i = 0; i < strlen(str); i++) {
        sum += p * getChar(str[i]);
        p *= 5;
    }
    return sum;
}

int h1(int key) {return key % M;}
int h2(int key) {return 1 + (key % (M - 1));}

int find(char str[]) {
    ll key, i, h;
    key = getKey(str);
    for (int i = 0; ; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str) == 0) return 1;
        else if (strlen(H[h]) == 0) return 0;
    }
}

int insert(char str[]) {
    ll key, i, h;
    key = getKey(str);
    for (int i = 0; ; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str) == 0) return 1;
        else if (strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

char cmd[10];
char str[10];
int n;

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    scanf("%d", &n);
    while (n--) {
        scanf("%s %s", cmd, str);
        if (cmd[0] == 'i') {
            insert(str);
        } else {
            if (find(str)) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 23484
import numpy as np
h,w=map(int,input().split())
S=np.array([list(input()) for _ in range(h)])
S=np.where(S==".",1,0)

left,right,up,down=[np.zeros((h,w),dtype=np.int64) for _ in range(4)]
for i in range(w):
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
for i in range(h):
    up[i]=(up[i-1]+1)*S[i]
    down[-i-1]=(down[-i]+1)*S[-i-1]

print(int(np.max(left+right+up+down)-3))

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

int main(){
    int i,j,n,*a,t,count=0,m;
    scanf("%d",&n);
    a=(int*)malloc(sizeof(int)*n);
    for(i=0;i<n;i++){
        scanf("%d",a+i);
    }
    for(i=0;i<n;i++){
        m=i;
    for(j=i+1;j<n;j++){
        if(a[m]>a[j])
        m=j;
    }
    if(a[i]>a[m]){
    t=a[m];
    a[m]=a[i];
    a[i]=t;
    count++;
    }
    }
    for(i=0;i<n;i++){
        printf(i==n-1?"%d\n":"%d ",a[i]);
    }
    printf("%d\n",count);
    return 0;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
signed main(){
  string S,T; cin>>S>>T;
  map<char,vi> M;
  int N=S.size();
  rep(i,0,N)
    M[S[i]].pb(i);
  int sum=0,ans=-2;
  rep(i,0,T.size()){
    if(M.count(T[i])){
      if(M[T[i]][M[T[i]].size()-1]<=ans){
        ans=M[T[i]][0];
        sum++;
      }
      else
        ans=M[T[i]][disup(M[T[i]],ans)];
    }
    else{
      sum=0;
      ans=-2;
      break;
    }
  }
  ans+=sum*N;
  ans++;
  cout<<ans<<endl;
  }



Measured memory_bytes: 1728
import sys
input=sys.stdin.readline
from collections import defaultdict
from heapq import heappush,heappop
from itertools import accumulate
N,m,s,t=map(int,input().split())
en=defaultdict(set)
sneek=defaultdict(set)
for i in range(m):
    u,v,a,b=map(int,input().split())
    en[u]|={(a,v)}
    en[v]|={(a,u)}
    sneek[u]|={(b,v)}
    sneek[v]|={(b,u)}
inf=float('inf')
def makedist(first,branch):
    dist=[inf]*(N+1)
    dist[first]=0
    check=[(0,first)]
    while len(check)>0:
        d,now=heappop(check)
        if dist[now]<d:
            continue
        for lenth,nex in branch[now]:
            if d+lenth<dist[nex]:
                dist[nex]=d+lenth
                heappush(check,(d+lenth,nex))
    return dist
disten=makedist(s,en)
distsneek=makedist(t,sneek)
x=[y+s for y,s in zip(disten,distsneek)][::-1]
ans=list(accumulate(x,min))
big=10**15
[print(big-ans[i]) for i in range(N-1,-1,-1)]

Measured memory_bytes: 116712
#include <stdio.h>
#include <math.h>

int main(void) {
  long long a, b, c, k;
  scanf("%lld %lld %lld %lld", &a, &b, &c, &k);
  printf("%lld\n", (a - b) * (long long) pow(-1.0, k % 2));
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int gcd(int a, int b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }
  
  
  int main() {
  int x ; cin>> x ;
  int y= gcd(x,360) ;
    cout<<360/y<<endl ;
  return 0;
}

Measured memory_bytes: 3580
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int T = sc.nextInt();

        int ans = 0;
        int times = 0 ;
        times = (int) Math.ceil((double) N / X);

        ans = times * T;

        System.out.println(ans);

    }
}

Measured memory_bytes: 35612
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

ll is_sq(ll N) {
	ll ok = 0, ng = 1e9 + 5;
	while (ng - ok > 1) {
		ll mid = (ng+ok)/2LL;
		if (mid*mid <= N)ok = mid;
		else ng = mid;
	}
	if (ok * ok == N)return ok;
	else return 0;
}

ll solve(ll A,ll B){
	ll ans;
	if (!is_sq(A*B)) {
		if (A > B)swap(A, B);
		ll sqr = sqrt(A*B);
		ans = 2LL * sqr - 2;
		if (sqr*(sqr + 1) < A*B)ans += 2;
		else ans++;
		ans--;
	}
	else {
		ll sqr = is_sq(A*B);
		ans = 2LL * sqr - 2;
		if (A != B)ans--;
	}
	return ans;
}

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

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		ll A, B;
		cin >> A >> B;
		puts(solve(A, B));
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;
  
  std::string S;

  std::cin >> N >> S;

  long long C = 0, cnt[26] = {0};

  for (const auto& c : S)
    cnt[c - 'a'] ++;

  long long c1[8192] = {0}, c2[8192] = {0};

  for (int i = 1, size = 1 << 13; i < size; i ++) {
    c1[i] = c2[i] = 1;
    
    for (int j = 0, b = 1; j < 13; j ++, b <<= 1)
      if (b & i) {
        (c1[i] *= cnt[j     ]) %= MOD;
        (c2[i] *= cnt[j + 13]) %= MOD;
      }
  }

  for (int i = 0; i < 8192; i ++) {
    (C += c1[i]) %= MOD;
    (C += c2[i]) %= MOD;
    
    for (int j = 0; j < 8192; j ++)
      (C += c1[i] * c2[j]) %= MOD;
  }

  std::cout << C << std::endl;

  return 0;
}


Measured memory_bytes: 592
#include <iostream>
#include <queue>

using namespace std;

int main(){
  string s;
  cin>>s;
  int n,q,w,i;
  cin>>n;
  while(n--){
    string a,b;
    cin>>a;
    if(a[2]=='p'){
      int c=0;
      cin>>q>>w>>b;
      for(i=q;i<=w;i++)s[i]=b[c++];
    }
    else if(a[2]=='v'){
      int c=0;
      cin>>q>>w;
      for(i=q;i<=w;i++)b[c++]=s[i];
      for(c=0,i=w;i>=q;i--)s[i]=b[c++];
    }
    else{
      cin>>q>>w;
      for(i=q;i<=w;i++)cout<<s[i];
      cout<<endl;
    }
  }
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long a,b,k;
    cin>>a>>b>>k;
    if(k<=a)
	cout<<a-k<<" "<<b;
    else if(k>a && k<=a+b)
	cout<<0<<" "<<a+b-k;
    else
	cout<<0<<" "<<0;
    return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
int main(void)
{
 int A[3][3];
 int i,j,k;
 int N,B[N];
 for(i=0;i<3;i++)
  scanf("%d %d %d\n",&A[i][0],&A[i][1],&A[i][2]);

 scanf("%d\n",&N);
 for(i=0;i<N;i++)
  scanf("%d\n",&B[i]);

 for(k=0;k<N;k++)
  for(i=0;i<3;i++)
    for(j=0;j<3;j++)
     if(B[k] == A[i][j]) A[i][j] = 0;

 if(A[0][0]==0 && A[0][1]==0 && A[0][2]==0) printf("Yes\n");
 else if(A[1][0]==0 && A[1][1]==0 && A[1][2]==0) printf("Yes\n");
 else if(A[2][0]==0 && A[2][1]==0 && A[2][2]==0) printf("Yes\n");
 else if(A[2][0]==0 && A[2][1]==0 && A[2][2]==0) printf("Yes\n");
 else if(A[0][0]==0 && A[1][0]==0 && A[2][0]==0) printf("Yes\n");
 else if(A[0][1]==0 && A[1][1]==0 && A[2][1]==0) printf("Yes\n");
 else if(A[0][2]==0 && A[1][2]==0 && A[2][2]==0) printf("Yes\n");
 else if(A[0][0]==0 && A[1][1]==0 && A[2][2]==0) printf("Yes\n");
 else if(A[2][0]==0 && A[1][1]==0 && A[0][2]==0) printf("Yes\n");
 else printf("No\n");

 return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define endl '\n'
#define line cout<<"----------------------"<<endl
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll  mx=300009;
double ara[mx];
double   dp[3001][3001];
int n;
double call(int ind,int cnt)
{
    if(ind==n and cnt>n/2) return 1;
    if(ind==n) return 0;
    double &ret=dp[ind][cnt];
    if(ret!=-1) return ret;
    double ans=ara[ind]*call(ind+1,cnt+1);
    double ans1=(1.0-ara[ind])*call(ind+1,cnt);
    return ret=ans+ans1;
}
int  main()
{

    cin>>n ;
    for(int i=0;i<n;i++) cin>>ara[i];
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) dp[i][j]=-1;
    printf("%.10f\n",call(0,0));
}


Measured memory_bytes: 72064
#include<iostream>
using namespace std;
int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if(u==s)
    cout << a-1 << " "<< b;
  else
    cout << a << " " << b-1;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;

namespace Tree
{
    class Rooted_Trees
    {
        struct Node
        {
            public int id;
            public int parent;
            public int depth;
            public int[] childlen;
            public string type;
        }
        static void Main(string[] args)
        {
            int size = int.Parse(Console.ReadLine());
            var nodes = new Node[size];

            for (int i = 0; i < size; i++)
                nodes[i].parent = -1;

            for (int i = 0; i < size; i++)
            {
                var token = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                var id = token[0];
                nodes[id].id = id;

                var k = token[1];
                if (k == 0) nodes[id].type = "leaf";
                else nodes[id].type = "internal node";
                nodes[id].childlen = new int[k];
                for (int j = 0; j < k; j++)
                {
                    nodes[id].childlen[j] = token[2 + j];
                    nodes[token[2 + j]].parent = id;
                }
            }

            for (int i = 0; i < size; i++)
                if (nodes[i].parent == -1)
                {
                    nodes[i].type = "root";
                    SetDepth(nodes, i, 0);
                    break;
                }

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            for (int i = 0; i < size; i++)
            {
                Console.Write("node {0}: parent = {1}, depth = {2}, {3}, [", nodes[i].id, nodes[i].parent, nodes[i].depth, nodes[i].type);
                var l = nodes[i].childlen.Length;
                for (int j = 0; j < l; j++)
                    if(j!=l-1)Console.Write(nodes[i].childlen[j] + ", ");
                    else Console.Write(nodes[i].childlen[j]);
                //Console.Write(string.Join(", ", Array.ConvertAll(nodes[i].childlen, n => n.ToString())));
                Console.WriteLine("]");
            }

            Console.Out.Flush();
        }

        static void SetDepth(Node[] nodes, int id, int depth)
        {
            nodes[id].depth = depth;
            for (int i = 0; i < nodes[id].childlen.Length; i++)
                SetDepth(nodes, nodes[id].childlen[i], depth + 1);
        }
    }
}

Measured memory_bytes: 25588
n = int(raw_input())
x = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
	seq = map(int,raw_input().split())
	tmp = seq[0]-1
	n2 = seq[1]
	if n2!=0:
		for e in seq[2:]:
			x[tmp][e-1]=1
for i in range(n):
	print " ".join(map(str,x[i]))

Measured memory_bytes: 4296
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

struct mypair{
    LL a,b;

    mypair(){}
    mypair(LL i,LL j):a(i),b(j){}

    bool operator < (const mypair &right)const{
        return a < right.a;
    }
};

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

    LL n,m;
    cin >> n >> m;

    vector<mypair> mp(m);

    for(int i = 0; i < m; i++){
        LL a,b;
        cin >> a >> b;
        mp[i] = mypair(a,b);
    }

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

    LL min = INF;
    LL ans = 0;
    
    for(int i = 0; i < m; i++){
        if(min > mp[i].b){
            min = mp[i].b;
        }
        if(mp[i].a >= min){
            ans++;
            min = mp[i].b;
        }
    }

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

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;



public class Main {

	private static BufferedReader br;
	
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		List<String> list = new ArrayList<String>();
		for(int i=0;i<n;i++) {
			list.add(br.readLine());
		}
		br.close();
		
		Map<String,Integer> counted = count(list);
		outMaxVal(counted);
	}
	
	private static Map<String,Integer> count(List<String> list){
		Map<String,Integer> map = new HashMap<String, Integer>();
		for(String str:list) {
			if(!map.containsKey(str)) {
				map.put(str, 1);
			}else {
				map.put(str,map.get(str)+1);
			}
		}
		return map;
	}
	
	public static void outMaxVal(Map<String, Integer> map) {
		ArrayList<String> max = null;
		Integer maxVal = 0;
		for(Entry<String, Integer> e: map.entrySet()) {
			if(e.getValue().compareTo(maxVal)>0) {
				max = new ArrayList<String>();
				max.add(e.getKey());
				maxVal = e.getValue();
			}else if(e.getValue().equals(maxVal)) {
				max.add(e.getKey());
			}
		}
		Collections.sort(max);
		
		for(String str: max) {
			System.out.println(str);
		}
	}

}


Measured memory_bytes: 68796
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var str = Console.ReadLine().ToCharArray();
            var reverse_str = str.Reverse();
            Console.WriteLine(reverse_str.Where((x, i) => x != str[i]).Count()/2);
        }
    }
}

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

#define MOD_1000000007 (1000000007LL)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)

using std::cerr;
using std::cout;
using std::endl;
using std::make_pair;
using std::map;
using std::pair;
using std::priority_queue;
using std::set;
using std::string;
using std::vector;
typedef long long ll;

int N, Q;
vector<int> G[200020];
map<int, int> counter;
int total[200020];
bool visited[200020];

void dfs(int u, int acc) {
  if(visited[u]) return;
  visited[u] = true;
  total[u] = acc + counter[u];
  for(const int& v : G[u]) dfs(v, total[u]);
}

void solve() {
  dfs(1, 0);
  rep1c(i, N) {
    if(i>1) printf(" ");
    printf("%d", total[i]);
  }
  printf("\n");
}

int main() {
  scanf("%d %d", &N, &Q);
  rep(i, N-1) {
    int a, b;
    scanf("%d %d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  rep(i, Q) {
    int p, x;
    scanf("%d %d", &p, &x);
    counter[p] += x;
  }
  solve();
  return 0;
}

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

using namespace std;

int n, ar[200005], t[200005], s, g;

int main()
{
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", t+i);
        ar[i] = t[i];
    }
    sort(ar+1, ar+n+1);
    s = ar[n/2];
    g = ar[n/2+1];
    for(int i=1;i<=n;i++){
        if(t[i]<=s) printf("%d\n", g);
        else printf("%d\n", s);
    }

    return 0;
}


Measured memory_bytes: 3712
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  ll ans=1;
  for(int i=1;i<=N;++i){
    ans=ans*i;
    if(100000000<ans) ans=ans%(1000000000+7);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3572
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();

    let mut iter = input.split_whitespace().map(|w| w.parse::<i32>().unwrap());
    let a = iter.next().unwrap();
    let b = iter.next().unwrap();
    let c = iter.next().unwrap();

    if a < b && b < c {
        println!("Yes");
    } else {
        println!("No");
    }
}



Measured memory_bytes: 5032
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n,m;
  cin>>n>>m;
  vector<tuple<int,int>> vt;
  REP(i,n) {
    int a,b;
    cin>>a>>b;
    vt.emplace_back(a,b);
  }
  boost::sort(vt);
  priority_queue<int> que;
  int j = 0;
  int sum = 0;
  FOR(i,1,m+1) {
    while (j < n) {
      int a,b;
      tie(a,b) = vt[j];
      if (a <= i) {
        que.push(b);
        ++j;
      } else {
        break;
      }
    }
    if (que.empty()) continue;
    int e = que.top();
    que.pop();
    sum += e;
  }
  cout<<sum<<endl;
  return 0;
}


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

ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}

int main() {
   ll i,j,k;
    ll n,m;
    cin >> n>>m;

    if(n==m)
    {
      cout<<"Yes"<<endl;
    }else
    {
 cout <<  "No"<< endl;
    }
 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, m, a[105];
    cin >> n >> m;
    REP(i,n) cin >> a[i];
    for(int k=1;k<=m;k++){
        REP(i,n-1){
            if(a[i]%k > a[i+1]%k) swap(a[i], a[i+1]);
        }
    }
    REP(i,n) cout << a[i] << endl;
    return 0;
}



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

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

string replace_with_str(string str, string str_from, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(str_from, pos), pos != string::npos) {
        str.replace(pos, str_from.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(int argc, char const *argv[]){
    int N, L;
    cin >> N >> L;
    string s_array[N];
    for(int n=0; n<N; n++){
        cin >> s_array[n];
    }
    
    stable_sort(s_array, s_array+N);
    
    for(int i=0; i<COUNTOF(s_array); i++){
        cout << s_array[i];
    }
    cout << endl;
    return 0;
}



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

int main(){
    int n;
    while(cin >> n){
        int d; cin >> d;
        int a[1001];
        rep(i,n) cin >> a[i];
        sort(a,a+n);
        reverse(a, a+n);
        int ans = 0;
        for(int i = 1; i <= n; ++i){
            int c = accumulate(a, a+i, 0) - d*i;
            ans = max(ans, c);
        }
        if(ans <= 0) cout << "kusoge"; else cout << ans; cout << endl;
    }
}

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

int main() {
    string s;
    cin >> s;
    int n = 3;
    for (int bit = 0; bit < (1 << n); bit++) {
        int sum = s[0] - '0';
        string f = "";
        f += s[0];
        for (int i = 0; i < n; i++) {
            if (bit & (1 << i)) {
                sum -= s[i + 1] - '0';
                f += "-";
            } else {
                sum += s[i + 1] - '0';
                f += "+";
            }
            f += s[i + 1];
        }
        if (sum == 7) {
            f += "=7";
            cout << f << endl;
            return 0;
        }
    }
    return 0;
}


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

int main(){

    ll n,m;
    cin >>n >>m;

    ll ans=0;

    if(n>=3&&m>=3){
        ans=m*n-((n-2)*2+(m-2)*2+4);
    }else{
        if(n>m){
            ll t=m;
            m=n;
            n=t;
        }
        if(n==1&&m!=1){
            ans=m-2;
        }else if(n==1&&m==1){
            ans=1;
        }else if(n==2){
            ans=0;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          int
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        998244353
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define N  100005

  
int main() 
{ 
	string X,Y;
	ll i,j;
	cin>>X>>Y;
	ll m=X.size(),n=Y.size();
   int L[m+1][n+1]; 
  
   /* Following steps build L[m+1][n+1] in bottom up fashion. Note 
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   // Following code is used to print LCS 
   int index = L[m][n]; 
  
   // Create a character array to store the lcs string 
   string lcs; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs+=X[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   }
   reverse(all(lcs));
   cout<<lcs;
}

Measured memory_bytes: 35456