akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>

#define repd(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

int main(){
	//source
	string n;
	cin >>n;
	rep(i,n.size()){
		if(n[i]=='1'){
			n[i]='9';
		}else if(n[i]=='9'){
			n[i]='1';
		}
	}
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 2000000
void maxHeapify(int);
int B;
int A[MAX+1];
int main(){
  int i;
  cin >> B;
  for(i = 1; i <= B;i++){
    cin >> A[i];
  }
  for(i = B/2; i >= 1; i--){
    maxHeapify(i);
  }
  for(i = 1; i <=B; i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

void maxHeapify(int i){
  int right,left,largest;
  left = 2*i;
  right = (2*i)+1;
  if(left <= B && A[left] > A[i]){
    largest = left;
  }
  else{
    largest = i;
  }
  if(right <= B && A[right] > A[largest]){
    largest = right;
  }
  if(largest != i){
    swap(A[i],A[largest]);
    maxHeapify(largest);
  }
}

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

int main()
{
  ll a,b;
  cin>>a>>b;
  ll c[b];
  map<ll,ll> mp;
  for(ll i=0;i<b;i++)
  {
    cin>>c[i];
  	mp[c[i]]++;
  }
  ll maxm=1000,ans;
  if(b==0)
    cout<<a<<endl;
  else
  {
 for(ll i=-2;i<=103;i++)
 {
   if(mp[i]==0)
   {
     if(maxm>abs(a-i))
     {
       maxm=abs(a-i);
       ans=i;
     }
   }
 }
  cout<<ans<<endl;
  }
}
     
  
  


Measured memory_bytes: 3636
from itertools import accumulate as ac
n=int(input())+2
t=[0]+list(map(int,input().split()))+[0]
v=[0]+list(map(int,input().split()))+[0]
s=[0]+list(ac(t))
def f(i,x):
    if s[i]<=x<=s[i+1]:return v[i]
    elif x<s[i]:return v[i]+s[i]-x
    else:return v[i]+x-s[i+1]
c=float("INF")
for i in range(n):
    c=min(c,f(i,0))
e=0
for i in range(1,2*s[-1]+1):
    i=i/2
    d=float("INF")
    for j in range(n):
        d=min(d,f(j,i))
    e+=0.25*(c+d)
    c=d
print(e)

Measured memory_bytes: 44012
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;


int main(void){
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    int num1=0,num2=0;
    for(int i=0;i<h;i++){
        if(num1<b){
            num2=0;
            for(int j=0;j<w;j++){
                if(num2<a){
                    cout<<0;
                    num2++;
                }
                else cout<<1;
            }
            cout<<endl;
        }
        else{
            num2=0;
            for(int j=0;j<w;j++){
                if(num2<a){
                    cout<<1;
                    num2++;
                }
                else cout<<0;
            }
            cout<<endl;
        }
        num1++;
    }
    return 0;
}

Measured memory_bytes: 1280
n, a, b = map(int, input().split())
s = input()
tukasha = 0
kaigai_tukasha = 0
for i in range(n):
    if s[i] == 'a' and tukasha < a + b:
        print('Yes')
        tukasha += 1
    elif s[i] == 'b' and tukasha < a + b and kaigai_tukasha < b:
        print('Yes')
        tukasha += 1
        kaigai_tukasha += 1
    else:
        print('No')

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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, S) = Slice2<long>();
            var Ai = Sarray();
            var dp = new long[N + 1, S + 1];
            dp[0, 0] = 1;
            for (var i = 0; i < N; ++i)
            {
                for (var j = 0; j <= S; ++j)
                {
                    //選ばない場合。フリー要素が増えるので2倍になる
                    dp[i + 1, j] = (dp[i + 1, j] + 2 * dp[i, j] % Mod) % Mod;
                    //選ぶ場合。フリー要素は増えない
                    if (j + Ai[i] <= S)
                        dp[i + 1, j + Ai[i]] = (dp[i + 1, j + Ai[i]] + dp[i, j]) % Mod;
                }
            }
            WriteLine(dp[N, S]);
        }
        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 99528
#include<bits/stdc++.h>
using namespace std;
long long n,a[100010],dp[100010],k;
long long Abs(long long u)
{
    if(u>0) return u;
    else return u*(-1);
}
int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
    }
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        dp[i]=LONG_LONG_MAX;
    }
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(j>=i) break;
            if((dp[i]>dp[i-j]+Abs(a[i]-a[i-j]))) dp[i]=dp[i-j]+Abs(a[i]-a[i-j]);
        }
    }
    printf("%lld",dp[n]);
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i,n) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end(), greater<int>());
  int a = 0;
  int b = 0;
  rep(i,n) {
    if (i%2 == 0) a += A.at(i);
    else b += A.at(i);
  }
  cout << a - b << endl;
}

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

