akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
template<class S>void tf(bool b,S t,S f){cout<<(b?t:f)<<endl;}
void OUT(bool b){tf(b,"YES","NO");}
void Out(bool b){tf(b,"Yes","No");}
void out(bool b){tf(b,"yes","no");}
template<class T>void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<vector<pll>> edge(n);
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		edge[a-1].emplace_back(b-1,c);
		edge[b-1].emplace_back(a-1,-c);
	}
	vl ans(n,-LINF);
	rep(i,n)if(ans[i]==-LINF){
		queue<pll> q;
		q.emplace(i,0);
		ans[i]=0;
		while(!q.empty()){
			ll p,cur;
			tie(p,cur)=q.front();
			q.pop();
			//puta(p,cur);
			if(ans[p]!=cur){
				Out(0); return 0;
			}
			for(auto&e:edge[p]){
				ll to,cost;
				tie(to,cost)=e;
				if(ans[to]!=-LINF and ans[p]+cost!=ans[to]){
					Out(0); return 0;
				}
				if(ans[to]==-LINF){
					ans[to]=ans[p]+cost;
					q.emplace(to,ans[to]);
				}
			}
		}
	}
	Out(1);
	return 0;
}

Measured memory_bytes: 14448
#include<bits/stdc++.h>
using namespace std;
int main(){
  string ans;
  int d;
  cin>>d;
  if(d==22)ans="Christmas Eve Eve Eve";
  if(d==23)ans="Christmas Eve Eve";
  if(d==24)ans="Christmas Eve";
  if(d==25)ans="Christmas";
  cout<<ans<<endl;
}

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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;

const int MAX = 510000;

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

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}


