akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main(){
int n  = 0;
int min = 1000000;
int max = - 1000000;
long long sum = 0;
scanf("%d", &n);
int a[n];

for(int i = 0; i< n; i++){
//cin >> a[i];
scanf("%d", &a[i]);
}
for(int i = 0; i< n; i++){
//最小値
      if(min > a[i]){
           min = a[i];
     }

//最大値
      if(max < a[i]){
           max = a[i];
     }

//合計値
      sum += a[i];
}

cout << min << " " << max << " " << sum << endl;
return 0;
}


Measured memory_bytes: 3220
n = int(input())
l = []
for i in range(4):
  l.append([])
  for x in range(3):
    l[i].append([0] * 10)
for nn in range(n):
  b, f, r, v = list(map(int, input().split(' ')))
  l[b - 1][f - 1][r - 1] += v
i = 0
for n in l:
  for nn in n:
    for nnn in nn:
      print(' {0}'.format(nnn), end='')
    print('', sep='\n')
  i += 1
  if i == len(l):
    break
  print('####################')


Measured memory_bytes: 5620
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using System.IO;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var N = consoleReader.Int;
            var K = consoleReader.Int;
            return N % K == 0 ? 0 : 1;
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader
    {
        private Queue<string> queue = new Queue<string>();
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (queue.Count > 0) return queue.Dequeue();
                var line = textReader.ReadLine().Split();
                for (int i = 1; i < line.Length; i++) queue.Enqueue(line[i]);
                return line[0];
            }
        }
        public class SplitLine
        {
            private string[] splited;
            public SplitLine(ConsoleReader cr) { splited = cr.textReader.ReadLine().Split(); }
            public int[] Int => String.Select(x => int.Parse(x)).ToArray();
            public long[] Long => String.Select(x => long.Parse(x)).ToArray();
            public double[] Double => String.Select(x => double.Parse(x)).ToArray();
            public string[] String => splited;
        }
        public SplitLine Split => new SplitLine(this);
        public class RepeatReader
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }
            public IEnumerable<T> Select<T>(Func<ConsoleReader, T> func) { for (int i = 0; i < count; i++) yield return func(cr); }
            public IEnumerable<string> String { get { for (int i = 0; i < count; i++) yield return cr.String; } }
            public IEnumerable<int> Int { get { for (int i = 0; i < count; i++) yield return cr.Int; } }
            public IEnumerable<double> Double { get { for (int i = 0; i < count; i++) yield return cr.Double; } }
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
}

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

using namespace std;

int n, k, s;
int ret;

void f(int m, int num, int sum){
    if(num == k && sum == s)ret++;
    else if(s <= sum || k <= num) return;
    else {
        for(int i=m; i <= n; i++){
            f(i+1, num+1, sum+i);
        }
    }
}

int main(){
    while(cin >> n >> k >> s, n+k+s){
        ret = 0;
        for(int i=1; i <= n; i++){
            f(i+1, 1, i);
        }
        cout << ret << endl;
    }
}

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

int main()
{
    map<string,int>mp;
    int n,i,j,ans=0;
    string s;
    cin >> n;
    while(n--)
    {
        cin >> s;
        mp[s]++;
        if(mp[s]==1)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 19128
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;

template <class T> using V = vector<T>;

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

const long long INF = 1LL << 60;

using ll = long long;
using db = long double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;



#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define pb(a) push_back(a);



ll Sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}



const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


#define comuse Comuse()

ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll perm(int n,int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] % MOD) % MOD;
}


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


vll div(ll n){
  vll ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  SORT(ret);
  return (ret);
}

ll modpow(ll a,ll n,ll mod){
  ll ans=1;
  while(n>0){
    if(n&1){
      ans=ans*a%mod;
    }

    a=a*a%mod;
    
    n>>=1;
  }

  return ans;
}

void Solve();