int main(void) {
  int N;
  cin >> N;
  vector<int64_t> B(N-1);
  for (int i = 0; i < N-1; i++) cin >> B.at(i);
  int64_t sum = 0;
  sum += B.at(0) + B.at(N-2);
  for (int i = 0; i < N-2; i++) {
    sum += min(B.at(i), B.at(i+1));
  }
  cout << sum << endl;
}

Measured memory_bytes: 3624
n = int(input())
ans, ba, xa, bx = 0, 0, 0, 0

for i in range(n):
    s = input()
    ans += s.count("AB")
    if s[0] == "B" and s[-1] == "A":
        ba += 1
    if s[0] == "B" and s[-1] != "A":
        bx += 1
    if s[0] != "B" and s[-1] == "A":
        xa += 1

if xa == 0 and bx == 0:
    ans += max(0, ba-1)
else:
    ans += ba
    ans += min(xa, bx)

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
const int mod=998244353;
int n,m;
string s;
map<string,int> ma;
void merge(string &a,string b)
{
	int len=a.length();
	for(int i=0;i<len;i++) if(b[i]=='0') a[i]='0';
}
int dp(string s)
{
	if(s.empty()) return 1;
	if(ma.count(s)) return ma[s];
	int ans=0,n=s.length();
	ans=(ans+((s[0]=='1')?2ll:1ll)*dp(s.substr(1,n)))%mod;
	for(int i=1;2*i<=n;i++)
	{
		string cur=s.substr(0,i);
		for(int j=2;i*j<=n;j++)
		{
			merge(cur,s.substr(i*(j-1),i*j));
			ans=(ans+1ll*dp(cur)*dp(s.substr(i*j,n))%mod)%mod;
		}
	}
	return ma[s]=ans;
}
int main()
{
	cin>>s;
	cout<<dp(s)<<endl;
}

Measured memory_bytes: 7936
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int len_s=s.size(),len_t=t.size();
    int ans=100000;
    for(int i=0; i<=len_s-len_t; i++){
        int p1=i,p2,cnt=0;
        for(p2=0; p2<len_t; p2++,p1++){
            if(s[p1]!=t[p2])cnt++;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3228
/*
 © 2020-09-19 08:02:22 Franco1010 All Rights Reserved
*/

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;

int main(){ _
  lli n, x, m; cin >> n >> x >> m;
  vector<lli> v = {x};
  vector<lli> vv;
  set<lli> st = {x};
  lli res = x;
  n--;
  while(n--){
    x = (x * x) % m;
    if(st.count(x)){
      n++;
      bool yes = false;
      fore(i, 0, sz(v)){
        if(v[i] == x) yes = true;
        if(yes) vv.pb(v[i]);
      }
      break;
    }
    st.insert(x);
    v.pb(x);
    res += x;
    if(x == 0){
      cout << res << ENDL;
      return 0;
    }
  }
  if(!vv.empty()){
    fore(i, 1, sz(vv)) vv[i] += vv[i - 1];
    res += vv.back() * (n / sz(vv));
    n -= sz(vv) * (n / sz(vv));
    if(n and n % sz(vv)) res += vv[n % sz(vv) - 1];
  }
  cout << res << ENDL;
  return 0;
}


Measured memory_bytes: 6672
#include"iostream"
#include"cstdio"
#include"cmath"
#include"cstring"
#include"algorithm"
#include"stack"
#include"queue"
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long 
#define ull unsigned long long
#define MAXN 3005 

char s[1005],t[1005];
int ss[1005],tt[1005];
int ans=0x7fffffff,now;

int main()
{
	//cin>>s>>t;
	scanf("%s%s",s,t);
	int lens=strlen(s),lent=strlen(t);
	for(int i=0;i<lens;i++) ss[i]=s[i]-'0';
	for(int i=0;i<lent;i++) tt[i]=t[i]-'0';
	for(int i=0;i<=lens-lent;i++)
	{
		now=0;
		for(int j=0;j<lent;j++)
		{
			if(ss[i+j]!=tt[j])
			{
				now++;
			}
		}
		ans=min(ans,now);
	}
	printf("%d\n",ans);
	return 0;
} 
/*

*/

Measured memory_bytes: 3832
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <assert.h>
typedef int64_t ll;
typedef uint64_t ull;
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (200001)
#define MOD (1000000007)

int main(void)
{
    ll x,a;
    scanf("%ld %ld",&x,&a);

    if(x<a)
    {
        printf("0\n");
    }else
    {
        printf("10\n");
    }
    
    return 0;
}


Measured memory_bytes: 128
//
// Created by 李青坪 on 2018/12/3.
//

#include <cmath>
#include <cstdio>
#include <algorithm>

#define EPSLON 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPSLON)

#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK -2
#define ONLINE_FRONT 2
#define ON_SEGMENT 0
using namespace std;

// 点
class Point {
public:
    double x;
    double y;

    Point() {}

    Point(double x, double y) : x(x), y(y) {}

    Point operator+(Point a) {
        return Point(x + a.x, y + a.y);
    }

    Point operator-(Point a) {
        return Point(x - a.x, y - a.y);
    }

    Point operator*(double a) {
        return Point(x * a, y * a);
    }

    Point operator/(double a) {
        return Point(x / a, y / a);
    }

    double norm() {
        return x * x + y * y;
    }

    double absVector() {
        return sqrt(norm());
    }

    bool operator==(Point a) const {
        return equals(x, a.x) && equals(y, a.y);
    }
};

typedef Point Vector;

// 线段
class Segment {
public:
    Point a, b;
};

typedef Segment Line;

double dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
    return a.x * b.y - a.y * b.x;
}

int ccw(Segment s, Point p) {
    Vector v1 = s.b - s.a;
    Vector v2 = p - s.a;
    if (cross(v1, v2) > 0) return COUNTER_CLOCKWISE;
    if (cross(v1, v2) < 0) return CLOCKWISE;
    if (dot(v1, v2) < 0) return ONLINE_BACK;
    if (v1.norm() < v2.norm()) return ONLINE_FRONT;
    return ON_SEGMENT;
}

bool intersection(Segment s1, Segment s2){
    return (ccw(s1, s2.a) * ccw(s1, s2.b) <= 0 && ccw(s2, s1.a) * ccw(s2, s1.b) <= 0);
}


int n;


int main() {
    Segment s[2];
    Point p[4];
    scanf("%d", &n);
    Point point;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 4; ++j) {
            double x, y;
            scanf("%lf %lf", &x, &y);
            point = Point(x, y);
            p[j] = point;
        }
        s[0].a = p[0];
        s[0].b = p[1];
        s[1].a = p[2];
        s[1].b = p[3];
        printf("%d\n", intersection(s[0], s[1]));
    }
}


