akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n, -1) {}
    int find(int x) {
        if (d[x]<0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x==y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return -d[find(x)];
    }
};

int fri[100005];
int blo[100005];

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        fri[a]++;
        fri[b]++;
        uf.unite(a, b);
    }
    
    rep(i, k) {
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        if (uf.same(c, d)) {
            blo[c]++;
            blo[d]++;
        }
    }
    rep(i, n) {
        int ans = uf.size(i) - 1 - fri[i] - blo[i];
        cout << ans << " " ;
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,m,k,ans;
string s;
int dp[111][2][111];//桁、未満フラグ、kのカウント
signed main(){
	 cin>>s>>k;
	 dp[0][0][0]=1;
	 rep(i,s.size()){
	 	int now=s[i]-'0';
	 	rep(smaller,2){
	 			rep(cnt,k+1){
	 				for(int x=0;x<=(smaller?9:now);x++){
	 					if(x==0)dp[i+1][smaller||x<now][cnt]+=dp[i][smaller][cnt];
	 					else dp[i+1][smaller||x<now][cnt+1]+=dp[i][smaller][cnt];
	 				}
	 			}
	 	}
	 }
	 cout<<dp[s.size()][0][k]+dp[s.size()][1][k]<<endl;
}


Measured memory_bytes: 384
O = input()
E = input()

arr = []
if len(O) > len(E):
    for i in range(len(E)):
        arr.append(O[i])
        arr.append(E[i])
    arr.append(O[-1])
else:
    for i in range(len(E)):
        arr.append(O[i])
        arr.append(E[i])


print(*arr, sep='')


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

const int MAX = 510000;
const int mod = 1000000007;

long long 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;
    }
}

