akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  
  vector<pair<int, int> > obstacle(N);
  map<pair<int, int>, bool> isObstacle;
  int x, y;
  for (int i = 0; i < N; i++) {
    cin >> x >> y;
    x--;
    y--;
    obstacle[i] = make_pair(y, x);
    isObstacle[make_pair(y, x)] = true;
  }
  sort(obstacle.begin(), obstacle.end());
  
  int counter = 0;
  int h = 0, w = 0;
  int best = H;
  while (true) {
    h++;
    if (h == H || isObstacle[make_pair(w, h)]) {
      best = min(best, h);
      break;
    }
    
    while(counter < N && obstacle[counter].first <= w) {
      int wObs = obstacle[counter].first;
      int hObs = obstacle[counter].second;
      // cout << w << " " << h << " " << wObs << " " << hObs << endl;
      if (wObs == w && hObs > h && best > hObs) {
        best = hObs;
      }
      counter++;
    }
    
    // cout << w + 1 << " " << h << endl;
    if (w + 1 < W && !isObstacle[make_pair(w + 1, h)]) {
      w++;
    }
  }
  
  cout << best << endl;

  return 0;
}


Measured memory_bytes: 34944
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

long long int D[50][50] = {}, c[600][600] = {};


int main(){
	
	int N, C;
	cin >> N >> C;
	
	for(int i = 0; i < C; i++){
		for(int j = 0; j < C; j++){
			cin >> D[i][j];
		}
	}
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			cin >> c[i][j];
			c[i][j]--;
		}
	}
	
	long long int cost[30][3] = {};
	
	for(int col = 0; col < C; col++){
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				cost[col][(i + j) % 3] += D[c[i][j]][col];
			}
		}
	}
	
	long long int ans = INF;
	for(int i = 0; i < C; i++){
		for(int j = 0; j < C; j++){
			for(int k = 0; k < C; k++){
				if(i == j || j == k || k == i){
					continue;
				}
				ans = min(ans, cost[i][0] + cost[j][1] + cost[k][2]);
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2560
#include "cstdio"

using namespace std ;

int main () {
    int a, b ;
    while ( scanf ("%d %d", &a, &b) != EOF ) {
        if ( a % b ) {
            printf ("%d\n", a) ;
        }
        else {
            printf ("-1\n") ;
        }
    }
    return 0 ; 
} 

Measured memory_bytes: 128
#include <iostream>

using namespace std;

typedef long long ll;

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

    int k, q;
    cin >> k >> q;
    int d[k];
    for (int i = 0; i < k; i++) {
        cin >> d[i];
    }

    while (q--) {
        int n, x, m;
        cin >> n >> x >> m;
        x %= m;

        ll psd[k+1], cnt[k+1];
        for (int i = 0; i <= k; i++) {
            psd[i] = i == 0 ? 0 : psd[i-1] + d[i-1] % m;
            cnt[i] = i == 0 ? 0 : cnt[i-1] + (d[i-1] % m == 0);
        }

        ll an = x + (n - 1) / k * psd[k] + psd[(n-1)%k];
        int c0 = (n - 1) / k * cnt[k] + cnt[(n-1)%k];

        cout << n - 1 - an / m - c0 << endl;
    }

    return 0;
}


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

#define ll long long
#define ull unsigned long long
#define met(a, x) memset(a,x,sizeof(a));
#define inf 0x3f3f3f3f
#define mp make_pair;

using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const int M = 1e5 + 10;
int a[M + 10];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    while (cin >> n) {
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        sort(a + 1, a + 1 + n);
        if (a[n] - a[1] > 1||a[n]>=n) {
            cout << "No" << endl;
        } else {
            int cnt1 = 0, cnt2 = 0;
            for (int i = 1; i <= n; i++) {
                if (a[i] == a[n]) {
                    cnt2++;
                } else if (a[n] == a[i] + 1){
                    cnt1++;
                }
            }
            int cnt = cnt1 + cnt2 / 2;
            if (cnt1 == 0) {
                if (a[n] == n - 1 || 2*a[n]<=n) {
                    cout << "Yes" << endl;
                } else {
                    cout << "No" << endl;
                }
            } else {
                if (cnt >= a[n] && cnt2 != 1&&cnt1<a[n])
                    cout << "Yes" << endl;
                else
                    cout << "No" << endl;
            }
        }
    }
    return 0;
}



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

int main() {
  string s;
  cin >>s;
  vector<int>a(26,0);
  for(int i=0;i<s.size();i++){
    for(char c='a';c<='z';c++){
      if(c==s[i])a[c-'a']++;
    }
  }
  for(int i=0;i<26;i++){
    if(a[i]==0){
      char b=i+'a';
      cout<<(char)b<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
  return 0;
}

Measured memory_bytes: 512
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        mut n: i32,
        k: usize,
        d: [i32; k],
    }
 
    let mut ans = n;
    loop {
        let mut check = true;
        let mut acc = ans;
        while acc > 0 {
            if d.contains(&(acc % 10)) {
                check = false;
            }
            acc /= 10;
        }
        if check {
            break
        } else {
            ans += 1;
        }
    }
 
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7

int main(){
    string s; cin >> s;
    ll n = s.size();
    rep(i,n){
        rep(j,n-i){
            string t = s;
            t.erase(i,j);
            if(t=="keyence"){
                puts("YES");
                return 0;
            }
        }
    }
    puts("NO");
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        String S = sc.next();
        sc.close();

        if(C < D){
            for(int i = A; i < D; i++){
                if(S.charAt(i) == '#' && S.charAt(i+1) == '#'){
                    System.out.println("No");
                    return;
                }
            }
            System.out.println("Yes");
        } else {
            for(int i = A; i < C; i++){
                if(S.charAt(i) == '#' && S.charAt(i+1) == '#'){
                    System.out.println("No");
                    return;
                }
            }
            for(int i = B-1; i < D; i++){
                if(S.charAt(i) == '.' && S.charAt(i-1) == '.' && S.charAt(i+1) == '.'){
                    System.out.println("Yes");
                    return;
                }
            }
            System.out.println("No");
        }
   }
}

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


using namespace std;
using ll = long long;

int main() {
	int value[100001];
	int n;
	cin >> n;
	for (int i = 0;i < 100001;i++) {
		value[i] = 0;
	}
	for (int i = 0;i < n;i++) {
		int tmp;
		cin >> tmp;
		value[tmp]++;
	}
	int q;
	cin >> q;
	ll ans = 0;
	for (int i = 0;i < q;i++) {
		int b, c;
		cin >> b >> c;

		if (i == 0) {
			value[c] += value[b];
			value[b] = 0;
			for (int i = 1;i < 100001;i++) {
				ans += (ll)value[i] * i;
			}
			cout << ans << endl;
		}
		else {
			ans += (ll)c * value[b];
			value[c] += value[b];
			ans -= (ll)b * value[b];
			value[b] = 0;
			cout << ans << endl;
		}

		
	}
	

}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    double r;
    cin >> r;
    cout << fixed << setprecision(10);
    double ans = 2 * 3.14159265359 * r;
    cout << ans << endl;
}

