akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <numeric>
#include<queue>
using namespace std;
typedef long long ll;
typedef vector<int>VI;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define fi first
#define se second
#define MAX 100100//5
#define MAX_N 200100
#define MAX_B 1001001//6
#define MAX_S 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL

int main(){
  int n;
  string s;
  cin>>n>>s;
  ll count=0;
  rep(i,1000){
      bool can=false;
      int x=i;
      int a1,a2,a3;
      int f_i,s_i;
      a1=x%10;x/=10;a2=x%10;x/=10;a3=x%10;
      rep(j,n-2){
          if(s[j]-'0'==a3){
              f_i=j;
              can=true;
              break;
          }
          can=false;
      }
      if(can)for(int j=f_i+1;j<n-1;++j){
          if(s[j]-'0'==a2){
          s_i=j;
          can=true;
          break; 
      }
      can=false;
      }
      if(can)for(int j=s_i+1;j<n;++j){
          if(s[j]-'0'==a1){
          can=true;
          break;
      }
      can=false;
      }
      if(can){
          count++;}
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b) {ll res = 1; a = a % mod; while (b) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b /= 2;} return res;}
ll invmod(ll a) {return power(a, mod - 2);}
vector<vector<ll>>dis;
ll n, m, l, a, b, c;
void solve() {
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				dis[j][k] = min(dis[j][k], dis[j][i] + dis[i][k]);
			}
		}
	}
}
int main(void)
{
	FIO
	int t = 1;
	// cin >> t;
	while (t--)
	{
		cin >> n >> m >> l;
		dis.assign(n, vector<ll>(n, 1e17));
		for (int i = 0; i < m; i++) {
			cin >> a >> b >> c;
			a--, b--;
			dis[a][b] = c;
			dis[b][a] = c;
		}
		solve();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i == j) dis[i][j] = 0;
				else dis[i][j] = (dis[i][j] <= l) ? 1 : 1e18;
			}
		}
		solve();
		int q;
		cin >> q;
		while (q--) {
			cin >> a >> b;
			a--, b--;
			if (dis[a][b] < 1e18) cout << dis[a][b] - 1 << "\n";
			else cout << "-1\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3940
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int max = 1500000;
        int[] p = new int[max];
        for(int i=2; i<p.length; i++) p[i] = 1;
        for(int i=2; i<Math.sqrt(max)+1; i++){
            for(int j=i*2; j<max; j+=i) p[j] = 0;
        }

        while(true){
            int n = sc.nextInt();
            if(n==0) break;

            int idx1 = n, idx2 = n;
            while(p[idx1]!=1) idx1--;
            while(p[idx2]!=1) idx2++;
            System.out.println(idx2 - idx1);
        }
    }

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

Measured memory_bytes: 30548
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: usize,
        k: usize,
        r: u32,
        s: u32,
        p: u32,
        tt: chars
    }
    let score = |x| {
        match x {
            'r' => p,
            's' => r,
            'p' => s,
            _   => 0
        }
    };
    let mut tt = tt;
    for i in k..n {
        if tt[i-k] == tt[i] {
            tt[i] = 'x';
        }
    }
    let res: u32 = tt.iter().map(|t| score(*t)).sum();
    println!("{}", res);
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <iostream>
using namespace std;
typedef long long LL;
const int Maxn = 1e5 + 6;
const int inf = 1000000000;
const LL Inf = 1LL<<60;
int s[100009],b[100009];
int gcd(int x, int y){
	if (y == 0) return x;
	return gcd(y,x%y);
	}
int main ()
{
	int n,x;
	scanf("%d%d",&n,&x);
	for (int i = 1; i <= n; i++) scanf("%d",&s[i]);
	sort(s+1,s+1+n);
	int cnt = 0;
	int t = 1000000000;
	for (int i = n; i >= 1; i--){
		b[++cnt] = abs(x - s[i]);
	}
	int k = 1000000000;
	for (int i = cnt; i >= 1; i--){
		k = min(gcd(b[i],b[1]),k);
	}
	printf("%d\n",k);
	return 0;
}

