akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

const int INF = 1000000000;

int main(void) {
    int edge[21][21];
    int n, m, a, b, c, d;
    int x1, x2, y1, y2;
    int i, j, k;

    scanf("%d", &n);
    scanf("%d", &m);

    for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++)
            edge[i][j] = INF;

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

    scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);

    for (k = 1;  k <= n; k++)
        for (i = 1; i <= n; i++)
            for (j = 1; j <= n; j++)
                if (edge[i][j] > edge[i][k] + edge[k][j])
                    edge[i][j] = edge[i][k] + edge[k][j];

    printf("%d\n", y1 - y2 - edge[x1][x2] - edge[x2][x1]);

    return 0;
}

Measured memory_bytes: 604
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[100010];
    rep(i,0,N) cin >> A[i];
    sort(A, A+N, greater<ll>());
    ll i = 0;
    vector<ll> v;
    while(i < N-1){
        if(A[i] == A[i+1]){
            v.push_back(A[i]);
            i += 2;
        }else{
            i++;
        }
    }
    if(v.size() < 2){
        print(0);
    }else{
        print(v[0] * v[1]);
    }
    

}

Measured memory_bytes: 1660
a, b, d = [], [], []
amount = 0
for i, x in enumerate(input()):
    if x == '\\':
        a += [i]
    elif x == '/' and a:
        j = a.pop()
        pool = i - j
        amount += pool
        while b and b[-1] > j:
            pool += d.pop()
            b.pop()
        b.append(j)
        d.append(pool)
print(amount)
print(len(b), *d)


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

#define int long long
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()

#define fast ios::sync_with_stdio(0); cin.tie(0)
#define print(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1> void __f(const char* name, Arg1&& arg1){
  cout << name << ": " << arg1 << '\n';
}

template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

const int sz = 2e5+1;
const int mod = 1e9+7;
int fact[sz],ifact[sz];


int fastmod(int base,int exp){

  if(exp==0) return 1;
  else if(exp%2==0){
    int ans=fastmod(base,exp/2);
    return (ans%mod*ans%mod)%mod;
  }
  else{
    return (fastmod(base,exp-1)%mod*base%mod)%mod;
  }
}

void factifact(){
    
    fact[0] = 1;
    for(int i=1;i<sz;i++) fact[i] = (i * fact[i-1])%mod;
    
    ifact[sz-1] = fastmod(fact[sz-1],mod-2);
    for(int i=sz-2;i>=0;i--) ifact[i] = (ifact[i+1] * (i+1))%mod;
}

int nCr(int n,int r){
  return (fact[n]*(ifact[n-r]%mod*ifact[r]%mod)%mod)%mod;
}

int32_t main(){

    fast;
    factifact();

    int h,w,a,b; cin >> h >> w >> a >> b;
    h--;
    w--;

    int s = 0;

    for(int i=h-a+1;i<=min(b+h-a,h);i++){
      s+=(nCr(b+h-a,i)%mod*nCr(w-b+a,h-i)%mod)%mod;
      s%=mod;
    }
    
    int ans = (nCr(w+h,h)%mod - s%mod + mod)%mod;

    cout << ans << '\n';
 
    return 0;
} 


