akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>
#include <sstream>
#include <iomanip>

using namespace std;

using Graph = vector<vector<int> >;

vector<int> seen;

vector<int> Ns;

int MakeN(int no, int ni, int flag_0, int flag_3, int flag_5, int flag_7)
{
	if (ni == 9) {
		if (flag_3 && flag_5 && flag_7) {
			Ns.push_back(no);
		}
		return 1;
	}

	if (flag_0 == 0) {
		MakeN(no, ni + 1, flag_0, flag_3, flag_5, flag_7);
	}

	MakeN(no + 3 * pow(10, 8 - ni), ni + 1, 1, 1, flag_5, flag_7);
	MakeN(no + 5 * pow(10, 8 - ni), ni + 1, 1, flag_3, 1, flag_7);
	MakeN(no + 7 * pow(10, 8 - ni), ni + 1, 1, flag_3, flag_5, 1);

	return 0;
}


int main()
{
	int N;

	cin >> N;

	MakeN(0, 0, 0, 0, 0, 0);

	int cnt = upper_bound(Ns.begin(), Ns.end(), N) - Ns.begin();

	//printf("%d %d %lld", xi, yi, H + gap);

	cout << cnt;
	

	return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const LL mod = 1e9 + 7;
const LL inf = 0x3f3f3f3f3f3f3f3f;
vector<pair<LL, int> > v;

LL qpower(LL a, LL b, LL c) {
    LL res = 1;
    a %= c;
    while(b) {
        if(b & 1) res = (res * a) % c;
        a = (a * a) % c; b >>= 1;
    }
    return res;
}

LL inv(LL a, LL mod) {
    return qpower(a, mod-2, mod);
}

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    bool po = false, ne = false;
    LL mul = 1;
    for(LL i = 0, t; i < n; ++i) {
        scanf("%lld", &t);
        mul = ((mul * t+mod)%mod + mod) % mod;
        if(!t) continue;
        po |= (t > 0);
        ne |= (t < 0);
        if(t > 0) v.push_back({t, 1});
        else v.push_back({-t, -1});
    }
    if(k == n)
        return 0*printf("%lld\n", mul);
    if((int)v.size() < k)
        return 0*printf("0\n");
    int zero = n - v.size();
    sort(v.begin(), v.end());
    if(!po && k%2) {
        if(zero) return 0*printf("0\n");
        else {
            LL ans = 1;
            for(int i = 0; i < k; ++i)
                ans = ((-ans*v[i].first+mod)%mod+mod) % mod;
            return 0*printf("%lld\n", ans);
        }
    }
    LL ans = 1, MP = inf, MN = inf, f = 1;
    for(int i = v.size()-1; i >= v.size()-k; --i) {
        ans = (ans*v[i].first)%mod;
        f *= v[i].second;
        if(v[i].second == 1) MP = min(MP, v[i].first);
        else MN = min(MN, v[i].first);
    }
    if(f == 1) printf("%lld\n", ans);
    else {
        bool c1 = false, c2 = false;
        LL ans1, ans2; long double g1, g2;
        for(int i = v.size()-k-1; i >= 0; --i) {
            if(c1 && c2) break;
            if(!c1 && v[i].second == 1 && MN != inf)
                ans1 = (ans *inv(MN,mod)%mod * v[i].first+mod)%mod, g1 = ((long double)v[i].first)/MN, c1 = true;
            else if(!c2 && v[i].second == -1 && MP != inf)
                ans2 = (ans *inv(MP,mod)%mod * v[i].first+mod)%mod, g2 = ((long double)v[i].first)/MP, c2 = true;
        }
        if(c1 && c2) {
            if(g1 > g2) printf("%lld\n", ans1);
            else printf("%lld\n", ans2);
        }
        else if(c1) printf("%lld\n", ans1);
        else printf("%lld\n", ans2);
    }
    return 0;
}

Measured memory_bytes: 7504
n = int(input())
A = list(map(int,input().split()))

dp = [[-float("INF")]*(n+1) for i in range(n+1)]
low = [-float("INF")]*(n+1)
m = 0
a,b = A[:2]
dp[a][b] = 0
dp[b][a] = 0
low[a] = 0
low[b] = 0
base = 0

for _ in range(1,n):
    a,b,c = A[3*_-1:3*_+2]
    q = []
    if a==b==c:
        base += 1
        continue
    m1 = m
    for j in range(3):
        q.append((a,b,max(m,dp[c][c]+1)))
        m1 = max(m1,dp[c][c]+1)

        for i in range(1,n+1):
            q.append((a,i,low[i]))

        if a==b:
            for i in range(1,n+1):
                q.append((c,i,dp[a][i]+1))
                m1 = max(m1,dp[a][i]+1)
                
        a,b,c = b,c,a

    for a,b,v in q:
        dp[a][b] = max(dp[a][b],v)
        dp[b][a] = max(dp[b][a],v)
        low[a] = max(low[a],v)  
        low[b] = max(low[b],v)      
    m = m1
print(max(m,dp[A[-1]][A[-1]]+1)+base)




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

