akhauriyash/Code-Regression huggingface dataset:
from operator import itemgetter
N, K = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort(key = itemgetter(0))
B_sum = 0
for i in range(N):
  B_sum += AB[i][1]
  if B_sum >= K:
    print(AB[i][0])
    exit()

Measured memory_bytes: 29096
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>

char first[300][300];

bool isGoodBoard(const uint32_t N, const uint32_t A, const uint32_t B) {
	for (uint32_t i = 0; i < N; i++) {
		for (uint32_t j = i; j < N; j++) {
			if (first[(A + i) % N][(B + j) % N] != first[(A + j) % N][(B + i) % N]) {
				return false;
			}
		}
	}

	return true;
}

int main(void) {
	uint32_t N;
	uint32_t goodCount = 0;

	scanf("%"PRIu32"\n", &N);
	for (uint32_t rowIdx = 0; rowIdx < N; rowIdx++) {
		for (uint32_t colIdx = 0; colIdx < N; colIdx++) {
			scanf("%c", &(first[rowIdx][colIdx]));
		}
		if (rowIdx != N-1)
			scanf("\n");
	}

	for (uint32_t A = 0; A < N; A++) {
		if (isGoodBoard(N, A, 0)) {
			goodCount += N - A;
		}
	}
	for (uint32_t B = 1; B < N; B++) {
		if (isGoodBoard(N, 0, B)) {
			goodCount += N - B;
		}
	}

	printf("%"PRIu32, goodCount);

	return 0;
}

Measured memory_bytes: 256
//归并排序及求逆序对
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int N=2E3+7;
typedef long long ll;
ll a[N] ,b[N];//b为辅助数组
ll cnt;
void merge_sort(ll l , ll r)
{
    if(r-l > 0)
    {
        ll mid = (l+r) / 2 ;
        ll i = l; 
        ll p = l , q = mid+1;
        merge_sort(l , mid);
        merge_sort(mid+1 , r);
        while(p<=mid || q<=r)
        {
            if(q>r || (p<=mid && a[p]<=a[q]))
                b[i++] = a[p++];
            else
            {
                b[i++] = a[q++];
                cnt += mid -p +1;
            }
        }
        for(i = l ; i <= r; i++)
            a[i] = b[i];
    }
}
int main()
{
    ll n,k;
    cin >> n>>k;
    for(int i = 1 ; i <= n; i ++)
        cin >> a[i];
    cnt = 0;
    merge_sort(1 , n);
    int cnt2=0;
    for(int i=1;i<=n;i++)
    	for(int j=1;j<=n;j++){
    		if(a[i]>a[j])
    			cnt2++;
		}
	if(k&1) {
		int x=(k-1)/2;
		printf("%d\n",(cnt%mod*k%mod+k%mod*x%mod*cnt2%mod)%mod);
    }
	else {
		int y=k/2;
		printf("%d\n",(cnt%mod*k%mod+(k-1)%mod*y%mod*cnt2%mod)%mod);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   int A,B,C,K;
   cin >> A >> B >> C >> K;
   if(K<=A) cout << K;
   else if (K>A && K<= (A+B)) cout << A;
   else cout << A - (K-(A+B));
   
   return 0;
}

Measured memory_bytes: 3596
s = raw_input().strip()
l = len(s)
t = 'gp' * (l / 2 * 2)
w = 0
for i in xrange(l):
    if s[i] == 'g' and t[i] == 'p':
        w += 1
    if s[i] == 'p' and t[i] == 'g':
        w -= 1
print w


Measured memory_bytes: 2948
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std; 
int n,m,i;
ll x,totx,toty;
int main()
{
    //freopen("sol.in","r",stdin);
    //freopen("sol.out","w",stdout);
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
    	cin>>x;
    	totx+=x*(i-(n-i-1));
    	totx%=mod;
    }
    for(i=0;i<m;i++)
    {
    	cin>>x;
    	toty+=x*(i-(m-i-1));
    	toty%=mod;
    }
    cout<<(totx*toty)%mod<<endl;
    return 0;
}

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

#define LL long long

LL gcd(LL y, LL x){
	if(y<x)swap(y,x);

	
	if(x==0)return y;
	return gcd(x, y%x);
}