Measured memory_bytes: 1024
def main():
    import sys
    N = int(input())
    A = ["?"]*N
    pos = N//2
    left = 0
    right = N
    if A[left] == "?":
        print(left)
        sys.stdout.flush()
        S = input()[0]
        if S == "V":
            return
        A[left] = S
    for i in range(20):
        pos = (left+right)//2
        if A[pos] == "?":
            print(pos)
            sys.stdout.flush()
            S = input()[0]
            if S == "V":
                return
            A[pos] = S

        if (pos - left) % 2 == 0:
            if A[pos] == A[left]:
                left = pos
            else:
                right = pos
        else:
            if A[pos] != A[left]:
                left = pos
            else:
                right = pos


if __name__ == '__main__':
    main()


Measured memory_bytes: 4424
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	//この問題の気持ち的にXORする数字（A_1からA_Nまでの数字）の各桁のビットを見ておき、その立っているか/立っていないかの数を調べていけばよさそう
	//XOR　は　11->0 10->1 01->1 00->0
	static int[] bits=new int[63];
	public static void main(String[] args) {
		for(int i=0; i<63; i++) {
			bits[i]=0;
		}
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		long K=sc.nextLong();
		//オーバーフローに注意
		long[] uketori=new long[N];
		for(int i=0; i<N; i++) {
			uketori[i]=sc.nextLong();
			calcbit(uketori[i]);
		}
		long[] suji=new long[62];
		suji[0]=1;
		for(int i=1; i<62; i++) {
			suji[i]=suji[i-1]*2;
		}
		long ans=0;
		for(int i=61; i>=0; i--) {
			if(bits[i]*2>N) {		//XORのビットが半分以上たっていないなら解のビットを立たせない  立っているものと立っていないものが同数のときは立たせないほうが値が小さくなり、より制限に適応できる
			}
			else if(bits[i]*2<=N) {
				if(ans+suji[i]<=K) {
					ans+=suji[i];
				}
			}
		}
		long output=0;

		for(int i=0; i<N; i++) {
			output+=(ans^uketori[i]);
		}
		pl(output);
	}
	public static void calcbit(long tmp) {
		long a=tmp;
		int counter=0;
		while(a>0) {
			if(a%2==1) {
				bits[counter]++;
			}
			counter++;
			a/=2;
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define endl '\n'

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

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...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<40;
const ll MOD = 998244353;

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

  ll a, b, c;
  cin >> a >> b >> c;
  cout << b + min(c, a+b+1) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <bitset>
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a==b)
    cout << c << endl;
  if (a == c)
    cout << b << endl;
  if (c == b)
    cout << a << endl;
}

Measured memory_bytes: 256
//darkstallion's template

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<stack>
#include<queue>
#include<algorithm>
#include<cmath>
#include<string>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define popb pop_back
#define del erase
#define sz size
#define ins insert
#define FOR(a,b,c) for(int a = b; a < c; a++)
#define FORS(a,b,c) for(int a = b; a <= c; a++)
#define FORN(a,b) for(int a = 0; a < b; a++)
#define FORD(a,b,c) for (int a = b; a >= c; a--)
#define RES(a,b) memset(a,b,sizeof(a))
#define LL long long
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define PDD pair<double,double>
#define PCC pair<char,char>
#define PSS pair<string,string>
#define PI acos(-1)
#define eps 1e-9
#define MOD 1000000007
using namespace std;

LL fac[200050];

LL bigmod(LL x, LL y) {
  if (y == 1) {
    return x % MOD;
  }

  LL ret = bigmod(x, y / 2);
  ret = ret * ret % MOD;
  if (y % 2) {
    ret = ret * x % MOD;
  }

  return ret;
}

LL imod(LL x) {
  return bigmod(x, MOD - 2);
}

LL nCr(int n, int r) {
  LL ret = fac[n-r] * fac[r] % MOD;
  ret = imod(ret) * fac[n] % MOD;
  return ret;
}