int main() {
    char b;
    cin >> b;
    if(b == 'A'){
        cout << 'T';
    } else if(b == 'T'){
        cout << 'A';
    } else if(b == 'G'){
        cout << 'C';
    } else {
        cout << 'G';
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define all(c) (c).begin(), (c).end()
#define cpresent(c,x) ((c).find(x) != (c).end()) 
#define vpresent(c,x) (find(all(c),x) != (c).end())
#define endl '\n'
using namespace std;

int x, y, a, b;

void solve(){
	cin >> x >> y;
    if(y&1^1 and 2*x <= y and y <= 4*x){
        cout << "Yes\n";
        return;
    }
    cout << "No\n";
}

int32_t main(){
	ios_base::sync_with_stdio(false),cin.tie(nullptr);
	// int t; cin >> t;
	// while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    
    if(C>(A-B)){
      System.out.println(C-(A-B));
    }else{
      System.out.println(0);
    }
  }
}

Measured memory_bytes: 23252
n,m=map(int,input().split())
a=list(map(int,input().split()))

import fractions
count=0
num=a[0]
#何個2の因数を持っているか調べる
while True:
    if num%2==0:
        count+=1
    else:
        break
    num//=2
    
for i in range(n):
    
    if a[i]%(2**count)!=0 or a[i]%(2**(count+1))==0:
        print(0)
        exit()
        

lcm=(a[0]//2)//fractions.gcd(a[0]//2,1)

for i in range(1,n):
    lcm=lcm*(a[i]//2)//fractions.gcd(lcm,a[i]//2)

print((m//lcm-1)//2+1)

Measured memory_bytes: 15060
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
int main()
{
    int r;
    while(cin>>r)
    {
        double ans=(double)r*1.0*(double)acos(-1)*2;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
#define int long long int

const int mod = (int)1e9 + 7;
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n;cin >> n;
    vector<int> in(n), pre;
    int tot;
    FOR(i, n)cin >> in[i];
    tot = 0;
    FOR(i, n)tot ^= in[i], pre.pb(tot);
    vector<int> ans(pre.size());
    map<int, int> zero;
    map<int, int> cum;
    vi prev(n), zCum(n);
    map<int, int> last;
    map<int, bool> found;
    for(int i = pre.size() - 1; i >= 0; i--){
        if(found[pre[i]]){
            prev[i] = last[pre[i]];
        }
        found[pre[i]] =true;
        last[pre[i]] = i;
    }
    int pp = 0;
    FOR(i, n)pp += (pre[i] == 0), zCum[i] = pp;
    
    FOR(i, n){
        if(prev[i])prev[i] = zCum[prev[i]] - zCum[i];
 //       cout << prev[i] << " ";
    }
  //  cout <<endl;
    
    bool first = false;
    FOR(i, pre.size()){
//        cout << pre[i] << " ";
        if(pre[i]){ // xor != 0
            ans[i] = cum[pre[i]] + 1; 
            ans[i] %= mod;
            zero[pre[i]] += ans[i];
            zero[pre[i]] %= mod;
            cum[pre[i]] += zero[pre[i]] * prev[i]; 
            cum[pre[i]] %= mod;
           //we need to consider all the beginnings behind zero
           //add 1 to make this the initial interval 
        }else{ // xor is 0
            if(!first)zero[0] = 1;
            else zero[0] *= 2;
            zero[0] %= mod;
            int j = i -1;
           /* while(j != prev){
                zero[pre[j]] += ans[j];
                zero[pre[j]] %= mod;
                j--;
            }
            for(pii x: zero){
                cum[x.first] += x.second;
                cum[x.first] %= mod;
            }*/
            first = true;
        } 
    }
  //  cout <<endl;
    if(tot)cout << ans[n-1];
    else{
        int sum = 0;
        for(pii x: zero)sum += x.second, sum %= mod;
        cout << sum;
    }
}




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

int main() {
  int N; cin >> N;
  int W[N]; for (int i = 0; i < N; i++) cin >> W[i];

  int ans = 2147483647;
  for (int T = 0; T < N; T++) {
    int left = 0, right = 0;
    for (int j = 0; j <= T; j++) {
      left += W[j];
    }
    for (int j = T + 1; j < N; j++) {
      right += W[j];
    }
    ans = min(abs(left - right), ans);
  }
  cout << ans << endl;
}

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

const ll DIV = 1000000007;

int main() {
  ll n;
  cin >> n;
  ll x = 1;
  for (int i = 1; i <= n; i++) {
    x = i * x % DIV;
  }
  cout << x << endl;

  return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {

    	Scanner sc = new Scanner(System.in);
    	int x,y;
    	x = sc.nextInt();
    	y = sc.nextInt();
    	while(x!=0 || y != 0){
    		if(x<y){
    			System.out.println(x + " " + y);
    		}else{
    			System.out.println(y + " " + x);
    		}
    		
    		x = sc.nextInt();
    		y = sc.nextInt();
    	}

    }
}

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

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

    vector<pair<int, int>> p(n);
    for (auto i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        p[i] = {a, b};
    }
    sort(p.begin(), p.end());

//    int64_t sum = 0;
//    for (auto i = 0; i < n; i++) {
//        sum += p[i].second;
//        if(sum >= k) {
//            cout << p[i].first << endl;
//            return 0;
//        }
//    }

    vector<pair<int64_t, int>> q;
    int64_t prev = 0;
    for (auto i = 0; i < n; i++) {
        q.emplace_back(p[i].second + prev, p[i].first);
        prev += p[i].second;
        // cout << p[i].first << " " << p[i].second << endl;
    }
    auto itr = lower_bound(q.begin(), q.end(), make_pair(k, 0));
    cout << itr->second << endl;

    return 0;
}

Measured memory_bytes: 3188
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int[] calc(string s) {
    auto xs = new int[s.length];
    xs[] = 1;

    for (int i = 0; i < s.length - 1; i++) {
        if (s[i] =='R' && s[i + 1] == 'R') {
            xs[i + 2] += xs[i];
            xs[i] = 0;
        }
    }

    for (int i = cast(int)s.length - 1; i > 0; i--) {
        if (s[i] == 'L' && s[i - 1] == 'L') {
            xs[i - 2] += xs[i];
            xs[i] = 0;
        }
    }

    return xs;
}

void main() {
    string s = read!string;
    auto ans = calc(s);
    writeln(ans.map!text.join(' '));
}



Measured memory_bytes: 4248
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define INF 10000000000000000
#define MOD 998244353
using namespace std;

int main(){
    int N;
    cin >> N;
    
    if(N<1000){
        cout<<"ABC"<<endl;
    }else{
        cout<<"ABD"<<endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

struct Node {
    bool fixed = false;
    bool onKP = false;
    bool Kon  = false;
    int cost = 0;
    int depth = 0;
    int parent = 0;
    ll  root_cost = 0;
};

int K, root;
vector<int> KP;

void makeKP(vector<Node>& NO) {
    int p = K;
    stack<int> ST;
    do {
        ST.push(p);
        p = NO.at(p).parent;
    } while (p != 0);
 
    ll cost = 0;
    int depth = 0;
    while(!ST.empty()) {
        auto pos = ST.top(); ST.pop();
        KP.emplace_back(pos);
        NO[pos].depth = depth++;
        cost += NO[pos].cost;
        NO[pos].root_cost = cost;
        NO[pos].onKP = true;
        NO[pos].fixed = true;
    }
    root = KP[0];
}


ll path(vector<Node>& NO, int x) {
    if (NO[x].fixed) {
        if (NO[x].onKP) {
            return NO[K].root_cost - NO[x].root_cost;
        } else if (NO[x].Kon) {
            return NO[x].root_cost - NO[K].root_cost;
        } else {
            int p = x;
            while (p != root && !NO[p].onKP) p = NO[p].parent;
            if (p == root) {
                return NO[x].root_cost + NO[K].root_cost;
            } else {
                return NO[x].root_cost + NO[K].root_cost - 2 * NO[p].root_cost;
            }
        }
    }

    int p = x;
    int connected = 0;
    stack<int> ST;
    bool KON = false;
    do {
        ST.push(p);
        if (connected == 0 && NO[p].onKP) connected = p;
        p = NO.at(p).parent;
        if (p == K) KON = true;
    } while (p != root);
 
    ll cost = 0;
    int depth = 1;
    while(!ST.empty()) {
        auto pos = ST.top(); ST.pop();
        if (KON && depth > NO[K].depth) NO[pos].Kon = true;
        NO[pos].depth = depth++;
        cost += NO[pos].cost;
        NO[pos].root_cost = cost;
        NO[pos].fixed = true;
    }
    if (connected != 0) {
        return NO[x].root_cost + NO[K].root_cost - 2 * NO[connected].root_cost;
    } else {
        return NO[x].root_cost + NO[K].root_cost;
    }
}

int main() {
    int N; cin >> N;
    vector<Node> NO(N+1);
    rep(i, N-1) {
        int a, b, c; cin >> a >> b >> c;
        NO.at(b).parent = a;
        NO.at(b).cost = c;
    }
    int Q; cin >> Q >> K;
    makeKP(NO);
    int KD = NO[K].depth;

    rep(i,Q) {
        int x, y; cin >> x >> y;
        ll cost = 0;
        int XD;

        if (K != x) cost = path(NO, x);

        if (K == y) {
            cout << cost << endl;
            continue;
        }

        cost += path(NO, y);
        cout << cost << endl;
    }
}


Measured memory_bytes: 6632
#include <iostream>
using namespace std;
int main(){
	long long unsigned int x,y,i;
	while(1){
		cin>> x >> y;
		if(x+y==0)break;
		if(x<y){
			int tmp=x;
			x=y;
			y=tmp;
		}
		int counter=0;
		while(y!=0){
			x=x%y;
			int tmp=y;
			y=x;
			x=tmp;
			counter++;
		}
		cout << x <<" "<<counter<<endl;
	}
}

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

int main() {
  long long s;
  cin >> s;
  int min_num = 753;
  while (s / 100 > 0) {
    int temp = fabs(s % 1000 - 753);
    min_num = min(min_num, temp);
    s /= 10;
  }
  cout << min_num << endl;
  return 0;
}


Measured memory_bytes: 256
import static java.util.Arrays.deepToString;

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		for (;sc.hasNext();) {
			int n = sc.nextInt();
			if (n < 0) break;
			if (n == 0) {
				System.out.println(0);
			} else {
				int p = 0;
				int[] s = new int[20];
				while (n > 0) {
					s[p++] = n % 4;
					n /= 4;
				}
				for (int i = p - 1; i >= 0; i--) {
					System.out.print(s[i]);
				}
				System.out.println();
			}
			
		}
	}
}

Measured memory_bytes: 21636
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;

typedef pair<ll,ll> PAIR;
void Main()
{
    ll H, W;
    cin >> H >> W;

    ll sy, sx;
    cin >> sy >> sx;
    sy--;
    sx--;
    ll gy, gx;
    cin >> gy >> gx;
    gy--;
    gx--;

    vector<string> S(H);
    rep(i, H) cin >> S[i];
    
    deque<PAIR> que;
    que.push_back(PAIR(sx, sy));

    ll INF = 1e18;
    vector<vector<ll> > d(H, vector<ll>(W, INF));
    d[sy][sx] = 0;

    vector<ll> dxs = { -1, 1, 0, 0 };
    vector<ll> dys = { 0, 0, -1, 1 };

    while (que.size() > 0) {
        auto p = que.front();
        que.pop_front();

        ll x = p.first;
        ll y = p.second;

        // 周辺の.
        rep (i, 4) {
            ll nx = x + dxs[i];
            ll ny = y + dys[i];
            if (nx < 0 || W <= nx || ny < 0 || H <= ny) {
                continue;
            }
            if (S[ny][nx] == '.' && d[ny][nx] > d[y][x]) {
                d[ny][nx] = d[y][x];
                que.push_front(PAIR(nx, ny));
            }
        }

        // 周辺5x5の
        for (int dx = -2; dx <= 2; dx++) 
            for (int dy = -2; dy <= 2; dy++) {
                ll nx = x + dx;
                ll ny = y + dy;
                if (nx < 0 || W <= nx || ny < 0 || H <= ny) {
                    continue;
                }
                if (S[ny][nx] == '.' && d[ny][nx] > d[y][x] + 1) {
                    d[ny][nx] = d[y][x] + 1;
                    que.push_back(PAIR(nx, ny));
                }
            }
    }

    if (INF <= d[gy][gx]) {
        put(-1);
    }
    else {
        put(d[gy][gx]);
    }
}
signed main(){ Main();return 0;}

Measured memory_bytes: 13476
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			String s = in.nextString();
			int n = s.length();

			for (int i = 0; i < n-1; i++) {
				if ("AC".equals(s.substring(i, i+2))) {
					out.println("Yes");
					return;
				}
			}
			out.println("No");

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

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

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

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

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

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

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21460
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

class HeavyLightDecomposition {
    // [in[v], out[v]) に対応した列が v を頂点とした部分木に対応
public:
    int n;
    V< V<int> > edges;
    V<int> subsz;
    V<int> in, out, nxt;
    V<int> par;

    HeavyLightDecomposition(int n): n(n), edges(n), subsz(n, 0), in(n), out(n), nxt(n), par(n) {}

    void add_edge(int u, int v) {
        edges[u].emplace_back(v);
    }

    void calc_subsz(int i, int p) {
        subsz[i] = 1;
        par[i] = p;
        if (edges[i].size() > 0 && edges[i][0] == p) swap(edges[i][0], edges[i].back());
        for (int ei = 0; ei < (int)edges[i].size(); ei++) {
            int e = edges[i][ei];
            if (e == p) continue;
            calc_subsz(e, i);
            subsz[i] += subsz[e];
            if (subsz[e] > subsz[edges[i][0]]) swap(edges[i][ei], edges[i][0]);
        }
    }

    void hld(int i, int p, int &t) {
        in[i] = t++;
        for (int e: edges[i]) {
            // nxt[e]: 分解した後の一番上の頂点
            // e が分解後の一番上 (e == edges[i][0]) なら、その上の頂点の nxt を代入
            if (e == p) continue;
            nxt[e] = (e == edges[i][0] ? nxt[i] : e);
            hld(e, i, t);
        }
        out[i] = t;
    }

    int lca(int u, int v) {
        while (true) {
            if (in[u] > in[v]) swap(u, v);
            if (nxt[u] == nxt[v]) return u;
            v = par[nxt[v]];
        }
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    HeavyLightDecomposition hld(n);
    for (int i = 0; i < n; i++) {
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int c; cin >> c;
            hld.add_edge(i, c);
        }
    }

    hld.calc_subsz(0, -1);
    int t = 0;
    hld.hld(0, -1, t);

    int q; cin >> q;
    for (int i = 0; i < q; i++) {
        int u, v; cin >> u >> v;
        cout << hld.lca(u, v) << '\n';
    }
    return 0;
}



Measured memory_bytes: 15196
def resolve():

    def is_prime(n):
        import math
        if n == 1:
            return False
        for i in range(2, int(math.sqrt(n)) + 1):
            if n % i == 0:
                return False

        return True

    x = int(input())
    while True:
        if is_prime(x):
            print(x)
            break
        else:
            x += 1


resolve()


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

#define ll 				long long
#define vi 				vector<ll>
#define vb 				vector<bool>
#define vvi				vector<vi>
#define vvb				vector<vb>
#define vii				vector<pair<ll,ll>>
#define pii				pair<ll,ll>
#define mii 			map<ll,ll>
#define rev(a); 		reverse(a.begin(), a.end());
#define sortv(a); 		sort(a.begin(), a.end());
#define sortd(a); 		sort(a.begin(), a.end(), greater<int>());
#define FOR(i,a,b) 		for (int i = (a); i < (b); i++)
#define ROF(i,a,b) 		for (int i = (b)-1; i >= (a); i--)
#define pb 				push_back
#define mp 				make_pair
#define printv(a);		FOR(_Q,0,(int)(a).size())cout<<(a)[_Q]<<" ";cout<<'\n';
#define IOS 			ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

void solve();

ll MOD = 1000000007;
ll INF = LLONG_MAX;

/*****************************************************************************/
signed main() {
	IOS;
	int a,b,c,d;cin>>a>>b>>c>>d;
	int turn=0;
	while(true) {
		if(turn%2==0) {
			c-=b;
		} else {
			a-=d;
		}
		if (a<=0||c<=0) break;
		turn++;
	}
	if (turn%2==0) {
		cout<<"Yes";
	}else{
		cout<<"No";
	}
}

Measured memory_bytes: 3612
#include<iostream>

using namespace std;

const int N = 101;

int a[N];

int b[N];

int main(){
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++){
    a[i] = 100001;
  }
  for (int i = 1; i < n; i++){
    cin >> b[i];
    a[i] = min(a[i], b[i]);
    a[i + 1] = min(a[i + 1], b[i]);
  }
  int sum = 0;
  for (int i = 1; i <= n; i++){
    sum += a[i];
  }
  cout << sum;
  return 0;
}


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

#define N_MAX 1002
#define W_MAX 20002
#define ll long long

using namespace std;

const int W = 10000;

int n;

struct Block
{
    int w, s, v;
};

Block blocks[N_MAX];

bool operator < (Block a, Block b)
{
    return a.w + a.s < b.w + b.s;
}

ll mxv[W_MAX];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> blocks[i].w >> blocks[i].s >> blocks[i].v;
    sort(blocks + 1, blocks + n + 1);
    for(int i = 1; i <= n; i++)
        for(int j = W; j >= 0; j--)
        {
            if(j <= blocks[i].s)
                mxv[j + blocks[i].w] = max(mxv[j + blocks[i].w],  mxv[j] + blocks[i].v);
        }
    ll ans = 0;
    for(int i = 0; i <= W * 2; i++)
        ans = max(ans, mxv[i]);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))

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

L = [0] * n
R = [0] * n

for i in range(n-1):
    L[i+1] = gcd(L[i], a[i])
    R[n-i-2] = gcd(R[n-i-1], a[n-i-1])

ans = 0

for i in range(n):
    ans = max(ans, gcd(L[i], R[i]))

print(ans)

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

int main() {
  int n; cin>>n;
  string s; cin>>s;
vector<int> r,g,b;
  rep(i,n){
      if(s[i]=='R') r.push_back(i);
      else if(s[i]=='G') g.push_back(i);
      else b.push_back(i);
  }

ll ans=r.size()*g.size()*b.size();
int x=0;
for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
        if(0<=i-j&&i+j<n&&s[i]!=s[i-j]&&s[i]!=s[i+j]&&s[i+j]!=s[i-j]) x++;
    }
}
cout<<ans-x<<endl;

}

