akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<ll> a(3*n);
    for(auto &x:a)cin >> x;

    sort(a.begin(),a.end());

    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=a[3*n-2*i];
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

const int maxn = 112345;

int n, v, m, p;
int a[maxn];

int main() {
  scanf("%d%d%d%d", &n, &m, &v, &p);
  FOR(i, 1, n) scanf("%d", a + i);
  sort(a + 1, a + n + 1, greater<>());
  int lo = p, hi = n;
  while (lo < hi) {
    int mi = lo + hi + 1 >> 1;
    ll have = ll(v) * m - ll(p) * m;
    bool ok = true;
    FOR(i, p, n) if (i != mi) {
      int d = min(m, a[mi] + m - a[i]);
      if (d < 0) {
        ok = false;
        break;
      }
      have -= d;
    }
    if (have > 0 || !ok) hi = mi - 1;
    else lo = mi;
  }
  printf("%d", lo);
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn=330;
int a[maxn][maxn],n,lat[maxn],m,cnt[maxn],top[maxn];
struct node{
	int cnt,x,vis;
	node(int a,int b,int c){cnt=a;x=b;vis=c;}
	friend bool operator<(node a,node b){
		return a.cnt<b.cnt;
	}
};
int stac[maxn],topp;
	
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			scanf("%d",&a[i][j]);
	int ans=INT_MAX; 
	priority_queue<node>q;
	for(int i=1;i<=n;++i)cnt[a[i][1]]++,top[i]=1,lat[a[i][1]]=1;
	for(int i=1;i<=m;++i)q.push(node(cnt[i],i,1));
	while(q.size()){
		int x=q.top().x;
		if(q.top().vis!=lat[x]){q.pop();continue;}
		ans=min(ans,cnt[x]);
		q.pop();
		topp=0;
		for(int i=1;i<=n;++i)
			if(a[i][top[i]]==x){
				if(top[i]==m)continue;
				cnt[a[i][top[i]+1]]++;
				top[i]++;
				stac[++topp]=a[i][top[i]];
			}
		topp=unique(stac+1,stac+1+topp)-stac-1;
		for(int i=1;i<=topp;++i){
			lat[stac[i]]++;
			q.push(node(cnt[stac[i]],stac[i],lat[stac[i]]));
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1088
import sys

sys.setrecursionlimit(10 ** 7)


def dfs(v):
    if d[v] != -1:
        return d[v]
    res = -1
    for u in e[v]:
        res = max(res, dfs(u))
    res += 1
    d[v] = res
    return res


n, m = map(int, input().split())
e = tuple(set() for _ in range(n))
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    e[x].add(y)

d = [-1] * n
res = -1
for v in range(n):
    res = max(res, dfs(v))
print(res)


Measured memory_bytes: 71044
for i in range(int(input())):
    x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
    det = abs((y1-y2) * (x3-x4) - (x1-x2) * (y3-y4))
    if det<1e-12 :
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 7492
k,n = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
temp = 0
ls = []
for i in range(n-1):
    temp = a[i+1]-a[i]
    ls.append(temp)
    ans += temp
ls.append((k-a[-1])+a[0])
ans += (k-a[-1])+a[0]
lsm = max(ls)
lsi = ls.index(lsm)
if lsi+1 <= k:
    ans = ans - lsm
else:
    ans = ans - lsm + a[ls.index(lsm)+1]-a[ls.index(lsm)]
print(ans)

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

using namespace std;

bool c[129];

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
	{
		c[s[i]] = true;
	}
	if (c['N'] == c['S'] && c['E'] == c['W'])
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>    //C++の標準ライブラリのヘッダを全て読み込む
 
int main() {
    using std::cout;
    using std::endl;
    using std::cin;

    int m = 0;
    cin >> m;
    cout << (24 - m) + 24 << endl;

}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll a,b,c,d; cin >> a >> b >> c >> d;
  
  if(b+1 != d) cout << 1 << endl;
  else cout << 0 << endl;
  
  
}

Measured memory_bytes: 3612
//Solution By SlavicG
#include "bits/stdc++.h"
using namespace std;
 
#define ll                          long long
 
#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
 
#define fastio                      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define   endl                      "\n"

int main()
{
	int x;
	cin >> x;
	cout <<!x;
}

Measured memory_bytes: 3632
L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input()) - 1
print(L[K])

Measured memory_bytes: 3060
use proconio::input;

fn main() {
    input! {
        n: usize, mut m: u64,
        mut ab: [(u64, u64); n],
    }
    ab.sort_by_key(|v| v.0);
    let mut total = 0;
    for i in 0..n {
        let (a, b) = ab[i];
        if b <= m {
            total += a * b;
            m -= b;
        } else {
            total += a * m;
            m -= m;
        }
        if m <= 0 {
            break;
        }
    }
    println!("{}", total);
}


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

int main(){
  int d;
  cin >> d;
  
  if(d == 22) cout << "Christmas Eve Eve Eve" << endl;
  else if(d == 23) cout << "Christmas Eve Eve" << endl;
  else if(d == 24) cout << "Christmas Eve" << endl;
  else cout << "Christmas" << endl;
  
  return 0;
}

Measured memory_bytes: 256
N = input()
#N=119
list_N  = list(str((N)))
#list_N = list(map(int,list_N))
#print(list_N)
#swap_N = map(lambda i: i=1 if i == 9 else i=9, list_N)

#for i in list_N:
def swap(i):
    if i == "9":
        re = "1"
    elif i=="1":
        re = "9"
    return re

swap_N = list(map(swap, list_N))
print(int("".join(swap_N)))


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

long N, ans;
string S;

int main(void) {

    cin >> N >> S;

    for (long pin = 0; pin <= 999; pin++) {
        long x, y, z;
        z = pin % 10; 
        y = ((pin - z) % 100) / 10;
        x = (pin - 10*y - z) / 100;

        bool f, g, h;
        f = g = h = false;
        for (auto e: S) {
            if (!f && !g && !h) {
                if ((e - '0') == x) {
                    f = true;
                }
            }
            else if (f && !g && !h) {
                if ((e - '0') == y) {
                    g = true;
                }
            }
            else if (f && g && !h) {
                if ((e - '0') == z) {
                    h = true;
                }
            }
        }

        if (f && g && h) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>

int main() {
    double iSideA; // 三角形の辺
    double iSideB; // 三角形の辺
    double iAngle; // 2辺の角度
    double S, L, h;

    scanf("%lf%lf%lf", &iSideA, &iSideB, &iAngle); //  入力

    iAngle = iAngle / 180.0 * M_PI;

    S = iSideA * iSideB * sin(iAngle) / 2.0;
    L = iSideA + iSideB + sqrt(iSideA * iSideA + iSideB * iSideB - 2 * iSideA * iSideB * cos(iAngle));
    h = 2.0 * S / iSideA;

    printf("%.8lf\n", S); // 面積
    printf("%.8lf\n", L); // 周の長さ
    printf("%.8lf\n", h); // aを底辺としたときの高さ

    return 0;
}


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

using namespace std;

#define ll long long

const int mxW = 1e5, mxN = 100;
ll dp[mxW+1], w[mxN], v[mxN];

int main()
{
	int n, W;
	cin >> n >> W;
	for(int i = 0; i < n; ++i)
		cin >> w[i] >> v[i];
	for(int i = 0; i < n; ++i){
		for(int j = W; w[i]<=j; --j){
			dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
		}
	}
	cout << dp[W];
			
	return 0;
}


Measured memory_bytes: 4384
#include <iostream>

using namespace std;

int main(){
    int n, y;
    bool flag = true;
    cin >> n >> y;
    y /= 1000;
    for (int i = 0; i <= y / 10; ++i) {
        int ry = y - 10 * i, rn = n - i;
        if ((rn <= ry) && (ry / 5 <= rn) && ((ry - rn) % 4 == 0)) {
            int j = (ry - rn) / 4;
            if (rn < j) continue;
            cout << i << " " << j << " " << (rn - j) << endl;
            flag = false;
            break;
        }
    }
    if (flag) cout << "-1 -1 -1" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n,k;
    cin >> n >> k;
    long long int result=0;
    while(n!=0){
        n/=k;
        result++;
    }
    cout<<result<<endl;

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
using ll = long long;
const int INF = 1e9 + 5;

int main(){
    double r;
    cin>>r;
    cout<<2*r*22/7;
}


Measured memory_bytes: 3776
import java.util.Scanner;

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

        String line = scanner.nextLine();

        String[] mn = line.split(" ");
        int m = Integer.parseInt(mn[0]);
        int n = Integer.parseInt(mn[1]);

        int ans = m  * (m - 1) / 2  + n * (n - 1) / 2;

        System.out.println(ans);

    }
}


Measured memory_bytes: 23892
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int height = sc.nextInt();
		int width = sc.nextInt();		
		List<List<Integer>> listHeight = new ArrayList<>();

		for(int cntHeight = 0 ; cntHeight < height ; cntHeight++){
			String str = sc.next();
			List<Integer> listWidth = new ArrayList<>();
			for(int cntWidth = 0 ; cntWidth < width ; cntWidth++){				
				char chr = str.charAt(cntWidth);
				int a=0;
				if(chr == '#'){
					a=1;
				}		
				listWidth.add(a);
			}
			listHeight.add(listWidth);
		}
		sc.close();

		for(int cntHeight = height-1 ; cntHeight > -1 ; cntHeight--){
			int sum = 0;
			for(int cntWidth = 0 ; cntWidth < width ; cntWidth++){				
				sum = sum + listHeight.get(cntHeight).get(cntWidth);			
			}
			if(sum == 0){
				listHeight.remove(cntHeight);
				height--;
			}
		}

		for(int cntWidth = width-1 ; cntWidth > -1 ; cntWidth--){
			int sum = 0;
			for(List<Integer> list :listHeight){
				sum = sum + list.get(cntWidth);
			}			
			if(sum == 0){
				for(List<Integer> list :listHeight){
					list.remove(cntWidth);					
				}
				width--;
			}
		}
		
		for(List<Integer> list : listHeight){
			for(int cntWidth = 0 ; cntWidth < width ; cntWidth++){	
				if(list.get(cntWidth)==1){
					System.out.print("#");
				}else{
					System.out.print(".");
				}
			}
			System.out.println("\n");
		}
	}
}


