akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; i++)
using namespace std;
typedef pair<int, int> P;
struct edge {
	int to, cost;
};
class dijkstra {
  private:
	int V;
	int d[100002];
	priority_queue<P, vector<P>, greater<>> que;

  public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }

    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first)
                continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

	int find(int e) {
		return d[e];
	}
};

int gcd(int a, int b) {
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

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

bool prime(int a) {
	if (a == 1)
		return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0)
			return false;
	}
	return true;
}

class Union_Find {
  private:
	vector<int> t, s;

  public:
	Union_Find(int max_length) {
		rep(i, max_length + 1) {
			t.push_back(i);
			s.push_back(1);
		}
	}

	void Union(int x, int y) {
		if (same(x, y))
			return;
		int tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}

	int Find(int n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}

	bool same(int x, int y) {
		return Find(x) == Find(y);
	}

	int get_Size(int a) {
		return s[a];
	}
};

vector<int> primeFactorization(int n) {
	vector<int> re;
	int cnt = 2;
	while (n != 1) {
		if (n % cnt != 0) {
			cnt++;
			continue;
		}
		n /= cnt;
		re.push_back(cnt);
	}
	return re;
}

signed main() {
    int n,k;
    cin>>n>>k;
    if((n-1)*(n-2)/2<k)cout<<-1<<endl;
    else{
        cout<<(n-1)*n/2-k<<endl;
        int a=1,b=2;
        rep(i,(n-1)*n/2-k){
            cout<<a<<" "<<b<<endl;
            b++;
            if(b>n){
                a++;
                b=a+1;
            }
        }
    }
}


Measured memory_bytes: 256
s = gets.chomp

left_is_mm = (1..12).member?(s[0..1].to_i)
right_is_mm = (1..12).member?(s[2..3].to_i)

ans = ''
if left_is_mm
  if right_is_mm
    ans = 'AMBIGUOUS'
  else
    ans = 'MMYY'
  end
else
  if right_is_mm
    ans = 'YYMM'
  else
    ans = 'NA'
  end
end

puts(ans)

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}
 
int main() {
    FAST_IO();
    int A, B; cin >> A >> B;
    cout << max(A + B, max(A - B, A * B)) << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {

  char s[26];
  scanf("%s", s);
  int length = strlen(s);
  int alp[26];
  for (int i = 0; i < 26; i++) {
    alp[i] = 0;
  }
  for (int i = 0; i < length; i++) {
    alp[s[i]-'a']++;
  }
  if (length != 26) {
    printf("%s", s);
    for (int i = 0; i < 26; i++) {
      if (alp[i] == 0) {
        printf("%c\n", i+'a');
        return 0;
      }
    }
  } else {
    int end = -1;
    for (int i = length-1; i > 0; i--) {
      alp[s[i]-'a']--;
      if (s[i] > s[i-1]) {
        end = i-1;
        for (int j = s[end]-'a'+1; j < 26; j++) {
          if (alp[j] == 0) {
            s[end] = j+'a';
            break;
          }
        }
        break;
      }
    }
    if (end == -1) {
      printf("-1\n");
      return 0;
    }
    for (int i = 0; i <= end; i++) {
      printf("%c", s[i]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

const long long mod = 1000000007;

struct mat {
	long long a[3][3];

	mat operator -(mat t) {
		mat r;
		for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++){
			r.a[i][j] = (a[i][j] + mod - t.a[i][j]) % mod;
		}
		return r;
	}

	mat operator *(mat t){
		mat r;
		for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++){
			r.a[i][j] = 0;
			for (int k = 0; k < 3; k++) {
				r.a[i][j] = (r.a[i][j] + a[i][k] * t.a[k][j]) % mod;
			}
		}
		return r;
	}
};

mat pow(mat a, int p)
{
	mat r;
	for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) r.a[i][j] = 0;
	for (int i = 0; i < 3; i++) r.a[i][i] = 1;
	while (p) {
		if (p & 1) r = r * a;
		a = a * a;
		p /= 2;
	}
	return r;
}

int N, M, X[100100];
long long D[100100];

long long get(mat t) {
	return (t.a[2][0] * 5 + t.a[2][1]) % mod;
}

int main()
{
	scanf("%d %d", &N, &M);
	for (int t = 1; t <= M; t++) scanf("%d", &X[t]);
	X[M + 1] = N;

	mat base = { 4,mod - 2,1,1,0,0,0,1,0 };
	mat sum = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };

	for (int i = 1; i <= M + 1; i++) {
		sum = sum * pow(base, X[i] - X[i-1]);
		D[i] = get(pow(base, X[i]) - sum);
		for (int k = 0; k < 3; k++) sum.a[k][k] = (sum.a[k][k] + D[i]) % mod;
	}

	printf("%lld\n", D[M+1]);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

const ll mod = 1000000007;

ll n, k, a[200010];
vector<ll> vecp, vecm;
int cnt0;
ll ans = 1;

signed main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == 0)cnt0++;
		else if (0 < a[i])vecp.push_back(a[i]);
		else vecm.push_back(a[i]);
	}
	if (n < cnt0 + k) {
		cout << 0 << endl;
		return 0;
	}
	if (n == k) {
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if (0 <= a[i])ans = ans * a[i] % mod;
			else ans = ans * -a[i] % mod, cnt++;
		}
		if (cnt % 2)cout << (mod - ans) % mod << endl;
		else cout << ans << endl;
		return 0;
	}
	sort(all(vecp));
	sort(all(vecm));
	if ((int)vecp.size() == 0) {
		if (k % 2) {
			if (cnt0) {
				cout << 0 << endl;
				return 0;
			}
			reverse(all(vecm));
			for (int i = 0; i < k; i++)ans = ans * -vecm[i] % mod;
			cout << (mod - ans) % mod << endl;
		}
		else {
			for (int i = 0; i < k; i++)ans = ans * -vecm[i] % mod;
			cout << ans << endl;
		}
		return 0;
	}
	reverse(all(vecp));
	int j = 0, l = 0;
	int cnt = 0;
	for (int i = 0; i < k; i++) {
		if (j == (int)vecp.size()) {
			ans = ans * -vecm[l] % mod;
			l++; cnt++;
		}
		else if (l == (int)vecm.size()) {
			ans = ans * vecp[j] % mod;
			j++;
		}
		else if (vecp[j] < -vecm[l]) {
			ans = ans * -vecm[l] % mod;
			l++; cnt++;
		}
		else {
			ans = ans * vecp[j] % mod;
			j++;
		}
	}
	if (cnt % 2 == 0) {
		cout << ans << endl;
		return 0;
	}
	if (j == (int)vecp.size())cout << ans * mod_pow(vecp[j - 1], mod - 2, mod) % mod*-vecm[l] % mod << endl;
	else if (l == (int)vecm.size())cout << ans * mod_pow(-vecm[l - 1], mod - 2, mod) % mod*vecp[j] % mod << endl;
	else if (!j)cout << ans * mod_pow(-vecm[l - 1], mod - 2, mod) % mod*vecp[0] % mod << endl;
	else {
		ll p = vecm[l - 1] * vecm[l];
		ll q = vecp[j] * vecp[j - 1];
		if (p <= q)cout << ans * mod_pow(-vecm[l - 1], mod - 2, mod) % mod*vecp[j] % mod << endl;
		else cout << ans * mod_pow(vecp[j - 1], mod - 2, mod) % mod*-vecm[l] % mod << endl;
	}
}