Measured memory_bytes: 3632
from collections import deque

S = deque(list(input()))
Q = int(input())
q = [list(input().split()) for _ in range(Q)]
r = 0


for i in range(Q):
    if q[i][0] == "1":
        r += 1
    else:
        if (q[i][1] == "1" and r%2==0)or (q[i][1] == "2" and r%2==1 ):
            S.appendleft(q[i][2])
        else:
            S.append(q[i][2])

S = "".join(S)
if r%2==1:
    S = S[::-1]
print(S)

Measured memory_bytes: 34904
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
  int a, b;
  double c, d;
  cin >> a >> b;
  c = a;
  d = b;
  cout << (a/b)<< " " << (a%b) << " ";
  std::cout<<fixed;
  std::cout<<std::setprecision(5) << (c / d);
  cout << endl;
}


Measured memory_bytes: 3248
pr = [True] * 1001
n = int(input())
ans = 1
MOD = 10 ** 9 + 7
 
for i in range(2, n + 1):
    if pr[i]:
        for j in range(i * 2, n + 1, i):
            pr[j] = False
        cnt = 0
        now = n
        while now:
            cnt += now // i
            now //= i
        ans = ans * (cnt + 1) % MOD
 
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#define N 14
#define MAX 1000000
 
char G[MAX][N];
int top=0;
 
 
int getChar(char c){
  if(c=='A') return 1;
  else if(c == 'C') return 2;
  else if(c=='G') return 3;
  else if(c=='T') return 4;
  else return 0;
}
 