Measured memory_bytes: 3800
#include <iostream>
using namespace std;
int main()
{
	int a,b,c;
	int five=0,seven=0;
	cin>>a>>b>>c;
	if(a==5)
	{
		five++;
	}
	else if(a==7)
	{
		seven++;
	}
		if(b==5)
	{
		five++;
	}
	else if(b==7)
	{
		seven++;
	}
		if(c==5)
	{
		five++;
	}
	else if(c==7)
	{
		seven++;
	}
	if(seven>1||five>2)
	{
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
int a[3];
int main()
{
    for(int i=0;i<3;i++) scanf("%d",&a[i]);
    std::sort(a,a+3);
    if(a[0]==5 && a[1]==5 && a[2]==7) printf("YES\n");
    else printf("NO\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;
int acd[100100], wac[100100];

int main()
{
	int n, m, i, p, acc=0, wact=0;
	string s;
	cin >> n >> m;
	for(i = 0; i <= n; i++ ){
		acd[i] = 0;
		wac[i] = 0;
	}
	for(i = 1; i <= m; i++) {
		cin >> p >> s;
		if(acd[p]==0) {
			if(s=="AC") {
				acc++;
				acd[p] = 1;
			} else {
			   wac[p] ++;
			}	   
		}
	}
	for(i = 1; i <= n; i++) {
		if(acd[i]==1) {
			wact+=wac[i];
		}
	}
	cout << acc << " " << wact << endl;
	return 0;
}


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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string message = "ABC";
            if (N >= 1000) message = "ABD";
            Console.WriteLine(message);

        }
    }
}

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

using namespace std;
typedef long long ll;
const int N = 1e9 + 1;
int mod = 1e9 + 7;
#define INF 0x3f3f3f3f
typedef pair<int, int> pii;

int main()
{
#ifndef ONLINE_JUDGE  
   // freopen("in.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif 
   // ios::sync_with_stdio(0);
    int n, a, b;
    while (~scanf("%d", &n))
    {
    	if (n == 1)
    	{
    		puts("Hello World");
    	}else
    	{
    		scanf("%d%d", &a, &b);
    		printf("%d\n",a + b);
    	}
    }
    return 0;
}

Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

//

fn run() {
    input! {
        s: chars,
    }
    let mut cnt = vec![0; 3];
    for c in s {
        let k: usize = c.to_digit(36).unwrap() as usize - 10;
        cnt[k] += 1;
    }
    let min = *cnt.iter().min().unwrap();
    let max = *cnt.iter().max().unwrap();
    if max - min <= 1 {
        println!("YES");
    } else {
        println!("NO");
    }
}

fn main() {
    run();
}


Measured memory_bytes: 4352
# ABC088B - Card Game for Two
import sys
input = sys.stdin.readline

n = int(input())
lst = sorted(list(map(int, input().rstrip().split())), reverse=True)
total = 0
for i in range(n):
    if i % 2 == 0:
        total += lst[i]
    else:
        total -= lst[i]
print(total)

Measured memory_bytes: 3060
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    II()
    s=SI()
    t=0
    ans=0
    for c in s:
        if c=="I":t+=1
        else:t-=1
        ans=max(ans,t)
    print(ans)

main()

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
 
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
  ll a,b; cin>>a>>b;
  cout << max({a+b,a-b,a*b}) << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
p = [0]*(n+1)
q = [False]*(n+1)
for _ in range(m) :
  v,s = input().split()
  v = int(v)
  if q[v]:
      continue
  if s[0] == 'A':
      q[v] = True
  else :
      p[v] += 1
print(sum(q), sum(p[i] for i in range(n+1) if q[i]))

Measured memory_bytes: 4596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>

#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#include <utility>
#include <list>

#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <complex>
#include <climits>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back

#define debug(x) cerr << #x << " = " << x << " "
int n;
deque<int> read()
{
  deque<int> v(n);
  for (auto & e : v) scanf("%d", &e);
  sort(v.begin(), v.end());
  return v;
}
const int mod = 1e9+7;
int main()
{
  scanf("%d", &n);
  auto a = read();
  auto b = read();
  auto stable_a = a;
  auto stable_b = b;
  vector<int> dq;
  auto count_range = [&](int left, int right)
    {
      auto lid = lower_bound(dq.begin(), dq.end(), left);
      auto rid = upper_bound(dq.begin(), dq.end(), right);
      return rid - lid + 1;
    };
  ll ans = 1;
  for (int i = 0; i < n; ++i)
    {
      int ca = a.front(); a.pop_front();
      int cb = b.front(); b.pop_front();
      ll multiplier = 1;
      if (ca > cb) swap(ca, cb);
      multiplier = count_range(ca, cb);
      ans = ans * multiplier % mod;
      dq.pb(cb);
    }
  printf("%lld\n", ans);
}


Measured memory_bytes: 2560
local H, W = io.read("*n", "*n", "*l")

local function mk2d()
    local t = {}
    for i=1,H do
        t[i] = {}
    end
    return t
end

local grid = mk2d()
for i=1,H do
    local s = io.read("*l")
    local line = grid[i]
    for j=1,W do
        line[j] = string.sub(s, j, j) == '#' and 1 or 0
    end
end

local U = mk2d()
local D = mk2d()
local L = mk2d()
local R = mk2d()

-- L
for i=1,H do
    local line = grid[i]
    local target = L[i]
    local cnt = 0
    for j=1, W do
        local a = line[j]
        if a == 0 then
            cnt = cnt + 1
        else
            cnt = 0
        end
        target[j] = cnt
    end
end
-- R
for i=1,H do
    local line = grid[i]
    local target = R[i]
    local cnt = 0
    for j=W, 1, -1 do
        local a = line[j]
        if a == 0 then
            cnt = cnt + 1
        else
            cnt = 0
        end
        target[j] = cnt
    end
end
-- U
for j=1,W do
    local cnt = 0
    for i=1,H do
        local a = grid[i][j]
        if a == 0 then
            cnt = cnt + 1
        else
            cnt = 0
        end
        U[i][j] = cnt
    end
end
-- D
for j=1,W do
    local cnt = 0
    for i=H,1,-1 do
        local a = grid[i][j]
        if a == 0 then
            cnt = cnt + 1
        else
            cnt = 0
        end
        D[i][j] = cnt
    end
end

local function count(i, j)
    if grid[i][j] == 1 then
        return -1
    else
        local a = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
        return a
    end
end

local ans = 0
for i=1,H do
    for j=1,W do
        ans = math.max(ans, count(i, j))
    end
end
print(ans)


Measured memory_bytes: 164352
def c_christmas_eve():
    N, K = [int(i) for i in input().split()]
    H = sorted([int(input()) for _ in range(N)])
    # 木の高さで昇順ソートしたなら、問題の「最大値と最小値の差」がすぐ求まる
    return min([H[j + K - 1] - H[j] for j in range(N - K + 1)])

print(c_christmas_eve())

Measured memory_bytes: 10892
def tax(p,x):
  return p*(100+x)//100
def highest(x,y,s):
  best = 0
  for i in range(1,s):
    for j in range(1,s):
      k = tax(i,x)+tax(j,x)
      if k == s:
        if best <= tax(i,y)+tax(j,y):
          best = tax(i,y)+tax(j,y)
  return best
while True:
  x,y,s = map(int,input().split())
  if x == y == s == 0:
    break
  print(highest(x,y,s))


Measured memory_bytes: 5604
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)((n>>m)&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

ll n;
ll a[200010];
ll s[200010];
#define kukan(l,r)(s[r]-s[l])

ll bs(ll l,ll r,ll sum){
	//[l,m)の和がsum以下となる最大のmを返す
	ll ok=l,ng=r;
	while(ng-ok>1){
		ll m=(ok+ng)/2;
		if(kukan(l,m)>sum)ng=m;
		else ok=m;
	}
	return ok;
}

ll ans=INF;
int main(){
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld",a+i);
	rep(i,0,n)s[i+1]=s[i]+a[i];
	rep(i2,2,n-1){
		ll i1=bs(0,i2,kukan(0,i2)/2);
		if(i2-i1>=2&&kukan(0,i1)<kukan(i1+1,i2))i1++;
		ll i3=bs(i2,n,kukan(i2,n)/2);
		if(n-i3>=2&&kukan(i2,i3)<kukan(i3+1,n))i3++;
		ll tmax=max(max(max(kukan(0,i1),kukan(i1,i2)),kukan(i2,i3)),kukan(i3,n));
		ll tmin=min(min(min(kukan(0,i1),kukan(i1,i2)),kukan(i2,i3)),kukan(i3,n));
		ans=min(ans,tmax-tmin);
//		printf("%lld %lld %lld ",i1,i2,i3);
//		printf("%lld %lld %lld %lld ",kukan(0,i1),kukan(i1,i2),kukan(i2,i3),kukan(i3,n));
//		printf("%lld %lld\n",tmax,tmin);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, l, t;
    cin >> n >> l >> t;
    
    vector<int> B(n);
    int shift = 0;
    for (int i = 0; i < n; ++i) {
        int x, w;
        cin >> x >> w;
        if (w == 1) {
            B[i] = (x + t) % l;
            shift += t / l;
            if (x + t % l >= l) {
                shift += 1;
            }
            shift %= n;
        } else {
            B[i] = (x - t) % l;
            if (B[i] < 0) B[i] += l;
            shift -= t / l;
            if (x - t % l < 0) {
                shift -= 1;
            }
            shift %= n;
        }
    }
    if (shift < 0) {
        shift += n;
    }
    sort(B.begin(), B.end());
    rotate(B.begin(), B.begin() + shift, B.end());
    for (int value: B) {
        cout << value << '\n';
    }
}


Measured memory_bytes: 1664
#include<cstdio>

int main(){
    int a, b;
    scanf ("%d %d", &a, &b);

    int d = a / b;
    int r = a % b;
    double f = (double)a / (double)b;

    printf ("%d %d %f\n",d, r, f);

    return 0;
}


Measured memory_bytes: 2736
#include<iostream>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int sum=1;
    for(int i=0;i<n;i++)
    {
        if(i==0){
            sum=k;
        }
        else{
            sum*=(k-1);
        }
    }
    cout<<sum;
}

Measured memory_bytes: 3592
/*

*/
#include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}
void flagfunc3(bool flag){cout<<(flag?"Yes\n":"No\n");}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int x;cin>>x;
  flagfunc3(x>=30);
}

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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
  ll n, k;
  string s;
  cin >> n >> k >> s;
  if (s[k - 1] == 'A') {
    s[k - 1] = 'a';
  }
  else if (s[k - 1] == 'B') {
    s[k - 1] = 'b';
  }
  else if (s[k - 1] == 'C') {
    s[k - 1] = 'c';
  }
  COUT(s);

}

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

