akhauriyash/Code-Regression huggingface dataset:
n,a,b,c=[int(i) for i in input().split()]
l = [int(input()) for _ in range(n)]
INF=10**9

def dfs(times,A,B,C):
    if times==n:
        return abs(A-a)+abs(B-b)+abs(C-c)- 30 if min(A,B,C)>0 else INF
    non_ans=dfs(times+1,A,B,C)
    a_ans=dfs(times+1,A+l[times],B,C)+10
    b_ans=dfs(times+1,A,B+l[times],C)+10
    c_ans=dfs(times+1,A,B,C+l[times])+10
    return min(non_ans,a_ans,b_ans,c_ans)

print(dfs(0,0,0,0))


Measured memory_bytes: 3064
require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
a=gsmi.sort
putsend 1 if a.size==1

max=a[-1]
a.each do |aa|
  h[aa]+=1
end

ar=h.to_a.select{|x,y|y==1}.sort
doubles = h.to_a.select{|x,y|y>1}.map{|i|i[0]}
ngs=Array.new(max+1)

doubles.each do |i|
  i.step(max,i) do |j|
    ngs[j]=1
  end
end

ar.each do |aa,c|
  unless ngs[aa]
    aa.step(max,aa) do |j|
      ngs[j]=1
    end
    cnt+=1
  end
end
puts cnt

