akhauriyash/Code-Regression huggingface dataset:
/*****************************************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

#define   offcin        ios::sync_with_stdio(false)
#define   DEBUG         freopen("#.txt", "r", stdin)
#define   sigma_size    26
#define   lson          l,m,v<<1
#define   rson          m+1,r,v<<1|1
#define   slch          v<<1
#define   srch          v<<1|1
#define   ll            long long
#define   ull           unsigned long long
#define   lowbit(x)     (x&-x)

const int    INF    = 0x3f3f3f3f;
const ll     INFF   = 1e18;
const double pi     = acos(-1.0);
const double inf    = 1e18;
const double eps    = 1e-9;
const ll     mod    = 1e9+7;
const int    maxmat = 10;
const ull    BASE   = 133333331;

/*****************************************************/
inline void RI(int &x) {
      char c;
      while((c=getchar())<'0' || c>'9');
      x=c-'0';
      while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0';
}
inline ll bits(ll x) {
      return !x ? x : bits(x - lowbit(x)) + 1;
}
/*****************************************************/

const int maxn = 1e5 + 5;

std::vector<int> G[maxn];
int c[maxn];
bool used[maxn];
int N, M;

bool bipartitite(int u) {
    bool ok = true;
    for (int v : G[u]) {
        if (c[u] == c[v]) ok = false;
        if (!c[v]) {
            c[v] = 3 - c[u];
            if (!bipartitite(v)) ok = false;
        }
    }
    return ok;
}

int main(int argc, char const *argv[]) {
    cin>>N>>M;

    memset(c, 0, sizeof(c));
    memset(used, false, sizeof(used));
    for (int i = 0; i < M; i ++) {
        int u, v;
        scanf("%d%d", &u, &v);
        used[u] = used[v] = true;
        G[u].push_back(v);
        G[v].push_back(u);
    }


    int I = 0, B = 0, P = 0;

    for (int i = 1; i <= N; i ++) {
        if (!used[i]) I ++;
        else if (!c[i]) {
            c[i] = 1;
            if (bipartitite(i)) B ++;
            else P ++;
        }
    }

    long long ans = 0;
    ans += (ll)I * I + 2ll * I * (N - I);
    ans += (ll)P * P + 2ll * P * B + 2ll * B * B;

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

Measured memory_bytes: 10112
function Main(arg) {
  var n = arg.split("\n")[0];

  if (n[2] == n[3] && n[4] == n[5]) {
    console.log("Yes");
  }
  else {
    console.log("No");
    
  }

  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22080
//y17-6
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while(true)

int N;
int d[300002];
int dp_l[300002];
int dp_r[300002];

bool move_l(int now){
    if(dp_l[now] == 0) return false;
    if(dp_l[now] == 1) return true;

    if(now == N-1) return true;
    if(now > N-1) return false;

    for(int i=1; i<=d[now]/10; i++){
        if(move_l(now+i)){
            dp_l[now] = 1;
            return true;
        }
    }
    dp_l[now] = 0;
    return false;
}

bool move_r(int now){
    if(dp_r[now] == 0) return false;
    if(dp_r[now] == 1) return true;

    if(now == 0) return true;
    if(now < 0) return false;

    for(int i=1; i<=d[now]/10; i++){
        if(move_r(now-i)){
            dp_r[now] = 1;
            return true;
        }
    }
    dp_r[now] = 0;
    return false;
}

int main(){
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> d[i];
        dp_l[i] = -1;
        dp_r[i] = -1;
        if(d[i] < 10){
            dp_l[i] = 0;
            dp_r[i] = 0;
        }
    }
    
    if(!move_l(0)){
        cout << "no" << endl;
        return 0;
    }
    if(!move_r(N-1)){
        cout << "no" << endl;
        return 0;
    }

    cout << "yes" << endl;
}



Measured memory_bytes: 20664
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
        int D = in.nextInt()*2+1;
        int count = 0;
        
      while(N>0){
        N = N-D;
        count++;
      }
      
      System.out.print(count);
	}
}