const int MAX_N = 131072;
//segment tree 
int NN;
int seg[MAX_N*2-1];
void seguse(){
  for(int i=0;i<2*NN-1;i++){
    seg[i]=INT_MAX;
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}




/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
//segtreeの葉の先頭の添え字はn-1
void Solve(){
  //vll segtree(524287);
  //ll N=262144;
  ll h,w,n;
    cin>>h>>w>>n;
  ll hei=0;
  ll ans=0;
  ll reans=0;
  while(hei<n){
    hei+=w;
    ans++;
  }
  ll wai=0;
  while(wai<n){
    wai+=h;
    reans++;
  }
  cout<<min(ans,reans)<<"\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<utility>
using namespace std;

typedef pair<int, int> P;

char A[1001][1001];
int k[1001][1001];

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

    
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> A[i][j];
            k[i][j] = 0;
        }
    }

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

    int ans = 0;

    queue<P> que;

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(A[i][j] == '#'){
                que.push(P(i,j));
                k[i][j] = 1;
            }
        }
    }

    while(1){
        if(que.size() == 0){
            break;
        }else{
            int m = que.size();
            for(int s = 0; s < m; s++){
                P p = que.front();
                que.pop();

                for(int i = 0; i < 4; i++){
                    int nx = p.first + dx[i];
                    int ny = p.second + dy[i];

                    if(nx >= 0 && nx < H && ny >= 0 && ny < W  && A[nx][ny] == '.'){
                        A[nx][ny] = '#';
                        que.push(P(nx,ny));
                    }
                }

            }
            ans++;
        }
    }
    ans--;
    cout << ans << endl;
}