Measured memory_bytes: 23788
#include<stdio.h>
int main (void){

    int a,b;


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

    if(a < b)
    printf("a < b\n");

    if(a > b)
    printf("a > b\n");

    if(a == b)
    printf("a == b\n");

    return 0;
}


Measured memory_bytes: 2600
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>
#include <limits>

using namespace std;

int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  int d = 0;
  int ans = 1;
  for (int i = 0; i < n; i++) {
    int L;
    scanf("%d", &L);
    d += L;
    if (d <= x) ans++;
  }
  printf("%d\n", ans);
  return 0;
}


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

int getGCD(int a, int b) { return b ? getGCD(b, a%b) : a; }
int main() {
	int a, b, gcd;
	while (cin >> a >> b) {
		gcd = getGCD(a, b);
		cout << gcd << " " << (long long)a*b/gcd << endl;
	}
	return 0;
}

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

using namespace std;

void solve(void)
{
	int n, k;
	cin >> n >> k;
	vector<long> cs, as(n);
	for (long& a : as) cin >> a;
	for (int i = 0; i < n-1; i++)
	{
		long v = as[i];
		for (int j = i+1; j < n; j++)
		{
			v += as[j];
			cs.push_back(v);
		}
	}
	long ans = 0;
	for (int i = 60; i >= 0; i--)
	{
		vector<long> ncs;
		int cnt = 0;
		for (long v : cs)
		{
			if (v>>i & 1)
			{
				cnt++;
				ncs.push_back(v);
			}
		}
		if (cnt >= k)
		{
			ans |= 1L << i;
			swap(cs, ncs);
		}
	}
	cout << ans << endl;

}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 6004
N, T = map(int, input().split())
min_c = 10**7

