akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
const int MAX = 2000005;
const ll 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;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//a^n%mod
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  COMinit();
  cout << (COM(c+1+d+1,c+1)+COM(a+b,a)-COM(a+d+1,a)-COM(c+b+1,b)+MOD*2)%MOD << endl;
}


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

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
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; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 


ll f(ll m){
    if (m == 1){
        return 1;
    }
    return 2 * f(m/2) + 1;
}

int main() {
    ll H;
    cin >> H;
    cout << f(H);
    return 0;
}


Measured memory_bytes: 256
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def is_match(parent, child, pi, pj):
    for ci in range(len(child)):
        for cj in range(len(child[ci])):
            # c = child[ci][cj]
            # p = parent[pi+ci][pj+cj]
            if child[ci][cj] != parent[pi+ci][pj+cj]:
                return False
    return True


def solve(N, M, inputs):
    map_parent = list(map(list, inputs[:N]))
    map_child = list(map(list, inputs[N:]))

    for pi in range(0, N-M+1):
        for pj in range(0, N-M+1):
            if is_match(map_parent, map_child, pi, pj):
                return 'Yes'
    return 'No'


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    [N, M] = string_to_int(input())
    ret = solve(N, M, inputs(N+M))
    print(ret)

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

int main() {
int a,b;
cin>>a>>b;
 if(a==b)
 {cout <<"Draw";}
else if(a==1)
cout<<"Alice";
else if(b==1)
{cout<<"Bob";}
else if (a>b)
{cout<<"Alice";}
else if (b>a)
{cout <<"Bob";}

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;

 
int main(){
  int r;
  cin>>r;
  if(r<1200) cout << "ABC" << endl;
  else if(r>=2800) cout << "AGC" << endl;
  else cout << "ARC" << 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++)
using ll = long long;

int main() {
int n;
cin >> n;
vector<int> h(n);
rep(i,n) cin >> h.at(i);
int ans  = 1;
int maxHeight = h.at(0);
for(int i = 1; i < n; i++){
  if(h.at(i) >= maxHeight){
    ans++;
    maxHeight = h.at(i);
  }
}
cout << ans << endl;
}
  


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

int main()
{

	int i, N;
	string S;
	long long M = 0, A = 0, R = 0, C = 0, H = 0;
	
	cin >> N;

	for (i = 0; i < N; ++i){
		cin >> S;
		if (S[0] == 'M')	++M;
		else if (S[0] == 'A')	++A;
		else if (S[0] == 'R')	++R;
		else if (S[0] == 'C')	++C;
		else if (S[0] == 'H')	++H;
	}
	
	long long total;

	total = M*A*R + M*A*C + M*A*H
		+ M*R*C + M*R*H
		+ M*C*H
		+ A*R*C + A*R*H
		+ A*C*H
		+ R*C*H;

	cout << total << endl;

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;

int main(){
    int a,t=0,tt=0,ans=1e9;cin>>a;
    vector<int> v(a);
    for(auto &i:v) {cin>>i;t+=i;}
    for(auto i:v) {tt+=i;t-=i;ans=min(ans,abs(t-tt));}
    cout<<ans;
}

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

unsigned long long
choose(unsigned long long n, unsigned long long k) {
	if (k > n) {
		return 0;
	}
	unsigned long long r = 1;
	for (unsigned long long d = 1; d <= k; ++d) {
		r *= n--;
		r /= d;
	}
	return r;
}

int main(void) {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) --a[i];
	vector<int> cnt(n);
	for (int i = 0; i < n; ++i) ++cnt[a[i]];
	long long tot = 0;
	for (int i = 0; i < n; ++i) {
		tot += choose(cnt[i], 2);
	}
	for (int i = 0; i < n; ++i) {
		long long ans = tot;
		ans -= choose(cnt[a[i]], 2);
		ans += choose(cnt[a[i]] - 1, 2);
		cout << ans << '\n';
	}
	return 0;
}

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

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

Measured memory_bytes: 3636
// ProblemURL : https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_a
// ---------------------------------------------
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	fmt.Println(s[:4] + " " + s[4:])
}


Measured memory_bytes: 512
#template
def inputlist(): return [int(j) for j in input().split()]
#template
"""
H,W = inputlist()
st = inputlist()
gl = inputlist()
maze = ['0']*H
for i in range(H):
    maze[i] = list(input())
table = [[10**9+7]*W for _ in range(H)]

"""
D,T,S = inputlist()
time = D//S + int(D%S != 0)
if time <= T:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9144
#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(){

int n,m;
cin >> n >> m;
vector<int>h(n);
rep(i,n){
    cin >> h.at(i);
}

vector<vector<int>> data(m, vector<int>(2));
rep(i,m){
    cin >> data.at(i).at(0) >> data.at(i).at(1);
}


vector<bool>good(n);
rep(i,n){
    good.at(i) = true;
}