/*

3 2
*/


Measured memory_bytes: 3536
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <deque>
#include <cstring>
#include <functional>
#include <climits>
#include <list>
#include <ctime>
#include <complex>

#define F1(x,y,z) for(int x=(y);x<(z);x++)
#define F2(x,y,z) for(int x=(y);x<=(z);x++)
#define F3(x,y,z) for(int x=(y);x>(z);x--)
#define F4(x,y,z) for(int x=(y);x>=(z);x--)
#define mp make_pair
#define pb push_back
#define LL long long
#define co complex<double>
#define fi first
#define se second

#define MAX 100005
#define AMAX 53
#define MOD 1000000007

#define f(c,d) ((1<<(c))*(d))

using namespace std;

int n,q,i,at,s=1,y[MAX*4][28],pre[MAX],cnt[26][26],z[MAX][26][26],ans;
char x[MAX];

void dfs(int a,int b){
	if(y[a][26]){
		pre[y[a][26]]=b++;
		F1(c,0,26)F1(d,0,26)z[y[a][26]][c][d]=cnt[c][d];
	}
	F1(c,0,26)if(y[a][c]){
		F1(d,0,26)cnt[d][c]+=y[y[a][d]][27];
		dfs(y[a][c],b);
		F1(d,0,26)cnt[d][c]-=y[y[a][d]][27];
	}
}