int get(char a[]){
  int sum=0;
  int p=1,i;
  for( i = 0; i < strlen(a); i++){
    sum += p*(getChar(a[i]));
    p *= 5;
  }
  return sum;
}
 
int g1(int data){return data % MAX;}
int g2(int data){return 1 + (data % (MAX-1));}
 
int find(char a[]){
  int key,i,g;
  key = get(a);
  i=0;
  while(1){
    g = (g1(key)+ i * g2(key)) % MAX;
    if(strcmp(G[g],a)==0) return 1;
    else if(strlen(G[g])==0) return 0;
    i++;
  }
  return 0;
}
 
int insert(char a[]){
  int key,i,g;
  key = get(a);
  i=0;
  while(1){
    g = (g1(key) + i * g2(key)) % MAX;
    if(strcmp(G[g],a)==0)return 1;
    else if(strlen(G[g])==0){
      strcpy(G[g],a);
      return 0;
    }
    i++;
  }
  return 0;
}
 
 
int main(){
  int i,j=0,b,k;
  char a[MAX][3],c[MAX],d[MAX];
 
  for(i=0;i<MAX;i++){
    G[i][0] = '\0';
  }
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%s%s",a[i],c);
  if(a[i][0] == 'i'){
    insert(c);
  }
  else{
    if(find(c)){
      printf("yes\n");
      
    }
    else{
      printf("no\n");
      
    }
  }
}
return 0;
}