Measured memory_bytes: 2756
#include <map>
#include <string>
#include <iostream>
#include <vector>
#include <set>
#include <cstdio>
#include <stack>
#include <algorithm>

using namespace std;

int main()
{
	int num;
	stack<int> nums;
	
	while (cin >> num)
	{
		if (num == 0)
		{
			cout << nums.top() << endl;
			nums.pop();
		} else {
			nums.push(num);
		}
	}
}

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


int main()
{
	string s; cin >> s;
	bool ok = true;
	if (s[0] != 'A') ok = false;
	int c = 0;
	for (int i = 2; i < s.size()-1; ++i)
		if (s[i] == 'C') c++;
	if (c != 1) ok = false;
	int d = 0;
	for (int i = 0; i < s.size(); ++i)
		if (s[i] < 97) d++;
	if (d != 2) ok = false;
	cout << (ok ? "AC" : "WA") << endl;
}



Measured memory_bytes: 3616
n, m = [int(e) for e in input().split()]
a = set(int(input()) for i in range(m))
t = [0] * (n + 2)
t[0] = 1
for i in range(n):
  if i in a:
    t[i] = 0
  else:
    t[i + 1] = (t[i + 1] + t[i]) % 1000000007
    t[i + 2] = (t[i + 2] + t[i]) % 1000000007
print(t[n])


