akhauriyash/Code-Regression huggingface dataset:
import sys
x, n = map(int, input().split())
P = list(map(int, input().split()))

if n == 0:
    print(x)
    sys.exit()

P_L = []
P_R = []

# for i in P:
#     if i <= x:
#         P_L.append(i)
#     else:
#         P_R.append(i)

A = True
i = 0

while A:
    if x - i not in P:
        print(x - i)
        A = False
    elif x + i not in P:
        print(x + i)
        A = False
    else:
        i += 1

Measured memory_bytes: 9200
#include<iostream>
#include<vector>
#include<algorithm>

struct store{
	long long a;
	long long b;
};

int main(){
	int n, m;
	long long ans=0;
	std::vector<store> sList;

	std::cin>>n>>m;

	sList.resize(n);

	for(int i=0; i<n; i++)
		std::cin>>sList[i].a>>sList[i].b;

	std::stable_sort(sList.begin(), sList.end(), [](const store &x, const store &y){return x.a< y.a;});

	for(int i=0; i<n; i++){
		if(m> sList[i].b){
			m-= sList[i].b;
			ans+= sList[i].a * sList[i].b;
		}
		else{
			ans+= sList[i].a * m;
			break;
		}
	}

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

	return 0;
}

Measured memory_bytes: 2560
N, K = map(int, input().split())
*P, = map(int, input().split())
*C, = map(int, input().split())

def get(pos):
    used = [-1] * N
    cost = [0] * (N+1)

    for k in range(N+1):
        if k:
            cost[k] = cost[k-1] + C[pos]
        if used[pos] >= 0:
            loop_size = k-used[pos]
            break
        used[pos] = k
        pos = P[pos] - 1
    if cost[loop_size] <= 0:
        return max(cost[1:K+1])
    else:
        a, b = divmod(K, loop_size)
        v1 = cost[loop_size] * (a-1) + max(cost[:K+1])
        v2 = cost[loop_size] * a + max(cost[:b+1])
        return max(v1, v2) if a else v2

ans = max([get(i) for i in range(N)])
print(ans)


Measured memory_bytes: 77700
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;


int a[1<<20], pre[1<<20] = {0};
int dp_pre[1<<20][2], dp[1<<20], apply = 0, used[1<<20] = {0};

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n; cin >> n;
  for (int i = 1; i < (1<<20); ++i) dp_pre[i][0] = 1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    pre[i + 1] = a[i] ^ pre[i];
  }
  for (int i = 1; i <= n; ++i) {
    if (pre[i] == 0) {
      ++apply;
    }
    else {
      int a = pre[i];
      int t = apply - used[a];
      used[a] = apply;
      dp_pre[a][0] = (dp_pre[a][0] + 1ll * t * dp_pre[a][1]) % MOD;
      dp[i] = dp_pre[a][0];
      (dp_pre[a][1] += dp[i]) %= MOD;
    }
  }
  if (pre[n] == 0) {
    for (int a = 1; a < (1<<20); ++a) {
      int t = apply - used[a];
      (dp[n] += dp_pre[a][1]) %= MOD;
    }
    int t = count(pre + 1, pre + n, 0);
    long long zeroContri = 1;
    while (t--) (zeroContri *= 2) %= MOD;
    cout << (dp[n] + zeroContri) % MOD << '\n';
  }
  else cout << dp[n] << '\n';
}


Measured memory_bytes: 18688
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define pb(b) push_back(b) 
#define all(a) a.begin(),a.end()
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
const int mod=1e9+7;
/* 
UnionFind：素集合系管理の構造体(union by size)
isSame(x, y): x と y が同じ集合にいるか。 計算量はならし O(α(n))
unite(x, y): x と y を同じ集合にする。計算量はならし O(α(n))
treeSize(x): x を含む集合の要素数。
*/
struct UnionFind{
 vector<int>size,parents;
 UnionFind(){}
 UnionFind(int n){//make n trees.
  size.resize(n,0);
  parents.resize(n,0);
  for(int i=0;i<n;i++)makeTree(i);
 }
 void makeTree(int x){
   parents[x]=x;//the parent of x is x
   size[x]=1;
  }
 bool isSame(int x,int y){return findRoot(x)==findRoot(y);}
 bool unite(int x,int y){
  x = findRoot(x);
  y = findRoot(y);
  if(x==y)return false;
  if(size[x]>size[y]){
   parents[y]=x;
   size[x]+=size[y];
  } 
  else{
   parents[x]=y;
   size[y]+=size[x];
  }
  return true;
 }
 int findRoot(int x){//木の根を探す,計算量削減のため低く
  if(x!=parents[x])parents[x]=findRoot(parents[x]);
  return parents[x];
 }
 int treeSize(int x){return size[findRoot(x)];}
};
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*迷路移動*/const int dx[4]={1,0,-1,0};const int dy[4]={0,1,0,-1};
llfor;////////////////////////////////////////////////////////////
int main(){
 //string s;cin>>s;
 ll a,b,c;cin>>a>>b>>c;
 pr(cei(a,b)*c);
return 0;}

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