Measured memory_bytes: 18400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx=1e5+5;
int l,r;
int prime[maxx];
int dp[maxx];
void init()
{
	memset(prime,0,sizeof(prime));
	prime[0]=1;
	prime[1]=1;
	for(int i=2;i<maxx;i++)
	{
		if(!prime[i])
		{
			for(int j=2;i*j<maxx;j++)
			prime[i*j]=1;
		}
	}
}
int main()
{
    int n;
    init();
    cin>>n;
    memset(dp,0,sizeof(dp));
    for(int i=3;i<maxx;i++)
     {
     	if(i%2)
	  {
        if(!prime[i]&&!prime[(i+1)/2])
         dp[i]=dp[i-1]+1;
        else dp[i]=dp[i-1];
      }
      else dp[i]=dp[i-1];
    }
    while(n--)
    {
    	cin>>l>>r;
		cout<<dp[r]-dp[l-1]<<endl;
	}
	return 0;
 } 

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

int read_table(vector<vector<int>> &t);
int calc_score(vector<vector<int>> &t);
int print_table(vector<vector<int>> &t);

int main()
{

	int h;
	vector<vector<int>> t(10,vector<int>(5));
	
	for (;;)
	{
		h=read_table(t);
		if (h==0)
		{
			return 0;
		}

		int total_score=0;
		for (;;)
		{
			//print_table(t);
			int score=calc_score(t);
			//fprintf(stderr, "score: %d\n",score);
			if (score==0)
			{
				cout << total_score << endl;
				break;
			}
			total_score+=score;
		}
	}
}

