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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) setfill('0') << setw(len) << right << a
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const ll LINF = 1e11;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

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

    int a, b;
    cin >> a >> b;

    if (13 <= a) {
        cout << b << endl;
    } else if (6 <= a) {
        cout << b / 2 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}


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

void Main()
{
  int N; cin >> N;
  vector<int> a(N);
  rep(i,N) cin >> a[i];
  unordered_map<int,int> umap;
  rep(i,N) {
    if (umap.find(a[i]) == umap.end()) umap[a[i]] = 1;
    else umap[a[i]]++;
  }
  int cnt = 0;
  for (unordered_map<int,int>::iterator it = umap.begin(); it != umap.end(); it++) {
    if (it->first < it->second) cnt += it->second - it->first;
    else if (it->first > it->second) cnt += it->second;
  }
  cout << cnt << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 4644
from collections import defaultdict
N,M=map(int,input().split())
PD=defaultdict(lambda: [])
OR=dict()
ANS=dict()
for i in range(M):
    p, y=map(int,input().split())
    OR[i] = (p,y)
    PD[p].append(y)

for k in PD.keys():
    l=sorted(PD[k])
    for i,n in enumerate(l):
        ANS[(k,n)] = str(k).zfill(6) + str(i+1).zfill(6)
for k in OR.values():
    print(ANS[k])

Measured memory_bytes: 65788
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int x, a, b;
    cin >> x >> a >> b;
    cout << (x - a) % b << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        System.out.println(Math.min(n % k, k - n %k));
    }

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int long long  count_baisu(int long long  x,int long long  A,int long long B){
 // cout <<B/x - (A-1)/x <<endl;
  return  B/x - (A-1)/x ;
}

int long long Gratest_Common_Deviser (int long long  a, int long long  b){
  int long long  r =b % a;
  while(r!=0){
    b = a;
    a = r;
    r = b % a ; 
  }
// cout << a;
  return a;
}

  
int long long Least_Common_Muliple (int long long  a, int long long  b){
  //cout <<  a*b /Gratest_Common_Deviser(a,b);
  return  a*b /Gratest_Common_Deviser(a,b);
}
  
int main() {
 int long long   a,b,c,d;
  cin >> a>>b>>c>>d;
  int long long ans =0;
  ans += b-a+1;
 //  cout << ans<<endl;
  ans -= count_baisu(c,a,b) ;
  ans -= count_baisu(d,a,b);
  ans += count_baisu(Least_Common_Muliple(c,d),a,b);
  cout << ans;
}


Measured memory_bytes: 256
n = int(input())
lines = [[] for i in range(n)]
for i in range(n-1):
	u,v,w = map(int,input().split())
	u-=1
	v-=1
	lines[u].append([v,w])
	lines[v].append([u,w])
# print(lines)
ans = [0 for i in range(n)]
q = [[0,0,-1]]
while q:
	u,w,v = q.pop(0)
	if w%2 == 0:
		ans[u] = 0
	else:
		ans[u] = 1
	for n,ww in lines[u]:
		if n == v:
			continue
		q.append([n,w+ww,u])
	# print(q)
	# print(ans)
for a in ans:
	print(a)

Measured memory_bytes: 45136
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define ff first
#define ss second
#define MAXN  1000005
#define endl "\n"
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, r;
    cin>>n;
    vector<int>dp(3,0);
    for(int i = 0; i < n; i++){
        vector<int>v(3);
        for(int j = 0; j < 3 ; j++){
            cin>>v[j];
            r = INT_MIN;
            for(int k = 0; k < 3; k++){
                if(k != j){
                    r = max(r, dp[k]);
                }
            }
            v[j] += r;
        }
        dp = v;
    }
    cout<<*max_element(all(dp));

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	double r;
	double pai = 3.141592653589;
	double are, circ;
	scanf("%lf",&r);
	are = pai*r*r;
	circ = 2*pai*r;
	printf("%f %f\n",are,circ);
	return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll A,B,C,K;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C>>K;
	
	if(K%2==0) {
		cout<<A-B<<endl;
	}
	else {
		cout<<B-A<<endl;
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <complex>
#include <math.h>

typedef long long ll;

using namespace std;

double pi=2*acos(0);
const int INF = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    string s,t;
    cin >> s >> t;
    cout << t << s;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	int X;
	cin >> X;

	vector<bool> dp( X+1 );
	dp[0] = true;

	for( int i = 100; i <= X; ++i ) {
		if( dp[i-100] || dp[i-101] || dp[i-102] || dp[i-103] || dp[i-104] || dp[i-105] ) {
			dp[i] = true;
		}
	}

	cout << dp[X] << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n"; 

signed main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	
	int e, o; cin >> e >> o;
	
	int ans = e*(e-1)/2;
	ans += (o * (o-1)/2);
	cout << ans << "\n";


	
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    string s;
    cin >> s;
    bool ans = true;
    if(s[0] != 'A') ans = false;
    int cnt = 0;
    forr(i, 2, s.size() - 1) {
        if(s[i] == 'C') cnt++;
    }
    if(cnt != 1) ans = false;
    cnt = 0;
    rep(i, s.size()) {
        if(s[i] >= 'a' && s[i] <= 'z') cnt++;
    } 
    if(cnt != s.size() - 2) ans = false;
    if(ans) cout << "AC" << endl;
    else cout << "WA" << endl;
    
    return 0;
}

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