Measured memory_bytes: 11884
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
int main(){
  ll kazu = 0;
  cin >> kazu;
  vector<ll> a(kazu);
  for(int i = 0;i <= kazu - 1;i++){
    cin >> a[i];
  }
  ll kotae = 0;
  for(int i = 0;i <= 59;i++){
    ll count = 0;
    for(int j = 0;j <= kazu - 1;j++){
      if(a[j] & (1LL<<i)){
        count++;
      }
    }
    ll syoukei = (1LL << i) % mod;
    syoukei = syoukei * count,syoukei %= mod;
    syoukei = syoukei * (kazu - count), syoukei %= mod;
    //cout << count << " " << syoukei << endl; 
    kotae = kotae + syoukei, kotae %= mod;
  }
  cout << kotae << endl;
  return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int n;
int h[101000],k;
ll dp[100100];

void input(){
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>h[i];
	return;
}

void solve(){
	for(int i=0;i<=n;i++)dp[i]=INF;
	dp[0]=0;
	for(int i=0;i<n-1;i++){
		for(int j=1;j+i<n&&j<=k;j++){
			dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
		}
	}
	cout<<dp[n-1]<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}

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

#define ll long long
#define all(it) it.begin(), it.end()
#define FOR(i, n) for(int i = 0; i < n; i++)
#define FORU(i, a, b, s) for(int i = a; i < b; i += s)
#define FORD(i, a, b, s) for(int i = a; i > b; i -= s)
#define endl "\n"
ll INF = 2e18;
ll MOD = 1e9 + 7;

int i, j, k, t;

int main() {
    int N;
    cin >> N;

    unordered_map<int, bool> m;
    FOR(i, N) {
        cin >> t;
        if(m.find(t) == m.end()) {
            m[t] = true;
        } else {
            m.erase(t);
        }
    }
    cout << distance(all(m)) << endl;
}

Measured memory_bytes: 7208
dict={}
n=int(input())
cnt=0
ans=[]
for i in range(n):
    str=list(input().split())
    if str[0]=='insert':
        dict[str[1]]=cnt
        cnt+=1

    if str[0]=='find':
        if str[1] in dict:
            print("yes")
        else:
            print("no")


Measured memory_bytes: 41816
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;

class Puzzle
{
public:

	int N, x;
	//vector<int> As;
	map<int,int> As;


	void input()
	{
		cin >> N >> x;

		int a;
		for (int ni = 0; ni < N; ni++) {
			cin >> a;
			if (As.count(a) == 0) {
				As[a] = 1;
			}
			else {
				As[a]++;
			}
		}

	}


	void play()
	{
		int ans = 0;
		int cnt = 0;
		int remain = x;
		for (auto a : As) {
			if (a.first * a.second <= remain) {
				ans += a.second;
				remain -= a.first * a.second;
			}
			else {
				ans += remain / a.first;
				remain = 0;
				break;
			}
		}
		if (remain > 0) ans--;

		cout << ans;
		return;

	}
};


int main()
{
	Puzzle puz;

	puz.input();
	puz.play();

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}
 
 
int n, M, powers[5005];
ll dist[5005], arr[5005][205], ans[5005], best_coupon[202], sparse[202][20][5005];
 
ll rmq(int j, int l, int r){
    int k = powers[r-l+1];
    return max(sparse[j][k][l], sparse[j][k][r-(1<<k)+1]);
}
 
 
void DnC(int l, int r, int optima_l, int optima_r){
 
    if(l > r)   return;
 
    int mid = (l+r)/2, optima_mid = -1;
    ans[mid] = -(ll)1e16;
 
    for(int j=1;j<=M;j++)
        best_coupon[j] = rmq(j, mid, max(optima_l, mid));
 
// cout<<"now at "<<l<<" "<<r<<" "<<optima_l<<" "<<optima_r<<endl;
// cout<<"best_coupon: ";for(int j=1;j<=M;j++) cout<<best_coupon[j]<<" ";cout<<endl;
 
    for(int k=max(optima_l, mid);k<=optima_r;k++){
 
        ll temp = -(dist[k]-dist[mid]);
        for(int j=1;j<=M;j++){
            best_coupon[j] = max(best_coupon[j], arr[k][j]);
            temp += best_coupon[j];
        }
 
        if(temp > ans[mid]){
            ans[mid] = temp;
            optima_mid = k;
        }
    }
 
// cout<<"for "<<l<<" "<<r<<" "<<optima_l<<" "<<optima_r<<" found "<<mid<<" "<<optima_mid<<endl;
 
    DnC(l, mid-1, optima_l, optima_mid);
    DnC(mid+1, r, optima_mid, optima_r);
}
 
 
 
int main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    //http://codeforces.com/blog/entry/49757?#comment-337424
 
    cin>>n>>M;
    dist[1] = 0;
    for(int i=2;i<=n;i++){
        cin>>dist[i];
        dist[i] += dist[i-1];
    }
 
    for(int i=2;i<=5000;i*=2)
        powers[i]++;
    for(int i=1;i<=5000;i++)
        powers[i] += powers[i-1];
 
    for(int i=1;i<=n;i++)
        for(int j=1;j<=M;j++){
            cin>>arr[i][j];
            sparse[j][0][i] = arr[i][j];
        }
 
    for(int j=1;j<=M;j++)
        for(int k=1;(1<<k)<=n;k++)
            for(int i=1;i+(1<<k)-1<=n;i++)
                sparse[j][k][i] = max(sparse[j][k-1][i], sparse[j][k-1][i+(1<<(k-1))]);
 
    //optimas are monotonous
    //if (i, j1) and (i+1, j2) are optimal solutions for i and i+1 respectively
    //then j2 >= j1
 
    DnC(1, n, 1, n);
 
// cout<<"ans: ";for(int i=1;i<=n;i++) cout<<ans[i]<<" ";cout<<endl;
 
    cout<<*max_element(ans+1, ans+n+1);
    return 0;
}