int main(){
	scanf("%d",&n);
	F2(a,1,n){
		i=at=0;
		scanf("%s",x);
		while(x[i]){
			if(!y[at][x[i]-='a'])y[at][x[i]]=s++;
			y[at=y[at][x[i]]][27]++;
			x[i++]=0;
		}
		y[at][26]=a;
	}
	dfs(0,0);
	scanf("%d",&q);
	while(q--){
		scanf("%d%s",&i,x);
		ans=pre[i]+1;
		F1(a,0,26)F1(b,a+1,26)ans+=z[i][x[a]-'a'][x[b]-'a'];
		printf("%d\n",ans);
	}
	#ifdef LOCAL_PROJECT
	system("pause");
	#endif
	return 0;
}


Measured memory_bytes: 278144
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

using Graph = vector<vector<int>>;
Graph G;

int f[100005];
int s[100005];

void dfs(int v, int p, string name){
    for(auto e: G[v]){
        if(e == p) continue;
        if(name == "Snuke") s[e] = s[v] + 1;
        else f[e] = f[v] + 1;
        dfs(e, v, name);
    }
    return;
}

int main(){
    int n;
    cin >> n;
    G.assign(n, vector<int>());
    rep(i, n-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(0, -1, "Fennec");
    dfs(n-1, -1, "Snuke");

    int S = 0;
    int F = 0;
    rep(i, n){
        if(f[i] < s[i]) F++;
        if(s[i] < f[i]) S++;
        if(s[i] == f[i]) F++;
    }

    if(S < F) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

Measured memory_bytes: 17408
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <math.h>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= base;
	}
	return ans;
}
static const long long MOD_NUM = 1000000007LL;

