akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,w; cin>>n>>w;
  vvll vs(4);
  ll base=-1;
  rep(i,n){
    ll w,v; cin>>w>>v;
    ll d;
    if(base==-1) d=0, base=w;
    else d=w-base;
    
    vs[d].push_back(v);
  }
  vvll s(4);
  rep(i,4){
    sort(vs[i].rbegin(),vs[i].rend());
    ll len=vs[i].size();
    s[i].resize(len+1);
    rep(j,len) s[i][j+1]=s[i][j]+vs[i][j];
  }
  
  ll ans=0;
  rep(i,s[0].size()){
    rep(j,s[1].size()){
      rep(k,s[2].size()){
        rep(l,s[3].size()){
          ll sumv=s[0][i]+s[1][j]+s[2][k]+s[3][l];
          ll sumw=base*i+(base+1)*j+(base+2)*k+(base+3)*l;
          if(sumw>w) continue;
          chmax(ans,sumv);
        }
      }
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    int N;
    cin >> N;
    Vi P(N), Q(N);
    for (int i = 0; i < N; i++) {
        cin >> P[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> Q[i];
    }

    Vi ref(N);
    for (int i = 0; i < N; i++) {
        ref[i] = i + 1;
    }

    int a, b;
    int cnt = 1;
    do {
        bool ok = true;
        for (int i = 0; i < N; i++) {
            if (P[i] != ref[i]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            a = cnt;
        }

        ok = true;
        for (int i = 0; i < N; i++) {
            if (Q[i] != ref[i]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            b = cnt;
        }

        ++cnt;
    } while (next_permutation(ref.begin(), ref.end()));

    cout << abs(a - b) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int ans = 0;
  int a = N % 10;
  if (a == 7) {
    ans++;
  }
  
  int b = (N / 10) % 10;
  if (b == 7) {
    ans++;
  }
  
  int c = N / 100;
  if (c == 7) {
    ans++;
  }
  
  if (ans == 0) {
    cout << "No" << endl;
  }
  
  if (ans != 0) {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3588
R, G, B, N = map(int, input().split())
ans = 0
r=0
while r*R <= N:
    g=0
    while r*R + g*G <= N:
        if (N - r*R - g*G) % B == 0:
            ans += 1
        g += 1
    r += 1
print(ans)


Measured memory_bytes: 40556
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
map<int,ll> data;
int main(){
	int n;
	while(cin>>n,n){
		data.clear();
		std::vector<int> a;
		a.clear();
		rep(i, n){
			ll e,c,s;
			cin>>e>>c>>s;
			if(!data[e]){
				a.push_back(e);
				
			}
			data[e]+=(c*s);
		}
		bool flag =false;
		for(int i =0;i < a.size();i++){
			if(data[a[i]]>= 1000000){
				cout <<a[i]<<endl;
				flag =true;
			}
		}
		if(!flag){
			cout<<"NA"<<endl;
		}
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)			// repeat reverse
#define size(collection) ((ll) (collection).size())						// collection size

#endif

struct Edge
{
	ll vertex;	// 頂点
	Edge(ll v)
	{
		vertex = v;
	}
};

using Graph = vector<vector<Edge>>;

/**
@brief 深さ優先探索
@param v 頂点
@param r 根
@param g 処理するグラフ
@param memo 前処理したメモ(加算するべきカウンタの値)
@param ans 出力する答えを格納する配列
@note
 DFSで全てのノードを処理する。
**/
void DFS(ll v, ll r, Graph& g, vector<ll>& memo, vector<ll>& ans)
{
	if (r != -1)
		ans[v] = ans[r] + memo[v];

	for (const auto& e : g[v])
	{	// 後戻りしないようにする
		if (e.vertex == r)
			continue;

		DFS(e.vertex, v, g, memo, ans);
	}
}

int main(void)
{
	ll n, q; cin >> n >> q;

	ll u, v;
	Graph g;
	g.resize(n);
	rep(ei, 0, n - 1)
	{
		cin >> u >> v;
		--u; --v;
		g[u].push_back(Edge(v));
		g[v].push_back(Edge(u));
	}

	vector<ll> p(q), x(q);
	rep(i, 0, q)
	{
		cin >> p[i] >> x[i];
		p[i]--;
	}

	// 頂点xで加算するべきカウンタの値をメモしておく。
	vector<ll> memo(n);
	rep(i, 0, q)
		memo[p[i]] += x[i];

	vector<ll> ans(n);
	ans[0] = memo[0];
	DFS(0, -1, g, memo, ans);

	for(auto& e: ans)
		cout << e << " ";

	return 0;
}


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

int main(){
	string s;
	cin >> s;
	int zero=0, one=0;
	for(int i = 0; s[i] != '\0'; i++){
		if(s[i] == '0'){
			zero++;
		}else{
			one++;
		}
	}
	//cout << zero << ":" << one << endl;
	if(zero > one){
		cout << one * 2 << endl;
	}else{
		cout << zero * 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 512
import java.util.*;

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

      int n = sc.nextInt();

      long sum = 0;

      for(int i = 1; i < n+1; i++){
         if (i%3!=0) {
            if(i%5!=0){
               sum = sum + i;
            }
         }
      }
      System.out.println(sum);

   }

}

Measured memory_bytes: 35828
//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=a,lim=b;i<=lim;i++)
#define Rep(i,a,b)	for(int i=a,lim=b;i>=lim;i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define n	1000005

int		N, pre[n], Q[n];

char	A[n], B[n];

int		main(int argc, char* argv[]){
	
		N= IN();
		scanf("%s%s", A+1, B+1);
		
		int flag= 0;
		For(i, 1, N)	if	(A[i] != B[i])	flag= 1;
		if	(! flag)	return	puts("0"), 0;
		
		for (int i= N, j= N; i; i--)	{
			j= min(j, i);
			for (; j && A[j] != B[i]; j--);
			if	(! j)	return	puts("-1"), 0;
			pre[i]= j;
		}
		
		int	Ans= 1, l= 1, r= 0;
		Rep(i, N, 1)	if	(pre[i] > pre[i-1])	{
			for (; l <= r && Q[l] - (r-l) > i; l++);
			if	(pre[i] < i)	Q[++ r]= pre[i], Ans= max(Ans, r-l+2);
		}
		printf("%d\n", Ans);
		
		return	0;
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

// UnionFind
struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n,-1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<vi> ab(n), cd(n);
    UnionFind uf(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        uf.unite(a, b);
        ab[a].pb(b);
        ab[b].pb(a);
    }
    rep(i, k) {
        int c, d;
        cin >> c >> d;
        --c; --d;
        cd[c].pb(d);
        cd[d].pb(c);
    }
    vi ans(n);
    rep(i, n) {
        int cnt = uf.size(i) - sz(ab[i]) - 1;
        rep(j, sz(cd[i])) {
            if (uf.same(i, cd[i][j])) --cnt;
        }
        ans[i] = cnt;
    }
    rep(i, n) printf("%d%c", ans[i], (i<n-1?' ':'\n'));
    return 0;
}


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

using namespace std;

int main()
{
	long long n, a, b;
	cin >>n >>a >>b;

	if(n == 1){
		if(a == b){
			cout <<"1\n";
		}
		else{
			cout<<"0\n";
		}
	}
	else{
		if(a > b){
			cout <<"0\n";
		}
		else{
			long long ans = (n - 2) * (b - a) + 1;
			cout <<ans <<'\n';
		}
	}

	return 0;
}


Measured memory_bytes: 3656
import sys, re
input = sys.stdin.readline
a = int(input())  # 500円の枚数
b = int(input())  # 100円の枚数
c = int(input())  # 50円の枚数
x = int(input())  # 目指したい合計金額

count = 0
for a_i in range(a+1):
  for b_i in range(b+1):
    for c_i in range(c+1):
      if x == a_i * 500 + b_i * 100 + c_i * 50:
        count += 1

print(count)


Measured memory_bytes: 3188
#include <map>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;i++)

//abbreviations
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vb vector<bool>
#define vvi vector<vector<int>>

using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    int N;
    cin >> N;
    vi P(N);
    int i;
    rep(i,N)cin>>P[i];

    int now = 3*pow(10,5);
    int cnt = 0;

    rep(i,N){
        if(P[i]<=now){
            cnt++;
            now = P[i];
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define MOD 1000000007
#define ar array
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector<int> prefix_sum;

int range_sum(int l, int r) {
	int res = prefix_sum[r];
	if (l > 0) res -= prefix_sum[l - 1];
	return res;
}

int32_t main() {
	fast_io;

	// int t; cin >> t;
	// while (t--) {

	// }
	int n; cin >> n;
	vector<int> a(n); int sum = 0;
	prefix_sum.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	prefix_sum[0] = a[0];
	for (int i = 1; i < n; i++) {
		prefix_sum[i] = prefix_sum[i - 1] + a[i];
	}
	vector<vector<int>> min_cost(n, vector<int> (n, LLONG_MAX));
	for (int i = 0; i < n; i++) {
		min_cost[i][i] = 0;
	}
	for (int len = 2; len <= n; len++) {
		for (int i = 0; i + len - 1 < n; i++) {
			int j = i + len - 1;
			for (int k = i; k <= j - 1; k++) {
				min_cost[i][j] = min(min_cost[i][j], range_sum(i, j) + min_cost[i][k] + min_cost[k + 1][j]);
			}
		}
	}
	cout << min_cost[0][n - 1] << endl;

	return 0;
}

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

int main() {

    int F[44];

    int n;

    cin >> n;

    F[0] = 1;
    F[1] = 1;
    for(int i = 2; i <= n; i++) {
        F[i] = F[i-1] + F[i-2];
        //cout << "n = " << i << " " << F[i] << endl;
    }

    cout << F[n] << endl;

    return 0;
}
 

Measured memory_bytes: 3096
// Etavioxy
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
#define il inline
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch; int f=1;
	while(!isdigit(ch=getchar())) f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar())) x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=200023};

int a[N];

int main(){
	int x=ci(), n=ci();
	int ans = 0;
	int a1=ci();
	rep(i,2,n) a[i] = ci()-a1;
	a[n+1] = x;
	rep(i,1,n) ans=max(ans,a[i+1]-a[i]);
	printf("%d\n",x-ans);
	return 0;
}


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

#define MAX 5100000
#define MOD 1000000007

long long modpow(long long a,long long n,long long mod){
  long long res=1;
  while(n>0){
    if(n&1){       //nのbitと...00001を比較  nが2で割り切れるならtrue
      res=(res*a)%mod;
    }
    a=(a*a)%mod;
    n>>=1;
  }
  return res;
}

long long modinv(long long a,long long mod){
  return modpow(a,mod-2,mod);
}

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

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

long long COM(int n,int k){
  if(n<k){
    return 0;
  }
  if(n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  int N,M;
  cin>>N>>M;
  COMinit();
  long long ans;
  if(N-M==0){
    cout<<((2*fac[N])%MOD)*fac[M]%MOD<<endl;
  }else if(N-M==1||N-M==-1){
    cout<<fac[N]*fac[M]%MOD<<endl;
  }else{
    cout<<0<<endl;
  }
}


Measured memory_bytes: 120316
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

n =int(input())
t = n
sn=0
while t > 0:
    sn += t % 10
    t = t // 10
if n % sn == 0:
    print("Yes")
else:
    print("No") 


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

int main() {
 long int X;
 cin >>X;
  int flag=0;
  long int i=X;
  int unique=0;//素数なら
  int nouni=1;
  i--;
  while(nouni==1){nouni=0;i++;
  	for(int j=2;j<=sqrt(i);j++){
  	  if(i%j==0){nouni=1;}    
  	}
   
  }
   cout <<i<<endl;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)

int main(){

	lli n,m;
	cin>>n>>m;

	vector<lli> a(m),b(m);

	REP(i,0,m){
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
	}
	lli cnt=0;

	for(lli i=0;i<m;i++){
		map<lli,vector<lli>> d;
		if(DEBUG)cout<<"i="<<i<<endl;

		REP(j,0,m){
			if(i==j)continue;
			d[a[j]].push_back(b[j]);
			d[b[j]].push_back(a[j]);
		}

		lli flag[60];
		REP(j,0,60)flag[j]=0;

		queue<lli> q;
		q.push(0);
		flag[0]=1;
		while(q.size()){
			lli top = q.front();
			q.pop();
			for(auto e:d[top]){
				if(flag[e])continue;
				flag[e]++;
				q.push(e);
			}
		}

		bool fl=true;

		REP(j,0,n){
			if(flag[j]==0){
				fl=false;
				break;
			}
		}
		if(!fl)cnt++;

	}
	cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 256
"C - Inserting'x' "

S = str(input())

left_pointa = 0
right_pointa = len(S)-1

flag = True
cnt = 0
while flag:
    if S[left_pointa] == S[right_pointa]:  # 同じ文字なら次に進めばいい
        left_pointa += 1
        right_pointa -= 1
        if left_pointa > right_pointa:  # leftが抜かしたら
            break
            # if S[left_pointa] == S[right_pointa]:
            #     flag = True
            #     break
            # else:
            #     flag = False
            #     break

    if S[left_pointa] != S[right_pointa]:  # 違う文字のときに分岐を考える
        if S[left_pointa] == 'x':
            cnt += 1  # 今right_pointaが見ている文字の右にxを挿入する
            left_pointa += 1  # 右側を停止させておいて左側を進めて行く
        elif S[right_pointa] == 'x':
            cnt += 1  # 今left_pointaが見ている文字の左にxを挿入する
            right_pointa -= 1  # 左側を停止させておいて右側を進めて行く
        else:  # どちらも違う文字を見ていたら回文にはならない
            flag = False
            break

if flag:
    print(cnt)
else:
    print(-1)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a < b && a != 1)
    cout << "Bob" << endl;
  else if(a > b && b != 1)
    cout << "Alice" << endl;
  else if(a== 1 && b != 1)
    cout << "Alice" << endl;
  else if(b== 1 && a != 1)
    cout << "Bob" << endl;
  else
    cout << "Draw" << endl;
}


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

ans = 0
for i in range(N):
	pick = 0
	for j in range(N):
		if j <= i:
			pick += A[0][j]
		if j >= i:
			pick += A[1][j]
	ans = max(pick, ans)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
ll a[2001],dp[2001][2001],n;
 
ll dfs(int l, int r, int t) {
  if(dp[l][r]) return dp[l][r];
  if(l==r) return t?0:a[l];
  if(t) dp[l][r]=(a[l]>a[r]?dfs((l+1)%n,r,0):dfs(l,(r+n-1)%n,0));
  else dp[l][r]=max(dfs((l+1)%n,r,1)+a[l],dfs(l,(r+n-1)%n,1)+a[r]);
  return dp[l][r];
}
 
int main() {
  cin >> n;
  for(int i=0; i<n; i++) cin >> a[i];
  ll ans=0;
  for(int i=0; i<n; i++) ans=max(ans,a[i]+dfs((i+1)%n,(i+n-1)%n,1));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 32564
#include <stdio.h>
int main(void)
{
	int h,n,x,i,j,k,m=0;
	
	for(h=1;h>0;h++)
	{
	
		scanf("%d %d",&n,&x);

	for(i=1;i<=n-2;i++)
		{

			for(j=i+1;j<=n-1;j++)
			{
			
				for(k=j+1;k<=n;k++)
				{
					if(i+j+k==x)
					{
						m++;
					}
				}
			
			}
			
	    }

	if(n==0&&x==0)
	{
		h = h*(-1);
	}
	else
	{
		printf("%d\n",m);
		
		m = 0;
	}
	
  }


	return 0;
}

Measured memory_bytes: 600
#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 ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	string s;
	int K;
	cin >> s >> K;
	
	vector<string> v;
	FOR(i, 1, min<int>(s.size(), 5) + 1) {
		REP(j, s.size() - i + 1) v.push_back(s.substr(j, i));
	}
	sort(ALL(v));
	v.erase(unique(ALL(v)), v.end());
	
	cout << v[K - 1] << endl;
	
	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <string>

int main() {
    std::string s;
    std::cin >> s;
    bool flag = true;

    for(int i = 1; i < 4; i++) {
        if(s[i] == s[i - 1]) {
            flag = false;
        }
    }

    if(flag) {
        std::cout << "Good" << std::endl;
    } else {
        std::cout << "Bad" << std::endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int T1, T2, A1, A2, B1, B2;
	cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

	A1 *= T1;
	A2 *= T2;
	B1 *= T1;
	B2 *= T2;
	A2 += A1;
	B2 += B1;
	if (A2 == B2) {
		cout << "infinity" << endl;
		return 0;
	}
	if (A2 < B2) {
		swap(A1, B1);
		swap(A2, B2);
	}
	int D = A2 - B2;
	int C = B1 - A1;

	int ans = 0;
	if (C > 0) {
		ans = (C - 1) / D + 1;
		ans *= 2;
		ans--;
		if (C%D == 0)ans++;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
#define vsort(v) sort(v.begin(), v.end());
#define vunique(v) unique(v.begin(), v.end());

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

	string c[3];
	for(int i = 0; i < 3; i++) {
		cin >> c[i];
	}
	cout << c[0][0] << c[1][1] << c[2][2] << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

using ll = long long;

const ll mod = 1000000000 + 7;

int main()
{
    ll n, m;
    vector<ll> x;
    vector<ll> y;

    cin >> n >> m;

    x.resize(n);
    y.resize(m);

    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    for (int i = 0; i < m; i++)
    {
        cin >> y[i];
    }

    ll a = 0;
    ll b = 0;
    for (int i = 0; i < m; i++)
    {
        a += i * y[i] - (m - 1 - i) * y[i];
    }
    for (int i = 0; i < n;i++)
    {
        b += i * x[i] - (n - 1 - i) * x[i];
    }

    cout << ((a % mod) * (b % mod)) % mod  << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
char a[10010],b[10010];
int main(){
    cin>>a;
    cin>>b;
    int la=strlen(a),lb=strlen(b);
    int len=min(la,lb),len2=max(la,lb);
    for(int i=0;i<=len-1;i++){
    	cout<<a[i]<<b[i];
	}
    if(la>lb){
    	for(int i=len;i<=len2-1;i++){
    		cout<<a[i];
		}
	}
    else{
    	for(int i=len;i<=len2-1;i++){
    		cout<<b[i];
		}
	}
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
#a_L = [0] * float(10**10)
#a_L[0] = 1
#a_L[1] = 1
MOD = 10 ** 9 + 7
dp = [0] * (n+1)
a_L = []

for val in range(m):
    a_L.append(int(input()))


a_L = set(a_L)
dp[0] = 1
if 1 in a_L:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2,n+1):
    if i not in a_L:
        dp[i] = (dp[i-1] + dp[i-2])%MOD
    else:
        dp[i] = 0

print(dp[n]%MOD)
#print(dp)

Measured memory_bytes: 56664
#include <iostream>
#include <vector>

using namespace std;

class Dice
{
  public:
    vector<int> diceNum;
    Dice(vector<int>& inputs);
    void toW();
    void toS();
    void ParallelRotation();
};

Dice::Dice(vector<int>& inputs)
{
  diceNum=inputs;
}

void Dice::toW()
{
  swap(diceNum[0],diceNum[3]);
  swap(diceNum[0],diceNum[5]);
  swap(diceNum[0],diceNum[2]);
}

void Dice::toS()
{
  swap(diceNum[0],diceNum[1]);
  swap(diceNum[0],diceNum[5]);
  swap(diceNum[0],diceNum[4]);
}

void Dice::ParallelRotation()
{
  swap(diceNum[1],diceNum[2]);
  swap(diceNum[2],diceNum[4]);
  swap(diceNum[4],diceNum[3]);
}

bool Judge(Dice& dice1,Dice& dice2)
{
  int count=0;
  for(int i=0;i<6;i++)
  {
    if(dice1.diceNum[i]==dice2.diceNum[i]) count++;
  }
  if(count==6)return true;
  else return false;
    
}

bool preJudge(Dice& dice1,Dice& dice2)
{
  int count=0;
  bool flag=false;
  while(1)
  {
    dice2.toS();
    for(int j=0;j<4;j++)
    {
      dice2.ParallelRotation();
      flag=Judge(dice1,dice2);
      if(flag==true) break;
    }
    if(flag==true) break;
    dice2.toW();
    for(int j=0;j<4;j++)
    {
      dice2.ParallelRotation();
      flag=Judge(dice1,dice2);
      if(flag==true) break;
    }
    count++;
    if(flag==true) break;
    if(count==3)break;
  } 
  return flag;
}

int main(int argc,char* argv[])
{
  vector<int> inputs(6);
  int number;
  int count =0;
  cin >> number;
  bool flag=false;
  
  vector<Dice> Dices;
  for(int i=0;i<number;i++)
  {
    for(int j=0;j<6;j++)
    {
      cin >> inputs[j];
    }
    Dices.push_back(Dice(inputs));
  }
  for(int i=0;i<number-1;i++)
  {
    for(int j=i+1;j<number;j++)
    {
      flag = preJudge(Dices[i],Dices[j]);
      if(flag==true) break;
    }
    if(flag==true) break;
  }
  if(flag==true) cout << "No" << endl;
  else if(flag==false) cout << "Yes" << endl;
}


Measured memory_bytes: 3152
program main
  
  implicit none
  integer :: intr 
  real    :: realr

  read( *,* ) intr
  realr = real( intr )

  if ( intr < 0 .or. intr > 100 ) then 
    print *, "Goodby"
    stop
  end if
  
  print *, int( realr**2e0 ) 
  
end program main



Measured memory_bytes: 256
N = int(input())
now = [0, 0]

for i in range(N):
    t, x, y = map(int, input().split())
    dist = abs(x - now[0]) + abs(y - now[1])
    if t < dist or (t % 2 != dist %2):
        print('No')
        quit()
 
print('Yes')

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


int main() {
  ll n, ans;
  cin >> n;
  ans = n * (n-1) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	long long N;
	int i,j,b;
	cin>>N;
	b=0;
	for (i=1;i<=3500;i++)
	{
	  for (j=1;j<=3500;j++)
	  {
	  	if (4*i*j-N*i-N*j>0 && (i*j*N)%(4*i*j-N*i-N*j)==0)
	  	{
	  		cout<<i<<' '<<j<<' ';
	  		cout<<(i*j*N)/(4*i*j-N*i-N*j)<<endl;
	  		b=1;
	  		break;
		}
	  }
	  if (b) break;
    }
    return 0;
 } 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String[] tmp = sc.nextLine().split(" ");
		int n = Integer.parseInt(tmp[0]);
		double x = Integer.parseInt(tmp[1]);
		int t = Integer.parseInt(tmp[2]);

		n = (int)(Math.ceil(n / x)) * t;
		System.out.println(n);

	}

}


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

int main()
{
    int n;
    cin>>n;
    int s[n+2]= {0};
    for(int x=1; x<100; x++)
    {
        for(int y=1; y<100; y++)
        {
            for(int z=1; z<100; z++)
            {
                int xyz=(x+y)*(x+y)+(z+y)*(z+y)+(x+z)*(x+z);
                if(xyz<=2*n)
                {
                    s[xyz/2]++;
                }
            }
        }
    }
    for(int i=1; i<=n; i++)
    {
        cout<<s[i]<<endl;
    }
}

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

    long long int n;
    cin>>n;
    long long int sum1=0,sum2=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0 || i%5==0)
            sum1 += i;
        sum2 +=i;
    }
    cout<<sum2-sum1<<endl;

    return 0;
}


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

using namespace std;   
 
int pt(int n, int m)
{  
    int i; 
    for (i = m-1; i < (m-1)*n; i = (m*i) / (m-1)+1) {}
    return (m * n - i); 
}   
 
int main()
{     
    int n, m;
    while (cin >> n >> m, (n | m)) {
	cout << pt(n, m) << endl;    
    }
    return 0;
}

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

using namespace std;
#define rep(i, n) for (int64_t i = 0; i < n; i++)

vector<vector<int>> memo;

int gcd(int a, int b)
{
        if (a % b == 0)
        {
                memo[a][b] = b;
                return memo[a][b];
        }
        else
        {
        	if (memo[a][b] == -1)
        	{
                        memo[a][b] = gcd(b, a % b);
        	}
                
                return memo[a][b];
        }
}


int main()
{
        int n;
        int a, b, c;
        cin >> n;
        int temp = 0,counter = 0;;
        memo = vector<vector<int>>(n + 1, vector<int>(n + 1, -1));
        for (int i = 1; i <= n; i++)
        {
                for (int j = 1; j <= n; j++)
                {
                        for (int h = 1; h <= n; h++)
                        {
                                temp = gcd(i, j);
                                counter += gcd(temp, h);
                        }
                }
        }
        cout << counter << endl;
        return 0;
}

Measured memory_bytes: 3740
n=int(input())
A=[int(i) for i in input().split()]
B=[0]*60
C=[0]*60
ans=0
mod=10**9+7
for i,a in enumerate(A):
  for j in range(60):
    if a%2==0:
      C[j]+=B[j]
    else:
      C[j]+=i-B[j]
      B[j]+=1
    a//=2
for i in range(60):
  ans=(ans+C[i]*(pow(2,i,mod)))%mod
print(ans)


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D) cout << "Left" << endl;
  else if (A + B == C + D) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {int N,i,j,Map[105][105];while (1) {scanf("%d",&N);if (!N) return 0;for (i=0;i<=N;i++) Map[i][N]=Map[N][i]=0;
    for (i=0;i<N;Map[N][N]+=Map[i++][N]) for (j=0;j<N;j++) {scanf("%d",&Map[i][j]);Map[i][N]+=Map[i][j];Map[N][j]+=Map[i][j];}for (i=0;i<=N;i++,puts("")) for (j=0;j<=N;j++) printf("%5d",Map[i][j]);}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<char> a(3),b(3);
  for(int i=0;i<3;i++){
    cin>>a[i];
  }
  for(int i=0;i<3;i++){
    cin>>b[i];
  }
  reverse(a.begin(),a.end());
  if(a[0]==b[0]&&a[1]==b[1]&&a[2]==b[2]){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

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

    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (i * j + (n - i) * (m - j) == k) {
                cout << "Yes\n";
                return 0;
            }
        }
    }

    cout << "No\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';
int mod = 1e9 + 7;
ll inf = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r, d, X;
    cin >> r >> d >> X;
    int x = X;
    for (int i = 1; i <= 10;i++){
        cout << r * x - d << endl;
        x = r * x - d;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
struct edge{
	int d,nex;
}e[200010];
int n,efree,q[100010],d[100010],siz[100010],a,b,f[100010];
template<class T>
inline void read(T&a){
	char c=getchar();
	for(a=0;c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-'0';
}
inline void add(int x,int y){e[++efree]=(edge){y,q[x]};q[x]=efree;}
void dfs(int x,int y){
	d[x]=d[y]+1;f[x]=y;
	for(int i=q[x];i;i=e[i].nex)
		if(e[i].d!=y)dfs(e[i].d,x),siz[x]+=siz[e[i].d];
	siz[x]++;
}
int main(){
	read(n);
	for(int i=1;i<n;i++){
		int x,y;read(x),read(y);
		add(x,y),add(y,x);
	}
	dfs(1,0);
	if((d[n]-2)&1){
		a=(d[n]-2)/2+1,b=(d[n]-2)/2;
		int x=n,y=0;
		while(y<b)x=f[x],y++;
		a=siz[1]-siz[x],b=siz[x];
	}
	else{
		a=b=(d[n]-2)/2;
		int x=n,y=0;
		while(y<b)x=f[x],y++;
		a=siz[1]-siz[x],b=siz[x];
	}
	puts(a>b?"Fennec":"Snuke");return 0;
}

Measured memory_bytes: 7936
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;
const long long mod = 1e9 + 7;

int main(){
     int n;
     cin >> n;
     int a[n];
     int max = 0;
     int max2 = 0;
     int max_num;
     for(int i = 0; i<n; i++){
          cin >> a[i];
     }
     for(int i = 0; i<n; i++){
          if(a[i]>=max){
               max2 = max;
               max = a[i];
               max_num = i;
          }else if(a[i] <= max && a[i]>= max2)max2 = a[i];
     }
     
     if(n==2){
         cout << a[1] << endl << a[0] << endl;
     }
     if(n!=2){
        for(int i = 0; i< n; i++){
          if(i==max_num)cout << max2 <<endl;
          else cout << max << endl;
     }
     
         
     }
     return 0;
}

Measured memory_bytes: 2432
N = int(input())
a = list(map(int,input().split()))

b1 = 0
b2 = 0
b4 = 0
for ai in a:
	if ai % 2 == 0:
		if ai % 4 == 0:
			b4 += 1
		else:
			b2 += 1
	else:
		b1 += 1

ok = False
if b2 == 0:
	if  b1 <= b4 + 1:
		ok = True
else:
	if b1 <= b4:
		ok = True

print("Yes" if ok == True else "No")

Measured memory_bytes: 14252
import sys
from math import log, floor

n = int(sys.stdin.readline().rstrip())

def main():
    cand = set()
    for i in range(floor(log(n, 6)) + 1):
        if 6 ** i <= n:
            cand.add(6 ** i)
        if 9 ** i <= n:
            cand.add(9 ** i)
    cand = sorted(cand)

    res = set([0])
    cnt = 0
    while True:
        nex = set()
        for val in res:
            for c in cand:
                if val + c <= n:
                    nex.add(val + c)
                else:
                    break
        cnt += 1
        if n in nex:
            return cnt
        res = nex
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 20244
#include <bits/stdc++.h>
int main() {
	int n;
	long long answer = 0;
	std::cin >> n;
	std::vector<int> a(n);
	for (int i = 0; i < n; i++) { std::cin >> a[i]; }
	std::sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		answer += a[n - 1 - i / 2];
	}
	answer -= a.back();
	std::cout << answer << '\n';
	return 0;
}

Measured memory_bytes: 4008
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 1e9 + 7;

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

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

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}

int main() {
	ll n, k;
	cin >> n >> k;
		
	ll ans=0;

	vector<ll> v(n);

	rep(i, k) {
		ll d;
		cin >> d;
		rep(j, d) {
			ll a;
			cin >> a;
			a--;
			v[a]++;
		}
	}

	rep(i, n) {
		if (v[i] == 0) {
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
//orz jzm
#define ll long long
#define ull unsigned ll
const ll PR=19260817;
int main() {
	string s;
	cin>>s;
	reverse(s.begin(), s.end());
	int i=0, l=s.length();
	while (i<l) {
		if (s[i]=='m') {
			if (s.substr(i, 5)!="maerd") {
				cout<<"NO"<<endl;
				return 0;
			}
			i+=5;
		}
		else if (s[i]=='e') {
			if (s.substr(i, 5)!="esare") {
				cout<<"NO"<<endl;
				return 0;
			}
			i+=5;
		} else if (s[i]=='r') {
			if (i+2>=l||s[i+1]!='e') {
				cout<<"NO"<<endl;
				return 0;
			}i+=2;
			if (s[i]=='m') {
				if (s.substr(i, 5)!="maerd") {
					cout<<"NO"<<endl;
					return 0;
				}i+=5;
			} else if (s[i]=='s') {
				if (s.substr(i, 4)!="sare") {
					cout<<"NO"<<endl;
					return 0;
				}i+=4;
			} else {
				cout<<"NO"<<endl;
				return 0;
			}
		} else {
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 512
//last updated : 11.04.2020
#include <bits/stdc++.h>
#pragma GCC optimization ("O3")
using namespace std;

#define ll              long long
#define ld              long double
#define pll             pair <ll, ll>
#define plll            pair <ll, pll>

#define fa(i, n, N)     for (ll i = n; i <= N; ++i)
#define fac(i, n, b, N) for (ll i = n; i <= N && b; ++i)
#define fd(i, n, N)     for (ll i = n; i >= N; --i)

#define mp              make_pair
#define pb              push_back
#define pob             pop_back
#define pf              push_front
#define pof             pop_front
#define fi              first
#define se              second

#define ms(arr,t)       memset (arr, t, sizeof(arr));
#define all(x)          x.begin(), x.end()
#define len             length()
#define endl            '\n'

#define isss(x, s)      istringstream x (s)
#define db(x)           cout << ">>>>>> " << #x << " -> " << x << endl
#define AAAA            cout << "\t------" << endl;

//urgent cases only!
#define get_rt		cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms.\n"

const ll inf = INT_MAX;
const ll inf2 = 1e18;
const ll MAX = 1e5+5;
const ll MOD = 1e9+7;
const double pi = acos(-1.0);
const double EPS = 1e-9;

void init(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

inline void iofile (){
	freopen ("input.txt", "r", stdin);
	// freopen ("output.txt", "w", stdout);
}


ll n, m, k, ttl;

int main() {
    init(10);
    //iofile();
	
	cin >> n >> m;
	ttl = 0;
	
	fa (i,1,m){
		cin >> k;
		ttl += k;
	}
	
	cout << (ttl > n ? -1 : n-ttl) << endl;

	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
 
vector<int> paths[650];
long double dp[650];
int N, M;
long double ans;
 
void input() {
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        int s, t;
        cin >> s >> t;
        paths[s].push_back(t);
    }
}
 
void f(int block) {
    dp[N] = 0;
    for(int i = N - 1; i >= 1; i--) {
        long double sum = 0.0;
        long double maxi = 0.0;
        int num = paths[i].size();
        for(auto to : paths[i]) {
            sum += dp[to];
            chmax(maxi, dp[to]);
        }
        if(i == block && num >= 2) {
            num--;
            sum -= maxi;
        }
        dp[i] = sum / num + 1;
    }
    chmin(ans, dp[1]);
}
 
void solve() {
    input();
    ans = 1e18;
    for(int i = 0; i <= N - 1; i++) {
        f(i);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 4924
#include <iostream>

using namespace std;
int m[2001];
int n, q, a;


bool judge(int time, int sum){
	if(time < n){
		return (judge(time + 1, sum) || judge(time + 1, sum - m[time]));
	}
	else{
		if(sum == 0){
			return true;
		}
		else{
			return false;
		}
	}
}


int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> m[i];
	}
	cin >> q;
	for(int i = 0; i < q; i++){
		cin >> a;
		if(judge(0, a)){
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
int a[114514],b[114514],c[114514];	
signed main(){
	int n;
	cin>>n;
	rep(0,i,n)cin>>a[i];
	rep(1,i,n){
		b[i]=a[i-1]*2-b[i-1];
	}
	int r=abs(a[n-1]*2-b[n-1])/2;
	rep(0,i,n){
		c[0]=r;
		c[i]=a[i-1]*2-c[i-1];
	}
	rep(0,i,n)cout<<c[i]<<" ";
}	

Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, a[1001][1001];
vector<vector<i64>> g;

i64 idx(i64 x, i64 y) {
  if (x > y) swap(x, y);
  return n * x + y;
}

bool seen[1000 * 1000 + 2];
bool fix[1000 * 1000 + 2];
i64 dist[1000 * 1000 + 2];
i64 dfs(i64 u) {
  if (fix[u]) return dist[u];
  if (seen[u]) return -1;
  seen[u] = true;
  i64 d = 0;
  for (i64 v : g[u]) {
    i64 x = dfs(v);
    if (x == -1) return -1;
    d = max(d, dfs(v) + 1);
  }
  fix[u] = true;
  return dist[u] = d;
}

int main() {
  cin >> n;
  init_n(g, 1000 * 1000 + 2);
  for (i64 i = 1; i <= n; ++i) {
    for (i64 j = 0; j < n - 1; ++j) {
      cin >> a[i][j];
    }
  }

  for (i64 i = 1; i <= n; ++i) {
    i64 prev = 0;
    for (i64 j = 0; j < n - 1; ++j) {
      i64 next = idx(i, a[i][j]);
      g[prev].push_back(next);
      prev = next;
    }
  }

  cout << dfs(0) << endl;
  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int sum = 0;
    int k = s.size();

    for (auto i = 0; i < k; i++)
    {
        if (s[i] == 'o')
        {
            sum += 1;
        }
    }

    if (sum + 15 - k >= 8)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

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

typedef long long ll;
ll INF = 1LL << 60;
int MAX = 100010;

void
dfs(long sum, long _max, int bit_flag, long& ans)
{
  if(sum > _max) return;
  if(bit_flag == 0b111) ans++;

  dfs(10 * sum + 7, _max, bit_flag | 0b001, ans);
  dfs(10 * sum + 5, _max, bit_flag | 0b010, ans);
  dfs(10 * sum + 3, _max, bit_flag | 0b100, ans);

}

int 
main() 
{
  long n; cin >> n;
  long ans = 0;
  dfs(0, n, 0, ans);

  cout << ans << endl;
  return 0;

}




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

int main () {
  int n, l;
  std::cin >> n >> l;
  std::vector<int> aji(300);
  int min_abs = 0;
  for (int i = 0; i < n; i++) {
    aji.at(i) = l;
    int pretmp = l;
    if (i != 0 && std::abs(pretmp - 1) > std::abs(l)) {
      min_abs = i;
    }
    l++;
  }
 
  aji.erase(aji.begin() + min_abs);
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ans += aji.at(i);
  }

  std::cout << ans << std::endl;

  return 0;
}


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

int main(){
    using namespace std;
    unsigned long Q;
    cin >> Q;
    constexpr auto M{205891132094649UL};
    const auto& calc = [](auto a, auto b, auto c, auto d){
        auto u{b}, l{b}, p{M};
        while(p /= 3)if((a / p + (4 - a / p % 3) % 3) * p <= c){
            if(u / p % 3 == 1)u = u / (3 * p) * 3 * p + 2 * p;
            if(l / p % 3 == 1){
                l = l / (3 * p) * 3 * p + p - 1;
                break;
            }
        }
        return c - a + min(u - b + max(u, d) - min(u, d), b + d - 2 * l);
    };
    for(unsigned long _{0}, a, b, c, d; _ < Q; ++_){
        cin >> a >> b >> c >> d;
        if(--a > --c)swap(a, c), swap(b, d);
        if(--b > --d){
            b = M - b - 1;
            d = M - d - 1;
        }
        cout << max(calc(a, b, c, d), calc(b, a, d, c)) << endl;
    }
    return 0;
}

Measured memory_bytes: 384
PI = Math::PI
A, B, X = gets.split.map(&:to_f)
capa = A**2 * B
ans = 0
if X > capa/2
  # a*(a*?/2) = 水筒キャパ - 水
  n = 2 * (capa - X)/(A**3)
  ans = (Math.atan(n)).abs * 180/PI
else
  # a*(b*?/2) = 水
  n = 2 * X/(A*B**2)
  ans = 90 - (Math.atan(n)).abs * 180/PI
end
p ans

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin >> S >> T;
  int cnt=0;
  for(int i=0;i<3;i++){
    if(S.at(i)==T.at(i)){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256