int main(){
  string s;
  cin >> s;
  map<char,int>cou;
  for(int i=0;i<s.size();i++)
    cou[s.at(i)]++;
  bool ok=true;
  for(pair<char,int> i:cou)
    if(i.second>1)
      ok=false;
  cout << (ok?"yes":"no") << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int x,y;
    cin>>x>>y;
    for(int i=0;i <=x;i++)
    {
      if(i*2+(x-i)*4==y)
      {
        cout<<"Yes";
        return 0;
      }
    }
  cout<<"No";
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const ll INF = 1000000000000000000;

ll mini(ll a, ll b)
{
    if (a < b)
        return a;
    return b;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> city(r);
    for (int i = 0; i < r; ++i)
    {
        cin >> city[i];
        --city[i];
    }
    vector< vector<ll> > G(n, vector<ll>(n, INF));
    for (int i = 0; i < m; ++i)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        G[a][b] = c;
        G[b][a] = c;
    }
    for (int i = 0; i < n; ++i)
        G[i][i] = 0;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            for (int k = 0; k < n; ++k)
                G[j][k] = mini(G[j][k], G[j][i] + G[i][k]);
    ll odp = INF;
    sort(city.begin(), city.end());
    do
    {
        ll c = 0;
        for (int i = 0; i < r - 1; ++i)
            c += G[city[i]][city[i + 1]];
        odp = mini(odp, c);
    } while (next_permutation(city.begin(), city.end()));
    cout << odp;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005

using namespace std;

int solve(){
    int n,k,m;
    cin>>n>>k>>m;
	int a[m];
	rep(i,0,m)cin>>a[i];
	int b[n]={0};
	int maxi=0;
	rep(i,0,m){
		b[a[i]-1]++;
		maxi=max(b[a[i]-1],maxi);
	}
	rep(i,0,n){
		if(b[i]+k>m)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


Measured memory_bytes: 1408
#include <stdio.h>
#define N 10000
#define Q 500

int LinearSearch(int n[], int num, int key) {
	int i;
	for (i = 0; i < num; i++) {
		if (n[i] == key) {
			return 1;
		}
	}
	return 0;
}

int main(void) {
	int i, j = 0, n, q, key, count = 0;
	int S[N], T[Q];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &S[i]);
	}
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &T[i]);
	}

	for (i = 0; i < q; i++) {
		key = T[i];
		if (LinearSearch(S, n, key)) {
			count++;
		}
	}

	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


class FenwickTree:
    def __init__(self, n):
        self.__data = [0] * n
        self.__n = n

    def add(self, i, x):
        i += 1
        while i <= self.__n:
            self.__data[i-1] += x
            i += i & -i

    def sum(self, l, r):
        return self.__sum(r) - self.__sum(l)

    def __sum(self, r):
        s = 0
        while r > 0:
            s += self.__data[r-1]
            r -= r & -r

        return s


@mt
def slv(N, A, Q):
    ft = FenwickTree(N)
    for i, a in enumerate(A):
        ft.add(i, a)

    ans = []
    for q in Q:
        if q[0] == 0:
            _, p, x = q
            ft.add(p, x)
        else:
            _, l, r = q
            ans.append(ft.sum(l, r))

    return ans


def main():
    N, Q = read_int_n()
    A = read_int_n()
    Q = [read_int_n() for _ in range(Q)]
    print(*slv(N, A, Q), sep='\n')


if __name__ == '__main__':
    main()


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

class D
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(long.Parse).ToArray();

		var M = a.Max(v => Math.Abs(v));
		var x = Enumerable.Range(0, n).First(i => Math.Abs(a[i]) == M);

		var r = new string[0].ToList();
		if (a[x] >= 0)
		{
			for (int i = 1; i < n; i++)
			{
				while (a[i - 1] > a[i])
				{
					a[i] += a[x];
					r.Add($"{x + 1} {i + 1}");
				}
				if (a[i] > a[x]) x = i;
			}
		}
		else
		{
			for (int i = n - 2; i >= 0; i--)
			{
				while (a[i] > a[i + 1])
				{
					a[i] += a[x];
					r.Add($"{x + 1} {i + 1}");
				}
				if (a[i] < a[x]) x = i;
			}
		}

		Console.WriteLine(r.Count);
		Console.WriteLine(string.Join("\n", r));
	}
}


Measured memory_bytes: 13396
n,l = gets.chomp.split.map(&:to_i)
s = 0
for i in 0...n
  s += l+i
end
x = 10000000
for i in 0...n
  y = s - (l+i)
  if (s-y).abs < (s-x).abs
    x = y
  end