template <class _T> _T nexp(_T N) {
	_T num = N;
	_T ans = 1;
	while (N) {
		ans *= N;
		N--;
	}
	return ans;
}

static void C_task();

int main()
{
	C_task();
	fflush(stdout);
	return 0;
}

static double C_calc(int N, const std::pair<int, int>* town, std::vector<int>& root)
{
	double dist = 0;
	for (int i = 1; i < N; i++) {
		dist += sqrt(tp_pow<LLONG>((town[root[i]].first - town[root[i - 1]].first), 2) 
				+ tp_pow<LLONG>((town[root[i]].second - town[root[i - 1]].second), 2));
	}
	return dist;
}

static double dfs(int N, int now, const std::pair<int, int>* town, std::vector<int> root, std::vector<bool> flag)
{
	double dist = 0;

	if (now == N) {
		return C_calc(N, town, root);
	}

	for (int i = 0; i < N; i++) {
		if (flag[i] == false) {
			flag[i] = true;
			root[now] = i;
			dist += dfs(N, now + 1, town, root, flag);
			flag[i] = false;
		}
	}
	return dist;
}

static void C_task()
{
	int N;
	get1int(N);

	std::pair<int, int> town[8];

	for (int i = 0; i < N; i++) {
		int x, y;
		get2int(x, y);
		town[i].first = x;
		town[i].second = y;
	}
	std::vector<bool> flag(N, 0);
	std::vector<int> root(N, 0);

	double ans = dfs(N, 0, town, root, flag) / (double)(nexp(N));

	printf("%.8lf\n", ans);
}


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

typedef long double ld;

const ld EPS = 1e-9;
const ld INF = 1e10;
const ld PI = M_PI;

struct Point{
  ld x, y;
  Point(ld x, ld y):x(x), y(y){}
  Point(){}
};

bool eq(ld a, ld b){
  return abs(a-b) < EPS;
}

Point operator+(const Point &a, const Point &b){
  return Point(a.x + b.x, a.y + b.y);
}
Point operator-(const Point &a, const Point &b){
  return Point(a.x - b.x, a.y - b.y);
}
Point operator*(const Point &a, const ld b){
  return Point(a.x * b, a.y * b);
}
Point operator*(const Point &a, const Point &b){
  return Point(a.x*b.x-a.y*b.y, a.x*b.y+a.y*b.x);
}
Point operator/(const Point &a, const ld b){
  return Point(a.x / b, a.y / b);
}

typedef vector<Point> Polygon;

Point next(const Polygon &a, int x){
  return a[(x+1)%a.size()];
}
Point prev(const Polygon &a, int x){
  return a[(x-1+a.size()) % a.size()];
}

ld cross(const Point &a, const Point &b){
  return a.x*b.y - a.y*b.x;
}

ld dot(const Point &a, const Point &b){
  return a.x*b.x + a.y*b.y;
}