for i in range(N):
  c, t = map(int, input().split())
  if t<=T and c<min_c:
      min_c = c

if min_c==10**7:
  print('TLE')
else:
  print(min_c)

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

using ll = long long;

int main() {
    int n; cin >> n;
    for(int i = 0; i <= 25; ++i) {
        for(int j = 0; j <= 20; ++j) {
            if(i * 4 + j * 7 == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

N,Q = imn()
S = input()
lr = [iln() for _ in range(Q)]

c = [0 for _ in range(N+1)]

for i in range(N):
    c[i+1] = c[i]
    if i+1 < N and S[i] == 'A' and S[i+1] == 'C': c[i+1] += 1

for i in range(Q):
    left = lr[i][0]-1
    right = lr[i][1]-1
    print(c[right]-c[left])


Measured memory_bytes: 32756
"use strict";
function main(input) {
    const S = input.replace("\n", "");
    let ans = 0;
    for (let i = 0; i < (S.length / 2 | 0); i++)
        if (S.charAt(i) !== S.charAt(S.length - i - 1)) ans++;
    console.log(ans);
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29632
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ull Pow(ull a , ull b){
	if(b == 0) return 1 ;
	ull c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c) % mod)) % mod;
	return (c * c) % mod ;
}

int main(){
	IOS;
	cout.precision(30) ;
	int n ; cin >> n ;
	vector<long double> a(n) ; for(int i = 0 ; i < n ; i++) cin >> a[i] ;
	long double sum = 0 ;
	for(int i = 0 ; i < n ; i++) sum += 1 / a[i] ;
	cout << 1 / sum << endl ;
	return 0;
}


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

int N, K, A[100];
double memo[100001];
double calc(int i) {
	if (memo[i] >= 0) return memo[i];
	vector<int> V;
	rep(j, N) {
		if (i - A[j] >= 0) V.pb(calc(i - A[j]));
	}
	int p = 0;
	sort(V.begin(), V.end());
	for (int j : V) {
		if (p == j) p++;
		if (p < j) break;
	}
	return memo[i] = p;
}


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


	cin >> N >> K;
	rep(i, N) cin >> A[i];
	rep1(i, K) memo[i] = -1;
	memo[0] = 0;

	if (calc(K)) co("First");
	else co("Second");


	Would you please return 0;
}

Measured memory_bytes: 12032
n, m, k = map(int, input().split(' '))
list_a = list(map(int, input().split(' ')))
list_b = list(map(int, input().split(' ')))
 
a_sum=[list_a[0]]
for i in range(1, n):
  a_sum.append(list_a[i]+a_sum[i-1])
  
b_sum=[list_b[0]]
for i in range(1, m):
  b_sum.append(list_b[i]+b_sum[i-1])

  
ans=0 
if (a_sum[0]>k) and (b_sum[0]>k):
  print(0)
else:
  for j in range(m):
    if b_sum[j]<=k:
      ans=max(ans, j+1)
  j=m-1
  for i in range(n):
    if a_sum[i]<=k:
      ans=max(ans, i+1)
      while a_sum[i] + b_sum[j] > k and j>0:
        j-=1
      if a_sum[i]+b_sum[j]<=k:
        ans=max(ans, i+j+2)
  print(ans)

Measured memory_bytes: 48568
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *A = map(int, read().split())

    ans = max(N - sum(A), -1)

    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 67260
N = int(input())
h_list = list(map(int, input().split()))
ans = "Yes"
for n in range(N):
    if(n == 0):
        h_list[n] -= 1
    else:
        if(h_list[n-1] < h_list[n]):
            h_list[n] -= 1
        elif(h_list[n-1] > h_list[n]):
            ans = "No"
            break
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    string s;
    cin >>n;
    int ac=0, wa=0, tle=0, re=0;
    
    for(int i = 0; i<n; i++){
        cin >>s;
        if(s=="AC") ac++;
        if(s=="WA") wa++;
        if(s=="TLE") tle++;
        if(s=="RE") re++;
    }
    cout <<"AC x "<<ac<<endl;
    cout <<"WA x "<<wa<<endl;
    cout <<"TLE x "<<tle<<endl;
    cout <<"RE x "<<re<<endl;
}

Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int count=0;
  int len=(s.size())/2;
  for(int i=0;i<len;i++)
  {
   	 if(s[i]!=s[s.size()-i-1])
     {
       count++;
     }
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
n, m = map(int, input().split())
if m==0:
    print("Yes")
    sys.exit()

tree = [[] for _i in range(n+1)]
for _i in range(m):
    l, r, d = map(int, input().split())
    tree[l].append([r, d])
    tree[r].append([l, -d])

from collections import deque
INF = "INF"
visit = [INF for _i in range(n+1)]
for i in range(1, n+1):
    if visit[i]==INF:
        visit[i] = 0
    else:
        continue
    q = deque([i])
    while q:
        p = q.popleft()
        if visit[p]==INF:
            visit[p] = 0
        for i, j in tree[p]:
            if i==p:
                continue
            elif visit[i] == INF:
                visit[i] = visit[p]+j
                q.append(i)
            elif visit[i] == visit[p]+j:
                continue
            else:
                print("No")
                sys.exit()

print("Yes")

Measured memory_bytes: 108704
while 1:
  n=input()
  if n==0: break
  D={}
  A=[]
  for _ in range(n):
    a,b,c=map(int, raw_input().split(' '))
    if a in D: D[a]+=b*c
    else:
      D[a]=b*c
      A.append(a)
  B=[i for i in A if D[i]>=1e6]
  if B==[]: B=["NA"]
  for e in B: print e

Measured memory_bytes: 4360
# coding: utf-8
import math
a, b, c = map(int,input().split())
#N = int(input())
#S = input()
ans = 0
#l = list(map(int,input().split()))

l = [a,b,c]

if l.count(a) == 1:
    print(a)
elif l.count(b) == 1:
    print(b)
else:
    print(c)

Measured memory_bytes: 9048
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int c=0;
	string s,t="CODEFESTIVAL2016";
	cin>>s;
	for(int i=0;i<16;i++)if(s[i]!=t[i])c++;
	cout<<c<<endl;
	return 0;
}


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