end
puts x


Measured memory_bytes: 1788
package main

import(
    "fmt"
)



func main() {
    var a,b,c int
    fmt.Scan(&a,&b,&c)
    ans := "No"
    if a+b >= c{
        ans = "Yes"
    }
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}


Measured memory_bytes: 512
// AOJ ITP1_10_A Distance
// 2018.4.28 bal4u

#include <stdio.h>
#include <math.h>

int main()
{
	double x1, y1, x2, y2;
	
	scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
	printf("%.8lf\n", hypot(x1-x2, y1-y2));
	return 0;
}


Measured memory_bytes: 2100
data = input().split()
N = int(data[0])
T = int(data[1])

data = input().split()
t = []
for i in range(N):
	t.append(int(data[i]))

X = 0
for n in range(N-1):
	if((t[n+1] - t[n]) < T):
		X += t[n+1] - t[n]
	else:
		X += T
X += T

print(X)


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n;
  cin >> n;
  vector<P> a;
  for(int i=0; i<n; i++){
    int x; cin >> x;
    a.push_back(make_pair(x,i));
  }
  sort(a.begin(), a.end());
  int ans[n];
  for(int i=0; i<n; i++){
    if(i<n/2) ans[a[i].second] = a[n/2].first;
    else ans[a[i].second] = a[n/2-1].first;
  }
  for(int i=0; i<n; i++){
    cout << ans[i] << endl;
  }
  return 0;
}


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

