akhauriyash/Code-Regression huggingface dataset:
using System.Linq;
using static System.Console;

namespace ConsoleApp30
{
    class FootPrint
    {
        public bool Visit { get; set; }
        public long Time { get; set; }

        public FootPrint(long t)
        {
            Visit = true;
            Time = t;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var buff = ReadLine().Split(' ').Select(long.Parse).ToArray();
            long N = buff[0];
            long K = buff[1];

            var teleport = ReadLine().Split(' ').Select(long.Parse).ToArray();

            long position = 1;
            long count = 0;
            var footprints = new FootPrint[N];
            footprints[0] = new FootPrint(0);

            for(long i = K - 1; i >= 0; i--)
            {
                position = teleport[position - 1];
                count++;
                if (footprints[position - 1] != null)
                {
                    i %= (count - footprints[position - 1].Time);
                }
                else
                {
                    footprints[position - 1] = new FootPrint(count);
                }
            }

            WriteLine(position);
        }
    }
}


Measured memory_bytes: 50280
#include <stdio.h>
#include <math.h>
int main()
{
    char letter[105];
    int n;
    int ans = 1;
    scanf("%d",&n);
    scanf("%s",letter);
    if(n%2 == 1)
    {
        printf("No");
        return 0;
    }
    else
    {
        for(int i = 0;i < n/2;i++)
        {
            if(letter[i]!=letter[i+n/2])
            {
                ans = 0;
            }
        }
    }
    if(ans)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//スペルミスに注意
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
	using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % M;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll N; cin >> N;
	vector<ll> a(N + 1);
	for (int i = 2; i < N + 1; i++) cin >> a[i];

	vector<ll> cnt(N + 1);
	for (int i = 2; i < N + 1; i++)cnt[a[i]]++;


	for (int i = 1; i < N + 1; i++) {
		cout << cnt[i] << endl;
	}
}

Measured memory_bytes: 14408
#include<bits/stdc++.h>
using namespace std;
const int max_n=200005;
int a[max_n],b[max_n];
long long sum1[max_n],sum2[max_n];
long long max(long long a,long long b)
{
	return a>=b?a:b;
}
long long ans;
int main()
{
	int n;cin>>n;
	for(long long i=1;i<=n;i++)
	{
		long long num=n/i;
		ans+=(2*i+i*(num-1))*num/2;
	}
	cout<<ans;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n;
ll X, b[maxn], l[maxn], r[maxn], base;
vector<pair<ll, int> >sums;
bool can(ll c)
{
	ll full = c / X, rem = c - full * X;
	ll sum = 0;
	for(int i = 0; i < full; i++)
		sum += sums[i].x;
	ll mx = 0;
	for(int i = 0; i < n; i++)
	{
		int j = sums[i].y;
		ll add;
		if(rem >= b[j])
			add = b[j] * l[j] + r[j] * (rem - b[j]);
		else
			add = l[j] * rem;
		if(i < full)
			mx = max(mx, sum - sums[i].x + add + (full == n ? 0 : sums[full].x));
		else
			mx = max(mx, sum + add);
	}
	return mx >= base;
}
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	cin >> n >> X;
	for(int i = 0; i < n; i++)
	{
		cin >> b[i] >> l[i] >> r[i];
		base += l[i] * b[i];
		sums.pb({(X - b[i]) * r[i] + b[i] * l[i], i});
	}
	sort(all(sums), greater<pair<ll, int> >());
	ll lo = 0, hi = X * n;
	while(lo < hi)
	{
		ll mid = (lo + hi) / 2;
		if(can(mid))
			hi = mid;
		else
			lo = mid + 1;
	}
	cout << lo << "\n";
	return 0;
}

Measured memory_bytes: 4336
from bisect import bisect_left

N, M = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

def solve() :
  sa = set(A)
  sb = set(B)
  
  if len(sa) + len(sb) != N + M :
    return 0
  
  sc = sa & sb

  A.sort()
  B.sort()

  ret = 1
  for i in range(N * M, 0, -1) :
    if i in sc :
      continue
    elif i in sa :
      ret *= M - bisect_left(B, i)
    elif i in sb :
      ret *= N - bisect_left(A, i)
    else :
      ca = N - bisect_left(A, i)
      cb = M - bisect_left(B, i)
      ret *= max(0, ca * cb - (N * M - i))

    ret %= mod

  return ret

print(solve())

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int tmp;

    if(a>b){
        tmp = a;
        a = b;
        b = tmp;
    }
    if(b>c){
        tmp = b;
        b = c;
        c = tmp;
    }
    if(a>b){
        tmp = a;
        a = b;
        b = tmp;
    }
    cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3088