int main() {
  fac[0] = 1;
  FORS(i, 1, 200000) {
    fac[i] = fac[i-1] * (LL) i % MOD;
  }
  
  int h, w, a, b;
  scanf("%d%d%d%d", &h, &w, &a ,&b);

  LL ans = 0;
  FORS(i, 1, h - a) {
    ans += nCr(i + b - 2, b - 1) * nCr(h + 1 - i + w - b - 2, w - b - 1) % MOD;
    ans %= MOD;
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 1920
N,A,B,C,D = map(int,input().split())
S = list(input().strip())
S.insert(0,0)
if C<D:
    flag = 0
    for i in range(A+1,C+1):
        if S[i-1]=="#" and S[i]=="#":
            flag = 1
            break
    for i in range(B+1,D+1):
        if S[i-1]=="#" and S[i]=="#":
            flag = 1
            break
    if flag==0:
        print("Yes")
    else:
        print("No")
else:
    flag = 0
    for i in range(A+1,C+1):
        if S[i]=="#" and S[i-1]=="#":
            flag = 1
            break
    if flag == 0:
        flag1 = 1
        for i in range(B,D+1):
            if i+1<=N and S[i-1]=="." and S[i]=="." and S[i+1]==".":
                flag1 = 0
                break
        if flag1==1:
            flag = 1
    if flag==0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 86456
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		// *AABCBDBA*
		// 0111111110
		// 1101111200 A L
		// 0100202020 B R
		// 1010202002 A R
		// 1000000001
		// 1000000011 A L
		// 1000000111 B L
		// 1100000111 A R
		// *ABC*
		// 10001
		// 11001
		var I = G;
		int N = I[0], Q = I[1];
		var S = Str.Select(c => c - 'A').ToList();
		S.Insert(0, 50);
		S.Add(50);
		var qs = new Pair[Q];
		for (var i = 0; i < Q; i++)
		{
			var q = Strs;
			qs[i] = new Pair(q[0][0] - 'A', q[1] == "L" ? -1 : 1);
		}
		var j = FirstBinary(0, N + 2, x =>
		{
			foreach (var q in qs) if (q.C == S[x]) x += q.D;
			return x > 0;
		});
		//WriteLine(j);
		var k = FirstBinary(j, N + 2, x =>
		{
			foreach (var q in qs) if (q.C == S[x]) x += q.D;
			return x == N + 1;
		});
		//WriteLine(k);
		WriteLine(k - j);
	}
	public static int FirstBinary(int min, int max, Predicate<int> pred)
	{
		while (min < max)
		{
			var mid = (min + max) / 2;
			if (pred(mid)) max = mid;
			else min = mid + 1;
		}
		return min;
	}
}
struct Pair
{
	public int C, D;
	public Pair(int c, int d) { C = c; D = d; }
}

Measured memory_bytes: 21432
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();
		System.out.printf("%d %d %6f",a/b,a%b,(double)a/b);
	}
		
	}

Measured memory_bytes: 17180
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = line[0];
            int B = line[1];
            int X = line[2];
            if (X < A)
            {
                Console.WriteLine("NO");
            }
            else if (X - A <= B)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
using namespace std;