Measured memory_bytes: 3328
#include <cmath>
#include <queue>
#include <cstdio>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 100010
#define ll long long
#define eps 1e-8
using namespace std;
inline ll read() 
{ 
    ll x=0,f=1;char ch=getchar(); 
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 
    return x*f; 
}
ll A,B,C,D;
ll E,F; 
long double ans;
ll ansx,ansy;
int main()
{
	A=read(),B=read(),C=read(),D=read();
	E=read(),F=read();
	for(ll a=0;a<=101;a++)
	for(ll b=0;b<=101;b++)
	for(ll c=0;c<=101;c++)
	for(ll d=0;d<=101;d++)
	{
		ll x=100*A*a+100*B*b;
		ll y=C*c+D*d;
		if(y>(A*a+B*b)*E)continue ;
		//int z=min(x/100*E,y);
		ll z=y;
		if(x+y>F)continue ;
		if(x+z==0)continue ;
		long double now=(long double)(100*z)/(long double)(x+z);
		if(now-ans>eps)
		{
			ans=now;
			ansx=x;
			ansy=y;
		}
	}
	if(ans<eps)
	ansx=100*A;
	printf("%lld %lld",ansx+ansy,ansy);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch IntervalRunning | diff IntervalRunning.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address IntervalRunning.cpp && ./a.out

/*
 
 12/1/2019
 
 5:07-5:40 give up
 10:20- read editorial
 
 */

LL T[2],A[2],B[2];

string solve() {
  LL P=(A[0]-B[0])*T[0],Q=(A[1]-B[1])*T[1];
  if(P>0) P*=-1,Q*=-1;
  if(P+Q<0) return "0";
  if(P+Q==0) return "infinity";
//  dump(P,Q,P+Q);
  LL k=-P/(P+Q);
  LL rem=-P%(P+Q);
  LL res=rem!=0?2LL*k+1:2LL*k;
  return to_string(res);
}

void solve_wrong() {
  int res=0;
  LL a=0,b=0;
  int sign=-100;
  FOR(i,0,1e6) {
    a+=T[i%2]*A[i%2];
    b+=T[i%2]*B[i%2];
    LL x=min(a,b);
    a-=x,b-=x;
    int sign2=a==b?0:a>b;
    if(sign2==0||sign2!=sign) ++res;
    sign=sign2;
  }
  if(res>1e5) cout<<"infinity"<<endl;
  else cout<<res-1<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>T[0]>>T[1]>>A[0]>>A[1]>>B[0]>>B[1];
  cout<<solve()<<endl;
  
  return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  string s;
  cin >> s;
  reverse(all(s));
  int cnt = 0;
  ll tot = 0;
  rep(i,sz(s)) {
    if(s[i] == 'B') {
      cnt++;
      tot += (i+1) - cnt;
    }
  }
  cout << tot << endl;
}

Measured memory_bytes: 720
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a= sc.nextInt();
		int b= sc.nextInt();
		int c= sc.nextInt();
		
		int d = c-a+b;
		if(d>0)System.out.println(d);
		else System.out.println(0);
	}

}


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

int main(){
  long long int N,A,B,C,D,E;
  cin>>N>>A>>B>>C>>D>>E;
  long long int b;
  b=min(min(min(min(A,B),C),D),E);
  if(N%b==0){
    cout<<N/b+4<<endl;
  }else{
    cout<<N/b+5<<endl;
  }
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,m,i,j,a,b,ans=0;
    cin >> n >> m;
    int can[n][2];
    for(i=0;i<n;i++){
        for(j=0;j<2;j++){
            can[i][j] = 0;
        }
    }
    for(i=0;i<m;i++){
        cin >> a >> b;
        if(a==1) can[b-1][0]=1;
        if(b==1) can[a-1][0]=1;
        if(a==n) can[b-1][1]=1;
        if(b==n) can[a-1][1]=1;
    }
    for(i=0;i<n;i++){
        if(can[i][0]*can[i][1])ans=1;
    }
    if(ans) cout <<"POSSIBLE" <<endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  string s,t; cin >> s >> t; ll count = 0;
  if(s.at(0) == t.at(0)) count++;
  if(s.at(1) == t.at(1)) count++;
  if(s.at(2) == t.at(2)) count++;
  
  cout << count << endl;
}

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

#define MAX 1001000
bool p[MAX];
int main(){
  memset(p, true, sizeof(p));
  
  p[0] = p[1] = false;
  
  for(int i = 0 ; i < MAX ; i++){
    if(p[i]){
      for(int j = 2 * i ; j < MAX ; j += i){
	p[j] = false;
      }
    }
  }
  
  int a, d, n;
  while(cin >> a >> d >> n){
    if(a == 0 && d == 0 && n == 0) break;
    int cnt = 0;
    
    while(true){
      if(p[a]) cnt++;
      if(n == cnt) break;
      a += d;
    }
 
    cout << a << endl;
  }
  return 0;
}



    

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


def solve(inp):
    (N, R) = map(int, inp.readline().strip().split(' '))

    if N < 10:
        R += 100 * (10 - N)

    return str(R)


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
 
int main() {
	string str;
	double x1,y1,x2,y2;
	cin >> x1>>y1>>x2>>y2;
	double ans = sqrt(pow(x1-x2,2) + pow(y1-y2,2));
	printf("%lf\n", ans);
	return 0;
}