ld norm(const Point &a){
  return dot(a, a);
}

int ccw(Point a, Point b, Point c){
  b = b - a;
  c = c - a;
  if(cross(b, c) > EPS) return +1; // 反時計周り
  if(cross(b, c) < -EPS) return -1; // 時計周り
  if(dot(b, c) < 0) return +2; // c -- a -- b がこの順番に一直線上
  if(norm(b) < norm(c)) return -2; // a -- b -- c がこの順番に一直線上
  return 0; // a -- c -- b が一直線上
}

bool compare(const Point &a, const Point &b){
  if(eq(a.y, b.y)) return a.x < b.x;
  return a.y < b.y;
}

Polygon convex_hull(Polygon ps){
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end(), compare);
  Polygon ch(2*n);
  for(int i = 0 ; i < n ; i++){
    while(k > 1 && ccw(ch[k-2], ch[k-1], ps[i]) == -1) --k;    
    ch[k++] = ps[i];
  }
  int t = k;
  for(int i = n-2 ; i >= 0 ; i--){
    while(k > t && ccw(ch[k-2], ch[k-1], ps[i]) == -1) --k;
    ch[k++] = ps[i];
  }
  ch.resize(k-1);
  return ch;
}

int main(){
  ld xa, ya, xb, yb, xc, yc, xd, yd;
  char c;
  while(cin >> xa >> c >> ya >> c >> xb >>
	c >> yb >> c>> xc >> c >> yc >> c >> xd >> c >> yd){
    Polygon poly;
    poly.push_back(Point(xa, ya));
    poly.push_back(Point(xb, yb));
    poly.push_back(Point(xc, yc));
    poly.push_back(Point(xd, yd));
    Polygon ans = convex_hull(poly);
    
    cout << (ans.size() == 4 ? "YES" : "NO") << endl;
  }
  
  return 0;
}

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

using namespace std;

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

  double x;
  string u;
  double ans = 0;
  double btc = 380000.;
  for (int i = 0; i < N; ++i) {
    cin >> x >> u;
    if (u == "BTC") {
      ans += x * btc;
    }
    else {
      ans += x;
    }
  }

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



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  char c;
  int x[26],i;
  for(i=0;i<26;i++) x[i]=0;
  while(scanf("%c",&c)!=EOF)
    {
      if((c>='A')&&(c<='Z')) c+='a'-'A';
      if((c>='a')&&(c<='z')) x[c-'a']++;
    }
  for(i=0;i<26;i++) printf("%c : %d\n",i+'a',x[i]);
  return 0;
}

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

P h[100000];
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		int ans = 0;
		rep(i, n) {
			int d, p; scanf("%d%d", &d, &p);
			ans += d*p;
			h[i] = P(p, d);
		}
		sort(h, h + n, greater<>());
		int sum = m;
		int i;
		for (i = 0; i < n&& sum - h[i].second >= 0; i++) {
			sum -= h[i].second;
			ans -= h[i].first*h[i].second;
		}
		ans -= h[i].first*sum;
		printf("%d\n", max(0, ans));
	}
}

Measured memory_bytes: 3268
from sys import exit

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))
BC.sort(key=lambda x: -x[1])
A.sort()

i = 0
for b, c in BC:
    for x in range(b):
        if i < N and A[i] < c:
            A[i] = c
            i += 1
        else:
            print(sum(A))
            exit()
print(sum(A))


Measured memory_bytes: 26012
def main():
    n = int(input())
    ans = []
    while n>25:
        p = n//26
        k = n-26*p
        if k==0:
            ans.append(26)
            n = p-1
        else:
            ans.append(k)
            n = p
    if n!=0:
        ans.append(n)
    ans = ans[::-1]
    b = []
    for i in range(len(ans)):
        b.append(chr(96+ans[i]))

    print(''.join(b))

if __name__ == "__main__":
    main()


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

int main() {
  long N;
  cin >> N;
  if (N < 10) {
    cout << N << endl;
  } else if (N < 100) {
    cout << 9 << endl;
  } else if (N < 1000) {
    cout << 9 + N - 99 << endl;
  } else if (N < 10000) {
    cout << 909 << endl;
  } else if (N < 100000) {
    cout << 909 + N - 9999 << endl;
  } else if (N == 100000) {
    cout << 90909 << endl;
  }
}


Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def check(s):
    for i in range(len(s)):
        if s[i] != s[len(s)-1-i]:
            return False
    return True

def main():
    x = ri()
    h1 = x//500
    x -= h1*500
    h2 = x//5
    print(h1*1000+h2*5)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
// B.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	int cnt[4] = {};
	for (int i = 0; i < 3; ++i) {
		int a, b;
		cin >> a >> b;
		cnt[a - 1]++;
		cnt[b - 1]++;
	}
	bool ans = cnt[0] <= 2 && cnt[1] <= 2 && cnt[2] <= 2 && cnt[3] <= 2;
	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc113/tasks/abc113_d
