akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

//Strong Connected Component Decomposition
vector<int> g[1010];
vector<int> rg[1010];
vector<int> vs;
bool use[1010];
int ord[1010];
int n,m;

void fdfs(int v){
  use[v] = true;
  for(int u : g[v]){
    if(!use[u])fdfs(u);
  }
  vs.push_back(v);
}

void rdfs(int v,int k){
  use[v] = true;
  ord[v] = k;
  
  for(int u : rg[v]){
    if(!use[u])rdfs(u,k);
  }
}

int scc(){
  memset(use,0,sizeof(use));
  vs.clear();
  rep(i,n){
    if(!use[i])fdfs(i);
  }

  memset(use,0,sizeof(use));
  int k = 0;
  for(int i=vs.size()-1;i>=0;i--){
    if(!use[vs[i]])rdfs(vs[i],k++);
  }
  return k;
}

int main(){
  cin >> n >> m;
  rep(i,m){
    int a,b;
    cin >> a >> b; a--; b--;
    g[a].push_back(b);
    rg[b].push_back(a);
  }
  int k = scc();

  vector< vector<int> > ng(k);
  rep(v,n){
    for(int u : g[v]){
      if(ord[v]!=ord[u])ng[ord[v]].push_back(ord[u]);
    }
  }

  vector<int> deg(k,0);
  rep(v,k){
    sort(all(ng[v]));
    ng[v].erase(unique(all(ng[v])),ng[v].end());
    for(int u : ng[v])deg[u]++;
  }

  queue<int> q;
  rep(v,k)if(deg[v]==0)q.push(v);
  vector<int> to;

  while(q.size()){
    int v = q.front(); q.pop();
    to.push_back(v);
    for(int u : ng[v]){
      deg[u]--;
      if(deg[u]==0)q.push(u);
    }
  }
  
  vector<ll> dp0(k,1), dp1(k,1);
  ll ans = 1;
  rep(i,k){
    int v = to[i];
    for(int u : ng[v]){
      (dp0[u] *= dp0[v]) %= mod;
      (dp1[u] *= dp0[v] + dp1[v]) %= mod;
    }
    if(ng[v].empty()) (ans *= dp0[v] + dp1[v]) %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
int main(void)
{
	 int H , W,i,j;
	 while(1){ scanf("%d %d",&H,&W);
	    if(H == 0 && W == 0) { break;
		 }
	    for(j=1; j<=H; j++) {
	       for(i=1; i<=W; i++) { 
		printf("#");
		 }
		printf("\n");
		 }
		printf("\n");
	    } 
	return 0;
} 


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
	int n,k;
	cin>>n>>k;
	int ans=0;
	int cnt=0;
	rep(i,n+1){
		cnt=cnt+n-i;
		cnt-=i;
		if(i+1>=k)ans=(ans+cnt+1)%MOD;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3640
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort()
    D = [True] * (10**6 + 1)
    ans = 0

    for i, a in enumerate(A):
        if not D[a]:
            continue
        if (i < n-1 and a != A[i+1]) or i == n-1:
            ans += 1

        j = a
        while (j < 10**6 + 1):
            D[j] = False
            j += a

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 104064
from collections import Counter

N, M = map(int, input().split())
X = list(map(int, input().split()))

modGrp = [[] for _ in range(M)]

for x in X:
    modGrp[x % M].append(x)

ans = len(modGrp[0]) // 2
modGrp[0] = []

if M % 2 == 0:
    ans += len(modGrp[M // 2]) // 2
    modGrp[M // 2] = []

for m in range(1, M // 2 + 1):
    S = modGrp[m]
    T = modGrp[M - m]

    if len(S) < len(T):
        S, T = T, S

    cnt = Counter(S)
    dis = 0
    for c in cnt.values():
        while c >= 2 and len(S) - dis * 2 > len(T):
            dis += 1
            c -= 2
            ans += 1

    ans += min(len(T), len(S) - dis * 2)
    modGrp[m] = []
    modGrp[M - m] = []

print(ans)

Measured memory_bytes: 19044
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()

def resolve():
    import sys
    input = sys.stdin.readline

    x = int(input().rstrip())

    num_set = set()
    for i in range(1, x+1):
        num = i * i
        while num <= x and i not in num_set:
            num_set.add(num)
            num = num * i

    print(max(num_set))

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 61588
#include<stdio.h>
#define MAX 500000
int H;
void maxHeapify(int *A,int i){
    int l,r,largest;
    int v;
    l=2*i;
    r=2*i+1;
    if(l<=H && A[l]>A[i])largest = l;
    else largest = i;
    if(r<=H && A[r]>A[largest])largest = r;
    if(largest!=i){
        v=A[i];
        A[i]=A[largest];
        A[largest]=v;
        maxHeapify(A,largest);
    }
}
void MaxHeap(int *A){
    int i;
    for(i=H/2;i>=1;i--){
        maxHeapify(A,i);
    }
}
int main(){
    int Heap[MAX+1];
    int i;
    scanf("%d",&H);
    for(i=1;i<=H;i++){
        scanf("%d",&Heap[i]);
    }
    MaxHeap(Heap);
    for(i=1;i<=H;i++){
        printf(" %d",Heap[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define PDD pair<LD,LD>
#define eps 1e-9
#define HH1 402653189
#define HH2 1610612741

int n, a[100055], ans;

int main () {
	
	scanf("%d", &n);
	
	FOR(i, 0, n) {
		scanf("%d", a + i);
		if (a[i] & 1) ans++;
	}
	
	printf("%s\n", (ans & 1) ? "NO" : "YES");
	
	return 0;
	
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
	int a, b, c=0;
	cin >> a >> b ;
	cout << a + b / 2 << endl;
	return 0;
}
/*
死のマウス
.　　あり許せん！
　　　∧＿＿∧
　|| （＃｀Д´ ） ||
　|| ( |　 　| | |||
　从| |　 　| |从从
￣) ⊂ノ￣￣!_つ￣て
　フヘ(　　　　ヽヘ(＼

*/

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
const int MAX = 300000 + 10;

int ans[MAX];

int main(){
  int n, x;
  scanf("%d %d", &n, &x);
  if (x == 1 || x == 2*n-1) {
    puts("No");
  } else {
    ans[n-1] = x;
    int now = n-2;
    for(int i = 1 ; i <= 2*n-1 ; i++) {
      if(i == x) continue;
      ans[now] = i;
      now--;
      if(now < 0) now = 2*n-2;
    }
    puts("Yes");
    for(int i = 0 ; i < 2 * n - 1 ; i++)
      printf("%d\n", ans[i]);
  }
  return 0;
}


Measured memory_bytes: 2176
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    a = list(map(int,input().split()))
    now,count = 1,0
    for num in a:
        if num == now:
            count += 1
            now += 1
    
    print(N-count if count!=0 else -1)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 20384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  if(N == 3) {
    cout << 2 << ' ' << 5 << ' ' << 63 << endl;
  } else if(N == 4) {
    cout << 2 << ' ' << 5 << ' ' << 20 << ' ' << 63 << endl;
  } else if(N == 5) {
    cout << 2 << ' ' << 5 << ' ' << ' ' << 20 << ' ' << 30 << ' ' << 63 << endl;
  } else {
    set<int> se;
    ll sum = 0;
    int tmp = 2;
    int i = 0;
    int diff[] = {1, 1, 2, 2};
    while(se.size() < N) {
      se.insert(tmp);
      sum += tmp;
      tmp += diff[i];
      (++i) %= 4;
    }
    switch(sum % 6) {
    case 2:
      se.erase(8);
      se.insert((tmp+5)/6*6);
      break;
    case 5:
      se.erase(9);
      se.insert((tmp+1)/6*6+4);
      break;
    case 3:
      se.erase(9);
      se.insert((tmp+5)/6*6);
      break;
    case 0:
      break;
    }
    for(int s: se) cout << s << ' ';
    cout << endl;
  }
  return 0;
}


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

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  int sum = 0;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    sum += A[i];
  }
  sort(A.begin(), A.end(), greater<int>());
  
  vector<int> d;
  for(int i = 1; i * i <= sum; i++){
    if(sum % i == 0) {
      d.push_back(i);
      d.push_back(sum / i);
    }
  }
  sort(d.begin(), d.end(), greater<int>());
  
  int max_gcd = 1;
  for(int gcd : d){
    int s = sum;
    priority_queue<int> pq;
    int man = 0;
    for(int i = 0; i < N; i++){
      man += A[i] % gcd;
      s -= (A[i] / gcd) * gcd;
      pq.push(A[i] % gcd);
    }
    
    while(s && !pq.empty()){
      man -= pq.top();
      s -= gcd;
      pq.pop();
    }
    
    if(man <= K){
      max_gcd = gcd;
      break;
    }
  }
  
  cout << max_gcd << endl;
  
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define INFll (1LL << 60)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)

ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x; }
ll lcm(ll x, ll y) { return x/gcd(x, y)*y; }

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

    ll a, b; cin >> a >> b;
    cout << lcm(a, b) << '\n';
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	Scanner sc;
	int N;
	int[] b;

	Main() {
		sc = new Scanner(System.in);
	}
	
	void calc() {
		N = sc.nextInt();
		b = new int[N];
		for (int i = 1; i < N; i++) b[i] = sc.nextInt();
		
		int s = b[1];
		for (int i = 1; i < N-1; i++)
			s += Math.min(b[i], b[i+1]);
		s += b[N-1];
		
		System.out.println(s);
	}

	public static void main(String[] args) {
		new Main().calc();
	}

}

Measured memory_bytes: 21972
O = input()
E = input()

password = ""

if len(O) == len(E):
  for i in range(len(O)):
    password += O[i]
    password += E[i]
    
else:
  for i in range(len(O) - 1):
    password += O[i]
    password += E[i]
  password += O[-1]
  
print(password)
  

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n;
    cin >> n;

    vector<int> b(n);
    rep(i, n){
        cin >> b[i];
    }

    vector<int> ans;
    bool flag = true;
    while(!b.empty()){
        flag = false;
        repr(i, b.size()){
            if(b[i] == i + 1){
                ans.emplace_back(b[i]);
                b.erase(b.begin() + i);
                flag = true;
                break;
            }
        }
        if(!flag){
            break;
        }
    }

    if((int)ans.size() == n){
        repr(i, n){
            cout << ans[i] << endl;
        }
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
from fractions import gcd
from math import ceil

def lcm(a, b):
    return a * b // gcd(a, b)

n, M = map(int, input().split())
A = tuple(map(lambda x: int(int(x)/2), input().split()))
scm_core = 1
for a in A:
    scm_core = lcm(scm_core, a)

canmake_scm = True
for a in A:
    if scm_core // a % 2 == 0:
        canmake_scm = False

if canmake_scm:
    print(ceil(M // scm_core / 2))
else:
    print(0)

Measured memory_bytes: 16420
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext() ){
            double a = scanner.nextDouble();
            double b = scanner.nextDouble();
            double c = scanner.nextDouble();
            double d = scanner.nextDouble();
            double e = scanner.nextDouble();
            double f = scanner.nextDouble();

            double x = ((c*e)-(f*b))/((a*e)-(d*b));
            double y = (c-(x*a))/b;

            if (x == -0.0){x = 0;}
            if (y == -0.0){y = 0;}

            System.out.printf("%.3f %.3f\n",x,y);
        }
    }
}


Measured memory_bytes: 28320
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
int n,k,r,s,p;
ll ans = 0;
void pl(char c) {
  //if (cnt == 1) {cnt = 0; return;}
  
  if (c == 'r') ans += p;
  else if (c == 's') ans += r;
  else ans += s;
  return;
} 
int main() {
  cin>>n>>k>>r>>s>>p;
  string t;
  cin >> t;
  int j = 0;
  vector<int> cnt(n,1);
  while (j < k)
  {
    for (int i = j; i < n-k; i+=k)
    {
      if (cnt[i] == 1) {
        pl(t[i]);
        if (t[i] == t[i+k]) cnt[i+k] = 0;
      }
      else {
        if (t[i] == t[i+k]) cnt[i+k] = 1;
      }
    }
    //cout << ans << endl;
    j++;
  }
  for (int i = n-k; i < n; i++)
  {
    if (cnt[i]) pl(t[i]);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define ld double
#define pb push_back
#define EPS 1e-9
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
using namespace std;
typedef pair<int, int> II;
typedef pair<II, int> III;

string s;
int n, qmL[100010], A[100010], C[100010], qmR[100010];
ll res;

ll mu(ll a, ll b)
{
    if (b < 0) return 0;
    if (b == 0) return 1;
    if (b == 1) return a%base;
    ll g = mu(a, b/2);
    if (b%2) return g*g%base*a%base;
    return g*g%base;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> s;
    n = sz(s);
    s = " " + s;
    FOR(i,1,n) qmL[i] = qmL[i-1] + (s[i] == '?');
    FOR(i,1,n) A[i] = A[i-1] + (s[i] == 'A');
    FORE(i,n,1) qmR[i] = qmR[i+1] + (s[i] == '?');
    FORE(i,n,1) C[i] = C[i+1] + (s[i] == 'C');
    FOR(i,1,n)
        if (s[i] == 'B' || s[i] == '?') {
            ll a = qmL[i-1];
            ll b = A[i-1];
            ll N = qmR[i+1];
            ll M = C[i+1];
            res = (res + b*M%base*mu(3,a)%base*mu(3,N)%base + b*N%base*mu(3,N-1)%base*mu(3,a)%base + M*a%base*mu(3,a-1)%base*mu(3,N)%base + a*N%base*mu(3,a-1)%base*mu(3,N-1)%base) % base;
        }
    cout << res;
    return 0;
}


Measured memory_bytes: 1900
#include<cstdio>
#include<iostream>
#include<cstring>

using namespace std;

int n,m;
int dx[3]={-1,0,1};
char ch[105][105];

int main(){
	int i,j,k,l,cnt;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			do{ch[i][j]=getchar();}while(ch[i][j]!='.'&&ch[i][j]!='#');
	
	/*for(i=1;i<=n;i++){
		putchar(10);
		for(j=1;j<=m;j++)
			putchar(ch[i][j]);
		//putchar(10);
	}*/
	
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			if(ch[i][j]=='#'){
				putchar('#');
				//putchar(' ');
			}
			else{
				cnt=0;
				for(k=0;k<=2;k++)
					for(l=0;l<=2;l++)
						if(ch[i+dx[k]][j+dx[l]]=='#')cnt++;
				printf("%d",cnt);
			}
		}
		putchar(10);
	}
	return 0;
}	

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

const int MAXN = 100005;

int main()
{
	bool f = 0;
	int n, a[MAXN], s = 0, maxn = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		maxn = max(maxn, a[i]);
	}
	for (int i = 1; i <= n; i++)
	{
		if (a[i] == maxn && f == 0)
		{
			f = 1;
			s += maxn / 2;
		}
		else s += a[i];
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int MaxN = 1e5;
typedef long long LL;

LL n;
LL a[MaxN + 5];
int main()
{
	while(scanf("%lld", &n) != EOF)
	{
		for(LL i = 1; i <= n; i++)
			scanf("%lld", &a[i]);
		LL sum = 0;
		LL ans1 = 0, ans2 = 0;
		for(LL i = 1; i <= n; i++) //奇为负
		{
			sum += a[i];
			if(i & 1)
			{
				if(sum >= 0)
				{
					ans1 += sum + 1;
					sum = -1;
				}
			}
			else
			{
				if(sum <= 0)
				{
					ans1 += (-1) * sum + 1;
					sum = 1;
				}
			}
		}
		sum = 0;
		for(LL i = 1; i <= n; i++) //奇为正
		{
			sum += a[i];
			if(i & 1)
			{
				if(sum <= 0)
				{
					ans2 += (-1) * sum + 1;
					sum = 1;
				}
			}
			else
			{
				if(sum >= 0)
				{
					ans2 += sum + 1;
					sum = -1;
				}
			}
		}
		printf("%lld\n", min(ans1, ans2));
		memset(a, 0, sizeof(a));
	}
	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  cout << (A - 1) * (B - 1) << endl;
  return 0;
}

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

using namespace std;

int main() {
  int a, b;
  std::cin >> a >> b;
  if (a + b == 15) {
    std::cout << "+" << std::endl;
  } else if (a * b == 15) {
    std::cout << "*" << std::endl;
  } else {
    std::cout << "x" << std::endl;
  }
  return 0;
}


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

int main() {
  ll n,a,b;
  cin >> n >> a >> b;

  //ボールの周期に着目する
  ll c = a+b;
  ll ans = a * (n/c);
  
  //ボールの周期を超えて切れた場合は、小さい方を足す
  ans += min(n%c, a);

  cout << ans << endl;
}

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

#define Abigail inline void
typedef long long LL;

const int N=20;

int n,a[N+9],b[N+9],ans;

Abigail into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i)
    scanf("%d",&a[i]);
  for (int i=1;i<=n;++i)
    scanf("%d",&b[i]);
}

Abigail work(){
  for (int i=1;i<=n;++i)
    ans+=max(0,a[i]-b[i]);
}

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

int main(){
  into();
  work();
  outo();
  return 0;
}

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

int main(){
    long long q,h,s,d;
    long long n;
    cin>>q>>h>>s>>d>>n;

    long long sum=0;
    if(d<2*s && d<4*h && h<8*q){
        sum+=(n/2)*d;
        n%=2;
    }
    if(s<2*h && s<4*q){
        sum+=n*s;
        n=0;
    }
    if(h<2*q){
        sum+=2*n*h;
        n=0;
    }
    {
        sum+=4*n*q;
        n=0;
    }

    cout<<sum<<endl;
}

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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    double ans = 0;
    for (double i : A) ans += 1 / i;
    ans = 1 / ans;
    cout << fixed << setprecision(10) << ans << '\n';
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

const int maxn = 1e5 + 5;
int deg[maxn];

int n, m;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for(int i = 1;i <= m;i++){
        int u, v;
        cin >> u >> v;
        deg[u]++;
        deg[v]++;
    }
    bool flag = true;
    for(int i = 1;i <= n;i++){
        if(deg[i] & 1)
            flag = false;
    }
    if(flag){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		int AC = 0;
		int WA = 0;
		int TLE = 0;
		int RE = 0;
		
		List<String> list = new ArrayList<>();
		
		for (int i = 0; i < n; i++) {
			
			list.add(scanner.next());
		}
		
		scanner.close();
		
		for (String s : list) {
			
			if ("AC".equals(s)) {
				AC++;
			} else if ("WA".equals(s)) {
				WA++;
			} else if ("TLE".equals(s)) {
				TLE++;
			} else if ("RE".equals(s)) {
				RE++;
			} else {
				
			}
		}
		
		System.out.println("AC x " + AC);
		System.out.println("WA x " + WA);
		System.out.println("TLE x " + TLE);
		System.out.println("RE x " + RE);
	}

}


Measured memory_bytes: 54804
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int n, k, ans;
int a[100];
signed main() {
	cin >> n >> k;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		for (int j = i + 1; j <= n; j++) {
			int cnt = 0, kaisu = 0;
			prique(int)que;
			rep(k, n) {
				if (k > i && k < j)continue;
				cnt += a[k];
				kaisu++;
				if (a[k] < 0)que.push(a[k]);
			}
			if (kaisu > k)continue;
			int nokori = k - kaisu;
			rep(k, nokori) {
				if (que.empty())break;
				cnt -= que.top(); que.pop();
			}
			ans = max(ans, cnt);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
C = [list(map(lambda x:int(x),input().split()))for i in range(3)]

a,b,c = C[0],C[1],C[2]

if((a[0]-a[1]==b[0]-b[1])and (b[0]-b[1]==c[0]-c[1]) and (a[2]-a[1])==(b[2]-b[1]) and (b[2]-b[1])==(c[2]-c[1])):
   print('Yes')

else:
   print('No')

   


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i, N) cin >> p.at(i);

    sort_g(p);

    int sum = accumulate(all(p), 0);
    sum -= p.at(0) / 2;

    cout << sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int N;
	int ACnum[128] = {0};
	int i;
	int ok, ng;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		int p;
		if (scanf("%d", &p) != 1) return 1;
		ACnum[p]++;
	}
	for (i = 100; i > 1; i--) ACnum[i - 1] += ACnum[i];
	ok = 0;
	ng = 101;
	while (ng - ok > 1) {
		int mid = (ng - ok) / 2 + ok;
		if (ACnum[mid] >= mid) ok = mid; else ng = mid;
	}
	printf("%d\n", ok);
	return 0;
}



Measured memory_bytes: 2064
S = int(input())

def main():
    a = [S]
    curr = S
    while a.count(curr) <= 1:
        curr = curr // 2 if curr % 2 == 0 else 3 * curr + 1
        a.append(curr)
    print(len(a))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
from heapq import heappush, heappop
n, m = map(int, input().split())
jobs = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a > m:
    continue
  if a in jobs:
    jobs[a].append(b)
  else:
    jobs[a] = [b]
result = 0
candidates = []
for a in range(1, m + 1):
  if a in jobs:
    for b in jobs[a]:
      heappush(candidates, -b)
  else:
    if len(candidates) == 0:
      continue
  result += -heappop(candidates)
print(result)


Measured memory_bytes: 26072
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;
ll r,c;
char ch [100][100];

ll bfs(ll x1,ll y1)
{
	ll d[r][c];
	memset(d,-1,sizeof(d));

	queue<pair<ll,ll> > q;
	q.push(mp(x1,y1));
	d[x1][y1]=0;

	while(!q.empty())
	{
		ll x=q.front().ff;
		ll y=q.front().ss;
			q.pop();
			if(x+1<r and ch[x+1][y]=='.' and d[x+1][y]==-1) q.push(mp(x+1,y)),d[x+1][y]=d[x][y]+1;
			if(x-1>-1 and ch[x-1][y]=='.' and d[x-1][y]==-1) q.push(mp(x-1,y)),d[x-1][y]=d[x][y]+1;
			if(y+1<c and ch[x][y+1]=='.' and d[x][y+1]==-1) q.push(mp(x,y+1)),d[x][y+1]=d[x][y]+1;
			if(y-1>-1 and ch[x][y-1]=='.' and d[x][y-1]==-1) q.push(mp(x,y-1)),d[x][y-1]=d[x][y]+1;
	}

	ll ans=0;
	for(ll i=0;i<r;i++)
		for(ll j=0;j<c;j++)
			ans=max(ans,d[i][j]);
		return ans;


}

int main()
{ 

    fast;

    
    cin>>r>>c;
    vector<pair<ll,ll> > v;

    
    ll res=0;

    for(ll i=0;i<r;i++)
    	for(ll j=0;j<c;j++)
    		cin>>ch[i][j];


    	for(ll i=0;i<r;i++)
    	{
    		for(ll j=0;j<c;j++)
    		{
    			if(ch[i][j]=='.')
    				res=max(res,bfs(i,j));
    		}
    	}
    	cout<<res<<endl;

  }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;

int n, m;
int a[100000], b[100000];
map<P, int> edge_id;
int cnts[100000];

vector<int> et[100000];		//無向グラフ
bool visit[100000];
vector<int> tree[100000];	//根0, 無向全域木
int parent[100000];
int depth[10000];
int parents[20][100000];
int fillCnt[100000];

bool isHanten[100000];

//全域木を作る
void dfs(int v, int dep) {
	int i;
	
	visit[v] = true;
	depth[v] = dep;
	rep(i, et[v].size()) {
		int nv = et[v][i];
		if (visit[nv]) continue;
		tree[v].push_back(nv);
		tree[nv].push_back(v);
		parent[nv] = v;
		dfs(nv, dep + 1);
	}
}

int lca(int u, int v) {
	if (depth[u] < depth[v]) {
		swap(u, v);
	}
	
	if (depth[u] > depth[v]) {
		int i;
		int diff = depth[u] - depth[v];
		for (i = 19; i >= 0; i--) {
			if ((diff >> i) % 2 == 1) {
				u = parents[i][u];
			}
		}
	}
	
	int i;
	for (i = 19; i >= 0; i--) {
		if (parents[i][u] != parents[i][v]) {
			u = parents[i][u];
			v = parents[i][v];
		}
	}
	if (u == v) return u;
	return parent[u];
}

void fillEdge(int oya, int ko) {
	fillCnt[oya]--;
	fillCnt[ko]++;
}

int dfs2(int p, int v) {
	int i;
	int ssum = fillCnt[v];
	
	rep(i, tree[v].size()) {
		int nv = tree[v][i];
		if (nv == p) continue;
		ssum += dfs2(v, nv);
	}
	
	//辺p -- vの向きを決める
	if (v != 0) {
		int eid = edge_id[P(p, v)];
		//cout << "p, v = " << p << ", " << v << ", eid = " << eid << endl;
		if (ssum % 2 == 0) { isHanten[eid] = false; }
		else { isHanten[eid] = true; }
	}
	return ssum;
}

int main() {
	int i, j;
	
	cin >> n >> m;
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		cnts[a[i]]++;
		et[a[i]].push_back(b[i]);
		et[b[i]].push_back(a[i]);
		edge_id[P(a[i], b[i])] = i;
		edge_id[P(b[i], a[i])] = i;
	}
	
	int odd_cnt = 0;
	rep(i, n) { if (cnts[i] % 2 == 1) odd_cnt++; }
	if (odd_cnt % 2 != 0) { cout << "-1" << endl; return 0; }
	
	parent[0] = 0;
	dfs(0, 0);
	rep(i, n) parents[0][i] = parent[i];
	rep(i, 19) {
		rep(j, n) {
			parents[i + 1][j] = parents[i][parents[i][j]];
		}
	}
	
	vector<int> vecs;
	rep(i, n) {
		if (cnts[i] % 2 == 1) vecs.push_back(i);
	}
	
	//rep(i, n) cout << "parent[" << i << "] = " << parent[i] << endl;
	
	rep(i, odd_cnt / 2) {
		int u = vecs[2 * i];
		int v = vecs[2 * i + 1];
		int l = lca(u, v);
		
		fillEdge(l, u);
		fillEdge(l, v);
	}
	
	//Srep(i, n) cout << "fillCnt[" << i << "] = " << fillCnt[i] << endl;
	
	dfs2(-1, 0);
	
	rep(i, m) {
		if (isHanten[i]) cout << b[i] + 1 << " " << a[i] + 1 << endl;
		else cout << a[i] + 1 << " " << b[i] + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 46080
K,N = map(int,input().split())
A = list(map(int,input().split()))
ans = []

for i in range(N-1):
  now = i
  pre = now-1
  post = now +1
  #nowとpreの距離を求める
  if now == 0:
    preDic = (K-A[N-1])+A[now]
  else:
    preDic = A[now]-A[pre]
  postDic = A[post]-A[now]  
  if preDic >= postDic:#時計回りに、i-1の位置まで進む
    ans.append(K-preDic)
  else:
    ans.append(K-postDic)
  
print(min(ans))

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

int main() {
  int W,H,N;
  scanf("%d %d %d", &W,&H,&N);
  int a[N],b[N],c[N];
  for (int i = 0; i < N; ++i) {
    scanf("%d %d %d", &a[i],&b[i],&c[i]);
  }

  int A[W][H];

  for (int i = 0; i < W; ++i) {
    for (int ii = 0; ii < H; ++ii) {
      A[i][ii] = 0;
    }
  }

  for (int i = 0; i < N; ++i) {
    if(c[i]==1){
      for (int ii = 0; ii < a[i]; ++ii) {
        for(int iii = 0; iii < H; ++iii){
          A[ii][iii] = 1;
        }
      }
    }
    if(c[i]==2){
      for (int ii = a[i]; ii < W; ++ii) {
        for(int iii = 0; iii < H; ++iii){
          A[ii][iii] = 1;
        }
      }
    }
    if(c[i]==3){
      for (int ii = 0; ii < b[i]; ++ii) {
        for(int iii = 0; iii < W; ++iii){
          A[iii][ii] = 1;
        }
      }
    }
    if(c[i]==4){
      for (int ii = b[i]; ii < H; ++ii) {
        for(int iii = 0; iii < W; ++iii){
          A[iii][ii] = 1;
        }
      }
    }

  }

  int count = 0;
  for (int i = 0; i < W; ++i) {
    for (int ii = 0; ii < H; ++ii) {
      if(A[i][ii] == 0) ++count;
    }
  }

  cout << count << endl;



}

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

int main() {
  int n,k;
  cin>>n>>k;
  vector<long long int>vec(n);
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  vector<long long int>bns(n-k+1);
  sort(vec.begin(),vec.end());
  for(int i=0;i<n-k+1;i++){
    bns[i]=vec[k-1+i]-vec[i];
  }
  sort(bns.begin(),bns.end());
  cout<<bns[0]<<endl;
}

Measured memory_bytes: 1792
#include <iostream>

const long long N = 1000;
const long long TOTAL_PATTERN = 8;
const long long V = 10007;

int main(void) {
  long long n = 0;
  std::string line;
  long long schedule[N + 1][TOTAL_PATTERN] = {0};

  std::cin >> n;
  std::cin >> line;

  /**
   * (X, X, X) = (0, 0, 0)
   * (J, X, X) = (1, 0, 0)
   * (J, O, I) = (1, 1, 1)
   */

  schedule[0][4] = 1; /* (J, X, X) */

  for (int i = 1; i <= n; i++) {
    char leader = line.at(i - 1);

    long long l = 0;
	
    if (leader == 'J') {
      l = 4;
    } else if (leader == 'O') {
      l = 2;
    } else {
      l = 1;
    }

    for (long long j = 1; j < TOTAL_PATTERN; j++) {
      if ((j & l) != l) {
	continue;
      }
      
      for (long long k = 1; k < TOTAL_PATTERN; k++) {
	if ((j & k) > 0) {
	  schedule[i][j] += (schedule[i - 1][k] % V);
	}
      }
    }
  }

  long long total = 0;

  for (int i = 1; i < TOTAL_PATTERN; i++) {
    total += schedule[n][i];
  }

  long long answer = total % V;

  std::cout << answer << std::endl;

  return 0;
}

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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    for(int i=0; i<S.size(); i++){
        for(int j=0; j<N; j++){
            if(S.at(i)=='Z'){
                S.at(i) = 'A';
            }
            else S.at(i)++;
        }
    }
    cout << S << endl;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
	if ( A+B > C+D)
      cout << "Left" << endl;
  	else if ( A + B == C + D ){
	  cout << "Balanced" << endl;
    }
  	else 
      cout << "Right" << endl;
}

Measured memory_bytes: 256
/*  In the name of ALLAH */

#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and Constants    *******/

#define int long long
#define ull unsigned long long 
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define w(x) int x;cin>>x;while(t--)
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int POSITIVE_INFINITY = 9223372036854775807;
const int NEGATIVE_INFINITY = -9223372036854775807;
const int MOD = 1000000007;
const ld PI = acos(-1.0);
 

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif



int32_t main() {
    io;
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
  
    string s,t;
    cin>>s>>t;
    for(int i = 0 ; i <s.size();i++){
        if(s[i]!=t[i]){
            cout<<"No";
            return 0;
        }
    }
    if(s.size()+1 == t.size()){
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
 

 
    
 
    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
long long INF=1e18;




ll uppersearch(ll key, vector<ll> &data){
    int left=0;
    int right=int(data.size())-1;

    while (left<right){
        int mid=(left+right)/2;
        if (data.at(mid)>key){
            right=mid;
        }
        else {
            left=mid+1;
        }
    }

    if (data.at(left)<=key){
        return int(data.size());
    }
    else {
        return left;
    }

}

ll lowersearch(ll key, vector<ll> &data){
    int left=0;
    int right=int(data.size())-1;

    while (left<right){
        int mid=(left+right)/2;
        if (data.at(mid)>=key){
            right=mid;
        }
        else {
            left=mid+1;
        }
    }

    if (data.at(left)<key){
        return int(data.size());
    }
    else {
        return left;
    }

}

int main(){

    int n;

    long long k;
    cin >> n >> k ;

  
    vector<ll> data(n);
    rep(i,n){
        long long tmp;
        cin>>tmp;
        data.at(i)=tmp;
    }

    sort(ALL(data));

    long long left=-INF;
    long long right=INF;

 
    while (left<right){
        long long mid=left+(right-left)/2;
        long long  cnt=0;
        rep(i,n){
            if (data.at(i)==0 and mid>=0){
                cnt+=n-i-1;
            }
            else if (data.at(i)>0){
                int tmp;
                tmp=uppersearch(mid/data.at(i),data);
                cnt+=max(0,(tmp-i-1));
            }
            else if (data.at(i)<0){
                long long mylimit;
                int tmp;

                if (mid%data.at(i)==0 or mid>=0){
                    mylimit=mid/data.at(i);
                }
                else {
                    mylimit=(mid/data.at(i))+1;
                }

                tmp=lowersearch(mylimit,data);
                cnt+=n-max(i+1,tmp);
            }
          

        }
 
        if (cnt>=k){
            right=mid;
        }
        else {
            left=mid+1;
        }
    }

    cout<<right<<endl;






}

Measured memory_bytes: 1792
N = int(input())
A_l = list(map(int,input().split()))
A_all = sum(A_l)
B_l = list(map(int,input().split()))

for i in range(N):
  a1 = A_l[i]
  a2 = A_l[i+1]
  b1 = B_l[i]
  if b1>a1:
    A_l[i] = 0
    b1 -= a1
  else:
    A_l[i] = a1-b1
    continue
  if b1>a2:
    A_l[i+1] = 0
  else:
    A_l[i+1] = a2-b1

print(A_all - sum(A_l))

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

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;
constexpr ll mod = 1e9+7;

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

    int N;
    cin>>N;
    vector<ll> C(N), S(N), F(N);
    for (int n = 0; n < N-1; n++) cin>>C[n]>>S[n]>>F[n];

    vector<ll> ans(N);
    ans[N-1] = 0;
    for (int n = N-2; n >= 0; n--) {
        int i = n + 1;
        ll count = S[n] + C[n];
        while (i < N-1) {
            if (count <= S[i]) {
                count = ans[i];
                break;
            }
            count = (ll)ceil((double)count/F[i]) * F[i] + C[i];
            i++;
        }
        ans[n] = count;
    }

    for (int n = 0; n < N; n++) cout<<ans[n]<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(a,max(b,c))-min(a,min(b,c)) << endl;
    return 0;
}

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;
const double PI = 3.14159265358979323846;

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> d(n + 1);
  rep(i, n+1) {
    if(i == 0) d[i] = 0;
    else if(i > 0) {
      int l;
      cin >> l;
      d[i] = d[i-1] + l;
    }
  }
  int ans = 0;
  for(int i = 1; i < n+1; i++) {
    if(d[i-1] <= x && x < d[i]) ans = i;
    else if(x >= d[i]) ans = i + 1;
  }
  cout << ans << endl;
  return 0;
}
  
    
      

Measured memory_bytes: 3640
#include<cstdio>
#include<algorithm>
using namespace std;

int l, n, m, d[100002], k[10000];

int main() {
  while (scanf("%d", &l), l) {
    int ans = 0;
    scanf("%d%d", &n, &m);
    for (int i = 1; i < n; i++) scanf("%d", &d[i]);
    d[n] = l;
    sort(d, d+n+1);
    for (int i = 0; i < m; i++) scanf("%d", &k[i]);
    for (int i = 0; i < m; i++) {
      if (k[i] == 0) continue;
      int x = lower_bound(d, d+n+1, k[i]) - d;
      int len = min(d[x] - k[i], k[i] - d[x-1]);
      ans += len;
    }
    printf("%d\n", ans);
  }
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	ll a;
	cin >> a;
	if(a%2) {
		cout << 0 << '\n';
		return 0;
	}
	ll x = 5;
	ll ret = 0;
	while(a/(2*x)) {
		ret += a/(2*x);
		x = x * 5;
	}
	cout << ret << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<string> s(n, "");
    set<string> se;

    REP(i, n) {
        cin >> s[i];
        se.insert(s[i]);
    }
    cout << se.size() << endl;

}


Measured memory_bytes: 25092
n = int(input())
MAX = 1000100
MOD = 10**9 + 7
modPow8 = [1] * MAX
modPow2 = [1] * MAX
for i in range(1, MAX):
    modPow2[i] = modPow2[i-1] * 2 % MOD
    modPow8[i] = modPow8[i-1] * 8 % MOD
fact = [1] * MAX
inv = [1] * MAX
fact_inv = [1] * MAX 
for i in range(2, 1000100):
    fact[i] = fact[i-1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    fact_inv[i] = fact_inv[i-1] * inv[i] % MOD
def comb(n, k):
    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD
ans = 0
for k in range(2, n+1):
    ans += comb(n, k) * (modPow2[k] - 2) * modPow8[n-k]
    ans %= MOD
print(ans)

Measured memory_bytes: 122036
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 gcd : ?????§??¬?´???°
 lcm : ????°???¬?????°
 */
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll res = 1;
    for(int i = 0; i < n;i++) {
        ll a; cin >> a;
        res = lcm(res,a);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3208
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
//#define int long long
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
int gcd(int n, int m) { return (m ? gcd(m, n%m) : n); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int k;
	cin >> k;
	int ans = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int x = 1; x <= k; x++) {
				ans += gcd(gcd(i, j), x);
			}
		}
	}
	cout << ans << '\n';
}

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

#define NIL -1

struct Node { int parent, right, left; };
Node T[30];

void preOrder(int u) {
    cout << " " << u;
    if (T[u].left != NIL) { preOrder(T[u].left); }
    if (T[u].right != NIL) { preOrder(T[u].right); }
}

void inOrder(int u) {
    if (T[u].left != NIL) { inOrder(T[u].left); }
    cout << " " << u;
    if (T[u].right != NIL) { inOrder(T[u].right); }
}

void postOrder(int u) {
    if (T[u].left != NIL) { postOrder(T[u].left); }
    if (T[u].right != NIL) { postOrder(T[u].right); }
    cout << " " << u;
}

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        T[i].parent = T[i].left = T[i].right = NIL;
    }
    for (int i = 0; i < n; ++i) {
        int id, right, left; cin >> id >> left >> right;
        T[id].right = right;
        T[id].left = left;
        if (left != NIL) { T[left].parent = id; }
        if (right != NIL) { T[right].parent = id; }
    }
    int u = 0;
    for (int i = 0; i < n; ++i) { if (T[i].parent == NIL) { u = i; } }
    cout << "Preorder" << endl;
    preOrder(u); cout << endl;
    cout << "Inorder" << endl;
    inOrder(u); cout << endl;
    cout << "Postorder" << endl;
    postOrder(u); cout << endl;

}