int a,b;
rep(i,m){

a = data.at(i).at(0) - 1;
b = data.at(i).at(1) - 1;

if(h.at(a) < h.at(b)){
    good.at(a) = false;
    
}

if(h.at(a) > h.at(b)){
    good.at(b) = false;
    
}
if(h.at(a) == h.at(b)){
    good.at(a) = false;
    good.at(b) = false;
}

}
int ans = 0;
rep(i,n){
if(good.at(i) == true){
    ans++;
}
}

cout << ans << endl;
}


Measured memory_bytes: 9072
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

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

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> grid(H);

  REP(i, H){
    cin >> grid[i];
  }

  auto is_valid = [=](int x, int y){
    if( x<0 || x >= H || y < 0 || y >= W) return false;
    if(grid[x][y] == '#') return false;
    return true;
  };

  vector<vector<int>> dp(H, vector<int>(W, 0));
  dp[0][0] = 1;

  REP(i, H){
    REP(j, W){
      if(!is_valid(i,j)) continue;
      int tmp1 = is_valid(i-1,j)? dp[i-1][j]%MOD : 0;
      int tmp2 = is_valid(i,j-1)? dp[i][j-1]%MOD : 0;
      chmax(dp[i][j], tmp1 + tmp2 % MOD);
    }
  }

  cout << dp[H-1][W-1] % MOD << endl;

}

Measured memory_bytes: 5248
import java.io.IOException;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {

        // long startTime = System.currentTimeMillis();

        Scanner scanner = new Scanner(System.in);

        int h = scanner.nextInt();
        int w = scanner.nextInt();

        char[][] map = new char[h][w];
        for (int i = 0; i < h; i++) {
            String str = scanner.next();
            for (int j = 0; j < w; j++) {
                map[i][j] = str.charAt(j);
            }
        }

        scanner.close();

        boolean result = true;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if ('.' == map[i][j]) {
                    continue;
                }

                if ((i - 1) >= 0 && '#' == map[i - 1][j]) {
                    continue;
                } else if ((i + 1) < h && '#' == map[i + 1][j]) {
                    continue;
                } else if ((j - 1) >= 0 && '#' == map[i][j - 1]) {
                    continue;
                } else if ((j + 1) < w && '#' == map[i][j + 1]) {
                    continue;
                }
                result = false;
                break;
            }
            if (!result) {
                break;
            }
        }
        System.out.println((result) ? "Yes" : "No");

        // System.out.println(System.currentTimeMillis() - startTime);
    }
}

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