# あみだくじは, 日本に古くから伝わる伝統的なくじ引きである.
# あみだくじを作るには, まず W 本の平行な縦線を引き, 次にそれらを繋ぐ横線を引いていく.
# それぞれの縦棒の長さは H+1 [cm] であり、
# 横線の端点となれるのは上から 1,2,3,...,H [cm] の位置のみである.
# ここで,「正しいあみだくじ」とは, 以下のような条件を満たすあみだくじのことである.
# どの 2 つの横棒も端点を共有しない.
# それぞれの横棒の 2 つの端点は同じ高さになければならない.
# 横棒は隣り合う縦線を繋がなければならない.

# 縦棒 1 の上端から, 横線があれば必ずそれを通るというルールで下へたどったときに,
#  最終的にたどり着く縦棒の番号が K となるような「正しいあみだくじ」の本数を 1 000 000 007 で割った余りを求めなさい.
# H は 1 以上 100 以下の整数
# W は 1 以上 8 以下の整数
# K は 1 以上 W 以下の整数
# H W K
# 15 8 5
# 437760187
H, W, K = gets.split.map(&:to_i)

FIB = [1, 1, 2, 3, 5, 8, 13, 21]
MOD = (10**9) + 7

# どこかとどこかをつなぐと、その左右は繋げない。
# ある隣接2本(直下系の為に引数を2つにする)に対して、残りの部分の組み合わせを返す
def getc(a,b)
  FIB[a] * FIB[W-1-b]
end

dp = Array.new(H+1) { Array.new(W, 0) }
dp[0][0] = 1
1.step(H) do |h|
  W.times do |w|
    # 直下・左・右への移動が考えられる
    dp[h][w]   += (dp[h-1][w]%MOD * getc(w,   w))
    dp[h][w-1] += (dp[h-1][w]%MOD * getc(w-1, w)) if w != 0
    dp[h][w+1] += (dp[h-1][w]%MOD * getc(w, w+1)) if w != W-1
  end%MOD
end
p dp[H][K-1]%MOD

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

int main() {
  ll X;
  cin >> X;
  ll sum = 100;
  rep(i, 1000000000){
    if(sum >= X){
      cout << i << endl;
      return 0;
    }else{
      sum += sum / 100;
    }
 }
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define all(x) (x).begin(), (x).end()
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,m,k,maxx=0,temp=0,maxx2=0;
    cin>>n>>m>>k;
    ll A[n+1],B[m+1];
    A[0]=0,B[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>A[i];
        A[i]=A[i]+A[i-1];
        if(A[i]<=k)maxx2=i;
    }
    for(ll i=1;i<=m;i++)
    {
        cin>>B[i];
        B[i]=B[i]+B[i-1];
        if(B[i]<=k)maxx=i;
    }
    ll j=maxx;

    for(ll i=1;i<=n;i++&&j>=1)
    {

        while((A[i]+B[j])>k&&j>=1)
        {
            j--;

        }
        if(A[i]+B[j]<=k)
        maxx=max(i+j,maxx);
    }


    cout<<max(maxx,maxx2)<<endl;

    return 0;
}


Measured memory_bytes: 6752
#include <stdio.h>
int main(void){
    int r,c,tmp;
    scanf("%d %d",&r,&c);
    int a[r+1][c+1];
    
    for(int i=0;i<=r;i++){
        for(int j=0;j<=c;j++){
            a[i][j] = 0;
        }
    }
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            scanf(" %d",&a[i][j]);
        }
    }
    for(int i=0;i<=r;i++){
        for(int j=0;j<=c;j++){
            if(i<r && j<c){
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            }
            else{
                a[r][c] += a[i][j];
            }
        }
    }
    a[r][c] /= 4;
    
    for(int i=0;i<=r;i++){
        for(int j=0;j<=c;j++){
            if(j != c){
                printf("%d ",a[i][j]);
            }
            else{
                printf("%d\n",a[i][j]);
            }
        }
    }
    return 0;
}



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

int main(void){
    ll n;
    cin >> n;
    if (n == 0){
        cout << 0 << endl;
        return 0;
    } 
    vector<char>s;
    while(n != 1){
        ll div = ceil(double(n)/(-2));
        ll mod = n - div * (-2);
        // cout << div << ' ' << mod << endl;
        if(mod == 0) s.push_back('0');
        else s.push_back('1');
        n = div;
    }
    s.push_back('1');
    for(int i=s.size()-1;0<=i;i--){
        cout << s[i];
    }
    cout << endl;
    return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
typedef tuple<int, int, int> Q;


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

    ll _max = -1;
    ll _min = INF;

    rep(i, n) {
        ll a;
        cin >> a;
        _max = max(_max, a);
        _min = min(_min, a);
    }
    cout << _max - _min << endl;

}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