Measured memory_bytes: 3076
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
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()))

s = input()
n = len(s)
t = []
for i in range(n):
    t.append(int(s[i])*pow(10,n-i-1,2019))
t = list(accumulate(t))
u = [i % 2019 for i in t]
u = list(Counter(u).items())
ans = 0
for i,j in u:
    if i == 0:
        ans += j
    if j >= 2:
        ans += j*(j-1) // 2
print(ans)

Measured memory_bytes: 98732
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li r, c, k;
    cin >> r >> c >> k;
    vector<vector<li>> items(r, vector<li>(c, 0));
    for (int i = 0; i < k; ++i) {
        li ir, ic, iv;
        cin >> ir >> ic >> iv;
        ir--; ic--;
        items[ir][ic] = iv;
    }
    vector<li> dp(c + 1, 0);
    for (int row = 0; row < r; ++row) {

        vector<vector<li>> subdp(c + 1, vector<li>(4, 0));
        for (int col = 0; col < c; ++col) {
            for (int used = 0; used <= 3; ++used) {
                subdp[col + 1][used] = max(dp[col + 1], subdp[col][used]);
                if (used > 0 && items[row][col] > 0) {
                    subdp[col + 1][used] = max(subdp[col + 1][used], subdp[col][used - 1] + items[row][col]);
                    if (used == 1) {
                        subdp[col + 1][used] = max(subdp[col + 1][used], dp[col + 1] + items[row][col]);
                    }
                }

            }
        }


        for (int i = 0; i < c + 1; ++i) {
            for (int j = 0; j <= 3; ++j) {
                dp[i] = max(dp[i], subdp[i][j]);
            }
        }
    }

    cout << dp[c] << endl;


    return 0;
}

Measured memory_bytes: 74136
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
bool IsPrime(int num)//素数
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(){
    std::vector<int> a(100001,0),b(100002);
    rrep(i,3,100002){
        if(i%2==0)continue;
        if(IsPrime(i)&&IsPrime((i+1)/2)){
          //  std::cout << i << std::endl;
            a[i]=1;
        }
    }
    rrep(i,1,100003)b[i+1]=a[i]+b[i];
    int q;
    std::cin >> q;
    rep(i,q){
        int l,r;
        std::cin >> l>>r;
        std::cout << b[r+1]-b[l] << std::endl;
    }
    
}

Measured memory_bytes: 1408