Measured memory_bytes: 6572
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int count = 0;
        int min = 0;
        int tmp = 0;
        int num[] = new int[N];
        for(int i = 0 ; i < N ; i++)
            num[i] = sc.nextInt();
        for(int i = 0 ; i < N - 1; i++)
        {
            min = i;
            for(int j = i + 1 ; j < N ; j++)
            {
                if(num[j] < num[min])
                {
                    min = j;
                }
            }
            if(i != min)
            {
                tmp =   num[i];
                num[i] = num[min];
                num[min] = tmp;
                count++;
            }
        }
        for(int i = 0 ; i < N - 1 ; i++)
            System.out.print(num[i] + " ");
        System.out.println(num[N - 1]);
        System.out.println(count);
    }
}


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

	static int N, K,MIN = 999999999,INDEX0,START,END;
	static int[] initArr, num_line;
	static boolean has0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		K = sc.nextInt();
		initArr = new int[N];
		num_line = new int[N + 1];
		for (int i = 0; i < N; i++) {
			initArr[i] = sc.nextInt();
			if(initArr[i] == 0) {
				INDEX0 = i;
				has0 = true;
			}
		}
		if(!has0) {
			boolean flagZ = false;
			boolean flagF = false;
			if (initArr[0] > 0) {
				INDEX0 = 0;
				num_line[0] = 0;
				flagZ = true;
			}
			if (initArr[N - 1] < 0) {
				INDEX0 = N;
				num_line[N] = 0;
				flagF = true;
			}
			if (!flagZ && !flagF) {
				for (int i = 0; i < initArr.length; i++) {
					int temp = initArr[i + 1];
					if (temp > 0) {
						INDEX0 = i + 1;
						num_line[i] = 0;
						break;
					}
				}
			}
			for (int i = 0; i < N; i++) {
				if (flagF) {
					num_line[i] = initArr[i];
				} else if (flagZ) {
					num_line[i + 1] = initArr[i];
				} else {
					int temp = initArr[i];
					if (temp < 0) {
						num_line[i] = temp;
					} else {
						num_line[i + 1] = temp;
					}
				}
			}
		}else {
			num_line = initArr;
		}
		if(INDEX0 == 0) {
			START = 0;
			END = K;
		}else if (INDEX0 == N) {
			START = N - K;
			END = N;
		}else {
			START = INDEX0 > K ? INDEX0 - K : 0;
			END = (N - INDEX0) > K ? INDEX0 + K : N;
		}
		if(has0) {
			END--;
			K--;
		}
		for (int i = START; i <= END - K; i++) {
			int left = Math.abs(num_line[i]);
			int right = Math.abs(num_line[i + K]);
			int min = left < right ? left : right;
			int size = left + right + min;
			MIN = size < MIN ? size : MIN;
		}
		System.out.println(MIN);
	}
}


Measured memory_bytes: 62076
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 1145141919810ll
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(15)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