Measured memory_bytes: 165248
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		long k = Long.parseLong(sa[1]);
		sa = br.readLine().split(" ");
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sa[i]);
		}
		br.close();

		Arrays.parallelSort(a);
		long ng = -1000000000000000000L;
		long ok = 1000000000000000001L;

		while (Math.abs(ok - ng) > 1) {
			long mid = (ok + ng) / 2;
			long cnt = 0;
			for (int i = 0; i < a.length; i++) {
				int c = calc(a, i, mid);
				cnt += c;
			}
			cnt /= 2;
			if (cnt < k) {
				ng = mid;
			} else {
				ok = mid;
			}
		}
		System.out.println(ok);
	}

	static int calc(long[] a, int i, long mid) {
		if (mid >= 0 && a[i] >= 0 ||
				mid < 0 && a[i] > 0) {
			int ok = -1;
			int ng = a.length;

			while (Math.abs(ng - ok) > 1) {
				int m = (ng + ok) / 2;
				if (a[m] * a[i] <= mid) {
					ok = m;
				} else {
					ng = m;
				}
			}
			if (ng > i) {
				return ng - 1;
			} else {
				return ng;
			}

		} else {
			int ok = a.length;
			int ng = -1;

			while (Math.abs(ng - ok) > 1) {
				int m = (ng + ok) / 2;
				if (a[m] * a[i] <= mid) {
					ok = m;
				} else {
					ng = m;
				}
			}
			if (ok <= i) {
				return a.length - ok - 1;
			} else {
				return a.length - ok;
			}
		}
	}
}


Measured memory_bytes: 50268
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
typedef long long int lli;
typedef unsigned long long int uli;
using namespace std;
int main(){
  int a,b,c,x,y,n,m;
  string s,t;
  char d,e;
  cin>>n>>m;
  if(n<=m)
    ou("Yes");
  else ou("No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int64_t n;
  cin >> s >> n;
  int64_t k=s.size(),cnt=0;  
  if(s==string(k,s[0]))cout << n*k/2 << endl;
  else{
      for(int64_t i=0;i<k;i++){
        if(s[i]==s[i+1] && s[i+1]==s[i+2]){
           cnt++;
           i++;
        }else if(s[i]==s[i+1])cnt++;
      }
    if(s[0]==s[k-1]){
      int a=0,b=0;
      for(int i=0;i<k;i++){
        if(s[i]==s[0])a++;
        else break;
      }
      for(int i=k-1;i>=0;i--){
        if(s[i]==s[k-1])b++;
        else break;
      }
      cout << (int64_t)cnt*n-(int64_t)((a/2)+(b/2)-((a+b)/2))*(n-1) << endl;
    }else cout << (int64_t)cnt*n << endl;
  }
}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<stdio.h>
#include<queue>
#include<map>
#include<stack>
using namespace std;
int dx[] = { -1,0,0,1,-1,-1,1,1,0 };
int dy[] = { 0,1,-1,0,1,-1,1,-1,0 };
/*
int main()
{
	int r, c;
	cin >> r >> c;
	int sy, sx, gy, gx;
	vector<vector<char>>field(r,vector<char>(c));
	sy--, sx--, gy--, gx--;
	for (int i = 0; i < r; i++)
	{
		for (int j = 0; j < c; j++)
		{
			cin >> field[i][j];
		}
	}
	queue<pair<int,int>>q;
	q.push({ sx,sy });
	vector<vector<int>>d(c, vector<int> (r, -1));
	d[sx][sy] = 0;

	while (!q.empty())
	{
		pair<int, int>p = q.front;
		q.pop();
		for (int i = 0; i < 4; i++)
		{
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (nx < 0 || ny < 0 || nx >= c || ny >= r || d[nx][ny] != -1 || field[nx][ny] == '#')continue;
			q.push({ nx,ny });
			d[nx][ny] = d[p.first][p.second] + 1;
		}
	}

	cout << d[gx][gy] << endl;
}*/


int main() 
{
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	while (true)
	{
		if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)
		{
			cout << ans << endl;
			break;
		}
		int a1 = b / 2 + c / 2;
		int b1 = a / 2 + c / 2;
		int c1 = a / 2 + b / 2;
		a = a1;
		b = b1;
		c = c1;
		ans += 1;

		if (a == b || b == c || c == a)
		{
			cout << -1 << endl;
			break;
		}
	}
	
}



Measured memory_bytes: 3152
#include<stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))

/*
A≦Bとして一般性を失わない。N=ABとおく。
x[i]*y[i]＜Nとなるものをできるだけ多く作りたい。
z=floor(√(N-1))とする。
x[i]≦z or y[i]≦zが必要。逆にこれを満たす2z個のうち使えないものは
１．z(z+1)≧Nならx[i]=zとy[i]=zは同じ組になるので-1
２．A≦zならx[i]=Aの組は使えないので-1
の2パターンに限る
*/

int main(){
	ll q;
	scanf("%lld",&q);
	while(q--){
		ll a,b;
		scanf("%lld%lld",&a,&b);		
		ll n=a*b;
		//n-1≧2^53になるときに誤差が怖いので
		ll c=sqrt(n-1)-1;
		while((c+1)*(c+1)<=n-1)c++;
		//
		ll ans=2*c;
		if(c*(c+1)>=n)ans--;
		if(min(a,b)<=c)ans--;
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, Y;
  cin >> N >> Y;
  Y /= 1000;
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= N - i; j++) {
      if (i * 10 + j * 5 + N - i - j == Y) {
        cout << i << ' ' << j << ' ' << N - i - j << endl;
        return 0;
      }
    }
  }
  cout << -1 << ' ' << -1 << ' ' << -1 << endl;
  return 0;
}


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