Measured memory_bytes: 13328
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define UNIQUE(a) unique(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
#include <ios>
#include <iomanip>
#include <sstream>
#include <map>

using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

const ll mod = 1e9+7;

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

	char a = '0', b = '0';
	int ac = 0, bc = 0;
	REP(i, 4) {
		if (a == '0' || s[i] == a) {
			a = s[i];
			ac++;
		}
		else if (b == '0' || s[i] == b) {
			b = s[i];
			bc++;
		}
	}

	if (ac == 2 && bc == 2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,a[N];
int main()
{
    ll ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<n;i++)
    {
        ll res=0;
        int l=0,r=n-1;
        while(true)
        {
            l+=i;r-=i;
            if(l==r||l-i==r||r<=i) break;
            res+=a[l]+a[r];
            ans=max(ans,res);
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#define MAX 10000
#define NIL -1

int parent[MAX],left[MAX],right[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u== NIL) return;
  D[u]=d;
  setDepth(left[u],d+1);
  setDepth(right[u],d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(left[u]!=NIL){
  h1 = setHeight(left[u])+1;}
  if(right[u]!=NIL){
  h2 = setHeight(right[u])+1;}
  return H[u]=(h1>h2 ? h1 : h2);
}

int getSibling(int u){
  if(parent[u]==NIL)return NIL;
  if(left[parent[u]] != u && left[parent[u]] != NIL){
  return left[parent[u]];}
  if(right[parent[u]] != u && right[parent[u]] != NIL){
  return right[parent[u]];}
  return NIL;
}

void print(int u){
  int degree =0;
  printf("node %d: ",u);
  printf("parent = %d, ",parent[u]);
  printf("sibling = %d, ",getSibling(u));
  if(left[u]!=NIL)degree++;
  if(right[u]!=NIL)degree++;
  printf("degree = %d, ",degree);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(parent[u]==NIL){
    printf("root\n");
  }
  else if (left[u]==NIL && right[u]==NIL){
    printf("leaf\n");
  }
  else printf("internal node\n");
}

int main(){
  int i,v,l,r,root=0;
  scanf("%d",&n);

  for (i=0;i<n;i++) parent[i]=NIL;

for (i=0;i<n;i++) {
  scanf("%d %d %d",&v,&l,&r);
  left[v]=l;
  right[v]=r;
  if (l!=NIL) parent[l]=v;
  if (r!=NIL) parent[r]=v;
}

for (i=0;i<n;i++) if(parent[i] == NIL) root=i;

setDepth(root,0);
setHeight(root);

for (i=0;i<n;i++) print(i);

return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>
#define ll long long
#define INF 1000000000
#define MOD 1
#define SIZE 100001
using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n;string s,t;
  cin>>n>>s>>t;
  for (int i=0; i<n; i++){
	  cout<<s[i]<<t[i];
  }
}


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

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	if (n % 3 == 0 || m % 3 == 0 || (n + m) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define Mod 1000000007
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
#define INF (ll)(1e17+5)
#define NN (ll)(1e6+5)
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {    
       ll n;
       cin>>n;
       cout<<(n/500)*1000+((n%500)/5)*5;
   }
}

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

// Shortcut

#define int long long
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) for (int i = 0; i < a.size(); i++) cout << a[i] << ' ';
#define PrintVl(a) for (int i = 0; i < a.size(); i++) cout << a[i] << endl;
#define PrintA(a, n) for (int i = 0; i < n; i++) cout << a[i] << ' ';
#define PrintAl(a, n) for (int i = 0; i < n; i++) cout << a[i] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

#define bend(a) a.begin(), a.end()
#define mset(a) memset(a, 0, sizeof(a));
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 2e5 + 5, mod = 1e9 + 7, inf = 1e9 + 7;


signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    int cnt = 0;
    int sum = 0, mn = inf;
    bool c = 0;
    For(i, 0, n){
        int t;
        cin >> t;
        sum += abs(t);
        if (t < 0) cnt++;
        if (t == 0) c = 1;
        mn = min(mn, abs(t));
    }
    if (cnt % 2 == 0) Ptest(sum);
    if (c) Ptest(sum);
   cout << sum - 2 * mn;
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
if n == 1:
    print(1)
    exit()
flag = [True for i in range(10**6+1)]
a.sort()
for i in range(n):
    if flag[a[i]] == False:
        continue
    if i >= 1:
        if a[i] == a[i-1]:
            continue
    for j in range(2,(10**6)//a[i]+1):
        flag[a[i]*j] = False
ans = 0
for i in range(n):
    if flag[a[i]]:
        if i >= 1:
            if a[i] == a[i-1]:
                continue
        if i < n-1:
            if a[i] == a[i+1]:
                continue
        ans+=1
print(ans)

Measured memory_bytes: 161560
import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
fun solve(N: Int, A: IntArray) {
    val dp = LongArray(N)
    dp[0] = 2L * A[N - 1]
    for (i in 1 until N) {
        dp[i] = 2L * A[i - 1] - dp[i - 1]
    }
    val a = dp[N - 1] / 2L
    for (i in 0 until N - 1) {
        if (i % 2 == 0) {
            pw.print(dp[i] - a)
        } else {
            pw.print(dp[i] + a)
        }
        pw.print(" ")
    }
    pw.println(a)
    pw.flush()
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val A = IntArray(N)
    for (i in 0 until N) {
        A[i] = sc.next().toInt()
    }
    solve(N, A)
}


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

int min2(int a,int b){
		if(a < b) return a;
		else return b;}

int main(int argc, char const *argv[]) {
	string S;
	cin >> S;
	int count0 = 0;
	int count1 = 0;
	for (int i=0; i<S.length();i=i+2){
		if(S[i]=='1') count1++;
	}
	for (int i=1;i<S.length();i=i+2){
		if(S[i]=='0') count0++;
	}
	int count = count0+count1;
	cout << min2(count, S.length()-count)<<endl;
	
}



Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int la[101010];
int p[101010];
int a[101010];
bool vis[101010];
int d[101010];
int main()
{
	int n,m,q,mi=1,cnt,lcnt,nowv,ii;
	bool mk=false;
	scanf("%d%d%d",&n,&m,&q);
	memset(la,0,sizeof(la));
	for(int i=1;i<=q;i++)
	{
		scanf("%d",&a[i]);
		p[i]=la[a[i]];
		la[a[i]]=i;
	}
	for(int i=1;i<=n;i++)
		d[i]=q+1;
	cnt=n;
	for(int i=q;i>=1;i--)
		if(a[i])
		{
			lcnt=cnt;
			cnt=0;
			nowv=a[i];
			ii=i;
			while(a[ii])
			{
				if(cnt<lcnt)
				{
					cnt++;
					if(ii<d[cnt])
						d[cnt]=ii;
					else
						cnt--;
				}
				a[ii]=0;
				ii=p[ii];
			}
			if(cnt!=n)
			{
				while(vis[mi])
					mi++;
				if(mi!=nowv)
				{
					printf("No");
					return 0;
				}
			}
			vis[nowv]=true;
		}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    int n;
    cin>>n;
    bool answer=false;
    while(n!=0){
        if(n%10==7) answer=true;
        n/=10;
    }
    if(answer) cout<<"Yes";
    else cout<<"No";

    return 0;
}


Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        int n = in.nextInt();
        int[] x = in.nextIntArray(n);
        long ans = inf;
        for (int i = 1; i <= 100; i++) {
            long cost = 0;
            for (int j = 0; j < n; j++) {
                cost += (x[j] - i) * (x[j] - i);
            }
            ans = Math.min(ans, cost);
        }
        out.println(ans);
    }

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

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private static PrintWriter out = new PrintWriter(System.out);

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
    }

    void flush() {
        out.flush();
    }
}


Measured memory_bytes: 21972
n = int(input())
tpred = 1
apred = 1

for i in range(n):
  t, a = map(int, input().split())
  tpred = t*max(-(-tpred//t), -(-apred//a))
  apred = a*max(-(-tpred//t), -(-apred//a))

print(tpred+apred)

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

const int MAX = 1e6+10;
const int INF = 0x3fffffff;
const int MOD = 1e9+7;
int a[MAX];

int n;
bool check(){
	if(a[1]==0){
		for(int i=2;i<=n;){
			if(a[i]!=a[i+1])
				return false;
			i+=2;
		}
	}
	else{
		for(int i=1;i<=n;){
			if(a[i]!=a[i+1])
				return false;
			i+=2;
		}
	}
	return true;
}
int Pow(int a,int n)
{
	if(n==0) 
		return 1;
	int temp=Pow(a,n/2);
	LL ans=(long long)temp*temp%MOD;
	if(n%2==1) ans=ans*a%MOD;
	return ans;
}
int main(){
	while(scanf("%d",&n)!=EOF){
		memset(a,0,sizeof(a));
		//int flag=1;
		int num=0;
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			if(a[i]==0)	num++;
		}
		sort(a+1,a+n+1);
		if(num==2||n%2==0&&num>0||!check())
			printf("0\n");
		else 
		{
			if(num==1){
				n--;
				n/=2;
			}
			else
				n/=2;
			int ans=Pow(2,n);
			printf("%d\n",ans);
		}
	}
	return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

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

int main(){

    bool flag=false;
    ll ans=0,sum=1;

    ll n;
    cin>>n;

    ll p = n;
    vector<ll> divis1;

    rep1(i,2,sqrt(p)+1){
        if(p%i==0){
            divis1.emplace_back(i);
            if(i!=p/i)divis1.emplace_back(p/i);
        }
    }
    divis1.emplace_back(p);

    p=n-1;
    rep1(i,2,sqrt(p)+1){
        if(p%i==0){
            divis1.emplace_back(i);
            if(i!=p/i)divis1.emplace_back(p/i);
        }
    }
    if(p!=1)divis1.emplace_back(p);

    
    for(ll can:divis1){
        ll c=n;
        while(c%can==0)c/=can;
        if(c%can==1){
            ans++;
            //db(can);ln;
        }
    }

    cout<<ans<<endl;
    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 384
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main()
{
    int n, k;
    cin >> n >> k;
    auto a = vector<int>(n);
    for (auto& a_i : a)
        cin >> a_i;

    auto i = 0;
    for (auto j = k; j < n; ++j, ++i) {
        cout << (a[i] < a[j] ? "Yes" : "No") << "\n";
    }

    return 0;
}


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

#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define rep(i, n) FOR(i, 0, n)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll INF = 1e18;
const ll MOD = 1e9+7;
//const ll MOD 998244353;
const ll MAX_N = 305;

ll d[MAX_N][MAX_N] = {};
ll dd[MAX_N][MAX_N] = {};

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

	rep(i, n) rep(j, n) d[i][j] = INF;
	rep(i, n) d[i][i] = 0;

	rep(i, m){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		d[a][b] = c;
		d[b][a] = c;
	}

	rep(k, n) rep(i, n) rep(j, n) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
	rep(i, n) rep(j, n){
		if(d[i][j] <= l) dd[i][j] = 1;
		else dd[i][j] = INF;
	}
	rep(i, n) dd[i][i] = 0;
	rep(k, n) rep(i, n) rep(j, n) dd[i][j] = min(dd[i][j], dd[i][k]+dd[k][j]);

	int q;
	cin >> q;
	rep(i, q){
		int s, t;
		cin >> s >> t;
		s--; t--;
		if(dd[s][t] != INF) co(dd[s][t]-1);
		else co(-1);
	}

	return 0;
}


Measured memory_bytes: 1920
import java.util.Scanner;

/**
 * https://abc044.contest.atcoder.jp/tasks/arc060_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long s = sc.nextLong();
		sc.close();
		
		long ans = -1;
		if(s==n){
			ans = n+1;
		}
		long sqrt = (long)Math.sqrt(n);
		if(ans==-1){
			for(long b=2; b<=sqrt; b++){
				if(s==compute(n,b)){
					ans = b;
					break;
				}
			}
		}
		
		if(ans==-1){
			for(long p=sqrt; p>=1; p--){
				long b = (n-s+p)/p;
				if(b>=2 && s==compute(n,b)){
					ans = b;
					break;
				}
			}	
		}
		System.out.println(ans);
	}

	private static long compute(long n, long b) {
		long sum = 0;
		while(n>0){
			sum += n%b;
			n = n/b;
		}
		return sum;
	}

}


Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#define ll long long
#define INF 0x3f3f3f3f
#define SIS std::ios::sync_with_stdio(false)
using namespace std;
ll fast_pow(ll a,ll b,ll mod)
{
    ll c=1;
    while(b>=2)
    {
        if(b%2==0)
            a*=a,b/=2;
        else
            c*=a,a*=a,b--,b/=2;
        a%=mod,c%=mod;
    }
    return (a*c)%mod;
}
bool judge(int l,int r);
string s;
int main()
{
    while(cin>>s)
    {
        int len=s.size();
        if(judge(0,len-1)&&judge(0,(len-1)/2-1)&&judge((len+3)/2-1,len-1))
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}

bool judge(int l,int r)
{
    while(l<=r)
    {
        if(s[l]!=s[r])
            return false;
        r--,l++;
    }
    return true;
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: isize = iterator.next().unwrap().parse().unwrap();
    let op = iterator.next().unwrap();
    let b: isize = iterator.next().unwrap().parse().unwrap();

    if op == "+" {
        (a + b).to_string()
    } else {
        (a - b).to_string()
    }
}


Measured memory_bytes: 2144
package main

import (
    "bufio"
    "fmt"
    "os"
    "math"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
    defer writer.Flush()
    var a, b, h, m int
    scanf("%v %v %v %v\n", &a, &b, &h, &m)
    x := float64(360) / float64(12 * 60) * float64(h * 60 + m)
    y := float64(360 / 60 * m)
    delta := math.Abs(x - y)
    degrees := delta
    if delta == 180 {
        printf("%v\n", a + b)
        return
    } else if delta > 180 {
        degrees = 360 - delta
    }
    ans := math.Sqrt(math.Pow(float64(a), 2) + math.Pow(float64(b), 2) - float64(2)*(float64(a)*float64(b)*math.Cos(degrees*math.Pi/180)))
    printf("%v\n", ans)
}

Measured memory_bytes: 1832
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vvl G;
vl visited;

void dfs(ll v) {
    visited[v] = 1;
    for(auto u : G[v]) { 
        if(visited[u]) {
            continue;
        }
        dfs(u);
    }
}

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

    G.resize(n);
    rep(i, m) {
        ll x, y, z;
        cin >> x >> y >> z;
        x--;  y--;
        G[x].pb(y);
        G[y].pb(x);
    }
    
    visited.assign(n, 0);
    ll renketuseibun = 0;
    rep(v, n) {
        if(visited[v]) {
            continue;
        } 
        dfs(v);
        renketuseibun++;
    }
    
    out(renketuseibun);
    re0;
}

Measured memory_bytes: 9600
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
from argparse import ArgumentParser

args=ArgumentParser()
args.add_argument('-loc', '--local', type=bool,default=False)
LOCAL=args.parse_args().local

def input(): 
    x=sys.stdin.readline(); 
    if x[-1]=="\n": 
        return x.rstrip() 
    return x
    
def printe(*x):_=print("## ",*x,file=sys.stderr) if LOCAL else 0
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    sa=sum(A)%mod
    sa2=0
    for a in A:
        sa2+=a**2
        sa2%=mod
    i2=pow(2,mod-2,mod)
    print((sa**2-sa2)%mod*i2%mod)


if __name__ == "__main__":
    main()

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

#define MAX 2000001 //2 * 10^6 ここを最低限にしておかないと絶対にいらない計算をやっちゃう
#define MOD 1000000007

using namespace std;

long fac[MAX];
long finv[MAX];

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

void fac_table(){
    fac[0] = 1;
    for(int i=1; i<MAX; i++){
        fac[i] = fac[i-1] * i;
        fac[i] %= MOD;
    }
}

long comb(int n, int k){
    long c = fac[n];
    c *= modinv(fac[k], MOD); c %= MOD;
    c *= modinv(fac[n-k], MOD); c %= MOD;
    return c;
}

int main(){
    long n, k;
    cin >> n >> k;
    fac_table();
    long ans = 0;
    for(long i=0; i<=min(n, k); i++){
        ans += comb(n-1, i) * comb(n, i) ;
        ans %= MOD;
        //cout << comb(n-1, i) * comb(n, i)  << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17152
#include<stdio.h>
long gcdf(long a,long b){
  long p = a;
  long q = b;
  long c = 0;
  c = p%q;
  while(c != 0){
    p = q;
    q = c;
    c = p%q;
  }
  return q;
}

int main(){
  int n = 0;
  long a[100000] = {};
  int i = 0;
  long lgcd[100000] = {};
  long rgcd[100000] = {};
  long r = 0;
  long max = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);
  }
  //printf("%ld",gcdf(24,16));
  for(i=0;i<n;i++){
    if(i==0){
      lgcd[i]= -1;
    }else if(i==1){
      lgcd[i] = a[0];
    }else{
      lgcd[i] = gcdf(a[i-1],lgcd[i-1]);
    }
  }
  /*for(i=0;i<n;i++){
    printf("%ld/",lgcd[i]);
  }*/
  for(i=0;i<n;i++){
    if(i==0){
      rgcd[n-1-i]= -1;
    }else if(i==1){
      rgcd[n-1-i] = a[n-1];
    }else{
      rgcd[n-1-i] = gcdf(a[n-i],rgcd[n-i]);
    }
  } 
  
  /*for(i=0;i<n;i++){
    printf("%ld/",rgcd[i]);
  }*/
  
  for(i=0;i<n;i++){
    if(lgcd[i] == -1){
      r = rgcd[i];
    }else if(rgcd[i] == -1){
      r = lgcd[i];
    }else{
      r = gcdf(lgcd[i],rgcd[i]);
    }
    
    if(r > max){
      max = r;
    }
  }
  printf("%ld",max);
  return 0;
}
             
      
      

Measured memory_bytes: 2560
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

def main():
	N = INT()
	A = [LIST() for _ in range(N)]

	match = defaultdict(int)
	cnt = 0
	for i, j in combinations(range(N), 2):
		match[(i, j)] = cnt
		match[(j, i)] = cnt
		cnt += 1

	V = N*(N-1)//2
	graph = [[] for _ in range(V)]
	dag = [0]*V

	for i in range(N):
		for j in range(N-2):
			graph[match[(i, A[i][j]-1)]].append(match[(i, A[i][j+1]-1)])
			dag[match[(i, A[i][j+1]-1)]] += 1

	q = deque([i for i in range(V) if dag[i] == 0])
	day = [1]*V
	while q:
		p = q.popleft()
		for v in graph[p]:
			dag[v] -= 1
			if dag[v] == 0:
				day[v] = day[p]+1
				q.append(v)

	if any(dag):
		print(-1)
	else:
		print(max(day))

if __name__ == '__main__':
	main()




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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  for (int i = 0; i < K; i++){
    if (A >= B) B *= 2;
    else if (B >= C) C *= 2;
  }
  
  if (A < B && B < C) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main() {
  for (int i = 0; i < 5; i++) {
    int a;
    cin >> a;
    if (a == 0) {
      cout << (i + 1) << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

int a[100003], b[100003];
bool used[100003];

int main() {
	int n, m; cin >> n >> m;
	int cnt[100003] = {};
	for (int i = 0; i < m; ++i) {
		cin >> a[i] >> b[i];
		--a[i]; --b[i];
		++cnt[a[i]]; ++cnt[b[i]];
	}
	bool flag = true;
	for (int i = 0; i < n; ++i) flag &= cnt[i]%2 == 0;
	cout << (flag ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 1408
//g++  5.4.0

#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
int main(void)
{
    ll n,m;
    cin>>n>>m;
    vector<pair<ll,ll>> map;
    for(ll i=0;i<n;++i)
    {
        ll a,b;
        cin>>a>>b;
        map.pb(mp(a,b));
    }
    sort(map.begin(),map.end());
    ll money=0;
    ll num=m;
    for(ll i=0;i<n;++i)
    {
        if(map[i].s<num)
        {
            money+=(map[i].s*map[i].f);
            //cout<<map[i].f<<" "<<map[i].s<<" "<<money<<"\n";
            num-=map[i].s;
        }
        else
        {
            money+=(num*map[i].f);
            //cout<<map[i].f<<" "<<map[i].s<<"\n";
            break;
        }
    }
    cout<<money;
    return 0;
}

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

ll a[200005], f[200005];

int main(){

    ll n, k; cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= n; i++)
        cin >> f[i];

    sort(a+1, a+1+n); reverse(a+1, a+1+n);
    sort(f+1, f+1+n);
    
    ll esq = 0, dir = 1e13, res = 1e18;
    while(esq <= dir){
        ll mid = (esq+dir)/2;
        ll sum = 0;
        for(int i = 1; i <= n; i++){
            if(a[i]*f[i] > mid)
                sum += (a[i] - mid/f[i]);
        }
        if(sum <= k){
            res = min(res, mid);
            dir = mid-1;
        }
        else esq = mid+1;
    }
    cout << res << endl;
	return 0;
}

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

int main(void) {
    int n;
    std::cin >> n;

    std::vector<int> vec_a{};
    for (int i = 0; i < n; ++i) {
        int a;
        std::cin >> a;
        vec_a.push_back(a);
    }

    int m;
    std::cin >> m;

    std::vector<int> vec_b{};
    for (int j = 0; j < m; ++j) {
        int b;
        std::cin >> b;
        vec_b.push_back(b);
    }

    if (std::lexicographical_compare(vec_a.begin(), vec_a.end(), vec_b.begin(),
                                     vec_b.end()))
        std::cout << 1 << std::endl;
    else
        std::cout << 0 << std::endl;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define ll long long
using namespace std;
const int N=1e5+5;
int n,m,x,y,a[N],b[N],w[N],f[N];
vector<int>e[N];
ll s[N],g[N];
bool ex[N];
bool cmp(int x,int y){return a[x]<a[y];}
int F(int x){return x==f[x]?x:f[x]=F(f[x]);}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	fo(i,1,n)cin>>a[i]>>b[i],a[i]=max(a[i]-b[i],0),w[i]=f[i]=i;
	fo(i,1,m)cin>>x>>y,e[x].push_back(y),e[y].push_back(x);
	sort(w+1,w+n+1,cmp);
	fo(i,1,n){
		int x=w[i],leaf=1;ex[x]=1;
		s[x]=b[x];
		g[x]=1e18;
		for(int j:e[x])if(ex[j]&&F(j)!=x){
			int y=f[j];
			f[y]=x;
			s[x]+=s[y];
			g[x]=min(g[x],max(g[y],-s[y]+a[x]));
			leaf=0;
		}
		if(leaf)g[x]=a[x];
	}
	cout<<g[w[n]]+s[w[n]];
}

Measured memory_bytes: 9212
from typing import List


def answer(n: int, k: int, l: List[int]) -> int:
    l.sort(reverse=True)
    return sum(l[:k])


def main():
    n, k = map(int, input().split())
    l = list(map(int, input().split()))
    print(answer(n, k, l))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10252
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

// Convex Hull Trick for min query
template<typename T, typename U=__int128>
class ConvexHullTrick {
private:
  deque<pair<T,T>> data;
  bool check(const pair<T,T> &p3) const {
    auto &p1 = data[data.size()-2];
    auto &p2 = data[data.size()-1];
    return (U)(p2.first-p1.first)*(p3.second-p2.second) < (U)(p2.second-p1.second)*(p3.first-p2.first);
  }
public:
  ConvexHullTrick(){ }
  // add line ax + b
  // additions of 'a' shold be given in NON-INCREASING order
  void add(T a, T b){
    auto p = make_pair(a, b);
    while(data.size()>=2 && !check(p)) data.pop_back();
    data.push_back(p);
  }
  // get value of i-th data in deque with x
  inline T val(int i, T x) const {
    return data[i].first*x + data[i].second;
  }
  // get minimun value of query x
  // queries shold be given in NON-DECREASING order
  T query(T x){
    while(data.size()>=2 && val(0, x) >= val(1, x)) data.pop_front();
    return val(0, x);
  }
  inline bool empty(){
    return data.empty();
  }
};

int main(){
  int n;long c;
  cin>>n>>c;
  vector<long> h(n);
  rep(i,n) cin>>h[i];

  ConvexHullTrick<long> cht;
  vector<long> dp(n,0);
  cht.add(-2*h[0], h[0]*h[0]);
  rep(i,1,n){
    dp[i] = h[i]*h[i] + c + cht.query(h[i]);
    cht.add(-2*h[i], dp[i]+h[i]*h[i]);
  }

  cout << dp[n-1] << endl;

  return 0;
}


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

int cnt[101010];

int main(){
  int N,K; cin>>N>>K;
  vector<pair<int,int>> V(N);
  rep(i,N){
    int T,D; cin>>T>>D;
    V[i]={D,T};
  }
  sort(V.rbegin(),V.rend());
  int k=0;
  ll sum=0;
  priority_queue<pair<int,int>> pq;
  rep(i,K){
    if(cnt[V[i].second]==0) k++;
    cnt[V[i].second]++;
    sum+=1LL*V[i].first;
    pq.push({-V[i].first,V[i].second});
  }
  ll ans=sum+1LL*k*k;
  int l=K;
  for(int i=k+1;i<=K;i++){
    while(cnt[pq.top().second]<=1&&pq.size()){
      pq.pop();
    }
    if(pq.size()==0) break;
    pair<int,int> p=pq.top(); pq.pop();
    sum+=p.first;
    cnt[p.second]--;
    while(cnt[V[l].second]>=1&&l<N) l++;
    if(l>=N) break;
    sum+=V[l].first;
    cnt[V[l++].second]++;
    ans=max(ans,sum+1LL*i*i);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2552
#include "iomanip"
#include "algorithm"
#include "iostream"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
void drop(const T& x) {
  cout << x << endl;
  exit(0);
}

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

  ll N;
  cin >> N;
  V<ll> as(N);
  for (auto& a : as) cin >> a;

  sort(all(as));

  rep(i, N - 1) {
    if (as[i] == as[i + 1]) {
      drop("NO");
    }
  }

  cout << "YES" << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
long long N;
long double eps  = 1e-12;
 
int main(){
  long double xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt;
  int n; cin >> n; pair<pair<int, int>, long double>p[n+2];
  rep(i, n){
    long double a, b, c; cin >> a >> b >> c; p[i+1] = {{a, b}, c};
  }
  p[0] = {{xs, ys}, (long double)0.0};
  p[n+1] = {{xt, yt}, (long double)0.0};
  vector<pair<int, long double>>to[n];
  long double dist[n+2][n+2];
  rep(i, n+2){
    rep(j, n+2){
      if(i==j) continue;
      long double diffx, diffy;
      diffx = p[i].first.first - p[j].first.first;
      diffy = p[i].first.second - p[j].first.second;
      dist[i][j] = max(sqrt(diffx*diffx+diffy*diffy)-p[i].second-p[j].second, (long double)0.0);
    }
  }
  priority_queue<pair<long double, int>, vector<pair<long double, int>>, greater<pair<long double, int>>>pq; long double dp[n+2];
  rep(i, n+2) dp[i] = longinf;
  dp[0] = 0.0;
  pq.push({0.0, 0});
  while(!pq.empty()){
    auto k = pq.top(); pq.pop();
    long double f = k.first; int s = k.second;
    if(dp[s]+eps<f) continue;
    rep(i, n+2){
      if(dp[i]>dp[s]+dist[s][i]+eps){
        dp[i]=dp[s]+dist[s][i];
        pq.push({dp[i], i});
      }
    }
  }
  cout<< fixed << setprecision(14) << dp[n+1] << endl;
}

Measured memory_bytes: 27460