int read_table(vector<vector<int>> &t)
{
	int h;
	cin >> h;
	if (h==0)
	{
		return 0;
	}

	int y;
	for (y=0;y<10-h;++y)
	{
		for (int j=0;j<5;++j)
		{
			t[y][j]=0;
		}
	}
	for (int i=0;i<h;++i)
	{
		y=(10-h)+i;
		for (int j=0;j<5;++j)
		{
			cin >> t[y][j];
		}
	}

	return h;
}


int calc_score(vector<vector<int>> &t)
{
	int total_score=0;
 	const int multiplier[]={
		0, 0, 0, 0, 0, 0, 0, 3,
		0, 0, 0, 0, 0, 0, 3, 4,
		0, 0, 0, 0, 0, 0, 0, 3,
		0, 0, 0, 0, 3, 3, 4, 5,
	};

 	const int mark[]={
		0, 0, 0, 0, 0, 0, 0, 7,
		0, 0, 0, 0, 0, 0, 14, 15,
		0, 0, 0, 0, 0, 0, 0, 7,
		0, 0, 0, 0, 28, 28, 30, 31,
	};


	// calc score and mark scored stones
	for (int i=10-1;i>=0;--i)
	{
		int s2=t[i][2];
		int p=4;
		if (t[i][0]==s2)
		{
			p+=1;
		}
		if (t[i][1]==s2)
		{
			p+=2;
		}
		if (t[i][3]==s2)
		{
			p+=8;
		}
		if (t[i][4]==s2)
		{
			p+=16;
		}
		//fprintf(stderr,"%d %d\n",i,p);
		total_score+=multiplier[p]*s2;

		if ((mark[p]&1)!=0)
		{
			t[i][0]=0;
		}
		if ((mark[p]&2)!=0)
		{
			t[i][1]=0;
		}
		if ((mark[p]&4)!=0)
		{
			t[i][2]=0;
		}
		if ((mark[p]&8)!=0)
		{
			t[i][3]=0;
		}
		if ((mark[p]&16)!=0)
		{
			t[i][4]=0;
		}
	}

	// shift stone down
	for (int i=0;i<5;++i)
	{
		int current=10-1;
		int lowest=current;
		while (current>=0)
		{
			while ((lowest>=0)&&(t[lowest][i]==0))
			{
				--lowest;
			}
			if (lowest<0)
			{
				// no more stone...
				for (;current>=0;--current)
				{
					t[current][i]=0;
				}
			}
			else
			{
				t[current][i]=t[lowest][i];
				--current;
				--lowest;
			}
		}
	}

	return total_score;
}


int print_table(vector<vector<int>> &t)
{
	fprintf(stderr,"table:\n");
	for (int i=0;i<10;++i)
	{
		for (int j=0;j<5;++j)
		{
			fprintf(stderr," %d",t[i][j]);
		}
		fprintf(stderr,"\n");
	}
	//fprintf(stderr,"\n");
}





Measured memory_bytes: 3116
#include <algorithm>
#include <array>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define FORBE(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
constexpr int INF = 100100100;

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}


using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;

using namespace std;

void visit(const Graph &g, int v, vector< vector<int> >& scc,
    stack<int> &S, vector<bool> &inS,
    vector<int> &low, vector<int> &num, int& time) {
  low[v] = num[v] = ++time;
  S.push(v); inS[v] = true;
  FORBE(e, g[v]) {
    int w = e->dst;
    if (num[w] == 0) {
      visit(g, w, scc, S, inS, low, num, time);
      low[v] = min(low[v], low[w]);
    } else if (inS[w])
      low[v] = min(low[v], num[w]);
  }
  if (low[v] == num[v]) {
    scc.push_back(vector<int>());
    while (1) {
      int w = S.top(); S.pop(); inS[w] = false;
      scc.back().push_back(w);
      if (v == w) break;
    }
  }
}
void stronglyConnectedComponents(const Graph& g,
    vector< vector<int> >& scc) {
  const int n = g.size();
  vector<int> num(n), low(n);
  stack<int> S;
  vector<bool> inS(n);
  int time = 0;
  REP(u, n) if (num[u] == 0)
    visit(g, u, scc, S, inS, low, num, time);
}

void solve(int n, int m, vector<tuple<int,int,int>> const &seq) {
  Graph g(n);
  for (auto &&s : seq) {
    int x, y, z; tie(x, y, z) = s;
    g[x].emplace_back(x, y, z);
    g[y].emplace_back(y, x, z);
  }
  vector<vector<int>> scc;
  stronglyConnectedComponents(g, scc);
  cout << scc.size() << endl;
}

int main() {
  // cout << fixed << setprecision(10);
  int N, M;
  cin >> N >> M;
  vector<tuple<int,int,int>> seq;
  REP(i, M) {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    seq.emplace_back(--X, --Y, Z % 2);
  }
  solve(N, M, seq);
  return 0;
}


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