Measured memory_bytes: 3208
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		if (x <y && y < z){
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 17172
# vim: fileencoding=utf-8


def main():
    n, k = map(int, input().split())
    ans = 0
    while True:
        t = n - k ** ans
        if t == 0:
            print(ans + 1)
            return
        if t < 0:
            print(ans)
            return
        ans += 1


if __name__ == "__main__":
    main()


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

cumsum_A = []
cumsum = 0
for a in A:
    cumsum += a
    cumsum_A.append(cumsum)

ans = float('INF')
left = 0
right = 2

for center in range(1, n-2):
    ll_value = cumsum_A[left]
    lc_value = cumsum_A[center] - ll_value
    cr_value = cumsum_A[right] - cumsum_A[center]
    rr_value = cumsum_A[-1] - cumsum_A[right]

    while abs(ll_value - lc_value) > abs(ll_value - lc_value + 2*A[left+1]):
        if left == center - 1:
            break
        left += 1
        ll_value += A[left]
        lc_value -= A[left]

    while abs(cr_value - rr_value) > abs(cr_value - rr_value + 2 * A[right + 1]):
        if right == n - 2:
            break
        right += 1
        cr_value += A[right]
        rr_value -= A[right]

    candidate = max(ll_value, lc_value, cr_value, rr_value) - min(ll_value, lc_value, cr_value, rr_value)
    ans = min(ans, candidate)

print(ans)


Measured memory_bytes: 24684
def main():
    A, B, C = map(int, input().split())

    #f(A, B, C)
    editorial(A, B, C)


def editorial(A, B, C):
    """
    fより、最終値をxとするとx={max, max + 1}
    操作回数: [3x - (A+B+C)] / 2
    1回の操作で2増えるので
        差分/2が回数となる
        3x mod 2 == abc mod 2

    3max mod 2 == abc mod 2
        true: 上記の通りのあまりの一致
        false: x=max+1より、全体では3max+3より奇数増えるので一致しない
    """
    abc = [A, B, C]
    m = max(abc)
    m3 = m * 3
    s = sum(abc)

    if m3 % 2 == s % 2:
        ans = (m3 - s) // 2
    else:
        ans = (m3 + 3 - s) // 2

    print(ans)


def f(A, B, C):
    """
    A: 545, 565, 666 ans=2
    B: 445,      555 ans=1
    C: 123, 233, A pattern ans=3
    D: 135, 245, 355, 555 ans=3
    E: 235, 345, 455, A pattern ans=4
    """
    A, B, C = sorted([A, B, C])
    ans = 0
    if B != C:
        ans += C - B
        B = C
        A += ans

    diff = B - A
    ans += diff // 2
    if diff % 2 != 0:
        # A+2,BC+1
        ans += 2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)


int main() {
	int n, k;
	cin >> n >> k;
	int A[n];
	rep(i, n) cin >> A[i];
	sort(A, A+n);

	int res = 1000000000;
	rep(i, n-k+1) {
		int d = A[i+k-1] - A[i];
		res = min(res, d);
	}
	cout << res << endl;
}

Measured memory_bytes: 640
import sys
from math import log2
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10**6)


def main():
    """
    Kの指定があるのに気づかずダブリングでLCA求めちゃった・・・！
    https://algo-logic.info/lca/
    勉強になったから良しとする。ポイントとして
    1. parents[k][u]の求め方がまず再帰
    2. LCAでまず深さを揃えるとこも2べき（必ずfor文はint(log2(N))まで回すこと！）
    3. ダブリングは祖先が一致しない時だけ更新
    を押さえとけば自力で再現できそう？
    """
    N = int(input())
    repn = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b, c = map(int, input().split())
        repn[a - 1].append((b - 1, c))
        repn[b - 1].append((a - 1, c))
    depth = [-1] * N
    dist = [0] * N
    parents = [[-1] * N for _ in range(int(log2(N)) + 3)]  # parents[k][u] = (頂点uから2^k先の祖先)

    def dfs(u):
        for v, c in repn[u]:
            if depth[v] != -1: continue
            depth[v] = depth[u] + 1
            dist[v] = dist[u] + c
            parents[0][v] = u
            dfs(v)

    depth[0] = 0
    dfs(0)

    for k in range(int(log2(N)) + 2):
        for u in range(N):
            if parents[k][u] < 0:
                parents[k + 1][u] = -1
            else:
                parents[k + 1][u] = parents[k][parents[k][u]]

    def doubling(u, v):
        if depth[u] < depth[v]: u, v = v, u
        for k in range(int(log2(N)) + 1):
            if ((depth[u] - depth[v]) & (1 << k)):
                u = parents[k][u]
                k += 1
        if u == v: return u
        for k in range(int(log2(N)) + 1, -1, -1):
            if parents[k][u] != parents[k][v]:
                u = parents[k][u]
                v = parents[k][v]
        return parents[0][u]

    Q, K = map(int, input().split())
    for _ in range(Q):
        u, v = map(int, input().split())
        lca1 = doubling(u - 1, K - 1)
        lca2 = doubling(K - 1, v - 1)
        d1 = dist[u - 1] + dist[K - 1] - dist[lca1] * 2
        d2 = dist[K - 1] + dist[v - 1] - dist[lca2] * 2
        print(d1 + d2)