int main(){
	int n;	cin>>n;
	LL ans;	cin>>ans;
	for(int i=1;i<n;i++){
		LL t;	cin>>t;
		ans=ans/gcd(ans,t)*t;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  string N;
  cin >> N;
  vector<vector<ll>> dp(N.size(),vector<ll>(2,0));
  rep(i,(ll)N.size()){
    if(i==0){
      dp.at(i).at(0)=min((N.at(i)-'0'),11-(N.at(i)-'0'));
      dp.at(i).at(1)=min((N.at(i)-'0')+1,10-(N.at(i)-'0'));
    }else{
      dp.at(i).at(0)=min(dp.at(i-1).at(0)+(N.at(i)-'0'),dp.at(i-1).at(1)+10-(N.at(i)-'0'));
      dp.at(i).at(1)=min(dp.at(i-1).at(0)+(N.at(i)-'0')+1,dp.at(i-1).at(1)+9-(N.at(i)-'0'));
    }
  }
  cout << dp.at((ll)N.size()-1).at(0) << endl;
}

Measured memory_bytes: 58856
// abc060_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, T;
    cin >> N >> T;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    ll ans = 0;
    ll l = 0;
    ll r = 0;
    REP(i, N){
        if (r < A[i]){
            ans += r - l;
            l = A[i];
            r = A[i] + T;
        } else {
            r = A[i] + T;
        }
    }
    ans += r - l;
    print(ans);

    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    char a;
    cin >> a;

    if (int('a') <= int(a) && int(a) <= int('a') + 26)
    {
        cout << "a" << endl;
    }
    else
    {
        cout << "A" << endl;
    }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

V<> sieve(int n) {
  V<bool> b((n + 1) / 3, true);
  V<> res{2, 3};
  for (int p = 5, d = 2; p * p < n; p += d, d = 6 - d) if (b[p / 3]) {
    for (int i = 5 * p, d = 2 * p; i < n; i += d, d = 6 * p - d) b[i / 3] = false;
  }
  for (int p = 5, d = 2; p < n; p += d, d = 6 - d) if(b[p / 3]) res.push_back(p);
  while (!res.empty() and res.back() >= n) res.pop_back();
  return res;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  auto ps = sieve(1e5);
  int m, a, b;
  while (cin >> m >> a >> b, m) {
    int mx = 0, rp = -1, rq = -1;
    for (int p : ps) for (int q : ps) {
      if (p * q > m) break;
      if (p <= q and a * q <= b * p) {
        if (p * q > mx) {
          mx = p * q;
          rp = p, rq = q;
        }
      }
    }
    cout << rp << ' ' << rq << '\n';
  }
}


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

typedef long long ll;
const int mod = 1e9 + 7;

ll A, B;

ll calc (ll x) {
    if (x < 0) return 0;
    x++;

    // 2^50 くらい
    ll ans = 0;
    for (int i = 0; i < 50; i++) {
        ll loop = (1LL << (i + 1));
        ll cnt = (x / loop) * (loop / 2);

        cnt += max(0LL, (x % loop) - (loop / 2));
        if (cnt % 2 == 1) {
            ans += 1LL << i;
        }
    }

    return ans;
}

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

    ll ans = calc(B) ^ calc(A - 1);
    cout << ans << endl;
}

Measured memory_bytes: 384
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::{min, max};

#[fastout]
fn main() {
    input! {
    n: usize,
    t: usize,
    mut ab: [(usize, usize); n]
    }
    ab.sort();
    let mut dp = vec![vec![0; 6005]; n + 1];
    for i in 0..n {
        let (a, b) = ab[i];
        for j in 0..t {
            dp[i + 1][j + a] = max(dp[i][j + a], dp[i][j] + b);
        }
        for j in 0..6005 {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }
    println!("{}", dp[n].iter().max().unwrap());
}


Measured memory_bytes: 142968
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	ans := make([]int, 3)
	l := make([][]int, n)
	for i := 0; i < n; i++ {
		t := make([]int, 3)
		t[0], _ = strconv.Atoi(stringLineScan())
		t[1], _ = strconv.Atoi(stringLineScan())
		t[2], _ = strconv.Atoi(stringLineScan())
		l[i] = t
	}
	for i := 0; i <= 100; i++ {
		for j := 0; j <= 100; j++ {
			t := make([]int, 0)
			for k := 0; k < n; k++ {
				x, y, h := l[k][0], l[k][1], l[k][2]
				if h > 0 {
					t = append(t, h+abs(x-i)+abs(y-j))
				}
			}
			if all(t) {
				z := t[0]
				f := true
				for k := 0; k < n; k++ {
					x, y, h := l[k][0], l[k][1], l[k][2]
					if larger(z-abs(x-i)-abs(y-j), 0) != h {
						f = false
					}
				}
				if f {
					ans[0], ans[1], ans[2] = i, j, t[0]
				}
			}
		}
	}
	fmt.Println(strings.Trim(fmt.Sprint(ans), "[]"))
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func all(x []int) bool {
	if len(x) == 0 {
		return false
	} else {
		f := true
		y := x[0]
		for _, i := range x {
			if i != y {
				f = false
				break
			}
		}
		return f
	}
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}


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

using namespace std;
int n,k;
double a[200100];

int main()
{
    cin >> n >> k;;
    for(int i = 0;i<n;i++)  cin >> a[i];
    double Ans = 0,sum = 0;
    int c = 0;
    for(int i = 0;i<n;i++){
        sum+=((a[i] * (a[i] + 1))/2)/a[i];
        c++;
        if(c == k)  {
                Ans = max(Ans , sum);
                sum-=((a[i - k + 1] * (a[i - k + 1] + 1))/2)/a[i - k + 1];
                c--;
        }
    }
    cout << setprecision(15) << fixed << Ans;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;

int main()
{
	fastIO;
	ll mod = 1e9 + 7;
	ll ans = 0;
	ll sum = 0;
	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i=0; i<n; i++) {
		cin >> a[i];
		sum += a[i];
		sum %= mod;
	}
	for (int i=0; i<n; i++) {
		sum -= a[i];
		if (sum < 0) sum += mod;
		ans = ans + (a[i]*sum)%mod;
		ans %= mod;
	}
	cout << ans << '\n';
}

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

using namespace std;

int main(){
	string a,b;
	cin >> a >> b;
	int ans = 0;
	for(int i = 0; i < a.size(); i++){
		ans += (a[i] != b[i]);
	}
	cout << ans << "\n";
	return 0;
}


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

#define ll long long

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin>>n;
	int64_t sum=0;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j+=i){
				sum+=j;	
		}
	}
	cout<<sum;
}