int main(){
    string s;
    cin>>s;
    int count;
    for(int i=0;i<s.size();i+=2){
        if(s[i]=='R' || s[i]=='U' || s[i]=='D') count+=0;
        else count+=1;
    }
    for(int i=1;i<s.size();i+=2){
        if(s[i]=='L' || s[i]=='U' ||s[i]=='D') count+=0;
        else count+=1;
    }
    if(count==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;

using ll = long long;

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

    ll n, k, x, y;
    cin >> n >> k >> x >> y;

    if (n <= k) cout << x * n << endl;
    else cout << k * x + (n - k) * y << endl;

    return 0;
}


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

string S;
int ans[110000];
signed main() {
    cin>>S;
    int i=0;
    while(i<S.length()){
        int l=0;
        while(S[i]=='R')l++,i++;
        int point=i-1;
        ans[point]+=l/2+l%2;
        ans[point+1]+=l/2;
        int r=0;
        while(i<S.length()&&S[i]=='L')r++,i++;
        ans[point]+=r/2;
        ans[point+1]+=r/2+r%2;
    }
    for(int i=0;i<S.length();i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
}

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

int main() {
    int n, x, t;
    int ans;
    cin >> n >> x >> t;
    if(n % x){
        ans = (n/x + 1)*t;
        cout << ans << endl;
    }else{
        ans = (n/x)*t;
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int t[200005];

int main(){
	int n,m;
	int i,j,k;
	LL a,b,c;
	cin>>n;
	b=0;
	for(i=0;i<n;i++){
		cin>>t[i];
		b+=t[i];
	}
	c=b,a=0;
	for(i=0;i<n;i++){
		a+=t[i];
		c=min(c,abs(b-2*a));
	}
	cout<<c<<endl;
}

Measured memory_bytes: 1024
import std.stdio;
import std.string;
import std.conv;

void main() {
    string s = readln.chomp;
    ulong k = readln.chomp.to!ulong;

    foreach(i, c; s) {
        if (c != '1') {
            if (i < k) {
                s[i].writeln;
                return;
            }
        }
    }
    1.writeln;
}


Measured memory_bytes: 256
s = str(input());MOD = pow(10,9)+7
n = len(s)
dp = [[0,0,0,0]  for _ in range(n+1)]
#i番目まで見て、(x,a,ab,abc)で終わる個数。
dp[0][0] = 1
for i in range(n):
  if s[i] == "A":
    dp[i+1][0] = dp[i][0]
    dp[i+1][1] = dp[i][0]+dp[i][1]
    dp[i+1][2] = dp[i][2]
    dp[i+1][3] = dp[i][3]
  if s[i] == "B":
    dp[i+1][0] = dp[i][0]
    dp[i+1][1] = dp[i][1]
    dp[i+1][2] = dp[i][2]+dp[i][1]
    dp[i+1][3] = dp[i][3]
  if s[i] == "C":
    dp[i+1][0] = dp[i][0]
    dp[i+1][1] = dp[i][1]
    dp[i+1][2] = dp[i][2]
    dp[i+1][3] = dp[i][3]+dp[i][2]
  if s[i] == "?":
    dp[i+1][0] = dp[i][0]*3
    dp[i+1][1] = dp[i][1]*3+dp[i][0]
    dp[i+1][2] = dp[i][2]*3+dp[i][1]
    dp[i+1][3] = dp[i][3]*3+dp[i][2]
  for j in range(4):
    dp[i+1][j] %= MOD
    
ans = dp[n][3]
#print(dp)
print(ans)

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

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

    vector<int> a(n, 0);

    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    
    sort(a.begin(), a.end());

    vector<int> count(max(a[n-1], n), 0);

    int count_num = 0;
    int plus = 1;
    for(int i = 0; i < n-1; i++){
        if(a[i] == a[i+1]){
            count_num++;
            if(i == n-2){
                count[a[i]-1] = count_num+1;
            }
        }
        else {
            count[a[i]-1] = count_num + 1;
            count_num = 0;
            if(i == n-2){
                count[a[i+1]-1] = 1;
            }
        }
    }

    sort(count.begin(), count.end());

    int count_zero = 0;
    for(int i = 0; i < count.size(); i++){
        if(count[i] == 0){
            count_zero++;
        }
    }

    /* 
    if(k >= count.size() - count_zero){
        cout << 0 << endl;
    }
    */
    
    int count_any = 0;
    int ans = 0;
    for(int i = count_zero; i < count.size(); i++){
        if(k >= count.size() - count_zero - count_any){
            cout << ans << endl;
            break;
        }
        count_any++;
        ans += count[i];
    }

    return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll ansp=0,ansn=0;
    vector<ll> a(n),s(n);
    for(int i = 0;i < n;i ++){
        cin >> a[i];
        if(i==0) {
            s[i] = a[i];
        }
        else s[i] = s[i-1] + a[i];
        if(i%2){
            if(s[i]>=0){
                ansp += s[i]+1;
                s[i] -= s[i]+1;
            }
        }else if(s[i]<=0){
            ansp += 1-s[i];
            s[i] += 1-s[i];
        }
    }
    for(int i = 0;i < n;i ++){
        if(i==0) {
            s[i] = a[i];
        }
        else s[i] = s[i-1] + a[i];
        if(i%2){
            if(s[i]<=0){
                ansn += 1-s[i];
                s[i] += 1-s[i];
            }
        }else if(s[i]>=0){
            ansn += s[i]+1;
            s[i] -= s[i]+1;
        }
    }
    cout << min(ansp,ansn) << endl;
    return 0;
}

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

bool isOk(int fst, int snd, int mid)
{
    return fst + snd > mid;
}

int main()
{
    int N;
    cin >> N;
    int L[N];
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
    }
    sort(L, L + N);

    int ans = 0;
    for (int i = 0; i < N - 2; i++)
    {
        int fst = L[i];
        for (int j = i + 1; j < N - 1; j++)
        {
            int snd = L[j];

            int ok = j, ng = N, mid;
            while (ng - ok > 1)
            {
                mid = (ng + ok) / 2;
                if (isOk(fst, snd, L[mid]))
                {
                    ok = mid;
                }
                else
                {
                    ng = mid;
                }
            }
            ans += ok - j;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <istream>
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
int main(){
	int n,r;
	cin>>n>>r;
	if(n<10)cout<<r+100*(10-n)<<endl;
	else cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std; 
int main() 
{
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  int count=0;
  if(a==b && b==c)
  {
    count=1;
  }else
  if((a==b && c!=a)||(a==c && b!=c)||(a!=b && b==c))
  {
    count=2;
  }else
  {
  count =3;
  }
  printf("%d\n",count);
}

Measured memory_bytes: 256
#include <cstdio>

const long long int MOD = 1e9 + 7;

int main(){
	int n, m;
	long long int x, y, xSum=0, ySum=0;
	scanf("%d %d", &n, &m);
	for(int i=0; i<n; ++i){
		scanf("%lld", &x);
		xSum += (2*i + 1 - n) * x;
		xSum %= MOD;
	}
	for(int i=0; i<m; ++i){
		scanf("%lld", &y);
		ySum += (2*i + 1 - m) * y;
		ySum %= MOD;
	}
	printf("%lld\n", xSum * ySum % MOD);
}


Measured memory_bytes: 128
N, M = map(int, input().split())
A=[]
for n in range(N):
    A.append(list(map(int,input( ).split( ))))

candi=[ ]
for m in range(M):
    tmp =[0 for _ in range(M)]
    for n in range(N):
        tmp[A[n][0]-1] +=1
    max_player=max(tmp)
    candi.append(max_player)
    max_sports=tmp.index(max_player)
    for n in range(N):
         A[n].remove(max_sports+1)
 
print(min(candi))

Measured memory_bytes: 4268
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s = "ACL";
    int n;
    cin >> n;
    while(n--) cout << s;
    cout << endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n,y;
	cin>>n>>y;
	for (int i = 0; i <= n; ++i)
	{
		for (int j = 0; j <= n; ++j)
		{
			int k=n-i-j;
			if (k<0)
			{
				continue;
			}
			if (10000*i+5000*j+1000*k==y)
			{
				cout<<i<<" "<<j<<" "<<k<<endl;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 4 * 1e18;
/* -- template -- */

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N);
    rep(i, M){
        int a, b; cin >> a >> b;--a;--b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int d[N];
    rep(i, N)
        d[i] = -1;
    d[0] = 0;
    queue<int> Q;
    Q.push(0);
    while(!Q.empty()) {
        int q = Q.front();Q.pop();
        for(int v : G[q]) {
            if(d[v] == -1)
                Q.push(v);
            d[v] = min(((d[v] == -1) ? INF : d[v]), d[q] + 1);
        }
    }
    cout << ((d[N - 1] == 2) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 13168
#include <iostream>
#include <cstdio>

using namespace std;

int n,k,ans;
int main()
{
    int i;
    cin >> n >> k;
    ans = k;
    for(i = 2; i<= n; i++)
    {
        ans *=(k - 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int c = s.nextInt();

		if(b-a==c-b) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

	}

}

Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n, a[101010];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	int ans = 0, cnt = 0;;
	for(int i = 1; i < n; i++){
		if(a[i] <= a[i-1]){
			cnt++;
		}
		else{
			ans = max(ans,cnt);
			cnt = 0;
		}
	}
	ans = max(ans,cnt);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <math.h>

int main(){
	int n;
	int x[100],y[100];
	
	int i;
	
	scanf("%d",&n);
	
	for(i = 0;i < n;i++)
		scanf("%d",&x[i]);
	
	for(i = 0;i < n;i++)
		scanf("%d",&y[i]);

	double r = 0;
	for(i = 0;i < n;i++){
		r += pow(fabs(x[i]-y[i]),1);
	}
	r = pow(r,1.0/1);
	printf("%lf\n",r);


	r = 0;
	for(i = 0;i < n;i++){
		r += pow(fabs(x[i]-y[i]),2);
	}
	r = pow(r,1.0/2);
	printf("%lf\n",r);

	r = 0;
	for(i = 0;i < n;i++){
		r += pow(fabs(x[i]-y[i]),3);
	}
	r = pow(r,1.0/3);
	printf("%lf\n",r);

	double che = 0;
	
	for(i = 0;i < n;i++)
		if(fabs(x[i]-y[i]) > che)che = fabs(x[i]-y[i]);
	printf("%lf\n",che);	
	
	return 0;
}

Measured memory_bytes: 696
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import time
import math
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
S,W=map(int,input().split())
if not S<=W:
    print("safe")
else:
    print("unsafe")


Measured memory_bytes: 72752
#include<bits/stdc++.h>
using namespace std;
struct zb{
	double x,y;
}a[10000];
double b[2000001];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].x>>a[i].y;
	}
	int cnd=0;
	for(int i=1;i<=n-1;i++){
		for(int j=i+1;j<=n;j++){
			b[cnd++]=sqrt((a[j].x-a[i].x)*(a[j].x-a[i].x)+(a[j].y-a[i].y)*(a[j].y-a[i].y));
		}
	}
	double sum=0;
	for(int i=0;i<cnd;i++)
	sum+=b[i]*2/n;
	cout<< fixed << setprecision(10) << sum;
	
	return 0;
} 

Measured memory_bytes: 256