/**
 * File              : D.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 22.12.2019
 * Last Modified Date: 22.12.2019
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    int cur = 1; 
    int cnt = 0;
    for (auto x: v) {
        if (x == cur) {
            cur++;
            cnt++;
        }
    }
    cout << (cur == 1 ? -1 : n - cnt);
    return 0;
}


Measured memory_bytes: 1024
X=int(input())
p=[]
p.append(1)
for i in range(2,1000):
  for j in range(2,10):
    p.append(pow(i,j))
p.sort()
ans=0
for i in range(len(p)):
  if p[i]>X:
    break
  ans=p[i]
print(ans)

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


int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s(n);
  rep(i, k){
    int d; cin >> d;
    rep(j, d){
      int a; cin >> a;
      s[a-1] = 1;
    }
  }
  int ans = 0;
  rep(i, n){
    if(s[i] == 0) ans++;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3580
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  n %= 10;
  if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9){
    cout << "hon" << endl;
  }else if(n == 0 || n == 1 || n == 6 || n == 8){
    cout << "pon" << endl;
  }else{
    cout << "bon" << endl;
  }
}

Measured memory_bytes: 3592
object Main extends App {
  val sc = new java.util.Scanner (Console.in)

  def nextInt() = Integer.parseInt(sc.next)

  def isprime(x:Int): Boolean = {
    if (x == 2)
      return true
    if (x < 2 || x % 2 == 0)
      return false

    var i = 3
    val sq = math.sqrt(x).toInt
    while (i <= sq) {
      if (x % i == 0)
        return false
      i += 2
    }
    return true
  }

  var n = nextInt
  var count = 0
  while (n > 0) {
    if (isprime(nextInt))
      count += 1
    n -= 1
  }
  println(count)
}



Measured memory_bytes: 59144
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
// #include<queue>
#include<vector>
#include<utility>
using namespace std;
int inf=1e9;
//vector<long long int>adj[10000];

int main()
{
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n-1;i++)
	{
		//int a=i;
		int b=(n-1)/i;
		//int c=n-(n-1)*b;
		ans+=b;
		// if(a>0 && b>0 && c>0)
		// {
		// 	if(a==b && b==c)ans+=1;
		// 	else if((a==b && b!=c) || (a==c && a!=b) || (b==c && a!=b))ans+=3;
		// 	else ans+=6;
		// }
		//cout<<a<<" "<<b<<" "<<c<<" "<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3584
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


X, Y = map(int, input().split())

n = (X + Y) // 3
x = (2 * X - Y) // 3
y = (-X + 2 * Y) // 3
if (X + Y) % 3 or x < 0 or y < 0:
    print(0)
    exit()

MOD = 1000000007
COM_MAX = n

fac, finv, inv = [0] * (COM_MAX + 1), [0] * (COM_MAX + 1), [0] * (COM_MAX + 1)
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

for i in range(2, COM_MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD


def mod_com(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


print(mod_com(n, x))


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

int main(){
  
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  int i, Min = min(s.size(), t.size());
  for(i=0; i<Min; i++){

    if(s[i]==t[i]) continue;
    if(s[i]>t[i]){
      cout << "No" << endl;
      return 0;
    }
    if(s[i]<t[i]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  if(s.size() < t.size()){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}



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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int inf = int (1e9) + int (1e5);
const ll infl = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double eps = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);i++)
#define MP make_pair


inline ull gcd(ull a, ull b) { return a ? gcd(b % a, a) : b; }
ull lcm(ull a, ull b) {return a / gcd(a, b) * b;}

int main() {
    int N;
    cin >> N;
    ull m=1LL,m2;
    while (N--){
        cin >> m2;
        m = lcm(m,m2);
    }
    cout << m;
    return 0;
}


Measured memory_bytes: 256
import bisect
import sys
sys.setrecursionlimit(3*10**5)

INF = 10**10

N = int(input())
a = list(map(int,input().split()))
T = [set() for x in range(N)]
for i in range(N-1):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    T[u].add(v)
    T[v].add(u)

search = [0]*N

A = [INF]*N

ans = [-1]*N

def dfs(V):
    num = a[V]
    k = bisect.bisect_left(A,num)
    v = A[k]
    A[k] = num
    ans[V] = bisect.bisect_left(A,INF)
    # このにぶたん無駄じゃね？まあ間に合うからいいか……
    for VV in T[V]:
        if search[VV]:
            continue
        search[VV] = 1
        dfs(VV)
    A[k] = v

search[0] = 1
dfs(0)

print(*ans,sep="\n")

Measured memory_bytes: 393292
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long x;
    cin>>x;
    long long a=100,p=0,sum=0;

    while(a<x)
    {
        p=a/100;
        a+=p;
        sum++;
    }

    cout<<sum<<"\n";
    return 0;
}



Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
const int N = 1005;
const double eps = 1e-9;

int n, sx, sy, ex, ey, x[N], y[N], r[N];
double c[N][N], dist[N], ans;

priority_queue<pair<double,int> > pq;

double d (int X1, int Y1, int X2, int Y2, int R) {
	return max(0.0, hypot(X1-X2, Y1-Y2)-R);
}

int main()
{
	scanf("%d%d%d%d%d",&sx,&sy,&ex,&ey,&n);
	for(int i=1;i<=n;i++) {
		scanf("%d%d%d",&x[i],&y[i],&r[i]);
		for(int j=1;j<i;j++) {
			c[i][j] = d(x[i], y[i], x[j], y[j], r[i]+r[j]);
			c[j][i] = c[i][j];
		}
		dist[i] = d(x[i], y[i], sx, sy, r[i]);
		pq.push({-dist[i], i});
	}
	while(!pq.empty()) {
		double V; int I; tie(V, I) = pq.top(); V *= -1; pq.pop();
		if(dist[I]+eps < V) continue;
		for(int i=1;i<=n;i++) {
			if(i == I) continue;
			if(dist[i] > V + c[I][i]) {
				dist[i] = V + c[I][i];
				pq.push({-dist[i], i});
			}
		}
	}
	ans = d(sx, sy, ex, ey, 0);
	for(int i=1;i<=n;i++) {
		ans = min(ans, dist[i] + d(x[i], y[i], ex, ey, r[i]));
	}
	printf("%.12f\n",ans);
}


Measured memory_bytes: 13680
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
int a[N],b[N];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        cin>>b[i];
    }
    reverse(b+1,b+n+1);
    vector<int >p,q;
    int val=0,cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]!=b[i])
            continue;
        cnt++;
        q.push_back(i);
        val=b[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(!cnt)
            break;
        if(a[i]==b[i])
            continue;
        if(a[i]!=val&&b[i]!=val)
        {
            cnt--;
            p.push_back(i);
        }

    }
    if(cnt)
    {
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=0;i<q.size();i++)
    {
        swap(b[q[i]],b[p[i]]);
    }
    cout<<"Yes"<<endl;
    for(int i=1;i<=n;i++)
    {
        cout<<b[i]<<" ";
    }
    cout<<endl;
    return 0;

}


Measured memory_bytes: 5840
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = 3.141592653589;
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    intl l[q],r[q];
    rep(i,q){
        intl a,b;
        cin >> l[i] >> r[i];
    }
    vector<intl> v;
    rep(i,s.length()-1){
        if((s[i] == 'A')&&(s[i + 1] == 'C'))v.pb(i + 1);
    }
    rep(i,q){
        intl cnt = lower_bound(all(v),r[i]) - lower_bound(all(v),l[i]);
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3064
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 28-Mar-20 11:08:43 PM
	flamers will **** you
*/
//#include<flamers.h>