main(){
   int n,m;
   cin>>n>>m;
   int a[m];
   int sum = 0;
   for(int i = 0;i<m;i++){
       cin>>a[i];
       sum+= a[i];
   }
   if(sum > n) cout<<"-1";
   else cout<<(n - sum);
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{
    string s,t;
    ll cnt=0;
    cin>>s>>t;
    for(ll i=0;i<s.size();i++)
        if(s[i]!=t[i])
            cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 3920
/*
Date: 2019/12/29.
Name: AtCoder ABC149 C "Next Prime".
Category: Prime number.
*/
#include<iostream>
#include<vector>
using namespace std;

struct PrimeNumber{//Check prime number.
	std::vector<int> jud;//0 or 1.
	
	PrimeNumber(int n):jud(n+1,-1){//constructor.
		jud[0]=jud[1]=0;
		for(int i=2;i<=n;++i){
			if(jud[i]==-1){
				jud[i]=1;
				for(int j=i+i;j<=n;j+=i) jud[j]=0;
			}
		}
	}
};

int main(){
	PrimeNumber cla((int)1e5+3);
	
	int x;
	cin>>x;
	
	while(1){
		if(cla.jud[x]==1) break;
		x++;
	}
	
	cout<<x<<endl;
}


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

long long r = 1000000007;

long long  factorialMethod(long long k){
    long long  sum = 1;
    for (long long i = 1; i <= k; ++i)
    {
        sum = (sum * i)%r;
    }
    return sum%r;
}


int main(){
    long long n, m;
    cin >> n >> m;
    

    if(n == m-1){
        cout << (factorialMethod(n)*factorialMethod(m))%r << endl;
    }
    else if(n == m){
        cout << (2*factorialMethod(n)*factorialMethod(m))%r << endl;
    }
    else if(n == m+1){
        cout << (factorialMethod(n)*factorialMethod(m))%r << endl;
    }
    else{
        cout << "0" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    for(int i = 1; i<= 9; i++ ){
        for(int j = 1; j<= 9; j++){
            if(i * j == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


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


template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v){
    if(!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}
//---------

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, fes;
    fes = "CODEFESTIVAL2016";
    cin >> s;
    int ans = 0;
    rep(i, 0, fes.size()){
        if(s[i] != fes[i]) ans++;
    }
    cout << ans << endl;



    return 0;
    
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using std::cin;
using std::cout;
typedef long long ll;
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e5 + 5;
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
struct str
{
	int cnt, *addr;
	bool operator<(str A) const { return cnt < A.cnt; }
} d[Maxn];
int Disc(int t)
{
	rg int tmp = 0;
	std::sort(d + 1, d + t + 1);
	for (int i = 1; i <= t; i++)
	{
		if (i == 1 || d[i].cnt != d[i - 1].cnt)
			d[++tmp] = d[i];
		*d[i].addr = tmp;
	}
	return tmp;
}
int n, ans[Maxn];
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
		ans[read()] = i;
	for (int i = 1; i <= n; i++)
		cout << ans[i] << " ";
	putchar('\n');
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int a[100005],t1[100005],t2[100005],mx[100005],mx2[100005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i+=2)t1[a[i]]++;
    for(int i=2;i<=n;i+=2)t2[a[i]]++;
    for(int i=1;i<=100000;i++)mx[i]=max(mx[i-1],t2[i]);
    for(int i=100000;i>=1;i--)mx2[i]=max(mx2[i+1],t2[i]);
    int ans=1e9;
    for(int i=1;i<=100000;i++)ans=min(ans,n-t1[i]-max(mx[i-1],mx2[i+1]));
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 5788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>

using namespace std;

int main() {

	int N;
	cin >> N;

	std::string S, T;
	cin >> S >> T;

	std::string ret="";

	for (int i = 0; i < N; i++)
	{
		ret.push_back(S[i]);
		ret.push_back(T[i]);

	}
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

// スキャナーを生成
var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	// 標準入力
    sc.Scan()
    // 文字列から数値へ変換
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}


func sort(values []int) (ret []int) {
    // 要素数が 1 以下の配列はそれ以上細分化してソートする必要がない
    if len(values) < 2 {
        return values
    }

    // 配列の先頭をピボット (基準値) に選ぶ
    pivot := values[0]

    // ピボットを基準にして値の大小で配列をふたつに分割する
    left := []int{}
    right := []int{}
    for _, v := range values[1:] {
        if v > pivot {
            left = append(left, v)
        } else {
            right = append(right, v)
        }
    }

    // 分割した配列をそれぞれ再帰的にソートする
    left = sort(left)
    right = sort(right)

    /*
    left(小さい) + pivot(基準値) + right(大きい) の順番で配列を組み立てる
    ここが実際のソート処理
    */
    ret = append(left, pivot)
    ret = append(ret, right...)

    return
}



func main() {
    sc.Split(bufio.ScanWords)
    n := nextInt()
    k := nextInt()
    x := []int{}
    for i := 0; i < n; i++ {
        x = append(x, nextInt())
    }

    y := sort(x)
    value := 0

    for i := 0; i < k; i++ {
    	value += y[i]
    }

    fmt.Println(value)
}


Measured memory_bytes: 640
N = str(input())
s = 0
if len(N) == 1:
    n = int(N)
    if n % 9 ==0:
        print("Yes")
    else:
        print("No")
else:
    for i in range(len(N)):
        s += int(N[-i+1])
    if s % 9 == 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 9296
N = int(input())
T, A = map(int, input().split())
HS = list(map(int, input().split()))
 
result = 1
min_dif = 10000
for i in range(N):
  dif = abs(A - (T - HS[i] * 0.0060))
  if dif < min_dif:
    min_dif = dif
    result = i + 1
print(result)

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

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

    cin >> a;
    cin >> s;

    if (a < 3200) {
        cout << "red"
             << "\n";
    } else {
        cout << s << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <climits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

using Pair = pair<int, int>;
using lint = long long;

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

// const int mod = 1e9 + 7;
// const int mod = 998244353;

template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

int main(){
  lint n, x, m;
  cin >> n >> x >> m;
  vector<int> used(m, -1);
  vector <lint > a;
  a.push_back(x);
  used[x] = 0;
  vector<lint> sum;
  while(1){
    int b = a[a.size() - 1] * a[a.size() - 1] % m;
    if(b==0){
      lint ret = 0;
      rep(i, a.size()) ret += a[i];
      cout << ret << endl;
      return 0;
    } else if (used[b]!=-1){
      sum.push_back(0);
      for (int i = used[b]; i < a.size();i++){
        sum.push_back(sum[sum.size() - 1] + a[i]);
      }
      break;
    } else {
      used[b] = a.size();
      a.push_back(b);
    }
  }
  if(n<=a.size()){
    int ret = 0;
    rep(i, n) ret +=a[i];
    cout << ret << endl;
  }else{
    lint ret = 0;
    rep(i, a.size()) ret += a[i];
    n -= a.size();
    ret += sum[sum.size() - 1] * (n / (sum.size() - 1));
    ret += sum[n % (sum.size() - 1)];
    cout << ret << endl;
  }
}


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

int main(void)
{
	int num, length[202]= {};
	int sum= 0;

	cin>>num;
	for(int i= 0; i < 2*num; i++)
		cin>>length[i];

	sort(length, length+num*2);
	for(int i= 0; i < num; i++)
		sum+= length[i*2];

	cout<<sum<<endl;
}

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

const int MAXN = 100 + 10;

typedef double flt;
const flt eps = 1e-8, PI = M_PI, S = 100.0;

inline flt sqr(flt x) {return x * x;}

struct Point {
    flt x, y;
    Point() {}
    Point(flt a, flt b) : x(a), y(b) {}
    Point operator + (const Point &rhs) const {
        return Point(x + rhs.x, y + rhs.y);
    }
    Point operator - (const Point &rhs) const {
        return Point(x - rhs.x, y - rhs.y);
    }
    Point operator * (const flt k) const {
        return Point(x * k, y * k);
    }
    flt abs() {
        return hypot(x, y);
    }
    flt sqr() {
        return x * x + y * y;
    }
};

Point operator ~(const Point &rhs) {
    return Point(-rhs.y, rhs.x);
}

Point C[MAXN];
flt H[MAXN], R[MAXN], D;
int N, W;

bool ok(Point o) {
    if (o.x < D || o.x > S - D || o.y < D || o.y > S - D) return false;
    for (int i = 0; i < N; ++ i) {
        if ((o - C[i]).abs() + eps < R[i]) return false;
    }
    return true;
}

bool check_line(Point o, flt r, flt a, flt b, flt c) {
    flt dis = a * o.x + b * o.y + c;
    if (fabs(dis) >= r) return false;
    flt u = sqrt(r * r - dis * dis);
    Point v = Point(o.x - a * dis, o.y - b * dis);
    return ok(Point(v.x + b * u, v.y - a * u)) ||
           ok(Point(v.x - b * u, v.y + a * u));
}

bool check() {
    if (ok(Point(D, D)) || ok(Point(D, S - D)) || ok(Point(S - D, D)) || ok(Point(S - D, S - D))) return true;
    for (int i = 0; i < N; ++ i) {
        if (check_line(C[i], R[i], 1, 0, -D)) return true;
        if (check_line(C[i], R[i], 0, 1, -D)) return true;
        if (check_line(C[i], R[i], 1, 0, D - S)) return true;
        if (check_line(C[i], R[i], 0, 1, D - S)) return true;
    }
    for (int i = 0; i < N; ++ i) {
        for (int j = i + 1; j < N; ++ j) {
            flt dis = (C[i] - C[j]).sqr();
            if (dis > sqr(R[i] + R[j]) || dis < sqr(R[i] - R[j])) continue;
            flt w = (1 + (R[i] * R[i] - R[j] * R[j]) / dis) * 0.5;
            flt e = R[i] * R[i] / dis - w * w;
            Point t = (~(C[j] - C[i])) * sqrt(e);
            Point s = C[i] + ((C[j] - C[i]) * w);
            if (ok(s + t) || ok(s - t)) return true;
        }
    }
    return false;
}

int main() {
    while (scanf("%d%d", &N, &W) == 2 && (N || W)) {
        for (int i = 0; i < N; ++ i) scanf("%lf%lf%lf", &C[i].x, &C[i].y, &H[i]);
        flt left = 0, right = 200;
        for (int _ = 0; _ < 50; ++ _) {
            double mid = (left + right) * 0.5;
            D = W > mid ? mid : sqrt(2 * W * mid - W * W);
            for (int i = 0; i < N; ++ i) {
                R[i] = H[i] > mid ? mid : sqrt(2 * H[i] * mid - H[i] * H[i]);
            }
            if (check()) left = mid;
            else right = mid;
        }
        printf("%.10f\n", left);
    }
}

Measured memory_bytes: 1248
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

constexpr bool isPrime(const int &n) {
  if (n == 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}

void solve() {
  int k;
  while (cin >> k, k) {
    int l = k, r = k;
    while (!isPrime(l)) l--;
    while (!isPrime(r)) r++;
    cout << r - l << endl;
  }
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n;
    string s;
    cin >> n >> s;
    bool a[n + 1];
    rep(i, 4) {
        memset(a, 0, sizeof a);
        rep(j, 2) { a[j] = i & (1 << j); }
        repd(j, 1, n) {
            if (s[j] == 'o') {
                a[j + 1] = a[j - 1];
            } else {
                a[j + 1] = !a[j - 1];
            }
            if (!a[j]) {
                a[j + 1] = !a[j + 1];
            }
        }

        bool ans_0;
        if (s[0] == 'o') {
            ans_0 = a[1];
        } else {
            ans_0 = !a[1];
        }
        if (!a[0]) {
            ans_0 = !ans_0;
        }
        if (ans_0 != a[n - 1] | a[0] != a[n]) {
            continue;
        }
        rep(j, n) {
            if (a[j]) {
                cout << "S";
            } else {
                cout << "W";
            }
        }
        cout << endl;
        return 0;
    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;



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

    vi G(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a]++;
        G[b]++;
    }

    rep(i, n) {
        if(G[i]&1)  {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

const int MAX = 5100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];


int main()
{
	string str;
	cin>>str;
	bool doesExist7 = false;
	for(int i = 0; i < str.length(); i++){
		if(str[i] == '7'){
			doesExist7 = true;
			break;
		}
	}
	if(doesExist7 == true){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}



Measured memory_bytes: 3568
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);    
        String line = stdIn.nextLine();
        String answer = "";
        int length = line.length();
        for(int i = 0; i < length; i++) {
            char ch = line.charAt(i);
            if(Character.isLowerCase(ch)) {
                ch = Character.toUpperCase(ch);
            } else {
                ch = Character.toLowerCase(ch);
            } 
            answer = String.valueOf(ch);
            System.out.print(answer);
        }
        System.out.println();
        stdIn.close();
    }
}


Measured memory_bytes: 26948
def resolve():
    N, M, C = list(map(int, input().split()))
    B = list(map(int, input().split()))
    A = [list(map(int, input().split())) for _ in range(N)]
    cnt = 0
    for i in range(N):
        total = 0
        for m in range(M):
            total += B[m]*A[i][m]
        if total + C > 0:
            cnt += 1
    print(cnt)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 38256
#include<stdio.h>
int mod=1000000007;
long long fun(int a,int b,int mod)
{
	long long d=1,t=a;
	while(b)
	{
		if(b&1)
		d=(d*t)%mod;
		b/=2;
		t=(t*t)%mod;
	}
	return d;
}

int main()
{
	int n,i,f;
	long long sum;
	int a[100005],m[100000];
	scanf("%d",&n);
	f=0;
	for(i=0;i<n;i++)
	{
		m[i]=0;
		scanf("%d",&a[i]);
	}
	 for(i=0;i<n;i++)
	  m[a[i]]++;
	if(n%2==1)
	{
		if(m[0]!=1)
		  f=1;
		for(i=2;i<n;i+=2)
			if(m[i]!=2)
			    f=1;
	} 
	else
	{
		for(i=1;i<n;i+=2)
			if(m[i]!=2)
			    f=1;
		
	} 
	sum=fun(2,n/2,mod);
	 if(n%2)
    {
        if(f)
        printf("0\n");
        else
        printf("%lld\n",sum);
    }   
    else
    {
        if(f)
        printf("0\n");
        else
        printf("%lld\n",sum);
    }
	return 0;
 }

Measured memory_bytes: 896
using System;
class Program
{
 static void Main(string[] args)
 {
  string[] sS = Console.ReadLine().Trim().Split(' ');
  long lA = long.Parse(sS[0]);
  long lB = long.Parse(sS[1]);
  long lX = long.Parse(sS[2]);
  long lOutA = lA / lX;
  long lOutB = lB / lX;
  long lAdd = 0;
  if (lA % lX == 0) { lAdd += 1; }
  long lOut = lOutB - (lOutA - lAdd);
  Console.WriteLine("{0}", lOut.ToString());
 }
}


Measured memory_bytes: 13268
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int k = sc.nextInt();

    public static void main(String[] args) {

        new Main().run();

    }

    void run() {
        int[] friendNum = new int[n];
        int[] blockNum = new int[n];

        UnionFind u = new UnionFind(n);

        for (int i=0; i<m; i++) {
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            u.unite(a, b);
            friendNum[a]++;
            friendNum[b]++;
        }

        for (int i=0; i<k; i++) {
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;

            if (u.same(a, b)) {
                blockNum[a]++;
                blockNum[b]++;
            }
        }

        sc.close();

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<n; i++) {
            int ans = u.size(i)-friendNum[i]-blockNum[i]-1;
            sb.append(ans+" ");
        }

        System.out.println(sb.toString());
    }

    class UnionFind {

        int[] parents, sizes;

        UnionFind(int n) {
            parents = new int[n];
            sizes = new int[n];
            for (int i=0; i<n; i++) {
                parents[i] = i;
                sizes[i] = 1;
            }
        }

        public int find(int x) {
            if (x==parents[x]) return x;
            return parents[x] = find(parents[x]);
        }

        public void unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x==y) return;
            if (sizes[x] < sizes[y]) {
                int tmp = x;
                x = y;
                y = tmp;
            }
            parents[y] = x;
            sizes[x] += sizes[y];
        }

        public boolean same(int x, int y) {
            return find(x) == find(y);
        }

        public int size(int x) {
            return sizes[find(x)];
        }

    }
}


Measured memory_bytes: 96084
List = [int(i) for i in input().split()]
count = 0
flag = 0
while(flag == 0):
    List.sort()
    if (List[0]==List[1]==List[2]):
        flag = 1
       
    elif (List[2]-List[0]>0) and (List[2]-List[1]>0):
        List[0]+=1
        List[1]+=1
        count += 1
        
    else:
        List[0]+=2
        count += 1
       

print(count)



Measured memory_bytes: 3060
use proconio::input;
use std::collections::VecDeque;
use num::Num;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut v = VecDeque::new();

    v.push_back(a[0]);

    for &na in a.iter().skip(1) {
        if na <= v[0] {
            //println!("append {}", na);
            v.push_front(na);
            continue;
        } else {
            let index = upper_bound(&v, na - 1);
            //println!("{} -> {}", v[index-1], na);
            v[index - 1] = na;
        }
    }

    println!("{}", v.len());
}

fn upper_bound<T>(v: &VecDeque<T>, n: T) -> usize 
where T: Num + PartialEq + PartialOrd
{
    let mut left = -1;
    let mut right = v.len() as isize;
    
    while right - left > 1 {
        let mid = (left + right) / 2;
        if v[mid as usize] <= n {
            left = mid;
        } else {
            right = mid;
        }
    } 
    right as usize
}

Measured memory_bytes: 4756
#include<iostream>
#include<algorithm>
using namespace std;
int red[100005],green[100005],colorless[100005];
void update(int node,int l,int r,int v,int segtree[]){
  if(l==r){
    segtree[node]=max(segtree[node],v);
    return;
  }
  int mid=(l+r)/2;
  if(segtree[2*node]<segtree[2*node+1]){
    if(segtree[2*node]<v){
      update(2*node,l,mid,v,segtree);
    }
  }
  else{
    if(segtree[2*node+1]<v){
      update(2*node+1,mid+1,r,v,segtree);
    }
  }
  segtree[node]=min(segtree[2*node],segtree[2*node+1]);
  return;
}
int query(int node,int l,int r,int segtree[]){
  if(l==r){
    return segtree[node];
  }
  int mid=(l+r)>>1;
  if(segtree[2*node]<segtree[2*node+1]) return query(2*node,l,mid,segtree);
  else return query(2*node+1,mid+1,r,segtree);
}
long long int get_sum(int node,int l,int r,int segtree[]){
  if(l==r) return segtree[node];
  int mid=(l+r)>>1;
  return get_sum(2*node,l,mid,segtree)+get_sum(2*node+1,mid+1,r,segtree);
}
int segtree_red[400005],segtree_green[400005];
int main(){
  int X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  for(int i=0; i<A; i++){
    cin>>red[i];
    update(1,0,X-1,red[i],segtree_red);
  }
  for(int i=0; i<B; i++){
    cin>>green[i];
    update(1,0,Y-1,green[i],segtree_green);
  }
  for(int i=0; i<C; i++){
    cin>>colorless[i];
    int red_cost=query(1,0,X-1,segtree_red);
    int green_cost=query(1,0,Y-1,segtree_green);
    if(colorless[i]<=min(red_cost,green_cost)) continue;
    if(red_cost<green_cost) update(1,0,X-1,colorless[i],segtree_red);
    else update(1,0,Y-1,colorless[i],segtree_green);
  }
  long long int sum=get_sum(1,0,X-1,segtree_red);
  sum+=get_sum(1,0,Y-1,segtree_green);
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int n,a[200005],s[200005],s2[200005];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) s[i]=max(s[i-1],a[i]);
	for(int i=n;i>=1;i--) s2[i]=max(s2[i+1],a[i]);
	for(int i=1;i<=n;i++) cout<<max(s[i-1],s2[i+1])<<endl;
	return 0;
}

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

    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	// 入力
    	int a = sc.nextInt();
    	int b = sc.nextInt();
    	int c = sc.nextInt();
    	int x = sc.nextInt();

    	int ans = 0;

    	//500,100,50
    	for(int i = 0;i <= a;i++){
    		int tmp500 =+ 500 * i;
    		for(int j = 0;j <= b; j++){
    			int tmp100 =+ 100 * j;

    			for(int k = 0;k <= c;k++){
    				int tmp50 =+ 50 * k;
                	if(tmp500 + tmp100 + tmp50 == x){
                		ans++;
                	}
    			}
    		}
    	}


    	// 出力
    	System.out.println(ans);
    }
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

long long mod(long long val) {
  long long res = val % MOD;
  if (res < 0) res += MOD;
  return res;
}


const int MAX = (1e6+10)*2;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    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;
    }
}