const int MAX = 4000;
const int MOD = 998244353;
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 pow2[2001];
Int solve(int K, int N, int i)
{
    if (i <= 1) return COM(K+N-1, N);
    if (i % 2 == 0) return (solve(K-1, N, i-1) + solve(K-1, N-1, i-1)) % MOD;
    Int ans = 0;
    int npairs = 0;
    for (int j = 1; j+j < i; j++) if (j <= K && i-j <= K) npairs++;
    int rest = K - npairs*2;
    for (int j = 0; j <= npairs; j++) {
        if (j + rest == 0) continue;
        if (j > N) continue;
        ans += COM(j+rest + N-j - 1, N-j) * COM(npairs, j) % MOD * pow2[j] % MOD;
        ans %= MOD;
    }
    ans %= MOD;
    return ans;
}
int main()
{
    COMinit();
    pow2[0] = 1;
    for (int i = 1; i < 2001; i++) {
        pow2[i] = pow2[i-1] * 2 % MOD;
    }
    int K, N; cin >> K >> N;
    for (int i = 2; i <= 2*K; i++) {
        cout << solve(K, N, i) << '\n';
    }
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  int a[n], b[n];
  for (int i=0; i<n; i++) {
    cin>>a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  long long ans = 0;
  for (int i=0; i<n; i++) {
    int j = lower_bound(b, b + n, a[i]) - b;
    int d = abs(i - j);
    if (d % 2 != 0) {
      ++ans;
    }
  }
  cout<<ans/2<<endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1000000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
  int n,x;
  cin >> n >> x;
  bool c[2*n-1] = { };
  if(x == 1 || x == (2*n - 1)) cout << "No" << endl;
  else{
    cout << "Yes" << endl;
    int a[2*n-1];
    a[n-1] = x;
    a[n-2] = x-1;
    a[n] = x+1;
    c[x-1] = true;
    c[x-2] = true;
    c[x] = true;
    if(x <= n){
      if(n!=2){
        a[n-3] = x+2;
        c[x+1] = true;
      }
      int cur = 2*n-1;
      REP(i, n-3){
        while(c[cur-1]) cur--;
        a[i] = cur;
        c[cur-1] = true;
      }
      REP(i, n-2){
        while(c[cur-1]) cur--;
        a[2*n-2-i] = cur;
        c[cur-1] = true;
      }
      REP(i, 2*n-1) cout << a[i] << endl;
     }
    else{
      if(n!=2){
        a[n+1] = x-2;
        c[x-3] = true;
      }
      int cur = 2*n-1;
      REP(i, n-2){
        while(c[cur-1]) cur--;
        a[i] = cur;
        c[cur-1] = true;
      }
      REP(i, n-3){
        while(c[cur-1]) cur--;
        a[2*n-2-i] = cur;
        c[cur-1] = true;
      }
      REP(i, 2*n-1) cout << a[i] << endl;
     }
  }
	return 0;
}

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


vector <ll> terms;
map <ll,ll> indexes;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    ll i,j,k,l,m,n,x;

    cin >> n >> x >> m;

    k = x;
    ll ans= 0;
    j = -1;
    for(i=1;i<=n;i++)
    {
        l = (k%m*k%m)%m;
        terms.push_back(k);
        
        
        if(indexes.find(k) != indexes.end())
        {
            j = indexes[k];
            // cout << indexes[k] << '\n';
            break;
        }
        else
        {
            indexes[k] = i-1;
        }

        ans += k;
        // cout << k << '\n';

        k = l;
    }

    if(j == -1)
    {
        cout << ans << '\n';
        return 0;
    }

    // cout << j << " " << i-2 << '\n';

    // for(k=0;k<j-1;k++)
    // {
    //     ans += terms[k];
    // }

    l = 0;

    for(k=j;k<i-1;k++)
    {
        l += terms[k];

    }

    // cout << "L: " << l << '\n';

    m = (i-j-1);
    ans += l*((n-i+1)/(i-j-1));

    // cout << m << " " << ((n-i+1)/(i-j-1)) << '\n';

    for(k=j;k<j+(n-i+1)%(i-j-1);k++)
    {
        ans += terms[k];
    }

    cout << ans << '\n';

    


}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n; cin >> n;
    vector<P> point(n);
    rep(i, n) point[i].second = i;
    rep(i, n*(n-1)/2) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        a--, b--;
        if(c > d) point[a].first += 3;
        if(c == d) point[a].first++, point[b].first++;
        if(c < d) point[b].first += 3;
    }
    sort(point.begin(), point.end());
    reverse(point.begin(), point.end());

    vector<int> ans(n);
    rep(i, n) {
        if(i != 0 && point[i].first == point[i-1].first) {
            ans[point[i].second] = ans[point[i-1].second];
        } else {
            ans[point[i].second] = i + 1;
        }
    }
    rep(i, n) cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>
#include <utility>
#include <iostream>

struct Node;
extern Node *NONE;
struct Node {
#define l ch[0]
#define r ch[1]
	Node *p = NONE;
	Node *ch[2] = {NONE, NONE};
	bool rev = false;
	bool enabled_self = false;
	int disabled_sum = 0;
	int light = 0; // LIGHT
	int right = 0;
	int left = 0;
	Node *fetch() {
		if (l != NONE) l->flush();
		if (r != NONE) r->flush();
		disabled_sum = l->disabled_sum + r->disabled_sum + !enabled_self;
		if (enabled_self) {
			left = l->disabled_sum ? l->left : light + l->left + 1 + r->left;
			right = r->disabled_sum ? r->right : light + r->right + 1 + l->right;
		} else left = l->left, right = r->right;
		return this;
	}
	Node *flush() {
		if (rev) {
			std::swap(l, r);
			l->rev ^= 1;
			r->rev ^= 1;
			std::swap(left, right);
			rev = false;
		}
		return this;
	}
	bool is_root() { return p == NONE || (p->l != this && p->r != this); }
	Node *rotate(bool dir) {
		Node *new_root = ch[!dir];
		ch[!dir] = new_root->ch[dir];
		ch[!dir]->p = this;
		new_root->ch[dir] = this;
		if (p->l == this) p->l = new_root;
		if (p->r == this) p->r = new_root;
		new_root->p = p;
		p = new_root;
		return fetch(), new_root->fetch();
	}
	void splay() {
		flush();
		while (!is_root()) {
			if (p->is_root()) {
				p->flush(), flush();
				p->rotate(p->l == this);
			} else {
				Node *pp = p->p;
				pp->flush(), p->flush(), flush();
				bool flag0 = pp->l == p;
				bool flag1 = p->l == this;
				if (flag0 == flag1) pp->rotate(flag0);
				p->rotate(flag1);
				if (flag0 != flag1) pp->rotate(flag0);
			}
		}
	}
	Node *expose() {
		Node *prev = NONE;
		for (Node *cur = this; cur != NONE; cur = cur->p) {
			cur->splay();
			if (cur->r != NONE) {
				cur->r->flush();
				cur->light += cur->r->left;
			}
			cur->r = prev;
			if (cur->r != NONE) {
				cur->r->flush();
				cur->light -= cur->r->left;
			}
			cur->fetch();
			prev = cur;
		}
		splay();
		return prev;
	}
	void link(Node *parent) {
		expose();
		parent->expose();
		p = parent;
		parent->r = this;
		parent->fetch();
	}
	void cut() {
		expose();
		l->p = NONE;
		l = NONE;
		fetch();
	}
	void evert() {
		expose();
		rev ^= 1;
		flush();
	}
#undef l
#undef r
};
Node *NONE = new Node;

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int q = ri();
	Node nodes[n];
	for (auto &i : nodes) i.enabled_self = true, i.fetch();
	
	for (int i = 1; i < n; i++) {
		int a = ri() - 1;
		int b = ri() - 1;
		nodes[a].evert();
		nodes[a].link(nodes + b);
	}
	for (int i = 0; i < q; i++) {
		int t = ri();
		int x = ri() - 1;
		if (t == 1) nodes[x].expose(), nodes[x].enabled_self ^= 1, nodes[x].fetch();
		else nodes[x].evert(), printf("%d\n", nodes[x].left);
	}
	
	return 0;
}