if __name__ == "__main__":
    main()


Measured memory_bytes: 197000
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<LL> A(N);
	for(int i=0;i<N;++i){
		cin >> A[i];
	}
	sort(A.begin(), A.end());

	LL ans = 1;
	int cnt = 0;
	int i = N-1;
	while(i>0){
		if( A[i] == A[i-1] ){
			ans *= A[i];
			++cnt;
			if( cnt == 2 ){
				cout << ans << endl;
				return;
			}
			i -= 2;
		}else{
			i -= 1;
		}
	}
	cout << 0 << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

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

int main() {
  int N;
  cin >> N;
  vector<long long> v;
  v.push_back(2);
  v.push_back(1);
  for (int i = 2; i <= N; ++i) {
    v.push_back(v.at(i - 1) + v.at(i - 2));
  }
  cout << v.back() << endl;
}


Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
ans = 1
numofcolor = [0] * (N+1)
numofcolor[0] = 3
for i in range(N):
    ans *= numofcolor[A[i]]
    ans %= 1000000007
    numofcolor[A[i]] -= 1
    numofcolor[A[i]+1] += 1
print(ans)


Measured memory_bytes: 13964
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

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




long long solve(int N, const vector<int> &a) {
    int iter = 1;
    for (int i = 0; i < N; ++i) {
        if (a[i] == iter) ++iter;
    }
//cout << iter << endl;
    if (iter == 1) return -1;
    else return N - (iter - 1);
}

int main() {
    int N; cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    cout << solve(N, a) << endl;
}

Measured memory_bytes: 1024
N, M, X = map(int, input().split())
C = [(list(map(int, input().split()))) for _ in range(N)]
 
# bit全探索を行い、参考書に関する全ての組みについて、値段と理解度を求める
ans = 10**10
for i in range(2**N):
  U = [0]*(M+1)
  for j in range(N):
    if ((i >> j) & 1):
      for k in range(M+1):
        U[k] += C[j][k]
  
  # ある組みが条件を満たすなら、その値段をvalに追加
  if sum([u >= X for u in U[1:]]) == M:
    ans = min(ans, U[0])

if ans == 10**10: print(-1)
else: print(ans)

Measured memory_bytes: 9160
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 210

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	
	priority_queue<int, vector<int>, greater<int>> Q1, Q2;
	
	int N;
	int K;
	int ans = 0;
	static int con1[MAX], con2[MAX];
	vector<int>  V;
	
	cin>>N>>K;
	
	V.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>V[i];
	}
	
	for(int i = 0; i <= N && i <= K; i++){
		
		for(int j = 0; j <= N && j + i <= K; j++){
			// cout<<i<<" "<<j<<endl;
			if(i+j > N) break;
			for(int m = 0; m <= K-i-j; m++){
				vector<int> temp;
				int sum = 0;
				for(int k = 0; k < i; k++) temp.push_back(V[k]);
				for(int k = 0; k < j; k++) temp.push_back(V[N-k-1]);
				
				sort(temp.begin(), temp.end());
				
				// cout<<"temp "<<endl;
				for(int k = 0; k < m && k < temp.size(); k++){
					temp[k] = max(0ll, temp[k]);
					// cout<<temp[k]<<" ";
				}
				// cout<<endl;
				for(int k = 0; k < temp.size(); k++){
					sum += temp[k];
				}
				// cout<<i<<" "<<j<<" "<<m<<" "<<sum<<endl;
				ans = max(sum, ans);
			}
		}
	}

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