Measured memory_bytes: 21844
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define epsilon 1e-9
#define INF 5e18
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int main(){
    //freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    int a, b; cin >> a >> b;
    if(a >= b) cout << '1';
    cout << "0\n";
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


ll ans = LINF;
int n=0,a,b,c;
int l[2000];

void solve(int sa, int ga, int sb, int gb, int sc, int gc, int N) {
  if(N == n) {
    if(ga == -1 || gb == -1 || gc == -1) {
      return;
    }
    ans = min(ans, (ll)(abs(sa-a) + ga * 10 + abs(sb-b) + gb * 10 + abs(sc-c) + gc * 10));
    return;
  }
  solve(sa + l[N], ga + 1, sb, gb, sc, gc, N+1);
  solve(sa, ga, sb + l[N], gb + 1, sc, gc, N+1);
  solve(sa, ga, sb, gb, sc + l[N], gc + 1, N+1);
  solve(sa, ga, sb, gb, sc, gc, N+1);
}

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

  cin>>n>>a>>b>>c;
  rep(i,n) cin>>l[i];
  solve(0,-1,0,-1,0,-1,0);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////


int main() {
	char c;
	cin >> c;

	if (c >= 'A' && c <= 'Z') { cout << "A" << endl; }
	else { cout << "a" << endl; }
	
}


Measured memory_bytes: 3612
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define let const auto
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'

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

   char s[10];
   int cnt[128] = {};

   cin >> s;
   rep(i, 3) {
      cnt[ s[i] ]++;
   }

   bool f = cnt['a'] && cnt['b'] && cnt['c'];

   outl( f? "Yes" : "No" );
}



Measured memory_bytes: 764
#include<cstdio>
#include<algorithm>

int main(){
    int a[3];
    for(int i = 0; i < 3; i++) scanf("%d",&a[i]);
    std::sort(a,a+3);
    int d0 = a[2]-a[0], d1 = a[2]-a[1];
    int ans = 0;
    if((d1-d0)%2==0) {
        ans = (d0+d1)/2;
    }
    else{
        ans = (d0+d1+1)/2+1;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a>=c)cout<<"0"<<endl;
	else if(a+b<c)cout<<"NA"<<endl;
	else cout<<c-a<<endl;
    return 0;
    }


Measured memory_bytes: 3100
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
 
 
public class Main {

	static long MOD = 1_000_000_007;
	static int INF = 1_000_000_007;
	//二項係数関連ここから-----
	static boolean isPreprocessing = false;	//二項係数を計算するための前処理を行っているかどうかのフラグ
	static int MAX = 260;				//MAXまで階乗やそれらの逆元のテーブルを保持する。
	static long[] fac;	//fac[i] := i! % MOD
	static long[] inv;	//inv[i] := mod. MODにおける i の逆元
	static long[] finv;	//finv[i] := mod. MODにおける i! の逆元(invの累積"積")
	//二項係数関連おわり------
	
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		//char[] A = sc.next().toCharArray();
		
		int N = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int ans = N/(2*D+1);
		if(N%(2*D+1)!=0)ans++;
		System.out.println(ans);
		
		
	}
	
	//aとbの最小公倍数を返す
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (c/b);
	}
	
	//二項係数用の前処理
	static void COMinit(){
		//二項係数演算用前処理
		fac = new long[MAX+1];
		fac[0] = 1L;
		fac[1] = 1L;
		inv = new long[MAX+1];
		inv[1] = 1L;
		finv = new long[MAX+1];
		finv[0] = 1L;
		finv[1] = 1L;
		for(int i=2;i<MAX;i++){
			fac[i] = fac[i-1] * i % MOD;
			inv[i] = MOD - inv[(int)(MOD%i)] * (MOD/i) % MOD;
			finv[i] = finv[i-1] * inv[i] % MOD;
		}
		isPreprocessing = true;
	}
	
	//二項係数i_C_jをMODで割った余りを返す
	static long COM(int i, int j){
		if(i<j)return 0;
		if(i<0 || j<0)return 0;
		if(!isPreprocessing)COMinit();
		return fac[i] * (finv[j] * finv[i-j] % MOD) % MOD;
	}
	
}



Measured memory_bytes: 21844
# -*- coding: utf-8 -*-

import sys
import os
import pprint
from queue import Queue

"""Diameter of Tree"""

#fd = os.open('GRL_5_A.txt', os.O_RDONLY)
#os.dup2(fd, sys.stdin.fileno())


class Edge:
    def __init__(self, to, weight):
        self.to = to
        self.weight = weight

    def __str__(self):
        return '{} {}'.format(self.to, self.weight)


N = int(input())
G = [[] for i in range(N)]
for i in range(N-1):
    start, end, weight = list(map(int, input().split()))

    # ??????
    edge = Edge(end, weight)
    G[start].append(edge)

    # ??°???
    edge = Edge(start, weight)
    G[end].append(edge)


