akhauriyash/Code-Regression huggingface dataset:
N, M, Q = map(int, input().split())

class Cell:
    def __init__(self):
        self.value = 0
        self.L = 0
    def __repr__(self):
        return str((self.value, self.L))

pairs = [[Cell() for _ in range(N+1)] for _ in range(N+1)]
for L, R in (map(int, input().split()) for _ in range(M)):
    cell = pairs[L][R]
    cell.value += 1
    cell.L = cell.value

for i in range(N-1, 0, -1):
    for j in range(i+1, N+1):
        cell = pairs[i][j]
        cell.L += pairs[i][j-1].L
        cell.value = cell.L + pairs[i+1][j].value
for p, q in (map(int, input().split()) for _ in range(Q)):
    print(pairs[p][q].value)


Measured memory_bytes: 53108
N = int(input())
*a, = map(int, input().split())
dp = [[0]*(N+1) for _ in range(N+1)]

for l in range(1, N+1):
    for i in range(N-l+1):
        j = i+l
        if (N-l) % 2 == 0:
            # first
            dp[i][j] = max([dp[i+1][j]+a[i], dp[i][j-1]+a[j-1]])
        else:
            # second
            dp[i][j] = min([dp[i+1][j]-a[i], dp[i][j-1]-a[j-1]])

print(dp[0][N])


Measured memory_bytes: 113628
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    int a,b,n,e,f=0;
    cin >> n >> a >> b;
    for(int i=1;i<=n;i++){
        e=0;
        int h=i;
        while(h!=0){
            e+=h%10;
            h=h/10;
        }
        if(e>=a&&e<=b){
           f+=i;
        }
    }
    cout << f;
}

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

using namespace std;

int main(void)
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> roadTarget(N+1, vector<int>());
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        roadTarget[a].push_back(b);
        roadTarget[b].push_back(a);
    }

    vector<int> ans(N+1, -1);
    queue<int> que;
    que.push(1);
    while(!que.empty()){
        int room = que.front();
        que.pop();
        vector<int>& target = roadTarget[room];
        for(int i = 0; i < target.size(); i++){
            if(ans[target[i]] == -1){
                ans[target[i]] = room;
                que.push(target[i]);
            }
        }
    }
    bool ok = true;
    for(int i = 2; i <= N; i++){
        if(ans[i] == -1){
            ok == false;
        }
    }
    if(ok){
        cout << "Yes" << endl;
        for(int i = 2; i <= N; i++){
            cout << ans[i] << endl;
        }
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 10044
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
using namespace std;

int main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }
    string s;
    cin >> s;
    if (s == "SUN") {
        cout << 7;
    }
    else if (s == "MON") {
        cout << 6;
    }
    else if (s == "TUE") {
        cout << 5;
    }
    else if (s == "WED") {
        cout << 4;
    }
    else if (s == "THU") {
        cout << 3;
    }
    else if (s == "FRI") {
        cout << 2;
    }
    else if (s == "SAT") {
        cout << 1;
    }
    return 0;
}

Measured memory_bytes: 256
def makedivisor(N):  # 約数列挙
    p, upper, lower = 1, [], []
    while p * p <= N:
        if N % p == 0:
            lower.append(p)
            if p * p != N:
                upper.append(N // p)
        p += 1
    return lower + upper[::-1]


def totient(N):  # オイラーのトーシェント関数
    p, phi = 2, N
    while p * p <= N:
        if N % p == 0:
            phi = phi // p * (p - 1)
        while N % p == 0:
            N //= p
        p += 1
    if N > 1:
        phi = phi // N * (N - 1)
    return phi

k = int(input()) * 9

# 解説AC オイラーの定理 O(n**0.5)
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()
if k % 7 == 0:
    k //= 7

cnt = totient(k)
num = makedivisor(cnt)
for i in num:
    if pow(10, i, k) == 1:
        print(i)
        break


Measured memory_bytes: 62736
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#define mid ((l + r) / 2)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1.0);

int main() {
    ios_base :: sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    if(k == 1) cout << 0; 
    else {
        if(n - k > 0) cout << n - k;
        else cout << 0;
    }
    cout << endl;
    return 0;
}

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

namespace AtCoder
{
    public class MainClass
    {
        public static void Main(string[] args)
        {
            var paramsList = Console.ReadLine().Split(' ').ToList();
            // abk
            var a = int.Parse(paramsList[0]);
            var b = int.Parse(paramsList[1]);
            var k = int.Parse(paramsList[2]);

            int count = 0;
            for (int i = 100; i >= 1; --i)
            {
                if ((a % i == 0) && (b % i == 0))
                {
                    ++count;
                    if (count == k)
                    {
                        Console.WriteLine(i);
                        return;
                    }
                }
            }
        }
    }

    public static class EnumerablePlus
    {
        ///<summary>出力文字列に変換。</summary>
        public static string MkString<T>(this IEnumerable<T> list)
        {
            return list.Aggregate(
                new System.Text.StringBuilder(),
                (a, b) => ((a.Length > 0) ? a.Append(' ') : a).Append(b)
                ).ToString();
        }

        ///<summary>添字付きfor。</summary>
        public static void ForEach<T>(this IEnumerable<T> list, Action<T, int> a)
        {
            int i = 0;
            foreach (var item in list)
            {
                a(item, i);
            }
        }

        ///<summary>指定回数デリゲートを呼び出す。</summary>
        public static IEnumerable<T> Repeat<T>(int n, Func<T> f)
        {
            for (int i = 0; i < n; i++)
            {
                yield return f();
            }
        }
    }

    public static class MathPlus
    {
        ///<summary>素因数分解。昇順。</summary>
        public static List<int> Prime(int a)
        {
            var res = new List<int>();

            for (int b = 2, c = (int)Math.Ceiling(Math.Sqrt(a)); b <= c; ++b)
            {
                while (a % b == 0)
                {
                    res.Add(b);
                    a = a / b;
                }
            }

            return res;
        }

        ///<summary>最小公倍数。</summary>
        public static long Lcm(IEnumerable<long> list)
        {
            return list.Aggregate(0L, (a, b) => a == 0L ? b : Lcm(a, b));
        }

        ///<summary>最小公倍数。</summary>
        public static long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }

        ///<summary>最大公約数。</summary>
        public static long Gcd(IEnumerable<long> list)
        {
            return list.Aggregate(0L, (a, b) => a == 0L ? b : Gcd(a, b));
        }

        ///<summary>最大公約数。</summary>
        public static long Gcd(long a, long b)
        {
            if (a < b)
                Gcd(b, a);

            while (b != 0)
            {
                long rem = a % b;
                a = b;
                b = rem;
            }

            return a;
        }
    }

}