int main(){
  int l, r, ans, min = 2019;
  cin >>  l >> r;
  
  if(l / 2019 < r / 2019){
    min = 0;
  }
  else{
    rep(i, r, l){
      rep(j, r+1, i+1){
        ans = ((i % 2019) * (j % 2019)) % 2019;
        if(min > ans) min = ans;
      }
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		long n = in.nextLong();
		long k = in.nextLong();
		long x = in.nextLong();
		long y = in.nextLong();
		if (n <= k) {
			out.println(n*x);
		} else {
			out.println(k*x+(n-k)*y);
		}
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

int main(){
  int A,B;
  cin >> A >> B;
  if(A == 1) A = 14;
  if(B == 1) B = 14;
  if(A > B) cout << "Alice" << endl;
  if(A == B) cout << "Draw" << endl;
  if(A < B) cout << "Bob" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
using Graph = vector<int>;
vector<Graph>g;
vector<int> d;
vector<int> f;
int t = 0;
void dfs(int i) {
    Graph G = g[i];
    if (d[i] != 0) {
        return;
    }

    t++;
    d[i] = t;
    for (int j=0; j < G.size(); j++) {
        dfs(G[j]);
    }

    t++;
    f[i] = t;
}

int main() {
    int G;
    cin >> G;
    g.resize(G);
    d.resize(G);
    f.resize(G);

    for (int i=0; i < G; i++) {
        int num, c;
        cin >> num >> c;
        for (int j=0; j<c; j++) {
            int k;
            cin >> k;
            g[num-1].emplace_back(k-1);
        }
    }

    dfs(0);
    for (int i=0; i < G; i++) {
        if (d[i] == 0) {
            dfs(i);
        }
    }

    for (int i=0; i < G; i++) {
        int start_time = d[i];
        int end_time = f[i];
        cout << i+1 << " " << start_time << " " << end_time << endl;
    }

    return 0;
}


Measured memory_bytes: 3152
using System.Collections.Generic;
using static System.Console;

class Program {
	static void Main() {
		var N = NextInt();
		var M = NextInt();
		var cities = new int[N];

		for (var i = 0; i < M; i++) {
			var a = NextInt();
			var b = NextInt();

			cities[a - 1]++;
			cities[b - 1]++;
		}
		foreach (var roads in cities) {
			WriteLine(roads);
		}
	}

	static int NextInt() {
		return int.Parse(NextString());
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if (!char.IsWhiteSpace(nextChar))
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}


Measured memory_bytes: 13268
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String str = sc.next();
        HashMap<Character, Integer> map = new HashMap<Character, Integer>(){
            {
                put('a', 0);
                put('b', 0);
                put('c', 0);
                put('d', 0);
                put('e', 0);
                put('f', 0);
                put('g', 0);
                put('h', 0);
                put('i', 0);
                put('j', 0);
                put('k', 0);
                put('l', 0);
                put('m', 0);
                put('n', 0);
                put('o', 0);
                put('p', 0);
                put('q', 0);
                put('r', 0);
                put('s', 0);
                put('t', 0);
                put('u', 0);
                put('v', 0);
                put('w', 0);
                put('x', 0);
                put('y', 0);
                put('z', 0);
            }
        };
        
        for(int i = 0; i < str.length(); i++){
            int n = map.get(str.charAt(i));
            n += 1;
            map.put(str.charAt(i), n);
        }
        
        Iterator entries = map.entrySet().iterator();
        
        if(!((map.values().contains(0))))
            System.out.println("None");
        else
            for(int i = 0; i < map.size(); i++){
                Map.Entry entry = (Map.Entry)entries.next();
		if((int)entry.getValue() == 0){
                    System.out.println((Character)entry.getKey());
                    break;
                }
            }
    }
}


Measured memory_bytes: 26464
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int x, p = 0;
    scanf("%d", &x);
    for (int i = 10, y = x; y; y /= i)
    {
        p += y % i;
    }
    printf(x % p ? "No\n" : "Yes\n");
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, t;
	cin >> a >> b >> t;
	int cur = a, ans = 0;
	while(cur <= t){
		cur += a;
		ans += b;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size() + 1;
    int a[n];
    fill(a,a+n,-1);
    for(int i=0; i<n-1; i++){
        if(s[i] == '<'){
            if(a[i] == -1) a[i] = 0;
            a[i+1] = a[i]+1;
        }
    }
    for(int i=n-2; i>=0; i--){
        if(s[i] == '>'){
            if(a[i+1] == -1) a[i+1] = 0;
            a[i] = max(a[i],a[i+1]+1);
        }
    }
    long long ans = 0;
    for(int i=0; i<n; i++){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

const int NMAX = 100;
bool flag;

bool cmp(int x,int y){
    return abs(0-x)<abs(0-y);
}

int main(){
    SCIN(s);
    char c;
    for(char i='a';i<='z';i++){
        flag=false;
        rep(j,s.size()){
            if(s[j]==i)flag=true;
            if(flag) break;
        }
        c=(char)i;
        if(!flag) break;
    }
    if(flag) printf("None");
    else printf("%c",c);
    
    return 0;
}

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

a = 0
b = 0

for _ in range(n):
    x, y = map(int, input().split())
    if not a:
        a, b = x, y
        continue
    z = max(-(-a // x), -(-b // y))
    a, b = z * x, z * y

print(a + b)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 307, MOD = 1e9+7;

//need define int long long
int mod(int n) {
    n %= MOD;
    if (n < 0) return n + MOD;
    else return n;
}   
int fp(int a, int p) {
    int ans = 1, c = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) ans = mod(ans * c);
        c = mod(c * c);
    }   
    return ans;
}   
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }

struct M {
ll x;
M (int x_) {
    x = mod(x_);
}   
M () {
    x = 0;
}
M operator + (M y) {
    int ans = x + y.x;
    if (ans >= MOD)
        ans -= MOD;
    return M(ans);
}
M operator - (M y) {
    int ans = x - y.x;
    if (ans < 0)
        ans += MOD;
    return M(ans);            
}   
M operator * (M y) {
    return M(x * y.x % MOD);   
}   
M operator / (M y) {
    return M(x * fp(y.x, MOD - 2) % MOD);
}   
M operator + (int y) {
    return (*this) + M(y);
}
M operator - (int y) {
    return (*this) - M(y);
}   
M operator * (int y) {
    return (*this) * M(y);
}   
M operator / (int y) {
    return (*this) / M(y);
}   
M operator ^ (int p) {
    return M(fp(x, p));
}   
void operator += (M y) {
    *this = *this + y;
}   
void operator -= (M y) {
    *this = *this - y;
}   
void operator *= (M y) {
    *this = *this * y;
}
void operator /= (M y) {
    *this = *this / y;
}   
void operator += (int y) {
    *this = *this + y;
}   
void operator -= (int y) {
    *this = *this - y;
}   
void operator *= (int y) {
    *this = *this * y;
}
void operator /= (int y) {
    *this = *this / y;
}   
void operator ^= (int p) {
    *this = *this ^ p;
}
};  

M f[N], inv[N];
void prec() {
    f[0] = M(1);
    for (int i = 1; i < N; ++i)
        f[i] = f[i - 1] * M(i);
    inv[N - 1] = f[N - 1] ^ (MOD - 2);
    for (int i = N - 2; i >= 0; --i)
        inv[i] = inv[i + 1] * M(i + 1);
}
M C(int n, int k) {
    if (n < k)
        return M(0);
    else
        return f[n] * inv[k] * inv[n - k];
}   

M dp[N][N][N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20); 
    #endif
    
    int n, m;
    cin >> n >> m;
    dp[0][1][0] = M(1);
    for (int len = 0; len <= m; ++len) {
        for (int i = 0; i <= n; ++i) {
            for (int j = 0; i + j <= n; ++j) {
                /*
                if (dp[len][i][j].x) {
                    cout << len << ' ' << i << ' ' << j << " : " << dp[len][i][j].x << endl;
                }   
                */
                dp[len + 1][i + j][0] += dp[len][i][j] * i;
                dp[len + 1][i][j] += dp[len][i][j] * j;
                dp[len + 1][i][j + 1] += dp[len][i][j] * (n - i - j);
            }   
        }   
    }
    cout << dp[m][n][0].x << endl;

}


Measured memory_bytes: 229708
#include <cstdio>

int main()
{
	int n;
	scanf("%d",&n);

	int p[100];

	p[0]=2;
	int k=1;
	for(int i=3;i<100;i+=2){
		int j;
		for(j=0;j<k;j++){
			if(i%p[j]==0) break;
		}
		if(j==k) p[k++]=i;
	}

	int e[k]={0};
	for(int i=2;i<=n;i++){
		int m=i;
		for(int j=0;j<k;j++){
			int tmp=0;
			while(m%p[j]==0){
				tmp++; m/=p[j];
			}
			e[j]+=tmp;
		}
	}

	int ans=0;

	for(int i=0;i<k;i++) if(e[i]>=74) ans++;

	for(int i=0;i<k;i++){
		for(int j=i+1;j<k;j++){
			if(e[i]>=2 && e[j]>=24) ans++;
			if(e[i]>=24 && e[j]>=2) ans++;
			if(e[i]>=4 && e[j]>=14) ans++;
			if(e[i]>=14 && e[j]>=4) ans++;
		}
	}

	for(int i=0;i<k;i++){
		for(int j=i+1;j<k;j++){
			for(int l=j+1;l<k;l++){
				if(e[i]>=2 && e[j]>=4 && e[l]>=4) ans++;
				if(e[i]>=4 && e[j]>=2 && e[l]>=4) ans++;
				if(e[i]>=4 && e[j]>=4 && e[l]>=2) ans++;
			}
		}
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

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

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

const int INF = 1<<29;
int N;
char S[500011];
int ans;
void go(VI v) {
    if (v.size() <= 1u) return;
    int a[3] = { 0, -INF, 0 };
    EACH (e, v) {
	int b[3] = { a[0], a[0], a[0] + *e };
	amax(b[0], a[1] + *e);
	amax(b[1], a[1] + *e - 1);

	amax(b[0], a[2]);
	amax(b[2], a[2] + *e - 1);
	if (*e > 1) {
	    amax(b[1], a[2]);
	}
	a[0] = b[0];
	a[1] = b[1];
	a[2] = b[2];
    }
    ans += a[0];
}

void MAIN() {
    scanf("%d%s", &N, S);

    for (int i=0; i<N; ) {
	if (S[i] == '0') i++;
	else {
	    VI v;
	    while (1) {
		int j = i;
		while (j < N && S[j] == '1') j++;
		v.push_back(j-i);
		i = j+1;
		if (i < N && S[i] == '1') {
		    continue;
		} else {
		    i++;
		    break;
		}
	    }
	    go(v);
	}
    }

    printf("%d\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



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

struct node{
	int p,x;
} a[100005];

bool comp(node a,node b){
	return a.x < b.x;
}

int main()
{
	int n;
	cin >> n;
	for(int i = 1;i <= n;++i) cin >> a[i].x,a[i].p = i;
	sort(a+1,a+n+1,comp);
	
	cout << a[1].p;
	for(int i = 2;i <= n;++i) cout << " " << a[i].p;
	return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    int N, X; cin >> N >> X;
    int L[N];
    REP(0, i, N) cin >> L[i];

    int ans = 1;
    int D = 0;
    REP(0, i, N) {
        D += L[i];
        if (D <= X) {
            ans++;
        } else {
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
dbflag=""

def debug(*args):
  if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
  if ""!=dbflag:return _INDATA.readline()
  else: return input()


result = -1

N = int(readline())



import numpy as np

A1 = [int(i) for i in readline().split(' ')]
A2 = [int(i) for i in readline().split(' ')]
data = np.zeros((2,N),dtype=int)
data[0,0:N]=A1
data[1,0:N]=A2

#np.reshape(data,[2,N])

memo = np.zeros((2,N), dtype=int)
score = np.zeros((2,N), dtype=int)


def getScore(i,j):
	if i < 0 or j < 0 : return 0
	
	if memo[i,j]: return score[i,j]
	
	x= data[i,j] + max(getScore(i-1,j) ,  getScore(i,j-1))
	memo[i,j]=1
	score[i,j]=x
	return x

result = getScore(1,N-1)
print(result)


Measured memory_bytes: 12444
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll a[101]={};
  for(ll i=1;i<10;i++){
    for(ll j=1;j<10;j++)a[i*j]=1;
  }

  ll n;
  cin >> n;
  if(a[n]==0)cout << "No" << endl;
  else cout << "Yes" << endl;

}

Measured memory_bytes: 3644
int a[200010];
int ans[200010];
int main(){
int n;
scanf("%d",&n);
for(int i=2;i<=n;i++)scanf("%d",&a[i]);
for(int i=2;i<=n;i++)ans[a[i]]++;
for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
}

Measured memory_bytes: 3236
#include <iostream>

int Classification(int pm, int pe, int pj)
{
	if(pm == 100 || pe == 100 || pj == 100) {
		return 1;
	} else if ( ( pm + pe) / 2 >= 90) {
		return 1;
	} else if ( ( pm + pe + pj) / 3 >= 80) {
		return 1;
	} else if ( ( pm + pe + pj) / 3 >= 70) {
		return 2;
	} else if ( ( pm + pe + pj) /3 > 50 && ( pm >= 80 || pe >= 80)) {
		return 2;
	} else {
		return 3;
	}
}

char Class(int x)
{
	if ( x == 1) {
		return 'A';
	} else if ( x == 2) {
		return 'B';
	} else {
		return 'C';
	}
}

int main()
{
	int n, pm, pe, pj;
	
	while (true) {
		std::cin >> n;
		if ( n == 0){
			break;
		} else {
			for (int i = 0; i < n; i++) {
				std::cin >> pm >> pe >>pj;
				std::cout << Class(Classification(pm, pe, pj)) << std::endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int a, b, c,d,e;
    int k;
    cin >> a >> b>> c>>d>>e;
    cin >> k;
    string ans = "";
    if(e-a > k){
        ans = ":(";
    }else{
        ans = "Yay!";
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int power(int num)
{
    int p=1;
    for(;0<num;num--)p*=10;
    return p;
}
int main() {
    int n,m,a[3]={15,3,5};
    while(cin>>m>>n,n,m){
        string str,fb[3]={"FizzBuzz","Fizz","Buzz"};
        bool player[1000]={};
        for(int i=1,now=0,out=m;i<=n;i++,now=(now+1)%m){
			cin>>str;
			if(out>1){
				int num=0,co=-1;
				while(player[now])now=(now+1)%m;
				for(int j=0;j<3&&co<0;j++)if(i%a[j]<1)co=j;
				for(int j=0;j<str.size()&&co<0;j++)num+=(str[j]-'0')*power(str.size()-1-j);
				if(co>-1&&str!=fb[co]||co<0&&i!=num)player[now]=1;
				if(player[now])out--;
			}
		}
		for(int i=0,co=0;i<m;i++){
			if(!player[i]&&co>0)cout<<" ";
			if(!player[i]){
				cout<<i+1;
				co++;
			}
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
    string s;
    cin >> s;

    int64_t k;
    cin >> k;

    bool b = false;
    int64_t tmp = 0;
    char prev = -1;
    for (auto c : s) {
        if (c == prev && !b) {
            ++tmp;
            b = true;
        } else {
            b = false;
        }

        prev = c;
    }
    auto b1 = b;

    int64_t tmp2 = 0;
    for (auto c : s) {
        if (c == prev && !b) {
            ++tmp2;
            b = true;
        } else {
            b = false;
        }

        prev = c;
    }
    auto b2 = b;

    if (s.size() == 1) {
        cout << k / 2 << endl;
    } else if (s.front() == s.back()) {
        if (b2) {
            cout << tmp * ((k + 1) / 2) + tmp2 * (k / 2) << endl;
        } else {
            if (b1) {
                throw new std::runtime_error("invalid b1.");
                return 1;
            }
            cout << tmp + tmp2 * (k - 1) << endl;
        }
    } else {
        cout << tmp * k << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
const int maxn = 2e5 + 10;
int n,k;
ll fpow(ll a,ll b) {
	ll r = 1;
	while (b) {
		if (b & 1) r = r * a % mod;
		b >>= 1;
		a = a * a % mod;
	}
	return r;
}
ll fac[maxn],ifac[maxn];
ll C(int x,int y) {
	if (x < 0 || x < y || y < 0) return 0;
	return fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
int main() {
	scanf("%d%d",&n,&k);
	fac[0] = 1;
	for (int i = 1; i <= maxn - 10; i++)
		fac[i] = fac[i - 1] * i % mod;
	ifac[maxn - 10]	= fpow(fac[maxn - 10],mod - 2);
	for (int i = maxn - 10 - 1; i >= 0; i--)
		ifac[i] = ifac[i + 1] * (i + 1) % mod;
	ll ans = 0;
	for (int i = 1; i <= min(n,k); i++) {
		ans = (ans + C(n,i) * C(n - 1,n - i - 1) % mod) % mod;
	}
	printf("%lld\n",ans + (k > 1));
	return 0;
}

Measured memory_bytes: 3328
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        ArrayList<Integer> num = new ArrayList<Integer>(n);
        boolean judge = true;


        for(int i = 0;i < n;i++){
            num.add(scan.nextInt());
        }

        scan.close();

        Collections.sort(num);

        for(int j = 0; j < n-1;j++){
            if(num.get(j).equals(num.get(j+1))) judge = false;
        }

        if(judge) System.out.println("YES");
        else System.out.println("NO");
    }
}

Measured memory_bytes: 93860
#include <bits/stdc++.h>
#include <fstream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ll unsigned long long

const int MOD = 1000000007;

int main() {
	//入力
	int k;
	cin >> k;

	//処理
	string ans="";
	rep(i, k) {
		ans += "ACL";
	}
	//出力
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int len = S.Length;
            int count = 0;
            for(int i = 0; i < len / 2; i++)
            {
                if(S[i] != S[len - i - 1])
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 25976
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e3+5;
const int maxval=2e4+5;
int w[maxn],s[maxn],arr[maxn];
ll v[maxn];
bool Less1(int a,int b)
{
	return s[a]+w[a]<s[b]+w[b];
}
ll maxx[maxn][maxval];
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
//    fl();
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%lld",&w[i],&s[i],&v[i]);
		arr[i]=i;
	}
	sort(arr+1,arr+n+1,Less1);
	for(int i=1;i<=n;i++)
		for(int j=0;j<=20000;j++)
		{
			maxx[i][j]=maxx[i-1][j];
			if(j>=w[arr[i]]&&j-w[arr[i]]<=s[arr[i]])
				maxx[i][j]=max(maxx[i][j],maxx[i-1][j-w[arr[i]]]+v[arr[i]]);
		}
	ll ans=0;
	for(int j=0;j<=20000;j++)
		ans=max(ans,maxx[n][j]);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 160084
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vvl G;
vl visited;
vl ans;
bool flag = false;

void dfs(ll v) {
    if(flag) {
        return;
    }
    if(v != 0) {
        ans.pb(v);
    }
    // 行きの処理はこのへんに書く
    visited[v] = 1;
    for(auto u : G[v]) { 
        if(visited[u]) {
            continue;
        }
        dfs(u);
        // 帰りの処理はこのへんに書く
    }
    flag = true;
}

int main() {
    ll n, m;
    cin >> n >> m;    
    
    G.resize(n);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    
    visited.resize(n);
    ans.pb(0);
    dfs(0);

    reverse(all(ans));
    flag = false;
    dfs(0);

    out(ans.size());
    for(auto v : ans) {
        cout << v+1 << " ";
    }

    cout << endl;
    re0;
}

Measured memory_bytes: 12276
a,b,c,d = map(int,list(input()))
bb,cc,dd = '','',''
op = [1,-1]

for i in op:
	for j in op:
		for k in op:
			bb,cc,dd = i*b,j*c,k*d
			if a+bb+cc+dd == 7:
				if bb >= 0:
					bb = '+'+ str(b)
				if cc >= 0:
					cc = '+'+ str(c)
				if dd >= 0:
					dd = '+'+ str(d)
				ans = str(a)+str(bb)+str(cc)+str(dd)+'=7'

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,m;
   cin >> n >> m;
   map<int,int> inc;
   map<int,int> done;
   int a;
   string b;
   int a1 = 0,a2 = 0;
   f(i,0,m){
      cin >> a >> b;
      if(done[a]){
         continue;
      }
      if(b == "AC"){
         a1 += 1;
         done[a] = 1;
         a2 += inc[a];
      }else{
         inc[a]++;
      }
   }
   cout << a1 << ' ' << a2 << '\n';
   return 0;
} 

Measured memory_bytes: 12800
import java.util.*;
import java.io.*;
public class Main{
	static class node{
		int x,y,d;
		 node(int x1, int y1,int d1){x=x1;y=y1;d=d1;}
	}

public static long gcd(long a,long b){
	if(b==0){return a;}
	return gcd(b,a%b);
}

static int bfs(int[][] arr, int sx,int sy,int dx,int dy){
	int n=arr.length,m=arr[0].length;
	Queue<node> q=new LinkedList<>();
	boolean[][] b=new boolean[n][m];
	if(arr[sx][sy]!=0)q.add(new node(sx,sy,0));
	b[sx][sy]=true;
	while(!q.isEmpty()){
		node curr=q.poll();
		int x=curr.x,y=curr.y,d=curr.d;
		if(x==dx&&y==dy){return d;}
		if(y+1<m&&arr[x][y+1]!=0&&!b[x][y+1]){q.add(new node(x,y+1,d+1));b[x][y+1]=true;}
		if(y-1>=0&&arr[x][y-1]!=0&&!b[x][y-1]){q.add(new node(x,y-1,d+1));b[x][y-1]=true;}
		if(x+1<n&&arr[x+1][y]!=0&&!b[x+1][y]){q.add(new node(x+1,y,d+1));b[x+1][y]=true;}
		if(x-1>=0&&arr[x-1][y]!=0&&!b[x-1][y]){q.add(new node(x-1,y,d+1));b[x-1][y]=true;}
	}
	return -1;
}
public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
       int n=s.nextInt(),m=s.nextInt();
       s.nextLine();
       int[][] arr=new int[n][m];
       int[][][][] dp=new int[n][m][n][m];
       for(int i=0;i<n;i++){
       	String ss= s.nextLine();
       	for(int j=0;j<m;j++){
       		if(ss.charAt(j)=='.'){arr[i][j]=1;}
       	}
       }
       int res=0;
        for(int i=0;i<n;i++){
        	for(int j=0;j<m;j++){
        		for(int k=0;k<n;k++){
        			for(int l=0;l<m;l++){
        				if(arr[i][j]==0||dp[k][l][i][j]!=0){continue;}
        				dp[i][j][k][l]=bfs(arr,i,j,k,l);
        				res=Math.max(res,dp[i][j][k][l]);
        			}
        		}
        	}
        }
                out.write(res+" ");
        
        out.flush();
  }
}


Measured memory_bytes: 276040
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int f(int y,int m,int d){
	return (y-1)/3*590+(y-1)%3*39*5+(m-1)/2*(39+!(y%3))+(m-1)%2*20+d;
}
int main(){
	int n;
	cin>>n;
	while(n--){
		int y,m,d;
		cin>>y>>m>>d;
		cout<<f(1000,1,1)-f(y,m,d)<<endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 3;
char s[N];
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	if (n < 3200) {
		puts("red");
	}else {
		scanf("%s", s);
		printf("%s\n", s);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n ,coin=0;

  while ( 1 ){
    cin >> n;
    if( n == 0 ){
      break;
    }
 
    n = 1000 - n; 
    
    if( n >= 500 ){
      while( n >= 500 ){
	n -= 500;
	coin++;
      }
    }
    
    if( n >= 100 ){
      while( n >= 100 ){
	n -= 100;
	coin++;
      }
    }
  
    if( n >= 50 ){
      while( n >= 50 ){
	n -= 50;
	coin++;
      }
    }
    
    if( n >= 10 ){
      while( n >= 10 ){
	n -= 10;
	coin++;
      }
    }
    
    if( n >= 5 ){
      while( n >= 5 ){
	n -= 5;
	coin++;
      }
    }
    
    if( n >= 1 ){
      while( n >= 1 ){
	n -= 1;
	coin++;
      }
    }
    
    cout << coin << endl;
    coin = 0;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  string S, T;
  cin >> S >> T;
  int length = T.length();
  if (S == T.substr(0, length - 1))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
N,M=map(int, input().split())
A=set(int(input()) for _ in range(M))
D=[0]*(N+1)
D[0]=1

for i in range(1,N+1):
 if i in A: continue
 D[i]=(D[i-1]+D[i-2])%(10**9+7)
print(D[-1])

Measured memory_bytes: 17556
M, D = [int(n) for n in input().split()]
c = 0
for m in range(1, M+1):
  for d in range(1, D+1):
    if d <= 9:
        d10 = 0
        d1 = d
    else:
        d10, d1 = [int(n) for n in list(str(d))]
    if m == d10*d1 and d10 >=2 and d1 >=2:
        c += 1
print(c)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int N;
string S;
main(){
  cin>>N>>S;
  vector<int> es(N),ws(N),n_changess(N);
  for(int i=0;i<N;++i){
    es[i]=S[i]=='E';
    ws[i]=S[i]=='W';
  }
  for(int i=1;i<N;++i)ws[i]+=ws[i-1];
  for(int i=N-2;i>=0;--i)es[i]+=es[i+1];
  for(int i=0;i<N;++i){
    int n_changes=0;
    if(i>0)n_changes+=ws[i-1];
    if(i<N-2)n_changes+=es[i+1];
    n_changess[i]=n_changes;
  }
  cout<<*min_element(n_changess.begin(),n_changess.end())<<endl;
}


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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,k,sum = 0;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> div;
    for (int i = 0;i < n;++i) {
        cin >> a[i];
        sum += a[i];
    }
    for (ll i = 1;i*i <= sum;++i) if (sum%i == 0) {
        div.push_back(i);
        if (sum != i*i) div.push_back(sum/i);
    }
    sort(div.begin(),div.end());
    reverse(div.begin(),div.end());
    for (int d : div) {
        vector<int> x;
        ll s = 0;
        for (int i = 0;i < n;++i) if (a[i]%d) {
            x.push_back(a[i]%d);
            s += a[i]%d;
        }
        sort(x.begin(),x.end());
        if (s%d == 0) {
            ll t = 0;
            for (int i = x.size()-s/d-1;i >= 0;--i) t += x[i];
            if (t <= k) {
                cout << d << endl;
                return 0;
            }
        }
    }
}

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

const long long INF = 1LL << 60;  // どういう意味だろうか

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

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

int func(int n) {
	if ((n % 2) == 0) {
		return n / 2;
	} else {
		return 3 * n + 1;
	}
}

int main() {
	int s;
	vector<int> a;
	vector<int> b;

	cin >> s;

	for (int i = 1;; i++) {
		if (i == 1) {
			a.push_back(s);
		} else {
			a.push_back(func(a[i-2]));
		}


		auto itr = find(b.begin(), b.end(), a[i-1]);
		size_t index = distance(b.begin(), itr);

		if(index != b.size()){
			cout << i << endl;
			return 0;
		}
		else{
			b.push_back(a[i-1]);
		}
	}

}


Measured memory_bytes: 384
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int N, M;
    cin >> N >> M;

    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];

    int S = accumulate(A.begin(), A.end(), 0);
    sort(A.rbegin(), A.rend());

    for (int i = 0; i < M; i++) {
        //cerr << A[i] << "\n";
        if (A[i] < 1.0 * S / (4 * M)) {
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math
INF = float("inf")


def solve(N: int, K: int):

    numer = 0
    for i in range(1, N+1):
        if i < K:
            b = math.ceil(math.log2(K/i))
            numer += 1/(2**b)
        else:
            numer += 1

    print(numer/N)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()


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

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

    list<int> li;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (i % 2 == 0) {
            li.push_back(x);
        } else {
            li.push_front(x);
        }
    }

    if (n & 1) {
        reverse(li.begin(), li.end());
    }

    for (int x : li) {
        cout << x << " ";
    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long   ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ii, ll>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
#define tam 120000
#define offset 
const ll MBOD= 1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<ii> v;
void gorange(int iz,int der)
{
    while(iz<der)
    {
        v.pb({iz,der});
        iz++,der--;
    }
}
int  main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m;
    cin>>n>>m;
    if (n%2==0)
    {
        gorange(1,int(n/2));
        gorange(int(n/2)+2,n);
    }
    else
        gorange(1,n);
    forr(i,0,m)
        cout<<v[i].fi<<' '<<v[i].se<<endl;
}
// PLUS ULTRA!
    


Measured memory_bytes: 5224
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#include<string.h>
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);                    
    cout.tie(NULL);
   	ll n,k;
   	cin>>n>>k;
   	ll arr[n];
   	for(int i=0;i<n;i++) cin>>arr[i];
   	sort(arr,arr+n);
   ll sum=0;
   	for(int i=0;i<k;i++) sum+=arr[i];
   		cout<<sum;
	return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int MAX_BITS = 60;

// to[i][j] is the destination of 2^i paths from j
vector<vector<int>> to;

// solution by doubling
int main(void) {
    int N;
    ll K;
    cin >> N >> K;

    to.resize(MAX_BITS, vector<int>(N, 0));
    for (int i = 0; i < N; i++) {
        int t;
        cin >> t;
        t--;
        to[0][i] = t;
    }

    for (int i = 1; i < MAX_BITS; i++) {
        for (int j = 0; j < N; j++) {
            to[i][j] = to[i - 1][to[i - 1][j]];
        }
    }

    int cur = 0;
    for (int i = 0; i < MAX_BITS; i++) {
        int bit = (K >> i) & 1;
        if (bit) {
            cur = to[i][cur];
        }
    }

    cout << cur + 1 << endl;

    return 0;
}


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	ll n, i, j;
	cin >> n;
	vl a(n);
	ll sum = 0;
	for (i = 0; i<n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	if (sum % (n*(n + 1) / 2) != 0) {
		cout << "NO" << endl;
		return 0;
	}
	ll m = sum / (n*(n + 1) / 2);
	vl num(n);
	for (i = 1; i<n; i++) {
		ll sa = a[i] - a[i - 1];
		if ((m - sa) % n != 0 || m-sa < 0) {
			cout << "NO" << endl;
			return 0;
		}
		num[i - 1] = (m - sa) / n;
	}
	ll sa = a[0] - a[n - 1];
	if ((m - sa) % n != 0 || m-sa < 0) {
		cout << "NO" << endl;
		return 0;
	}
	num[n - 1] = (m - sa) / n;

	ll ans = 0;
	for (i = 0; i<n; i++) {
		ans += num[i];
	}
	if (ans == m) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 1920
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class B
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var NK = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var (N, K) = (NK[0], NK[1]);
            var answer = K;
            for (var i = 1; i < N; i++)
            {
                answer *= (K - 1);
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 28040