struct edge{
  int from, to, cost;
};

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

  int N, M, P, A, B, C; cin >> N >> M >> P;
  vector<edge> G;
  vector<int> graph[2500], grapha[2500];
  int d[2500]; fill(d, d+N, INF); d[0] = 0;
  REP(i, M){
    cin >> A >> B >> C;
    A--; B--; C-=P;
    G.push_back({A, B, -C});
    graph[B].pb(A);
    grapha[A].pb(B);
  }

  queue<int> que; que.push(N-1);
  bool visit[2500] = {}, visita[2500] = {}; visit[N-1] = 1; visita[0] = 1;
  while(!que.empty()){
    int pos = que.front(); que.pop();
    REP(i, graph[pos].size()){
      int nx = graph[pos][i];
      if(!visit[nx]){
        visit[nx] = 1; que.push(nx);
      }
    }
  }

  que.push(0);
  while(!que.empty()){
    int pos = que.front(); que.pop();
    REP(i, grapha[pos].size()){
      int nx = grapha[pos][i];
      if(!visita[nx]){
        visita[nx] = 1; que.push(nx);
      }
    }
  }

  REP(i, G.size()){
    int p = G[i].from, q = G[i].to;
    if(!(visit[p] and visit[q] and visita[p] and visita[q])){
      G.erase(G.begin()+i);
      i--;
    }
  }

  bool close = 0;
  REP(cnt, N){
    REP(i, G.size()){
      edge e = G[i];
      int tmp = d[N-1];
      if(d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from] + e.cost;
        if(cnt == N-1){
          close = 1; break;
        }
      }
    }
  }

  if(close){
    cout << -1 << endl;
  } else {
    cout << max(0ll, -d[N-1]) << endl;
  }
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;

