akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node {
  int key;
  struct Node *right,*left,*parent;
};

struct Node *root,*NIL;

void insert(int k){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z =(struct Node*) malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if( z-> key < x-> key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;
  if( y == NIL){
    root = z;
  }
  else{
    if(z->key < y-> key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}

void inorder( struct Node *u){
  if(u == NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct Node *u){
    if(u == NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
  int n,i,x;
  char com[6];
  scanf("%d", &n);

  for(i = 0;i<n;i++){
    scanf("%s",com);
    if(strcmp(com,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }
    else if( strcmp(com,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 24040
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	memo := make([][]int, n)
	for i := 0; i < n ; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		memo[i] = make([]int, 3)
		memo[i][0], memo[i][1], memo[i][2] = a, b, c
	}
	arr := make([][]int, n)
	arr[0] = make([]int, 3)
	arr[0][0], arr[0][1], arr[0][2] = memo[0][0], memo[0][1], memo[0][2]
	for i := 0; i < n - 1; i++ {
		arr[i + 1] = make([]int, 3)
		for j := 0; j < 3; j++ {
			arr[i + 1][j] = max1(arr[i][(j + 1) % 3], arr[i][(j + 2) % 3]) + memo[i + 1][j]
		}
	}
	mx := 0
	for i := 0; i < 3; i++ {
		if mx < arr[n - 1][i] {
			mx = arr[n - 1][i]
		}
	}
	fmt.Println(mx)
}

func max1(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

Measured memory_bytes: 12416
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
MOD = 10**9+7
N = int(input())
G = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)


def tree(S):
    for g in G[S]:
        G[g].remove(S)
        tree(g)


tree(0)

dp = [[-1]*2 for _ in range(N)]


def main(S, f):
    if dp[S][f] != -1:
        return dp[S][f]
    ret = 1
    if f == 1:
        for g in G[S]:
            ret *= main(g, 0)
            ret %= MOD
    else:
        for g in G[S]:
            ret *= main(g, 0)+main(g, 1)
            ret %= MOD
    dp[S][f] = ret
    return ret


print((main(0, 0)+main(0, 1)) % MOD)


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

int main()
{
    int a,b;
    scanf("%i%i",&a,&b);
    if(a<=0 && b>=0) printf("Zero\n");
    else if((a>0 && b>0) || (a<0 && b<0 && (b-a)%2==1)) printf("Positive\n");
    else printf("Negative\n");
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
public class s
{
  public static void Main()
  {
    string s=Console.ReadLine();
    string ans="";
    for(int i=0;i<s.Length;i++)
    {
      if(i%2==0)ans+=s[i];
    }
    Console.WriteLine(ans);
  }
}

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

void Main(){
    ll N,X,M; cin >> N >> X >> M;
    VVI appear(M); appear[X].push_back(0);

    bool flag = true;
    int pos = 1;
    REP(i,N-1){
        X = X*X % M;
        if(appear[X].size() == 2){
            flag = false;
            break;
        }
        appear[X].push_back(pos++);
    }

    ll ans = 0;
    if(flag){
        REP(i,M){
            ans += (ll)i * (ll)appear[i].size();
        }
    }
    else{
        ll cycle;
        REP(i,M){
            if(appear[i].size()<2) continue;
            cycle = appear[i][1] - appear[i][0];
            break;
        }

        REP(i,M){
            if(appear[i].empty()) continue;

            if(appear[i].size() == 1) ans += i;
            else{
                ans += ((N-1-appear[i][0]) / cycle + 1) * (ll)i;
            }
        }
    }

    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 7064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;bool flag = false;
  while(1){
    cin >> H >> W;
    if(H==0&&W==0)break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	if(j==0){
	  if(i%2 == 0){
	    cout << '#';
	    flag = true;
	  }
	  else{
	    cout << '.';
	    flag = false;
	  }
	}
	else{
	  if(flag == true){
	    cout << '.';
	    flag = false;
	  }
	  else{
	    cout << '#';
	    flag = true;
	  }
	}
      }
      cout << endl;
    }
    cout << endl;
  }
  
}

Measured memory_bytes: 1152
h,w=map(int,input().split())
f=lambda:[[0]*w for _ in range(h)]
g=[input() for _ in range(h)]
l,r=f(),f()
for i in range(h):
  lc=rc=0
  for j in range(w):
    if g[i][j]=='.': lc+=1; l[i][j]=lc
    else: lc=0
    if g[i][-1-j]=='.': rc+=1; r[i][-1-j]=rc
    else: rc=0
d,u=f(),f()
for i in range(w):
  dc=uc=0
  for j in range(h):
    if g[j][i]=='.': dc+=1; d[j][i]=dc
    else: dc=0
    if g[-1-j][i]=='.': uc+=1; u[-1-j][i]=uc
    else: uc=0
print(max(l[i][j]+r[i][j]+d[i][j]+u[i][j]-3 for i in range(h) for j in range(w)))

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


void solve(long long N, long long M){
    cout<<(N*(N-1))/2 + (M*(M-1))/2<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
long long combi(long long n, long long k) {
	if (n == k || k == 0)
		return 1;
	else {
		return combi(n - 1, k - 1) + combi(n - 1, k);
	}
}
long long gcd(long long a, long long b) {
	return a % b ? gcd(b, a%b) : b;
}
long long isPrime(long long x){
	if (x <= 1) return 0;
	if (x == 2) return 1;
	for (int i = 2; i < sqrt(x); i++) {
		if (x % i == 0) return 0;
	}
	return 1;
}
int main() {
	ll a, b;
	cin >> a >> b;
	ll c = gcd(a, b);
	int k=2;
	vector<ll> v;
	v.push_back(1);
	if (isPrime(c)) {
		cout << 2 << endl;
		return 0;
	}
	const int sq = sqrt(c);
	while (k <= sq) {
		if (c%k==0) {
			c /= k;
			if(v.back()!=k){
				v.push_back(k);

			}
		}
		else {
			k++;
		}
	}
	if (c != 1)v.push_back(c);
	cout << v.size() << endl;
	return 0;
}

Measured memory_bytes: 256
#ABC096-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
B=[False]*2+[True]*(55554)
mid=55555//2
for i in range(2,mid):
    if B[i]:
        for j in range(2*i,55556,i):
            B[j]=False
c=0
for i in range(2,55556):
    if c==n:
        break
    else:
        if B[i] and i%5==1:
            print(i,end=" ")
            c+=1
print()

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

using namespace std;

typedef long long ll;

ll n, x;

int main() {
  scanf("%lld %lld", &n, &x);
  ll a = min(x, n - x);
  ll b = max(x, n - x);
  ll res = n;
  while (b % a) {
    res += (b / a) * 2 * a;
    b %= a;
    swap(a, b);
  }
  res += ((b / a - 1) * 2 + 1) * a;
  printf("%lld\n", res);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //ATTENTION: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/
string s;
/**********************************/

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

    cout << "ABC" << s << endl;
}


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

int n,m,l,s,inf=1e5+1,t,a,c,b,ok;
int g[305][305],G[305][305],re;
int ind[25],cost[25],dp[20][(1<<18)];


int f(int cur,int vis){
if(dp[cur][vis]!=-1) return dp[cur][vis];
if((vis&(~(1<<cur)))==0) return dp[cur][vis]=G[l][cur]+cost[cur];
dp[cur][vis]=1e9;
for(int j=0;j<l;j++){
    if((j!=cur)&&(((1<<j)&vis)!=0)){
        dp[cur][vis]=min(dp[cur][vis],f(j,vis&(~(1<<cur)))+G[j][cur]);
    }
}
dp[cur][vis]+=cost[cur];
return dp[cur][vis];
}

int main(){
while(cin>>n>>m>>l>>s>>t){
    if(n+m+l+s+t==0) break;
    memset(dp,-1,sizeof(dp));s--;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) g[i][j]=inf;
        g[i][i]=0;
    }
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        a--;b--;
        g[a][b]=c;
        g[b][a]=c;
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++)
                g[i][j]=min(g[i][k]+g[k][j],g[i][j]);
        }
    }
    for(int i=0;i<l;i++){
        cin>>ind[i]>>cost[i];
        ind[i]--;
    }
    for(int i=0;i<l;i++){
        G[i][l]=g[ind[i]][s];
        G[l][i]=g[ind[i]][s];
        for(int j=0;j<l;j++) G[i][j]=g[ind[i]][ind[j]];
    }
    re=0;
    for(int i=0;i<(1<<l);i++){
        int cnt=0;
        for(int j=0;j<l;j++) if(i&(1<<j)) cnt++;
        for(int j=0;j<l;j++){
            if(i&(1<<j)){
                if(f(j,i)+G[j][l]<=t) re=max(re,cnt);
            }
        }
    }
    cout<<re<<endl;
}
return 0;
}

Measured memory_bytes: 23896
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, A, B = in.nextInt
  val Mod = 1000000007


  def nCk(n: Int, k: Int): BigInt = {
    val numer = (n - k + 1 to n).foldLeft(1L)((z, i) => z * i % Mod)
    (2 to k).foldLeft(BigInt(numer))((z, i) => BigInt(i).modInverse(Mod) * z % Mod)
  }

  def powMod(base: Int, pow: Int): Int = {
    @scala.annotation.tailrec
    def powMod0(base: Long, pow: Int, mul: Long): Long = {
      if (pow == 1) base * mul % Mod
      else powMod0(base * base % Mod, pow / 2, mul * (if ((pow & 1) == 1) base else 1) % Mod)
    }
    powMod0(base, pow, 1).toInt
  }

  println((Mod.toLong * 2 + powMod(2, N) - nCk(N, A) - nCk(N, B) - 1) % Mod)
}

Measured memory_bytes: 119652
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;

int main(){
	int a, b, c;
	while (1){
		cin >> a;
		if (!a){
			break;
		}
		int count = 0;
		for (size_t i = 2; i<a; i++){
			double x = (double)a / i;
			if (x - (double)i / 2 < 0){
				break;
			}
			if ((x - (int)x)==0.0&&i%2==1){
				count++;
				//cout << "!" <<x<< endl;
			}
			else if (x - (int)x == 0.5&&i%2==0){
				count++;
				//cout << "?" <<x<< endl;
			}
		}
		cout <<count << endl;
	}
}

Measured memory_bytes: 1160
n = int(input())
xu = []
sum_xu = 0
for i in range(n):
    x, u = input().split()
    xu.append([float(x), u])

for i in range(n):
    if xu[i][1] == 'JPY':
        sum_xu += xu[i][0]
    elif xu[i][1] == 'BTC':
        sum_xu += xu[i][0]*380000.0

print(sum_xu)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<int> vi;

int main(){FIN
	
  	vi es = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
           int k;
           cin >> k;
           cout << es[k - 1] << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#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 FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n;
    cin >> n;
    vector<ll> a;
    REP(i, n * 3) {
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(ALL(a));
    int cur_a = 0;
    int cur_b = a.size();
    ll res = 0;
    while(cur_a != cur_b) {
        cur_b -= 2;
        res += a[cur_b];
        cur_a++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<string> S(N);
    rep(i,N) cin >> S[i];

    int cnt = 0;
    rep(i,N) {
        if (S[i] == "A") cnt++;
        else cnt--;
        if (cnt < 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << (cnt ? "NO" : "YES") << endl;
}


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

int main(){ 
  int x, a, b;
  cin >> x >> a >> b;
  int d1 = abs(x - a), d2 = abs(x - b);
  cout << (d1 < d2 ? 'A' : 'B') << endl;
  return 0;
} 

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
xdvd = int(input())
res = 0
for al in range(a + 1):
  for be in range(b + 1):
    for ga in range(c + 1):
      if 500 * al + 100 * be + 50 * ga == xdvd:
        res += 1
print(res)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if((b-2*a)%2==0&&(4*a-b)%2==0&&b>=2*a&&4*a>=b)
        cout<<"Yes";
    else cout<<"No";
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N,M;
const LL mod = 1e9 + 7;
LL ans;

int main(){
	scanf("%d%d" , &N , &M);
	if(N<M) swap(N,M);
	if(N-M>1){
		printf("0\n");
	} else {
		ans = 1;
		repm(i,N,0){
			(ans *= i) %= mod;
		}
		repm(i,M,0){
			(ans *= i) %= mod;
		}
		printf("%lld\n" , (ans * (N==M?2:1)) % mod);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
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;
}
int iso_lower(vector<int> V, int x) {
    //ソートされたVの中から、V[i]>=xとなる最小のiを返す.存在しなければVの要素数を返す
    int s = V.size();
    V.push_back(INF);
    int l = -1;
    int r = s;  //rが常にtrue
    while(r - l > 1) {
        int mid = (l + r) / 2;
        if(V[mid] < x)
            l = mid;
        else
            r = mid;
    }
    return r;
}
int N, M;
signed main() {
    cin >> N >> M;
    vector<int> A(N), B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    sort(all(A));
    sort(all(B));
    rep(i, N - 1) {
        if(A[i] == A[i + 1]) {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, M) {
        if(B[i] == B[i + 1]) {
            cout << 0 << endl;
            return 0;
        }
    }
    int ans = 1;
    for(int i = N * M; i >= 1; i--) {
        int tate = iso_lower(A, i);
        int yoko = iso_lower(B, i);
        //cout << i << ' ' << ans << ' ' << tate << ':' << yoko << endl;
        if(tate == N || yoko == M) {
            cout << 0 << endl;
            return 0;
        }
        if(A[tate] == i || B[yoko] == i) {
            if(A[tate] == i)
                tate = 1;
            else
                tate = N - tate;
            if(B[yoko] == i)
                yoko = 1;
            else
                yoko = M - yoko;
            ans = (ans * tate * yoko) % mod;
            continue;
        }
        int now = N * M - i;
        tate = N - tate;
        yoko = M - yoko;
        if(tate * yoko <= now) {
            cout << 0 << endl;
            return 0;
        }
        ans = (ans * (tate * yoko - now)) % mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
const Int MAX = 300000;
const Int INV2 = 500000004;
Int itwo[MAX];
void init() {
    itwo[0] = 1;
    for (Int i = 1; i < MAX; i++) {
        itwo[i] = itwo[i - 1] * INV2 % MOD;
    }
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    init();
    int N; cin >> N;
    vector<vector<int>> G(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    vector<int> nodes(N);
    Int ans = 0;
    auto recur = [&](auto&& recur, int node, int prev) -> void {
        nodes[node] = 1;
        vector<int> A;
        for (int next : G[node]) if (next != prev) {
            recur(recur, next, node);
            A.push_back(nodes[next]);
            nodes[node] += nodes[next];
        }
        A.push_back(N - nodes[node]);
        Int prob = 1;
        prob = (prob + MOD - itwo[N - 1]) % MOD;
        for (auto a : A) {
            prob = (prob + MOD - itwo[N - 1 - a] + itwo[N - 1]) % MOD;
        }
        ans = (ans + INV2 * prob) % MOD;
    };
    recur(recur, 0, -1);
    cout << ans << '\n';
    return 0;
}


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

#define pb push_back

#define ll long long

#define ft first

#define sd second

using namespace std;

const int N = 5050 ;

bool used[N];

ll z , r , w ;

ll p = -1 ;

int main(){

    ll n , m , k ;
    cin >> n >> m >> k ;
    ll j = k - n ;
    if( j < 0 ){
        cout<< n-k<<' '<<m;
    }
    else if(j==0){
        cout<<0<<' '<<m;
    }
    else{
            if(m-(k-n)>=0)
                cout<< 0 <<' ' << m-(k-n);
            else
                cout<<0<<' '<<0;
    }
}


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

using namespace std;

int main()
{
    string s;
    cin>>s;
    int j=0,i;
    for(i=0;i<=2;i++)
    {
        if(s[i]=='7')
            j++;
    }
    if(j==0)
        cout<<"No";
    else
        cout<<"Yes";
    return 0;
}




Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int N,M;
int A[SIZE];
ll K;

int main()
{
	cin >> N >> M;
	vector<int> res;
	for(int i=1;i*i<=M;i++){
		if(M%i == 0){
			res.push_back(i);
			if(i != M/i)res.push_back(M/i);
		}
	}
	sort(res.begin(),res.end());
	//rep(i,0,res.size())cout << res[i] << endl;

	rep(i,0,res.size()){
		if(res[i] >= N){
			cout << M/res[i] << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
def main():
    from collections import deque
    from operator import itemgetter
    from string import ascii_lowercase

    N = int(input())

    deq = deque(), deque()
    curr = 0
    deq[curr].append(('a', 0))  # (word,largest_char_index)
    for _ in range(N - 1):
        while deq[curr]:
            word, largest_char_index = deq[curr].popleft()
            for add_char_index in range(largest_char_index + 1 + 1):
                new_word = word + ascii_lowercase[add_char_index]
                deq[curr ^ 1].append(
                    (new_word, max(largest_char_index, add_char_index)))
        curr ^= 1

    print(*map(itemgetter(0), deq[curr]), sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 22504
#include<iostream>
#include<array>
#include<vector>
#include<algorithm>
bool comp0(const std::array<long long, 3>&arg1, const std::array<long long, 3>&arg2) { return +arg1[0] + arg1[1] + arg1[2] > +arg2[0] + arg2[1] + arg2[2]; }
bool comp1(const std::array<long long, 3>&arg1, const std::array<long long, 3>&arg2) { return +arg1[0] + arg1[1] - arg1[2] > +arg2[0] + arg2[1] - arg2[2]; }
bool comp2(const std::array<long long, 3>&arg1, const std::array<long long, 3>&arg2) { return +arg1[0] - arg1[1] + arg1[2] > +arg2[0] - arg2[1] + arg2[2]; }
bool comp3(const std::array<long long, 3>&arg1, const std::array<long long, 3>&arg2) { return +arg1[0] - arg1[1] - arg1[2] > +arg2[0] - arg2[1] - arg2[2]; }
bool comp4(const std::array<long long, 3>&arg1, const std::array<long long, 3>&arg2) { return -arg1[0] + arg1[1] + arg1[2] > -arg2[0] + arg2[1] + arg2[2]; }
bool comp5(const std::array<long long, 3>&arg1, const std::array<long long, 3>&arg2) { return -arg1[0] + arg1[1] - arg1[2] > -arg2[0] + arg2[1] - arg2[2]; }
bool comp6(const std::array<long long, 3>&arg1, const std::array<long long, 3>&arg2) { return -arg1[0] - arg1[1] + arg1[2] > -arg2[0] - arg2[1] + arg2[2]; }
bool comp7(const std::array<long long, 3>&arg1, const std::array<long long, 3>&arg2) { return -arg1[0] - arg1[1] - arg1[2] > -arg2[0] - arg2[1] - arg2[2]; }
int main()
{
	int n, m;
	std::cin >> n >> m;
	std::vector<std::array<long long, 3>>xyz(n);
	for (int i = 0; i < n; i++)
	{
		std::cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];
	}
	long long ans = 0;
	for (auto c : { comp0, comp1, comp2, comp3, comp4, comp5, comp6, comp7 })
	{
		std::sort(xyz.begin(), xyz.end(), c);
		long long sum[3] = { 0,0,0 };
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < 3; j++)
			{
				sum[j] += xyz[i][j];
			}
		}
		long long ans_tmp = std::abs(sum[0]) + std::abs(sum[1]) + std::abs(sum[2]);
		if (ans < ans_tmp)
		{
			ans = ans_tmp;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
MOD=10**9+7
import fractions
N=int(input())
if N==1:
  A=int(input())
  print(1)
  exit()

A=list(map(int, input().split()))
 
def f(a, b):
  return a*b//fractions.gcd(a, b)
 
if N>10:
  A1=A[:N//2]
  A2=A[N//2:]
  
  tmp1=f(A1[0], A1[1])
  n1=len(A1)
  for i in range(2, n1):
    tmp1=f(tmp1, A1[i])
    
  tmp2=f(A2[0], A2[1])
  n2=len(A2)
  for i in range(2, n2):
    tmp2=f(tmp2, A2[i])
    
  tmp=f(tmp1, tmp2)
  
  out1=sum([(tmp1//A1[i]) for i in range(n1)])
  out2=sum([(tmp2//A2[i]) for i in range(n2)])
  out1*=(tmp//tmp1)
  out2*=(tmp//tmp2)
  print((out1+out2)%MOD)
  exit()
  
tmp=f(A[0], A[1])
for i in range(2, N):
  tmp=f(tmp, A[i])
out=0
print(sum([(tmp//A[i])%MOD for i in range(N)])%MOD)

Measured memory_bytes: 70780
#include<stdio.h>

int main(void) {
    int N;
    scanf("%d", &N);
    for(int i=1; i<10; i++) {
        for(int j=1; j<10; j++) {
            if(N == i*j) {
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         998244353 
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
void solve(){   
    int n,len = 0,tot = 0,mul = 1;
    cin >> n;
    string ans = "";
    while(tot < n){
        mul *= 26;
        tot += mul;
        ++len;
    }
    FOR(i,0,len)ans += 'a';
    int rem = n-tot+mul;
    FOR(i,0,sz(ans)){
        int cur = 0;
        while(rem > pow(26,sz(ans)-i-1)){
            cur++;
            rem -= pow(26,sz(ans)-i-1);
        }
        ans[i] = (char)('a'+cur);
    }
    cout << ans << "\n";
}

signed main()
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){   
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


Measured memory_bytes: 4012
#include "bits/stdc++.h"

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>C(N); 
	vector<int>S(N); 
	vector<int>F(N);
	for (int i = 0;i<N-1;++i) {
		cin >>C[i]>>S[i]>>F[i];
	}
	vector<int>Ans(N); 
	for (int i = N-2; i >= 0; --i) {
		int time = C[i] + S[i];
		if (i== N-2) {
			Ans[i] = time;
			continue;
		}
		for (int j = i + 1;j<N-1;++j) {
			if (S[j]>=time) {
				Ans[i] = Ans[j];
				break;
			}
			else {
				if (0 == time % F[j]) {
					time = time + C[j];
				}
				else {
					time = time + C[j] - time % F[j]+F[j];
				}
				if (N-2 == j) {
					Ans[i] = time;
				}
			}
		}
	}	
	for (int i = 0; i < N; ++i) {
		cout << Ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3600
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

w,h,x,y = load_list()

print(w * h / 2, int(x+x == w and y+y == h))

Measured memory_bytes: 38256
A, B, K = map(int, input().split())

for i in range(K):
    if i % 2 == 0 and A > 0:
        if A % 2 == 1:
            A -= 1
        B += A // 2
        A //= 2
    
    if i % 2 == 1 and B > 0:
        if B % 2 == 1:
            B -= 1
        A += B // 2
        B //= 2

print(str(A) + " " + str(B))

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

using lli = long long int;
using ulli = unsigned long long int;

#define INF 999999999;

//#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

string N;

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

cin >> N;
if( ((N[0] == N[1]) && (N[1] == N[2])) || ((N[1] == N[2]) && (N[2] == N[3]))) cout << "Yes\n";
else cout << "No\n";

	return 0;
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int main(){
    string n;
    cin>>n;

    rep(i,3){
        if(n[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    
    return 0;

}
/*


*/


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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> tree(N, vector<int>());
    for(int i=0; i<N-1; i++){
        int a, b;  cin >> a >> b;
        a--;  b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    vector<int> c(N);
    for(int i=0; i<N; i++){
        cin >> c[i];
    }
    sort(c.begin(), c.end(), greater<int>());
    vector<int> ans(N);
    int root = 0;
    queue<pair<int,int>> que;
    que.push({0, -1});
    int idx = 0;
    while(!que.empty()){
        int now = que.front().first;
        int pre = que.front().second;
        que.pop();
        ans[now] = c[idx];
        idx++;
        for(int i=0; i<tree[now].size(); i++){
            int nxt = tree[now][i];
            if(nxt==pre) continue;
            que.push({nxt, now});
        }
    }

    cout << accumulate(ans.begin(), ans.end(), 0) - *max_element(ans.begin(), ans.end()) << endl;
    for(int i=0; i<N; i++){
        cout << ans[i] << " ";
    }cout << endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		final Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final long A = sc.nextLong();
		final long B = sc.nextLong();
		
		long[] xs = new long[N];
		for(int i = 0; i < N; i++){
			xs[i] = sc.nextLong();
		}
		
		long answer = 0;
		for(int i = 1; i < N; i++){
			final long diff = xs[i] - xs[i - 1];
			final long A_cost = A * diff;
			final long B_cost = B;
			
			answer += Math.min(A_cost, B_cost);
		}
		
		System.out.println(answer);
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (auto&& e : p) {
    cin >> e;
  }
  vector<double> cum(n + 1);
  for (int i = n; i--; ) {
    cum[i] = 0.5 * (1 + p[i]) + cum[i + 1];
  }
  double res = 0;
  for (int i = 0; i + k <= n; ++i) {
    res = max(res, cum[i] - cum[i + k]);
  }
  cout << res << '\n';
}


Measured memory_bytes: 2560
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
 
int main(void){
	string a, b, c;
	cin >> a >> b >> c;
	cout << char(a[0]+'A'-'a') << char(b[0]+'A'-'a') << char(c[0]+'A'-'a') << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]

def main():
    n, x = na()
    aa = na()

    aa.sort()
    #print(aa)

    c = 0
    for a in aa:
        x -= a
        if x >= 0:
            c += 1
            
    if x > 0:
        c -= 1
    print(c)


main()


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

using namespace std;

int n, m;
const int maxn = 1e5 + 100;
struct node
{
    int a, b;
    bool operator<(const node &S) const
    {
        if(a == S.a)
            return b < S.b;
        return a < S.a;
    }
} e[maxn];

int main()
{
    cin >> n >> m;
    for(int i = 0; i < m; i ++)
        cin >> e[i].a >> e[i].b;
    stable_sort(e, e + m);
    int st = e[0].a;
    int en = e[0].b;
    int ans = 0;
    for(int i = 1; i < m; i ++)
    {
        if (en <= e[i].a)
        {
            ans ++;
            st = e[i].a;
            en = e[i].b;
        }
        else
        {
            st = e[i].a;
            if(en > e[i].b)
                en = e[i].b;
        }

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


Measured memory_bytes: 1408
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static int N;
    static String S;
    static int Q;
    static int[] K;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        S = sc.next();
        Q = sc.nextInt();
        K = sc.nextIntArray(Q);

        long[] ans = solve();
        PrintWriter pw = new PrintWriter(System.out);
        for (long i : ans) {
            pw.println(i);
        }
        pw.flush();
    }

    static long[] solve() {
        int[] M = new int[N];
        int[] C = new int[N];
        long[] CM = new long[N];
        for (int i = 0; i < N; i++) {
            if( i != 0 ) {
                M[i] = M[i-1];
                C[i] = C[i-1];
                CM[i] = CM[i-1];
            }

            if( S.charAt(i) == 'M' ) {
                M[i]++;

            } else if ( S.charAt(i) == 'C' ) {
                CM[i] += M[i];
                C[i]++;
            }
        }

        long[] ans = new long[Q];
        for (int i = 0; i < N; i++) {
            if( S.charAt(i) == 'D' ) {
                for (int ki = 0; ki < Q; ki++) {
                    int k = K[ki];
                    int j = Math.min(N-1, i+k-1);
                    ans[ki] += (CM[j] - CM[i]) - (C[j] - C[i]) * (long)M[i];
                }
            }
        }
        return ans;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

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

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 48312
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define int long long int
#define repeat(n) for (int i = 0; i < n; ++i)
#define repeat2(n) for (int j = 0; j < n; ++j)
#define all(x) (x).begin(), (x).end()

#define PRIME (1'000'000'007)
#define MAX_SIZE (100001)

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

    int ans = 0;
    for (int i = k; i <= n + 1; ++i) {
        int min = (i + 1) * i / 2;
        int max = (2 * n - i + 3) * i / 2;
        ans = (ans + max - min + 1) % PRIME;
    }

    cout << ans;
    
    return 0;
}

Measured memory_bytes: 3140
#include<stdio.h>
#include<string.h>
int MAX(int a,int b){return a<b?b:a;}
//int P[1010],L[1010],R[1010],H[1010],C=1;
int P[3][1010],H[1010],C=1;
//int hyouka(int i,int x){return N[i]<=x?N[i]<x?-1:0:1;}
char N[1010][110];
int hyouka(int i,char *s){return strcmp(s,N[i]);}
int h(int a){return H[P[2][a]]-H[P[1][a]];}
void rotr(int a){//printf("r %d\n",a);
  int b=P[1][a],r=P[0][a];
  P[1][r]==a?(P[1][r]=b):(P[2][r]=b);
  if(P[2][b])P[0][P[2][b]]=a;
  P[1][a]=P[2][b];
  P[2][b]=P[0][b];
  P[0][b]=P[0][a];
  P[0][a]=b;
  H[a]=MAX(H[P[1][a]],H[P[2][a]])+1;
  H[b]=MAX(H[P[1][b]],H[P[1][b]])+1;
}
void rotl(int a){//printf("l %d\n",a);
  int b=P[2][a],r=P[0][a];
  P[1][r]==a?(P[1][r]=b):(P[2][r]=b);
  if(P[1][b])P[0][P[1][b]]=a;
  P[2][a]=P[1][b];
  P[1][b]=P[0][b];
  P[0][b]=P[0][a];
  P[0][a]=b;
  H[a]=MAX(H[P[1][a]],H[P[2][a]])+1;
  H[b]=MAX(H[P[1][b]],H[P[2][b]])+1;
}
int mfind(char *x){
  int i,j,r,n;
  if(C==1){
    P[1][0]=C;
    //N[C]=x;
    strcpy(N[C],x);
    H[C]=1;
    P[0][C++]=0;
    return 1;
  }
  for(i=P[1][0];r=hyouka(i,x);i=n){//printf("%d %s\n",r,x);
    if(r<0){
      if(P[1][i]==0){
	P[1][i]=C;
	P[0][C]=i;
	H[i]=MAX(2,H[i]);
	//N[C]=x;
	strcpy(N[C],x);
	H[C]=1;
	C++;
      }
      n=P[1][i];
    }
    else{
      if(P[2][i]==0){
	P[2][i]=C;
	P[0][C]=i;
	H[i]=MAX(2,H[i]);
	strcpy(N[C],x);
	//N[C]=x;
	H[C]=1;
	C++;
      }
      n=P[2][i];
    }
  }//printf("%d\n",i);
  //for(j=0;j<C;j++){
  // printf(":%d %d %d %d %s\n",P[0][j],P[1][j],P[2][j],H[j],N[j]);
  //}
  j=P[0][i];
  while(1){
    H[j]=MAX(H[P[1][j]],H[P[2][j]])+1;
    if(h(j)<-1){
      if(h(P[1][j])>0)rotl(P[1][j]);
      rotr(j);
      break;
    }
    if(h(j)>1){
      if(h(P[2][j])<0)rotr(P[2][j]);
      rotl(j);
      break;
    }
    if(h(j)==0)break;
    j=P[0][j];
    if(j==0)break;
  }//printf("%d\n",i);
  return i;
}      
void prim(int n){
  int i;
  if(P[1][n])prim(P[1][n]);
  for(i=0;i<H[n];i++)printf("  ");
  printf("%s\n",N[n]);
  if(P[2][n])prim(P[2][n]);
}
/*int main(){
  int n,i;
  //for(i=0;i<100;i++)H[i]=-1;
  char s[10];
  while(~scanf("%s",s)){
    printf("%d\n",mfind(s));
    for(i=0;i<C;i++){
      printf("%d %d %d %d %s\n",P[0][i],P[1][i],P[2][i],H[i],N[i]);
    }
    prim(P[1][0]);printf("end\n");
  }
  return 0;
}/*/
int main(){
  int i,l,max=0,mj=1,r,a[1010]={};
  char *c,*mi,s[1020];
  fgets(s,1010,stdin);
  mi=strtok(s," \n");
  a[mj=mfind(mi)]++;
  max=strlen(mi);
  // printf("%s\n",mi);
  while(c=strtok(NULL," \n")){
    //printf("%s\n",c);
    a[r=mfind(c)]++;
    //printf("%d\n",r);
    l=strlen(c);//printf("%s %d\n",mi,l);
    if(max<l){
      max=l;
      strcpy(mi,c);
    }//printf("a\n");
    if(a[r]>a[mj])mj=r;//printf("a\n");
  }
  //printf("%s %d\n",mi,mj);
  printf("%s %s\n",N[mj],mi);
  return 0;
  }//*/

Measured memory_bytes: 564
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let s = read_as_string();

    for _ in 0..s.len(){
        print!("x");
    }
    println!();
}


Measured memory_bytes: 4352
package main

import (
	"fmt"
)

func main() {
	var n int

	fmt.Scan(&n)
	a := make([]int, n)
	dic := make(map[int]int, 0)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		if _, exist := dic[a[i]]; exist {
			fmt.Println("NO")
			return
		}
		dic[a[i]]++
	}

	fmt.Println("YES")
}


Measured memory_bytes: 16896
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	ll n,k,x,y;
	ll ans=0;
	
	cin>>n>>k>>x>>y;
	ans=min(k,n)*x+max(n-k,0LL)*y;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

		int A = scan.nextInt();
		int B = scan.nextInt();

		if (A <= 8 && B <= 8){
			System.out.println("Yay!");
		}else {
			System.out.println(":(");
		}

	}
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )
#define SORT(x) sort(x.begin(), x.end())

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<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; }

int a[10];

bool fun(int n) {
    while (n) {
        if (a[n % 10]) return false;
        n /= 10;
    }
    return true;
}

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

    int N, K, x; cin >> N >> K;
    rep(i, K){
        cin >> x;
        a[x] = 1;
    }
    REP(i, N, 10 * N) {
        if(fun(i)){
            COUT(i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256