Measured memory_bytes: 7908
#include <stdio.h>
#include <vector>
#include <queue>

int main() {
    int n; scanf("%d", &n);
    std::vector<std::vector<int>> g(n);
    for(int i = 0; i < n - 1; i++) {
        int a, b; scanf("%d%d", &a, &b);
    
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    std::vector<bool> used(n, false);
    std::queue<int> qu;
    while(true) {
        for(int i = 0; i < n; i++) {
            if(used[i]) continue;

            int count = 0;
            for(auto e: g[i]) {
                if(used[e]) continue;
                count++;
            }
            if(count == 1) qu.push(i);
        }

        if(!qu.size()) break;
        while(!qu.empty()) {
            auto p = qu.front(); qu.pop();

            int B = -1;
            for(auto e: g[p]) {
                if(used[e]) continue;
                B = e;
            }
            if(B == -1) continue;
            used[p] = used[B] = true;
        }
    }

    bool ans = true;
    for(auto v: used) ans &= v;

    if(!ans) printf("First\n");
    else printf("Second\n");
    return 0;
}


Measured memory_bytes: 6016
n=int(input())

l=[n]
while True:
  if n%2==0:
    n=n/2
    if n in l:
      print(len(l)+1)
      break
    l.append(n)
  else:
    n=3*n+1
    if n in l:
      print(len(l)+1)
      break
    l.append(n)

Measured memory_bytes: 9248
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
vector<int>v[N];
int res[N];
int vis[N];
int main(){
	int n,m,st,ed;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>st>>ed;
		v[st].push_back(ed);
		v[ed].push_back(st);
	} 
	queue<int>q;
	q.push(1);
	vis[1]=1;
	while(q.size()){
		int x=q.front();
		q.pop();
		for(int i=0;i<v[x].size();i++){
			int to=v[x][i];
			if(!vis[to]){
				res[to]=x;
				//printf("%d to %d\n",x,to);
				vis[to]=1;
				q.push(to);
			} 
		} 
	} 
	int cnt=0;
	for(int i=2;i<=n;i++){
		if(res[i]!=0){
			cnt++;
		}
	}
	if(cnt==n-1){
		printf("Yes\n");
		for(int i=2;i<=n;i++){
			printf("%d\n",res[i]);
		}
	
	}
	else printf("No\n");
}

Measured memory_bytes: 10784
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef long long ll;
const int MAX = 1e5+10;
const int  MAX1 = 1e5+10;
const int INF = 1e9+10;
double eps = 1e-6;
int main(){
    IOS
    string s, t;
    cin >> s >> t;

    int ln = s.length(), sum = 0;
    for(int i = 0;i < ln;i++){
        if(s[i] != t[i]){
            sum++;
        }
    }
    cout << sum << endl;


}


/*


*/


Measured memory_bytes: 3796
while True:
    try:
        num=list(map(int, input().split(",")))
        #trainとか作る必要なかった
        train=[num[10],num[11]]
        del num[10]
        del num[-1]
            
    except:
        break
    #dis=両端の距離(全体の距離)
    dis=0
    for i in num:
        dis+=i
    #x=両電車がすれ違うまでの時間[h]
    x=dis/(train[0]+train[1])
    lon=x*train[0]
    b=0
    l=1
    while l<=10:
        b+=num[l-1]
        if b>=lon:
            print(l)
            break
        l+=1
        
        
        


Measured memory_bytes: 5604
#include <iostream>

using namespace std;