int main() {
	ll n, k;
	ll ans = 0;

	cin >> n >> k;

	if (k != 0) {
		FOR(i, 1, n + 1) {
			ll p = n / i;
			ll q = n % i;
			ans += max((ll)0, (i - k) * p) + max((ll)0, q - k + 1);
		}
	}
	else {
		ans = n * n;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#ARC98 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = [0] + LI()
b = list(accumulate(a))
l,r,tmp,ans = 0,0,0,0
while r < n:
    if b[r+1] - b[l] == tmp ^ a[r+1]:
        tmp ^= a[r+1]
        r += 1
        ans += r-l
    elif l == r:
        tmp ^= a[l]
        l += 1
        r += 1
    else:
        l += 1
        tmp ^= a[l]
print(ans)


Measured memory_bytes: 82252
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define maxn (int)1e5+100
int n, m, odw[maxn];
long long wynik[maxn], dp[maxn],  prefiks[maxn], sufiks[maxn];
vector <int> v[maxn], v1[maxn];

void dfs1(int x)
{
	odw[x]=1;
	dp[x]=1;
	for (int i=0; i<(int)v[x].size(); i++)
	{
		if (odw[v[x][i]]!=1)
		{
			dfs1(v[x][i]);
			dp[x]=(dp[x]*(dp[v[x][i]]+1))%m;
		}
	}
}

void dfs(int x, long long ile)
{
	odw[x]=2;
	int wsk1=1;
	int wsk2=(int)v[x].size();
	prefiks[0]=1;
	sufiks[wsk2+1]=1;
	long long ile1=1;
	for (int i=0; i<(int)v[x].size(); i++)
	{
		if (odw[v[x][i]]==2)
		{
			prefiks[wsk1]=prefiks[wsk1-1];
			wsk1++;
			continue;
		}
		prefiks[wsk1]=(prefiks[wsk1-1]*(dp[v[x][i]]+1))%m;
		wsk1++;
		ile1=(ile1*(dp[v[x][i]]+1))%m;
	}
	for (int i=(int)v[x].size()-1; i>=0; i--)
	{
		if (odw[v[x][i]]==2)
		{
			sufiks[wsk2]=sufiks[wsk2+1];
			wsk2--;
			continue;
		}
		sufiks[wsk2]=(sufiks[wsk2+1]*(dp[v[x][i]]+1))%m;
		wsk2--;
	}
	if (x!=1) wynik[x]=((ile+1)*(ile1))%m; // tutaj z pewnością xd
	else wynik[x]=(ile1)%m;
	if (x==1) ile=(ile-1+m)%m;
	for (int i=0; i<(int)v[x].size(); i++)
	{
		if (odw[v[x][i]]==2)
		{
			v1[x].pb(0);
			continue;
		}
		v1[x].pb((((prefiks[i])*(sufiks[i+2]))%m * (ile+1))%m);
	}
	for (int i=0; i<(int)v[x].size(); i++)
	{
		if (odw[v[x][i]]==2) continue;
		dfs(v[x][i], v1[x][i]);
	}
}

int32_t main()
{
	scanf("%lld%lld", &n, &m);
	for (int i=1; i<n; i++)
	{
		int a, b;
		scanf("%lld%lld", &a, &b);
		v[a].pb(b);
		v[b].pb(a);
	}
	dfs1(1);
	dfs(1, 1);
	for (int i=1; i<=n; i++)
	{
		printf("%lld\n", wynik[i]%m);
	}
}


Measured memory_bytes: 21888
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
#ifdef LOCAL_TEST
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif
	string yes = "Possible", no = "Impossible";
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	map<int, int> mp;
	for(auto& i : a) mp[-i]++;
	
	int b = -mp.begin()->fi;
	for(int i = b; i >= b/2+1; --i) {
		if(mp[-i] < 2) {
			cout << no << endl;
			return 0;
		}
	}
	if(b%2 == 0) {
		if(mp[-b/2] != 1) {
			cout << no << endl;
			return 0;
		}
	}
	else {
		if(mp[-(b/2+1)] != 2) {
			cout << no << endl;
			return 0;
		}
	}
	cout << yes << endl;
	return 0;
}

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

int main() {
  int A,B;
  string op;
  cin >> A >> op >> B;
  
  // ここにプログラムを追記
  if (op == "+"){
	  cout << A + B << endl;
  }
  else if (op == "-"){
	  cout << A - B << endl;
  }
    
}


Measured memory_bytes: 3592
import itertools

n = int(input())
A = []
for i in range(n):
    line = input()
    A.append([int(x) for x in line.split()])


V = set(range(n))
Vnew = {0}  # ??¨???????°???¨?????????
weights = []

while V != Vnew:
    T = V - Vnew
    minw = float('inf')
    for u, v in itertools.product(Vnew, T):
        w = A[u][v]
        if w != -1 and minw > w:
            e = (u, v)
            minw = w
    Vnew.add(e[1])
    weights.append(minw)

print(sum(weights))

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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long  ll;
#define endl '\n'


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


const int MOD = 1000000007;

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

int a, p;

void Input() {
	
   cin >> a >> p;
}

void Solve() {

	cout << ((a*3) + p) / 2 << endl;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}


Measured memory_bytes: 256
import sys
import collections
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")

n=int(input())
d=list(map(int,input().split()))

c=collections.Counter(d)
if c.most_common()[0][1]>2:
    print(0)
    quit()
if 0 in c:
    if c[0]==1:
        print(0)
        quit()

li=list(map(int,c.keys()))
li.append(0)
ans=0
# print(li)
# print(len(li))
for i in range(2**len(li)):
    hour=[]
    for j in range(len(li)):
        if c[li[j]]==2:
            hour.append(li[j])
            hour.append(24-li[j])
            continue
        if i&(1<<j):
            hour.append(li[j])
        else:
            hour.append(24-li[j])
    hour.sort()
    # print(hour)
    tmp=24+hour[0]-hour[-1]
    for j in range(len(hour)-1):
        tmp=min(tmp,hour[j+1]-hour[j])
    # print(tmp)
    ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 42352
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

/*================================================
	Disjoint Set
================================================*/
class DisjointSet {
private:
	vector<int> rank, p;

	void link(int x, int y) {
		if (rank[x] > rank[y]) {
			p[y] = x;
		}
		else {
			p[x] = y;
			if (rank[x] == rank[y]) rank[y]++;
		}
	}
	int findSet(int x) {
		if (x != p[x]) p[x] = findSet(p[x]);
		return p[x];
	}

public:
	DisjointSet() {}
	DisjointSet(int size) {
		rank.resize(size + 1, 0);
		p.resize(size + 1, 0);
		repc(i, 1, size) makeSet(i);
	}
	void makeSet(int x) {
		p[x] = x;
		rank[x] = 0;
	}
	bool same(int x, int y) {
		return findSet(x) == findSet(y);
	}
	void unite(int x, int y) {
		link(findSet(x), findSet(y));
	}
};

int pp[100001];

int main()
{
	int N, M, x, y, ans = 0;

	cin >> N >> M;
	repc(i, 1, N) cin >> pp[i];

	DisjointSet DS = DisjointSet(N);

	rep(i, M) {
		cin >> x >> y;
		DS.unite(x, y);
	}

	repc(i, 1, N) {
		if (DS.same(i, pp[i])) ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  vl v(n);
  rep(i, n) cin >> v[i];
  vector<vl> c(51, vl(51, 0));
  c[0][0] = 1;
  rep(i, 50) rep(j, 50) {
    if(c[i][j] == 0) continue;
    c[i + 1][j] += c[i][j];
    c[i + 1][j + 1] += c[i][j];
  }
  ll mx = *max_element(all(v));
  map<ll, ll, greater<ll>> mp;
  rep(i, n) mp[v[i]]++;
  double ans = 0;
  ll m = 0;
  for(auto p : mp) {
    ll num = p.first;
    ll cnt = p.second;
    if(a - m > cnt) {
      m += cnt;
      ans += num * cnt;
    } else if(a - m == cnt) {
      ans += num * cnt;
      ans /= double(a);
      printf("%.10f\n1\n", ans);
      return 0;
    } else {
      ans += num * (a - m);
      ans /= double(a);
      ll ans2 = c[cnt][a - m];
      if(num == mx)
        for(ll i = a - m + 1; i <= b - m; i++) ans2 += c[cnt][i];
      printf("%.10f\n", ans);
      cout << ans2 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
N = int(input())

divisors = []
for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        divisors.append(i)
        if i != N // i:
            divisors.append(N//i)

m_list = []
for k in divisors:
    if N % k == 0 and N > k:
        m = int((N / k) - 1)
        if k == N%m:
            A = N / (m + 1)
            m_list.append(m)

print(sum(m_list))

Measured memory_bytes: 3296
# ABC109C - Skip
def gcd(a, b):
    while a:
        a, b = b % a, a
    return b
        

n, x = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
d = abs(x - lst[0])
for i in range(n):
    dif = abs(x - lst[i])
    if dif % d == 0:
        continue
    d = gcd(d, dif)
print(d)

Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
      
int main(){
  int N,sum=0;
  cin >> N;
  vector<int> L(N);
  for(int i=0;i<N;i++){
    cin >> L.at(i);
    sum+=L.at(i);
  }
  sort(L.begin(),L.end());
  if(L.at(N-1)<sum-L.at(N-1)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Atcoder_with_csharp
{
    using cl = Console;

    class Program
    {
        static void Main(string[] args)
        {
            var ap = new ArgsProcess();
            var s = ap.Args[0];

            var count = 0;

            int len = s.Length;
            for (int i = 0; i < (len / 2); i++)
            {
                if (s[i] == s[len - i - 1])
                {
                    //cl.WriteLine("same");
                }
                else
                {
                    //cl.WriteLine("not same");
                    count++;
                }
            }
            cl.WriteLine(count);
        }
    }


    public class ArgsProcess
    {
        // 引数格納
        public string[] Args { get; set; }

        // 引数格納(int)
        public int[] ArgsInt
        {
            get { return GetArgsAsArrayOfInteger(); }
        }

        public ArgsProcess(string args)
        {
            initialize(args);
        }

        public ArgsProcess()
        {
            // 入力してから
            var args = Console.ReadLine();
            initialize(args);
        }

        private void initialize(string args)
        {
            // スペース区切り
            var s = args.Split(' ').ToList();
            s.RemoveAll(x => x == "");

            this.Args = s.ToArray();
        }

        private int[] GetArgsAsArrayOfInteger()
        {
            int[] ret = Array.Empty<int>();
            try
            {
                // intにparse
                ret = this.Args.ToList().ConvertAll(x => int.Parse(x)).ToArray();
            }
            catch
            {
                Console.WriteLine("This args is not integer.");
            }
            return ret;
        }

    }
}

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

using namespace std;
#define pb push_back
#define vi vector<int>
#define ll long long
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll,ll>


int main() {
	
	int a,b;
	cin>>a>>b;
	int num=max(a,b);
	int var=min(a,b);
	if(num>8)
	{
		cout<<":(";
		return 0;
	}
	cout<<"Yay!";
	

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while (scanf ("%d",&n)!=EOF)
    {
    int prime[n+1],i,j;
    for (i=0;i<=n;i++)
        prime[i]=1;
    prime[0]=0;
    prime[1]=0;
    for (i=2;i<=sqrt(n);i++)
    {
        if (prime[i]==1)
        {
            for(j=2;i*j<=n;j++)
                prime[i*j]=0;
        }
    }
    int cnt=0;
    for (i=0;i<=n;i++)
    {
        if (prime[i]!=0)
            cnt++;
    }
    cout<<cnt<<endl;
    }
}


Measured memory_bytes: 7052
#include<bits/stdc++.h>
using namespace std;
string b;
int a,c;
double d;
stringstream ss;
int main(){
    cin>>a>>b;
    ss<<b;ss>>c;
    d=sqrt(a*pow(10,b.length())+c);
    if(d-(int)d==0)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
using namespace std;
// clang-format on

main {
  int n, x;
  while (cin >> n >> x, n || x) {
    int c = 0;
    loop(i, 1, n - 1) loop(j, i + 1, n) loop(k, j + 1, n + 1) c += i + j + k == x;
    cout << c << endl;
  }
}

Measured memory_bytes: 3100
# C
n, m = map(int,input().split())
plst = []
result = []
for _ in range(m):
    p, s = input().split()
    p = int(p)
    plst.append(p)
    result.append(s)
rui = list(set(plst))
tmps = [[] for _ in range(len(rui))]
dic = dict(zip(rui, tmps))

for p, s in zip(plst, result):
    dic[p].append(s)

ac = 0
wa = 0

for item in dic.values():
    if 'AC' in item:
        ac += 1
        for l in item:
            if l == 'AC':
                break
            else:
                wa += 1
print(ac, wa)

Measured memory_bytes: 33464
S = input()

runlength = []
prevc = "R"
count = 0
for c in S:
    if c != prevc:
        runlength.append(count)
        count = 1
    else:
        count += 1
    prevc = c
runlength.append(count)

pairs = len(runlength)//2
A = [0 for i in range(len(S))]
index = 0
for i in range(pairs):
    R = runlength[2*i]
    L = runlength[2*i+1]
    A[index+R-1] = (R+1)//2 + L//2
    A[index+R] = R//2 + (L+1)//2
    index += runlength[2*i]+runlength[2*i+1]

print(*A)

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

int main() {
  long long int n, temp, count=0;
  vector<long long int> nums;
  cin >> n;
  for (long long int i=0; i<n; i++) {
    cin >> temp;
    if (temp%2==0) nums.push_back(temp);
  }
  for (long long int i=0; i<nums.size(); i++) {
    while (nums[i]%2==0) {
      nums[i]/=2;
      count++;
    }
  }
  cout << count;
  return 0;
}

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

int main(){

    int A1,A2,A3;
    cin >> A1 >> A2 >> A3;

    if(A1+A2+A3 >= 22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <string>

using namespace std;

int a[123456];
int num;
int flag;

void dfs(int k)
{
    if(num>=200000){
        flag = 1;
        return;
    }
    if(a[k]==2) return;
    num++;
    dfs(a[k]);
}

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    num=1;
    flag=0;
    dfs(1);
    if(flag){
        puts("-1");
        return 0;
    }
    printf("%d\n",num);
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int MOD = 1000000007;

int main() {
	map<ll, ll>buka;
	ll N;
	cin >> N;
	ll c;
	for (int i = 1; i < N; i++) {
		cin >> c;
		buka[c]++;

	}
	for (int i = 1; i <= N;i++) {

		cout <<buka[i]<<endl;

	}
}

Measured memory_bytes: 16136
#include "bits/stdc++.h"
using namespace std;
const int N=1e6+20,MOD=1e9+7;
int x,y,f[N],ie[N];

int power(int a,int b)
{
	int num=a,ans=1;
	for(int i=0;i<31;i++)
	{
		if(b&(1<<i)) ans=(1ll*ans*num)%MOD;
		num=(1ll*num*num)%MOD;
	}
	return ans;
}

int inverse_euler(int n)
{
	return power(n,MOD-2);
}

int ncr(int n,int r)
{
	return (1LL*f[n]*((1LL*ie[r]*ie[n-r])%MOD))%MOD;
}

void precompute()
{
	f[0]=1;
	f[1]=1;
	for(int i=2;i<N;i++) f[i]=(1LL*f[i-1]*i)%MOD;
	for(int i=0;i<N;i++) ie[i]=inverse_euler(f[i]);
}

int main()
{
	cin>>x>>y;
	int sum=x+y;
	if(sum%3) return 0 * printf("0");

	int col=sum/3,row=2*col,n=col,r=0;
	while(r<=n)
	{
		if(x==row and y==col) break;
		row--,col++,r++;
	}
	if(r==n+1) return 0 * printf("0");

	precompute();
	cout<<ncr(n,r);
}

Measured memory_bytes: 8064
S=[0 if c =='0' else 1 for c in input()]
a = S[0::2]
b = S[1::2]
x = a.count(1)
y = b.count(1)
if x > y:
    ans = (len(a)-x) + (y)
else:
    ans = (len(b)-y) + (x)
print(ans)


Measured memory_bytes: 10268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second
  

int main() {

  int k,s;
  cin>>k>>s;
    
    int ct=0;
  for(int i=0;i<=k;++i)
  for(int j=0;j<=k;++j){
    int  z = s-i-j;
      if(z>=0&&z<=k)
       ct++;
  }
  
  cout<<ct;
  
	return 0;
}

Measured memory_bytes: 256
import scala.annotation.tailrec
import scala.io.StdIn

object Main extends App {
  
  @tailrec def loop(x: Int, y: Int): Unit = {
    if(x == 0 && y == 0) ()
    else {
      if(x <= y) println(x + " " + y)
      else println(y + " " + x)

      val a = StdIn.readLine().trim.split(' ').map(_.toInt)
      loop(a(0), a(1))
    } 
  }

  val Array(fx, fy) = StdIn.readLine().trim.split(' ').map(_.toInt)

  loop(fx, fy)

}


Measured memory_bytes: 46396
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;
typedef long long ll;

template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a*b/gcd(a,b);
}

int main(void){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll a_,b_,l=lcm<ll>(c,d);
    a_=(a-1)/c+(a-1)/d-(a-1)/l;
    b_=b/c+b/d-b/l;
    cout<<(b-a+1)-(b_-a_);
}
/*
*/


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC161
{
    class A
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine("{0} {1} {2}", a[2], a[0], a[1]);
        }
    }
}


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

int main() {
  string n;
  cin >> n;
  
  bool isSeven = false;
  for (int i = 0; i < n.size(); ++i) if (n.at(i) - '0' == 7) isSeven = true;
  
  isSeven ?  cout << "Yes" << endl : cout << "No" << endl; 
  
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()

long long fact(long long n){
	return n==1LL ? 1LL : fact(n-1)*n;
}
int main(){
	long long n; scanf("%lld",&n);
	printf("%lld\n",fact(n));
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<math.h>

int main(void)
{
	double h;
	double k;
	long int ans;
	
	scanf("%lf",&h);
	
	k = log(h)/log(2);
	
	ans = pow(2,(int)k+1)-1;
	printf("%ld",ans);
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Console.WriteLine(input[0] - input[1] + 1);
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N,M;
    cin >> N >> M;
    cout << (N == M ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3636
#include <stdio.h>
double zenka(double q)
{    
    double x=q/2;
    while(x*x*x-q>=0.00001*q || x*x*x-q<=-0.00001*q)
    {        
        x=x-((x*x*x)-q)/(3*x*x);    
        
    }        
    return x;
    
}
int main(void)
{    
    int q;        
    while(1)    
    {        
        scanf("%d",&q);        
        if(q==-1) break;        
        else        
        {            
            printf("%.6f\n",zenka(q));        
            
        }    
        
    }        return 0;}


Measured memory_bytes: 2676
// kartikay26
#include <bits/stdc++.h>
using namespace std;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#ifdef LOCAL
#include "prettyprint.hpp"
#else
#define debug(...)
#define debuga(arr, n)
#define debugg(grid, n) 
#endif
typedef long long int ll;
#define int ll
#define F first
#define S second
#define float double
const int inf = LLONG_MAX;
int get() { int x; cin >> x; return x; }
void getl(int* ar, int sz){ for(int i=0; i<sz; i++) cin >> ar[i];}
template <typename T> void print(T x) { cout << x << "\n";}
template <typename T> void prints(T x) { cout << x << " ";}
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int mod = 1e9+7;
const int N = 1e6+1;

int h[N], cost[N];

int32_t main(){
	fast_io();
	int n = get();
	int k = get();
	getl(h, n);
	for (int i = 1; i < n; ++i) {
		vi l;
		for (int j = 1; j <= k; ++j) {
			if(i>=j) l.push_back(cost[i-j] + abs(h[i] - h[i-j]));
		}
		cost[i] = *min_element(all(l));
	}
	print(cost[n-1]);
	return 0;
}

Measured memory_bytes: 5120
import sys
from sys import stdin
import numpy as np

def main():
    #pass
    S = list(input())
    if len(set(S)) != 2:
        print("No")
        return
    else:
        count=0
        for i in range(1, 4):
            #print(S[0],S[i])
            if S[0]==S[i]:
                count+=1
        if count==1:
            print("Yes")
        else:
            print("No")
        return
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 21504
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<n;i++)
#define REP1(i,n) for(long long i=1;i<=n;i++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();ite++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<a<<endl;
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

//---------------------
#define MAXN 100
//---------------------

ll n,x,l[MAXN];
ll jumppoint[MAXN+5];
ll ret=-1;
int main(){
	cin>>n>>x;
	REP(i,MAXN+5) jumppoint[i]=100000;
	REP(i,n){
		cin>>l[i];
	}
	jumppoint[0]=0;
	REP1(i,n){
		jumppoint[i]=jumppoint[i-1]+l[i-1];
	}
	//PRTLST(jumppoint,n+1);
	REP1(i,n){
		if(jumppoint[i]>x) {ret=i;break;}
	}
	if(ret<0) ret=n+1;
	cout<<ret<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int city,way;
    scanf("%d %d",&city,&way);
    int ans[city];
    for(int i = 0;i < city;)
        ans[i++] = 0;
    for(int i = 0;i < way;i++)
    {
        int temp1,temp2;
        scanf("%d %d",&temp1,&temp2);
        ans[temp1-1]++;
        ans[temp2-1]++;
    }
    for(int i = 0;i < city;i++)
        printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
template< class t>
long long int gcd( t g,t h )
{
    return ( h==0 ? g : gcd(h,g%h) );
}
 
 
struct Comp {
  bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {
    if (a.first != b.first) {
      return a.first < b.first;
    }
    return a.second > b.second;
  }
 
}comp_functor;
 
 
int main() 
{
    ios_base::sync_with_stdio(false) ; cin.tie(0) ;
    
    long long int i,j,k,n,ans=3000006,te=0,w=0,e=0,a[3000006],temp=0;
    string s;
    
    cin>>n>>s;
    
    for(i=0;i<n;i++)
    {
        if(s[i]=='E')
        {
            te++;
        }
    }
   
    for(i=0;i<n;i++)
    {
        if(s[i]=='E')
        {
            e++;
            temp = w+te-e;
        }
        else
        {
            temp = w+te-e;
            w++;
        }
        ans = min(temp,ans);
    }
    
    cout<<ans<<endl;
   
    return 0;
}  

Measured memory_bytes: 720
'use strict'
const f = n => {
  let num = 0
  if (n % 2 === 0) {
    num = n / 2
  } else {
    num = 3 * n + 1
  }
  return num
}

function main(input) {
  let a = Number(input)
  const set = new Set()
  set.add(a)

  let i = 1
  while (true) {
    i++
    let tmp = f(a)
    // console.log(tmp)

    if (set.has(tmp)) {
      console.log(i)
      return i
    } else {
      a = tmp
      set.add(tmp)
    }
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7500
import collections
from collections import deque

h,w = map(int, input().split())
maze=[list(input()) for i in range(h)]

# 枠を囲う
for i in range(h):
    maze[i]=['#']+maze[i]+['#']
maze=[['#' for i in range(w+2)]]+maze+[['#' for i in range(w+2)]]

def clear_maze(sx, sy):

    INF=-10**9
    distance = [[INF for i in range(w+2)] for j in range(h+2)]
    #    distance = [[None]*field_x_length]*field_y_length
    def bfs():
        d = deque()
        d.append((sx, sy))
        distance[sx][sy] = 0
        ans=0

        while len(d):
            x, y = d.popleft()

            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]

                if (0 <= nx and  0 <= ny  and maze[nx][ny] != '#' and distance[nx][ny] == INF):
                    d.append((nx, ny))
                    distance[nx][ny] = distance[x][y] + 1
                    ans=max(distance[nx][ny],ans)


        return ans

    return bfs()

m=0
for i in range(1,h+1):
    for j in range(1,w+1):
        if maze[i][j] == '.':
            x=clear_maze(i,j)
            m=max(x,m)
print(m)

Measured memory_bytes: 44268
N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
a = A.group_by(&:itself).map{ |k, v| v.count }.sort

if K>=a.size
  puts 0
else
  c = a[0, a.size-K]
  puts c.inject(:+)
end


Measured memory_bytes: 46832
// AOJ GRL_6_A
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

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

using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vc;

const int INF = 0x3fffffff;

// ?????§???????±???????(Dinic??????bfs()??????????????¨Ford-Fulkerson???)
class Flow{
	public:
		int N;	// ????????°
		vector<vc> F, C, edge;	// F:????????°?????? C:???????????? edge:??£??\????????????
		vector<bool> bf;	// ??????????????£???????????????
		vector<int> lv;	// S??????????????¢

		// ????????????????????? n:????????°
		Flow(int n): F(n,vc(n)), C(n,vc(n)), N(n), edge(n) {}

		// ??????????????????
		void addEdge(int f, int t, int c){
			F[f][t] = C[f][t] = c;
			edge[f].push_back(t);
			edge[t].push_back(f);
		}

		// s????????????????????¢????±?????????????????????????????????¨DFS??§??????????????¢??????????????¢?´¢??????
		int bfs(int S, int T){
			lv.assign(N, 0);
			queue<int> que;
			que.push(S);
			lv[S] = 1;
			while( !que.empty() ){
				int n = que.front(); que.pop();
				for(auto v: edge[n]) if( !lv[v] && F[n][v] ){
					lv[v] = lv[n] + 1;
					que.push(v);
				}
			}
			return lv[T];
		}

		// ?¢?????????????DFS??§??¢???
		int flow(int n, int c, int T){
			if( n == T ) return c;
			bf[n] = true;
			for(int v: edge[n]) if( F[n][v] && !bf[v] && lv[v] > lv[n] ){	// ??????????????¶??????????????¨bfs()?????????????????????
				int f = flow(v, min(c, F[n][v]), T);
				F[n][v] -= f;
				F[v][n] += f;
				if( f > 0 ) return f;
			}
			return 0;
		}

		// ?????§???????±???????
		int maxFlow(int S, int T){
			int ret = 0;
			while( bfs(S,T) )	// bfs()???????????´?????????????????????????????????
				for(int add; bf.assign(N,0), add = flow(0, INF, T);) ret += add;
			return ret;
		}

		// ??°???????????????????????????
		void clear(){ rep(i,N) rep(j,N) F[i][j] = C[i][j]; }
};

int main(){
	int V, E;
	cin >> V >> E;
	Flow fl(V);
	rep(i, E){
		int u, v, c;
		cin >> u >> v >> c;
		fl.addEdge( u, v, c );
	}

	cout << fl.maxFlow(0, V-1) << endl;

	return 0;
}

Measured memory_bytes: 3244
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
L = [LIST() for i in range(M)]

def dijkstra(E, start):
    N_d = len(E)
    dist = [INF] * N_d
    dist[start] = 0
    q = [(0, start)]
    while q:
        dist_v, v = heappop(q)
        if dist[v] != dist_v:
            continue
        for u, dist_vu in E[v]:
            dist_u = dist_v + dist_vu
            if dist_u < dist[u]:
                dist[u] = dist_u
                heappush(q, (dist_u, u))
    return dist

graph = defaultdict(list)
for a, b in L:
    graph[a-1].append((b-1, 1))
    graph[b-1].append((a-1, 1))

ans = 0
for a, b in L:
    E = deepcopy(graph)
    E[a-1].remove((b-1, 1))
    E[b-1].remove((a-1, 1))
    d = dijkstra(E, a-1)
    if d[b-1] == INF:
        ans += 1
print(ans)

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

int main() {
  int A,B,C,K;
  cin >>A>>B>>C>>K;
  if(A>=K){
    int a=0;
    for(int i=0;i<K;i++){
      a++;
    }
    cout<< a << endl;
  }
   else if(A<K&&A+B>=K){
    int a=0,b=0;
     for(int i=0;i<A;i++){
     a++;
     }
     
     cout<<a<<endl;
   }
   else {
    int a=0,b=0,c=0;
     for(int i=0;i<A;i++){
      a++;
     }
    for(int i=0;i<K-A-B;i++){
      c--;
     }
     cout<<a+b+c<<endl;
   }
}


Measured memory_bytes: 3584
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int h,n,a,cnt=0;
  cin >> h >> n;
  for(int i=0; i<n; i++) {
    cin >> a;
    cnt+=a;
  }
  if(cnt>=h) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	char s[5];
	scanf("%s",s);
	int mae = (s[0] - '0') * 10 + (s[1] - '0'), maecheck = 0, ushiro =  (s[2] - '0') * 10 + (s[3] - '0'), ushirocheck = 0;
	if(mae >= 1 && mae <= 12) maecheck = 1;
	if(ushiro >= 1 && ushiro <= 12) ushirocheck = 1;
	if(maecheck == 1 && ushirocheck == 1) printf("AMBIGUOUS");
	if(maecheck == 0 && ushirocheck == 1) printf("YYMM");
	if(maecheck == 1 && ushirocheck == 0) printf("MMYY");
	if(maecheck == 0 && ushirocheck == 0) printf("NA");
	return 0;
}

Measured memory_bytes: 128