bool solve(int p, int t);
void sortA(void);

int A[3000];
int n;

int main(){
  
  int q;
  
  cin >> n;
  
  for(int i=0; i<n; i++){
    cin >> A[i];
  }
  sortA();
  
  cin >> q;
  int tmp;
  for(int j=0; j<q; j++){

    cin >> tmp;
    int i,lim=n-1;
    for(i=0; i<n; i++){
      if(lim==n-1 && tmp < A[i]){
	lim=(i-1>=0?i-1:0);
      }
    }
    if(solve(lim,tmp)){
      cout << "yes\n";
    }else{
      cout << "no\n";
    }
  }
  
  return 0;
}
void sortA(void){
  int i,j;
  int tmp;
  for(i=0; i<n; i++){
    for(j=i+1; j<n; j++){
      if(A[i]>A[j]){
	tmp = A[i];
	A[i] = A[j];
	A[j] = tmp;
      }
    }
  }
}
bool solve(int i, int t){
  if(t == A[i]){
    return true;
  }else if(t <= 0){
    return false;
  }else if(i==0){
    return false;
  }
  
  if(solve(i-1,t-A[i])){
    return true;
  }else if(solve(i-1,t)){
    return true;
  }else{
    return false;
  }
  
} 

Measured memory_bytes: 1124
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL A, B, C, K;
	cin >> A >> B >> C >> K;
	LL ans = 0;
	ans += min(A, K);
	K -= ans;
	if (K == 0)goto coutans;
	K -= min(B, K);
	if (K == 0)goto coutans;
	ans -= min(C, K);
	goto coutans;