int main(){
    int h;
    int w;
    for(int i = 0; i < 300;){
        cin >> h >> w;
        if(h == 0 && w == 0){
            break;
        }
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(i == 0 || j == 0 || i == h - 1 || j == w - 1){
                    cout << "#";
                }
                else{
                    cout << ".";
                }
            }
            cout << "" << endl;
        }
        cout << "" << endl;
    }
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
#define INF 1000000000
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t)
{
    std::ostringstream os;
    os << t;
    return os.str();
}
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main()
{
    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == b[i] && a[i] == c[i])
        {
            continue;
        }
        else if ((a[i] == b[i] && b[i] != c[i]) || (a[i] == c[i] && a[i] != b[i]) || (b[i] == c[i] && a[i] != c[i]))
        {
            ans++;
        }
        else if (a[i] != b[i] && a[i] != b[i] && b[i] != c[i])
        {
            ans += 2;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll=long long;
using Graph = vector<vector<int>>;
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; }
const long long INF = 1LL<<60;
ll dp[100010];
Graph g;
int rec(int v){
    if(dp[v] != -1) return dp[v]; 
    int res = 0;   
    for(auto nv : g[v]){
        chmax(res,rec(nv)+1);
    }
    return dp[v] = res;
}

int main() {

int n,m,mx=0; cin >> n >> m;
for (int i = 0; i < n; ++i)
{
    dp[i]=-1;
}
g.assign(n, vector<int>());
for (ll i = 0; i < m; ++i)
{
    int x,y; cin>>x>>y;--x;--y;
    g[x].push_back(y);
}
int res=0;
for (ll i = 0; i < n; ++i)
{
    chmax(res,rec(i));
}

cout << res;
return 0;
}




Measured memory_bytes: 8576
import scala.io.StdIn

object Main extends App {

  val Array(h, w) = StdIn.readLine().split(' ').map(_.toInt)

  val tiles = (0 until h).map(_ => StdIn.readLine().split(' ')).toArray
  val square = Array.fill[Int](h + 1, w + 1)(0)
  var max = 0

  (1 to h).foreach { i =>
    (1 to w).foreach { k =>
      square(i)(k) = if(tiles(i-1)(k-1) == "0"){
        val t1 = square(i)(k-1)
        val t2 = square(i-1)(k-1)
        val t3 = square(i-1)(k)

        (if(t1 < t2){
          if(t1 < t3) t1 else t3
        } else if(t2 < t3){
          t2
        } else {
          t3
        }) + 1
      } else {
        0
      }

      max = scala.math.max(square(i)(k), max)
    } 
  }

  println(max*max)

}



Measured memory_bytes: 192036
# frozen_string_literal: true

N, M = gets.chomp.split(' ').map(&:to_i)

class PriorityQueue
  def initialize
    @elements = [nil]
  end

  def <<(element)
    @elements << element
    # bubble up the element that we just added
    bubble_up(@elements.size - 1)
  end

  def bubble_up(index)
    parent_index = (index / 2)

    # return if we reach the root element
    return if index <= 1

    # or if the parent is already greater than the child
    return if @elements[parent_index] >= @elements[index]

    # otherwise we exchange the child with the parent
    exchange(index, parent_index)

    # and keep bubbling up
    bubble_up(parent_index)
  end

  def exchange(source, target)
    @elements[source], @elements[target] = @elements[target], @elements[source]
  end

  def pop
    # exchange the root with the last element
    exchange(1, @elements.size - 1)

    # remove the last element of the list
    max = @elements.pop

    # and make sure the tree is ordered again
    bubble_down(1)
    max
  end

  def bubble_down(index)
    child_index = (index * 2)

    # stop if we reach the bottom of the tree
    return if child_index > @elements.size - 1

    # make sure we get the largest child
    not_the_last_element = child_index < @elements.size - 1
    left_element = @elements[child_index]
    right_element = @elements[child_index + 1]
    child_index += 1 if not_the_last_element && right_element > left_element

    # there is no need to continue if the parent element is already bigger
    # then its children
    return if @elements[index] >= @elements[child_index]

    exchange(index, child_index)

    # repeat the process until we reach a point where the parent
    # is larger than its children
    bubble_down(child_index)
  end
end

bites = Array.new(M) { [] }
N.times do
  a, b = gets.chomp.split(' ').map(&:to_i)
  next if a > M

  bites[a - 1].push(b)
end

queue = PriorityQueue.new()
cnt = 0
bites.each do |bite|
  bite.each { |b| queue << b }
  pop = queue.pop
  cnt += pop unless pop.nil?
end

puts cnt


Measured memory_bytes: 13308
fn main() {
    proconio::input! {
        mut a: i64,
        b: i64,
        mut c: i64,
        d: i64
    }
    loop {
        c -= b;
        if c <= 0{
            println!("Yes");
            break;
        }
        a -= d;
        if a <= 0{
            println!("No");
            break;
        }
    }
}

Measured memory_bytes: 2172
using System;


