akhauriyash/Code-Regression huggingface dataset:
using System;

namespace ABC112_B_TimeLimitExceeded
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			//入力文字列をスペースで分割して配列に一旦代入、それぞれ別の変数に代入
			string[] inStrArr = Console.ReadLine().Split(' '); 
			int N = int.Parse(inStrArr[0]);
			int T = int.Parse(inStrArr[1]);
			
			//コスト、時間を入れる用の配列を用意
			int[] nowCostArr = new int[N];
			int[] nowTimeArr = new int[N];
			
			//コストは<=1000のため、1001で初期化
			int minCost = 1001;
			
			for (int i = 0; i < N; i++)
			{
				//入力されたコスト、時間をそれぞれ別々に入れる
				string[] costAndTimeArr = Console.ReadLine().Split(' ');
				nowCostArr[0] = int.Parse(costAndTimeArr[0]);
				nowTimeArr[0] = int.Parse(costAndTimeArr[1]);
				
				//条件を満たした場合、最小コストを入れ替え
				if (nowTimeArr[0] <= T && nowCostArr[0] < minCost)
				{
					minCost = nowCostArr[0];
				}
			}

			if (minCost != 1001) //最小コストが初期値のまま入れ替えされなかった場合
			{
				Console.WriteLine(minCost);
			}
			else
			{
				Console.WriteLine("TLE");
			}
		}
	}
}

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

#define M 1000000007

typedef pair<int, int> P;
struct edge { int to, cap, cost, rev; };

int V;
vector<edge> G[400];
int h[400];
int dist[400];
int prevv[400], preve[400];
void add_edge(int from, int to, int cap, int cost) {
    G[from].push_back((edge){ to, cap, cost, (int)G[to].size() });
    G[to].push_back((edge){ from, 0, -cost, (int)G[from].size() - 1 });
}