# ???i??????1????????????????±???????
def bfs(index):
    d = [float('inf')] * N
    visited = [False] * N
    queue = Queue()
    queue.put(index)
    d[index] = 0

    while not queue.empty():
        u = queue.get()
        visited[u] = True

        for edge in G[u]:
            if d[u] + edge.weight < d[edge.to]:
                d[edge.to] = d[u] + edge.weight
            if not visited[edge.to]:
                queue.put(edge.to)

    max_i = 0
    max_d = 0
    for i in range(N):
        if max_d < d[i]:
            max_i = i
            max_d = d[i]
    #print('farthest i {} d {}'.format(max_i, max_d))
    return max_i, max_d

# ?§???????????????§????????????????????????1???????????????????????????
temp_i, temp_d = bfs(0)
# ?¬????????????????1???????????????????????????
temp_i, temp_d = bfs(temp_i)

# diameter
print(temp_d)

Measured memory_bytes: 68928
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
#define int long long
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);
#define f first
#define s second

const int maxn = 200010;

int32_t main() {
	int k; cin >> k;
	int cur = 7;
	int co = 1;
	cur %= k;
	
	while (cur != 0) {
		cur %= k;
		cur = (cur*10) % k;
		cur = (cur + 7) % k;
		
		co++;
		if (co == 10000000) break;
	}
	if (co == 10000000) cout << "-1";
	else cout << co;
}


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