signed main() {
    int n;
    int h[20] = {0};
    int ans = 0;
    cin >> n;
    rep(i, n) {
        cin >> h[i];
        if (h[i] >= h[0] && h[i] >= h[1] && h[i] >= h[2] && h[i] >= h[3] && h[i] >= h[4] && h[i] >= h[5] && h[i] >= h[6] && h[i] >= h[7] && h[i] >= h[8] && h[i] >= h[9] && h[i] >= h[10] && h[i] >= h[11] && h[i] >= h[12] && h[i] >= h[13] && h[i] >= h[14] && h[i] >= h[15] && h[i] >= h[16] && h[i] >= h[17] && h[i] >= h[18] && h[i] >= h[19]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/


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

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int ans = 0;
	ans += min(a, b);
	ans += min(c, d);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	fmt.Println(harshad(n))
}

func harshad(n int) string {
	f := digitSum(n)
	if n%f == 0 {
		return "Yes"
	}
	return "No"
}

func digitSum(n int) int {
	var s int
	for n > 0 {
		s += n % 10
		n /= 10
	}
	return s
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

vector<ll> A;
vector<ll> S;
map<ll, ll> counter;

int main(void) {
    ll N, M;
    cin >> N >> M;

    A.resize(N + 1, 0);
    S.resize(N + 1, 0);
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        A[i + 1] = x;
        S[i + 1] = S[i] + x;
    }

    ll acc = 0;
    for (int i = 0; i <= N; i++) {
        ll x = S[i] % M;
        acc += counter[x];
        counter[x]++;
    }

    cout << acc << endl;

    return 0;
}


Measured memory_bytes: 5760
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc = new FastScanner();
	static PrintWriter out = new PrintWriter(System.out);

	static void solve() {
		int N = sc.nextInt();
		int Q = sc.nextInt();
		int[] year = new int[N];
		String[] name = new String[N];
		for (int i = 0; i < N; i++) {
			year[i] = sc.nextInt();
			name[i] = sc.next();
		}
		String ans = "kogakubu10gokan";
		for (int i = 0; i < N - 1; i++) {
			if (year[i] <= Q && Q < year[i + 1]) {
				ans = name[i];
				break;
			}
		}
		if (year[N - 1] <= Q) {
			ans = name[N - 1];
		}
		out.println(ans);
		out.flush();
	}

	public static void main(String[] args) {
		solve();
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private static boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

}

Measured memory_bytes: 24400
/*#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")*/
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
using namespace std;
#define ll long long

//ゼロにリセットする用
vector<ll>R_26(26),R_365(365);
vector<vector<ll>>R_365_26(365,vector<ll>(26));

//色々計算する用
vector<ll>C(26),last2(26),T(365),Tans(365),V(365),Vorigin(365);
vector<vector<ll>>S(365,vector<ll>(26)),
                last(365,vector<ll>(26)),
                last_sim(365,vector<ll>(26));
ll D,vmax,dadd_best,steps=0;

void greedy(){
    ll dadd,i,j,k,l,i_calc,tbest,score,vbest;
    for(dadd=0;dadd<=26;++dadd){
        //リセット
        last2=R_26;
        last=R_365_26;

        for(i=0;i<D;i++){
            i_calc=min(i+dadd+1,D);
            //cout<<i_calc<<endl;
            for(j=0;j<26;j++){
                //得点の初期化
                //cout<<i<<endl;
                if(i==0){
                    V[i]=0;
                }else{
                    V[i]=V[i-1];
                }
                
                //lastの初期化
                if(i==0)last[i]=R_26;
                else last[i]=last[i-1];

                last[i][j]=i+1;
                V[i]+=S[i][j];

                for(k=0;k<26;k++)
                    for(l=i;l<i_calc;l++)V[i]-=C[k]*(l+1-last[i][k]);

                if(j==0||V[i]>=vmax){
                    vmax=V[i];
                    tbest=j;
                }
            }
            if(i==0)last[i]=R_26;
            else last[i]=last[i-1];
            T[i]=tbest+1;
            last[i][tbest]=i;
        }

        //得点の再計算
        score=0;
        last2=R_26;

        for(i=0;i<D;i++){
            score+=S[i][T[i]-1];
            last2[T[i]-1]=i+1;
            for(j=0;j<26;j++)score-=C[j]*(i+1-last2[j]);
        }

        if(dadd==0||score>vbest){
            dadd_best=dadd;
            vbest=score;
            Tans=T;
            last_sim=last;
        }
    }

    vmax=vbest;
    T=Tans;
    last=last_sim;
}

int main(){
    int i,j;
    cin>>D;
    for(i=0;i<26;i++)cin>>C[i];
    for(i=0;i<D;i++)for(j=0;j<26;j++)cin>>S[i][j];
    greedy();
    //cout<<dadd_best<<endl;
    for(i=0;i<D;i++)cout<<T[i]<<"\n";
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200003,INF=1<<30;

int expr(string& s,int& i);
int number(string& s,int& i);

int expr(string& s,int& i){
    vector<int> T;
    
    for(;;){
        if(s[i]=='['){
            i++;
            T.push_back(expr(s,i));
        }else if(s[i]==']'){
            i++;
            break;
        }else if(i>=s.size()){
            break;
        }else{
            T.push_back(number(s,i));
        }
    }
    
    sort(all(T));
    
    int ret=0;
    
    for(int j=0;j<(T.size()+1)/2;j++) ret+=T[j];
    
    return ret;
}

int number(string& s,int& i){
    int ret=0;
    
    while(isdigit(s[i])){
        ret*=10;
        ret+=int(s[i]-'0');
        i++;
    }
    
    return (ret+1)/2;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        string S;cin>>S;
        int i=0;
        
        cout<<expr(S,i)<<endl;
    }
}







Measured memory_bytes: 3284
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <tuple>
#include <vector>
#include <set>
#include <map>
#include <iterator>
#include <random>
#include <cmath>

using namespace std;
using lint = long long int;



int main() {
	int n;
	cin >> n;
	cout << (n - 1) / 2;

	return 0;
}

Measured memory_bytes: 256
object Main {
	
	// 繰り返し二乗法　O(log n)
//	def pow(x: BigInt, n: Int, m: Int): BigInt = n match{
//		case 0 => 1
//		case n if n%2==0 => pow(x*x, n/2, m) % m
//		case n if n%2!=0 => pow(x*x, n/2, m) * x % m
//	}
	
	def main(args: Array[String]) = {
		val sc = new java.util.Scanner(System.in)
		val m,n = sc.nextInt
		val bigM = BigInt(m)
		val bigN = BigInt(n)
		
		println(bigM.modPow(n, 1000000007))	// modPowクソ早い
	}
}

Measured memory_bytes: 45132
integer(8) :: i,j,k,m,n,nn,ans(1000)=0,ii
read*, n

if(n==0)then
  print"(i0)",0
  stop
endif

nn=n
i = 1
ii = 1

do while(nn/=0)
  if(mod(nn,-2*ii)/= 0)then
    ans(i) = 1
    nn = nn - ii
  endif
  i=i+1
  ii = ii * (-2)
end do

print"(1000(I0))", ans(i-1:1:-1)

end

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
typedef pair<int,int> P;
const int INF=1e9;
int main(){
    ll ans=0;
    ll n;
    cin>>n;
    vector<ll> k(n+5);
    for(ll i=1;i<=n;i++){
        ll j=i;
        while(j<=n){
            k[j]++;
            j+=i;
        }
    }
    for(ll i=1;i<=n;i++){
        ans+=i*k[i];
    }
    cout<<ans;
}

Measured memory_bytes: 81400
// abc154_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
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;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  string s,t,u;
  int a,b;
  cin>>s>>t>>a>>b>>u;
  if(s==u)cout<<a-1<<" "<<b<<endl;
  else cout<<a<<" "<<b-1<<endl;
  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001001001001ll;

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int N,D;
int A[222222];
signed main(){
	cin>>N>>D;
	rep(i,N)cin>>A[i];

	UnionFindTree uf(N);

	int ans=0;
	while(true){
		if(uf.size(0)==N)break;
		vector<tuple<int,int,int>>uku,ushi;

		pint p(INF,-1);
		int cur=0;
		while(cur<N){
			int nex=cur;
			int mi1=INF,mi2=INF;
			while(nex<N&&uf.areSame(cur,nex)){
				chmin(mi1,nex*D+A[nex]);
				chmin(mi2,-nex*D+A[nex]);
				nex++;
			}
			uku.pb(make_tuple(p.fi+mi1,p.se,cur));
			if(p.fi>mi2)p={mi2,cur};
			cur=nex;
		}

		p={INF,-1};

		cur=N-1;
		while(cur>=0){
			int nex=cur;
			int mi1=INF,mi2=INF;
			while(nex>=0&&uf.areSame(cur,nex)){
				chmin(mi1,-nex*D+A[nex]);
				chmin(mi2,nex*D+A[nex]);
				nex--;
			}
			ushi.pb(make_tuple(p.fi+mi1,p.se,cur));
			if(p.fi>mi2)p={mi2,cur};
			cur=nex;
		}
		reverse(all(ushi));
		rep(i,uku.size()){
			tuple<int,int,int>t=min(uku[i],ushi[i]);
			int c,x,y;tie(c,x,y)=t;
			if(uf.areSame(x,y))continue;
			ans+=c;
			uf.unite(x,y);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 21228
//Leonidas
#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container'.',hpp>
//#include <ext/pb_ds/tree_policy'.',hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
int T[205];
int32_t main()
{
    speed
    int n,x;
    cin>>x>>n;
    for(int i=1;i<=n;i++)
    {
        int a;
        cin>>a;
        T[a]=1;
    }
    int ile=inf,skad=0;
    for(int i=0;i<=200;i++)
    {
        if(!T[i]&&abs(i-x)<ile)
        {
            ile=abs(i-x);
            skad=i;
        }
    }
    cout<<skad;
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
#define N 100100
using namespace std;

ll n,fa[N],bb,ans;
struct Node
{
	ll x,y,id;
}node[N];
struct Bn
{
	ll a,b,c;
	bool operator < (const Bn u) const
	{
		return c<u.c;
	}
}bn[N<<1];

ll ff(ll u){return u==fa[u]?u:fa[u]=ff(fa[u]);}
inline bool cmp1(Node u,Node v){return u.x<v.x;}
inline bool cmp2(Node u,Node v){return u.y<v.y;}

int main()
{
	ll i,j,p;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		scanf("%lld%lld",&node[i].x,&node[i].y);
		node[i].id=i;
		fa[i]=i;
	}
	sort(node+1,node+n+1,cmp1);
	for(i=1;i<n;i++) bn[++bb].a=node[i].id,bn[bb].b=node[i+1].id,bn[bb].c=node[i+1].x-node[i].x;
	sort(node+1,node+n+1,cmp2);
	for(i=1;i<n;i++) bn[++bb].a=node[i].id,bn[bb].b=node[i+1].id,bn[bb].c=node[i+1].y-node[i].y;
	sort(bn+1,bn+bb+1);
	for(i=1;i<=bb;i++)
	{
		if(ff(bn[i].a)==ff(bn[i].b)) continue;
		fa[ff(bn[i].a)]=ff(bn[i].b);
		ans+=bn[i].c;
	}
	cout<<ans;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;

    // Se um dos números for par o produto será par. Logo só é possível se os três forem ímpares
    cout<<(a % 2 and b % 2 ? "Yes" : "No")<<endl;   // a%2 e b%2, só sai do if se a condição for igual a 0
    return 0;
}


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

int main() {
  string num;
  cin >> num;
  for (int i = 0; i < 3; i++) {
    if (num.at(i) == '1') {
      num.at(i) = '9';
    }
    else {
      num.at(i) = '1';
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<int> diff_weight;

	UnionFind(int n = 1, int SUM_UNITY = 0) {
		init(n, SUM_UNITY);
	}

	void init(int n = 1, int SUM_UNITY = 0) {
		par.resize(n); rank.resize(n); diff_weight.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
	}

	int root(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			int r = root(par[x]);
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}
	}

	int weight(int x) {
		root(x);
		return diff_weight[x];
	}

	bool issame(int x, int y) {//same
		return root(x) == root(y);
	}

	bool merge(int x, int y, int w) {//unite
		w += weight(x); w -= weight(y);
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y), w = -w;
		if (rank[x] == rank[y]) ++rank[x];
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}

	int diff(int x, int y) {//頂点間の距離
		return weight(y) - weight(x);
	}
};

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

	int N, M; cin >> N >> M;
	UnionFind uni(N);
	REP(i, M) {
		int a, b, c; cin >> a >> b >> c;
		a--;b--;
		if (uni.issame(a, b)) {
			if (uni.diff(a, b) != c) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			uni.merge(a, b, c);
		}
	}

	cout << "Yes" << endl;

	return 0;
}



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

using namespace std;
long long f(long long h, long long w)   {
    long long a1, a2, a3, ans = h*w;
    for(int i = 1; i < h; i++)  {
        a1 = w*i;
        a2 = (h-i)*(w/2);
        a3 = (h-i)*(w-w/2);
        long long m = min(a1, min(a2, a3));
        long long M = max(a1, max(a2, a3)); 
        //cout<<a1<<' '<<a2<<' '<<a3<<' '<<m<<' '<<M<<'\n';
        ans = min(M-m, ans);
        a2 = (h-i)/2*w;
        a3 = h*w-a2-a1;
        m = min(a1, min(a2, a3));
        M = max(a1, max(a2, a3));
        ans = min(M-m, ans);
        //cout<<a1<<' '<<a2<<' '<<a3<<' '<<m<<' '<<M<<'\n';
    }
    return ans;
}
int main()  {
    long long h, w, a1, a2, a3, ans;
    cin>>h>>w;
    if((h*w)%3 == 0)    {
        cout<<"0\n";
        return 0;
    }
    cout<<min(f(h,w), f(w,h))<<'\n';    
    return 0;
}

Measured memory_bytes: 256
def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    cumsumA = [0] * (N + 1)
    cumsumB = [0] * (N + 1)
    for i in range(N):
        cumsumA[i + 1] = cumsumA[i] + A[i]
        cumsumB[N - i - 1] = cumsumB[N - i] + A[N - i - 1]
    minA = 10**18
    for i in range(N + 1):
        minA = min(minA, abs(cumsumA[i] - cumsumB[i]))
    print(minA)


resolve()


Measured memory_bytes: 39300
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef char keytype;

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

/* a[0], ..., a[n-1] の数の最大公約数 */
int ngcd(int n, int a[])
{
    int i, d;

    d = a[0];
    for (i = 1; i < n && d != 1; i++)
        d = gcd(a[i], d);
    return d;
}

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

//#define N 5
//int p[N + 1];
int nextperm(int p[], int N)  /* 辞書式順序で次の順列 */
{
    int i, j, t;

    i = N - 1;
    p[0] = 0;  /* 番人 */
    while (p[i] >= p[i + 1]) i--;
    if (i == 0) return 0;  /* 完了 */
    j = N;
    while (p[i] >= p[j]) j--;
    t = p[i];  p[i] = p[j];  p[j] = t;
    i++;  j = N;
    while (i < j) {
        t = p[i];  p[i] = p[j];  p[j] = t;  i++;  j--;
    }
    return 1;  /* 未了 */
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

int min(int a, int b){
    if(a > b) return b;
    else return a;
}

const int inf = 1012345678;
int main(){
    int a, b, c;

    scanf("%d %d %d", &a, &b, &c);

    if(a <= c && c <= b) puts("Yes");
    else puts("No");

    return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>

int main(void)
{
	int a, b;
	int keta;
	int count;
	
	while (scanf("%d %d", &a, &b) != EOF) {
		keta = a + b;
		count = 1;
		while (keta >= 10) {
			keta /= 10;
			count++;
		}
		
		printf("%d\n", count);
	}
	return (0);
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;
const ll MAX_CNT = 1e9;

ll N, H;

bool is_ok(ll a_index, ll a, std::vector< ll >& vb, ll cnt)
{
  ll damage = 0;
  damage += a * cnt;
  ll max_throw_cnt = std::min(cnt, (ll)vb.size());

  for (ll i = 0; i < max_throw_cnt; i++) {
    damage += vb[i] >= a ? vb[i] - a : 0;
  }

  bool judge = false;
  if (damage >= H) {
    judge = true;
  }

  return judge;
}

int main(int argc, char* argv[])
{
  std::cin >> N >> H;

  std::vector< ll > va(N, 0);
  std::vector< ll > vb(N, 0);

  ll a_index = -1;
  ll a = -1;

  for (ll i = 0; i < N; i++) {
    std::cin >> va[i] >> vb[i];
    if (va[i] > a) {
      a_index = i;
      a = va[i];
    }
  }

  std::sort(vb.begin(), vb.end());
  std::reverse(vb.begin(), vb.end());

  ll left  = 0;
  ll right = MAX_CNT;
  while (right - left > 1) {
    ll mid = (left + right) / 2;
    if (is_ok(a_index, a, vb, mid)) {
      right = mid;
    } else {
      left  = mid;
    }
  }

  std::cout << right << std::endl;

  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

#define MIN(x,y) (x)>(y)?(y):(x)

int main(void){
	int n;
	scanf("%d",&n);
	char S[101];
	scanf("%s",S);
	int d=0,left=0,right=0;
	for(int i=0;i<n;i++){
		if(S[i]=='(')left++;
		else right++;
		d = MIN(d,left-right);
	}
	for(int i=0;i<-d;i++)printf("(");
	printf("%s",S);
	for(int i=0;i<left-right-d;i++)printf(")");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n;
  cin >> n;
  ll a = n / 1000;
  ll b = n % 1000 / 100;
  ll c = n % 100 / 10;
  ll d = n % 10;
  if(a==b&&b==c){
    print("Yes");
  }
  else if(b==c&&c==d){
    print("Yes");
  }
  else{
    print("No");
  }
}

Measured memory_bytes: 256
//#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 ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int v, e;
    cin >> v >> e;
    vvi dist(v, vi(v, INT_MAX));
    rep(i, e) {
        int s, t, d;
        cin >> s >> t >> d;
        dist[s][t] = d;
    }

    rep(i, v) {
        dist[i][i] = 0;
    }

    rep(k, v) {
        rep(i, v) {
            rep(j, v) {
                if(dist[i][k] == INT_MAX or dist[k][j] == INT_MAX) continue;
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    rep(i, v) {
        if(dist[i][i]) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }

    rep(i, v) {
        rep(j, v) {
            cout << (dist[i][j] == INT_MAX?"INF":to_string(dist[i][j])) << (j == v-1?'\n':' ');
        }
    }

}


Measured memory_bytes: 3352
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String s1 = sc.next();
        String ans = s1.substring(0,1);
        String s2 = sc.next();
        ans+=s2.substring(0,1);
        String s3 = sc.next();
        ans+=s3.substring(0,1);
        
        System.out.print(ans.toUpperCase());
   }
}


Measured memory_bytes: 39024
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int N, M;
    cin >> N >> M;
    vector<LP> drink(N);
    rep(i,N)cin >> drink[i].first >> drink[i].second;
    sort(all(drink));
    ll money = 0, bottle = 0;
    for(int i = 0; i < N && bottle < M; ++i){
        if(drink[i].second >= M-bottle){
            money += drink[i].first * (M-bottle);
            bottle = M;
        }else{
            money += drink[i].second * drink[i].first;
            bottle += drink[i].second;
        }
    }
    cout << money << endl;
    return 0;
}


Measured memory_bytes: 4840
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  int N,ans=0;
  cin >> N;
  pint A[N];
  rep(i,N) cin >> A[i].first,A[i].second=i;
  sort(A,A+N);
  rep(i,N) if(abs(A[i].second-i)%2==1) ans++;
  cout << ans/2 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

#define x first
#define y second

using pi = pair<int,int>;
using P = pair<pi,pi>;

struct Page{
    string name;

    int m;
    vector<P> b;
    vector<string> l;

    Page(){};

    void READ(){
        cin >>name >>m;
        b = vector<P>(m);
        l = vector<string>(m);
        rep(i,m){
            cin >>b[i].fi.x >>b[i].fi.y >>b[i].se.x >>b[i].se.y;
            cin >>l[i];
        }
    }

    string click(int x, int y){
        rep(i,m){
            if(b[i].fi.x<=x && x<=b[i].se.x && b[i].fi.y<=y && y<=b[i].se.y) return l[i];
        }
        return "?";
    }
};

int main(){
    int n;
    while(cin >>n,n){
        int W,H;
        cin >>W >>H;

        vector<Page> p(n);
        rep(i,n) p[i].READ();

        map<string,int> name2id;
        rep(i,n) name2id[p[i].name] = i;

        int Q;
        cin >>Q;

        vector<int> a(Q+2,-1);
        int idx = 0;
        a[0] = 0;

        rep(qq,Q){
            string s;
            cin >>s;
            if(s == "click"){
                int X,Y;
                cin >>X >>Y;
                string res = p[a[idx]].click(X,Y);
                if(res != "?"){
                    for(int j=idx+1; j<Q+2; ++j) a[j] = -1;
                    a[idx+1] = name2id[res];
                    ++idx;
                }
            }
            else if(s == "back"){
                if(idx>0) --idx;
            }
            else if(s == "forward"){
                if(a[idx+1] != -1) ++idx;
            }
            else{
                // show
                cout << p[a[idx]].name << "\n";
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3092
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();

        var ans = A.Skip(1).Aggregate(A[0], (s, e) => GcdLcm.Gcd(s, e));

        WriteLine(ans);
    }
}
static class GcdLcm
{
    public static long Gcd(long a, long b) => (b != 0) ? Gcd(b, a % b) : a;
    public static long Lcm(long a, long b) => a / Gcd(a, b) * b;
}


Measured memory_bytes: 38508