Measured memory_bytes: 3596
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] s = new String[h + 2];
		for (int i = 1; i < h + 1; i++) {
			s[i] = "k" + sc.next() + "k";
		}
		for (int i = 0; i < w + 2; i++) {
			s[0] += "k";
			s[h + 1] += "k";
		}
		char[][] ch = new char[h + 2][w + 2];
		for (int i = 0; i < h + 2; i++) {
			for (int j = 0; j < w + 2; j++) {
				ch[i][j] = s[i].charAt(j);
			}
		}
		int count = 0;
		for (int i = 0; i < h + 2; i++) {
			for (int j = 0; j < w + 2; j++) {
				if (ch[i][j] == '.') {
					if (ch[i - 1][j - 1] == '#') {
						count++;
					}
					if (ch[i - 1][j] == '#') {
						count++;
					}
					if (ch[i - 1][j + 1] == '#') {
						count++;
					}
					if (ch[i][j - 1] == '#') {
						count++;
					}
					if (ch[i][j + 1] == '#') {
						count++;
					}
					if (ch[i + 1][j - 1] == '#') {
						count++;
					}
					if (ch[i + 1][j] == '#') {
						count++;
					}
					if (ch[i + 1][j + 1] == '#') {
						count++;
					}
				}
				if (ch[i][j] == '#') {
					System.out.print("#");
				} else if (ch[i][j] == '.') {
					System.out.print(count);
				}
				count = 0;
			}
			if (i != 0 || i != h + 1) {
				System.out.println("");
			}
		}
	}
}


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

#define NDEBUG
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == 0) {
        v.clear();
        return 0;
    }
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

ll solve(string s){
    int L = s.size();

    vector<char> without_x;
    without_x.reserve(L);
    rep(i,L) if (s[i] != 'x') without_x.pb(s[i]);
    int M = without_x.size();
    rep(i,M) if (without_x[i] != without_x[M-1-i]) return -1;

    vi xs(M+1, 0);
    int pos = 0;
    rep(i,L) {
        if (s[i] == 'x') xs[pos]++;
        else ++pos;
        assert(pos <= M);
    }
    int ans = 0;
    for (int i=0,j=M; i<j; ++i,--j) {
        ans += abs(xs[i] - xs[j]);
    }
    return ans;
}