int main(){
	
	while(1){
	int N,k = 0,i,a=0,b=0;
		cin>>N;
		
		if(N==0)
			break;
		
		for(i = 0;i<N;i++){
			cin>>k;
			if(k >= 2)
			a = 1;
			if(k == 0)
			b++;
		}
		if(a == 0)
			cout<<"NA"<<endl;
		
		else
			cout<<N - b + 1<<endl;
		}
	return 0;
}		

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;

    int d;
    if(a==b&&b==c)d=1;
    else if(a==b&&b!=c || a==c&&a!=b || b==c&&a!=b)d=2;
    else d=3;
    cout<<d<<endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int> vec (N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  int count = 0;
  for(int i = 0; i < N; i++){
    if(vec.at(i) % 2 == 1){
      if((i + 1) % 2 == 1){
        count++;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3604
#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    unsigned long long int a[n];
    int loop1;
    int ki=0;
    for(loop1=0;loop1<n;loop1++){
        scanf("%lld",&a[loop1]);
        if(a[loop1]%2==1)ki++;
    }
    if(ki%2==0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool is_prime[4000011];
void sieve(ll n){
    ll p=0;
    for(ll i=0; i<= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(ll i=2; i<=n; i++){
        if(is_prime[i]){
            for(ll j = 2*i; j <= n; j+= i)
                is_prime[j] = false;
        }
    }
}
map<ll, ll> prime_fact(long long n){
    map<ll, ll> pfact;
    while(n % 2 == 0){
        if(!pfact.count(2)) pfact[2]=1;
        else pfact.at(2)++;
        n /=2;
    }
    for(ll p = 3; p <= sqrt(n); p+=2){
        while( n % p == 0){
            if(!pfact.count(p)) pfact[p] = 1;
            else pfact.at(p)++;
            n /= p;
        }
        if(n == 1) break;
    }
    if (n > 2)
        pfact[n] = 1;
    return pfact;
}

void solve(long long A, long long B){
    ll G = __gcd(A, B);

    auto pfact = prime_fact(G);
    
    cout << pfact.size()+1 << endl;
}

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


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int Q,H,S,D,N;
    public void Solve()
    {
        var line = Console.ReadLine().Split();
        Q = int.Parse(line[0]);
        H = int.Parse(line[1]);
        S = int.Parse(line[2]);
        D = int.Parse(line[3]);
        N = int.Parse(Console.ReadLine());
        if(Q*2<H)
        {
            H=Q*2;
        }
        if(H*2<S)
        {
            S=H*2;
        }
        long anser = 0;
        if(S*2<D)
        {
            anser=(long)S*N;
        }
        else
        {
            if(N%2==1)
            {
                anser=S;
            }
            anser+=(long)D*(N/2);
        }
        Console.WriteLine(anser);
    }
}

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

#define maxn
#define FOR(i, l, r) for (int i=l; i<=(int)r; ++i)
#define FORD(i, r, l) for (int i=r; i>=l; --i)
#define REP(i, r) for (int i=0; i<(int)r; ++i)
#define REPD(i, r) for (int i=(int)r-1; i>=0; --i)
#define fi first
#define se second
#define mk make_pair
#define nil NULL
#define y0 y902
#define y1 y232
#define x0 x92
#define x1 x899
#define next asdfa
#define sz size
#define Debug(X) {cerr << #X << " = " << X << '\n';}
#define PR(A, n) {cerr << #A << " = "; FOR(i, 1, n) cerr << A[i] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; REP(i, n) cerr << A[i] << ' '; cerr << '\n';}
typedef long long ll;
typedef double db;
typedef pair<db, db> dd;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int inf = 1e9;
template<class T> int getbit(T x, int pos) {return (x>>(pos-1)) & 1;}
template<class T> void turn_on(T &x, int pos) {x = x | ((T)1<<(pos-1));}
template<class T> void turn_off(T &x, int pos) {x = x & ~((T)1<<(pos-1));}
template<class T> T sqr(T a) {return a*a;}

string s, s2;

int solve(string s, char x) {
    int cnt = 0;
    while (true) {
        bool ok = true;
        REP(i, s.sz()) {
            ok = ok && (s[i]==x);
        }
        if (ok) return cnt;
        ++cnt;
        s2.clear();
        FOR(i, 0, s.sz()-2) {
            if (s[i]==x) s2 += x;
            else s2 += s[i+1];
        }
        s = s2;
    }
}

int main() {
    //freopen("shrinking.inp", "r", stdin);
    //freopen("", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> s;
    Debug(s);
    int res = inf;
    FOR(i, 0, 25)
        res = min(res, solve(s, i+'a'));
    cout << res;
}



Measured memory_bytes: 256
#include <stdio.h>

int left=0,right=0,n;
int A[100005];

int Binary(int key){
	left=0;
	right=n;
	int mid;
	while(left<right){
		mid=(left+right)/2;
		if(key==A[mid]) return 1;
	    if(key<A[mid]){
			right=mid;
		}else {
			left=mid+1;
		}
	}
	return 0;
}


int main(){
	int sum=0,i=0,q,k;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&k);
		if(Binary(k))
		sum++;
	}
	
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 980
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  int n,p;
  while(cin>>n>>p, n+p){
    vector<int> v(n);
    int st = p;
    int ans;
    while(true){
      REP(i,n){
	if(st == 0){
	  st += v[i];
	  v[i] = 0;
	}else{
	  st--;
	  v[i]++;
	  if(v[i] == p){
	    ans = i;
	    goto end;
	  }
	}
      }
    }
  end:
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 908
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
k=0#満足度
for i in range(0,n):
    k+=b[a[i]-1]
    if i!=0:
        if a[i-1]+1==a[i]:
            k+=c[a[i-1]-1]
print(k)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, cnt=0;
    string s;
    cin >> n >> s;
    sort(s.begin(), s.end());
    for(int i=0; i<n; i+=2){
        if(s[i]==s[i+1]) ++cnt;
    }
    if(cnt==n/2 && n%2==0){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
    return 0;
}


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

using namespace std;

int main() {
	int n;

	cin >> n;
	vector<int> a(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[a[i]] == i) {
			ans++;
		}
	}
	ans /= 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline

N = int(input())
TA = []

for _ in range(N):
    TA.append([int(x) for x in input().split()])

x, y = TA[0]

for i in range(1, N):
    X, Y = TA[i]
    if X < x or Y < y:
        mul = max(x // X + (x % X != 0), y // Y + (y % Y != 0))
        x, y = X * mul, Y * mul
    else:
        x, y = X, Y
    # print(x, y)

print(x + y)




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


int main() {
    int n;
    string s;
    cin >> n >> s;
    for (int i = 0; i < s.size(); i++) {
        char c = (((s.at(i) - 'A') + n) % 26) + 'A';
        cout << c;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, K;
	long long A[100001];
	scanf("%d", &K);
	for (i = 1; i <= K; i++) scanf("%lld", &(A[i]));
	
	long long l[2] = {2}, r[2] = {2};
	for (i = K; i >= 1; i--) {
		l[1] = (l[0] + A[i] - 1) / A[i];
		r[1] = r[0] / A[i];
		if (l[1] > r[1]) break;
		l[0] = l[1] * A[i];
		r[0] = r[1] * A[i] + (A[i] - 1);
	}
	
	if (i >= 1) printf("-1\n");
	else printf("%lld %lld\n", l[0], r[0]);
	fflush(stdout);
	return 0;
}

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

int main() {
  string S,T;
  int N,answer=0,i;
  
  cin >> N;

  int *B = new int[N];

  for ( i = 0; i < N-1; i++)
  {
    cin >> B[i];
  }

  answer+=B[0];

  for ( i = 1; i < N-1; i++)
  {
    answer+=min(B[i],B[i-1]);
  }
  answer+=B[N-2];
  
  cout << answer << endl;
}

Measured memory_bytes: 256
class Unionfind():
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        while(self.table[x] >= 0):
            x = self.table[x]
        return x

    def union(self, x, y):
        xp = self.find(x)
        yp = self.find(y)
        if xp != yp:
            if self.table[xp] <= self.table[yp]:
                self.table[xp] += self.table[yp]
                self.table[yp] = xp
            else:
                self.table[yp] += self.table[xp]
                self.table[xp] = yp

n, m = map(int, input().split())
clue = Unionfind(n)
for _ in range(m):
    x, y, _ = map(int, input().split())
    clue.union(x-1, y-1)
roots = set()
for i in range(n):
    roots.add(clue.find(i))
print(len(roots))

Measured memory_bytes: 55968
import sys

n = int(input())
a_lst = [int(x) for x in input().split()]

dic = {}

for i in range(1, n + 1, 2):
    j = n - i
    dic[j] = 1 if j == 0 else 2

for i in a_lst:
    if i not in dic:
        print(0)
        sys.exit()

    dic[i] -= 1

    if dic[i] < 0:
        print(0)
        sys.exit()

print(pow(2, n // 2) % (pow(10, 9) + 7))

Measured memory_bytes: 14692
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

// initial: random
// annealing: no
// 77477817

// initial: max s
// annealing: no
// 93907681

// initial: max s
// annealing:         if (diff >= 0 || (rng()%10 < 1 && diff > -1000)) {

class AAtCoderContestScheduling {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;

      int d; cin >> d;
      vector<int> c(26);
      rep(i, 26) {
        cin >> c[i];
      }
      vector<vector<ll>> s(d, vector<ll>(26));
      rep(i, d) rep(j, 26) {
        cin >> s[i][j];
      }
      ll ret = 0;
      set<int> last[26];
      rep(i, 26) {
        last[i].insert(0);
        last[i].insert(d+1);
      }
      vector<ll> last2(26);
      vector<int> contests(d);
      rep(i, d) {
        ll ma = -1;
        int t = -1;
        rep(j, 26) {
          if (chmax(ma, s[i][j])) t = j;
        }

        contests[i] = t;
        ret += s[i][t];
        last[t].insert(i+1);
        last2[t] = i+1;
        rep(j, 26) {
          ret -= c[j]*(i+1-last2[j]);
        }
      }

      auto start = clock();

      while(clock() - start < 1.9 * CLOCKS_PER_SEC) {
        int day = rng()%d;
        int q = rng()%26;

        int before = contests[day];

        ll diff = 0;
        diff += s[day][q];
        diff -= s[day][before];

        day++;
        last[before].erase(day);
        auto it = last[before].upper_bound(day);
        int right = (*it);
        it--;
        int left = (*it);
        diff -= c[before]*(day-left)*(right-day);

        it = last[q].upper_bound(day);
        right = (*it);
        it--;
        left = (*it);
        diff += c[q]*(day-left)*(right-day);
        //debug(day, q, diff);

        if (diff >= 0 || (rng()%10 < 1 && diff > -1000)) {
          last[q].insert(day);
          contests[day-1] = q;
          ret += diff;
        } else {
          last[before].insert(day);
        }
      }

      rep(i, d) {
        cout << contests[i]+1 << '\n';
      }
      debug(ret);
    }
};

signed main() {
  AAtCoderContestScheduling solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3796
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long h, i, j, k, ct, ans;

	cin >> h;
	ct = 1;
	ans = 0;

	while (h > 0) {
		if (h == 1) {
			h = 0;
			ans += ct;
		}
		else {
			ans += ct;
			ct *= 2;
			h /= 2;
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <unordered_set>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <climits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>
#include <atomic>
#include <thread>

using namespace std;
typedef long long ll;
#define ln '\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define drep(i,n) int i = 0;for(;i<(n);++i)
#define FOR(i,s,e) for(int i=s;i<=(e);++i)
#define DFOR(i,s,e) int i = s;for(;i<=(e);++i)
#define FORR(i,s,e) for(int i=s;i>=(e);--i)
#define DFORR(i,s,e) int i = s;for(;i>=(e);--i)
#define fore(a, x) for(auto& a : x)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ft first
#define sd second
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define Fill(a,b) memset(a,b,sizeof(a))
template<typename T1, typename T2> bool Max(T1& a, T2 b) { return a<b ? a = b, 1 : 0; }
template<typename T1, typename T2> bool Min(T1& a, T2 b) { return a>b ? a = b, 1 : 0; }



const int N = 100001, inf = 10000;



void solve() {
  int n, m;
  cin >> n >> m;
  int t = m * 1900 + (n - m) * 100;
  while (m--)t *= 2;
  cout << t << ln;
  
}


void init() {
  
}

int main(void) {
  ios::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
  //freopen("C:\\Users\\LENOVO\\Documents\\Visual Studio 2015\\Projects\\Test\\Input\\in.in", "r", stdin);

  init();
  int TC = 1;
#if 0
  cin >> TC; cin.get();
#endif
  FOR(TI, 1, TC) {
    //cout << "Case #" << TI << ": ";
    solve();
  }
  
  
  return 0;
}



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

const int maxn = 100005;

int n, mx = -1, mn = maxn;
int a[maxn], cnt[maxn];

signed main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		++cnt[a[i]];
		mn = min(mn, a[i]), mx = max(mx, a[i]);
	}
	if (mx - mn > 1)
		printf("No\n");
	else if (mx == mn) {
		if (mx == n - 1 || 2 * mx <= n)
			printf("Yes\n");
		else
			printf("No\n");
	}
	else {
		if (cnt[mn] + 1 <= mx && mx <= cnt[mn] + cnt[mx] / 2)
			printf("Yes\n");
		else
			printf("No\n");
	}
}


Measured memory_bytes: 4168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string alp = "abcdefghijklmnopqrstuvwxyz";
  string str;
  cin >> str;
  int N = str.size();
  rep(i, N) {
    rep(j, 26) {
      if(str.at(i) == alp.at(j)) {
        alp.at(j) = '0';
      }
    }
  }
  int c = 0;
  rep(i, 26) {
    if(!(alp.at(i) == '0')) {
      cout << alp.at(i) << endl;
      break;
    }
    else {
      c++;
    }
    if(c == 26) {
      cout << "None" << endl;
    }
  }
}


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

ans = [0] * (10 ** 5 + 1)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            ans[x * x + y * y + z * z + x * y + y * z + z * x] += 1

for i in range(1, n + 1):
    print(ans[i])

Measured memory_bytes: 9764
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int[] x = new int[M];
        int[] dif = new int[M-1];
        for(int i= 0; i<M; i++) {
            x[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(x);
        for(int i= 0; i<M-1; i++) {
            dif[i] = x[i+1]-x[i];
        }
        Arrays.sort(dif);
        int ans = 0;
        for(int i=0; i<M-N; i++) {
            ans += dif[i];
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 49308
#include<bits/stdc++.h>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
using namespace std;

#define ll long long
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)

const ll MOD = 1e9+7;

// Combinationの使い方
// vector<vector<ll>> v(N+1, vector<ll>(N+1, 0));
// comb(v);
void comb(vector<vector<ll>> &v){
    for(int i = 0; i < v.size(); i++){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(int k = 1; k < v.size(); k++){
        for(int j = 1; j < k; j++){
            v[k][j] = (v[k-1][j-1] + v[k-1][j]);
            //余りを求める問題は毎回計算ごとにやる
            // v[k][j] = (v[k-1][j-1] + v[k-1][j]) % MOD;
        }
    }
}

// Union Find
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

// 1 << 3 : int "3" change to bit "100"
// rep(pattern, 1 << N) if (pattern & (1 << x)) cnt++

vector<int> D(10+1, -1);

int check(int N){
    while(N!=0){
        rep(i,D.size()){
            if(D[i] == N % 10) return 1;
        }
        N /= 10;
    }
    return 0;
}

int main(){
    int N,K;
    cin >> N >> K;
    rep(i,K) cin >> D[i];

    while(check(N)) N++;
    cout << N << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict

NIL = -1
n = int(input())
pre = list(map(int, sys.stdin.readline().split()))
ino = list(map(int, sys.stdin.readline().split()))
post = []

pos = 0

def rec(l, r,):
    global pos # posはglobal変数だと明示する
    if l >= r:
        return
    root = pre[pos]
    pos += 1
    m = ino.index(root)
    rec(l, m)
    rec(m+1, r)
    post.append(str(root))

pos = 0

rec(0, n)
print(' '.join(post))


Measured memory_bytes: 5996
n,m = map(int,input().split())
aa = list(map(int,input().split()))
 
bb = [abs(a-m) for a in aa]


def gcd(a,b):
    while b:
        a, b = b, a % b
    return a

    
ans = bb[0]
if len(aa) == 1:
    print(abs(aa[0]-m))
else:
    for b in bb:
        ans = gcd(ans,b)
    print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
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; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int X;
    cin >> X;
    int now = X;
    int ans = 1;
    while (now != 0) {
        ans++;
        now += X;
        now %= 360;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
use std::io::Read;

const MOD: usize = 1_000_000_007;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();

    let blue = k;
    let red = n - k;

    let mut result = String::new();

    let mc = mod_comb::ModComb::init(MOD, 5000);
    for i in 1..=k {
        if red + 1 < i {
            result.push_str("0\n");
            continue;
        }
        let b = mc.calc(blue - 1, i - 1);
        let r = mc.calc(red + 1, red + 1 - i);
        result.push_str(&format!("{}\n", (b * r) % MOD));
    }

    result.trim().to_string()
}

mod mod_comb {
    pub struct ModComb {
        modulo: usize,
        fac: Vec<usize>,
        finv: Vec<usize>,
    }

    impl ModComb {
        pub fn init(modulo: usize, max: usize) -> ModComb {
            let mut fac = vec![1; max];
            let mut finv = vec![1; max];
            let mut inv = vec![1; max];
            for i in 2..max {
                fac[i] = fac[i - 1] * i % modulo;
                inv[i] = modulo - inv[modulo % i] * (modulo / i) % modulo;
                finv[i] = finv[i - 1] * inv[i] % modulo;
            }
            ModComb {
                modulo,
                fac,
                finv,
            }
        }

        pub fn calc(&self, n: usize, k: usize) -> usize {
            if n < k {
                return 0;
            }
            self.fac[n] * (self.finv[k] * self.finv[n - k] % self.modulo) % self.modulo
        }
    }
}


Measured memory_bytes: 2232
/*
─────────▄▄▄▄▄▄▄▄▄▄▄▄─────────
─────▄▄▀▀░░░░░░░░░░░░▀▀▄▄─────
───▄▀░░░░░░░░░░░░░░░░░░░░▀▄───
──█░░░░░▄▄▄▄▄░░░░▄▄▄▄▄░░░░░█──
─█░░░░░██░█░██▄▄██░█░██░░░░░█─
█░░░░░░░▀▀▀▀▀░░░░▀▀▀▀▀░░░░░░░█
█░░░░▄▄▄░░░░░░░░░░░░░░▄▄▄░░░░█
█░░░░██▀█▄▄▄▄▄▄▄▄▄▄▄▄██▀█░░░░█
─█░░░▀██▄████████▄▄▄▄██▄▀░░░█─
──█░░░░▀██▀▀▀▀████████▀░░░░█──
───▀▄░░░░▀▄▄▄▄██████▀░░░░▄▀───
─────▀▀▄▄░░░░░░░░░░░░▄▄▀▀─────
─────────▀▀▀▀▀▀▀▀▀▀▀▀─────────
*/
#include <bits/stdc++.h>

using namespace std;

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

	string s, t;
	cin >> s >> t;
	vector<set<int>> pos(26);
	for (int i = 0; i < s.size(); ++i) {
		pos[s[i] - 'a'].insert(i + 1);
	}
	int ptr = 0;
	long long ans = 0;
	for (char c : t) {
		c -= 'a';
		if (pos[c].empty()) {
			ans = -1;
			break;
		}
		auto it = pos[c].upper_bound(ptr);
		if (it == pos[c].end()) {
			ans += s.size() - ptr;
			ptr = 0;
			it = pos[c].upper_bound(ptr);
		}
		ans += *it - ptr;
		ptr = *it;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 5200
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

int main()
{
    int n;
    while(cin >> n && n) {

        vector<string> v;

        vector<pair<string,string> > res;
        rep(i,n) {
            string s,t;
            cin >> s >> t;
            res.push_back(make_pair(s,t));
        }
        sort(res.begin(),res.end());
        
        v.push_back(res[0].second);

        REP(i,1,n) {
            string s = res[i].first;
            string t = res[i].second;

            bool flag = true;

            rep(j,v.size()) {
                if(v[j] <= s) {
                    v[j] = t;
                    flag = false;
                    break;
                }
            }

            if(flag) v.push_back(t);
        }

        cout << v.size() << endl;
    }

    return 0;
}

Measured memory_bytes: 2400
// Copyright lzt
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
#include<ctime>
using namespace std;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef std::pair<long long, long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, j, k)  for (register int i = (int)(j); i <= (int)(k); i++)
#define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--)
#define Debug(...) fprintf(stderr, __VA_ARGS__)

inline ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}

string s;

void work() {
  cin >> s;
  int num = 0;
  rep(i, 0, s.size() - 1) if (s[i] == 'x') num++;
  if (num >= 8) puts("NO");
  else puts("YES");
}

int main() {
  #ifdef LZT
    freopen("in", "r", stdin);
  #endif

  work();

  #ifdef LZT
    Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
  #endif
}


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

void fnInput(vector<int>& rvnMaxHeap)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvnMaxHeap.resize(nMaxSiz + 1);

  for (int i = 1; i < nMaxSiz + 1; ++i)
    cin >> rvnMaxHeap[i];
}

void fnMaxHeapify(vector<int>& rvnMaxHeap, int nx)
{
  int nLeft = nx * 2;
  int nRigt = nLeft + 1;
  int nLarg = nx;

  if (nLeft < rvnMaxHeap.size()  &&
      rvnMaxHeap[nx] < rvnMaxHeap[nLeft])  
    nLarg = nLeft;
  if (nRigt < rvnMaxHeap.size()  &&
      rvnMaxHeap[nLarg] < rvnMaxHeap[nRigt])
    nLarg = nRigt;

  swap(rvnMaxHeap[nx], rvnMaxHeap[nLarg]);
  if (nx != nLarg)
    fnMaxHeapify(rvnMaxHeap, nLarg);
}

void fnMaximumHeap(vector<int>& rvnMaxHeap)
{
  for (int i = (rvnMaxHeap.size() - 1) / 2; i > 0; --i)
    fnMaxHeapify(rvnMaxHeap, i);
}

void fnResult(const vector<int>& cnrvnMaxHeap)
{
  for (int i = 1; i < cnrvnMaxHeap.size(); ++i)
    cout << " " << cnrvnMaxHeap[i];

  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnMaxHeap; 

  fnInput(vnMaxHeap);
  fnMaximumHeap(vnMaxHeap);
  fnResult(vnMaxHeap);
  return 0;
}

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (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 FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int a, b, c, n, x, y;
  cin >> a >> b >> x >> y;
  if (a <= b)
    pr(a * x);
  else
    pr(b * x + (a - b) * y);
  return 0;
}

Measured memory_bytes: 3552
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, M): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let p: Vec<usize> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };
    let (x, y): (Vec<usize>, Vec<usize>) = {
        let (mut x, mut y) = (vec![], vec![]);
        for _ in 0..M {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            x.push(iter.next().unwrap().parse().unwrap());
            y.push(iter.next().unwrap().parse().unwrap());
        }
        (x, y)
    };

    struct UnionFindTree {
        parent: Vec<usize>,
        size: Vec<i64>
    }

    impl UnionFindTree {
        fn new(n: usize) -> UnionFindTree {
            UnionFindTree {
                parent: (0..(n + 1)).collect(),
                size: vec![1; n + 1]
            }
        }
        fn find(&mut self, x: usize) -> usize {
            if self.parent[x] != x {
                let parent_x = self.parent[x];
                self.parent[x] = self.find(parent_x);
            }
            self.parent[x]
        }
        fn same(&mut self, x: usize, y: usize) -> bool {
            self.find(x) == self.find(y)
        }
        fn size(&mut self, x: usize) -> i64 {
            let i = self.find(x);
            self.size[i]
        }
        fn union(&mut self, x: usize, y: usize) {
            let parent_x = self.find(x);
            let parent_y = self.find(y);
            if !self.same(x, y) {
                if self.size[parent_x] < self.size[parent_y] {
                    self.size[parent_y] += self.size[parent_x];
                    self.parent[parent_x] = parent_y;
                } else {
                    self.size[parent_x] += self.size[parent_y];
                    self.parent[parent_y] = parent_x;
                }
            }
        }
    }

    let mut uft = UnionFindTree::new(N);
    for i in 0..M { uft.union(x[i], y[i]); }
    let ans = (0..N).filter(|&i| uft.same(i + 1, p[i])).count();

    println!("{}", ans);
}


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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int n,m; cin>>n>>m;
    UnionFind uf(n);
    rep(i,m){
        int a,b; cin>>a>>b;
        a--; b--;
        uf.unite(a,b);
    }

    set<int> s;
    rep(i,n){
        s.insert(uf.root(i));
    }
    cout << s.size() - 1 << endl;
}

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

int main(void) {
    long long K;
    cin >> K;
    if (K % 2 == 0) {
        printf("-1\n");
        return 0;
    }
    long long d = 7;
    long long i;
    bool flag = false;
    for (i = 1; i <= 10000000; i++) {
        d %= K;
        if (d == 0) {
            flag = true;
            break;
        }
        d = d * 10 + 7;
    }
    if (flag) {
        printf("%lld\n", i);
    } else {
        printf("-1\n");
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

ll rec(ll n, map<ll, ll>& memo)
{
  if (n == 0) { return 1; }
  if (n == 1) { return 2; }
  if (memo.count(n) > 0) { return memo[n]; }

  ll ret = (rec(n / 2, memo) + rec((n - 1) / 2, memo)) % MOD;
  ret = (ret + rec((n - 2) / 2, memo)) % MOD;
  return memo[n] = ret;
}

int main()
{
  ll N; scanf("%lld", &N);
  map<ll, ll> memo;
  ll ans = rec(N, memo);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256