#include "bits/stdc++.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define PB push_back
#define POB pop_back

using namespace std;

int main(){
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie();
	long long X;
	cin>>X;
	long long q = X / 500;
	long long r = X % 500;
	long long q1 = r / 5;
	
	cout<<q * 1000 + q1 * 5<<endl;
	
	return 0;
}


Measured memory_bytes: 256
N = input()


def f(d, used, next):
    num = len(used | set(next))
    if d == 0:
        if num == 3:
            return 1
        else:
            return 0
    elif num == 3:
        return 3 ** d
    elif num == 2:
        return 3 ** d - 2 ** d
    else:
        return 3 ** d - 2 * (2 ** d) + 1


def high(N, used, ret):
    if N:
        if int(N[0]) > 3:
            ret += f(len(N) - 1, used, "3")
        if int(N[0]) > 5:
            ret += f(len(N) - 1, used, "5")
        if int(N[0]) > 7:
            ret += f(len(N) - 1, used, "7")
    else:
        if len(used) == 3:
            ret += 1
        return ret
    if N[0] in ["3", "5", "7"]:
        ret = high(N[1:], used | set(N[0]), ret)
    return ret


def low():
    d = 0
    ret = 0
    for i in range(len(N) - 1):
        ret += 3 * (3 ** d - 2 ** (d + 1) + 1)
        d += 1
    return ret


def main():
    print(high(N, set(), low()))
    return