int main() {
  int n, c[4];
  char bt[10];
  const char *label[4] = {"A", "B", "AB", "O"};

  memset(c, 0, sizeof(int)*4);
  while (scanf("%d,%s\n", &n, bt) == 2) {
    for (int i=0; i<4; i++) {
      if (!strcmp(bt, label[i])) {
        ++c[i];
        break;
      }
    }
  }
  for (int i=0; i<4; i++) {
    printf("%d\n", c[i]);
  }
  return 0;
}

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

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for(int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    vector<bool> memo(k+1, false);
    for(int i = 1; i <= k; ++i) {
        for(int &x : arr) {
            if(i-x >= 0 && !memo[i-x]) {
                memo[i] = true;
                break;
            }
        }
    }
    cout << (memo[k] ? "First\n":"Second\n");
    return 0;
}


























Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    System.out.println(((a * b) % 2) == 0 ? "Even" : "Odd");
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <functional>

using namespace std;

#define F first
#define S second
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; 
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << ": "; for (auto& xxxx: a) cerr << xxxx << " "; cerr << endl;
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)a.size()
#define pw(n) (1ll << (n))
#define equal equalll
#define less lesss

typedef double dbl;
typedef long long ll;
const int N = -1;
const int INF = 1.01e9;
typedef vector<int> vi;