// 二項係数計算
long long 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 main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> factors;
    int s=floor(sqrt(m));
    int r=0;
    rep(i,2,s+1){
        if((m%i)==0){
            r=0;
            while(m%i==0){
                ++r;
                m/=i;
            }
            factors.push_back(r);
        }
    }
    if(m>s) factors.push_back(1);

    ll ans=1;
    COMinit();
    for(auto au:factors){
        ans*=COM(n+au-1,n-1);
        ans%=mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 12160
from collections import defaultdict

N, M = map(int, input().split())

submit = defaultdict(list)
for i in range(M):
    p,s = map(str, input().split())
    submit[p].append(s)


wa = 0
ac = 0
for k in submit.keys():
    if "AC" in submit[k]:
        for i in range(len(submit[k])):
            if submit[k][i] == "WA":
                wa += 1
            elif submit[k][i] == "AC":
                ac += 1
                break
        


print(ac, wa)


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

int main() {
  string s;
  cin>>s;
  int p,q;

  rep(i,s.size()){
    if(s[i]=='A'){
      p=i;
      break;
    }
  }
  for(int i=s.size();i>0;i--){
    if(s[i]=='Z'){
      q=i;
      break;
    }
  }
  cout<<q-p+1<<endl;
}

Measured memory_bytes: 640
from copy import deepcopy

N, M = map(int, input().split())

k = []
s = []
for m in range(M):
    i = input().split()
    k.append(i[0])
    s.append(list(map(int, i[1:])))

p = list(map(int, input().split()))

def dfs(sw, depth):
    if depth == N:
        for i in range(M):
            counter = 0
            for j in s[i]:
                if sw[j-1] == 1:
                    counter += 1
            if counter % 2 != p[i]:
                return 0
        return 1
    
    ans = 0
    copy1 = deepcopy(sw)
    copy2 = deepcopy(sw)
    copy1.append(0)
    copy2.append(1)
    ans += dfs(copy1, depth + 1)
    ans += dfs(copy2, depth + 1)
    return ans

print(dfs([], 0))

Measured memory_bytes: 45148
#include <stdio.h>

int main()
{
    int n, p;

    while (scanf("%d %d", &n, &p) * n){
        int stone[64] = {0};
        int bowl = p;
        int i;

        for (i = 0; stone[i] != p; i = (i + 1) % n){
            if (bowl > 0){
                bowl--;
                stone[i]++;
            }
            else {
                bowl += stone[i];
                stone[i] = 0;
            }
        }
        printf("%d\n", i);
    }
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void Main()
{
  int a;
  cin >> a;
  
  printf("%d", a + a * a + a * a * a);
}

int main()
{
  std::cout << std::fixed << std::setprecision(15);
  Main();
}



Measured memory_bytes: 3796
#include <iostream>
#include <algorithm>

using namespace std;

long long get_gcd_cd(long long c, long long d){
	long long r = 0;
	long long min = c;
	long long big = d;
	if(c>d){
		int tmp = min;
		min = big;
		big = tmp;
	}

	r = big % min;
	while(r != 0){
		big = min;
		min = r;
		r = big % min;
	}

	return min;
 }

int main(){
	/*input*/
	long long a, b, c, d;
    cin >> a >> b >> c >> d;

	/*calc*/
    long long ans = 0;
    long long lcm = 0; //最小公倍数
    long long gcd = 0; //最大公約数
    long long num_under_b = 0;
    long long num_under_a = 0;

    gcd = get_gcd_cd(c,d);
    lcm = c*d/gcd;

    num_under_b = (b/c)+(b/d)-(b/lcm);
    num_under_a = (a-1)/c + (a-1)/d - (a-1)/lcm;

    ans = (b - num_under_b) - (a-1 - num_under_a);
	/*output*/
   	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll n,m;
    cin>>n>>m;
    ll sum=0;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i],sum+=a[i];
    sort(a,a+n);
    ll p=(sum+(4*m)-1)/(4*m);
    ll r=0;
    for(int i=n-1;i>=0;i--){
        if(a[i]>=p) r++;
    }
    if(r>=m) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
    int K, S; cin >> K >> S;

    ll cnt = 0;
    for (int x = 0; x <= K; x++) {
        for (int y = 0; y <= K; y++) {
            int z = S - x - y;
            if (z >= 0 && z <= K) cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3576
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] B = new int[N - 1];
        int A = 0;

        for (int i = 0; i < N - 1; i++) {
            B[i] = Integer.parseInt(sc.next());
        }

        A += B[0];
        for (int i = 1; i < N - 1; i++) {
            A += Math.min(B[i - 1], B[i]);
        }
        A += B[N - 2];

        PrintWriter out = new PrintWriter(System.out);
        out.println(A);

        sc.close();
        out.flush();
    }
}

Measured memory_bytes: 35696
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	int L[10];
	int goukei = 0;
	rep(i, N) {
		cin >> L[i];
		goukei += L[i];
	}
	int saidai = *max_element(L, L + N);
	
	goukei -= saidai;
	ce(goukei);
	ce(saidai);

	if (saidai < goukei) co("Yes");
	else co("No");

	Would you please return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)

ans = 'Yes'