int main() {
    string s;cin >> s;
    cout << solve(s) << endl;
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define END getchar();getchar();return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

signed main() {
	int n, c, k, t[114514], ans = 0;
	cin >> n >> c >> k;
	for (int i = 0; i < n; i++) {
		cin >> t[i];
	}
	sort(t, t + n);
	int cnt = 0, st = t[0];
	for (int i = 0; i < n; i++) {
		if (cnt < c&&t[i] - st <= k) {
			cnt++;
		}
		else {
			ans++;
			cnt = 1;
			st = t[i];
		}
	}
	cout << ans + 1 << endl;
	END;
}


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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int K;
    string S;
    ist >> K;
    ist >> S;

    /* ------- 計算 ------- */

    if (S.length() <= K)
    {
        ost << S << endl;
        return;
    }

    for (int i = 0; i < K; i++)
    {
        ost << S[i];
    }

    ost << "..." << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 3608
#include <iostream>
#include <cmath>
#include<bits/stdc++.h>
using namespace std;
double dp(double x, double y, double a, double b)
{
return sqrt(pow(x - a, 2) + pow(y - b, 2));
}
int fact(int n) { 
   if ((n==0)||(n==1))
      return 1;
   else
      return n*fact(n-1);
}
int main() {
int n;
cin >> n;
int arr[n][2];
for (int i=0;i<n;i++)
    cin >> arr[i][0]>>arr[i][1];
int fac=1;
double dis=0;
for(int i=0;i<n;i++)
{
    for(int j=0;j<n;j++)
    {
        if(i!=j)
        dis=dis+dp(arr[i][0],arr[i][1],arr[j][0],arr[j][1]);
    }
}

cout << fixed<<setprecision(8)<<dis/n;
	
}

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

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

long long MOD = 1000000000 + 7;

bool compare(pii x, pii y){
  return x.first < x.second;
}
int main(){
  cout << setprecision(10);

  ll N,D,A;
  cin >> N >> D >> A;

  vector<pii> v;
  for(int i = 0; i < N; i++){
    ll tmp1,tmp2;
    cin >> tmp1 >> tmp2;
    v.push_back(make_pair(tmp1, (tmp2+A-1)/A));
  }

  sort(v.begin(), v.end());
  auto tmp_last_monstar = v[v.size()-1];
  v.push_back(make_pair(tmp_last_monstar.first + 2*D + 2, 0));


  vector<ll> x(N);
  vector<ll> d(N+1,0);
  vector<ll> a(N);
  vector<ll> x_2D(N);
  for(int i = 0; i < N; i++){
    x[i] = v.at(i).first;
    a[i] = v.at(i).second;
  }

  for(int i = 0; i < N; i++){
    auto itr = lower_bound(x.begin(), x.end(), x[i] + 2*D+1);
    int index = itr - x.begin();
    x_2D[i] = index;
    // cerr << "D: " << D << " x[i]: " << x[i] << " x_2D[i]: " << x_2D[i] << endl;
  }

  ll ans = a[0];
  d[0] = a[0];
  d[x_2D[0]] -= a[0];
  for(int i = 1; i < N; i++){
    d[i] = d[i-1] + d[i];
    a[i] -= d[i];
    if(a[i] > 0){
      ans += a[i];
      d[i] += a[i];
      d[x_2D[i]] -= a[i];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 10476
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,arr[100000];
  cin>>n;
  for(int i=0;i<n;i++) cin>>arr[i];
 
  int cnt[3]={1,0,0},idx=0,ans=0;
  for(int i=1;i<n;i++){
    if(arr[i-1]!=arr[i])cnt[idx%3]++;
    else ans=max(ans,cnt[0]+cnt[1]+cnt[2]),cnt[(idx+1)%3]=1,idx++;
  }
  ans=max(ans,cnt[0]+cnt[1]+cnt[2]);
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 1548
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
int a,b,c,x,y;
signed main(){
  cin>>a>>b>>c>>x>>y;
  int res=0;
  res+=min(x,y)*(min(a+b,2*c));
  if(x<y){
    res+=min(b,2*c)*(y-x);
  }
  else{
    res+=min(a,2*c)*(x-y);
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

#define M 1000000007

char a[100004];
ll dp[13], dp2[13];

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

    scanf("%s", a);
    int n = strlen(a);
    memset(dp, 0, sizeof(dp));
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        memset(dp2, 0, sizeof(dp2));
        int d = (a[i] == '?' ? -1 : a[i]-'0');
        for (int k = 0; k < 10; k++)
            if (d == -1 || k == d)
                for (int j = 0; j < 13; j++) {
                    dp2[(j*10+k)%13] += dp[j];
                    dp2[(j*10+k)%13] %= M;
                }
        memcpy(dp, dp2, sizeof(dp));
    }

    cout << dp[5] << endl;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,n,i,j,k,tot=0;
	cin>>a>>b>>c>>n;
	for (i=0;i<=a;i++)
		for (j=0;j<=b;j++)
			for (k=0;k<=c;k++)
				if (i*500+j*100+k*50==n)
					tot++;
	cout<<tot;
}

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

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<vector<int>> data(N, vector<int>(M));
    vector<int> sum(M, 0);
    map<int, int> data2;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        data2[i] = a;
        for (int j = 0; j < M; j++) {
            cin >> data.at(i).at(j);
            sum.at(j) += data.at(i).at(j);
        }
    }
    for (int i = 0; i < M; i++) {
        if (sum.at(i) < X) {
            cout << -1 << endl;
            return 0;
        }
    }
    int ans = INF, keep = 0;
    bool can = true;
    for (int bit = 0; bit < (1<<N); bit++) {
        vector<int> keep2(M, 0);
        can = true;
        keep = 0;
        for (int i = 0; i < N; i++) {
            if (bit & (1<<i)) {
                for (int j = 0; j < M; j++) {
                    keep2.at(j) += data.at(i).at(j);
                }
                keep += data2.at(i);
            }
        }
        for (int i = 0; i < M; i++) {
            if (keep2.at(i) < X) {
                can = false;
            }
        }
        if (can && ans > keep) {
            ans = keep;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> a(M), b(M);
    vector<vector<ll>> c(M);
    vector<vector<ll>> dp(5000,vector<ll>(1001,1e18));
    dp[0][0] = 0;
    ll C;
    rep(i,M){
        cin >> a[i] >> b[i];
        rep(j,b[i]){
            cin >> C;
            c[i].push_back(--C);
        }
    }
    //cout << "bb" <<endl;
    rep(i,M){
        ll k=0;
        rep(j,b[i]){
            k = k | (1LL << c[i][j]);
        }
        rep(j,(1LL << N)){
            dp[j][i+1] = dp[j][i];
        }
        rep(j,(1LL << N)){
            dp[(j|k)][i+1] = min(dp[j|k][i+1], dp[j][i] + a[i]);
        }
    }
    if(dp[((1LL << N) - 1LL)][M] == 1e18){
        cout << -1 << endl;
        return 0;
    }
    cout << dp[((1LL << N) - 1LL)][M] << endl;
}

Measured memory_bytes: 42960
house = [[[0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0]],
         [[0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0]],
         [[0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0]],
         [[0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0]]
          ]

n = int(input())
for i in range(0,n):
    b,f,r,v = map(int,input().split())
    house[b-1][f-1][r-1] += v

for i in range(0,len(house)):
    for j in range(0, len(house[i])):
        print(' '+' '.join(map(str,house[i][j])))
    if (i<len(house)-1):
        print('#'*20)



Measured memory_bytes: 5620
#!/usr/bin/perl

$line = 0;
while (<>) {
    chomp;
    if($line == 0) {
        ($x, $a, $b) = split /\s+/, $_
    } else {
    }
    $line++;
}

if(abs($x - $a) < abs($x - $b)) {
    print "A\n";
} else {
    print "B\n";
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

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

  string s;
  cin >> s;

  ll sum = 0;

  rep(i, s.size()) {
    int x = int(s[i] - '0');
    sum += x;
    sum %= 9;
  }

  if (sum % 9 == 0) puts("Yes");
  else puts("No");

  return 0;
}


Measured memory_bytes: 3744
#include <stdio.h>

int main() {
	 long long int n, notfb, sum = 0, i;
	 scanf("%lld", &n);
	 	for(i = 0 ;i<=n; i++){
	 		if(i%3 == 0 || i%5 == 0){
	 			continue;
			 }
			 else {
			 	sum += i;
			 }
		 }
	
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 1736
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        solve(sc);
    }

    private static void solve(Scanner sc) {
        int x = Integer.parseInt(sc.nextLine().split(" ")[0]);
        int count = 1;
        int arg = x;
        while (true) {
            if (arg % 360 == 0) {
                break;
            }
            arg += x;
            count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 35736
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

vector<ll> vec;

void go(ll val, int len) {
	if (len == 11) return;

	vec.push_back(val);
	for (int i = max(0ll, val % 10 - 1); i <= min(9ll, val % 10 + 1); ++i) {
		ll nxt = val * 10 + i;
		go(nxt, len + 1);
	}
}
int main() {
	fastio;
	int K;
	cin >> K;

	for (int i = 1; i <= 9; ++i) go(i, 1);
	sort(all(vec));

	cout << vec[K - 1];

	return 0;
}

Measured memory_bytes: 2420
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> as(n); cin >> as;
    vector<ll> bs(n); cin >> bs;
    if(accumulate(as.begin(), as.end(), 0ll) < accumulate(bs.begin(), bs.end(), 0ll)){
        cout << -1 << '\n';
        return 0;
    }
    vector<ll> diffs;
    for(int i = 0; i < n; i++){
        ll diff = as[i] - bs[i];
        if(diff > 0){
            diffs.push_back(diff);
        }
    }
    sort(diffs.begin(), diffs.end());
    bool used = false;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        ll rq = bs[i] - as[i];
        if(rq <= 0){ continue; }
        cnt++;
        while(rq){
            ll mi = min(diffs.back(), rq);
            rq -= mi;
            diffs.back() -= mi;
            used = true;
            if(diffs.back() == 0){
                diffs.pop_back();
                used = false;
                cnt++;
            }
        }
    }
    cout << cnt + used << '\n';
}


Measured memory_bytes: 2428
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int N = sc.nextInt();
            Map<Long, Integer> cnt = new HashMap<>();
            Set<Long> set = new HashSet<>();
            for (int i = 0; i < N; i++) {
                long x = sc.nextLong();
                int nowCnt = cnt.getOrDefault(x, 0);
                nowCnt++;
                cnt.put(x, nowCnt);
                set.add(x);
            }

            List<Long> sortList = new ArrayList<>(set);
            sortList.sort(Long::compareTo);

            long ans = 0;
            List<Long> hen = new ArrayList<>();

            for (int i = sortList.size() - 1; hen.size() < 2 && i >= 0; i--) {
                long len = sortList.get(i);
                if ( cnt.get(len) >= 2 ) {
                    hen.add(len);
                }
                if ( cnt.get(len) >= 4 ) {
                    hen.add(len);
                }
            }
            if ( hen.size() >= 2 ) {
                ans = hen.get(0) * hen.get(1);
            }

            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 74264
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ul n, m, d;
  cin >> n >> m >> d;
  ul ans = 0;
  if (d == 0) ans = n;
  else ans = (n-d)*2;
  ans *= (m-1);
  cout << ans * 1.0 / n / n << endl;
  return 0;
}


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

int main(){
    int N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    A--;
    B--;
    C--;
    D--;
    string S;
    cin >> S;
    
    bool yesA = true;
    bool yesB = true;

    int cnt = 0; // check # count
    for(int i = A; i <= C; i++) {
        if(S[i] == '#')cnt++;
        else cnt=0;

        if(cnt == 2){
            yesA = false;
            break;
        }
    }

    cnt=0;
    for(int i = B; i <= D; i++) {
        if(S[i] == '#')cnt++;
        else cnt=0;

        if(cnt == 2){
            yesB = false;
            break;
        }
    }

    if(yesA == false || yesB == false){
        cout << "No" << endl;
        return 0;
    }

    if(C < D){
        cout << "Yes" << endl;
        return 0;
    }

    cnt = 0;
    for(int i=B-1; i <= D+1; i++){
        if(S[i] == '.')cnt++;
        else cnt = 0;

        if(cnt == 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
#! /usr/bin/env python3

n, k = map(int, input().split())
M = [[7*i+j-7 for j in range(1, 7+1)] for i in range(1, min(n+1, 14))]
cnt = 0
f = lambda i, j : sum(M[i+y][j+x] for y in range(3) for x in range(3)) % 11 == k
h = [0] * 11
for i in range(min(max(0, n-2), 11)):
    for j in range(7-2):
        if f(i, j) :
            h[i] += 1
cnt = sum(h) * ((n-2) // 11)
for i in range((n-2) % 11):
    cnt += h[i]
print(cnt)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 3e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;

int n;
int a[maxn];
ll dp[maxn][10][2];

int main() {
    n=read();
    for(int i=1; i<=n; ++i) a[i]=read();
    memset(dp,-inf,sizeof(dp));
    dp[0][5][0]=0;
    for(int i=1; i<=n; ++i) {
        for(int j=0; j<10; ++j) {
            if(j+1<10) {
                dp[i][j+1][1]=max(dp[i][j+1][1],dp[i-1][j][0]+a[i]);
            }
            if(j) {
                dp[i][j-1][0]=max({dp[i][j-1][0],dp[i-1][j][0],dp[i-1][j][1]});
            }
        }
    }
    cout<<max(dp[n][5-(n&1)][0],dp[n][5-(n&1)][1])<<endl;
}

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

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    string s,t,c;cin>>s>>t>>c;
    cout<<'A'<<t[0]<<'C'<<endl;return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n, m, a[5000], b[5000], cnt[5000] = {};
  cin >> n >> m;
  for(int i = 0 ; i < n ; i++ ){
    cin >> a[i];
  }
  for(int i = 0 ; i < m ; i++ ){
    cin >> b[i];
  }
  for(int i = 0 ; i < n ; i++ ){
    int j = 0;
    while(a[j] > b[i]) j++;
    cnt[j]++;
  }
  cout << distance(cnt,max_element(cnt,cnt+n)) + 1 << endl;
}

Measured memory_bytes: 1200
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#define MIN 1<<31-1
#define HMAX 1000000000000000000
#define MOD 1000000007
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RSET(s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
typedef long long int ll;
using namespace std;
int Z[300000];int V[300000]; 
int main()
{
	int n;cin>>n;int M=0;
	for(int i=0;i<n;i++)
		{
			cin>>Z[i];
			M=max(M,Z[i]);
		}
	int Q=MIN;int ans1;
	for(int i=0;i<n;i++)
	{
		if(Z[i]==M) continue;
		int now=abs(Z[i]*2-M);
		if(Q>now)
		{
		Q=now;
		ans1=Z[i];
		}
	}
	cout<<M<<" "<<ans1;
}

Measured memory_bytes: 640
nmx = [int(x) for x in input().split()]
n = nmx[0]
m = nmx[1]
x = nmx[2]

lis = []
for i in range(0,n):
    lis.append([int(x) for x in input().split()])


def dp(i, cost, scores):
    if i == n:
        ok = True
        for j in range(0, m):
            if scores[j] < x:
                ok = False
        if ok == True:
            return(cost)
        else:
            return(999999999999)
    else:
        newCost = cost + lis[i][0]
        newScores = [0]*m
        for j in range(0,m):
            newScores[j] = scores[j] + lis[i][j+1]
        return(min([dp(i+1,cost,scores), dp(i+1,newCost,newScores)]))

temp = [0]*m

yeet = (dp(0,0,temp))
if yeet == 999999999999:
    print(-1)
else:
    print(yeet)
    


Measured memory_bytes: 9252
#include<iostream>
#include<cstdio>

int N;

int main()
{
	int i,x;
	scanf("%d",&N);
	int cnt0=0,cnt2=0,cnt4=0;
	for(i=1;i<=N;i++)
	{
		scanf("%d",&x);
		if(x%4==0) cnt4++;
		else if(x%2==0) cnt2++;
		else cnt0++;
	}
	if((cnt2&&cnt4>=cnt0)||(cnt2==0&&cnt4>=cnt0-1)) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

string  S;
int ans;

signed main()
{
	cin >> S;
	string c = "CODEFESTIVAL2016";
	rep(i,S.length()) {
		if (S[i] != c[i]) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32), allocatable:: f(:)
    integer(int32):: x,y,z,n,v,i


    read*, n
    allocate(f(n), source=0)

    do x=1,100
        do y=1,100
            do z=1,100
                v = x*x + y*y + z*z +x*y + y*z + z*x
                if (v <= n) f(v)=f(v)+1
            end do
        end do
    end do

    do i=1,n
        print'(i0)', f(i)
    end do
end program main

Measured memory_bytes: 2924
from copy import *
from sys import *
import math
import queue
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)

#dp[i][j]: iまでからj枚えらんで和がkになるのは何通り
def main():
	s =  input()
	if(len(set(s))==2):
		print('Yes')
	else:
		print('No')

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Measured memory_bytes: 63596
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    ll a,b,c;
    cin>>a>>b>>c;
    if(c-b-a>0&&llpow(c-b-a,2)-4*a*b>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
int gcd(int x,int y){
	int d;
	d=(x%y);
	while(d!=0){
			x=y;
			y=d;
			d=(x%y);
	}
	return y;
}
int main(){
    int x,y,d;
	scanf("%d%d",&x,&y);
	if(x>y)d=gcd(x,y);
	else if(x<=y)d=gcd(x,y);
	printf("%d\n",d);
    return 0;
}


Measured memory_bytes: 2140
#include <iostream>

using namespace std;

const int N = 8;

short row[N],col[N],dpos[2*N-1],dneg[2*N-1];

enum {
	FREE = 20,NOT_FREE
};

bool Graph[N][N];

void initialize() {
	for (int i=0;i<N;i++) {
		for (int j=0;j<N;j++) {
			Graph[i][j] = false;
		}
	}
	
	for (int i=0;i<N;i++) {
		row[i] = col[i] = FREE;
	}
	
	for (int i=0;i<2*N-1;i++) {
		dpos[i] = dneg[i] = FREE;
	}
}

void printQ() {
	for (int i=0;i<N;i++) {
		for (int j=0;j<N;j++) {
			if (Graph[i][j] && row[i] != j) return;
		}
	}
	
	for (int i=0;i<N;i++) {
		for (int j=0;j<N;j++) {
			if (row[i] == j) {
				cout << "Q";
			} else {
				cout << ".";
			}
		}
		cout << endl;
	}
}

void solve(int i) {
	if (i == N) {
		printQ();
		return;
	}
	
	for (int j=0;j<N;j++) {
		if (row[i] == FREE && col[j] == FREE && dpos[i+j] == FREE && dneg[i-j+N-1] == FREE) {
			row[i] = j;
			col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
			solve(i+1);
			row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
 		}
	}
}

int main() {
	initialize();
	int k;
	cin >> k;
	while (k--) {
		int x,y;
		cin >> x >> y;
		Graph[x][y] = true;
	}
	solve(0);
	return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

#include <boost/multiprecision/cpp_int.hpp>
namespace boost_multiprecision = boost::multiprecision;
#define CINT boost_multiprecision::cpp_int

int main(){
    iostream::sync_with_stdio(false);
    
    int A,B;
    cin >> A >> B;
    cout << ceil((double)B/A) << endl;
    
    return 0;
}


Measured memory_bytes: 3268
from bisect import bisect_left

N,M=map(int,input().split())
A=list(map(int,input().split()))

A.sort()

l=1
r=200000+1

def chk(x):
    c=0
    for la in A:
        y=bisect_left(A,x-la)
        c+=N-y
    if c>=M:
        return True
    else:
        return False



while l+1<r:
    mid=(l+r)//2
    if chk(mid):
        l=mid
    else:
        r=mid

AN=l

S=[0]*(N+1)

for i in range(N):
    S[i+1]=S[i]+A[i]

ans1=0
c=0
for la in A:
    ll = -1
    rr = N
    while ll + 1 < rr:
        mi = (ll + rr) // 2
        if A[mi] > AN - la:
            rr = mi
        else:
            ll = mi
    c+=N-rr
    ans1=ans1+la*(N-rr)+S[N]-S[rr]

ans=ans1+(M-c)*AN
print(ans)




Measured memory_bytes: 14636
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		for (int i=2; i<S.length(); i+=2){
			if (S.substring(0, (S.length()-i)/2).equals(S.substring((S.length()-i)/2, S.length()-i))){
				System.out.println(S.length()-i);
				return;
			}
		}
	}
}

Measured memory_bytes: 22612
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner teclado = new Scanner(System.in);
        int n = teclado.nextInt();
        int a = teclado.nextInt();
        int b = teclado.nextInt();
        int nb = (b*1);
        int na = (n*a);
        if(na <= nb){
            System.out.println(na);
        }else{
            System.out.println(nb);
        }
            
            
    }
    
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <utility>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

// 基本的な演算
namespace BasicMath {
    // 絶対値を求める
    static inline UInt Abs(const Int a);
    // 二つの値の最小値を求める関数
    static inline Int Min(const Int a, const Int b);
    // 絶対値を求める
    UInt Abs(const Int a) {
        return a > 0 ? a : -a;
    }
    // 二つの値の最小値を求める関数
    Int Min(const Int a, const Int b) {
        if (a <= b) {
            return a;
        } else {
            return b;
        }
    }
}
using namespace BasicMath;

// ビット演算
namespace Bits {
    // 整数x の 下から i 桁目が1かどうかを返す
    static inline bool IsFlagUp(Int x, Int i);
    // 整数x の 下から i 桁目が1かどうかを返す
    bool inline IsFlagUp(Int x, Int i) {
        return ((x & (1 << i)) != 0);
    }
}
using namespace Bits;

int main(void) {
    Int n, a, b, c;
    cin >> n >> a >> b >> c;
    VI l(n);
    for (Int i = 0; i < n; ++i) {
        cin >> l[i];
    }
    Int size = pow(2, n);
    VI bamboo(size);
    VI cost(size);
    for (Int i = 0; i < size; ++i) {
        bamboo[i] = 0;
        cost[i] = 0;
        for (Int j = 0; j < n; ++j) {
            if (IsFlagUp(i, j)) {
                bamboo[i] += l[j];
                cost[i]++;
            }
        }
    }
    VI da(size);
    VI db(size);
    VI dc(size);
    for (Int i = 1; i < size; ++i) {
        da[i] = Abs(bamboo[i] - a) + 10 * (cost[i] - 1);
        db[i] = Abs(bamboo[i] - b) + 10 * (cost[i] - 1);
        dc[i] = Abs(bamboo[i] - c) + 10 * (cost[i] - 1);
    }
    Int answer = INT_MAX;
    for (Int i = 1; i < size; ++i) {
        for (Int j = 1; j < size; ++j) {
            for (Int k = 1; k < size; ++k) {
                bool flag = true;
                for (Int x = 0; x < n; ++x) {
                    bool xa = IsFlagUp(i, x);
                    bool xb = IsFlagUp(j, x);
                    bool xc = IsFlagUp(k, x);
                    if (xa && xb) {
                        flag = false;
                    }
                    if (xb && xc) {
                        flag = false;
                    }
                    if (xc && xa) {
                        flag = false;
                    }
                }
                if (flag) {
                    answer = Min(answer, da[i] + db[j] + dc[k]);
                }
            }
        }
    }
    cout << answer << endl;
    return 0;
}



Measured memory_bytes: 4056
N,A,B,C=map(int,input().split())
L=[int(input()) for i in range(N)]
answ=10**9
for i in range(1<<N):
    for j in range(1<<N):
        M=[0]*4
        num=[0]*4
        for k in range(N):
            s=(1<<k)&i
            t=(1<<k)&j
            if s:
                if t:
                    continue
                else:
                    M[1]+=L[k]
                    num[1]+=1
            else:
                if t:
                    M[2]+=L[k]
                    num[2]+=1
                else:
                    M[3]+=L[k]
                    num[3]+=1
        ans=abs(A-M[1])+abs(B-M[2])+abs(C-M[3])
        for l in range(1,4):
            if num[l]==0:
                ans=10**9
            elif num[l]!=0:
                ans+=(num[l]-1)*10
        #print(M,num,ans)

        answ=min(ans,answ)
print(answ)

Measured memory_bytes: 45148
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int height[] = new int[N];
		for (int i = 0; i < N; i++) {
			height[i] = sc.nextInt();
		}

		int road[][] = new int[M][2];

		for (int i = 0; i < M; i++) {
			for (int c = 0; c < 2; c++) {
				road[i][c] = sc.nextInt();
			}
		}

		int goodnum[] = new int[N];
		//for (int i = 0; i < M; i++) {
			//for (int c = 0; c < 2; c++) {
				//goodnum[road[i][c]-1] = 9;
			//}
		//}

		for (int i = 0; i < M; i++) {
			if(height[road[i][0]-1] <= height[road[i][1]-1]) {
				goodnum[road[i][0]-1]=9;
			}
			if(height[road[i][1]-1] <= height[road[i][0]-1]) {
				goodnum[road[i][1]-1]=9;
			}
		}

		int ans = 0;
		for (int i = 0; i < N; i++) {
			if(goodnum[i] == 0) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 64120