namespace AtCoder20170211 {
	class Program {
		static void Main(string[] args) {
			decimal n = Convert.ToDecimal(Console.ReadLine());
			decimal k = Convert.ToDecimal(Console.ReadLine());
			decimal x = Convert.ToDecimal(Console.ReadLine());
			decimal y = Convert.ToDecimal(Console.ReadLine());

			decimal result = 0;

			if (n > k) {
				result = k * x;
				result += (n - k) * y;
			}
			else {
				result = n * x;
			}
			Console.WriteLine(result);
		}
	}
}


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

using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;
const int N = 1e5;
const int INF = 1e9 + 10;
int n, kk;
int h[N], dp[N+1];

int main() {
  scanf("%d%d ", &n, &kk);
  REP(i,n) scanf("%d ", h+i);
  REP(i,n+1) dp[i] = INF;
  dp[0] = 0;
  REP(i,n) FOR(j,1,kk+1) {
    if (i+j >= n) continue;
    dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]));
  }
  printf("%d\n", dp[n-1]); 
  return 0;
}


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

int main(){
  long long N, K;
  cin >> N >> K;
  long long a, b;
  pair<long long, long long> p[N];
  rep(i, N){
    cin >> a >> b;
    p[i].first = a;
    p[i].second = b;
  }
  //

  sort(p, p+N);

  int i = 0;
  long long sum = 0;
  while(sum < K){
    sum += p[i].second;
    i++;
  }

  cout << p[i-1].first << endl;

  return 0;
}


Measured memory_bytes: 5128
import scala.io.StdIn


object Main {
    def main(args:Array[String]) = {
        /* 文字列を読み込み、空白で分割して配列にし、Int型にする */
//        val in = StdIn.readLine().split(" ").map(_.toInt)
//        val a = in(0)
//        val b = in(1)
//        val c = in(2)
//        println(a)
//        println(b)
//        println(c)
        val in = StdIn.readLine().split(" ").map(_.toInt)
        val a = in(0)
        if (a < 1200) {
            print("ABC")
        } else {
            print("ARC")
        }
 //       println(a)
    }
}

Measured memory_bytes: 21420
def p2(num):
    if num == 0:
        return 0
    else:
        return (num * (num - 1)) // 2


a = [sorted(input()) for i in range(int(input()))]
sorted_arr = sorted(a)

tmp = [""]
tmp_num = 0
tmp_arr = []
for i in sorted_arr:
    if i != tmp:
        tmp = i
        tmp_arr.append(tmp_num)
        tmp_num = 1
    else:
        tmp_num += 1
tmp_arr.append(tmp_num)
res = 0
for i in tmp_arr:
    res += p2(i)
print(res)


Measured memory_bytes: 26052
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>

ll INF = 1000000007;


//-----------------//
  #define amin main
//-----------------//


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i,j;
	ll n;
	cin>>n;
	ll cnt=0;
	ll f= 0;
	while(n--)
	{
		ll a,b;
		cin>>a>>b;
		if(a==b)
			cnt++;
		else
			cnt= 0;
		if(cnt>=3)
			f=1;

	}
	if(f==0)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
	
	


	
	return 0;
}

Measured memory_bytes: 3684
#include<stdio.h>
#include<stdlib.h>
typedef struct {
	int b;
	int j;
}button;
int main()
{
	int n;
	scanf("%d",&n);
	button *b;
	b = (button*)malloc(sizeof(button)*(n+1));
	for(int t=1;t<=n;t++)
	{
		scanf("%d",&b[t].b);
		b[t].j = 0;
	}
	int s=0,t=1;
	
	do
	{
		b[t].j = 1;
		t = b[t].b;
		s++;
		if(b[t].j == 1)
		{
			printf("-1\n");
			return 0;
		}
	}while(t != 2);
	printf("%d\n",s);
	return 0;
}

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

using namespace std;

#define fRead(x)  freopen(x,"r",stdin)
#define fWrite(x) freopen (x,"w",stdout)

#define LL long long
#define ULL unsigned long long
#define ff first
#define ss second
#define pb push_back
#define INF 2e16
#define PI acos(-1.0)
#define mk make_pair

#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define SQR(a) ((a)*(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,b) for(int i=0;i<b;i++)
#define MEM(a,x) memset(a,x,sizeof(a))
#define ABS(x) ((x)<0?-(x):(x))

#define scanI(a) scanf("%d",&a)
#define scanI2(a,b) scanI(a) , scanI(b)
#define scanI3(a,b,c) scanI(a), scanI(b), scanI(c)
#define scanI4(a,b,c,d) scanI(a), scanI(b), scanI(c), scanI(d)

#define scanL(a) scanf("%I64d",&a)
#define scanL2(a,b) scanL(a) , scanL(b)
#define scanL3(a,b,c) scanL(a), scanL(b), scanL(c)
#define scanL4(a,b,c,d) scanL(a), scanL(b), scanL(c), scanL(d)