// 二項係数計算
long long 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;
}

LL g(int r, int c){
    LL f = 0;
    FOR(i,1,r+2){
        f += COM(i+c,i);
    }
    return f;

}

void Main()
{
    COMinit();
    int r1,r2,c1,c2;
    cin>>r1>>c1>>r2>>c2;

    //dump(g(1,1))
    //dump(g(1,2))
    //dump(g(2,1))
    //dump(g(2,2))

    LL result = g(r2,c2)-g(r1-1,c2)-g(r2,c1-1)+g(r1-1,c1-1);
    result = mod(result);

    cout << result << endl;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

int main(){
  ll a;
  double b;
  cin >> a >> b;
  cout <<  (a * (ll)round(b * 100)) / 100 << endl;
}


Measured memory_bytes: 3788
#include <iostream>
#include <cmath>

int main(int argc, const char *argv[]) {
    double x1, y1, x2, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;
    std::cout << std::fixed << std::sqrt(std::pow(x2 - x1, 2.0) + std::pow(y2 - y1, 2.0)) << std::endl;
    return 0;
}

Measured memory_bytes: 3280
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(s: str):
    a = s.find('A')
    z = ''.join(list(reversed(s))).find('Z')
    print(len(s) - z - a)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7388
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 100000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long
/* define/include */

int main(){
  char x,y;
  cin >> x >> y;
  if(x<y){
    cout << "<";
  }if(x==y){
    cout << "=";
  }if(x>y){
    cout << ">";
  }
  return 0;
}


Measured memory_bytes: 256
import numpy as np
n, m = map(int, input().split())
a = []
b = []
bot = m
ans = 0
for i in range(n):
  l,m = map(int, input().split())
  a.append(l)
  b.append(m)
  
a = np.array(a)
b = np.array(b)
s = np.argsort(a)
for i in s:
  if(bot >= b[i]):
    bot -= b[i]
    ans += a[i] * b[i]
  else: 
    ans += a[i] * (bot)
    bot = 0
    break

print(ans)


Measured memory_bytes: 20848
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var L = Sarray()[0];
            var N = 0;
            for (var i = 0; i < 20; ++i)
                if ((L & (1 << i)) != 0) N = i;
            var graph = Enumerable.Range(0, N).Select(_ => new List<(int to, int c)>()).ToArray();
            for (var i = 0; i < N; ++i)
            {
                graph[i].Add((i + 1, 0));
                graph[i].Add((i + 1, (int)Pow(2, i)));
            }
            var last = L - 1;
            var now = (int)Pow(2, N);
            var pos = N - 1;
            while (now <= last)
            {
                var left = (int)Pow(2, pos) - 1;
                if (now + left <= last)
                {
                    graph[pos].Add((N, now));
                    now += left + 1;
                }
                --pos;
            }
            var m = graph.Sum(g => g.Count);
            WriteLine($"{N + 1} {m}");
            for (var i = 0; i < N; ++i)
            {
                foreach (var tc in graph[i])
                {
                    WriteLine($"{i + 1} {tc.to + 1} {tc.c}");
                }
            }
        }
    }
}

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