Measured memory_bytes: 59004
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main(){
  ll a, b;
  cin >> a >> b;

  ll tmp = b;
  ll c = a;

  while(tmp > 0){
    c *= 10;
    tmp /= 10;
  }

  c += b;

  rep(i, 1000){
    if(i * i == c){
      cout << "Yes" << endl;
      return 0;
    }
    if(i * i > c){
      break;
    }
  }

  cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 764
import numpy as np
from collections import defaultdict
from functools import reduce

# s = input()
# n = int(input())
# A = list(map(int, input().split()))
n, a, b, c, d  = map(int, input().split())
a = a-1
b = b-1
c = c-1
d = d-1
s2 = input()
s = list(s2)

if '...' in s2[(b-1):(d+1)] and not ('##' in s2[a:c]):
    print('Yes')
    exit()


if all(s[i] == '.' or s[i+1] == '.' for i in range(b,d)):
    s[d] = '#'
    if all(s[i] == '.' or s[i+1] == '.' for i in range(a,c)):
        print('Yes')
        exit()

print('No')




Measured memory_bytes: 14412
import java.util.Scanner;

public class Main {

	static Scanner sc;
	static String input;

	public static void main(String[] args) {
		//初期化
		init();

		String ans = "";
		//メインの処理
		switch(input) {
		case "A":
			ans = "T";
			break;
		case "T":
			ans = "A";
			break;
		case "G":
			ans = "C";
			break;
		case "C":
			ans = "G";
			break;
		}

		System.out.println(ans);

		sc.close();
	}

	private static void init() {
		sc = new Scanner(System.in);
		input = sc.nextLine();
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,s,e) for(ll i=s;i<e;++i)

int main(){
    string s;
    cin >> s;
    if(s[s.size()-1]=='s') s+="es";
    else s+="s";

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3596
X = []
for _ in range(3):
    X.append(list(map(int,input().split(' '))))

for i in range(3):
    D = []
    for j in range(3):
        D.append(X[i][j]-X[i-1][j])
    if len(set(D)) > 1:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 3060
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
using namespace std;

int main(void){
    int n,x;
    cin >> n >> x;
    int boy[102];
    for(int i=0; i<n; i++){
        cin >> boy[i];
    }
    int temp,change;
    for(int i=0; i<n; i++){
        temp=i;
        for(int j=i; j<n; j++){
            if(boy[temp]>boy[j])temp=j;
        }
        change=boy[i];
        boy[i]=boy[temp];
        boy[temp]=change;
    }
    int ans=0;
    for(int i=0; i<n; i++){
        x-=boy[i];
        if(x>=0)ans++;
        else break;
    }
    if(x>0)ans--;
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n; cin>>n;
    int fn=0;
    for(int i=n;i!=0;i/=10){
        fn+=i%10;
    }
    if(n%fn==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long int a[2050]= {0};
const long long int inf=0x3f3f3f3f3f3f3f3f;
long long int b[2050][2050]= {0};
long long int n,x;
long long zz=inf;
int main()
{
    scanf("%lld%lld",&n,&x);
    for(long long int i=1; i<=n; i++)
    {
        scanf("%lld",&a[i]);
    }
    for(long long int i=1; i<=n; i++)
    {
        b[i][0]=a[i];
        for(long long int j=1; j<n; j++)
        {
            long long int cz=i-j;
            if(cz<=0)
                cz+=n;
            b[i][j]=min(b[i][j-1],a[cz]);
        }
    }
    for(long long int i=0; i<n; i++)
    {
        long long sum=x*i;
        for(long long int j=1; j<=n; j++)
            sum+=b[j][i];
        zz=min(zz,sum);
    }
    printf("%lld",zz);
    return 0;
}


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

#define ll long long
using namespace std;

const int e = 2e5 + 69;

ll a[e];

int main()
{
    int n;
    ll k;
    cin >> n >> k;
    map<ll,ll>kt;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
    }
    int pos = 1;
    vector<int>cur, ans;
    while(kt[pos] == 0)
    {
        kt[pos] ++;
        //cout << pos <<" ";
        cur.push_back(pos);
        pos = a[pos];
    }
    kt[pos] ++;
    //cur.push_back(pos);
    bool chk = false;
    int dem = 0;
    for(auto j : cur){
        if(kt[j] == 2 && chk == false){
            chk = true;
            ans.push_back(j);
        }
        else if(kt[j] == 2 && chk == true){
            //ans.push_back(j);
            break;
        }
        else if(chk == true) ans.push_back(j);
        else if(chk == false) dem ++;
    }
    if(k < dem)
    {
        cout << cur[k] ;
        return 0;
    }
    k -= dem;
    //k --;
    //if(kt[1] == 2) k ++;
    //for(auto j : ans) cout << j <<" ";
    cout << ans[k % ans.size()];


}
/*

*/


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int n;
bool dp[101010];
void solve(){
	cin >> n;
	
	priority_queue<P,vector<P>,greater<P>> q;
	q.push({1,1});
	while(!q.empty()){
		P p = q.top(); q.pop();
		int c = p.first, a = p.second;
		a %= n;
		if(a == 0){
			cout << c << endl;
			break;
		}
		if(dp[a]) continue;
		dp[a] = 1;
		q.push({c,a*10});
		q.push({c+1,a+1});
		//cout << c << " " << a << endl;
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 2548
#include <stdio.h>
#include <stdlib.h>
 
int
main (
  int   argc,
  char *argv[ ]
  )
{
  double x[ 4 ], y[ 4 ];
  int n;
 
  scanf ( "%d", &n );
  while ( n-- )
  {
    scanf ( "%lf%lf%lf%lf%lf%lf%lf%lf", &x[ 0 ], &y[ 0 ]
          , &x[ 1 ], &y[ 1 ], &x[ 2 ], &y[ 2 ], &x[ 3 ], &y[ 3 ] );
 
    puts ( fabs ( ( y[ 1 ] - y[ 0 ] ) * ( x[ 3 ] - x[ 2 ] )
                - ( y[ 3 ] - y[ 2 ] ) * ( x[ 1 ] - x[ 0 ] ) ) < 1e-12
         ? "YES" : "NO" );
  }
 
  return ( EXIT_SUCCESS );
}

Measured memory_bytes: 620
N = input()
A = [int(a) for a in input().split()]

ans = 1

if 0 in A:
    print(0)
    exit()

for i in range(len(A)):
    if ans > 10 ** 18:
        print(-1)
        exit()
    ans *= A[i]


if ans > 10 ** 18:
    print(-1)
    exit()
print(ans)

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

int main(){
  int N, K, R, S, P;
  string T;

  cin >> N >> K >> R >> S >> P >> T;

  int ans;
  vector<bool> win;
  for(int i=0; i<T.length(); i++){
    if(i-K < 0){
      if(T[i] == 'r') ans += P; 
      else if(T[i] == 's') ans += R;
      else if(T[i] == 'p') ans += S; 
      win.push_back(true);
    } else {
      if(T[i] == T[i-K] && win[i-K] == true){
        win.push_back(false);
      } else {
        if(T[i] == 'r') ans += P; 
        else if(T[i] == 's') ans += R;
        else if(T[i] == 'p') ans += S; 
        win.push_back(true);
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
using namespace std;

int main(){
  int N, L, S = 0;
  cin >> N >> L;
  int T[N];
  for (int i = 0; i < N; i++) {
    T[i] = L + i;
    S += T[i];
  }
  sort(T, T + N);
  for (int i = 0; i < N; i++) {
    if (T[i] == 0) {
      cout << S << endl;
      break;
    }
    else if (T[i] > 0 && i == 0) {
      cout << S - T[0] << endl;
      break;
    }
    else if (T[i] > 0 && i != 0) {
      if (fabs(T[i-1]) > fabs(T[i])) {
        cout << S - T[i] << endl;
        break;
      }
      else {
        cout << S - T[i-1] << endl;
        break;
      }
    }
    else if (i == N-1) {
      cout << S - T[N-1] << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long
#define mod 1000000007

void solve() {
        int n; cin >> n;
        int cnt = 0;
        while (n> cnt) {
                cnt+= 1000;
        }
        cout << cnt- n;
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int t = 1;
        //cin >> t;
        while ( t-- ) {
                solve();
        }
return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	//int n; cin >> n;
	
	vector<int> a(5); rep(i,5) cin >> a[i];
	rep(i, 5)if(a[i]==0) cout << i+1 << endl;
	
	

	
	return 0;
}


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

int main(){
  int n,x= 0,y = 0,t = 0,xi,yi,ti;
  cin >> n;
  bool can = true;



  for(int i =0;i < n; i++){
    cin >> ti >> xi >> yi;
    if(ti - t < abs(xi - x) + abs(yi - y)){
      can = false;
      break;
    }

    if(((ti - t)-abs(xi - x) - abs(yi - y))%2 == 0){
      x = xi;
      y = yi;
      t = ti;
    }else{
      can = false;
      break;
    }

  }

if(can){
  cout << "Yes" << endl;
}else{
  cout << "No" << endl;
}
  return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
	fast;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans=b-a+1;
	if(a==b)
	{
		if(a%c==0||a%d==0)
			cout<<0;
			return 0;
	}
	ans=ans-(b/c - (a-1)/c) - (b/d - (a-1)/d) + (b/lcm(c,d) - (a-1)/lcm(c,d));
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define pb push_back
#define int long long int
#define f(i,a,b) for (int i= a; i <b; ++i)
using namespace std;

vector<int> v[100005];
int dp[100005];

int solve(int src)
{
    if(dp[src]!=-1)
        return dp[src];
    int best=0;
    for(int i=0;i<v[src].size();i++)
    {
        best=max(best,1+solve(v[src][i]));
    }
    return dp[src]=best;

}
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,x,y;
    cin>>n>>m;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        v[x].push_back(y);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans=max(ans,solve(i));
    }
    cout<<ans;
}



Measured memory_bytes: 8576
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;


//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;




/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/
/*
const int N=100001;
ll fact_inverse[N];
ll num_inverse[N];
ll fact[N];
void number_inverse(int m){
   num_inverse[0]=1;
   num_inverse[1]=1;
   for(int i=2;i<=N;i++){
     num_inverse[i]=num_inverse[m%i]*(m - m/i)%m;
   }
}

void factorial_inverse(int m){
   fact_inverse[0]=1;
   fact_inverse[1]=1;
   for(int i=2;i<=N;i++){
      fact_inverse[i]=(num_inverse[i]*fact_inverse[i-1])%m;
   }
}

void factorial(int m){
  fact[0]=1;
  for(int i=1;i<=N;i++)fact[i]=(i*fact[i-1])%m;
}

int modular_nCr(int n,int r,int m){
   ll res=((fact[n]*fact_inverse[r])%m *  fact_inverse[n-r])%m;
   return res;
}
*/
int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
       string s;
       cin>>s;
       if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes"<<endl;
       else cout<<"No"<<endl;
  }
}









Measured memory_bytes: 3448
import sys

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


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

    dp = [[0] * (N * 50 + 1) for j in range(N + 1)]
    dp[0][0] = 1

    for i in range(N):
        for j in range(N, 0, -1):
            for k in range(X[i], N * 50 + 1):
                dp[j][k] += dp[j - 1][k - X[i]]

    ans = 0
    for j in range(1, N + 1):
        ans += dp[j][A * j]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 67276
#include<bits/stdc++.h>
using namespace std;
long long n,m,all;
long long f[100001],v[100001],w[100001];
int main(){
	cin>>n>>all;
	for(int i=1;i<=n;i++){
		cin>>w[i]>>v[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=all;j>=w[i];j--)
    	{
    		f[j]=max(f[j],f[j-w[i]]+v[i]);
    	}
	}
    cout<<f[all];
    return 0;
} 

Measured memory_bytes: 1024
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left # bisect_left(list, value)
#from fractions import gcd

sys.setrecursionlimit(10**7)
N = int(input())
X = list(map(int, input().split()))
X.sort()

minv = 10**18

for xi in range(X[0], X[-1]+1):
    val = 0
    for xj in X:
        val += (xi - xj) ** 2
    if minv > val:
        minv = val

print(minv)


Measured memory_bytes: 38896
from bisect import bisect_right, bisect_left
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
s = 0
for j in range(N):
    s += bisect_left(A, B[j]) * (N - bisect_right(C, B[j]))
print(s)

Measured memory_bytes: 23360
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm> // sort
#include <map>       // pair
#include <vector>
using namespace std;

#define REP(a,b) for(int i =(a);i < (b);i++)
#define FOR(n) for(int i = 0; i<(n); i++)
#define COUT(c)  cout<<(c)<<endl


const int INF = 100100100;
const int MOD = (int)1e9 +7;
const double EPS = 1e-9; 

typedef long long int ll;

//char in[120];
//ex. pair
//pair<pair<string,int>,int> p[110];

int main(){
    ll n;cin>>n;
    ll pref=0,now=0;
    cin >> pref;
    pref--;
    if(n==1){
        cout<< "Yes" << endl;
        return 0;
    }
    FOR(n-1){
        cin >> now;
        //cout << pref << " " <<now << endl;
        if(pref > now){
            cout << "No" << endl;
            return 0;
        }
        if(pref < now){
            pref = now - 1;
        }else{
            pref = now;
        }
    }
    cout << "Yes" <<endl;
    return 0;    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdlib.h>
#include<set>
#include<math.h>
#include<iomanip>

using namespace std;


int main(void)
{
    int k,x;
    cin>>k>>x;
    
    for(int i=-(k-1);i<k;i++){
        cout<<x+i<<" ";
    }
    cout<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_V 1000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const long long int MOD = 1000000007;
const int INF = 100000000;

struct edge{int to, cap, rev; };

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap){
	G[from].push_back((edge){to, cap, G[to].size()});
	G[to].push_back((edge){from, cap, G[from].size()-1});
}

int dfs(int v, int t, int f){
	if(v == t) return f;
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			int d = dfs(e.to, t, min(f,e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t){
	int flow = 0;
	for(;;){
		memset(used, 0, sizeof(used));
		int f = dfs(s,t,INF);
		if(f == 0) return flow;
		flow += f;
	}
}


int n, e, q;
int x[1000], s[1000], t[1000];
set<P> saw;
int pre = 0;

int main(){
    cin >> n >> e >> q;
    rep(i,e){
        int s, t;
        cin >> s >> t;
        if(s > t) swap(s,t);
        s--; t--;
        saw.insert(P(s,t));
        add_edge(s,t,1);
    }
    rep(i,q){
        cin >> x[i] >> s[i] >> t[i];
        s[i]--; t[i]--;
        if(s[i] > t[i]) swap(s[i],t[i]);
        if(saw.count(P(s[i],t[i])) == 0){
            add_edge(s[i],t[i],0);
            saw.insert(P(s[i],t[i]));
        }
    }
    pre = max_flow(0,n-1);
    rep(i,q){
        if(x[i] == 1){
            rep(j,G[s[i]].size()){
                int rev = G[s[i]][j].rev;
                if(G[s[i]][j].to == t[i]){
                    G[s[i]][j].cap = 1;
                    G[t[i]][rev].cap = 1;
                }
            }
            memset(used,0,sizeof(used));
            pre = dfs(0,n-1,1)+pre;
        } else{
            int div = 0;
            rep(j,G[s[i]].size()){
                int rev = G[s[i]][j].rev;
                if(G[s[i]][j].to == t[i]){
                    div = G[s[i]][j].cap;
                    G[s[i]][j].cap = 0;
                    G[t[i]][rev].cap = 0;
                }
            }
            memset(used,0,sizeof(used));
            if(div == 0){
                if(dfs(s[i],t[i],1) == 0){
                    memset(used,0,sizeof(used));
                    dfs(n-1,t[i],1);
                    memset(used,0,sizeof(used));
                    dfs(s[i],0,1);
                    pre--;
                }
            } else if(div == 2){
                if(dfs(t[i],s[i],1) == 0){
                    memset(used,0,sizeof(used));
                    dfs(n-1,s[i],1);
                    memset(used,0,sizeof(used));
                    dfs(t[i],0,1);
                    pre--;
                }
            }
        }
        cout << pre << endl;
    }
}

Measured memory_bytes: 4900
N, K, L, *A = map(int, open(0).read().split())

def solve(X):
    R = []
    res = 0
    for t, a in enumerate(A):
        if a <= X:
            R.append(t)
        if len(R) >= K:
            res += R[-K]+1
    return res >= L

left = 0; right = N
while left+1 < right:
    mid = (left + right) >> 1
    if solve(mid):
        right = mid
    else:
        left = mid
print(right)


Measured memory_bytes: 27652
#include <iostream>
//#include <iomanip>
using namespace std;

int main()
{
    double n,a,sum=0,total;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
      cin>>a;
      sum = sum+(1/a) ;
      total = 1/sum;
    }
    //cout<<fixed;
    //cout<<setprecision(5);
    cout<<total;
    return 0;
}


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

void solve(std::vector<long long> H, std::vector<long long> M, long long K){
    ll start = H[0]*60 + M[0];
    ll end = H[1]*60 + M[1];
    cout << max(end-start -K,0ll) <<endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::vector<long long> H(2);
    std::vector<long long> M(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&H[i]);
        scanf("%lld",&M[i]);
    }
    long long K;
    scanf("%lld",&K);
    solve(std::move(H), std::move(M), K);
    return 0;
}


Measured memory_bytes: 3692
while True:
    n=int(input())
    if n==0:
        break
    m=[0 for i in range(10)]
    for i in range(n):
        a=int(input())
        m[a]+=1
    for a in m:
        if a>0:
            print("*"*a)
        else:
            print("-")
    



Measured memory_bytes: 5628
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < n-2; i++){
		if(s.substr(i,3) == "ABC")
			cnt++;
	}
	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 256
inp=input
li=list
iinp=lambda : int(inp())
ent=lambda : map(int,inp().split())
lient=lambda : [int(i) for i in inp().split()]
li0= lambda x: [0 for i in range(x)]
livalor=lambda valor,x: [valor for i in range(x)]
stent=lambda : [i for i in inp()]
filldp=lambda valor,x,y: [[valor for i in range(y)] for i in range(x)]

meta=iinp()
inicio=100
res=1
while True:
    inicio=inicio+int(inicio*0.01)
    if inicio>=meta:
        print(res)
        break
    res=res+1

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

ll BIT[200200], BIT2[200200];
void add(int A, int B) {
	while (A < 200200) {
		BIT[A] += B;
		A += A & -A;
	}
}

ll query(int A) {
	ll kotae = 0;
	while (A > 0) {
		kotae += BIT[A];
		A -= A & -A;
	}
	return kotae;
}

void add2(int A) {
	while (A < 200200) {
		BIT2[A]++;
		A += A & -A;
	}
}

ll query2(int A) {
	ll kotae = 0;
	while (A > 0) {
		kotae += BIT2[A];
		A -= A & -A;
	}
	return kotae;
}

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


	int Q;
	cin >> Q;

	int QL[200000];
	pair<int, int> Q1[200000];
	vector<int> Q1N;
	vector<int>za;
	rep(q, Q) {
		cin >> QL[q];
		if (QL[q] == 1) {
			int a, b;
			cin >> a >> b;
			Q1[q] = mp(a, b);
			za.pb(a);
			Q1N.pb(q);
		}
	}

	vector<int> za2;
	sort(za.begin(), za.end());
	int mae = -1e9 - 1;
	for (int i : za) {
		if (mae != i) za2.pb(i);
		mae = i;
	}

	ll B = 0;
	int SIZE = 0;
	rep(q, Q) {
		if (QL[q] == 1) {
			SIZE++;
			B += Q1[q].second;
			int QK = lower_bound(za2.begin(), za2.end(), Q1[q].first) - za2.begin() + 1;
			add(QK, Q1[q].first);
			add2(QK);
		}
		else {
			int s = SIZE;
			s = (s + 1) / 2;
			
			int L = 0;
			int R = 200199;
			while (L + 1 < R) {
				int H = (L + R) / 2;
				if (query2(H) >= s) R = H;
				else L = H;
			}
			int kari = za2[R - 1];
			cosp(kari);
			ll kotae = B;
			kotae += 1ll * query2(R) * kari - query(R);
			kotae += (query(200199) - query(R)) - 1ll * (SIZE - query2(R)) * kari;
			co(kotae);
		}
	}

	Would you please return 0;
}

Measured memory_bytes: 7924
import collections
n = int(raw_input())
nums = map(int,raw_input().split(' '))
q = int(raw_input())
s = sum(nums)
h = collections.Counter(nums)
for _ in range(q):
	ov,nv = map(int, raw_input().split(' '))
	h[nv] += h[ov]
	s += h[ov] * (nv - ov)
	
	h[ov] = 0
	print s

Measured memory_bytes: 96872
def base_10_to_n(X, n):
    if (int(X/n)):
        return base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

def f(a,la,A):
    if la == 0:
        return 1e12
    return (la-1)*10 + abs(a-A)

N,A,B,C = map(int,input().split())
l = [int(input()) for i in range(N)]

ans = 1e12
for i in range(4**N+1):
    tmp = list(base_10_to_n(i,4).zfill(N))
    a,la,b,lb,c,lc = 0,0,0,0,0,0
    for s,t in zip(tmp,l):
        if s == "1":
            a += t
            la += 1
        elif s == "2":
            b += t
            lb += 1
        elif s == "3":
            c += t
            lc += 1
    ans = min(ans,f(a,la,A)+f(b,lb,B)+f(c,lc,C))

print(ans)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    dp = [0, abs(h[0] - h[1])]
    for i in range(2, n):
        min_cost = float('inf')
        for j in range(max(i - k, 0), i):
            cost = dp[j] + abs(h[j] - h[i])
            if min_cost > cost:
                min_cost = cost
        dp.append(min_cost)


    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 20584
#include <cstdio>
#include <vector>
#include <algorithm>

int n;
int W[1000], S[1000], V[1000];


long long int dp[20001];

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++) scanf("%d%d%d", W+i, S+i, V+i);
  std::vector<std::pair<int, int> > v;
  for(int i = 0; i < n; i++){
    v.emplace_back(S[i] + W[i], i);
  }
  std::sort(v.begin(), v.end());
  for(int i = 0; i < n; i++){
    int j = v[i].second;
    for(int k = S[j] + W[j]; k >= W[j]; k--){
      dp[k] = std::max(dp[k], dp[k - W[j]] + V[j]);
    }
  }
  long long int ans = 0;
  for(int i = 0; i <= 20000; i++) ans = std::max(ans, dp[i]);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

bool vis[105];
int main(){
    FASTIO;
    int n,k,d,a,cnt=0;
    cin>>n>>k;
    REP(i,0,k){
      cin>>d;
      REP(i,0,d){
        cin>>a;
        if(!vis[a]){
            cnt++;vis[a]=1;
        }
      }
    }
    cout<<n-cnt<<endl;
    return 0;
}


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

int main()
{
    char a;
    cin >> a;
    int inta = a;
    if (a <= 90)
        cout << 'A' << endl;
    else
        cout << 'a' << endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    int n;
    ll q, k;
    cin >> n >> k >> q;
    vector<int> a(q);
    rep(i, q) {
        cin >> a[i];
        --a[i];
    }
    vector<ll> p(n); 
    rep(i, q) {
        ++p[a[i]];
    }
    rep(i, n) {
        if (k - (q-p[i]) > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

int gcd(int a, int b){ return b?gcd(b, a%b):a; }

bool canWin(vector<int> ov, vector<int> ev, ll s){
	int n=ov.size() + ev.size();
	if(n == 1){
		ov.pb(0); ev.pb(0);
		if(ov[0]+ev[0] == 1) return 0;
		else return 1;
	} else if(n == 2){
		if(ev.empty()) return 0;
		else return 1;
	} else {
		if((n&1) != (s&1)) return 1;
		if(ov.size() != 1) return 0;
		if(ov[0] == 1) return 0;
		--ov[0];
		vector<int> no, ne;
		ll ns=0;
		int ng=0;
		for(int& x:ov) ng=gcd(ng, x);
		for(int& x:ev) ng=gcd(ng, x);
		for(int& x:ov) x/=ng, ns+=x, ((x&1)?no:ne).pb(x);
		for(int& x:ev) x/=ng, ns+=x, ((x&1)?no:ne).pb(x);
		return !canWin(no, ne, ns);
	}
}

int main()
{
    int n;
    scanf("%d",&n);
    vector<int> ov, ev;
    for(int i=1; i<=n; ++i){
		int x; scanf("%d",&x);
		if(x&1) ov.pb(x);
		else ev.pb(x);
    }
    ll s = accumulate(all(ov), 0LL) + accumulate(all(ev), 0LL);
    puts(canWin(ov, ev, s)?"First":"Second");
    return 0;
}


Measured memory_bytes: 19176
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
data = [0] * M
for _ in range(M):
    data[_] = (int(stdin.readline().rstrip()))
 
ans = [1] + [0] * (N)
for i in (set(range(1,N+1)) - set(data)):
    ans[i] = ans[i-1] + ans[i-2]
print(ans[-1] % 1000000007)

Measured memory_bytes: 467292
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, L = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    last = -1
    for i in range(N-1):
        if L <= A[i] + A[i+1]:
            last = i+1
    if last < 0:
        return print("Impossible")
    ans = [i for i in range(1, last)] + \
        [i for i in range(last+1, N)][::-1] + [last]
    print("Possible")
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 59624
using System;
using System.Linq;
    class Program
    {
        static void Main(string[] args)
        {
            var inputNX = Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
            var N = inputNX[0];
            var X = inputNX[1];
            var inputA = Console.ReadLine().Split(' ').Select(x=>int.Parse(x))
                .OrderBy(x=>x).ToList();
            var count = 0;

            foreach(var a in inputA)
            {
                X -= a;
                if (X < 0) break;
                count++;
            }
            if (X > 0) count--;
            Console.WriteLine(count);
        }
    }

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  vector<int> A(100);
  for (int i = 0; i < N; i++) {
    A.at(d.at(i) - 1) = 1;
  }
  int ans = 0;
  for (int i = 0; i < 100; i++) {
    ans += A.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;
  ll m=inf;
  ll c=0;
  for(ll i=0;i<n;i++){
    ll p;
    cin >> p;
    if(p<=m)c++;
    m=min(m,p);
  }

  cout << c << endl;

}

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
const ll INF = 1LL << 60;
const int mod = 1e9+7;
//Write From this Line

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i]; 
	ll odd = 0;
	rep(i,n){
		if(a[i] & 1 ) odd ++ ;
	}
	if(odd%2 == 0){
		puts("YES");
	} else puts("NO");
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;

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

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}

   

int main(){
    lint A,B,count=0;
    cin>>A>>B;
    vector <lint> x;
    vector<lint>y;
    x.push_back(1);
      y.push_back(1);
    rep(i,sqrt(A)){
            if(i==0)continue;
            if(A%i!=0)continue;
           if(primary(i)) x.push_back(i);
            if(primary(A/i)) x.push_back(A/i);
        
    }
     rep(i,sqrt(B)){
            if(i==0)continue;
            if(B%i!=0)continue;
           if(primary(i)) y.push_back(i);
            if(primary(B/i)) y.push_back(B/i);    
    }
    rep(i,x.size()){
        
        rep(j,y.size()){
          if(x[i]==y[j])count++;
        }
    }
    cout<<count;
     
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

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

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

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

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////


void solve() {
	int N;
	cin >> N;
	cout << N / 3 << endl;
}

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

	solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

int isvisited[100010];
vector<int> enum_div(int n)//nの約数を列挙
{
	vector<int> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}
int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int cnt[100010] = {};
    REP(i, 1, K) {
        cnt[i] = power(K/i, N);
    }
    RREP(i, K, 1) {
        vector<int> v = enum_div(i);
        for(auto& e: v) {
            if (i == e) continue;
            cnt[e] = (cnt[e] - cnt[i] + mod) % mod;
        }
    }
    int ans = 0;
    REP(i, 1, K) ans = (ans + Mul(i, cnt[i])) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4404
import java.util.Scanner;

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

    public static void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println((a +b) % 24);
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
    int H,W;
    cin >> H >> W;
    char a[W];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> a[j];
            cout << a[j];
        }
        cout << "\n";
        for(int j=0;j<W;j++){
            cout << a[j];
        }
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[100100],lb[100100],ub[100100],rs;
void end(){
	cout<<"-1"<<endl;
	exit(0);
}
int main(){
	#ifndef DavidLaptop
		#ifdef FILIN
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=0;i<=n;i++) cin>>a[i];
	if(a[n]==0LL) end();
	lb[n]=ub[n]=a[n];
	for(int i=n-1;i>=0;i--){
		lb[i]=(lb[i+1]+1LL)/2LL;
		ub[i]=ub[i+1];
		lb[i]+=a[i];
		ub[i]+=a[i];
	}
	if(lb[0]>1LL) end();
	ub[0]=1;
	for(int i=1;i<=n;i++){
		lb[i]=max(lb[i],lb[i-1]-a[i-1]);
		ub[i]=min(ub[i],2LL*(ub[i-1]-a[i-1]));
		if(lb[i]>ub[i]) end();
	}
	if(lb[n]>a[n]) end();
	ub[n]=a[n];
	for(int i=0;i<=n;i++) rs+=ub[i];
	cout<<rs<<endl;
	return 0;
}



Measured memory_bytes: 5960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int kN = 2e5 + 10;

int n, a[kN];
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	ll ans = 0;
	int mx = a[1];
	for(int i = 2; i <= n; i++) {
		if(a[i] < mx) ans += mx - a[i];
		else mx = a[i];
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main(){
	string S;
	bool D[26]={};
	char a = 'a';
	bool flag;
	cin >> S;
	for(int i=0;i<S.length();i++){
		 if(D[(S[i]-a)]==1){
			 cout << "no" << endl;
			 return 0;
		 }
		 else	D[S[i]-a]=1;
	}
	cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 256
N,A,B,C = map(int,input().split())
L = [int(input()) for _ in range(N)]
INF = 10 ** 9
def dfs(depth,a,b,c):
  if depth == N:
    return abs(a - A) + abs(b - B) + abs(c - C) if min(a,b,c) > 0 else INF
  ret0 = dfs(depth+1,a,b,c)
  # 最初の一本目は合体コストがないことに注意する
  ret1 = dfs(depth+1,a+L[depth],b,c) + 10 if a else dfs(depth+1,a+L[depth],b,c)
  ret2 = dfs(depth+1,a,b+L[depth],c) + 10 if b else dfs(depth+1,a,b+L[depth],c)
  ret3 = dfs(depth+1,a,b,c+L[depth]) + 10 if c else dfs(depth+1,a,b,c+L[depth])
  return min(ret0,ret1,ret2,ret3)
print(dfs(0,0,0,0))

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

const int MAX = 500000, MS = 2;
const ll mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<ll> hs[MS], pw[MS];
    rolling_hash(){};
    rolling_hash(const string &s) {
        n = s.size();
        for(int i = 0; i < MS; i++) {
            hs[i].assign(n + 1, 0);
            pw[i].assign(n + 1, 0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for(int j = 0; j < n; j++) {
                pw[i][j + 1] = pw[i][j] * base % mod[i];
                hs[i][j + 1] = (hs[i][j] * base + s[j]) % mod[i];
            }
        }
    }

    ll get_hash(int l, int r, int i) {
        return ((hs[i][r] - hs[i][l] * pw[i][r - l]) % mod[i] + mod[i]) %
               mod[i];
    }

    /* get hash [l,r) */
    pair<ll, ll> get(int l, int r) {
        return make_pair(get_hash(l, r, 0), get_hash(l, r, 1));
    }
};

int main() {
    int N;
    string S;
    cin >> N >> S;
    rolling_hash Hash(S);
    int lb = 0, ub = N;
    while(ub - lb > 1) {
        int mid = (lb + ub) / 2;
        int ok = 0;
        for(int i = 0; i + mid - 1 < N; i++) {
            for(int j = i + mid; j + mid - 1 < N; j++) {
                if(Hash.get(i, i + mid) == Hash.get(j, j + mid)) {
                    ok = 1;
                    break;
                }
            }
            if(ok)
                break;
        }
        if(ok) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    cout << lb << endl;
    return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("O3")

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

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
const int mxN=2e5+5;
const int mxA=1e6+5;
int arr[mxN];
bool sieve[mxA];
int n;
map<int,int> ma;

void calcSieve() {
    F0R(i,mxA)
        sieve[i]=true;
    for(auto p : ma) {
        int cur=p.first;
        if(sieve[cur]==false)
            continue;
        for(int j=2*cur; j<mxA; j+=cur)
            sieve[j]=false;
    }
}

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    F0R(i,n) {
        cin >> arr[i];
        ma[arr[i]]++;
    }
    int cnt=0;
    calcSieve();
    F0R(i,n) {
        if(ma[arr[i]]==1 && sieve[arr[i]])
            cnt++;
    }
    cout << cnt;

    return 0;
}


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

int N, K;
vector<int> D(9);

bool check(int x){
  while(x != 0){
    for(int i = 0; i < K; i++){
      if(x % 10 == D.at(i)){
        return false;
      }
    }
    x /= 10;
  }
  return true;
}


int main(){
  cin >> N >> K;
  for(int i = 0; i < K; i++){
    cin >> D.at(i);
  }
  
  int ans = N;
  
  while(! check(ans)){
    ans++;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

dist_sum = 0
for n, (x_i, y_i) in enumerate(XY[:-1]):
    for (x_j, y_j) in XY[n+1:]:
        dist_sum += ((x_i - x_j)**2 + (y_i - y_j)**2) ** 0.5
print(dist_sum * 2 / N)


Measured memory_bytes: 3060
#include <stdlib.h> 
#include <stdio.h>
#include <iostream>


using namespace std; 

int main()
{
    int x1,x2,x3,x4,x5;
    int arr[5];

    cin>>x1;
    cin>>x2;
    cin>>x3;
    cin>>x4;
    cin>>x5;

    arr[0] = x1;
    arr[1] = x2;
    arr[2] = x3;
    arr[3] = x4;
    arr[4] = x5;  

    for ( int i = 0; i < 5 ; i++)
    {
        if(arr[i] == 0) cout<<i+1;
    }


}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;
#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif


namespace Solver{
using namespace std;

struct Problem{
    int n;
    vector<vector<int>> a;
    Problem(LL n):n(n),a (2,vector<int>(n)){};

    void solve(){
        for(int i=0; i<2; ++i){
            for(int j=0; j<n; ++j){
                cin >> a[i][j];
            }
        }
        int ans = 0;
        for(int i=0; i<n; ++i){
            int  tmp =0;
            for(int j=0; j<=i; ++j){
                tmp+=a[0][j];
            }
            for(int j=i; j<n; ++j){
                tmp+=a[1][j];
            }
            ans=max(ans,tmp);
        }
        cout << ans <<"\n";
    }
};
}

int main(){
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    long long n=0;
    std::cin >> n;
    Solver::Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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() {
  int A, B;
  cin >> A >> B;
  cout << A * B - A - B + 1 << endl;
}

Measured memory_bytes: 256