Measured memory_bytes: 11220
#include<cstdio>
using namespace std;
int main(){
  int a, b;
  scanf ("%d%d", &a, &b);
  int ans = a / (b * 2 + 1);
  if (a > ans * (b * 2 + 1)) ans++;
  printf ("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"regexp"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	// sc.Split(bufio.ScanWords)
	S := readLine()

	fmt.Printf("%s\n", ARC065A(S))
}

// ARC065A ...
func ARC065A(S string) string {
	r := regexp.MustCompile(`^(dream|dreamer|erase|eraser)+$`)

	if r.MatchString(S) {
		return "YES"
	}
	return "NO"
}


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

using namespace std;

bool isTriangle(int i, int j, int k){
	return (i+j>k)&&(j+k>i)&&(k+i>j);
}

int main(){
  ios::sync_with_stdio(0);
  long long x, k, d;
  cin >> x >> k >> d;
  
  x = abs(x);
  
  if(x/d >= k){
  	x = x - k*d;
    cout << x;
    return 0;
  }
  
  long long hop = x/d;
  x -= (hop*d);
  k -= hop;
  if(k%2 == 0) cout << x;
  else cout << min(abs(x+d),abs(x-d));  
  
  return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <utility>
#include <queue>
#include <iostream>
using namespace std;
int main(){
  int W, H, gx, gy, sx, sy, n = 0;
  cin >> W >> H;
  string M[H];
  vector< pair<int,int> > springs;
  for(int i = 0; i < H; ++i){
    cin >> M[i];
    for(int j = 0; j < W; ++j){
      if(M[i][j] == 'g'){
	gx = i;
	gy = j;
	M[i][j] = '.';
      }else if(M[i][j] == 's'){
	sx = i;
	sy = j;
	M[i][j] = '.';
	++n;
      }else if(M[i][j] == '.') ++n;
      else if(M[i][j] == '*'){
	springs.push_back(make_pair(i,j));
      }
    }
  }
  long double INF = (1e10), l = 0.0, r = INF, exp_[H][W], exp[H][W];

  int d[] = {1,0,-1,0};
  queue< pair<int,int> > que;
  que.push(make_pair(gx,gy));
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      exp_[i][j] = INF;
      exp[i][j] = INF;
    }
  }

  exp_[gx][gy] = 0.0;
  while(!que.empty()){
    int x = que.front().first, y = que.front().second;
    que.pop();
    for(int k = 0; k < 4; ++k){
      int x_ = x + d[k], y_ = y + d[(k+1)%4];
      if(x_ >= H || x_ < 0 || y_ >= W || y_ < 0) continue;
      char c = M[x_][y_];
      if(c == '.' && exp_[x_][y_] > exp_[x][y]+1){
	exp_[x_][y_] = exp_[x][y]+1;
	que.push(make_pair(x_,y_));
      }
    }
  }
  /*
  long double dist_from_spring[H][W];
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      dist_from_spring[i][j] = INF;
    }
  }
  */
  vector< vector<long double> > dist_from_spring(H, vector<long double>(W, INF));
  for(int i = 0; i < springs.size(); ++i){
    queue< pair<int,int> > que2;
    que2.push(make_pair(springs[i].first, springs[i].second));
    dist_from_spring[springs[i].first][springs[i].second] = 0;
    while(!que2.empty()){
      int x = que2.front().first, y = que2.front().second;
      que2.pop();
      for(int k = 0; k < 4; ++k){
	int x_ = x + d[k], y_ = y + d[(k+1)%4];
	if(x_ >= H || x_ < 0 || y_ >= W || y_ < 0) continue;
	char c = M[x_][y_];
	if(c == '.' && (dist_from_spring[x_][y_] > dist_from_spring[x][y]+1)){
	  que2.push(make_pair(x_,y_));
	  dist_from_spring[x_][y_] = dist_from_spring[x][y]+1;
	}
      }
    }
  }
 
  for(int t = 0; t < 100; ++t){
    long double mean = (l+r)/2.0;
    long double s = 0.0;
    for(int i = 0; i < H; ++i){
      for(int j = 0; j < W; ++j){
	if(M[i][j] == '.'){
	  exp[i][j] = min(exp_[i][j], dist_from_spring[i][j]+mean);
	  s += exp[i][j];
	}
      }
    }

    if(s/n < mean){
      r = mean;
    }else{
      l = mean;
    }
  }
  printf("%.12Lf\n",exp[sx][sy]);
  return 0;
}