int main(){

	long ans;
	long x , y;

	cin >> x >> y;

	ans = x * (y - 1);

	if (x % y == 0) ans = -1;

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
using namespace std;
int to_int(string s){
    int x;
    stringstream geek(s);
    geek >> x;
    return x;
}
int max3(int a,int b,int c){
    if (a > b && a > c){
        return a;
    }else if(b > a && b > c){
        return b;
    }else if(c > a && c > b){
        return c;
    }
}
int check(int a,int b,int c){
    if (a > b && a > c){
        return b+c;
    }else if(b > a && b > c){
        return a+c;
    }else if(c > a && c > b){
        return a+b;
    }
}
int check2(int a,int b,int c){
    if (a == b && max3(a,b,c) == a){
        return c;
    }else if(a == c && max3(a,b,c) == a){
        return b;
    }else if(c == b && max3(a,b,c) == c){
        return a;
    }
}
long long int drujba=0;
void solve(int a,int b,int c){
    if(a==b && max3(a,b,c) == a|| a == c && max3(a,b,c) == a|| c == b && max3(a,b,c) == c){
        cout << max3(a,b,c) + 1ll *check2(a,b,c)/2 << "\n";
    }else{
        if(max3(a,b,c) <= check(a,b,c)){
            cout << max3(a,b,c) << "\n";
        }else{
            cout << check(a,b,c) << "\n";
        }
    }
}
int main(){
    int a,b;
    cin >> a >> b;
    int c,d;
    cin >> c >> d;
    if(c == a+1){
        cout << 1;
    }else{
        cout << 0;
    }
}


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

#define PrintLn(X) cout << X << endl
int main(void)
{
	int x, a, b;
	cin >> x >> a >> b;
	if(abs(x-a)<abs(x-b)){
		PrintLn("A");
	}else{
		PrintLn("B");
	}
	return 0;
}


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

int main() {
    string T;
    int doctor = 0;
    cin >> T;
    for (int i = 0; i < T.size(); i++){
        if(T.at(i) == '?'){
        T.at(i) = 'D';
        }
    }
    cout << T << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define MOD 100000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
inline ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ll char_to_ll(char c) { return (int)(c - '0'); }
inline ll string_to_ll(string s) { return atoi(s.c_str()); }
inline bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    ll N;
    cin >> N;
    set<string> S;
    rep(i, 0, N){
        string s;
        cin >> s;
        S.insert(s);
    }

    cout << S.size() << endl;

    return 0;
}


Measured memory_bytes: 19180
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 100000 + 10;
int n,W,w[N],v[N];
int dp[102][100002];
int main() {
	scanf("%d%d",&n,&W);
	for(int i=1;i<=n;i++)scanf("%d%d",&w[i],&v[i]);
	for(int i=0;i<102;i++)for(int j=0;j<100002;j++)dp[i][j]=1e9+7;
	dp[0][0]=0;	
	for(int i=0;i<n;i++){
		for(int j=0;j<100002;j++){
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
			if(j+v[i+1]<100002) dp[i+1][j+v[i+1]]=min(dp[i+1][j+v[i+1]],dp[i][j]+w[i+1]);
		}
	}
	for(int i=100001;i>=0;i--)if(dp[n][i]<=W)return !printf("%d\n", i);
}


Measured memory_bytes: 40064
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, x, n) for(decltype(x) i = (x); i < (n); i++)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

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

	int w, h, n;
	cin >> w >> h >> n;

	vvi M(h, vi(w));

	REP(i, 0, n) {
		int x, y, a;
		cin >> x >> y >> a;

		if (a == 1) {
			REP(i, 0, h) {
				REP(j, 0, x) {
					M[i][j] = 1;
				}
			}
		} else if (a == 2) {
			REP(i, 0, h) {
				REP(j, x, w) {
					M[i][j] = 1;
				}
			}
		} else if (a == 3) {
			REP(i, 0, y) {
				REP(j, 0, w) {
					M[i][j] = 1;
				}
			}
		} else {
			REP(i, y, h) {
				REP(j, 0, w) {
					M[i][j] = 1;
				}
			}
		}
	}

	int ans = 0;
	REP(i, 0, h) {
		REP(j, 0, w) {
			if (M[i][j] == 0) ans++;
		}
	}

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

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    miti = [set() for _ in range(N)]
    for i in range(M):
        a = A[i] - 1
        b = B[i] - 1
        miti[a].add(b)
        miti[b].add(a)

    res = 0
    for i in range(N):
        jibunn = H[i]
        ok = True
        for aite in miti[i]:
            if H[aite] >= jibunn:
                ok = False
        if ok:
            res += 1

    print(res)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, H, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 106176