main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll max(ll a, ll b){
    return a > b ? a : b;
}
int main(){
    ll a, b, k; cin >> a >> b >> k;
    if(a == 0 && b == 0){
        cout << "0 0" << endl;
        return 0;
    }
    if(a >= k){
        cout << a - k << " " << b << endl;
    }else{
        cout << 0 << " " << max(b - (k - a), 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, *B = map(int, open(0).read().split())
A = []
for _ in range(N):
    for j in reversed(range(len(B))):
        if B[j] == j + 1:
            A.append(B.pop(j))
            break
    else:
        print(-1)
        quit()
print(*reversed(A), sep="\n")


Measured memory_bytes: 3060
#include<string>
#include<iostream>
#include<deque>
#include<cstdlib>
#include<algorithm>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define rep(n) for(int i=0;i<(n);i++)

const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    lli res = 1;
    rep(n) {
        res *= 10;
        res %= MOD;
    }
    lli minus = -2 + MOD;
    rep(n) {
        minus *= 9;
        minus %= MOD;
    }
    lli plus = 1;
    rep(n) {
        plus *= 8;
        plus %= MOD;
    }
    cout << (res + minus + plus) % MOD << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	string s[n];
	for(int i=0; i<n; i++){
		cin >> s[i];
	}
	for(int i=1; i<n; i++){
		if(s[i-1].back()!=s[i].front()){
			cout << "No" << endl;
			return 0;
		}
		for(int j=0; j<i; j++){
			if(s[i]==s[j]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

using namespace std;

#define int long long

main(){
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, x;
    cin >> n;
    vector < int > a;
    for (int i = 1; i <= n; ++i){
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(), a.end());
    if (a.back() <= 0){
        int ans = 0;
        vector < pair < int, int > > out;
        for (int i = 0; i < n - 1; ++i){
            //cout << a.back() << " " << a[i] << '\n';
            out.push_back({a.back(), a[i]});
            a.back() -= a[i];
        }
        cout << a.back() << '\n';
        for (auto key : out) cout << key.first << " " << key.second << '\n';
    }
    else{
        int k = a[0];
        vector < pair < int, int > > out;
        for (int i = 1; i < n - 1; ++i){
            if (a[i] < 0) continue;
            out.push_back({k, a[i]});
            k -= a[i];
        }
        out.push_back({a.back(), k});
        int ans = a.back() - k;
        for (int i = 1; i < n - 1; ++i){
            if (a[i] < 0){
                out.push_back({ans, a[i]});
                ans -= a[i];
            }
        }
        cout << ans << '\n';
        for (auto key : out) cout << key.first << " " << key.second << '\n';
    }
    return 0;
}



Measured memory_bytes: 4336
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second

const int N = 2e5 + 5 , mod = 1e9 + 7;
using namespace std;

int V[N] , C[N];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n , ans = 0; cin >> n;
    for (int i=0; i<n; i++)
        cin >> V[i];

    for (int i=0; i<n; i++)
        cin >> C[i];

    for (int i=0; i<n; i++) if (V[i] > C[i])
        ans += V[i] - C[i];

    cout << ans;
}


Measured memory_bytes: 256
import kotlin.math.*
import java.util.*

fun main(args: Array<String>) {
  val x = readLine()!!.toLong()
  var n = 0
  var c = 100L
  do {
    n++
    c = floor(c * 1.01).toLong()
  } while (c < x)
  println(n)
}


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

typedef long long ll;

int main() {
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    rep(i, N) cin >> S[i];
    sort(S.begin(), S.end());
    rep(i, N) cout << S[i];
    cout << endl;
}

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

int n, c1, c2;
string s;
stack<int> a;
int main()
{
	int i, t;
	cin >> n >> s;
	for (i = 0; i < n; i++) {
		if (s[i] == '(') a.push(1);
		else {
			if (!a.empty() && a.top() == 1) a.pop();
			else a.push(2);
		}
	}
	while (!a.empty()) {
		t = a.top(), a.pop();
		if (t == 1) c1++;
		else c2++;
	}
	while (c2--) printf("(");
	cout << s;
	while (c1--) printf(")");
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Program
{
    static void Main()
    {
        string text = ReadLine();
        int len = text.Length;
        int count = 0;

        for (int i = 0; i < len; i++){
            if (text.Substring(i,1) == "1")
                count++;
        }

        WriteLine(count.ToString());
    }
}

Measured memory_bytes: 11092
N,A,B,C=map(int, input().split())
l=[int(input()) for _ in range(N)]

def dfs(num, a, b, c):
    if N == num:
        return abs(A-a)+abs(B-b)+abs(C-c) - 30 if min(a,b,c)>=1 else 10**10
    ret = []
    ret.append(dfs(num+1, a, b, c))
    ret.append(dfs(num+1, a+l[num], b, c)+10)
    ret.append(dfs(num+1, a, b+l[num], c)+10)
    ret.append(dfs(num+1, a, b, c+l[num])+10)
    return min(ret)

print(dfs(0,0,0,0))

Measured memory_bytes: 43740
import std.stdio, std.algorithm, std.range, std.random, std.array, std.string, std.conv;

long count_inversion(int[] xs) {
    if (xs.length == 1) return 0;
    auto ls = xs[0 .. $ / 2],
         rs = xs[$ / 2 .. $];
    long inv = 0;
    inv += count_inversion(ls);
    inv += count_inversion(rs);
    int i = 0, j = 0;
    auto ys = new int[xs.length];
    foreach (ref y; ys) {
        if (i == ls.length) {
            y = rs[j++];
        } else if (j == rs.length) {
            y = ls[i++];
        } else if (ls[i] < rs[j]) {
            y = ls[i++];
        } else {
            y = rs[j++];
            inv += (ls.length - i);
        }
    }
    ys.copy(xs);
    return inv;
}

void main() {
    int N = readln.chomp.to!int;
    auto xs = readln.chomp.split(" ").map!(to!int).array;
    writefln("%d", count_inversion(xs));
}

Measured memory_bytes: 12452
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

constexpr Int mod = 1e9+7;
Int n, k, sn;
vector<Int> v;
vector<vector<Int>> dp;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for(Int i=1;; ++i){
		if(i*i > n){
			sn = i-1;
			break;
		}
	}
	if(n / sn == sn){
		dp.resize(k, vector<Int>(2*sn-1));
	}else{
		dp.resize(k, vector<Int>(2*sn));
	}
//	dp[0].resize(dp[0].size(), 1);
	for(Int i=0; i<sn; ++i){
		dp[0][i] = 1;
		dp[0][dp[0].size()-1-i] = n/(i+1) - n/(i+2);
	}
//	for(size_t i=0; i<dp.size(); ++i)
//		for(size_t j=0; j<dp[i].size(); ++j)
//			cout << dp[i][j] << " \n"[j+1==dp[i].size()];
	for(Int i=1; i<k; ++i){
		for(Int j=0; j<sn; ++j){
			dp[i][dp[i].size()-1-j] += dp[i-1][j];
			dp[i][dp[i].size()-1-i] %= mod;
			dp[i][j] += dp[i-1][dp[i].size()-1-j];
			dp[i][j] %= mod;
		}
		if(n / sn == sn){
			dp[i][sn-1] -= dp[i-1][sn-1];
			if(dp[i][sn-1] < 0) dp[i][sn-1] += mod;
		}
		for(Int j=dp[i].size()-2; j>=0; --j){
			dp[i][j] += dp[i][j+1];
			dp[i][j] %= mod;
		}
		for(Int j=0; j<sn; ++j){
			dp[i][dp[i].size()-1-j] *= dp[0][dp[i].size()-1-j];
			dp[i][dp[i].size()-1-j] %= mod;
		}
	}
	Int ans = 0;
	for(size_t i=0; i<dp[k-1].size(); ++i){
		ans += dp[k-1][i];
		ans %= mod;
	}
	cout << ans << "\n";
//	for(size_t i=0; i<dp.size(); ++i)
//		for(size_t j=0; j<dp[i].size(); ++j)
//			cout << dp[i][j] << " \n"[j+1==dp[i].size()];
}

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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int ans = H2*60+M2-H1*60-M1-K;
    cout << ans << "\n";
}

Measured memory_bytes: 3652
import sys

N = sys.stdin.readline()

N = N.split()
N = map(int, N)

if N[2] > N[1] or N[0] > N[3]:
	print 0

else:
	least = max(N[0], N[2])
	most = min(N[1], N[3])
	
	print abs(most- least)

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

namespace BC121C
{
    class Program
    {
        struct drink
        {
            public int price;
            public int stock;
        }
        static void Main(string[] args)
        {
            // 整数の入力
            //int a = int.Parse(Console.ReadLine());
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]); // N軒
            int M = int.Parse(input[1]); // M本のドリンクを買う
            //　リストに情報をセットする
            List<drink> basket = new List<drink>();
            for(var i = 0; i < N; i++)
            {
                drink d = new drink();
                string[] inputAB = Console.ReadLine().Split(' ');
                d.price =int.Parse(inputAB[0]);
                d.stock=int.Parse(inputAB[1]);
                basket.Add(d);
            }
            basket.Sort((a, b) => a.price - b.price); // 価格の安い順に並べた
            /*
            foreach(drink member in basket)
            {
                Console.WriteLine(member.price+" "+member.stock);
            }
            */
            long ans = 0;
            for(var i = 0; i < N; i++)
            {
                if (basket[i].stock <= M)
                {
                    ans +=(long)basket[i].price * (long)basket[i].stock;
                    M = M - basket[i].stock;
                }
                else
                {
                    ans += (long)basket[i].price * (long)M;
                    M = 0;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 17664
#include <iostream>

int main() {
  int n, b, f, r, v;
  int floor[4][3][10] = {};
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> b >> f >> r >> v;
    floor[b - 1][f - 1][r - 1] += v;
  }

  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
        std::cout << " " << floor[i][j][k];
      }
      std::cout << std::endl;
    }
    if (i < 3) {
      std::cout << "####################"  << std::endl;
    }
  }
}



Measured memory_bytes: 3076
#include<stdio.h>

#define N 100

typedef struct{
  int k,u;
  int c[N];
}Node;

Node a[N];

int main()
{
  int n,i,j,b[N][N] = {{0},{0}};

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      scanf("%d %d",&a[i].u,&a[i].k);
      for(j = 0;j < a[i].k;j++)
	scanf("%d",&a[i].c[j]);
    }

  for(i = 0;i < n;i++)
    {
      for(j = 0;j < a[i].k;j++)
	  b[i][a[i].c[j]-1] = 1;
    }

  for(i = 0;i < n;i++)
    {
      for(j = 0;j < n-1;j++)
	printf("%d ",b[i][j]);
      printf("%d\n",b[i][j]);
    }
  
  return 0;
}



Measured memory_bytes: 2112
#include<iostream>
using namespace std;
int main()
{
    long long int n, m, sum=0, i;
    cin>>n>>m;
    long long int arr[m];
    for(i=0; i<m; i++)
    {
        cin>>arr[i];
        sum += arr[i];
    }
    if(sum<=n)
    cout<<n-sum<<endl;
    else
    cout<<-1<<endl;
    return 0;
}
  

Measured memory_bytes: 3712
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main () {

    double a, b, C;     // 入力

    double c;           // 角Cの対角に存在する辺cの長さ
    double sinB;        // bの対角に存在する角Bのsin
    
    double S, L, h;     // 出力（面積, 周の長さ, 高さ）

    cin >> a >> b >> C;

    C = C * M_PI / 180.0;   // 角度Cをラジアンに変換
    c = sqrt (pow(a, 2) + pow(b, 2) - 2 * a * b * cos(C));  // Cの対角に存在する辺cの長さを求める。余弦定理を利用。 「c^2 = a^2 + b^2 - 2ab * cos(C)」
    sinB = b * sin(C) / c;  // sinAを求める。正弦定理を利用。　「a / sin(A) = b / sin (B) = c / sin (C) = 2R」

    S = 0.5 * a * b * sin(C);   // 面積を求める。面積を求める公式を利用。
    
    L = a + b + c;  // 周の長さを求める。

    h = c * sinB; // 高さを求める。

    cout << fixed;
    cout << setprecision(10) << S << endl;
    cout << setprecision(10) << L << endl;
    cout<< setprecision(10) << h << endl;

    return 0;
}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, i;
	
	cin>>n;
	vector<int> top(n), bot(n);
	
	for (i = 0; i < n; ++i)
	{
		cin>>top[i];
		if (i)
			top[i] += top[i - 1];
	}
	for (i = 0; i < n; ++i)
	{
		cin>>bot[i];
		if (i && bot[i - 1] > top[i])
			bot[i] += bot[i - 1];
		else bot[i] += top[i];
	}
	
	cout<<bot.back()<<'\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int c[501];
int s[501];
int f[501];
int t[501];
int main()
{
	int n,i,tmp,j;
	scanf("%d",&n);
	for(i=1;i<n;i++)
		scanf("%d %d %d",&c[i],&s[i],&f[i]);
	if(n==1)
	{
		printf("0");
		return 0;
	}
	for(i=1;i<=n-1;i++)
	{
		tmp=s[i]+c[i];
		for(j=i+1;j<=n-1;j++)
		{
			if(tmp<=s[j])
				tmp=s[j]+c[j];
			else if((tmp-s[j])%f[j]==0)
				tmp+=c[j];
			else
				tmp+=f[j]-(tmp-s[j])%f[j]+c[j];
		}
		t[i]=tmp;
	}
	for(i=1;i<=n;i++)
		printf("%d\n",t[i]);
	return 0;
}

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

int main()
{
    vector<char> N(4);

    for (int i = 0; i < 4;i++){
        cin >> N.at(i);
    }

    if(N.at(0)==N.at(1) && N.at(1)==N.at(2) ){
        cout << "Yes" << endl;
    }
    else if (N.at(1) == N.at(2) && N.at(2) == N.at(3) ){
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#変数でなく定義で、クラス内参照おk
ARRAY = [512, 256 , 128, 64, 32, 16, 8, 4, 2, 1]

while tmp = gets
  break if tmp == nil
  tmp = tmp.to_i
  tmp_hash = Hash.new
  ARRAY.each do |i|
    if  tmp / i  > 0
      tmp_hash[i] =tmp / i
      tmp = tmp - (i * (tmp/i))
    else
      next
    end
  end
  #最終出力
  puts tmp_hash.keys.reverse.join(" ")
end



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

using namespace std;

int N;
int T;
int A;
int H[1000];

void solve() {
    double min = 100000;
    int min_i = 0;
    for (int i = 0; i < N; i++) {
        if (min > abs(A - T + 0.006 * H[i])) {
            min = abs(A - T + 0.006 * H[i]);
            min_i = i + 1;
        }
    }
    printf("%d\n", min_i);
    return;
}

int main() {
    cin >> N;
    cin >> T >> A;
    for (int i = 0; i < N; i++) cin >> H[i];
    solve();
    return 0;
}

Measured memory_bytes: 3776
mod, MAX = 10**9+7, 500000
fac, inv = Array.new(MAX + 5, 0), Array.new(MAX + 5, 0)

fac[0] = 1
for i in 1..MAX
  fac[i] = fac[i-1]*i%mod
end
inv[MAX] = fac[MAX].pow(mod-2, mod)
for i in 1..MAX
  j = MAX - i
  inv[j] = inv[j+1]*(j+1)%mod
end

N, M = gets.split.map(&:to_i)
ans = 0
for i in 0..N
  now = fac[N]*inv[i]*inv[N-i]%mod * fac[M-i] % mod
  ans += i%2==0 ? now : -now
end
ans = (ans%mod + mod) % mod
ans = ans * fac[M] * inv[M-N] * inv[M-N] % mod
p ans


Measured memory_bytes: 22104
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int X = sc.nextInt();
		int sum = 0;
		int min = 1001;
		int[] m = new int[N];
		for(int i = 0; i < N; i++){
			m[i] = sc.nextInt();
			sum += m[i];
			if(m[i] < min) min = m[i];
		}
		
		System.out.println((X - sum) / min + N);
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
 
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int e[n+1] = {}, w[n+1] = {};
    e[0] = 0;
    w[0] = 0;
    for(int i = 1; i <= n;i++){
        e[i] = e[i-1];
        w[i] = w[i-1];
        if(s[i-1] == 'E'){
            e[i]++;
        }else{
            w[i]++;
        }
    }
    int ans = 300001;
    for(int i = 1; i <= n; i++){
        ans = min(ans,w[i-1] + e[n] - e[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;

int n, k;
vector<int> arr;

void solve() {
  vector<bool> dp(k+1, false);
  dp[0] = false;
  for (int i=1; i<=k; ++i) {
    for (int j: arr) {
      if (i - j < 0) {
        break;
      }
      if (!dp[i-j]) {
        dp[i] = true;
        break;
      }
    }
  }
  cout << (dp[k] ? "First" : "Second") << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  arr = vector<int>(n);
  for (int i=0; i<n; ++i) {
    cin >> arr[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      	int K = sc.nextInt();
		if(N%2 == 1){
          if(N/2+1 < K){
          	System.out.println("NO");
          }else{
          	System.out.println("YES");
          }
        }else{
        	if(N/2 < K){
            	System.out.println("NO");
            }else{
           	 System.out.println("YES");
            }
        }
    }
}


Measured memory_bytes: 21460
N = int(input())
W = list(map(int, input().split()))
mins = []
def get_abs(n):
    return abs(n)
for i in range(1, N):
    right = sum(W[:i])
    left = sum(W[i:])
    diff_abs = get_abs(right - left)
    mins.append(diff_abs)
print(min(mins))

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

int search(vector<int> num_i){
    int k=0;
    for(int i=0; i<8; i++){
    int sum=num_i.at(0);  
    k=i;
    for(int j=1; j<num_i.size(); j++){
      if(k%2==0){
        sum+= num_i.at(j);
      }
      if(k%2==1){
        sum-= num_i.at(j);
      }
      k/=2;
      if(j==num_i.size()-1 && sum==7){
        return i;
      }
    }
  }
  return -1;
}
  
int main(){
  string num_s;
  cin >> num_s;
  vector<int> num_i(num_s.size());
  for(int i=0; i<num_s.size(); i++){
    num_i.at(i)= num_s.at(i)-48;
  }

//sum=7になるときの符号値 search(num_i);
  if(search(num_i)==-1) return 0;
  int op= search(num_i);
//出力
  for(int i=0; i<4; i++){
    cout << num_i.at(i);
    if(i==3) break;
    if(op%2==0){
      cout << "+";
    }
    if(op%2==1){
      cout << "-";
    }
    op/=2;
  }
  cout << "=7" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
vector<int> w,v;
long int dpv[100001][3];
/*long int dp(int W,int N)
{
	if(dpv[W][N])
		return dpv[W][N];
	if(W==0 || N==0)
		return 0;
	if(w[N]<=W)
		dpv[W][N]=max(dp(W-w[N],N-1)+v[N],dp(W,N-1));
	else
		dpv[W][N]=dp(W,N-1);
	return dpv[W][N];
}*/
long int dp(int W,int N)
{
	int i,j;
	if(W==0 || N==0)
		return 0;
	for(j=1;j<=N;j++)
		for(i=1;i<=W;i++)
		{
			if(w[j]<=i)
				dpv[i][j%2]=max(dpv[i-w[j]][(j-1)%2]+v[j],dpv[i][(j-1)%2]);
			else
				dpv[i][j%2]=dpv[i][(j-1)%2];
		}
	j--;
	return dpv[W][N%2];
}
int main()
{
  	w.pb(0);v.pb(0);
	int N,W,i,w1,v1;
	cin>>N>>W;
	for(i=1;i<=N;i++)
	{
		cin>>w1>>v1;
		w.pb(w1);
		v.pb(v1);
	}
	cout<<dp(W,N);
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
class SegmentTree
{
private:
  using Fn = function<T(T, T)>;
  int N;
  vector<T> dat;
  T unit;
  Fn func;

public:
  SegmentTree() {}
  SegmentTree(int n_, Fn func_, T unit_) : func(func_), unit(unit_)
  {
    N = 1;
    while (N < n_)
      N *= 2;
    dat.assign(2 * N - 1, unit);
  }
  SegmentTree(const vector<T> &v, Fn func_, T unit_) : func(func_), unit(unit_)
  {
    N = 1;
    int sz = v.size();
    while (N < sz)
      N *= 2;
    dat.resize(2 * N - 1);
    for (int i = 0; i < N; ++i)
      dat[i + N - 1] = (i < sz ? v[i] : unit);
    for (int i = N - 2; i >= 0; --i)
      dat[i] = func(dat[i * 2 + 1], dat[i * 2 + 2]);
  }

  // k 番目の要素を a に変更
  void update(int k, T a)
  {
    k += N - 1;
    dat[k] = a;
    while (k > 0)
    {
      k = (k - 1) / 2;
      dat[k] = func(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  // k 番目の要素を取得
  T get(int k) { return dat[k + N - 1]; }

  // 区間 [l, r) の和を取得
  T query(int l, int r)
  {
    T vl = unit, vr = unit;
    for (l += (N - 1), r += (N - 1); l < r; l >>= 1, r >>= 1)
    {
      if ((l & 1) == 0)
        vl = func(vl, dat[l]);
      if ((r & 1) == 0)
        vr = func(vr, dat[--r]);
    }
    return func(vl, vr);
  }
};
int main(){
ll n,q;
cin >> n >> q;
auto summa = [](ll a, ll b) { return a + b; };
SegmentTree<ll> sgt(n, summa, 0);
for (ll i = 0; i < q;i++){
    ll s,t,u;
    cin >> s >> t >> u;
    t--;
    if (s == 0) {
        sgt.update(t, sgt.get(t)+u);
    } else {
        cout << sgt.query(t,u)<< endl;
    }
}
}


Measured memory_bytes: 4876
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
ll n,k;
ve <ll> arr;
bool is_poss(ll x)
{
    ll cnt=0;
    rep (i,0,n)
    {
        if (arr[i]>x)
        {
            cnt+=arr[i]/x;
            if (arr[i]%x==0)
            {
                cnt--;
            }
        }
        
    }
    if (cnt<=k)
    {
        return true;
    }
    return false;
}
int main()
{
    FAST
        // freopen("input1.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    cin >> n >> k;
    arr.assign(n,0);
    rep(i, 0, n)
    {
        cin >> arr[i];
    }
    ll low=1,high=1e16;
    while (low<=high)
    {
        ll mid=(low+high)/2;
        if (is_poss(mid))
        {
            high=mid;
        }
        else
        {
            low=mid;
        }
        if (high-low<=5)
        {
            rep (i,low,high+1)
            {
                if (is_poss(i))
                {
                    cout<<i<<"\n";
                    return 0;
                }
            }
        }
    }
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define oo 2000000000
#define inf 1000000000000000LL
#define M 1000000007
typedef long long ll;
using namespace std;
const int N = 105001;

map<string,string> mp;

signed main(){
    string s;
    cin >> s;
    for(int i = 0 ; i < s.size() ; i++){
        if(s[i]=='L'&&(i%2==0)||s[i]=='R'&&(i&1))return puts("No"),0;
    }
    puts("Yes");
    
    

    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    int A, B;
    cin >> A >> B;

    cout << max({A+B, A-B, A*B}) << endl;

    return 0;
}

Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

bn = 2 ** 42

def bb(v):
	ra = bin(v+bn)[3:][::-1]
	return ra

def cc(v, i):
	r = pow(2, i)
	vn = v+1
	vna = vn //(2*r)
	vnb = vn % (2*r)
	ret = vna * r
	ret += max(vnb - r, 0)
	#pa((v,i,ret))
	return ret

def main():
	#a = int(input())
	f, t = tin()
	#s = input()
	ret = 0
	for i, _ in enumerate(bb(0)):
		r = pow(2, i)
		nn = cc(t,i) - cc(f-1, i)
		if (nn) % 2 == 1:
			#pa(r)
			ret += r
	return ret
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 62328
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
ll n[31];
ll solve(ll a, ll b, ll c, ll d, int k){
	assert(0<=a && a<n[k] && 0<=b && b<n[k] && 0<=c && c<n[k] && 0<=d && d<n[k]);
	ll x1=a/n[k-1], y1=b/n[k-1], x2=c/n[k-1], y2=d/n[k-1];
	if(P(x1, y1)==P(x2, y2)){
		a-=n[k-1]*x1, b-=n[k-1]*y1, c-=n[k-1]*x2, d-=n[k-1]*y2;
		return solve(a, b, c, d, k-1);
	}
	if(x1!=x2 && y1!=y2) return abs(a-c)+abs(b-d);
	if(y1!=y2){
		swap(a, b), swap(c, d), swap(x1, y1), swap(x2, y2);
	}
	if(y1==1){
		ll s=b-n[k-1]+1+d-n[k-1]+1;
		return abs(a-c)+min(s, 2*(n[k-1]+1)-s);
	}
	b-=y1*n[k-1], d-=y1*n[k-1];
	if(k==1) return abs(a-c)+abs(b-d);
	if(x1>x2){
		swap(x1, x2), swap(a, c), swap(b, d);
	}
	ll x11=a/n[k-2], y11=b/n[k-2], x22=c/n[k-2], y22=d/n[k-2];
	if(y11!=y22){
		return abs(a-c)+abs(b-d);
	}
	if(y11==1 && ((x11==2 && x22==3) || (x11==5 && x22==6))){
		b-=n[k-2], d-=n[k-2], a-=x11*n[k-2], c-=x11*n[k-2];
		return solve(a, b, c, d, k-1);
	}else if(y11==1){
		c-=n[k-2]*(x22-2);
		a-=n[k-2]*x11;
		return (x22-x11-2)*n[k-2]+solve(a, b, c, d, k-1);
	}else if(x22-x11==1){
		c-=n[k-2]*(x22-1);
		a-=n[k-2]*x11;
		return (x22-x11-1)*n[k-2]+solve(a, b, c, d, k-1);
	}else{
		c-=n[k-2]*(x22-2);
		a-=n[k-2]*x11;
		return (x22-x11-2)*n[k-2]+solve(a, b, c, d, k-1);
	}
}
int main()
{
	n[0]=1;
	for(int i=1; i<=30; i++) n[i]=n[i-1]*3;
	int q; cin>>q;
	for(int i=0; i<q; i++){
		ll a, b, c, d;
		cin>>a>>b>>c>>d;
		a--;b--;c--;d--;
		cout<<solve(a, b, c, d, 30)<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
a = int(input())

b = list(map(int,input().split()))

c = sum(b)/a
d = 10000
for i in range(a):
	if abs(b[i]-c) < d:
		d = abs(b[i]-c)

for i in range(a):
	if abs(b[i]-c) == d:
		print(i)
		break

Measured memory_bytes: 3316