Measured memory_bytes: 14964
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] A = new int[N];
		long c = 1000000007;
		
		for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			A[a]++;
		}
		
		long ans = 1;

		if(N % 2 == 0) {
			for(int i = 1; i < N; i += 2) {
				if(A[i] != 2) {
					System.out.println(0);
					return;
				} else {
					ans = ans % c * 2 % c;
				}
			}
			System.out.println(ans);
		} else {
			if(A[0] != 1) {
				System.out.println(0);
				return;
			}
			for(int i = 2; i < N; i += 2) {
				if(A[i] != 2) {
					System.out.println(0);
					return;
				} else {
					ans = ans % c * 2 % c;
				}
			}
			System.out.println(ans);
		}
				
	}
}


Measured memory_bytes: 50716
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	int N,A,B,C;
	cin>>N>>A>>B>>C;
	vector<int> l(N);
	
	for(int i=0;i<N;i++){
		cin>>l[i];
	}
	
	int ans = Inf;
	
	for(int i=0;i<(1<<(2*N));i++){
		vector<int> a,b,c;
		int x = i;
		for(int j=0;j<N;j++){
			if(x%4==0)a.push_back(l[j]);
			if(x%4==1)b.push_back(l[j]);
			if(x%4==2)c.push_back(l[j]);
			x/=4;
		}
		if(a.size()==0||b.size()==0||c.size()==0)continue;
		
		int cost = (a.size()-1)*10 + (b.size()-1)*10 + (c.size()-1)*10;
		int sumA=0,sumB=0,sumC=0;
		for(int j=0;j<a.size();j++)sumA+=a[j];
		for(int j=0;j<b.size();j++)sumB+=b[j];
		for(int j=0;j<c.size();j++)sumC+=c[j];
		
		cost += abs(sumA-A)+abs(sumB-B)+abs(sumC-C);
		
		ans = min(ans,cost);
		
	}
	
	cout<<ans<<endl;
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
int main()
{
    int a,b,c;
    cin>>a>>b;
    int res=a,sum=1;
    if(b==1){
        cout<<0<<endl;
        return 0;
    }
    while(res<b){
        res+=a-1;
        sum++;
    }
    cout<<sum<<endl;
//    int n;
//    cin>>n;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main()
{
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	if(abs(c - a) <= d || abs(b - a) <= d && abs(c - b) <= d)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N, K;
  cin >> N >> K;
  vector<ll> minus;
  vector<ll> zero;
  vector<ll> plus;
  rep (i, N) {
    ll tmp;
    cin >> tmp;
    if (tmp < 0) minus.push_back(tmp);
    else if (tmp == 0) zero.push_back(tmp);
    else plus.push_back(tmp);
  }

  sort(minus.begin(), minus.end());
  sort(plus.begin(), plus.end());
  cerr << "K: " << K << endl;

  if (minus.size() * plus.size() >= K) {
    ll foo = -1000000010;
    foo *= 1000000010;

    ll bar = 0;

    while (bar - foo > 1) {
      ll mid = (foo + bar) / 2;
      ll count = 0;
      for (auto m: minus) {
        ll x = mid / m;
        if (mid % m) x++;
        ll tmp = lower_bound(plus.begin(), plus.end(), x) - plus.begin();
        tmp = plus.size() - tmp;
        count += tmp;
      }
      if (count < K) foo = mid;
      else bar = mid;
    }

    cout << bar << endl;
    return;
  }
  K -= minus.size() * plus.size();
  cerr << "K: " << K << endl;

  ll zero_count = 0;
  zero_count += zero.size() * (minus.size() + plus.size());
  zero_count += zero.size() * (zero.size() - 1) / 2;

  if (zero_count >= K) {
    cout << 0 << endl;
    return;
  }

  K -= zero_count;

  cerr << "K: " << K << endl;

  rep (i, minus.size()) minus[i] *= -1;
  sort(minus.begin(), minus.end());

  {
    ll foo = 0;
    ll bar = 1000000010;
    bar *= 1000000010;
    while (bar - foo > 1) {
      ll mid = (foo + bar) / 2;
      ll count = 0;
      for (auto mit = minus.begin(); mit != minus.end(); mit++) {
        ll m = *mit;
        ll x = mid / m;
        auto aaa = upper_bound(minus.begin(), minus.end(), x);
        if (mit < aaa) aaa = mit;
        ll tmp = aaa - minus.begin();
        count += tmp;
      }
      for (auto pit = plus.begin(); pit != plus.end(); pit++) {
        ll p = *pit;
        ll x = mid / p;
        auto aaa = upper_bound(plus.begin(), plus.end(), x);
        if (pit < aaa) aaa = pit;
        ll tmp = aaa - plus.begin();
        count += tmp;
      }
      //cerr << "---- mid: " << mid << ", count" << count << endl;
      if (count < K) foo = mid;
      else bar = mid;
    }

    cout << bar << endl;
    return;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 2548
import Control.Monad
import Control.Applicative

combinations :: Int -> [a] -> [[a]]
combinations 0 _ = [[]]
combinations _ [] = []
combinations n (x:xs) = (map (x:) (combinations (n-1) xs)) ++ (combinations n xs)

solve :: [Int] -> String
solve [n, x] =
   show $ length [nc3 | nc3<-combinations 3 [1..n], sum nc3==x]

main =
    mapM_ putStrLn =<< map solve . takeInputs . lines <$> getContents
    where
    takeInputs :: [String] -> [[Int]]
    takeInputs = takeWhile (not . all (== 0)) . map (map read . words) 


Measured memory_bytes: 5488
def cross(a, b):
    return (a.conjugate() * b).imag

points = int(raw_input())
pts = [complex(*[float(_) for _ in raw_input().split()]) for i in xrange(points)]

 
pts.sort(key=lambda p: (p.imag, p.real))
go_right = []
for p in pts:
    while len(go_right) >= 2 and cross(go_right[-1] - go_right[-2], p - go_right[-1]) < 0:
        go_right.pop()
    go_right.append(p)

go_left = []
for p in reversed(pts):
    while len(go_left) >= 2 and cross(go_left[-1] - go_left[-2], p - go_left[-1]) < 0:
        go_left.pop()
    go_left.append(p)

ans = go_right[:-1] + go_left[:-1]
print len(ans)
for p in ans:
    print int(p.real), int(p.imag)



Measured memory_bytes: 24020
#include <iostream>
#include <algorithm>

using namespace std;

main(){
  long long da[10][1001], a, b;
  fill(da[0], da[10], 0);
  da[0][0] = 1;
  for(int i=0;i<=100;i++){
    for(int j=8;j>=0;j--){
      for(int k=0;k<=1000;k++){
        if(da[j][k] && i + k <= 1000) da[j+1][i+k] += da[j][k];
      }
    }
  }
  while(cin >> a >> b && (a|b)) cout << da[a][b] << endl;
}

Measured memory_bytes: 1232
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
const double pi=acos(-1);
int main()
{
    double a,b,h,m,ma,ha,a1,a2,angle,l,d,s;
    cin>>a>>b>>h>>m;
    ma=m*(6.0);
    ha=h*(30.0);
    ha=ha+((0.5)*m);
    if(ma==0.0)
    {
        ma=360.0;
    }
    if(ha==0.0)
    {
        ha=360.0;
    }
    if(ha>=ma)
    {
        angle=ha-ma;
    }
    else
    {
        angle=ma-ha;
    }
    angle=(angle*pi)/180.0;
    l=(a*a)+(b*b)-((2*a*b)*cos(angle));
    d=sqrt(l);
    cout<<fixed<<showpoint<<setprecision(20)<<d<<endl;
    return 0;    
}

Measured memory_bytes: 4236
while(True):
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=="?":
        break
    if op=="+":
        print(a+b)
    elif op=="-":
        print(a-b)
    elif op=="/":
        print(int(a/b))
    else:
        print(a*b)

        



Measured memory_bytes: 5596
import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))

b = [0] * m
c = [0] * m
for i in range(m):
    b[i], c[i] = map(int, input().split())

hq = []

for i in range(n):
    heapq.heappush(hq, [-a[i], 1])

for i in range(m):
    heapq.heappush(hq, [-c[i], b[i]])

ans = 0

for i in range(n):
    val, cnt = heapq.heappop(hq)
    ans += -val
    if cnt > 1:
        cnt -= 1
        heapq.heappush(hq, [val, cnt])

print(ans)

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

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/


int main() {
    int n;
    cin >> n;
    vector<int> b(n - 1);
    rep(i, n - 1) cin >> b[i];
    int ans = 0;

    rep(i, n) {
        if (i == 0) {
            ans += b[i];
            continue;
        }
        else if(i == n - 1) {
            ans += b[i - 1];
            break;
        }
        ans += min(b[i - 1], b[i]);
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

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

unsigned euclidean_gcd(unsigned a, unsigned b) {
	if (a < b) euclidean_gcd(b, a);
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main() {
	int h, w;
	cin >> h >> w;
	int rec = euclidean_gcd(h, w);
	int div = h / rec;
	cout << h + w + 1 - (h / div) << endl;
	return 0;
}


Measured memory_bytes: 3136
#!/usr/bin/env python3
 
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)


Measured memory_bytes: 3976
#include"iostream"
using namespace std;
int partition(int a[],int p,int r)
{
	int t;
	int x = a[r];
	int i = p - 1;
	for(int j=p;j<r;++j)
		if (a[j] <= x)
		{
			++i;
			t = a[j];
			a[j] = a[i];
			a[i] = t;
		}
	t = a[i + 1];
	a[i + 1] = a[r];
	a[r] = t;
	return i + 1;
}
int main()
{
	int n;
	cin >> n;
	int* a = new int[n];
	int i;
	for (i = 0; i < n; ++i)
		cin >> a[i];
	int q = partition(a,0, n - 1);
	for (i = 0; i < n; ++i)
	{
		if (i)cout << ' ';
		if (i == q)cout << '[';
		cout << a[i];
		if (i == q)cout << ']';
	}cout << endl;
	return 0;
}



Measured memory_bytes: 3452
import sys
sys.setrecursionlimit(10**9)
INF = float('inf')


def BFord(n,es):
    v_cost = [INF]*n
    v_cost[0] = 0
    for v in range(n*2):
        for e in es:
            frm = e[0]
            to = e[1]
            if v_cost[to] > v_cost[frm]+e[2]:
                v_cost[to] = v_cost[frm]+e[2]
                if v >= n:
                    v_cost[to] = -INF
        if v == n-1:
            prev = v_cost[:]
    v_cost = [-INF if prev[idx]!=v_cost[idx] else v_cost[idx] for idx in range(n)]
    return v_cost
    

def main():
    n, m, p = map(int, input().split())
    es = []
    for _ in range(m):
        e = list(map(int, input().split()))
        es.append([e[0]-1, e[1]-1, - e[2] + p])

    v_cost = BFord(n,es)

    if v_cost[-1] == -INF:
        return -1

    return max(0, -v_cost[-1])


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 48112
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

L = sorted(L, key=lambda x: x[1], reverse=True) # 0番目の要素でソート
default_sum = sum(A)
# A.sort()
heapify(A)
n = 0
for times, num in L:
    cnt = 0
    while cnt < times and len(A) != 0:
        min_num = heappop(A)
        default_sum += max(num - min_num, 0)
        cnt += 1
print(default_sum)




    



Measured memory_bytes: 35664
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define mod 1000000007

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; }

typedef long long ll;
typedef pair<ll, ll> p;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  mint res = 0;
  comb_init();
  for (int i = k; i <= n+1; ++i) {
    mint tmp1, tmp2;
    tmp1 = (mint(i-1)*mint(i))/mint(2);
    tmp2 = (mint(i)*mint(2*n-i+1)) / mint(2);
    // cout << tmp2 << ' ' << tmp1 << endl;
    res += tmp2 - tmp1 + 1;
    // cout << res << endl;
  }
  cout << res << endl;
}


Measured memory_bytes: 15608
#include<bits/stdc++.h>
using namespace std;
    int main(){
        int a, b, c;
            cin >> a >> b >> c;
                if(a == b + c || b == a + c || c == a + b){
                    cout << "Yes";
                }else{
                    cout << "No";
                }
    return 0;}

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

using ll = long long;

constexpr ll INF = 1e18;

int main() {
    int N;
    cin >> N;
    vector<ll> a(3 * N);
    for(int i = 0; i < 3 * N; ++i) {
        cin >> a[i];
    }

    vector<ll> left(N + 1);
    vector<ll> right(N + 1);
    ll sum = 0;
    priority_queue<ll, vector<ll>, greater<ll>> que;
    for(int i = 0; i < N; ++i) {
        que.push(a[i]);
        sum += a[i];
    }
    left[0] = sum;
    for(int i = N; i < 2*N; ++i) {
        sum += a[i];
        que.push(a[i]);
        sum -= que.top();
        que.pop();
        left[i - N + 1] = sum;
    }

    sum = 0;
    priority_queue<ll> rque;
    for(int i = 3 * N - 1; i >= 2 * N; --i) {
        rque.push(a[i]);
        sum += a[i];
    }
    right[N] = sum;
    for(int i = 2 * N - 1; i >= N; --i) {
        sum += a[i];
        rque.push(a[i]);
        sum -= rque.top();
        rque.pop();
        right[i - N] = sum;
    }

    ll res = -INF;
    for(int i = 0; i <= N; ++i) {
        res = max(res, left[i] - right[i]);
    }
    cout << res << endl;
}


Measured memory_bytes: 6516
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i <= (b); ++i)
#define drep(i,a,b) for (int i = (a); i >= (b); --i)
#define grep(i,u) for (int i = head[u],v = e[i].v; i; v = e[i = e[i].nxt].v)
#define il inline
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>
#define fi first
#define se second
using namespace std;
il int read() {
	int res = 0,f = 1; char ch = getchar(); while (!isdigit(ch)) {if (ch == '-') f = -f; ch = getchar();}
	while (isdigit(ch)) {res = res*10+ch-'0'; ch = getchar();} return res*f;
}
namespace qiqi {
	const int N = 21; int n,m,f[N][1<<N],tr[1<<N][2],s[1<<N];
	il void print(int x) {drep(i,s[x],0) putchar('0'+((x>>i)&1)); putchar(' ');}
	void main() {
		int x,k; n = read(); m = read(); char ch = getchar(); rep(i,0,n) {while (ch != '0' && ch != '1') ch = getchar(); rep(j,0,(1<<i)-1) {f[i][j|(1<<i)] = ch-'0'; ch = getchar();}}
		s[0] = -1; rep(i,1,(2<<n)-1) if (s[i] = s[i>>1]+1) {if ((i>>(s[i]-1))&1) tr[i][0] = tr[tr[i][1] = i^(1<<s[i])][0]; else tr[i][1] = tr[tr[i][0] = i^(3<<(s[i]-1))][1];}
		drep(i,n,1) rep(j,1<<i,(2<<n)-1) if (f[i][j]) {k = (j&((1<<i)-1))|(1<<i); f[0][x=j>>i] += f[i][j]; if (tr[k][0]) f[s[tr[k][0]]][(((x<<1)|1)<<s[tr[k][0]])^tr[k][0]] += f[i][j]; if (tr[k][1]) f[s[tr[k][1]]][(x<<(s[tr[k][1]]+1))|tr[k][1]] += f[i][j];}
		x = 1; rep(i,2,(2<<n)-1) if (f[0][i] >= m && s[i] > s[x]) x = i; drep(i,s[x]-1,0) putchar('0'+((x>>i)&1));
	}
}
int main() {qiqi::main(); return 0;}