Measured memory_bytes: 384
/* Akshat Sharma @akshat98 */
#include <iostream>
#include <bits/stdc++.h>
#define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp   make_pair
#define pb   push_back
#define F    first
#define S    second
#define ll   long long
#define MOD  1000000007
#define MAX  1000000001
#define vi 	 vector<int>
#define vl   vector<ll>
#define vpi  vector<pair<int,int> >
#define vpl  vector<pair<ll,ll> >
#define rep(i,a,b) for(i=a;i<b;i++)
#define reqp(i,a,b) for(i=a;i<=b;i++)
#define ren for(i=0;i<n;i++)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;


int main()
{
	// #ifndef ONLINE_JUDGE
//	freopen("input_file.txt", "r", stdin);
	//freopen("output_file.txt", "w", stdout);
	// #endif
	int i,j,k,l,n,test_case,a,b,c;
	test_case=1;
	//cin>>test_case;
	while(test_case--){
		int ans=0;
		cin>>a>>b>>k;
		i=a;
		while(k){
			if(a%i==0 && b%i==0){
				k--;
			}
			if(k==0)break;
			i--;
		}
		cout<<i;



	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

int main(){
  string s;
  ll k;
  cin >> s >> k;
  ll cnt=0;
  while(s[cnt]=='1'){cnt++;}
  cnt = min(cnt,k-1);
  cout << s[cnt] << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lint;
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
int main(){
    lint n;
    cin >> n;
    vector < pair <int, int> > v;
    for(int i=0; i<n; i++){
        int temp1, temp2;
        cin >> temp1 >> temp2;
        v.push_back(make_pair(temp1,temp2));
    }
    sort(v.begin(), v.end(), sortbysec);
    lint cntr1 = 0;
    
    for(int i=0; i<n; i++){
        cntr1+=v[i].first;
        
        if(cntr1>v[i].second){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 3444
// Lets go to the next level
// AIM EXP at CF *__* asap
// Hit A,B,C faster and reach Expert
// Remember you were also a novice when you started,
// hence never be rude to anyone who wants to learn something!Be calm and help everyone.
// Never open the rank list until and unless you are done with solving problems!
/*HACK ME IF YOU CAN!
░░███▒▒░░░░░░░░░░░░░░░░████
░░████▒░░░░░░░░░░░░░░░███▒█
░░██████░░░░░░░░░░░░░███▒▒▒█
░░██▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒█████▒██
░▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▓▓▓▓▓▓▒▒▒░██
▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒█
▒▒▓▓███████▓░▓▓███████▓▒▒▒▒▒▒
▒▒▓▓▓█▓▄▓█▓░░░▓▓█▓▄▓█▓▓▒▒▒▒▒▒
▒▒▓▓▓▓███▓░░░░░▓▓███▓▓▓▒▒▒▒▒▒
▒▒▒▓▓▓▓▓▓████▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒
▒▒▒▒▓▓▓▓▓▒██▒▒▒▓▓▓▓▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
░▒▒▒▒▒▒▒▒█████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
░░▒▒▒▒▒▒█▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒
░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
*/

//Author: kaiyu
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define leastsigbit(x)     __builtin_ffs(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<int,int>
#define vpii vector<pii>
#define tt ll tt;cin >> tt;while(tt--)
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n";}
const double PI = acos(-1);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm( ll x, ll y) { return (x*y)/gcd(x,y);}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
bool isPowerOfTwo(int x)
{
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
}
struct cmp {
    bool operator() (const pair<int,int>& lhs, const pair<int,int>& rhs) const {
        return lhs.ff * rhs.ss < lhs.ss * rhs.ff;
    }
//for map<pii,int>
};

bool cmps(pair<int,int>p1,pair<int,int>p2) {
    return p1.ss > p2.ss;
}

const int MAXN = 2e5+ 10;

#define int long long
int32_t main() {
//#ifndef ONLINE_JUDGE
    //freopen("inp1.txt","r",stdin);
    //freopen("out1.txt","w",stdout);
//#endif
    fio

    int a;
    cin >> a;
    cout << a+a*a+a*a*a << endl;

    cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;


}






Measured memory_bytes: 3792
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

li bip(vector<vector<int>>& adj,int a=0,int part=1){
  static li va=0;
  int n=adj.size();
  static vector<int> seen(n,0);
  seen[a]=part;
  if(part==1) va++;
  for(int v:adj[a]){
    if(seen[v]){
      if(seen[v]==seen[a]) return 0;
      continue;
    }
    if(not bip(adj,v,part*(-1))) return 0;
  }
  return va;
}


int main(){
  int n,m; cin >>n >>m;
  vector<vector<int>> adj(n);
  rep(i,m){
    int a,b; cin >>a >>b; a--;b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  li f;
  if(f=bip(adj)){
    print(f*(n-f)-m);
  }else{
    print((li)n*(n-1)/2-m);
  }
}


Measured memory_bytes: 6528
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

// 参考：Um_nik氏のソースコード
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  sort(ALL(a));
  bool ok = true;
  if (n % 3 == 0) {
    n /= 3;
    bool check1 =
        a[0] == a[n - 1] && a[n] == a[2 * n - 1] && a[2 * n] == a[3 * n - 1];
    bool check2 = (a[0] ^ a[n] ^ a[2 * n]) == 0;
    if (check1 && check2)
      ok = true;
    else
      ok = false;
  } else {
    if (a[n - 1] != 0) ok = false;
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 640
//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] w = new int[n];
        int a = 0;
        int b = 0;
        for(int i = 0 ; i < n ; i++){
            w[i] = sc.nextInt();
            b += w[i];
        }
        a += w[0];
        b -= w[0];
        int yono = 1000000;
        for(int i = 1 ; i < n ; i++){
            yono = Math.min(yono , Math.abs(a - b));
            a += w[i];
            b -= w[i];
        }
        System.out.println(yono);
    }
}

Measured memory_bytes: 35924
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().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
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()

money = []
pow6 = 1
while pow6 <= N:
    money.append(pow6)
    pow6 *= 6
pow9 = 9
while pow9 <= N:
    money.append(pow9)
    pow9 *= 9
lm = len(money)
dp = [INF for _ in range(N+1)]
dp[0] = 0
for i in range(lm):
    for j in range(N+1):
        if j - money[i] >= 0:
            dp[j] = min(dp[j], dp[j-money[i]]+1)
print(dp[N])


Measured memory_bytes: 9196
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    x1, y1, x2, y2 = LI()
    a = x2 - x1
    b = y2 - y1
    print(x2 - b, y2 + a, x1 - b, y1 + a)
    return

#C
def C():
    n, k = LI()
    if k % 2:
        print((n // k)** 3)
    else:
        print(int((n//k)**3 + ((n-k/2)//k+1)**3))
        
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

int main() {
  double PI = 3.14159265358979;
  double a, b, x;
  cin >> a >> b >> x;
  double S = x / a;

  if (S > a * b / 2) {
    double y;
    y = 2 * S / a - b;
    double t = b - y;
    double theta = atan(t / a) * 180 / PI;
    fcout << theta;
  } else {
    double t = 2 * S / b;
    double theta = atan(b / t) * 180 / PI;
    fcout << theta;
  }

  return 0;
}

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

int main()
{
	int n, m, l;
	cin >> n >> m >> l;
	vector<vector<long long int>> v1(n, vector<long long int>(m, 0));
	vector < vector<long long int>> v2(m, vector<long long int>(l, 0));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> v1[i][j];
		}
	}
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < l; j++)
		{
			cin >> v2[i][j];
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			long long int acc = 0;
			for (int k = 0; k < m; k++)
			{
				acc += v1[i][k] * v2[k][j];
			}
			string s = (j == l - 1) ? "\n" : " ";
			cout << acc << s;
		}
	}

	return 0;
}

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

const int maxn=1000005;
int n;
int data[maxn];

int main()
{
    while(~scanf("%d", &n)){
        int a=0, b=0, c=0;
        for(int i=0;i<n;i++){
            scanf("%d", &data[i]);
            if(data[i]%4==0)a++;
            else if(data[i]%2==0)b++;
            else c++;
        }
        int ans=0;
        if(b%2==0)c--;
        if(a>=c)ans=1;
        printf("%s\n", ans?"Yes":"No");
    }
    return 0;
}


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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MOD  1000000007
#define mod1 1000000009
#define var    int i,j,c=0,t,l,r,mid,z=0,k,x,y
#define aloc(n,t) ((t*)malloc((n)*sizeof(t)))

//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

string s;
ll a[2019];

int main()
{
    cin>>s;
    reverse(s.begin(),s.end());
    ll n = 2019,ans =0,cnt = 0,p=1;
    a[0] = 1;
    for(int i=0;i<s.size();i++)
    {
        cnt = cnt + p*(s[i]-48);
        cnt%=n;
        ans += a[cnt];
        a[cnt]++;
        p = p*10;p%=n;
    }
    cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

const int MAXN = 12;

int n, m, x;
int c[MAXN], a[MAXN][MAXN];

void read() {
	cin >> n >> m >> x;
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
}

int have[MAXN];

bool check(int mask) {
	fill(have, have + m, 0);
	for (int i = 0; i < n; i++) {
		if (!((mask >> i) & 1)) continue;
		for (int j = 0; j < m; j++) {
			have[j] += a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		if (have[i] < x) return false;
	}
	return true;
}

int cost(int mask) {
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if ((mask >> i) & 1) {
			ans += c[i];
		}
	}
	return ans;
}

const int INF = 1e9 + 10;
int ans;

void run() {
	ans = INF;
	for (int mask = 0; mask < (1 << n); mask++) {
		if (!check(mask)) continue;
		chkmin(ans, cost(mask));
	}
	if (ans == INF) ans = -1;
}

void write() {
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

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

#define ll long long

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int cnt = 0;
	for (int i = 0; i < n-2; i++) {
		for (int j = i + 1; j < n-1; j++) {
			for (int k = j + 1; k < n; k++) {
				if (a[i] == a[j] || a[i] == a[k] || a[j] == a[k]) continue;
				if (a[i] + a[j] > a[k]) {
					cnt++;
				}
			}
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>

using namespace std;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) cout << "ACL";
    cout << endl;
}


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

A, B, C, X, Y = map(int, input().split(' '))

ans = 2 * 100000 * 5000
for i in range(10**5+1):
    price = 2*C*i + A*max(0, X-i) + B*max(0, Y-i)
    ans = min(ans, price)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll X,L=0,A;cin>>X;
    A=X;
    while(X>0){
        L+=X%10;
        X/=10;
    }
    cout << (A%L==0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> x(n), y(n);
	rep(i,n) cin >> x.at(i) >> y.at(i);
	double ans = 0;
	vector<int> b(n);
	rep(i,n) b.at(i) = i;
	ll t = 1;
	for(int i = 1; i <= n; i++) t *= i;
	do{
		double sum = 0;
		rep(i,n-1){
			sum += sqrt(pow(x.at(b.at(i)) - x.at(b.at(i + 1)), 2) + pow(y.at(b.at(i)) - y.at(b.at(i + 1)), 2));
		}
		ans += sum / t;
	}while(next_permutation(b.begin(),b.end()));
	
	cout << setprecision(20) << fixed << ans << endl;
}


Measured memory_bytes: 256
/*************************************
 * problem:      AT2163.
 * user ID:      63720.
 * user name:    Jomoo.
 * time:         2019-mm-dd.
 * language:     C++.
 * upload place: Luogu.
*************************************/ 

#include <bits/stdc++.h>
using namespace std;
#define puts_return(x) { puts(x); return 0; }

typedef signed char          int8;
typedef unsigned char       uint8;
typedef short                int16;
typedef unsigned short      uint16;
typedef int                  int32;
typedef unsigned            uint32;
typedef long long            int64;
typedef unsigned long long  uint64;

template <typename Int>
inline Int read()       
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}  

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}

int n, x;
bool used[200003];

int main()
{
    n = read<int>();
    x = read<int>();
    if (x == 1 || x == 2 * n - 1) puts_return("No");
    puts("Yes");
    used[x - 1] = true;
    used[x] = true;
    used[x + 1] = true;
    if (x == 2) used[x + 2] = true;
    else used[x - 2] = true;
    int pos = 1;
    for (int i = 1; i <= n - 2 - (x == 2); i++) {
        while (used[pos]) pos++;
        write(pos, 10);
        pos++;
    }
    if (x == 2 && n != 2) write(x + 2, 10);
    write(x - 1, 10);
    write(x, 10);
    write(x + 1, 10);
    if (x != 2) write(x - 2, 10);
    for (int i = n + 2 + (x != 2); i <= 2 * n - 1; i++) {
        while (used[pos]) pos++;
        write(pos, 10);
        pos++;
    }   
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i;
  double x,ans;
  string u;
  cin >> n;
  ans=0.0;
  for(i=0;i<n;i++){
    cin >> x >> u;
    if(u=="JPY"){
      ans+=x;
    }else{
      ans+=x*380000;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

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

int main(){
    cin.tie(0);

    string s; cin >> s;
    if (s[6] < '5' && s[5] == '0'){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }

}


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

int main(){
  int n;
  cin>>n;
  if(n>399 && n<600) cout<<"8";
  if(n>599 && n<800) cout<<"7";
  if(n>799 && n<1000) cout<<"6";
  if(n>999 && n<1200) cout<<"5";
  if(n>1199 && n<1400) cout<<"4";
  if(n>1399 && n<1600) cout<<"3";
  if(n>1599 && n<1800) cout<<"2";
  if(n>1799 && n<2000) cout<<"1";
}

Measured memory_bytes: 3608
def gcd(x,y):
  if y==0:
    return x
  else:
    return gcd(y,x%y)

n=int(input())
a=list(map(int,input().split()))
a=list(sorted(a))

g=a[0]
for aa in a:
  g=gcd(g,aa)
print(g)


Measured memory_bytes: 14252
import java.util.Scanner;
class Main{
    public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n,x;
		int a,b,c;
		int cnt=0;
		n=sc.nextInt();
		x=sc.nextInt();
		while(!(n==0&&x==0)){
			for(int i=1;i<=n-2;i++){
				for(int j=i+1;j<=n-1;j++){
					for(int k=j+1;k<=n;k++){
						if(i+j+k==x){
							cnt++;
						}
					}
				}
			}
			System.out.println(cnt);
			cnt=0;
			n=sc.nextInt();
			x=sc.nextInt();
		}
    }
}




Measured memory_bytes: 26616
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();	
		if(b%a==0) {
			System.out.println(a+b);
		}else {
			System.out.println(b-a);
		}
	}
}

Measured memory_bytes: 21332
N = gets.to_i
A = gets.split.map(&:to_i)

counter = Hash.new(0)

A.each do |a|
  color = case a
          when 1..399
            0
          when 400..799
            1
          when 800..1199
            2
          when 1200..1599
            3
          when 1600..1999
            4
          when 2000..2399
            5
          when 2400..2799
            6
          when 2800..3199
            7
          else
            8
          end

  counter[color] += 1
end

colors = counter.keys.select { |x| x <= 7 }

min = [colors.size, [counter[8], 1].min].max
max = colors.size + counter[8]

puts [min, max].join(' ')


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main() {

    int i,H,N,a,sum=0;

    cin>>H>>N;

    for(i=0;i<N;i++)
    {
        cin>>a;
        sum = sum + a;
    }

    if(sum>=H)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 3e3 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n;
ll arr[maxn], dp[maxn][maxn][2];
ll solve(int l, int r, ll f)
{
    if(dp[l][r][f] != -1) return dp[l][r][f];
    if(l == r) return f * arr[l];
    if(f == 1) return dp[l][r][1] = max(arr[l] + solve(l + 1, r, 0), arr[r] + solve(l, r - 1, 0));
    else return dp[l][r][0] = min(solve(l + 1, r, 1), solve(l, r - 1, 1));
}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    ll sum = 0;
    for(int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        sum += arr[i];
    }
    memset(dp, -1, sizeof dp);
    cout << 2 * solve(1, n, 1) - sum << "\n";
    return 0;
}


Measured memory_bytes: 150528
n,k = gets.split.map(&:to_i)
ab = Array.new(n,[])
n.times do |i|
  ab[i] = gets.split.map(&:to_i)
end
ab.sort_by! do |ab_i|
  ab_i[0]
end
result = []
count = 0
ab.each do |ab_i|
  count += ab_i[1]
  if count >= k
    puts ab_i[0]
    exit
  end
end

Measured memory_bytes: 12792