for i in range(N // 2):
    if S[i] != S[N - 1 - i]: ans = 'No'

for i in range((N // 2) // 2):
    if S[i] != S[(N // 2) - 1 - i]: ans = 'No'
    if S[((N + 1) // 2) + i] != S[N - 1 - i]: ans = 'No'

print(ans)

Measured memory_bytes: 3060
main = do
 n <- read <$> getLine :: IO Int
 hList <- map read . words <$> getLine :: IO [Int]
 let tmp = scanr1 (\x y -> if x > y then x - 1 else x) hList
 putStr $ (\x -> if and x then "Yes" else "No") $ map (\x -> x <= 0) $ zipWith (-) tmp $ tail tmp

Measured memory_bytes: 69788
// aaaaaaaaaaaaaaaaaaaburirburbubruburbrirbiur


#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second

#define all(v) (v).begin(), (v).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,b) FOR(i,0,b)
#define reps FOR
#define eb emplace_back
#define pb eb

template<class T> inline bool MX(T &l, const T &r) { return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l, const T &r) { return l>r?l=r,1:0;}

using LL = long long;
using pii = pair<int, int>;
using pll = pair<LL, LL>;

int N;
LL M;
vector<pll> segs;


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

  vector<pll> evs;
  rep(i, N) {
    LL l, r;
    cin >> l >> r;
    segs.eb(pll(r, l));
    evs.eb(pll(l, -1));
    evs.eb(pll(r, 1));
  }
  sort(all(evs));

  LL prev = -1;
  int cur = 0;
  int times = 0;
  for (auto &e : evs) {
    MX(times, cur);
    cur -= e.Y;
    prev = e.X;
  }

  if (times%2) { // hidari dakara migi
    //reverse siyou
  } else { // migi dakara hidari
    rep(i, N) {
      LL a, b;
      tie(a, b) = segs[i];
      segs[i] = pll(M-b, M-a);
    }
  }
  
  multiset<int> cur_end;
  rep(i, times) {
    cur_end.insert(-1);
  }

  //cout << "times: " << times << endl;
  sort(all(segs));
  for (auto &p : segs) {
    auto itr = cur_end.lower_bound(p.Y);
    assert(itr != cur_end.begin());
    itr--;
    cur_end.erase(itr);
    cur_end.insert(p.X);
  }
  assert(*cur_end.begin() != -1);
  //for (LL v : cur_end) cout << v << " ";
  //cout << endl;
  //cout << M*LL(times-1) << ", " << *cur_end.begin() << endl;
  cout << M*LL(times-1) + *cur_end.begin() << endl;
}



Measured memory_bytes: 21396
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007LL;
const int INF = LLONG_MAX;

signed main(){
    
    int n, k; cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }

    sort(h.begin(), h.end());
    int ans = INF;
    for(int i = 0; i <= n - k; i++){
        ans = min(ans, h[i + k - 1] - h[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		Drink[] d = new Drink[n];
		for (int i = 0; i < n; i++) {
			d[i] = new Drink(sc.nextInt(), sc.nextInt());
		}
		Arrays.sort(d, new Comparator<Drink>() {
			public int compare(Drink d1, Drink d2) {
				if(d1.price == d2.price) {
					return d2.num-d1.num;
				}else {
					return d1.price-d2.price;
				}
			}
		});
		long sum = 0;
		for(Drink d1:d) {
			if(m>d1.num) {
				sum += (long)d1.num*(long)d1.price;
				m -= d1.num;
			}else {
				sum += (long)d1.price*(long)m;
				break;
			}
		}
		System.out.println(sum);
		sc.close();
	}
	public static class Drink {
		int price; int num;
		Drink(int a, int b){
			this.price = a;
			this.num = b;
		}
	}
}

Measured memory_bytes: 88560
fn chmin<T: PartialOrd>(x: &mut T, a: T) {
    if *x > a {
        *x = a;
    }
}

fn main() {
    proconio::input! {
        n: usize,
        h: [i32; n],
    }
    let mut dp = vec![std::i32::MAX; n];
    dp[0] = 0;
    for i in 0..n {
        let a = h[i];
        let d = dp[i];
        for (b, x) in h.iter().zip(dp.iter_mut()).skip(i + 1).take(2) {
            chmin(x, d + (a - *b).abs());
        }
    }
    let ans = dp[n - 1];
    println!("{}", ans);
}

Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],f=0;
    for(int i=0;i<n;i++)
    {cin>>a[i];
    if(a[i]%2==0 && a[i]%3!=0 && a[i]%5!=0)
    f=1;
    }
    if(f)
    cout<<"DENIED";
    else
    cout<<"APPROVED";
}


Measured memory_bytes: 256
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

inline void print(string name,int *arr,int len){
	rep(i,1,len) printf("%s[%d]=%d\n",name.c_str(),i,arr[i]);puts("");
}
inline void print(string name,int a){
	printf("%s=%d\n",name.c_str(),a);puts("");
}

typedef long long ll;
const int INF=1<<30;

int main()
{
	int a,b;cin>>a>>b;
	if(abs(a+b)&1){
		puts("IMPOSSIBLE")	;
	}
	else cout<<(a+b)/2<<endl;
	return 0;
}


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

void koch(int n, double xx, double xy, double yx, double yy)
{
	if( n == 0 ){
		return;
	}
	
	double sx, sy, tx, ty, ux, uy;
	
	sx = (2.0*xx+1.0*yx) / 3.0;
	sy = (2.0*xy+1.0*yy) / 3.0;
	tx = (1.0*xx+2.0*yx) / 3.0;
	ty = (1.0*xy+2.0*yy) / 3.0;
	ux = (tx-sx)*cos(M_PI/3) - (ty-sy)*sin(M_PI/3) + sx;
	uy = (tx-sx)*sin(M_PI/3) + (ty-sy)*cos(M_PI/3) + sy;
	
	koch(n-1, xx, xy, sx, sy);
	printf( "%.8f %.8f\n", sx, sy );
	koch(n-1, sx, sy, ux, uy);
	printf( "%.8f %.8f\n", ux, uy );
	koch(n-1, ux, uy, tx, ty);
	printf( "%.8f %.8f\n", tx, ty );
	koch(n-1, tx, ty, yx, yy);
}
	

int main(void){
	int n;
	scanf( "%d", &n );
	
	double ax = 0.0;
	double ay = 0.0;
	double bx = 100.0;
	double by = 0.0;
	
	printf( "%.8f %.8f\n", ax, ay );
	
	koch(n, ax, ay, bx, by);
	
	printf( "%.8f %.8f\n", bx, by );
	
	return 0;
}


Measured memory_bytes: 2072
eval"A,B,C,D,E,F="+`tr \\  ,`;d={};f=->a,b{d[[a,b]]||=a*100+b>F||a*E<b ?-1:(f[a+A,b];f[a+B,b];f[a,b+C];f[a,b+D];b.quo a)};f[A,0];f[B,0];a,b=d.max_by{|_,v|v}[0];p a*100+b,b

Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1.0);

signed main(){
    double A,B,H,M;cin>>A>>B>>H>>M;
    cout<<fixed<<setprecision(20.20);
    double d=pi*H/6.0+pi*M/360.0;
    double t=pi*M/30.0;
    double ansf=A*A+B*B-2*A*B*cos(d-t);
    cout<<sqrt(ansf)<<endl;
}

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


#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define MAXX 10000007
#define INF INT_MAX

#define PI   3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll 	 long long 
#define mod  1000000007


int main()
{
	FAST;
	int n;
	cin >> n;
    if(n == 1){
        cout << "0" << endl;
        return 0;
    }
    if(n == 2){
        cout << "2" << endl;
        return 0;
    }
    ll ans = 1;
    for(ll i = 0; i < n; i++){
        ans *= 10;
        ans %= mod;
    }
    ans += mod;
    ans += mod;
    ll k = 2;
    int sum = 0;
    for(ll i = 0; i < n; i++){
        k *= 9;
        k %= mod;
    }
    k += mod;
    ll p = 1;
    for(ll i = 0; i < n; i++){
       p *= 8;
       p %= mod;
    }
    ans = (ans - (k - p)) % mod;
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;

int j[10];

bool check(int);

int main(){
	int n,d,a;
	cin>>n>>d;
	lp2(i,d){
		cin>>a;
		j[a]=1;
	}
	//lp2(i,10)cout<<i<<" "<<j[i]<<endl;
	while(check(n)==true){
		n++;
	}
	return 0;
}

bool check(int n){
	int num = n;
	while(n!=0){
	if(j[n%10]==1)return true;
	n/=10;
	}
	cout<<num<<endl;
	return false;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;

    int i = 0;
    ll now = 1;
    while(i < n){
        if (s1[i] == s2[i]){
            if (i == 0) now *= 3;
            else {
                if (s1[i-1] == s2[i-1]) now *= 2;
                else now *= 1;
            }
            i++;
        }
        else {
            if (i == 0) now *= 6;
            else {
                if (s1[i-1] == s2[i-1]) now *= 2;
                else now *= 3;
            }
            i += 2;
        }
        now %= MOD;
    }
    cout << now << endl;

    return 0;
}

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

int main() {
  
  int n; cin >> n; int64_t sum = 0; vector<int> vec(n);
  
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  cout << vec.at(0) << " " << vec.at(n - 1) << " " << sum << endl;
  
}


Measured memory_bytes: 3180
S = input()
a = {}

for i in range(4):
    if S[i] in a.keys():
        a[S[i]] += 1
    else:
        a[S[i]] = 1
    

check = 0
for i in a.values():
    if i==2:
        check += 1

if check == 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int h=sc.nextInt();
    int a=0;
    Integer[] b=new Integer[n];
    for(int i=0;i<n;i++){
      a=Math.max(sc.nextInt(),a);
      b[i]=sc.nextInt();
    }
    Arrays.sort(b);
    int fi;
    for(fi=0;fi<n;fi++){
      if(b[fi]>a){
        break;
      }
    }
    int ans=0;
    for(int i=n-1;i>=fi;i--){
      h-=b[i];
      ans++;
      if(h<=0){
        System.out.println(ans);
        return;
      }
    }
    System.out.println((h+a-1)/a+ans);
  }
}

Measured memory_bytes: 65088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int N;
vector<int> b;
int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        int x; cin >> x;
        b.push_back(x);
        if(x > i+1){
            cout << -1 << endl;
            return 0;
        }
    }
    vector<int> a(0);
    while(b.size()){
        bool flg = false;
        for(int i = b.size()-1; i >= 0; i--){
            if(b[i] == i+1){
                a.push_back(b[i]);
                b.erase(b.begin() + i);
                flg = true;
                break;
            }
        }
        if(!flg){
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i = a.size()-1; i >= 0; i--){
        cout << a[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void f(int i,vector<int> x[],int b[],set<int> &v,vector<int> &vv)
{
    if(b[i]==0)
    {
        vv.push_back(i);
        v.insert(i);
        b[i]=-1;
        for(int j=0;j<x[i].size();++j)
        {
            f(x[i][j],x,b,v,vv);
        }
    }
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
int p[n+1];
for(int i=1;i<=n;++i)
{
    cin>>p[i];
}
vector<int> x[n+1];
for(int i=0;i<m;++i)
{
    int e,r;
    cin>>e>>r;
    x[e].push_back(r);
    x[r].push_back(e);
}
int b[n+1]={0};
int ans=0;
for(int i=1;i<=n;++i)
{
    if(b[i]==0)
    {
        set<int> v;
        vector<int> vv;
        f(i,x,b,v,vv);
        for(int j=0;j<vv.size();++j)
        {
            if(v.find(p[vv[j]])!=v.end())
                ++ans;
        }
    }
}
cout<<ans;
}


Measured memory_bytes: 15608
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using L = long long;

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

	int n;
	cin >> n;
	vector<int> a(n);
	for(int &ai : a)
		cin >> ai;

	vector<L> pref(n);
	pref[0] = a[0];
	for(int i = 1; i < n; ++i)
		pref[i] = pref[i - 1] + a[i];

	auto getSum = [&](int l, int r) {
		if(l == 0)
			return pref[r];
		return pref[r] - pref[l - 1];
	};

	vector<vector<L>> dp(n, vector<L>(n, L(1e18))); // answer for interval [l, r]
	for(int len = 1; len <= n; ++len)
		for(int l = 0; l <= n - len; ++l) {
			int r = l + len - 1;
			if(l == r)
				dp[l][r] = 0;

			for(int i = l; i < r; ++i)
				dp[l][r] = min(dp[l][r], dp[l][i] + dp[i + 1][r] + getSum(l, r));
		}
	cout << dp[0][n - 1] << '\n';
}



Measured memory_bytes: 1536
#include<iostream>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
  
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[2][n];
	REP(i,2) {
		REP(j,n) {
			cin >> a [ i ] [ j ];
		}
	}
	int sum;
	int maxSum = 0;
	
	REP(i,n) {
		sum = 0;
		REP(j,i+1) {
			sum += a [ 0 ] [ j ];
		}
		FOR(k,i,n) {
			sum += a [ 1 ] [ k ];
		}
		if ( sum > maxSum ) maxSum = sum;
	}
	
	cout << maxSum << endl;
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
vector<int> G[10];
bool OK[1024];
void Calc(){
	int N = rei();
	int M = rei();
	for(int i=0;i<M;i++){
		int K = rei();
		for(int j=0;j<K;j++){
			int s = rei()-1;
			G[i].push_back(s);
		}
	}
	for(int i=0;i<1<<N;i++){
		OK[i] = true;
	}
	for(int i=0;i<M;i++){
		int p = rei();
		for(int j=0;j<1<<N;j++){
			bool odd = false;
			for(int t:G[i]){
				if(j & (1 << t)){
					odd = !odd;
				}
			}
			if((odd && p == 0) || (!odd && p == 1)){
				OK[j] = false;
			}
		}
	}
	int ans = 0;
	for(int i=0;i<1<<N;i++){
		if(OK[i]){
			ans++;
		}
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define MOD 1000000007
#define y1 dskgj
#define y2 dskfj
typedef long long ll;
using namespace std;
ll n,i,j,k,x,y,w,m,Q, used[100500], start;
int main() {
    //freopen("input.txt", "r", stdin);
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    C = min(4*A, min(2*B, C));
    cin >> n;
    if (C*2 <= D)
        cout << C*n << endl;
    else
        cout << D*(n/2) + C*(n%2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
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; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision
ll fxor(ll n){
    ll ans=0;
    if(n%2==0 && (n/2)%2==0){
        ans=n;
    }
    else if(n%2==0 && (n/2)%2!=0){
        ans=1^n;
    }
    else if(n%2==1 && (n/2)%2==0){
        ans=(n-1)^n;
    }
    else{
        ans=0;
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll a,b;
    cin >> a >> b;
    ll res=0;
    res=(fxor(a-1))^(fxor(b));
    cout << res << endl;
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

ll gcd(ll x, ll y)
{
	return y==0 ? x:gcd(y,x % y);
}

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

    ll ans = 0;

    REP(i, 1, K+1)
    {
        REP(j, 1, K+1)
        {
            REP(k, 1, K+1)
            {
                ans += gcd(i, gcd(j, k));
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	string s, t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string u; cin >> u;
    if(s == u) {
        cout << a - 1 << " " << b << endl;
    } else {
        cout << a << " " << b - 1 << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 892
def main():
    S = input()
    from itertools import groupby
    ans = 0
    SL = [(k, len(list(v))) for k, v in groupby(S)]
    if SL[0][0] == ">":
        ans += (SL[0][1])*(SL[0][1] + 1)//2
        pre_v = SL[0][1]
        for k, v in SL[1:]:
            if k == "<":
                pre_v = v
                continue
            else:
                if pre_v > v:
                    ans += pre_v*(pre_v+1)//2
                    ans += v*(v-1)//2
                else:
                    ans += (pre_v-1)*pre_v//2
                    ans += v*(v+1)//2
            # print(ans, pre, pre_v)
            pre_v = v
    else:
        pre_v = 0
        for k, v in SL:
            if k == "<":
                pre_v = v
                continue
            else:
                if pre_v > v:
                    ans += pre_v*(pre_v+1)//2
                    ans += v*(v-1)//2
                else:
                    ans += (pre_v-1)*pre_v//2
                    ans += v*(v+1)//2
            # print(ans, pre, pre_v)
            pre_v = v
    if SL[-1][0] == "<":
        ans += (SL[-1][1])*(SL[-1][1] + 1)//2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 83400
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9

int main(){
    int n; 
    cin >> n;
    vector<int> p(n), q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<int> a(n);
    rep(i,n) a[i] = i+1;

    map<vector<int>, int> mp;
    do {
        mp[a] = mp.size();
    } while (next_permutation(a.begin(), a.end()));

    int ans = abs(mp[p] - mp[q]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8640
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

LL ans[55];
int main(){
	int n = 50;
	printf("%d\n", n);
	LL k; cin >> k;
	LL ave = k / n, lft = k % n;
	REP(i, 1, n) ans[i] = ave * (n + 1) + (n - 1) - k;
	REP(i, 1, lft) ans[i] += (n + 1);
	// printf("%d\n", n);
	REP(i, 1, n) printf("%lld ", ans[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 256
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 res ;

        if (a<=5) {
        	res = 0;            	
        }else if (a<=12) {
        	res = b/2; 
        }else {
        	res = b;
        } 
      System.out.println(res);
    }
}


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

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var ac = 0;
            var wa = 0;
            var tle = 0;
            var re = 0;

            for (int i = 0; i < n; i++)
            {
                var s = Console.ReadLine();
                if (s == "AC")
                {
                    ac++;
                }
                if (s == "WA")
                {
                    wa++;
                }
                if (s == "TLE")
                {
                    tle++;
                }
                if (s == "RE")
                {
                    re++;
                }
            }
            Console.WriteLine("AC x " + ac);
            Console.WriteLine("WA x " + wa);
            Console.WriteLine("TLE x " + tle);
            Console.WriteLine("RE x " + re);
        }
    }
}


Measured memory_bytes: 30484
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	in >> N;
	std::vector<LL>p(N);
	rep(i, N) in >> p[i];

	LL cnt = 0;
	rep(i, N)
	{
		if (p[i] != i + 1) ++cnt;
	}

	out << (cnt <= 2 ? "YES" : "NO") << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
long long n, ans, cnt;
void dfs(long long x, int f) {
    if (x > n) return;
    if (f == 7) cnt++;
    dfs(x * 10 + 3, f | 1);
    dfs(x * 10 + 5, f | 2);
    dfs(x * 10 + 7, f | 4);
}
void solve() {
    cin >> n;
    dfs(0, 0);
    cout << cnt << endl;
    return;
}
//逆元を求める関数
long long 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;
    }
}
//組み合わせ
long long 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 main(int args, char* argv[]) {
    solve();
}

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

int main(){
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;

  for(int i = 0;i <= n;i++){
    int j;
    for(j = 0;j < n;j++){
      if(j+i < n){
        if(s[i+j] != t[j]){
          break;
        }
      }
    }
    if(j == n){
      cout << n+i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
import java.util.Comparator;
import java.util.Scanner;

/* static int java.util.Arrays.binarySearch(int[] a, int key); */


public class Main {
    Scanner sc = new Scanner(System.in);
    int n, c;
    int[][] d;
    public void run(){
        n = sc.nextInt();
        c = sc.nextInt();
        d = new int[c][c];
        for(int i = 0; i < c; i++){
            for(int j = 0; j < c; j++){
                int cd = sc.nextInt();
                d[i][j] = cd;
            }
        }
        solve();
    }
    public void solve(){
        int memo[][] = new int[c][3];

        for(int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                int nc = sc.nextInt() - 1;
                int nn = (i + j) % 3;
                for(int k = 0; k < c; k++){
                    memo[k][nn] += d[nc][k];
                }
            }
        }

        int ans = Integer.MAX_VALUE;
        for(int i = 0; i < c; i++){
            for(int j = 0; j < c; j++){
                for(int k = 0; k < c; k++){
                    if(i != j && j != k && k != i){
                        int sum = memo[i][0] + memo[j][1] + memo[k][2];
                        if(ans > sum){
                            ans = sum;
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }

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

    static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }
    static class Edge{
        int to, cost;
        public Edge(int a, int b){
            this.to = a;
            this.cost = b;
        }
    }
    class MyComparator implements Comparator {
        @Override
        public int compare (Object arg0, Object arg1) {
            int x = ((Pair)arg0).first;
            int y = ((Pair)arg1).first;

            if (x < y) {
                return 1;
            } else if (x > y) {
                return -1;
            } else{
                return 0;
            }
        }
    }
    static class UnionFind{
        int par[];
        int rank[];

        //n要素で初期化
        public UnionFind(int maxn){
            par = new int[maxn];
            rank = new int[maxn];

            for(int i = 0; i < maxn; i++){
                par[i] = i;
                rank[i] = 0;
            }
        }

        //木の根を求める
        int find(int x){
            if(par[x] == x){
                return x;
            }
            else {
                return par[x] = find(par[x]);
            }
        }

        // xとyの属する集合を併合
        void unite (int x, int y){
            x = find(x);
            y = find(y);
            if(x == y){
                return;
            }

            if(rank[x] < rank[y]){
                par[x] = y;
            }
            else{
                par[y] = x;
                if(rank[x] == rank[y]) rank[x]++;
            }
        }

        // xとyが同じ集合に属するか否か
        boolean same(int x, int y){
            return find(x) == find(y);
        }
    }

}

Measured memory_bytes: 76024
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

void dfs(vvll &g,vll &cnt,vll &sum,ll n,ll sub){
	if(sum.at(n)!=-1) return ;
	sum.at(n) = sub+cnt.at(n) ;
	for(int i=0;i<g.at(n).size();i++){
		dfs(g,cnt,sum,g.at(n).at(i),sum.at(n)) ;
	}
}

int main(){
	ll n ; cin >> n ;
	ll q ; cin >> q ;
	vvll g(n,vll(0)) ;
	for(int i=0;i<n-1;i++){
		ll a,b ;
		cin >> a >> b ;
		a-- ; b-- ;
		g.at(a).push_back(b) ;
		g.at(b).push_back(a) ;
	}
	vll cnt(n,0) ;
	for(int i=0;i<q;i++){
		ll p,x ;
		cin >> p >> x ;
		p-- ;
		cnt.at(p) += x ;
	}
	vll sum(n,-1) ;
	dfs(g,cnt,sum,0,0) ;
	for(int i=0;i<n;i++){
		cout << sum.at(i) ;
		if(i==n-1) cout << endl ;
		else cout << " " ;
	}
}


Measured memory_bytes: 32128
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>
#include <iomanip>
#include <functional>
#include <queue>

#define int long long
int inf = (1LL <<  62);
using namespace std;

signed main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int , int>> ls;
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        pair<int, int> p;
        p.first = y;
        p.second = x;
        ls.push_back(p);
    }
    sort(ls.begin(), ls.end());
    int point = ls[0].first;
    int ans = 1;
    for(int i = 1; i <= m - 1; i++){
        if(point <= ls[i].second){
            ans++;
            point = ls[i].first;
        }
    }
    cout << ans;
}


Measured memory_bytes: 2420
#include <stdio.h>
int bubblesort(int a[],int n)
{
    int i,j,temp,ans=0;
    for(i=0; i<n; i++)
    {
        for(j=n-1; j>i; j--)
        {
            if(a[j]<a[j-1])
            {
                temp=a[j];
                a[j]=a[j-1];
                a[j-1]=temp;
                ans++;
            }
        }
    }
    for(i=0; i<n; i++)
    {
        if(i>0) printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
    printf("%d\n",ans);
    return ans;
}

int main()
{
    int n,i,j;
    int a[100];

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

    bubblesort(a,n);

    return 0;
}



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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int dp[50][100010][2];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  rep(i, 50) rep(j, 100010) rep(k, 2) dp[i][j][k] = 1e9;
  dp[0][0][0] = 0;
  i32 K; cin >> K;
  rep(i, 45) {
    vi32 b(K, false);
    rep(j, K) {
      if (b[j]) continue;
      i32 p = j, n = (p * 10) % K;
      do {
        amin(dp[i][n][1], dp[i][p][1]);
        p = n; n = (p * 10) % K;
        b[p] = true;
      } while (!b[n]);
    }
    rep(j, K) rep(k, 2) rep(l, 10) {
      if (dp[i][j][k] == 1e9) continue;
      if (k == 0 && l == 0) { dp[i + 1][j][k] = 0; continue; }
      amin(dp[i + 1][(j * 10 + l) % K][1], dp[i][j][k] + l);
    }
  }
  i32 ans = 1e9;
  reps(i, 45) amin(ans, dp[i][0][1]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 39724
#include <iostream>
#include <string>

using namespace std;

int main(){
	string o, e;
	cin >> o >> e;
	for(int i = 0; i < e.size(); i++){
		cout << o[i] << e[i];
	}
	if(o.size() != e.size())
		cout << o[o.size() - 1];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
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;
}
constexpr int INF = 1e9 + 7;
constexpr ll LINF = 1LL << 60;

void solve() {
    int n, k;
    cin >> n >> k;
    V<int> D(k);
    rep(i, k) cin >> D[i];
    int ans = n;
    while (true) {
        int v = ans;
        bool ok = true;
        while (v > 0) {
            int d = v % 10;
            rep(i, k) {
                if (D[i] == d) ok = false;
            }
            v /= 10;
        }
        if (ok) break;
        ans++;
    }
    cout << ans << "\n";
}
int main() {
    cin.tie(nullptr);
    // ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3572