Measured memory_bytes: 194944
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second > b.second; }

signed main() {
    ll n; cin>>n;
    vector<pair<ll,ll>>r(n),b(n);
    rep(i,n)cin>>r[i].first>>r[i].second;
    rep(i,n)cin>>b[i].first>>b[i].second;
    sort(r.begin(),r.end(),cmp);
    sort(b.begin(),b.end());

    rep(i,n)rep(j,r.size()){
           if(r[j].first<b[i].first&&r[j].second<b[i].second){
               r.erase(r.begin()+j);
               break;
           }
    }
    cout << n-r.size() << endl;
}

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

int main(){
    int h,w; cin >> h >> w;
    int n; cin >> n;
    vector<int> a;
    rep(i,n) {
        int x; cin >> x;
        rep(j,x) a.push_back(i+1);
    }
    vector<vector<int>> ans(h,vector<int> (w));
    int cnt = 0;
    rep(i,h){
        rep(j,w){
            if(i %2 == 0) ans[i][j] = a[cnt];
            else ans[i][w-1-j] = a[cnt];
            cnt++;
        }
    }
    rep(i,h){
        rep(j,w-1) cout << ans[i][j] << ' ';
        cout << ans[i][w-1] << endl;
    }
}

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

int main() {
	char s[11];
	scanf("%s", s);
	
	int ans;
	if(s[0]=='M') ans = 6;
	else
	if(s[2]=='E') ans = 5;
	else
	if(s[0]=='W') ans = 4;
	else
	if(s[1]=='H') ans = 3;
	else
	if(s[0]=='F') ans = 2;
	else
	if(s[2]=='T') ans = 1;
	else ans = 7;
	
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n';
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod2 = 1000000007;
constexpr ll mod = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end(),greater<ll>());
  unordered_map<ll,ll> mp;
  for(int i=0; i<N; i++){
    mp[A[i]]++;
  }
  int ans = 0;
  for(int i=0; i<N; i++){
    if(mp[A[i]] == 0) continue;
    mp[A[i]]--;
    for(int j=40; j>=0; j--){
      if(!mp.count((1LL<<j)-A[i])) continue;
      if(mp[(1LL<<j) - A[i]] > 0){
        ans++;
        mp[(1LL<<j)-A[i]]--;
      }      
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10056
while True:
    n = int(input())
    if n == 0:
        break
    d = []
    for i in range(n):
        tmp = input().split()
        t = tmp[0]
        w = sum(1 for c in tmp[1:] if not int(c))
        l = sum(1 for c in tmp[1:] if int(c) == 2)
        d.append([t, w, l, n-i])
    ans = sorted(d, key=lambda x: (x[1], x[2], x[3]))
    for a in ans[::-1]:
        print(a[0])

Measured memory_bytes: 7632
#include <bits/stdc++.h>
using namespace std;
#define opt ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long int
#define ull unsigned long long int
#define I int
#define S string
#define D long double
#define rep(i,a,b) for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
// I might be a loser, but I have nothing to lose :p
// g++ -std=gnu++14 A.cpp
int main()
{
opt;
I i;
S s;
cin>>s;
rep(i,0,s.size())
{
    if(s[i]=='1')
        s[i]='9';
    else
        s[i]='1';
}
cout<<s;
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int n, min, a;
    scanf("%d", &n);
    int r1, r2;
    scanf("%d", &r1);
    min = r1;
    scanf("%d", &r2);
    a = r2 - r1;
    if (min > r2)
      min = r2;
    n -= 2;
    while (n--) {
      scanf("%d", &r1);
      if (a < (r1 - min))
        a = r1 - min;
      if (min > r1)
        min = r1;
    }
    printf("%d\n", a);
    return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)


#define MAX_V 200100
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> each_scc[MAX_V];


void add_edge(int from, int to){
    G[from].push_back(to);
    rG[to].push_back(from);
}

void dfs(int v,bool used[], vector<int> &vs){
    used[v] = true;
    rep(i,G[v].size()){
        if(!used[G[v][i]])dfs(G[v][i],used,vs);
    }
    vs.push_back(v);
}

void rdfs(int v,int k,vector<int> &sccs, vector<int> &cmp, bool used[]){
    used[v] = true;
    sccs.push_back(v);
    cmp[v]=k;
    rep(i,rG[v].size()){
        if(!used[rG[v][i]])rdfs(rG[v][i],k,sccs,cmp,used);
    }
}

int scc(int V, vector<int> &cmp){
    vector<int> vs;
    bool used[MAX_V];
    fill(used, used+MAX_V, false);
    vs.clear();
    rep(v,V){
        if(!used[v])dfs(v,used, vs);
    }
    fill(used, used+MAX_V, false);
    int k=0;
    int cnt = 0;
    for(int i=vs.size()-1;i>=0;i--){
        vector<int> sccs;
        if(!used[vs[i]]){
            rdfs(vs[i],k++,sccs,cmp,used);
            each_scc[cnt++] = sccs;
        }
    }
    return k;
}


map<ll, ll> memo;
vector<int> nG[MAX_V];
int dfs(int cur,int prev,vector<int> &cost){
    int ret = cost[cur];
    int add=0;
    if (memo.count(cur) > 0) return memo[cur];
    for(auto &e:nG[cur]){
        if(e==prev)continue;
        add = max(add,dfs(e,cur,cost));
    }
    return memo[cur] = ret+add;
}

int f(vector<int> &list, vector<int> &cost, int v ){
    int ret = 0;
    for(auto &e:list){
        if(e>=v)continue;
        ret += cost[e];
    }
    return ret;
}

int main(){
    int v,e;
    cin>>v>>e;
    vector<int> c(v);
    rep(i,v)cin>>c[i];
    rep(i,e){
        int a,b;
        cin>>a>>b;
        add_edge(a,v+b);
        add_edge(v+a,b);
    }

    vector<int> cmp(v*2);
    int k = scc(2*v,cmp);

//    set<pii> st;


    rep(i,k){
        set<int> st;
        for(auto &e:each_scc[i]){
            for(auto &to:G[e]){
                if(st.count(cmp[to])!=0)continue;
                if(i==cmp[to])continue;
                st.insert(cmp[to]);
                nG[i].pb(cmp[to]);
            }
        }
    }

    vector<int> nc(k);
    rep(i,k){
        nc[i] = f(each_scc[i],c,v);
    }
    cout<<dfs(cmp[0],-1,nc)<<endl;
}

Measured memory_bytes: 71852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int n = 1, m = 0;
		StringBuilder sb = new StringBuilder();
		while((1<<n-1)-1<l) n++;
		n--;
		for (int i = 1; i < n; i++) {
			sb.append(String.valueOf(i)+' '+String.valueOf(i+1)+" 0\n");
			sb.append(String.valueOf(i)+' '+String.valueOf(i+1)+' '+String.valueOf(1<<(i-1))+"\n");
			m += 2;
		}
		int max = (1<<n-1)-1;
		while(l-max>1) {
			int k = 1;
			while((1<<k-1)<l-max) k++;
			k--;
			sb.append(String.valueOf(k)+' '+String.valueOf(n)+' '+String.valueOf(max+1)+"\n");
			m++;
			max += (1<<k-1);
		}
		System.out.printf("%d %d\n",n,m);
		System.out.println(new String(sb));
		sc.close();
	}
}