int main() {
	COMinit();
	int n, m;
	cin >> n >> m;
	VI v;
	int i = 2;
	int res = 0;
	while (m != 1) {
		if (m%i == 0) {
			m /= i;
			res++;
		}
		else {
			i++;
			if (res) {
				v.push_back(res);
				res = 0;
			}
		}
	}
	if (res)v.push_back(res);
	ll ans = 1;
	REP(i, v.size()) {
		ans *= COM(n - 1 + v[i], v[i]);
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12160
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    if(x/d>=k){
        cout<<abs(x)-k*d<<endl;
    }
    else{
        ll a=k-x/d;
        ll ans=x-x/d*d;
        if(a%2==1){
            ans=d-ans;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3636
# N  個のリンゴがあります。
# これらはそれぞれリンゴ 1、リンゴ 2、リンゴ 3、...、リンゴ N と呼ばれており、
# リンゴ i の「味」は L+i−1 です。「味」は負になることもありえます。
# また、1 個以上のリンゴを材料として、アップルパイをつくることができます。
# その「味」は、材料となったリンゴの「味」の総和となります。
# あなたはこれらのリンゴを全て材料として、アップルパイをつくる予定でしたが、
# おなかがすいたので 1 個だけ食べることにしました。
# 勿論、食べてしまったリンゴはアップルパイの材料にはできません。
# つくる予定だったアップルパイとできるだけ同じものをつくりたいので、
# N 個のリンゴ全てを材料としてできるアップルパイの「味」と、
# 食べていない N−1 個のリンゴを材料としてできるアップルパイの「味」の差の絶対値が
# できるだけ小さくなるように、食べるリンゴを選ぶことにしました。
# このようにして選ばれたリンゴを食べた時、食べていない N−1 個のリンゴを
# 材料としてできるアップルパイの「味」を求めてください。
# なお、この値は一意に定まることが証明できます。

input = gets.chomp.split
n = input[0].to_i
l = input[1].to_i

def apple_pie n, l, lost
    n_apple_pie = 0
    n.times do |i|
        next if i == lost
        n_apple_pie += l + (i + 1) - 1
    end
    return n_apple_pie
end

n_apple_pie = apple_pie(n, l, -1)

n_1_apple_pies = []
n.times do |i|
    n_1_apple_pies << apple_pie(n, l, i)
end

diff_apple_pies = []
n.times do |i|
    diff_apple_pie = n_apple_pie - n_1_apple_pies[i]
    diff_apple_pie *= (-1) if diff_apple_pie < 0
    diff_apple_pies << diff_apple_pie
end

puts n_1_apple_pies[diff_apple_pies.index(diff_apple_pies.min)]

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

int main(int argc, char *argv[])
{
    int N, K;
    cin >> N >> K;
    vector<long long> H(N);
    for (auto& h : H) {
        cin >> h;
    }
    sort(rbegin(H), rend(H));
    long long res = 0;
    for (int i = K; i < N; i++) {
        res += H[i];
    }
    cout << res << "\n";
    return 0;
}


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

using namespace std;

/** Problem1193 : Chain Disappearance Puzzle **/

int main()
{
	int H;
	while (cin>>H, H) {
		vector<vector<int> > board(H, vector<int>(5));
		int ans=0;
		
		for (int y=0; y<H; y++) {
			for (int x=0; x<5; x++) {
				cin>>board[y][x];
			}
		}
		
		
		while (true) {
			bool update=false;

			// erase
			for (int y=0; y<H; y++) {
				for (int x=0; x<5; x++) {
					int count = 1;
					if (board[y][x]<0) continue;
					
					for (int tx=x+1; tx<5; tx++) {
						if (board[y][tx] == board[y][tx-1])	
							count++;
						else
							break;
					}
					
					if (count>=3) {
						update = true;
						ans += count*board[y][x];
						for (int i=0; i<count; i++) {
							board[y][x+i] = -1;
						}
					}
				}
			}
		
			// drop
			for (int x=0; x<5; x++) {
				for (int y=H-2; y>=0; y--) {
					if (board[y][x]>=0) {
						int ty=y;
						while (ty+1<H && board[ty+1][x]<0 && board[ty][x]>=0) {
							swap(board[ty+1][x], board[ty][x]);
							ty++;
						}
					}
				}
			}
			
			if (!update) break;
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 1220
<?php
fscanf(STDIN, '%d', $length);
fscanf(STDIN, '%s', $string);

echo solve($length, $string);
echo "\n";

function solve($len, $str) {
    if ($len % 2 !== 0) {
        return "No";
    }

    $first = substr($str, 0, $len/2);
    $last = substr($str, -$len/2);

    return $first === $last ? "Yes" : "No";
}

Measured memory_bytes: 4728
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
void init(int a[100001]){
    for(int i = 0; i < 100001; i++){
        a[i] = MM;
    }
}
int main(){
    int N,K; cin >> N >> K;
    cout << N-K+1 << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
d=[]
a=[]
for i in range(k):
    d.append(int(input()))
    a.append(list(map(int,input().split())))
    
aa=[0]*n

for j in a:
    for k in j:
        aa[k-1]+=1
        
ans=0

for x in aa:
    if x==0:
        ans+=1

print(ans)

Measured memory_bytes: 9140
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long A, B, C;
    scan(A, B, C);
    long K = lread();

    long m = A.max(B).max(C);
    writeln(A + B + C + (m * ((2 ^^ K) - 1)));
}


Measured memory_bytes: 256
A,B,K = map(int,input().split())
ans = []

for i in range(A,A+K):
  if(A<= i<= B):
   ans.append(i)
for j in range(B-K+1,B+1):
  if(A<= j<= B):
   ans .append(j)
  
ans = set(ans)
ans = list(ans)
ans.sort()
for i in range(len(ans)):
   print(ans[i])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int K,N; cin>>K>>N;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  int ans=A[0]+K-A[N-1];
  rep(i,1,N) ans=max(ans,A[i]-A[i-1]);
  cout<<K-ans<<endl;
  }


Measured memory_bytes: 1792
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a[90];
  a[0] = 2;
  a[1] = 1;
  int n;
  cin >> n;
  rep(i,n-1){
    a[i+2] = a[i+1] + a[i];
  }
  cout << a[n] << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {

    private static final int ABSENT = -1;

    protected static String process(String data) {
        StringBuilder sb = new StringBuilder();
        final String[] lines = splitForLines(data);

        for (String line : lines) {
            final int[] split = split(line);

            final int midScore = split[0];
            final int finalScore = split[1];
            final int retestScore = split[2];

            if (midScore == ABSENT && finalScore == ABSENT && retestScore == ABSENT) {
                break;
            }

            sb.append(calcGrade(midScore, finalScore, retestScore)).append('\n');
        }

        return sb.toString();
    }

    static Grade calcGrade(int midScore, int finalScore, int retestScore) {
        if (midScore == ABSENT || finalScore == ABSENT) {
            return Grade.F;
        }

        final int baseScore = midScore + finalScore;

        if (baseScore >= 80) {
            return Grade.A;
        }

        if (baseScore >= 65) {
            return Grade.B;
        }

        if (baseScore >= 50) {
            return Grade.C;
        }

        if (baseScore >= 30) {
            if (retestScore >= 50) {
                return Grade.C;
            }
            return Grade.D;
        }

        return Grade.F;
    }

    enum Grade {
        A, B, C, D, F
    }

    private static String readAll(InputStream is) {
        InputStreamReader r = null;
        BufferedReader br = null;

        try {
            r = new InputStreamReader(is);
            br = new BufferedReader(r);
            StringBuilder sb = new StringBuilder();
            String s;

            while ((s = br.readLine()) != null) {
                sb.append(s).append('\n');
            }

            return sb.toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                }
            }
            if (r != null) {
                try {
                    r.close();
                } catch (IOException e) {
                }
            }
        }
    }

    private static String[] splitForLines(String lines) {
        return lines.split("\\n");
    }

    private static int[] split(String s) {
        final String[] s0 = s.split(" ");
        int[] ia = new int[s0.length];

        for (int i = 0; i < s0.length; i++) {
            ia[i] = Integer.parseInt(s0[i]);
        }

        return ia;
    }

    public static void main(String[] args) {
        System.out.print(process(readAll(System.in)));
    }
}

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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	std::string S;
	std::cin >> S;
	std::string T;
	std::cin >> T;

	for (ll i = 0; i < S.size(); ++i)
	{
		if (S[i] != T[i])
		{
			cout << "No" << endl;
			return EXIT_SUCCESS;
		}
	}
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 3596
#define MAX 10000005
p[MAX],four[999],j,f;main(i){for(i=2;i<MAX;i++)if(!p[i])for(j=i*2;j<MAX;j+=i)p[j]=1;for(i=9;i<MAX;i+=2)if(!p[i]&&!p[i-2]&&!p[i-6]&&!p[i-8])four[f++]=i;for(four[f]=MAX;scanf("%d",&j),j;printf("%d\n",four[i-1]))for(i=0;four[++i]<=j;);exit(0);}

Measured memory_bytes: 0
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    dp = [[0] * 3 for _ in range(N+1)]

    for i, (ca, cb, cc) in enumerate(zip(a, b, c)):
        dp[i + 1][0] = max(dp[i][1], dp[i][2]) + ca
        dp[i + 1][1] = max(dp[i][0], dp[i][2]) + cb
        dp[i + 1][2] = max(dp[i][0], dp[i][1]) + cc
    return max(dp[-1])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    c = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    result = solve(N, a, b, c)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 36628
#include <iostream>

using namespace std;

int main(){
  int n,T; cin >> n >> T;
  int t[n+1];
  for(int i=1;i<=n;i++) cin >> t[i];
  long long sum=0;
  for(int i=1;i<=n-1;i++){
    int dt=t[i+1]-t[i];
    if(dt<=T) sum+=dt;
    else sum+=T;
  }
  sum+=T;
  cout << sum << endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES 1
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007ll
#define INF 1000000000000000000ll
#define EPS 1e-9
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock

typedef long long         ll;
typedef long double       ld;
typedef pair <ll,ll>      pl;
typedef tuple <ll,ll,ll>  tl;

ll N, A[1000005], R;
bool z;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N;
	R = 1;
	z = 0;
	
	for (ll i = 1; i <= N; i++) {
		cin >> A[i];
		if (A[i] == 0) z = 1;
	}
	
	if (z) {
		cout << "0";
		return 0;
	}
	
	for (ll i = 1; i <= N; i++) {
		if (A[i] > 1000000000000000000ll / R) {
			cout << "-1";
			return 0;
		}
		R *= A[i];
	}
	
	cout << R;
	
    return 0;
}

Measured memory_bytes: 4436
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  ll n; cin >> n;
  ll tmp = INF;
  rep(i, 5) {
    ll a; cin >> a;
    tmp = min(tmp, a);
  }
  if (n%tmp == 0) cout << n/tmp + 4 << endl;
  else cout << n/tmp + 5 << endl;
}

Measured memory_bytes: 3580
#include <stdio.h>

int main(void)
{
    int n, a[101];
    int i, j, tmp;

    scanf("%d", &n);

    for (i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }

    for (i = 1; i < n; i++){
        for (j = 0; j < n; j++){
            printf("%d", a[j]);
            if (j < n - 1){
                printf(" ");
            }
        }
        printf("\n");
        tmp = a[i];
        j =  i - 1;
        while (j >= 0 && a[j] > tmp){
            a[j + 1] = a[j];
            j--;
            a[j + 1] = tmp;
        }
    }

    for (i = 0; i < n - 1; i++){
        printf("%d ", a[i]);
    }
    printf("%d\n", a[n - 1]);

    return (0);
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<ll> A(N+1);
  for(int i=0;i<N+1;i++)  cin >> A.at(i);

  if(N==0){
    if(A.at(0)==1)  cout << 1 << endl;
    else  cout << -1 << endl;
    return 0;
  }
  if(A.at(0)!=0){
    cout << -1 << endl;
    return 0;
  }

  vector<ll> MX(N+1,1e15);
  ll now=1;
  for(int i=0;i<N+1;i++){
    MX.at(i)=now;
    now-=A.at(i);
    if(now<0){
      cout << -1 << endl;
      return 0;
    }
    now*=2;
    if(now>(ll)1e15)  break;
  }

  ll ans=0;
  now=0;
  for(int i=N;i>=0;i--){
    now+=A.at(i);
    chmin(now,MX.at(i));
    ans+=now;
    //cout << now << endl;
  }
  cout << ans << endl;

  return 0;
}

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

string a,b;int k;
int Max=0;
string c;
void dfs(int i,int p,int t){
	if(i==a.size()){
		string q=c;reverse(q.begin(),q.end());
		Max=max(Max,stoi(q));
		return;
	}
	if(a[i]-p>=b[i]){
		c+=to_string(a[i]-p-b[i]);
		dfs(i+1,0,t);c.pop_back();
	}
	else{
		c+=to_string(a[i]-p+10-b[i]);
		dfs(i+1,1,t);c.pop_back();
	}
	if(t){
		if(a[i]>=b[i]){
			c+=to_string(a[i]-b[i]);
			dfs(i+1,0,t-1);c.pop_back();
		}
		else{
			c+=to_string(a[i]+10-b[i]);
			dfs(i+1,1,t-1);c.pop_back();
		}
	}
}
int main(){
	cin>>a>>b>>k;
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	while(a.size()>b.size())b+='0';
	for(char&c:a)c-='0';
	for(char&c:b)c-='0';
	dfs(0,0,k);
	printf("%d\n",Max);
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

  int a, b, h;
  cin >> a >> b >> h;
  cout << (a+b) * h / 2 << endl;

  return 0;
};


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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	int i=1;
	while(i*2<=n) i*=2;
	cout<<i<<'\n';
}




Measured memory_bytes: 3636
// Knapsack 1

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

long long n, w;
long long w_i, v_i;

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

    // dp[i][j]: 重さがj以下になるように、i番目までの品物の中から選んだときの価値の最大値
    long long dp[n+1][w+1];

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= w; j++) {
            dp[i][j] = 0;
        }
    }

    for (int i = 1; i <= n; i++) {
        cin >> w_i >> v_i;
        for (int j = 0; j <= w; j++) {
            if (w_i <= j) {
                dp[i][j] = max(dp[i-1][j-w_i] + v_i, dp[i-1][j]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    // for (int i = 0; i <= n; i++) {
    //     for (int j = 0; j <= w; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    cout << dp[n][w] << endl;

    return 0;
}


Measured memory_bytes: 79104
n, k, q = map(int, input().split())
A = [int(input()) for i in range(q)]
C = [0 for i in range(n)]
for i in range(q):
    C[A[i]-1] += 1
for i in range(n):
    c = C[i]
    if k - q + c <= 0:
        print ("No")
    else:
        print ("Yes")

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

#define ll long long 
#define pi  pair<int,int>
#define ti  tuple<int,int,int>
#define mt  make_tuple
#define mk  make_pair
#define vi  vector<int>
#define vll vector<ll>
#define fastInOut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pr(a) for(auto x:a) cout<<x<<" ";
#define prmap(m) for(auto x:m) cout<<x.first<<" "<<x.second<<"\n";

ll n,m,t;
int main() 
{ 
    fastInOut
    cin>>n>>m>>t;
    ll sum=0,u=0;
    while(sum<t+0.5){
       if(sum+n>t+0.5)
          break;
       sum+=n;
       u+=m;
    }  
    cout<<u;  
    return 0; 
} 

Measured memory_bytes: 256
//2017-10-19
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define N (500+5)

char mp[N][N];

int main(){
	int n, m;

	scanf("%d%d", &n, &m);
	For(i, 1, n) scanf("%s", mp[i]+1);

	For(i, 1, n){
		printf("#");
		For(j, 2, m)
			if(((i&1) && (j!=m)) || mp[i][j]=='#') printf("#");
			else printf(".");
		puts("");
	}

	puts("");

	For(i, 1, n){
		For(j, 1, m-1)
		    if((!(i&1) && (j!=1)) || mp[i][j]=='#') printf("#");
			else printf(".");
		printf("#\n");
	}

	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string S;
  ll K;
  cin >> S >> K;

  bool all_same = true;
  char c = S[0];
  REP(i, 1, S.size()) {
    if (c != S[i]) {
      all_same = false;
      break;
    }
  }
  if (all_same) {
    cout << S.size() * K / 2 << endl;
    return 0;
  }

  ll b = 0;
  char current = '*';
  ll clen = 1;
  for (ll i = 0; i < S.size(); i++) {
    if (current == S[i]) {
      clen++;
    } else {
      b += clen / 2;
      clen = 1;
    }
    current = S[i];
  }
  b += clen / 2;
  if (S[0] == S[S.size() - 1]) {
    ll b0 = 1;
    {
      char cur = S[0];
      REP(i, 1, S.size()) {
        if (cur == S[i]) {
          b0++;
        } else {
          break;
        }
      }
    }
    ll b9 = 1;
    {
      char cur = S[S.size() - 1];
      REV(i, S.size() - 2, 0) {
        if (cur == S[i]) {
          b9++;
        } else {
          break;
        }
      }
    }
    cout << b * K - (b0 / 2 + b9 / 2 - (b0 + b9) / 2) * (K - 1) << endl;
  } else {
    cout << b * K << endl;
  }

  return 0;
}


Measured memory_bytes: 256
using System.Collections.Generic;
using static System.Console;

class Program {
	static void Main() {
		var a = NextString();
		var b = NextString();
		var x = int.Parse(a + b);

		for (var i = 1; ; i++) {
			if (i * i == x) {
				WriteLine("Yes");
			} else if (i * i > x) {
				WriteLine("No");
			} else {
				continue;
			}
			break;
		}
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if (!char.IsWhiteSpace(nextChar))
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}

Measured memory_bytes: 13268
#include<stdio.h>
#include<string.h>
int main(void){
  int N,i,j;
  char S[200];
  scanf("%d",&N);
  scanf("%s",S);
  j=0;
  for(i=0;i<N-2;i++){
    if(S[i]=='A'){
      if(S[i+1]=='B'){
        if(S[i+2]=='C'){
          j++;
        }
      }
    }
  }
  printf("%d",j);
}

Measured memory_bytes: 1736
#include <stdio.h>
#include <stdlib.h>
#define MAX 100005
#define NIL -1
struct Node{
  int p,l,r;
};
struct Node T[MAX];
int n,D[MAX];

void print(int);
int rec(int,int);

int main(){
  int i,j;
  int d,v,c,l,r;
  scanf("%d",&n);
  if(n < 1 || n > 100000)
    exit(1);
  for(i = 0; i < n; i++)
    T[i].p = T[i].l = T[i].r = NIL;

  for(i = 0; i < n; i++){
    scanf("%d %d",&v,&d);
    for(j = 0; j < d; j++){
      scanf("%d",&c);
      if(j == 0)
	T[v].l = c;
      else
	T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }

  for(i = 0; i < n; i++){
    if(T[i].p == NIL)
      r = i;
  }

   rec(r,0);

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

  return 0;
}

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p == NIL)
    printf("root, ");
  else if(T[u].l == NIL)
    printf("leaf, ");
  else
    printf("internal node, ");

  printf("[");

  for(i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i)
      printf(", ");
    printf("%d",c);
    }
  printf("]\n");
}

int rec(int u, int p){
  D[u] = p;
  if(D[u] > 20)
    exit(1);
  if(T[u].r != NIL)
    rec(T[u].r, p);
  if(T[u].l != NIL)
    rec(T[u].l, p+1);
  return 0;
}



Measured memory_bytes: 6412
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N;
void input(){
    fast_io();
    cin >> N;
}
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int calc(ll e){
    int ret = 0;
    for (int l = 0; l < 100; l++)
    {
        if(2*e>=l*(l+1)){
            ret = l;
        }
        else break;
    }
    return ret;
}

int solve(){
    auto pf = prime_factor(N);
    int ans = 0;
    DBG(pf)
    for(auto p:pf){
        ans += calc(p.second);
    }
    cout << ans << endl;
    return 0;
}   

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

Measured memory_bytes: 3652
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=104;
int n;
struct Node {
	double x,y;
	friend bool operator <(const Node &a,const Node &b) {
		return atan2(a.y,a.x)<atan2(b.y,b.x);
	}
}a[N];
double ans;
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		scanf("%lf%lf",&a[i].x,&a[i].y);
	sort(a+1,a+n+1);
	for (int i=1;i<=n;++i) {
		double x=0,y=0;
		int j=i;
		do {
			x+=a[j].x,y+=a[j].y;
			ans=max(ans,x*x+y*y);
			++j;
			if (j>n) j%=n;
		} while (j^i);
	}
	printf("%.11lf\n",sqrt(ans));
	return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline

n = int(input())
a = [int(input()) for i in range(n)]

max_d = [-1, -1]
semi_max_d = [-1, -1]

for i in range(n):
    if a[i] > max_d[1]:

        if max_d[1] > semi_max_d[1]:
            semi_max_d[0], semi_max_d[1] = max_d[0], max_d[1]

        max_d[0], max_d[1] = i, a[i]
    else:
        if a[i] > semi_max_d[1]:
            semi_max_d[0], semi_max_d[1] = i, a[i]

[print(semi_max_d[1]) if max_d[0] == i else print(max_d[1]) for i in range(n)]


Measured memory_bytes: 14148
/*---- enazuma11-------  */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define inc(a,n) sort(a,a+n)
#define dec(a,n) sort(a,a+n,greater<int>() )
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	ll a,b;
	cin>>a>>b;
	ll p=a+b;
	ll m=a*b;
	ll s=a-b;
	ll mx=max(p,max(m,s));
	cout<<mx<<'\n';
	// your code goes here
	return 0;
}

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

int main(){
    int a;
    cin>>a;
    int s1=a%10;
    int s2=(a/10)%10;
    int s3=((a/10)/10)%10;
    int s4=(((a/10)/10)/10)%10;
    if(s1==s2&&s2==s3 || s2==s3&&s3==s4){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[N + 1];
    REP(i, 0, N + 1) {
        cin >> A[i];
    }
    if (N == 0) {
        if (A[0] == 1) {
            cout << 1 << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }
    if (A[0] > 0) {
        cout << -1 << endl;
        return 0;
    }
    ll sum[N + 1];
    sum[N] = 0;
    PER(i, N - 1, -1) {
        sum[i] = sum[i + 1] + A[i + 1];
    }
    ll maxnum[N + 1];
    maxnum[0] = 1;
    ll ans = 1;
    bool ok = true;
    REP(i, 1, N) {
        maxnum[i] = min(sum[i], 2 * maxnum[i - 1] - A[i]);
        ans += maxnum[i] + A[i];
        if (maxnum[i] <= 0) {
            ok = false;
        }
    }
    ans += A[N];
    if (maxnum[N - 1] * 2 < A[N]) {
        ok = false;
    }
    if (!ok) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}


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

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const long long MOD_NUM = 1000000007LL;

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

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

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

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void B_task();

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

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

	double X = (double)N / 1.08;
	int val = (int)ceil(X) * 1.08;
	if (val == N) {
		printf("%d\n", (int)ceil(X));
	}
	else {
		printf(":(\n");
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll int
#define pb emplace_back
using namespace std;
ll n , k , q;
ll a[2002];
const ll inf = 1e9;
bool take[2002];
vector<ll> t;
vector<ll> v;
ll solve(ll x)
{
        for(ll i=1;i<=n;i++) {
                if(a[i] < x) take[i] = false;
                else take[i] = true;
        }
        t.clear();
        for(ll i=1;i<=n;i++) {
                if(take[i] == false) continue;
                ll j = i;
                while(j <= n && take[j] == true) j++;
                if(j - i - k + 1 <= 0) continue;
                v.clear();
                for(ll p = i ; p < j ; p++) v.pb(a[p]);
                ll sz = v.size();
                sort(v.begin() , v.end());
                for(ll p=0;p < sz-k+1 ; p++) t.pb(v[p]);
                i = j-1;
        }
        sort(t.begin() , t.end());
        if(t.size() < q) return inf;
        return t[q-1] - t[0];
}
int main()
{
        //ios_base::sync_with_stdio(false);
        //cin.tie(NULL);
        //cout.tie(NULL);
        scanf(" %d %d %d", &n , &k , &q);
        for(ll i = 1 ; i <= n ; i++) {
                scanf(" %d", &a[i]);

        }
        ll ans = inf;
        for(ll i=1;i<=n;i++) {
                //cout << solve(a[i]) << endl;
                ans = min(ans , solve(a[i]));
        }
        printf("%d", ans);
        return 0;
}


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

int main() {
	int w, a, b;
	cin >> w >> a >> b;
	int ans = 0;
	if (a <= b && a + w >= b) ans = 0;
	else if (a <= b + w && a + w >= b + w) ans = 0;
	else if (a + w < b) ans = b - (a + w);
	else ans = a - (b + w);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int min_cost(int *arr,int n,int k)
{
  int *dp = new int[n+1];
  for(int i=0;i<=n;i++)
  {
      dp[i]=INT_MAX;
  }
  dp[1]=0;
  dp[2]=abs(arr[1]-arr[0]);
  for(int i=3;i<=n;i++)
  {
      for(int j=1;j<=k;j++)
      {
          if(i-j>0)
          {
              dp[i] = min(dp[i],dp[i-j]+abs(arr[i-1]-arr[i-1-j]));
          }
      }
  }
  /*for(int i=1;i<=n;i++)
  {
      cout<<dp[i]<<" ";
  }*/
  return dp[n];
}
int main()
{
  int n,k;
  cin>>n>>k;
  int * arr = new int[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  cout<</*"\n ans : "<<*/min_cost(arr,n,k)<<endl;
  delete [] arr;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int a[200];
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  int ans=0;
  REP(i,2*n){
    cin>>a[i];
  }
  sort(a,a+2*n);
  reverse(a,a+2*n);
  REP(i,n){
    ans+=a[2*i+1];
  }
  P(ans);
  return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> dct;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define pi 3.14159265

bool compare(pair<pii,vector<int>> a, pair<pii,vector<int>> b){
    if(a.first.first*b.first.second==a.first.second*b.first.first)
        return a.first.second>b.first.second;
    return a.first.first*b.first.second<a.first.second*b.first.first;
}

const int mod = 1e9 + 9;
const ll inf = ll(1e18);

ll modexp(ll x,ll n){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%mod,n/2);
    return (x*modexp((x*x)%mod,n/2))%mod;
}
vi g[100000],disu(100000,0),disv(100000,0);
void dfsu(int s,int p){
    fr(i,g[s]){
        if(i!=p){
            disu[i]=disu[s]+1;
            dfsu(i,s);
        }
    }
}
void dfsv(int s,int p){
    fr(i,g[s]){
        if(i!=p){
            disv[i]=disv[s]+1;
            dfsv(i,s);
        }
    }
}
int main(){
    fastio;
    int n,u,v,x,y;
    cin>>n>>u>>v;
    --u;--v;
    f(i,0,n-1){
        cin>>x>>y;
        --x;--y;
        g[x].pb(y);g[y].pb(x);
    }
    dfsu(u,-1);dfsv(v,-1);
    int ans=disv[u];
    int flag=1;
    f(i,0,n){
        if(disu[i]<=disv[i] and disv[i]>ans){
            ans=disv[i];
        }
    }
    --ans;
    //cout<<disv[8]<<endl;
    cout<<ans<<endl;
}

Measured memory_bytes: 10368
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; i++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

ll memo[200010] = {};

ll f(ll n) {
	if (n == 0 || n == 1)return 1;
	return ((n % 1000000007) * (f(n - 1) % 1000000007) ) % 1000000007;
}

ll C(ll n, ll k) {
	return (f(n) % 1000000007) / ((( (f(k) % 1000000007) * (f(n - k) % 1000000007))) % 1000000007);
}

int main() {
	ll N, R; cin >> N >> R;
	if (N >= 10) cout << R << endl;
	else cout << R + 100 * (10 - N) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define rep(i,a,b)		for(int i=a;i<=b;i++)
const long long INF = 1e18;
long long ans;
int n;
int main() 
{ 

	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    vector<long long> arr(n);

   	rep(i,0,n-1)
   	{
   		cin>>arr[i];
   		if(arr[i]==0)
   		{
   			cout<<0<<endl;
   			return 0;
   		}
   	}

   	ans = 1;
   	rep(i,0,n-1)
   	{
   		if(ans<=(INF/arr[i]))
   			ans*=arr[i];
   		else
   		{
   			cout<<-1<<endl;
   			return 0;
   		}
   	}
   	cout<<ans<<endl;
   	return 0;
} 


Measured memory_bytes: 3944
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int min = N + 1, count = 0, a;
  for(int i = 0; i < N; i++){
    cin >> a;
    if(a < min){
      count++;
      min = a;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For( i, j, k ) for( int i = j; i <= k; ++i ) 
using std::cin;
using std::cout;
using std::pair;
const int N = 3e5 + 1, M = 1e5 + 1;
int n, m, SC1[ M ], SC2[ M ];
pair < int, int > p[ N ];
bool cmp( pair < int, int > p1, pair < int, int > p2 ) { return p1.second - p1.first < p2.second - p2.first; }
void Add( int x )
{
 while( x <= n )
  ++SC2[ x ],
  x += x & -x;
 return;
}
void Sub( int x )
{
 while( x <= n )
  --SC2[ x ],
  x += x & -x;
 return;
}
int Sum( int x )
{
 int res = 0;
 while( x )
  res += SC2[ x ],
  x -= x & -x;
 return res;
}
int main( )
{
 std::ios::sync_with_stdio( false );
 cin >> m >> n;
 For( i, 1, m )
  cin >> p[ i ].first >> p[ i ].second;
 std::sort( p + 1, p + 1 + m, cmp );
 For( i, 1, m )
  SC1[ p[ i ].second - p[ i ].first + 1 ]++;
 for( int i = n - 1; i; --i )
  SC1[ i ] += SC1[ i + 1 ];
 int cur = 1, ans = 0;
 For( d, 1, n )
 {
  ans = SC1[ d ];
  for( int i = d; i <= n; i += d )
   ans += Sum( i );
  cout << ans << '\n';
  while( cur <= m && p[ cur ].second - p[ cur ].first + 1 == d )
  {
   Add( p[ cur ].first );
   Sub( p[ cur ].second + 1 );
   cur++;
  }
 }
 return 0;
}

Measured memory_bytes: 6760
import random

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum += c[i]*(d-last_d[i])
        
    return (score - sum)

def main():
    D = int(input())

    c = list(map(int, input().split()))

    s = [list(map(int, input().split())) for i in range(D)]

    #print(c)

    #print(s)

    last_d = [0 for i in range(26)]
    
    ans = []
    
    score = 0
    
    for i in range(D):
        max = 0
        idx = 0
        for j in range(26):
            if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
                max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
                idx = j
            elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] > c[idx]:
                idx = j
        last_d[idx] = i+1
        score += s[i][j]
        down_score(i+1,c,last_d,score)
        
        ans.append(idx)

    for i in range(D):
        print(ans[i]+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9808