int main(){
#ifdef HOME 
    assert(freopen("in", "r", stdin));
#endif
    string s;
    cin >> s;
    int n = s.size();
    int l = 0; 
    int r = n - 1;
    int answer = 0;
    for (; l < r; ) {
        if (s[l] == s[r]) {
            l++;
            r--;
        }
        else {
            if (s[l] == 'x') {
                l++;
                answer++;
            }
            else if (s[r] == 'x') {
                r--;
                answer++;
            }
            else {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << answer << endl;


    
    
#ifdef HOME 
    epr("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
#endif
    return 0;
}



Measured memory_bytes: 512
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

input = sys.stdin.readline
a, b = map(int, input().split())

ans = 0
if a > b:
    ans = a + a - 1
elif b > a:
    ans = b + b - 1
else:
    ans = a + b

print(ans)


Measured memory_bytes: 2940
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please



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


	int N;
	scanf("%d ", &N);
	int sL[1001] = {}, sR[1001] = {};
	bool bL[1001] = {}, bR[1001] = {};
	pair<int, int> RR[500], LL[500];
	int rr = 0, ll = 0;
	int tot = 0;
	rep(i, N) {
		char c;
		int l = 0, r = 0;
		while((c = getchar_unlocked()) >= '(') {
			if (c == '(') r++;
			else {
				if (r > 0) r--;
				else l++;
			}
		}
		tot += r - l;
		if (l <= r) {
			if (l <= 1000) sR[l] += r - l, bR[l] = true;
			else RR[rr++] = { l,r };
		}
		else {
			if (r <= 1000) sL[r] += l - r, bL[r] = true;
			else LL[ll++] = { r,l };
		}
	}

	if (tot != 0) {
		printf("No");
		return 0;
	}

	sort(RR, RR + rr);
	sort(LL, LL + ll);

	int OK = 1;
	int k = 0;
	rep(i, 1001) {
		if (bR[i]) {
			if (k < i) OK = 0;
			k += sR[i];
		}
	}
	rep(i, rr) {
		if (k < RR[i].first) OK = 0;
		k += RR[i].second - RR[i].first;
	}
	k = 0;
	rep(i, 1001) {
		if (bL[i]) {
			if (k < i) OK = 0;
			k += sL[i];
		}
	}
	rep(i, ll) {
		if (k < LL[i].first) {
			OK = 0;
		}
		k += LL[i].second - LL[i].first;
	}

	if (OK) printf("Yes");
	else printf("No");

	Would you please return 0;
}

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

int main(){
 string s; cin>>s;
  int min=999;
  for(int i=0;i<s.size()-2;i++){
    int sa;
    sa=753-atoi(s.substr(i,3).c_str());
    if(sa<0)sa=-sa;
    if(sa<min)min=sa;
  }
    cout<<min<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[3005];
int main(int argc, const char * argv[])
{
    int n,ans=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        ans+=a[i]-1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n, total = gets.split.map(&:to_i)
ans_x, anx_y, ans_z = -1, -1, -1

(0..n).each do |x|
  (0..n-x).each do |y|
    z = n - x - y
    if 10000*x + 5000*y + 1000*z == total
      ans_x, anx_y, ans_z = x, y, z
    end
  end
end

puts "#{ans_x} #{anx_y} #{ans_z}"

Measured memory_bytes: 1916
n,a,b,c,d = [int(i)-1 for i in input().split()] 
S = input()
flag = 1
if a < b < c < d:
    if ("##" in S[a:d+1]): flag = 0
elif a < b < d < c:
    if ("##" in S[a:c+1]): flag = 0
    if ("..." not in S[b-1:d+2]):flag = 0
else:
    if ("##" in S[a:c+1]): flag = 0
    if ("##" in S[b:d+1]): flag = 0
print("Yes" if flag else "No")

Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe



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

int x,ans=0,mi = 800;
string s;
cin >> s;

for (int i = 0; i < s.size()-2; i++)
{
    x = STI(s.substr(i,3));

    ans = abs(753-x);

    mi = min(mi,ans);
}

cout << mi << endl;









//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
import sys

def main():
    input = sys.stdin.readline
    MOD = 10**6 + 3

    factrial = [1] * (MOD)
    for k in range(1, MOD):
        factrial[k] = (factrial[k-1] * k) % MOD
    
    fact_inv = [1] * (MOD)
    fact_inv[MOD-1] = pow(factrial[MOD-1], MOD - 2, MOD)
    for k in range(MOD-2, -1, -1):
        fact_inv[k] = (fact_inv[k+1] * (k+1)) % MOD

    Q = int(input())
    for _ in range(Q):
        x, d, n = map(int, input().split())

        if d == 0:
            ans = pow(x, n, MOD)

        else:
            y = x * pow(d, MOD-2, MOD) % MOD

            if y + n - 1 >= MOD:
                ans = 0

            else:
                ans = (factrial[y+n-1] * fact_inv[y-1] * pow(d, n, MOD)) % MOD

        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 84944
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    ll sum1 = 0, sum2 = 0;
    ll cost1 = 0, cost2 = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            if (sum1 + a[i] <= 0) {
                cost1 += 1 - sum1 - a[i];
                sum1 = 1;
            }
            else { sum1 += a[i]; }
            if (sum2 + a[i] >= 0) {
                cost2 += abs(-1 - sum2 - a[i]);
                sum2 = -1;
            }
            else { sum2 += a[i]; }
        }
        else {
            if (sum1 + a[i] >= 0) {
                cost1 += abs(-1 - sum1 - a[i]);
                sum1 = -1;
            }
            else { sum1 += a[i]; }
            if (sum2 + a[i] <= 0) {
                cost2 += 1 - sum2 - a[i];
                sum2 = 1;
            }
            else { sum2 += a[i]; }
        }
    }
    cout << min(cost1, cost2) << '\n';
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include <string.h>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
const ll mod=1e9+7;

int main(void){
    ll N,X,sum=0,ans=1;
    cin>>N>>X;
    vector<ll> L(N);
    rep(i,N) {
        cin>>L.at(i);
        if(sum+L.at(i)<=X){
            ans++;
            sum+=L.at(i);
        }
        else break;
    }
    cout<<ans<<endl;
    return 0;
}


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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e6 + 7;
const int N = 3e3 + 7;
const int M = 20;
const int mod = 998244353;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
    int a,b;
    cin >> a >> b;
    for( int i = 0; i < NN; i++ ){
        int x = 8 * i / 100;
        int y = 10 * i / 100;
        if( x == a && y == b ){
            cout << i;
            return;
        }
    }
    cout << -1;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
 
const ll inf = 1e9;
const int mxN = 2e6+1;
const int mod = 1e9+7; 

int vis[mxN] = {};
vector<int> v[mxN];


void dfs(int start){
    vis[start] = 1;
    for(auto x : v[start]){
        if(!vis[x]){
            vis[x] = 1;
            dfs(x);        
        }
    }
}
 
void solve(){
  int n, m;
  cin >> n >> m;
  for(int i = 0 ; i < m ; i++){
    int a,b;
    cin >> a >> b;
    v[a].pb(b);
    v[b].pb(a);
  }
  int ans = 0;
  for(int i = 1 ; i <= n ; i++){
    if(!vis[i]){
        dfs(i);
        ans++;
    }
  }
  cout << ans-1 << "\n";
}


 
int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
  return 0; 
}



Measured memory_bytes: 54548
n, t = map(int, input().split(" "))
ct = [tuple(map(int, input().split(" "))) for _ in range(n)]

filtered = tuple(filter(lambda x: x[1] <= t, ct))
if len(filtered) != 0:
	print(min(map(lambda x: x[0], filtered)))
else:
	print("TLE")

Measured memory_bytes: 3060
#include <bits/stdc++.h>  // ver1.9.4
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl;
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(15);
  int n;
  cin >> n;
  vector<pair<int,int>> a(n);
  int qw, er;
  rep(i,0,n){
    cin >> qw >> er;
    a[i] = mp(qw,er);
  }
  sort(ALL(a));
  int ans;
  ans = a[n-1].first + a[n-1].second;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null) {

			int[] rails = new int[10];
			int total = 0;

			int v1 = 0;
			int v2 = 0;

			//
			int i = 0;
			for (String s : line.split(",")) {
				if (i < 10) {
					rails[i] = Integer.parseInt(s);
					total += rails[i];
				} else if (i == 10) {
					v1 = Integer.parseInt(s);
				} else if (i == 11) {
					v2 = Integer.parseInt(s);
				}
				i++;
			}

			//
			double across = (double) total * (double) v1 / (double) (v1 + v2);

			int sum = 0;
			for (int j = 0; j < rails.length; j++) {
				if (across == sum) {
					System.out.println(j + 1);
					break;
				}
				sum += rails[j];
				if (across <= sum) {
					System.out.println(j + 1);
					break;
				}
			}
		}
	}
}

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//
int N;
ll ans = 0;
vector<ll> A;
vector<ll> B;