Measured memory_bytes: 23764
#include <iostream>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

  int k, s; cin >> k >> s;

  int ans = 0;
  rep(i, k+1) rep(j, k+1) {
    int c = s - i - j;
    if(0<=c && c<=k) ++ans;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std; 

int list[1000000]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163,
 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251,
 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443,
 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557,
 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647,
 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757,
 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983,
 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069};

long int a,b,loop,hasil,input,mid;
long int lo;
long int hi;

 bool Prima(unsigned long n) 
{
    for (unsigned short i = 0; list[i]*list[i] <= n; i++) 
	{
        if (n % list[i] == 0) 
		{
            return false;
        }
    }
 
    return true;
}

int main()
{
	lo=1087;
	a=180;
	while(lo<=1000003)
	{
		if(Prima(lo))
		{
			list[a]=lo;
			a++;
		}
		lo+=2;
	}
	//printf("%d",list[78498]);
	while(scanf("%ld",&input)!= EOF)
	{	
	lo=0;
	while(input>=list[lo])
	{
		lo++;
	}
	printf("%d\n",lo);
	}
	return 0; 
}

Measured memory_bytes: 1496
#include<iostream>
#include<map>
#include<list>
#include<stack>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

int main(){
	int A,B,C,X;
	cin >> A >> B >> C >> X;
	
	int cnt = 0;
	for(int i = 0;i < A+1;i++){
		for(int j = 0;j < B+1;j++){
			for(int k = 0;k < C+1;k++){
				if( (500*i + 100*j + 50*k) == X)cnt++;
			}
		}
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
s = list(map(str, input().rstrip()))
k = int(input())

diff = [(ord("a") + 26 - ord(x)) % 26 for x in s]

for i in range(len(s) - 1):
    if diff[i] <= k:
        s[i] = "a"
        k -= diff[i]
    else:
        continue

tmp = ord(s[-1]) + k % 26
if tmp > 122:
    tmp -= 26

s[-1] = chr(tmp)

print("".join(s))

Measured memory_bytes: 4916
package main

import (
  "fmt"
)

func areChained(s, t string) bool {return s[len(s)-1] == t[0]}

func main() {
  var a [3]string
  for i := 0; i < 3; i++ {fmt.Scan(&a[i])}
  ans := "YES"
  for i := 0; i < 2; i++ {
    if !areChained(a[i], a[i+1]) {
      ans = "NO"
      break
    }
  }
  fmt.Println(ans)
}

Measured memory_bytes: 512
L1 = input()
L2 = list(map(int,input().split(" ")))
LA = [0]*int(L1)

for i in range(len(LA)):
    if i == 0:
        LA[i] = L2[i]
    elif i == len(LA)-1:
        LA[i] = L2[i-1]
    else:
        LA[i] = min(L2[i-1],L2[i])
print(sum(LA))

Measured memory_bytes: 38384
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	public static void main(String[] args) {
		int X=sc.nextInt();
		int g,ans=1;
		for(int i=2;i<=X;i++) {
			
			for(int a=2;a<=i&&a*a<=i;a++) {
				g=i;
				//p(i+" "+a);
				if(g%a==0) {
					g/=a;
					while(g%a==0) {
						g/=a;
						if(g==1) {
							ans=i;
							break;
							}
					}
				
				}
				if(ans==i)break;
			}
		}
		p(ans);
	}
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 21844
/*
 * ALDS1_11_C.cpp
 *
 *  Created on: May 8, 2018
 *      Author: 13743
 */

#include<iostream>
#include<queue>
#include<vector>

using namespace std;

queue<int> Q;
int d[101];

void bfs(vector<int>* a, int rt) {
	Q.push(rt);
	d[rt] = 1;
	while(!Q.empty()) {
		int u = Q.front();
		Q.pop();
		for(int &x:a[u]) {
			if(d[x] == 0) {
				Q.push(x);
				d[x] = d[u] + 1;
			}
		}

	}
}

int main() {
	int n;
	vector<int> adj[101];

	cin >> n;
	for(int i=0; i<n; i++) {
		int u, k;
		cin >> u >> k;
		while(k--) {
			int v;
			cin >> v;
			adj[u].push_back(v);
		}
	}

	bfs(adj, 1);

	for(int i=1; i<=n; i++) {
		cout << i << " " << d[i] - 1 << endl;
	}

}




Measured memory_bytes: 3128
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;

int main(){
	int n,a,b;
	cin>>n>>a>>b;
	int c=abs(a-b);
	if(c%2==0){
		cout<<"Alice"<<endl;
	}else{
		cout<<"Borys"<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
using namespace std;
using ll = long long;

signed main() {
    IO;
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll xor_val = 0, and_val;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        if(i > 1) xor_val ^= a[i];
    }
    if((a[0] + a[1] - xor_val < 0) || (a[0] + a[1] - xor_val) % 2 == 1) {cout << -1; return 0;}
    and_val = (a[0] + a[1] - xor_val) / 2;
    if((and_val & xor_val) != 0) {cout << -1; return 0;}
    
    ll a0 = 0, a1 = 0;
    bool pos = true;
    for(ll i = 45; i >= 0; --i) {
        ll two = 1ll << i;
        if(and_val & two) {
            a0 |= two; a1 |= two;
        }
    }
    for(ll i = 45; i >= 0; --i) {
        ll two = 1ll << i;
        if(xor_val & two) {
            ll new_a0 = a0 | two;
            if(new_a0 < a[0]) a0 = new_a0;
            else a1 |= two;
        }
    }
    DB(a0); DB(a1);

    if(a0 == 0) pos = false;
    if(a0 > a[0]) pos = false;

    if(!pos) cout << -1;
    else cout << a[0] - a0;
    return 0;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <cstring>

#define MAX_LEN 100

using namespace std;

int main() {
    int c, i, j=0;
    char T[] = "keyence_";
    bool dp[8][3][MAX_LEN+1] = {{{0}}};
    dp[0][0][0] = true;
    while ((c = getchar()) >= 'a' && c <= 'z') {
        for (i = 0; i < 8; i++) {
            dp[i][1][j+1] = dp[i][0][j] || dp[i][1][j];
            if (c == (int)T[i]) {
                dp[i+1][0][j+1] = dp[i][0][j];
                dp[i+1][2][j+1] = dp[i][1][j] || dp[i][2][j];
            }
        }
        j++;
    }
    if (dp[7][0][j] || dp[7][1][j] || dp[7][2][j]) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int n,x;cin>>n>>x;
    int now=0;int t;
    int ans=1;
    rep(i,n){
        cin>>t;
        now+=t;
        if(now<=x)ans++;
        else break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256