#define SORT(v) sort(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())

#define FastRead ios_base::sync_with_stdio(0);cin.tie(nullptr);

LL BigMod(LL B,LL P,LL M){LL R=1;while(P>0){if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;}return R;}

LL n,x;
vector<LL>v;
int main()
{

    cin >> n >> x;
    REP(i,n)
    {
        LL a;
        cin >> a;
        v.pb(a);
    }
    LL ans = 0;
    for(LL i =1;i<v.size()-1;i++)
    {
        if(v[i]+v[i-1]>x)
        {
            LL dif = v[i]+v[i-1]-x;
            LL baad = min(v[i],dif);
            v[i] -= baad;
            ans+=baad;
        }
    }
//    cout << ans<<endl;
//    REP(i,v.size())cout << v[i] << " ";
//    cout << endl;
    if(v[0]+v[1]>x){
            LL dif = v[0]+v[1]-x;
            LL baad = min(v[0],dif);
            v[0] -= baad;
            ans+=baad;
    }
    if(v[n-1]+v[n-2]>x){
            LL dif = v[n-1]+v[n-2]-x;
            LL baad = min(v[n-1],dif);
            v[n-1] -= baad;
            ans+=baad;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1400
l,r=[int(i) for i in input().split()]
ans=100000000000000
for i in range(max(2019*(l//2019)-1,l),min(2019*(l//2019+1),r)+1):
    for j in range(max(2019*(l//2019)-1,l),min(2019*(l//2019+1),r)+1):
        if i!=j:
            ans=min(ans,(i*j)%2019)
print(ans)

Measured memory_bytes: 40940
#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++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
#define PER(i,n) for(int i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n;
  cin >> n;
  vi v(n);
  rep(i,n) cin >> v[i];
  int d = 0;
  vector<vP> cnt(2);
  rep(cur,2) {
    map<int,int> mp;
    for(int i = d; i < n; i += 2) mp[v[i]]++;
    for(P p : mp) {
      cnt[d].emplace_back(p.se, p.fi);
    }
    d++;
  }
  cnt[0].emplace_back(0,-1);
  cnt[1].emplace_back(0,-1);
  sort(rall(cnt[0]));
  sort(rall(cnt[1]));

  int ans = n;
  if(cnt[0][0].se != cnt[1][0].se) {
    ans -= (cnt[0][0].fi + cnt[1][0].fi);
  }
  else {
    ans -= max(cnt[0][0].fi + cnt[1][1].fi, cnt[0][1].fi + cnt[1][0].fi);
  }

  cout << ans << endl;
}

Measured memory_bytes: 4216
import math
import time

if __name__ == '__main__':
    a = int(input())
    count = 0
    while(a != 1):
        count += 1
        a = math.floor(a / 2)
    sum_d = 0
    d = 1
    for i in range(count):
        sum_d += 2 ** d
        d += 1
    print(sum_d + 1)

Measured memory_bytes: 3184
// B - Product Max
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = 0;
    ll acd = max(a*c, a*d);
    ll bcd = max(b*c, b*d);
    ans = max(acd, bcd);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

p = 0
for i in al:
    p += bl[i-1]

count = 0
tmp = -1
for i in al:
    if tmp == i-1:
        p += cl[tmp-1]
    tmp = i
print(p)

Measured memory_bytes: 3060
s = input()
t = input()

my_d = dict()

for i, ch in enumerate(s):
    if ch not in my_d:
        if t[i] in my_d.values():
            print('No')
            exit()
        else:
            my_d[ch] = t[i]
    else:
        if my_d[ch] != t[i]:
            print('No')
            exit()

print('Yes')

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<bool> is_prime( 1000100 );
vector<int> Eratosthenes( const int N = 1000100 ) {
    for( int i = 0; i <= N; i++ ) {
        is_prime[ i ] = true;
    }
    vector<int> P;
    for( int i = 2; i <= N; i++ ) {
        if( is_prime[ i ] ) {
            for( int j = 2 * i; j <= N; j += i ) {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}

int main(void) {
    int n;
    cin >> n;

    vector<int> foge = Eratosthenes();

    vector<int> ans;

    for (int i = 11; i <= 55555; i++) {
        if (is_prime[i] && i % 5 == 1) ans.pb(i);
    }
    
    rep (i, n) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 1020
def insertionSort(arr, N, g):
    cnt = 0
    for i in range(g, N):
        tmp = arr[i]
        j = i - g
        while(j >= 0 and arr[j] > tmp):
            arr[j + g] = arr[j]
            j -= g
            cnt += 1
        arr[j + g] = tmp
    return cnt


def shellSort(arr, N):
    cnt = 0
    G = []
    h = 0
    m = 0
    while h <= N / 9:
        h = 3 * h + 1
        G.append(h)
        m += 1
    G = G[::-1]

    cnt = sum([insertionSort(arr, N, g) for g in G])
    return (cnt, G)


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

(cnt, G) = shellSort(arr, N)
print(len(G), ' '.join(map(str, G)), cnt, '\n'.join(map(str, arr)), end='\n')



Measured memory_bytes: 125976
(R,C,K),*RCV = $<.map{|ln| ln.split.map(&:to_i) }

Rs = Array.new(R){ [0]*C }
RCV.each{|s,d,v|
	Rs[s-1][d-1] = v
}

r0 = [0]*C
while r1 = Rs.shift
	c,vs = 0,[0]*4
	while c < C
		vs[0] = r0[c] if vs[0] < r0[c]
		if 0 < v = r1[c]
			vs[3] = vs[2]+v if vs[3] < vs[2]+v
			vs[2] = vs[1]+v if vs[2] < vs[1]+v
			vs[1] = vs[0]+v if vs[1] < vs[0]+v
		end
		r0[c] = vs.max
		c += 1
	end
end

p r0[-1]


Measured memory_bytes: 99632
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let vs: Vec<usize> = sc.vec(n);
    let cs: Vec<usize> = sc.vec(n);
    
    let result: usize = vs
        .iter()
        .zip(cs.iter())
        .map(|x| {
            if x.0 >= x.1 {
                return x.0 - x.1;
            }
            0
        })
        .sum();
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}
// end of Template
str s;
bool valid = true;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>s;
    for(int i=0;i<s.size();i++){
        if(i%2==0 && s[i]=='L') valid=false;
        if(i%2==1 && s[i]=='R') valid=false;
    }
    if(valid)cout<<"Yes\n";
    else cout<<"No\n";

}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            Tea[] teas = new Tea[4];
            for (int i = 0; i < 4; i++) {
                teas[i] = new Tea(in.nextLong(), 1 << i);
            }
            Arrays.sort(teas, new Comparator<Tea>() {

                public int compare(Tea o1, Tea o2) {
                    return Long.compare(o1.yen * o2.liter, o2.yen * o1.liter);
                }
            });
            long N = in.nextLong() * 4;
            long ans = 0;
            for (int i = 0; i < 4; i++) {
                ans += N / teas[i].liter * teas[i].yen;
                N %= teas[i].liter;
            }
            out.println(ans);
        }

        class Tea {
            long yen;
            int liter;

            public Tea(long yen, int liter) {
                this.yen = yen;
                this.liter = liter;
            }

        }

    }

    static class InputReader {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(nextLine());
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 21460
import sys
input=lambda: sys.stdin.readline().rstrip()
mod=10**9+7
n=int(input())
edge=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
Ans=[]
inf=10**6

#親と入次数を求める
Par=[inf]*n
Par[0]=-1
Deg=[0]*n
Deg[0]=0
Chk=[0]
while Chk:
  c=Chk.pop()
  for next in edge[c]:
    if Par[next]==inf:
      Par[next]=c
      Deg[next]+=1
      Chk.append(next)
 
#トポソする
from collections import deque
TS=list(v for v in range(n) if Deg[v]==0)
D=deque(TS)
while D:
  v=D.popleft()
  for t in edge[v]:
    if t!=Par[v]:
      Deg[t]-=1
      if Deg[t]==0:
        D.append(t)
        TS.append(t)

C1,C2=[0]*n,[0]*n
for i in reversed(range(n)):
  v=TS[i]
  if len(edge[v])==1 and Par[v]!=-1:
    C1[v]=1
    C2[v]=1
  else:
    c1,c2=1,1
    for g in edge[v]:
      if g==Par[v]:
        continue
      else:
        c1*=C1[g]+C2[g]
        c2*=C1[g]
    C1[v]=c1%mod
    C2[v]=c2%mod
print((C1[0]+C2[0])%mod)



Measured memory_bytes: 74288
import sys
import math
from collections import Counter
get_string = lambda: sys.stdin.readline().strip()
get_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
get_int = lambda: int(sys.stdin.readline())

#----------------------------------------------------------------------#

n,k=get_list()
a=get_list()
freq_dict=Counter(a)
if len(freq_dict)<=k:
    print(0)
else:
    freq=[]
    for key in freq_dict:
        freq.append(freq_dict[key])
    freq.sort()
    ans=0
    for i in range(len(freq_dict)-k):
        ans+=freq[i]
    print(ans)

Measured memory_bytes: 95704
n = int(input())
A = sorted(map(int, input().split()), key=lambda x : abs(x))
count = sum(x < 0 for x in A)
if count % 2 == 0:
    print(sum(abs(x) for x in A))
else:
    print(-abs(A[0]) + sum(abs(x) for x in A[1:]))

Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }

int main(){
  int n,m; cin >> n >> m;
  cout << (1900*m+100*(n-m))*(int)pow(2,m);
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3964