int check(int l, int c, int r){
    if(B[c] - B[l] - B[r] >= A[c]){
        return true;
    }
    return false;
}

void proc(int l, int c, int r){
    ll tmp = (B[c]-A[c]) / (B[l] + B[r]);
    B[c] -= tmp * (B[l] + B[r]);
    ans += tmp;
    return;
}

void bfs(){
    queue<int> que;
    if(check(N-1, 0, 1)){
        que.push(0);
    }
    if(check(N-2,N-1, 0)){
        que.push(N-1);
    }

    for(int i = 1; i < N - 1; ++i){
        if(check(i-1, i, i + 1)){
            que.push(i);
        }
    }

    while (!que.empty()) {
        int idx = que.front(); que.pop();
        int l, r;
        if(idx == 0){l = N-1; r = 1;}
        else if(idx == N - 1){l = N-2; r = 0;}
        else{l = idx-1; r = idx + 1;}

        proc(l, idx, r);

        int l_l, l_r;
        if(l == 0){l_l = N-1; l_r = 1;}
        else if(l == N - 1){l_l = N-2; l_r = 0;}
        else{l_l = l-1; l_r = l + 1;}
        if (check(l_l, l, l_r)) {
            que.push(l);
        }

        int r_l, r_r;
        if(r == 0){r_l = N-1; r_r = 1;}
        else if(r == N - 1){r_l = N-2; r_r = 0;}
        else{r_l = r-1; r_r = r + 1;}
        if (check(r_l, r, r_r)) {
            que.push(r);
        }
    }
    return;
}

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    cin >> N;
    A.resize(N);
    B.resize(N);
    for(int i = 0; i < N; ++i){cin >> A[i];}
    for(int i = 0; i < N; ++i){cin >> B[i];}

    bfs();

    for(int i = 0; i < N; ++i){
        if(B[i] != A[i]){
            cout << -1 << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 3840
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  vector<pair<int, int>> AB(N);
  for (int i = 0; i < N; i++) {
    AB[i] = make_pair(A[i], B[i]);
  }
  sort(AB.begin(), AB.end());

  ll ans = 0;

  for (int i = 0; i < N; i++) {
    int buy = min(M, AB[i].second);
    ans += AB[i].first * (ll)buy;
    M -= buy;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4764
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

int n,a[55],b[55],g[55][55],v[55];

vector <ll> ans;

void DFS(int nod){
    if(v[nod]) return;
    v[nod]=1;
    for(int i=0;i<=50;i++){
        if(g[nod][i]) DFS(i);
    }
}

bool Find(int a, int b){
    for(int i=0;i<=50;i++) v[i]=0;
    DFS(a);
    return v[b];
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    for(int i=1;i<=n;i++){
        cin >> b[i];
    }
    for(int i=0;i<=50;i++) g[i][i]=INF;
    for(int k=1;k<=50;k++){
        for(int i=0;i<=50;i++){
            g[i][(i%k)]++;
        }
    }
    int f=1;
    for(int i=1;i<=n;i++){
        if(!Find(a[i],b[i])) f=0;
    }
    if(!f){
        cout << -1;
        return 0;
    }
    for(int k=50;k>=1;k--){
        for(int i=0;i<=50;i++){
            g[i][i%k]--;
        }
        f=1;
        for(int i=1;i<=n;i++){
            if(!Find(a[i],b[i])) f=0;
        }
        if(!f){
            ans.pb(k);
            for(int i=0;i<=50;i++){
                g[i][(i%k)]++;
            }
        }
    }
    ll val=0;
    for(int i : ans) val+=(1ll<<i);
    cout << val;
}


Measured memory_bytes: 256
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

ll ans=0;

int main(void){
    ll n;
    ll ans =0;
    cin >>n;
    for(ll i=1; i<=n; i++){
        ll max = n/i;
        ans += (max*(max+1))*i/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3216
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        for (int i = 0; i < 1100; i++) {
            if (i * 8 / 100 == a && i * 10 / 100 == b) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(-1);
    }
}

Measured memory_bytes: 23892