coutans:
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3192
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(ll i=a;i<=b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define efo(i,v,u) for(int i=last[v],u=to[last[v]];i;i=next[i],u=to[i])
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
void read(ll &n)
{
	ll t=0,p=1;char ch;
	for(ch=getchar();!('0'<=ch && ch<='9');ch=getchar())
		if(ch=='-') p=-1;
	for(;'0'<=ch && ch<='9';ch=getchar()) t=t*10+ch-'0';
	n=t*p;
}
const int N=6e5+5;
int n,sig,top;
ll a[N],s[N],f[N],g[N],h[N],F[N],G[N],sta[N];
void rev(ll *arr)
{
	fo(i,1,n/2) swap(arr[i],arr[n-i+1]);
	fo(i,1,n) s[i]=s[i-1]+a[i];
}
ll H(ll j){return 2*(sig==0?f[j]:g[j])+2*s[j]+j*j-j;}
db xl(int j,int k){return 1.0*(H(j)-H(k))/(j-k);}
ll S(ll x){return x*(x+1)/2;}
ll dp(ll *d) // j as a point
{
	mset(d,0);mset(sta,0);
	sta[top=1]=0;
	fo(i,1,n)
	{
		while(top && xl(sta[top-1],sta[top])<=2*i) top--;
		int j=sta[top];
		d[i]=max(d[i-1],d[j]+S(i-j)-s[i]+s[j]);
		while(top && xl(sta[top-1],sta[top])<=xl(sta[top],i)) top--;
		sta[++top]=i;
	}
}
db cross(ll k1,ll b1,ll k2,ll b2)
{
	return 1.0*(b2-b1)/(k1-k2);
}
void solve(int l,int r)
{
	if(l==r)
	{
		h[l]=max(h[l],f[l-1]+g[l+1]+1-a[l]);
		return;
	}
	int mid=l+r>>1;
	fo(i,l,mid) F[i]=f[i-1]+s[i-1]+((ll)i*i-3*i)/2+1;
	fo(j,mid+1,r) G[j]=g[j+1]-s[j]+((ll)j*j+3*j)/2;
	top=0;
	//j as a line
	fd(j,r,mid+1)
	{
		while(top && G[j]>=G[sta[top]]) top--;
		while(top>1 && cross(-j,G[j],-sta[top],G[sta[top]])<=cross(-sta[top],G[sta[top]],-sta[top-1],G[sta[top-1]]))
			top--;
		sta[++top]=j;
	}
	int p=1;ll t=-1e16;
	fo(i,l,mid)
	{
		while(p<top && G[sta[p]]-sta[p]*i<=G[sta[p+1]]-sta[p+1]*i) p++;
		t=max(t,F[i]+G[sta[p]]-i*sta[p]);
		h[i]=max(h[i],t);
	}
	solve(l,mid);solve(mid+1,r);
}
int main()
{
	scanf("%d",&n);
	fo(i,1,n) read(a[i]),s[i]=s[i-1]+a[i];
	sig=0;dp(f);
	rev(a);sig=1;dp(g);rev(g);rev(a);
	mset(h,128);
	rev(a);
	rev(f);rev(g);swap(f,g);rev(h);
	solve(1,n);
	rev(h);swap(f,g);rev(g);rev(f);
	rev(a);
	solve(1,n);
	int Q,x,y;
	scanf("%d",&Q);
	fo(i,1,Q)
	{
		scanf("%d %d",&x,&y);
		printf("%lld\n",max(f[x-1]+g[x+1],h[x]+a[x]-y));
	}
	return 0;
}

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

int main() {
int n,l;
  cin>>n>>l;
  vector<string> s(n);
  rep(i,n) cin>>s[i];
  sort(s.begin(),s.end());
  rep(i,n)cout<<s[i];
  cout<<endl;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

count = 0
for i in range(n):
    minj = i
    for j in range(i + 1, n):
        if (A[minj] > A[j]):
            minj = j
    if (i != minj):
        A[i], A[minj] = A[minj], A[i]
        count += 1

print(' '.join(map(str, A)))
print(count)



Measured memory_bytes: 5600
n, m, l = [int(i) for i in input().split()]

A = []
B = []
C = []

for ni in range(n):
    A.append([int(i) for i in input().split()])

for mi in range(m):
    B.append([int(i) for i in input().split()])

for i in range(n):
    C.append([])
    for j in range(l):
        C[i].append(0)
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]

for ni in range(n):
    print(" ".join([str(s) for s in C[ni]]))

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

int main(void)
{
    vector<char> vec(3, 0);

    bool conitnuing = false;
    int count = 0;

    for(int i = 0; i < 3; i++){
        cin >> vec[i];
        if(vec[i] == 'R'){
            if(conitnuing){
                count++;
            }else{
                count = 1;
                conitnuing = true;
            }
        }else{
            conitnuing = false;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 1000000

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    set<ll> st;
    ll n;
    pair<ll,ll> p[100010];
    cin>>n;
    for(int i=0;i<n;i++){
	cin>>p[i].first;
	p[i].second=i;
    }
    sort(p,p+n,greater<pair<ll,ll> >());
    st.insert(-1);st.insert(-2);
    st.insert(n); st.insert(n+1);
    ll ans=0;
    for(int i=0;i<n;i++){
	ll x=p[i].second;
	ll a,b,c,d;
	auto it=st.lower_bound(x);
	c=*it; it++; d=*it; it--; it--; chmin(d,n);
	b=*it; it--; a=*it; chmax(a,(ll)-1);
	ll cnt=0;
	cnt+=(x-b)*(d-c);
	cnt+=(b-a)*(c-x);
	ans+=p[i].first*cnt;
	st.insert(x);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 6528
import static java.lang.Math.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 26;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		long n, s;
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			n = in.nextLong();
			s = in.nextLong();

			if (s == n) {
				out.println(n+1);
				return;
			}

			long ans = Long.MAX_VALUE;
			// (1) b <= √n
			for (long b = 2; b*b <= n; b++) {
				if (func(b, n) == s) {
					ans = b;
					break;
				}
			}

			// (2) √n < b ⇔ p < √n
			for (long p = 1; p*p < n; p++) {
				long b = (n-s)/p + 1;
				if (b < 2) {
					continue;
				}
				if (func(b, n) == s) {
					ans = min(ans, b);
				}
			}

			out.println(ans == Long.MAX_VALUE ? -1 : ans);
		}

		long func(long b, long n) {
			if (n < b) {
				return n;
			} else {
				return func(b, n/b) + n%b;
			}
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

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

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;
void solve()
{
	ll n, m;
	cin>>n>>m;
	ll l ,r;
	vector<ll> range(n+2, 0);
	REP(i, m)
	{
		cin>>l>>r;
		range[l]++;
		range[r+1]--;
	}
	int cnt = 0;
	for(int i=1; i<=n; i++)
	{
		range[i]+=range[i-1];
		if(range[i]==m) cnt++;
	}
	cout<<cnt<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

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

int main(){
    int n;

    cin >> n;
    vector<ll> A(n);
    vector<ll> B(n);
    for (int i = 0; i < n;i++){
        cin >> A[i];
        B[i] = A[i];
    }
    sort(A.begin(), A.end());

    ll l = A[n / 2 - 1];
    ll r = A[n / 2];

    for (int i = 0; i < n;i++){
        if(B[i] < r)
            cout << r << endl;
        else
            cout << l << endl;
    }

    return 0;
}


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

using namespace std;
using ll=long long;

int main()
{
    int A, B, C;
    
    cin >> A >> B >> C;
    
    if ( (A == 5 && B == 5 && C == 7) ||
         (A == 5 && B == 7 && C == 5) ||
         (A == 7 && B == 5 && C == 5) )
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    
    return 0;
}


Measured memory_bytes: 256
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i and a[0][0] < c:
        x, y = a[0]
        if y > i:
            heapq.heapreplace(a, (x, y - i))
            i = 0
        else:
            heapq.heappop(a)
            i -= y
    heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))


Measured memory_bytes: 21548
#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
    int n,tmp,digits,cnt;
    cin>>n;
    tmp=n;
    digits=0;

    while(tmp>0){
        tmp/=10;
        digits++;    
    }
    
    cnt=0;
    while(n>0){
        //cout<<"digits = "<<digits<<endl;
        if(digits%2==1){
            cnt+=n-(pow(10,digits-1)-1);
            //cout<<"cnt += "<<n-(pow(10,digits-1)-1)<<endl;
        }
        digits--;
        n=pow(10,digits)-1;
        //cout<<"10^(digits) = "<<pow(10,digits-1)<<endl;
        //cout<<"n = "<<n<<endl;
        //cout<<endl;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
// Last Change: 08/10/2019 21:10:55.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  const ll left = -1000000, right = 1000000;
  ll k, x;
  cin >> k >> x;

  ll start = max(left, x - k + 1);
  ll last = min(right, x + k - 1);

  for (ll i = start; i <= last; ++i) {
    cout << i << ' ';
  }
  cout << endl;
}



Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	while (N) {
		bitset<8000000>b(false);
		int index = N;
		int cnt = 0;
		while (cnt <= M) {
			if (b[index]) {
				index++;
				continue;
			}
			cnt++;
			for (int i = index; i < 8000000; i += index) {
				b[i] = true;
			}
			index++;
		}
		cout << index-1 << endl;
		cin >> N >> M;
	}
	return 0;
}



Measured memory_bytes: 4088
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
long M[1000][1000];
long solve(vector<vector<long> > &G,int i,int j,int n,int m)
{
   if(i>=n || j>=m || G[i][j]==1)
   {
   	return 0;
   }

   if(i==n-1 && j==m-1)
   {
   	return 1;
   }

   if(M[i][j]!=-1)
   {
   	return M[i][j];
   }

   long ct=0;
   
   long r1 = solve(G,i+1,j,n,m); 
   long r2 = solve(G,i,j+1,n,m);

   ct = ((r1%mod)+(r2%mod))%mod;

   M[i][j] = ct;
   return M[i][j];

}
main()
{

  for(int i=0;i<1000;i++)
  {
  	for(int j=0;j<1000;j++)
  	{
  		M[i][j] = -1;
  	}
  }

  int n,m;
  cin>>n>>m;
  vector<vector<long> > G(n);
  for(int i=0;i<n;i++)
  {
  	for(int j=0;j<m;j++)
  	{
        char c;
        cin>>c;

        if(c=='.')
        {

        	G[i].push_back(0);
        }
        else
        {
        	G[i].push_back(1);
        }



  	}
  }



  cout<<solve(G,0,0,n,m);




}

Measured memory_bytes: 16256
# -*- coding: utf-8 -*-
from itertools import product
from bisect import bisect, bisect_left
def inpl(): return list(map(int, input().split()))
A, B, Q = inpl()
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]

for x in X:
    ans = 1e12
    ls, lt = S[max(0, bisect(S, x)-1)], T[max(0, bisect(T, x)-1)]
    rs, rt = S[min(A-1, bisect_left(S, x))], T[min(B-1, bisect_left(T, x))]
    for s in [ls, rs]:
        for t in [lt, rt]:
            if s < t:
                a, b = s, t
            else:
                a, b = t, s

            if x < a:
                ans = min(ans, b-x)
            elif b < x:
                ans = min(ans, x-a)
            else:
                ans = min(ans, 2*(x-a) + (b-x), (x-a) + 2*(b-x))
    print(ans)

Measured memory_bytes: 94828
Mod = 1000000007
N = gets.to_i
h = {}
gets.split.map(&:to_i).each{ |x| h[x] = (h[x] || 0) + 1 }
if (N%2 == 0)
  p (0...N/2).all?{ |i| h[2*i+1] == 2 } ? (0...N/2).reduce(1){ |a,_| (a * 2) % Mod } : 0
else
  p h[0] == 1 && (1..N/2).all?{ |i| h[2*i] == 2 } ? (1..N/2).reduce(1){ |a,_| (a * 2) % Mod } : 0
end


Measured memory_bytes: 12172
#include <stdio.h>

char w[101];
int c[26];
int ans = 1;

int main(void)
{
	int i, j;

	scanf("%s", w);
	for (i = 0; w[i]; ++i)
	{
		++c[w[i] - 'a'];
	}
	for (i = 0; i < 26; ++i)
	{
		if (c[i] & 1) ans = 0;
	}

	printf("%s\n", ans ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 1640
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int n,cot=0,a[200005],b[200005];
int pre[200005];
long long dp[200005][2];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int i=1;i<=n;i++)
        if(b[i]!=b[i-1]) a[++cot]=b[i];
    dp[1][0]=1;
    pre[a[1]]=1;
    for(int i=2;i<=cot;i++)
    {
        dp[i][0]=(dp[i-1][0]+dp[i-1][1])%mod;
        dp[i][1]=(dp[i][1]+dp[pre[a[i]]][1]+dp[pre[a[i]]][0])%mod;
        pre[a[i]]=i;
    }
    printf("%lld\n",(dp[cot][0]+dp[cot][1])%mod);
}


Measured memory_bytes: 5760
import sys
import math
x,k,d = map(int,input().split())
if abs(x) >= k*d:
  ans = abs(x) - k*d
  print(ans)
  sys.exit()
else:
  n = math.floor(x/d)
  dist = x - n*d
  if (k - n)%2 == 0:
    print(dist)
    sys.exit()
  else:
    print(abs(d-dist))

Measured memory_bytes: 9176
#include <iostream>
#include <ios>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <iomanip>
#include <cmath>

using namespace std;

const int N = (int) 2e5 + 5;
const int M = (int) 1e9 + 7;

typedef long long ll;

int h, w, k;
string s[15];

int main() {
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++) cin >> s[i];

    int res = h * w;
    for (int b = 0; b < (1 << (h - 1)); b++) {
        int total = 0;

        for (int i = 0; i < h; i++)
            if (b & (1 << i)) total++;

        bool valid = true;

        int blk[10] = {0};
        int col[10] = {0};

        for (int j = 0; j < w; j++) {
            for (int i = 0; i < h; i++) col[i] = 0;

            int id = 0;
            for (int i = 0; i < h; i++) {
                col[id] += s[i][j] == '1';
                if ((1 << i) & b) id++;
            }

            for (int i = 0; i <= id; i++) {
                if (col[i] > k) {
                    valid = false;
                    break;
                }
            }

            if (!valid) break;

            bool inc = false;

            for (int i = 0; i <= id; i++) {
                if (blk[i] + col[i] > k) {
                    inc = true;
                    break;
                }
            }

            if (inc) {
                total++;
                for (int i = 0; i <= id; i++) blk[i] = 0;
            }
            for (int i = 0; i <= id; i++) blk[i] += col[i];
        }

        if (valid) res = min(res, total);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    //Into the Hardware Mode
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
       pn(Math.min(nl()*nl(), nl()));
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    long IINF = (long)1e18, mod = (long)998244353;
    final int INF = (int)1e9, MX = (int)2e5+5;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-6;
    static boolean multipleTC = false, memory = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str = "";
            try{   
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }  
            return str;
        }
    }
}