// ??????????????´??????M
int min_cost_flow(int s, int t, int f) {
    int res = 0;
    fill(h, h + V, 0);
    while (f > 0) {
        priority_queue<P, vector<P>, greater<P> > q;
        fill(dist, dist + V, M);
        dist[s] = 0;
        q.push(P(0, s));
        while (!q.empty()) {
            P p = q.top();
            q.pop();
            int v = p.second;
            if (dist[v] < p.first) continue;
            for (int i = 0; i < (int)G[v].size(); ++i) {
                edge &e = G[v][i];
                if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
                    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                    prevv[e.to] = v;
                    preve[e.to] = i;
                    q.push(P(dist[e.to], e.to));
                }
            }
        }
        if (dist[t] == M) {
            return M;
        }
        for (int v = 0; v < V; ++v) {
            h[v] += dist[v];
        }
        int d = f;
        for (int v = t; v != s; v = prevv[v]) {
            d = min(d, G[prevv[v]][preve[v]].cap);
        }
        f -= d;
        res += d * h[t];
        for (int v = t; v != s; v = prevv[v]) {
            edge &e = G[prevv[v]][preve[v]];
            e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}

int main()
{
    while (true) {
        int n;
        cin >> n;
        if (n == 0) return 0;
        V = 3 * n + 2;
        for (int i = 0; i < 400; ++i) {
            G[i].clear();
            h[i] = 0;
            dist[i] = 0;
            prevv[i] = 0;
            preve[i] = 0;
        }
        int S = 3 * n, T = 3 * n + 1;
        for (int i = 0; i < n; ++i) {
            add_edge(S, i * 3 + 1, 1, 0);
            add_edge(i * 3 + 2, T, 1, 0);
        }
        int ans = 0;
        vector<vector<int> > a(n);
        for (int i = 0; i < n; ++i) {
            a[i].resize(3);
            cin >> a[i][0] >> a[i][1] >> a[i][2];
            sort(a[i].begin(), a[i].end());
            int cub = a[i][0] * a[i][1] * a[i][2];
            add_edge(i * 3, i * 3 + 1, 1, -cub);
            add_edge(i * 3 + 1, i * 3 + 2, 1, 0);
            ans += cub;
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (i == j) continue;
                if (a[i][0] > a[j][0] && a[i][1] > a[j][1] && a[i][2] > a[j][2]) {
                    add_edge(i * 3 + 2, j * 3, 1, 0);
                }
            }
        }
        while (true) {
            int cost = min_cost_flow(S, T, 1);
            if (cost >= 0) break;
            ans += cost;
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final String HIT = "HIT", HOMERUN = "HOMERUN", OUT = "OUT";
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int out, point, rui;
		String j;
		for (int i = 0; i < n; i++) {
			out = 0;
			point = 0;
			rui = 0;
			while (out < 3) {
				j = in.next();
				if (OUT.equals(j)) {
					out++;
				} else if (HIT.equals(j)) {
					rui++;
					if (rui > 3) {
						rui = 3;
						point++;
					}
				} else if (HOMERUN.equals(j)) {
					point += rui + 1;
					rui = 0;
				}
			}
			System.out.println(point);
		}
	}
}

Measured memory_bytes: 15364
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;


int main()
{
    ll N;

    cin >> N;
    ll cnt = 0;

    ll kisuwa[N+1] = {};
    ll gusuwa[N+1] = {};

    ll dam[N+1] = {};
    ll yama[N+1] = {};

    for(ll i = 1; i <= N; ++i)
    {
        cin >> dam[i];
        if(i==1)
        {
            kisuwa[1] = dam[1];
            continue;
        }
        if(i % 2 == 1)
        {
            kisuwa[i] += kisuwa[i-2] + dam[i];
        }
        else
        {
            gusuwa[i] += gusuwa[i-2] + dam[i];
        }
    }

    ll tmp;

    //i == 1
    tmp += kisuwa[N];
    tmp -= gusuwa[N-1];
    tmp += 2*gusuwa[0];


    cout << tmp << endl;



    for(ll i= 2; i <= N; ++i)
    {
        tmp = 0;
        if(i % 2 == 0)
        {
            tmp += gusuwa[N-1];
            tmp -= kisuwa[N];
            tmp -= 2*gusuwa[i-2];
            tmp += 2*kisuwa[i-1];

            cout << tmp << endl;
        }
        else
        {
            tmp += kisuwa[N];
            tmp -= gusuwa[N-1];
            tmp -= 2*kisuwa[i-2];
            tmp += 2*gusuwa[i-1];

            cout << tmp << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 4480
import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_4.txt', 'r')
# sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"

    # write code
    # †私は証明のない決め打ちを提出しました†
    if N == 1:
        print(abs(a[-1]-W))
    elif abs(a[-1] - W) > abs(a[-1] - a[-2]):
        print(abs(a[-1] - W))
    else:
        print(abs(a[-1] - a[-2]))

Measured memory_bytes: 5716
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
input = sys.stdin.readline


def main():
    n, k, l = map(int, input().split())
    p, q = [], []
    for _ in range(k):
        pi, qi = map(int, input().split())
        p.append(pi)
        q.append(qi)
    r, s = [], []
    for _ in range(l):
        ri, si = map(int, input().split())
        r.append(ri)
        s.append(si)

    road_tree = make_union_find(p, q, n)
    rail_tree = make_union_find(r, s, n)

    a, b = [], []
    x = defaultdict(int)
    for i in range(n):
        a.append(root(road_tree, i))
        b.append(root(rail_tree, i))
        key = (a[i], b[i])
        x[key] += 1

    for i in range(n):
        print(x[(a[i], b[i])], end=' ')


def make_union_find(a, b, n):
    union_find_tree = [i for i in range(n)]

    for i in range(len(a)):
        x = root(union_find_tree, a[i] - 1)
        y = root(union_find_tree, b[i] - 1)
        if x != y:
            union_find_tree[x] = y

    return union_find_tree


def root(union_find_tree, target):
    if union_find_tree[target] == target:
        return target
    else:
        union_find_tree[target] = root(
            union_find_tree, union_find_tree[target])
        return union_find_tree[target]


if __name__ == '__main__':
    main()


Measured memory_bytes: 71428
#include <stdio.h>

int n, A[50];

int solve(int i, int m){
  if(m==0)
    return 1;
  if(i >= n)
    return 0;
  int res = solve(i+1, m) || solve(i+1, m-A[i]);
  return res;
}

int main(){
  int q, M, i;
  
  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      scanf("%d", &A[i]);
    }
  scanf("%d", &q);
  for(i=0; i<q; i++)
    {
      scanf("%d", &M);
      if(solve(0, M))
	printf("yes\n");
      else
	printf("no\n");
    }

  return 0;
}



Measured memory_bytes: 2104
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxn = 100000;
bool vis[maxn + 5];
int ans[maxn + 5];
void Init() {
	vis[1] = 1;
	for(int i = 2; i <= maxn; i++) {
		if(!vis[i]) {
			ans[++ans[0]] = i;
			for(int j = i * 2; j <= maxn; j += i)vis[j] = 1;
		}
	}
}
int n;
int main() {
	Init();
	scanf("%d", &n);
	for(int i = 1; i <= ans[0]; i++) {
		if(n == 0)break;
		if(ans[i] % 10 == 1) {
			if(n == 1)printf("%d\n", ans[i]);
			else printf("%d ", ans[i]);
			n--;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using std::cin;
using std::cout;
using std::endl;

#include<map>
using std::map;

#include<string>
using std::string;

#include<stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void){
	int A[200001];
	int N;
	scanf("%d",&N);
	for(int k=0;k<N;k++){
		scanf("%d",&A[k]);
	}
	qsort(A,N,sizeof(int),compare_int);
	for(int k=0;k<N-1;k++){
		if(A[k]==A[k+1]){
			printf("NO");
			return 0;
		}
	}
	printf("YES");
}

Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>
#include <set>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define v_in(v) for(auto&& i : v) cin >> i
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(),v.end()

#define PI 3.14159265358979323846

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;


int main(void){
    FAST_IO
    
    string s;
    cin >> s;

    set<char> is_vaild;

    rep(i,(ll)s.size()){
        if(!is_vaild.insert(s[i]).second){
            cout << "no" << endl;
            return 0;
        }
    }

    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 3072
import fractions
import math
A,B=map(int, input().split())
n=fractions.gcd(A, B)
divisors = []
for i in range(1, int(n**0.5)+1):
    flag=-1
    lag=-1
    if n % i == 0:
      flag=0
      for j in range(2, int(i**0.5)+1):
        if i%j==0 and i!=j:
          flag=1
          break
      if i != n // i :
        lag=0
        for j in range(2, int((n // i)**0.5)+1):
          if (n // i)%j==0 and i!=j:
            lag=1
            break
    if flag==0:
      divisors.append(i)
    if lag==0:
      divisors.append(n//i)
#flag=0
#print(divisors)
#for j in range(2, int(n**0.5)+1):
#    if n%j==0:
#     flag=1
 #     break
#if flag==0:
 #     divisors.append(n)
print(len(divisors))    

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;




int n;
int a[maxn];

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

    
    cin>>n;

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

    int i=0;
    int j=n-1;

    int single=0;

    while (1) {
	while (i+1<=j && a[i+1]!=a[i]) {
	    single++;
	    i++;
	}
	
	if (i==j) {
	    single++;
	    break;
	}
	
	while (j>i && a[j]!=a[j-1]) {
	    single++;
	    j--;
	}


	//cerr<<i<<" "<<j<<endl;
	
	if (i+1==j) {
	    assert(single>0);
	    i++;
	    break;
	} else {
	    i++; j--;
	}
    }

    cout<<single<<endl;
  

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
  int N;
  vector<int> V(N);
  vector<int> C(N);
  vector<int> D(N);
  int X,Y;
  int ans = 0;
  
  cin >> N;
  for (int i=0;i<N;i++)
    cin >> V[i];
  for (int i=0;i<N;i++)
    cin >> C[i];
  for (int i=0;i<N;i++){
    D[i] = V[i] - C[i];
    if (D[i] > 0)
      ans += D[i];
  }
cout << ans << endl;
}




Measured memory_bytes: 640
using System;

class Program
{
    static void Main(string[] args)
    {
        var ab = Console.ReadLine().Split(' ');
        var a = int.Parse(ab[0]);
        var b = int.Parse(ab[1]);
        var ans = Math.Max(Math.Max(
            a + b,
            a - b),
            a * b);
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
import numpy as np

n, W = map(int, input().split())
w, v = [],[]
for i in range(n):
    temp = list(map(int, input().split()))
    w.append(temp[0])
    v.append(temp[1])

table = np.full(sum(v)+1, np.inf)
table[0] = 0

for i in range(n):
    l = table[:-v[i]]
    r = table[v[i]:]
    np.minimum(l + w[i], r, out = r)
    
print(np.max(np.where(table <= W)))

Measured memory_bytes: 13924
#include<stdio.h>
int main(void)
{
	int a,s[7],i,j,d,f,g,h;
	scanf("%d",&a);
	for(i=1;i<=6;i++)	s[i]=0;
	for(i=1;i<=a;i++){
		scanf("%d.%d",&d,&f);
		if(d>=185)
			s[6]++;
		else if(d>=180)
			s[5]++;
		else if(d>=175)
			s[4]++;
		else if(d>=170)
			s[3]++;
		else if(d>=165)
			s[2]++;
		else if(d<165)
			s[1]++;
	}
	for(i=1;i<=6;i++){
		printf("%d:",i);
		for(j=1;j<=s[i];j++){
			printf("*");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1028
import * as fs from 'fs';

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
}

class Queue<T> {
	array: T[];
	start: number;
	end: number;
	N: number;
	constructor(N: number) {
		this.N = N+1;
		this.array = new Array(this.N).fill(null);
		this.start = 0;
		this.end = 0;
	}
	push(n: T): void {
		this.array[this.end++] = n;
		this.end = this.end%this.N;
	}
	pop(): T {
		let a: T = this.array[this.start++];
		this.start = this.start%this.N;
		return a;
	}
	size(): number {
		if (this.end < this.start) {
			return this.N-(this.start-this.end);
		}
		return this.end-this.start;
	}
	clear(): void {
		this.start = 0;
		this.end = 0;
	}
	print(): void {
		console.log(`Queue. start=${this.start} end=${this.end} size=${this.size()}`);
		for(let i=this.start; i<this.start+this.size(); i++) {
			console.log(this.array[i%this.N]);
		}
	}
}


function solve(): number {
	let reader = new Reader();
	let N = reader.readInt();
	let S: number[][] = [];
	for(let i=0; i<N; i++) {
		let line = reader.readLine();
		S.push(new Array(N).fill(null).map((value, index) => Number(line.charAt(index))));
	}
	let isLeft: boolean[] = new Array(N).fill(false);
	let isAssigned: boolean[] = new Array(N).fill(false);
	isLeft[0] = true;
	isAssigned[0] = true;
	let stack: number[] = [0];
	while (stack.length > 0) {
		let parentNode = stack.pop();
		for(let j=0; j<N; j++) {
			if (S[parentNode][j] == 1) {
				if (!isAssigned[j]) {
					isLeft[j] = !isLeft[parentNode];
					isAssigned[j] = true;
					stack.push(j);
				} else if (isLeft[j] == isLeft[parentNode]) {
					return -1;
				}
			}
		}
	}
	for(let i=0; i<N; i++) {
		for(let j=0; j<N; j++) {
			if (i != j && S[i][j] == 0) {
				S[i][j] = Number.POSITIVE_INFINITY;
			}
		}
	}
	for(let k=0; k<N; k++) {
		for(let i=0; i<N; i++) {
			for(let j=0; j<N; j++) {
				S[i][j] = Math.min(S[i][j], S[i][k]+S[k][j]);
			}
		}
	}
	let diameter = 0;
	for(let i=0; i<N; i++) {
		for(let j=0; j<N; j++) {
			diameter = Math.max(diameter, S[i][j]);
		}
	}

	return diameter+1;
}

console.log(solve());


Measured memory_bytes: 35128
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAX_N = 110;
const int MAX_H = 100000;
int dp[MAX_H];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h,n;
	cin >> h >> n;
	vector<int> a(n), b(n);
	REP(i,n) cin >> a[i] >> b[i];
	REP(i,MAX_H) dp[i] = 1<<29;
	dp[0] = 0;

	REP(hh, h+1){
		REP(i,n){
			dp[hh + a[i]] = min(dp[hh+a[i]], dp[hh]+b[i]);
		}
	}

	int ans = 1<<29;
	FOR(i,h,MAX_H) ans = min(ans, dp[i]);
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 640
#!python3.8
# -*- coding: utf-8 -*-
# abc174/abc174_a
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    X = i2n()
    print('Yes' if X >= 30 else 'No')
    return

main()


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

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<ll, ll> pll;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

//----------------------------------------------------------------------

#define MAX 1000

int main(void) {
  cin >> n;
  string c[110];
  
  flag = false;

  FOR(i, 0, n) {
	cin >> c[i];
	if (c[i] == "Y") flag = true;
  }

  if (flag) {
	cout << "Four" << endl;
  }
  else {
	cout << "Three" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	int x;
	cin >> x;
	if(x<1200)
		cout << "ABC" << endl;
	else
		cout << "ARC" << endl;
}

Measured memory_bytes: 3584
#include<cstdio>
#include<map>
#include<set>
#include<queue>
long long int n;
long long int a, b, c, d;
std::map<long long int, long long int> codemp;
std::set<long long int> chkset;
struct st {
	long long int v, c;
	bool operator<(const st&r)const {
		return c > r.c;
	}
};
std::priority_queue<st> pq;
long long int ans;
void pqinsert(long long int v, long long int c) {
	if (codemp.find(v) != codemp.end()) {
		if (codemp[v] < c)return;
	}
	codemp[v] = c;
	st p;
	p.v = v;
	p.c = c;
	pq.push(p);
}
int main() {
	int tcn;
	scanf("%d", &tcn);
	while (tcn--) {
		scanf("%lld", &n);
		scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
		ans = (a + d) * 100LL;
		codemp[n] = 0;
		st initp;
		initp.v = n;
		initp.c = 0;
		pq.push(initp);
		while (pq.size() > 0) {
			st pa = pq.top();
			pq.pop();
			long long int pv = pa.v;
			long long int pc = pa.c;
			if (chkset.find(pv) != chkset.end()) {
				continue;
			}
			chkset.insert(pv);
			pqinsert(pv / 2, a + pc + d * (pv % 2));
			pqinsert(pv / 2 + 1, a + pc + d * (2 - pv % 2));
			pqinsert(pv / 3, b + pc + d * (pv % 3));
			pqinsert(pv / 3 + 1, b + pc + d * (3 - pv % 3));
			pqinsert(pv / 5, c + pc + d * (pv % 5));
			pqinsert(pv / 5 + 1, c + pc + d * (5 - pv % 5));
			if ((ans - pc + d - 1) / d > pv) {
				ans = pv * d + pc;
			}
		}
		codemp.clear();
		chkset.clear();
		printf("%lld\n", ans);
	}
	return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vz;
typedef vector<vz> vvz;
typedef pair<ll, ll> pll;
#define sz(x) ll((x).size())
#define fo(i,n) for(ll i=0; i<(n); i++)
#define FO(i,a,b) for(ll i=(a); i!=(b); i+=(b)>(a)?1:-1)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(c) c.begin(), c.end()
#define F first
#define S second
#define os(x) cout<<x<<' '
#define on(x) cout<<x<<"\n"
#define nl cout<<"\n"
#define maxe(x) max_element(all(x))-(x).begin()
#define mine(x) min_element(all(x))-(x).begin()
const ll P=1e9+7;

ll gcd(ll a, ll b)
{
	ll m=min(a, b), M=max(a, b);
	if(m==0) return M;
	return gcd(m, M%m);
}

ll powmod(ll x, ll y)
{
	ll ans=1;
	while(y>0)
	{
		if(y%2) ans=(ans*x)%P;

		x=(x*x)%P;
		y/=2;
	}
	return ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("C:\\Users\\ASISH\\Desktop\\coding\\input1.txt", "r", stdin);
	freopen("C:\\Users\\ASISH\\Desktop\\coding\\output1.txt", "w", stdout);
#endif

	ll n;
	cin>>n;
	vector<pll> a(n);
	fo(i, n) cin>>a[i].F>>a[i].S;
	vll p, q, r;
	fo(i, n){
		p.pb(a[i].F + a[i].S);
		q.pb(a[i].S - a[i].F);
		r.pb(a[i].F - a[i].S);
	}
	sort(all(p));
	sort(all(q));
	sort(all(r));
	on(max(p[n-1]-p[0], max(q[n-1]-q[0], r[n-1]-r[0])));
	cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "s\n";
	return 0;
}

Measured memory_bytes: 11288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,m;
    cin >> n >> m;
    vector<ll>p(m),y(m);
    vector<vector<ll>>py(n+1);
    for(ll i=0;i<m;i++){
        cin >> p[i] >> y[i];
        py[p[i]].push_back(y[i]);
    }
    for(ll i=1;i<=n;i++){
        sort(py[i].begin(),py[i].end());
    }
    vector<ll>number(m);
    for(ll i=0;i<m;i++){
        auto ite=lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i]);
        number[i]=ite-py[p[i]].begin()+1;
    }
    for(ll i=0;i<m;i++){
        string ans;
        ll pketa=0,pcopy=p[i];
        while(pcopy>0){
            pketa++;
            pcopy/=10;
        }
        for(ll j=0;j<6-pketa;j++){
            ans.push_back('0');
        }
        pcopy=p[i];
        for(ll j=pketa-1;j>=0;j--){
            ll x=pcopy/pow(10,j);
            x%=10;
            char pc=x+'0';
            ans.push_back(pc);
        }
        cout << endl;
        ll nketa=0,ncopy=number[i];
        while(ncopy>0){
            nketa++;
            ncopy/=10;
        }
        for(ll j=0;j<6-nketa;j++){
            ans.push_back('0');
        }
        ncopy=number[i];
        for(ll j=nketa-1;j>=0;j--){
            ll x=ncopy/pow(10,j);
            x%=10;
            char nc=x+'0';
            ans.push_back(nc);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 11044
def resolve():
    '''
    code here
    '''
    N = int(input())
    robots = [[int(item) for item in input().split()] for _ in range(N)]


    arm_body_arm = []

    for body, arm in robots:
        arm_body_arm.append([body - arm, body + arm])
    
    arm_body_arm = sorted(arm_body_arm, key=lambda x:x[1])

    res = 1
    prev = arm_body_arm[0][1]
    for start, end in arm_body_arm:
        if prev <= start:
            res += 1
            prev = end

    print(res)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 40312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll inf  = 1e7+5;
typedef pair<int, bool> pib;
bool visited [inf];
int dist[inf];
int main() {
  int n; cin >> n;
  vector<int> arr (n);
  int maxIndex = -1;
  int maxValue = -1;
  int secondValue = -1;
  for (int i = 0 ; i < n; i++){
      cin >> arr[i];
      if (arr [i] > maxValue){
          maxIndex = i;
          maxValue = arr[i];
      }
      else if (arr[i] > secondValue){
          secondValue = arr[i];
      }
  }
  for (int i = 0; i < n; i++){
      if (i != maxIndex){
          cout << maxValue << '\n';
      }
      else{
          cout << secondValue << '\n';
      }
  }
}



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

#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 EPS (1e-7)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int MAX_N=200001;

int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n);
	REP(i,n)cin>>a[i];
	REP(i,n)cin>>b[i];
	REP(i,n)cin>>c[i];
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	ll ans=0;
	REP(i,n){
		ll j=lower_bound(a.begin(),a.end(),b[i])-a.begin();
		ll k=upper_bound(c.begin(),c.end(),b[i])-c.begin();
		ans+=j*(n-k);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 10000000000000000;
const ll mod = 1000000007;
ll iti[12345678], test[12345678], cost[4321][4321];
signed main() {
	ll n, m, sum = 0, ans = 0; cin >> n;
	ll mae = 0, ato = n - 1;
	for(int h = 0; h < n; h++) {
		cin >> test[h];
	}
	sort(test, test + n);
	ll a = 0, cnt1 = 0, cnt2 = 0;
	while (true) {
		a++;
		if (mae == 0) { cnt1 = test[mae]; cnt2 = test[mae]; mae++; continue; }
		if (mae > ato) { break; }
		if (mae == ato) {
			sum += max(abs(test[mae] - cnt1), abs(test[mae] - cnt2));
			break;
		}
		if (a % 2 == 0) { 
			sum += abs(test[ato] - cnt1); cnt1 = test[ato]; ato--;
			sum += abs(test[ato] - cnt2); cnt2 = test[ato]; ato--;
		}
		else {
			sum += abs(test[mae] - cnt1); cnt1 = test[mae]; mae++;
			sum += abs(test[mae] - cnt2); cnt2 = test[mae]; mae++;
		}
		//cout << ' ' << sum << endl;
	}
	a = 0; cnt1 = 0; cnt2 = 0; mae = 0; ato = n - 1; ans = sum; sum = 0;
	while (true) {
		a++;
		if (ato == n - 1) { cnt1 = test[ato]; cnt2 = test[ato]; ato--; continue; }
		if (mae > ato) { break; }
		if (mae == ato) {
			sum += max(abs(test[mae] - cnt1), abs(test[mae] - cnt2));
			break;
		}
		if (a % 2 == 1) {
			sum += abs(test[ato] - cnt1); cnt1 = test[ato]; ato--;
			sum += abs(test[ato] - cnt2); cnt2 = test[ato]; ato--;
		}
		else {
			sum += abs(test[mae] - cnt1); cnt1 = test[mae]; mae++;
			sum += abs(test[mae] - cnt2); cnt2 = test[mae]; mae++;
		}
		//cout << ' ' << sum << endl;
	}
	//cout << ans << ' ' << sum << endl;
	cout << max(ans, sum) << endl;
	cin >> n; return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <iostream>
#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
using namespace std;
const LL MOD=1e9+7;
LL n,a,b,mx,sum,h[100010];
bool check(LL mid)
{LL sum=0;
rep(i,n)
{
if(h[i]-mid*b>0) 
sum+=(h[i]-mid*b+(a-b-1))/(a-b);
}	return sum<=mid;
}
int main()
{
	cin>>n>>a>>b;
	LL mid;
	rep(i,n)
	{
cin>>h[i];
sum+=h[i];
mx=max(h[i],mx);
}
LL lb=(mx+a-1)/a,ub=(mx+b-1)/b;
while(lb<ub)
{
mid=(lb+ub)/2;
if(check(mid)) ub=mid;
else lb=mid+1;
}
cout<<lb<<endl;
return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

signed main(){
    const int INF = 1e9;
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int h,n; cin >> h >> n;
    vector<int> dp(h+1,INF);
    dp[0]=0;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        rep(j,h+1){
            int x=min(h,j+a);
            chmin(dp[x],dp[j]+b);
        }
    }
    cout << dp[h] << endl;
}




Measured memory_bytes: 3668
import collections as col

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

dic = col.Counter(li)
k = len(list(dic.keys()))

likey = list(dic.keys())
ans = 0
for i in range(k):
  tmp = dic[likey[i]]
  if likey[i] <= tmp:
    ans += tmp - likey[i]
  else:
    ans += tmp
print(ans)

Measured memory_bytes: 18672
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        var v = new List<int>();
        for (int i = 0; i < n; i++)
        {
            v.Add(sc.nextInt());
        }

        long ans = 0;
        for (int i = 0; i <= k; i++)
        {
            for (int j = 0; j <= k - i; j++)
            {
                if (n < i + j) continue;
                var w = new List<int>();
                for (int s = 0; s < i; s++)
                {
                    if (s == n) break;
                    w.Add(v[s]);
                }
                for (int t = 0; t < j; t++)
                {
                    if (n - t == 0) break;
                    w.Add(v[n - t - 1]);
                }
                if (w.Count == 0) continue;
                w.Sort();
                for (int u = 0; u < k - i - j; u++)
                {
                    if (w.Count == 0) break;
                    if (w[0] < 0) w.RemoveAt(0);
                }
                if (w.Count != 0) ans = Math.Max(ans, w.Sum());
            }
        }

        Console.WriteLine(ans);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <stdlib.h>

int descending( const void* a, const void* b)
{
     unsigned long int_a = * ( (unsigned long*) a );
     unsigned long int_b = * ( (unsigned long*) b );

     if ( int_a == int_b ) return 0;
     else if ( int_a < int_b ) return 1;
     else return -1;
}

unsigned long sum( unsigned long *ul, unsigned long size )
{
    unsigned long val = 0;
    for( unsigned long i = 0; i < size; i ++ )
    {
        val += ul[i];
    }
    return val;
}

int main()
{
    unsigned long n, i, color;
    unsigned long *c;
    scanf("%lu", &n);
    c = malloc( n * sizeof(unsigned long));
    for( i = 0; i < n; i++ )
    {
        scanf( "%lu", &c[i] );
    }

    qsort( c, n, sizeof(unsigned long), descending );
    
    i = 0;
    color = 0;
    while( i < n )
    {
        if( i == 0 
            || c[i]*2 >= c[i-1] )
        {
            color ++;
        }
        else
        {
            if( sum( &c[i], n-i )*2 >= c[i-1] ) 
            {
                color ++;
            }
            else
            {
                break;
            }
        }
        i++;
    }

    printf( "%lu ", color );
   
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll x, y;
  cin >> x >> y;

  string ans = "No";
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      if (i * 2 + j * 4 == y && i + j == x) {
        ans = "Yes";
      }
    }
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 3668
#include<stdio.h>
#include<string.h>
int main()
{
    int n, a, i, t;
    i = 1;
    scanf("%d%d", &n, &a);
    t = a;
    for (i = 1;t < n;)
    {
        t += a;
        i++;
    }
    printf("%d", i);
    return 0;
}

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

int main()
{
    string input;
    cin >> input;

    vector<string> dayList = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    int remain;
    for (int i = 0; i < dayList.size(); ++i)
    {
        if (input == dayList.at(i))
        {
            remain = (7 - i);
        }
    }

    cout << remain << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;

struct E{
	int to, len, num;
};

int n, m, l;
int cost[100][200];
vector<E> edge[100];

void solve(){
	rep(i,100) rep(j,200) cost[i][j] = INF;
	rep(i,100) edge[i].clear();
	rep(i,m){
		int a, b, d, e;
		cin >> a >> b >> d >> e;
		a--; b--;
		edge[a].push_back((E){b,d,e});
		edge[b].push_back((E){a,d,e});
	}
	cost[0][l] = 0;
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0,l));
	while(true){
		if(que.size() == 0) break;
		P q = que.top();
		que.pop();
		int v = q.second/1000, co = q.second%1000;
		rep(i,edge[v].size()){
			E e = edge[v][i];
			if(co >= e.len && cost[e.to][co-e.len] > cost[v][co]){
				cost[e.to][co-e.len] = cost[v][co];
				que.push(P(cost[e.to][co-e.len],e.to*1000+co-e.len));
			}
			if(cost[e.to][co] > cost[v][co]+e.num){
				cost[e.to][co] = cost[v][co]+e.num;
				que.push(P(cost[e.to][co],e.to*1000+co));
			}
		}
	}
	int ans = INF;
	rep(i,200) ans = min(ans,cost[n-1][i]);
	cout << ans << endl;
}

int main(){
	while(true){
		cin >> n >> m >> l;
		if(n==0&&m==0&&l==0) break;
		solve();
	}
}

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

#define INF 1000000000;

int main(){
    int n,m;
    int c[20];
    cin>>n>>m;
    for (int i=0; i<m; i++)cin>>c[i];
    
    int T[50000];
    for (int i=0; i<=n; i++)T[i]=INF;
    T[0]=0;
    for (int i=0; i<m; i++) {
        for (int j=c[i]; j<=n; j++) {
            T[j]=min(T[j], T[j-c[i]]+1);
        }
    }
    cout<<T[n]<<endl;
    return 0;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> p(n), x(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
    x.at(p.at(i)) = i;
  }
  
  multiset<ll> s;
  s.insert(x.at(n));
  s.insert(-1);
  s.insert(-1);
  s.insert(n);
  s.insert(n);
  ll ans = 0;
  for (int i = n - 1; i >= 1; i--) {
    s.insert(x.at(i));
    auto now = s.find(x.at(i));
    auto b = now;
    b--;
    auto a = b;
    a--;
    auto c = now;
    c++;
    auto d = c;
    d++;
    
    ll keep = (*now - *b) * (*d - *c) + (*b - *a) * (*c - *now);
    ans += keep * i;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 6528
#include <stdio.h>

int main(int ac, char** av) {
  int n, score_a = 0, score_b = 0, *a, *b;
  while(1) {
    scanf("%d", &n);
    if(n == 0) return 0;
    a = (int*) malloc(sizeof(int) * n);
    b = (int*) malloc(sizeof(int) * n);
    int i;
    for(i = 0; i < n; i++) {
      scanf("%d %d", a+i, b+i);
    }
    for(i = 0; i < n; i++) {
      if(a[i] > b[i]) {
        score_a += a[i] + b[i];
      } else if(a[i] < b[i]) {
        score_b += a[i] + b[i];
      } else if(a[i] == b[i]) {
        score_a += a[i];
        score_b += b[i];
      }
    }
    printf("%d %d\n", score_a, score_b);
    score_a = score_b = 0;
  }
  free(a);
  free(b);
  return 0;
}

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

int main(){
    int n;
    cin>>n;
   
    for(int i=0;i<n;i++){
        int res[3]={0};
        cin>>res[0]>>res[1]>>res[2];
        sort(res, res+3);
        if(res[2]*res[2]==(res[1]*res[1]+res[0]*res[0])) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

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

using namespace std;

int main() {
    int n;
    int_fast64_t s = 0;

    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        if(i % 3 != 0 && i % 5 != 0) {
            s += i;
        }
    }

    printf("%ld\n", s);

    return 0;
}

Measured memory_bytes: 3812
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
var lines = input.split('\n');

var num;
while (num = lines.shift()) {
    if (num == '0')
        break;

    var n = +num;
    var m = [];
    var colsum = [];
    for (var i = 0; i < n; i++) {
        var cols = lines.shift().split(' ').map(function(n){return +n;});
        cols[cols.length] = cols.reduce(function(p,n) {
            return p + n;
        });
        m.push(cols);

        for (var j = 0; j < cols.length; j++) {
            if (i == 0) {
                colsum.push(cols[j]);
            } else {
                colsum[j] += cols[j];
            }
        }
    }
    m.push(colsum);

    m.forEach(function(row) {
        row.forEach(function(col) {
            process.stdout.write(('    ' + col).slice(-5));
        });
        console.log();
    });
}

Measured memory_bytes: 10228
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    int cur = 0, ans = 1;
    rep(i,n){
        int l;
        cin >> l;
        cur += l;
        if(cur <= x) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    s = input()
    ans = ''
    for c in s:
        if c == 'B':
            ans = ans[:-1] if ans else ans
        else:
            ans += c
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61768
#include<stdio.h>
#include<cmath>
using namespace std;

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    double s,l,h;
    double rad = 2*M_PI*c/360.0;
    s = 1.0/2.0*a*b*sin(rad);
    double x;
    x = sqrt(a*a+b*b-2*a*b*cos(rad));
    l = a+b+x;
    h = 2.0*s/a;
    
    printf("%.5f\n%.5f\n%.5f\n",s,l,h);
    
    return 0;
}


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

int main() {
    long long a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a>=k){
        cout<<k<<endl;
    }
    if(a<k){
        if(b+a>=k){
            cout<<a<<endl;
        }else{
            cout<<a-(k-a-b)<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<list>
#include<stack>
#include<sstream>
#define lli long long int
#define h 100
#define pf push_front
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
using namespace std;
int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL) ;
  lli t, k, i, n, m, sum, flag, j;
  	cin>>n;
  	string x;
  	cin>>x;
  	if(n%2==1)cout<<"No"<<endl;
  	else
  	{
  		flag=1;
  		for(i=0,j=n/2;j<x.size();j++, i++)  
  		if(x[i]!=x[j]) {flag=0;break;} 
  		if(flag) cout<<"Yes"<<endl;
  		else cout<<"No"<<endl;
  	} 
  return 0;
} 


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

vvec<pair<int,int>> G;
vec<int> ans;
void dfs(int cur = 0, int pre = -1, int col = 0){
    ans[cur] = col;
    for(auto nxt: G[cur]){
        if(nxt.first == pre)continue;
        dfs(nxt.first, cur, (col + nxt.second)%2);
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    G.resize(N);
    ans.resize(N);
    rep(i,N-1){
        int u, v, w;
        cin >> u >> v >> w;
        u--;v--;
        w &=1;
        G[u].push_back({v,w});
        G[v].push_back({u,w});
    }
    dfs();
    rep(i,N){
        cout << ans[i] << endl;
    }
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
typedef unsigned long long ull;
const ull BASE = 1e9 + 7;

string A, B;
int n, m;

ull getHash(const vector< int >& c) {
	ull ret = 0;
	for_(i,0,26) ret = ret * BASE + c[i];
	return ret;
}

bool check(int k) {
	if (k == 0) return true;
	
	vector< int > c(26, 0);
	for_(i,0,k) c[A[i] - 'a']++;
	
	unordered_set< ull > hash_set;
	hash_set.insert(getHash(c));
	
	for_(i,k,n) {
		c[A[i-k] - 'a']--;
		c[A[i] - 'a']++;
		hash_set.insert(getHash(c));
	}
	
	c.assign(26, 0);
	for_(i,0,k) c[B[i] - 'a']++;
	
	if (hash_set.count(getHash(c))) return true;
	
	for_(i,k,m) {
		c[B[i-k] - 'a']--;
		c[B[i] - 'a']++;
		if (hash_set.count(getHash(c))) return true;
	}
	
	return false;
}

int main() {
	cin >> A;
	cin >> B;
	n = A.size();
	m = B.size();
	
	for_rev(i,min(n,m),0) {
		if (check(i)) {
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 3272
#include <iostream>
#include <deque>
#include <string>
#include <vector>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <cmath>
#include<list>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int maxn = 1e4 + 8;

int n,q,x,num;
int s[maxn],t[maxn];

bool if_find(int x)
{
    s[n] = x;
    int i = 0;
    while(s[i] != x) i++;
    if(i == n) return false;
    return true;
}
int main()
{
    scanf("%d",&n);
    num = 0;
    for(int i = 0; i < n; ++i) scanf("%d",&s[i]);
    scanf("%d",&q);
    for(int i = 0; i < q; ++i){
        scanf("%d",&x);
        if(if_find(x)){
            num++;
        }
    }
    printf("%d\n",num);
    return 0;
}

Measured memory_bytes: 3240
n=int(input())
A = list(map(int,input().split(' ')))
A.sort()
B = list(map(int,input().split(' ')))
B.sort()
C = list(map(int,input().split(' ')))
C.sort()
ia=0
ib=0
Lb = [0]*n
while ia<n and ib<n:
    if A[ia]<B[ib]:
        Lb[ib]+=1
        ia+=1
    else:
        ib+=1
jb = 0
LB=[]
bb=0
while jb<n:
    bb+=Lb[jb]
    LB.append(bb)
    jb+=1

kb=0
kc=0
Lc=[0]*n
while kb<n and kc<n:
    if B[kb]<C[kc]:
        Lc[kc]+=LB[kb]
        kb+=1
    else:
        kc+=1

jc=0
LC=[]
cc=0
while jc<n:
    cc+=Lc[jc]
    LC.append(cc)
    jc+=1
x=int(sum(LC))
print(x)

Measured memory_bytes: 28212
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    std::cin >> N;

    std::vector<ll> d;
    d.resize(N);

    for(ll i=0; i<N; ++i)
        std::cin >> d[i];

    std::sort(d.begin(), d.end());

    ll ans = 0;
    for(int k=1; k<=100000; ++k)
    {
        auto it = std::upper_bound(d.begin(), d.end(), k);
        ll pos = it - d.begin();

        if(pos==N/2)
            ans++;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1152
"""
author : halo2halo
date : 24,Oct,2019
"""

import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c = map(int, readline().rstrip().split())

print("YES" if (a*100+b*10+c) % 4 == 0 else "NO")


Measured memory_bytes: 2940
use std::io::*;
use std::str::FromStr;

fn main() {
    let mut x: i64 = read();
    let y: i64 = read();
    let mut ans: i64 = 0;
    if y >= 0 {
        if x > y {
            ans += 1;
            x = -x;
        }
        if -y <= x && x < 0 {
            ans += 1;
            x = -x;
        }
        if x >= 0 || y == 0 {
            ans += y - x;
        } else {
            ans += -y - x + 1;
        }
    } else {
        if x > -y {
            ans += 1;
            x = -x;
        }
        if y < x && x < 0 {
            ans += 1;
            x = -x;
        }
        if x < 0 || y == 0 {
            ans += y - x;
        } else {
            ans += -y - x + 1;
        }
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352