int main()
{
  int n;
  cin>>n;
  vector<int> L(n);
  rep(i,n)cin>>L[i];
  sort(L.begin(),L.end());
  int ans=0;
  rep(b,n)
  {
    rep(a,b)
    {
      int ab=L[a]+L[b];
      int r=lower_bound(L.begin(),L.end(),ab)-L.begin();
      int l=b+1;
      ans+=max(0,r-l);
    }
  }
  cout<<ans<<endl;

  return 0;
}


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

int main()
{
	char c;
	int i,n=-1,sum=0,a[5]={0};

	while(scanf("%c",&c)!=EOF)
	{
		if(c>=48 && c<=57)
		{
			n++;
			a[n]=c-48;
		}
		else if(n!=-1)
		{
			for(i=0;i<=n;i++)
			{
				sum+=a[n-i]*(int)(pow(10.0,i));
			}
			n=-1;
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 580
n, m = [int(x) for x in input().split()]

answers = []
for x in range(m):
    answers.append(input().split())

correct_answers = set([answer[0] for answer in answers if answer[1] == "AC"])

temp = {k[0]: [] for k in answers}
for x in answers:
    temp[x[0]].append(x[1])

penalties = 0
for x in temp:
    if (temp[x].count("AC") > 0):
        G = temp[x][:temp[x].index("AC")]
        penalties += len(G)


print(len(correct_answers), penalties)

Measured memory_bytes: 54072
t=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())-1
print(t[k])


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

signed main() {
	for (int K; cin >> K&&K;) {
		int sum = 0;
		rep(i, 0, K*(K - 1) / 2) { int c; cin >> c; sum += c; }
		cout << sum / (K - 1) << endl;

	}
	return 0;
}

Measured memory_bytes: 3056
# 決め打ち二分探索
# 全員にBダメージ、その後1体選んで(A-B)ダメージと読み替える（対称性の確保。lesson.md参照）
# あとはk回以下で倒せるかを計算して二分探索
# Gluttonyと同様の構造なので、あちらと同様にTLEには注意して書くこと

n, a, b =list(map(int, input().split()))
hitpoints = [int(input()) for _ in range(n)]

additional = a - b

def feasible(k):
    additional_num = sum([max((hp-(b*k) + additional - 1) // additional, 0) for hp in hitpoints])
    return additional_num <= k

ok = 10**9+1
ng = 0

# めぐる式二分探索
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if feasible(mid):
        ok = mid
    else:
        ng = mid

print(ok)


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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> p (N, 0);
    REP (i, N) cin >> p[i];
    ALL (sort, p);
    cout << accumulate (p.begin(), p.begin() + K, 0) << endl;
    return 0;
}


Measured memory_bytes: 3588
n, t = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(n)]
print('TLE' if min([a[i][0] if a[i][1] <= t else 1000000 for i in range(n)]) == 1000000 else min([a[i][0] if a[i][1] <= t else 1000000 for i in range(n)]) )

Measured memory_bytes: 3060