Measured memory_bytes: 21716
def main():
    k = int(input())
    a, b = map(int, input().split())
    for i in range(a, b + 1):
        if i % k == 0 and i // k >= 1:
            print("OK")
            break
    else:
        print('NG')


if __name__ == '__main__':
    main()


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

struct Magic {
    int damage, cost;
};

uint64_t solve(const std::vector<Magic> &magics, const int h, std::unordered_map<int, uint64_t> &memo) {
    if(h <= 0) {
        return 0;
    }

    const auto i = memo.find(h);
    if(i != memo.end()) {
        return i->second;
    }

    uint64_t result = UINT64_MAX;

    for(const auto m: magics) {
        const auto x = solve(magics, h - m.damage, memo);
        result = std::min(result, x + m.cost);
    }

    memo[h] = result;

    return result;
}

int main() {
    int h, n;
    std::cin >> h >> n;

    auto magics = std::vector<Magic>();
    magics.reserve(n);

    for(int i = 0; i < n; ++i) {
        int damage, cost;
        std::cin >> damage >> cost;
        magics.push_back(Magic{damage, cost});
    }

    auto memo = std::unordered_map<int, uint64_t>();

    std::cout << solve(magics, h, memo) << std::endl;

    return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
#define N 50
#define O 0
#define M -1
#define I 1
#define T 2

int dp[N];

int Fib(int);

int main(){
  int n,i;

  for(i=0;i<N;i++){
    dp[i]=M;
  }
  scanf("%d",&n);
  printf("%d\n",Fib(n));
  return 0;
}

int Fib(int n){
  if(n==O || n==I){
    return dp[n] =I;
  }
  if(dp[n]!=M){
    return dp[n];
  }
  return dp[n]=Fib(n-I)+Fib(n-T);
}



Measured memory_bytes: 2108
//Author Name - Mohammad Shehar Yaar Tausif
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000007

typedef long long int lld;
lld DP[1000][1000];

lld mod_add(lld a,lld b){
	return ((a%INF)+(b%INF))%INF;
}

int main(){
	lld h,w,i,j;
	char x;
	cin>>h>>w;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cin>>x;
			if(x == '#'){
				DP[i][j] = 0;
			}else{
				DP[i][j] = -1;
			}
		}
	}
	DP[0][0] = 1;
	for(i=0;i<h;i++){
		if(DP[i][0] == -1){
			DP[i][0] = DP[i-1][0];
		}
	}
	for(i=0;i<w;i++){
		if(DP[0][i] == -1){
			DP[0][i] = DP[0][i-1];
		}
	}
	for(i=1;i<h;i++){
		for(j=1;j<w;j++){
			if(DP[i][j] == -1){
				DP[i][j] = mod_add(DP[i-1][j],DP[i][j-1]);
			}
		}
	}
	cout<<DP[h-1][w-1]<<endl;
	return 0;
}

Measured memory_bytes: 8064