akhauriyash/Code-Regression huggingface dataset:
let n = Scanf.scanf " %d" (+) 0
let g = Array.make n []
let ans = Array.make n 0
let rec f v p c =
  ans.(v) <- c;
  List.iter (fun (u, w) -> if u <> p then f u v @@ if w mod 2 = 0 then c else 1 - c) g.(v)
let _ =
  for _ = 1 to n - 1 do
    Scanf.scanf " %d %d %d" @@ fun u v w ->
      g.(u - 1) <- (v - 1, w) :: g.(u - 1); g.(v - 1) <- (u - 1, w) :: g.(v - 1) done;
  f 0 (-1) 0;
  ans |> Array.iter @@ Printf.printf "%d\n"

Measured memory_bytes: 19584
#include <cstdio>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(1e5 + 10), Mod(1e9 + 7);
int fastpow(int x, int y)
{
	int ans = 1;
	for (; y; y >>= 1, x = 1ll * x * x % Mod)
		if (y & 1) ans = 1ll * ans * x % Mod;
	return ans;
}

int fac[N], inv[N], n, m;
int C(int n, int m)
{
	int ans = 1;
	for (int i = n; i > n - m; i--) ans = 1ll * ans * i % Mod;
	return 1ll * ans * inv[m] % Mod;
}

int main()
{
	n = read(), m = read(), fac[0] = inv[0] = 1;
	for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
	inv[n] = fastpow(fac[n], Mod - 2);
	int ans = 1;
	for (int i = n - 1; i; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % Mod;
	for (int i = 2; i * i <= m; i++) if (!(m % i))
	{
		int cnt = 0;
		while (!(m % i)) m /= i, ++cnt;
		ans = 1ll * ans * C(cnt + n - 1, n - 1) % Mod;
	}
	if (m > 1) ans = 1ll * ans * n % Mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'000;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

void solve(){
    ll n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    map<ll,ll> mp;
    mp[2]=a,mp[3]=b,mp[5]=c;
    map<ll,ll> dp;
    dp[0]=0;
    dp[1]=d;
    auto dfs=[&](auto &dfs,ll x)->ll{
        if(x<0) return -inf;
        if(dp.count(x)) return dp[x];
        ll ret=inf;
        if(ret/d>x) ret=x*d;
        for(auto div:{2,3,5}){
            ll r=x%div;
            chmin(ret,dfs(dfs,(x-r)/div)+mp[div]+r*d);
            if(r) chmin(ret,dfs(dfs,(x+div-r)/div)+mp[div]+(div-r)*d);
        }
        return dp[x]=ret;
    };
    cout<<dfs(dfs,n)<<endl;
}

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

Measured memory_bytes: 4484
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int n;
  cin >> n;
  long s = 0;
  rep(i,0,n){
    long a,b;
    cin >> a >> b;
    s += b-a+1;
  }
  P(s);
  ret 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define LL long long
using namespace std;
int n,m,a[N],b[N],c[N],d[N]; LL sum,x[N],k;
int main()
{
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%lld",&x[i]);
	scanf("%d %lld",&m,&k);
	for(i=1;i<=m;i++) scanf("%d",&a[i]);
	for(i=n;i>=1;i--) x[i]-=x[i-1];
	for(i=1;i<=n;i++) b[i]=c[i]=i;
	for(i=1;i<=m;i++) swap(b[a[i]],b[a[i]+1]);
	while(k){
		if(k&1) for(i=1;i<=n;i++) c[i]=b[c[i]];
		k>>=1;
		for(i=1;i<=n;i++) d[i]=b[b[i]];
		for(i=1;i<=n;i++) b[i]=d[i];
	  }
	for(i=1;i<=n;i++)
		sum+=x[c[i]],printf("%lld\n",sum);
	return 0;
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    LL k;cin>>k;


    LL now = 7;
    FOR(i,1,10000000){
        if(now % k == 0){
            cout<<i<<endl;
            return;
        }

        now %= k;
        now = now*10+7;

    }

    cout<<-1<<endl;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

string s;
int p;

int dfs(){
  vector<int> v;
  while(s[p]=='[')p++,v.push_back(dfs());
  if(isdigit(s[p])){
    int c=0;
    while(isdigit(s[p])){
      c=c*10+s[p]-'0';
      p++;
    }
    p++;
    return (c+1)/2;
  }
  p++;
  sort(v.begin(),v.end());
  int res=0;
  for(int i=0;i<(v.size()+1)/2;i++)res+=v[i];
  return res;
}

int main(){
  int T;
  cin>>T;
  while(T--){
      cin>>s;
      p=0;
      cout<<dfs()<<endl;
  }
  return 0;
}

Measured memory_bytes: 3244
s = int(input())
if s <= 10**9:
	print(0, 0, 1, 0, 0, s)
elif s == 10**18:
	print(0, 0, 10**9, 0, 0, 10**9)
else:
	t = 10**9 - (s%(10**9))
	print(0, 0, 10**9, 1, t, (s+t)//10**9)

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

using namespace std;

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

	string S;
	cin >> S;
	int sum = 0, ans = 0;

	for (int i = 0; i < S.length(); i++) {
		if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
			sum++;
		}
		else {
			sum = 0;
		}
		ans = max(ans, sum);
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    int m = 3 * n;
    vector<int> a(m);
    rep(i, m) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    rep(i, n) {
        ans += a[2 * i + n];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

const int MAX = 1000000;

// fac: 階乗, finv: 階乗の逆元, inv: 逆元
ll fac[MAX], finv[MAX], inv[MAX];

void cominit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

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

ll com(ll n, ll k){
    if (n<k) return 0;
    if (n<0 or k<0) return 0;
    return fac[n] * (finv[k]*finv[n-k]%mod)%mod;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    cominit();
    if(n-1<=k){
        ans = com(n+n-1, n);
        cout << ans << endl;
        return 0;
    }else{
        ll tmp = 1;
        rep(i, k){
            tmp += com(n, i+1)*com(n-1, i+1);
            tmp %= mod;
        }
        cout << tmp << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s,a;
    cin >> s;
    for(int x=0; x<s.size(); x++){
        if(s[x]=='0') a+='0';
        if(s[x]=='1') a+='1';
        if(s[x]=='B') a=a.substr(0,a.size()-1);    
    } cout << a << endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define vbi vector<bool> 
#define mod 1000000007
#define INF 1000000000
#define db double
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define ms(x,v) memset(x,v,sizeof x)
#define endl '\n'
#define cnl cout<<endl;
#define frr(i,b) for(ll i=0; i<b;i++)
#define fb(i,b) for(ll i=b-1; i>=0; i--)
#define pi  3.141592653589793238
ll i,j,k;
ll ans;
vector<long int > tree[10000+1];
vector<long int > v;
vector<bool> visited(10000+1,0);
int main(){
   
     ll n; cin>>n;
      vl v(n) ;
      frr(i,n) cin>>v[i];
      vector<pair<long int ,long int>> pa;
      for(i=0;i<n;i++)
      {
        pa.pb(mp(v[i],(i+1)));
      }
      sort(all(pa));
      for(i=0;i<n;i++){
        cout<<pa[i].sd<<" ";
      }








return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    typedef pair<ll, ll> l_l;
    typedef pair<int , int> i_i;
    typedef vector<ll> vl;
    typedef vector<int> vi;
    typedef vector<char> vec;
    typedef vector<bool> veb;
    typedef vector<string> ves;
    typedef vector<vector<ll>> vvl;
    typedef vector<vector<int>> vvi;
    typedef vector<vector<char>> vvec;
    typedef vector<vector<bool>> vveb;
    typedef vector<vector<string>> vves;
    #define rep(i,n) for(int i=0;i<(int)(n);i++)
    #define rep1(i,n) for(int i=1;i<(int)(n);i++)
    #define rep2(i,n) for(int i=2;i<(int)(n);i++)
    #define repk(i,k,n) for(int i=k;i<(int)(n);i++)
    #define fs first
    #define sc second
    #define pb push_back
    #define pp pop_back
    #define all(a) a.begin(),a.end()
    #define rall(a) a.rbegin(),a.rend()
    #define maxel(a) *max_element(all(a))
    #define minel(a) *min_element(all(a))
    #define acc accumulate
    #define EPS (1e-7)
    #define INF (1e9)
    #define PI (acos(-1))
    #define mod (1000000007)
    typedef long long int64;
    //const int64 INF = 1LL << 58;
    #define dame { puts("-1"); return 0;}
    #define YES { cout << "YES" << endl; return 0; }
    #define NO { cout << "NO" << endl; return 0; }
    #define Yes { cout << "Yes" << endl; return 0; }
    #define No { cout << "No" << endl; return 0; }
    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 (a>b) { a=b; return 1; } return 0; }
    int dx[] = {0, 0, -1, 1};
    int dy[] = {1, -1, 0, 0};
     
    int main(){
    	cin.tie(0);
    	ios::sync_with_stdio(false);
     
    	ll a,b,n;
    	cin >> n;
    	cin >>a;
    	cin >>b;
    	ll kazu=0;
    	ll x = a+b;
    	ll y =0;
      	kazu = n/x;
    	n %= x;
    	y = a*kazu + min(n,a);
      	cout << y << endl;
      	return 0;
    	
 
    }

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int x,y,w,h,r;
	cin>>w>>h>>x>>y>>r;
	if(x-r>=0&&x+r<=w&&y-r>=0&&y+r<=h)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define int long long
using namespace std;

int n;
double p[3000];
double dp[3000][3000][3];

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cout<<fixed<<setprecision(10);
    cin >> n;
    for(int i=1;i<=n;i++) cin >> p[i];
    dp[1][1][1]=p[1];
    dp[1][0][0]=(1-p[1]);
    for(int i=2;i<=n;i++){
        for(int j=0;j<=i;j++){
            dp[i][j][1]=(dp[i-1][j-1][0]+dp[i-1][j-1][1])*p[i];
            dp[i][j][0]=(dp[i-1][j][0]+dp[i-1][j][1])*(1-p[i]);
        }
    }
    int j=n/2+1;
    double ans=0;
    for(int i=j;i<=n;i++){
        ans+=(dp[n][i][1]+dp[n][i][0]);
    }
    cout<<ans;
}


Measured memory_bytes: 209280
// https://atcoder.jp/contests/abc049/tasks/arc065_a

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

//　見つかったら次の桁数、見つからなければ-1
int vsearch(string s, int i) {
    int ret = -1;
    if (s.size() == i) {
        return i;
    }
    if (s.substr(i, 5) == "dream") {
        ret = vsearch(s, i + 5);
        if (s.size() == ret) {
            return ret;
        }
    }
    if (s.substr(i, 7) == "dreamer") {
        ret = vsearch(s, i + 7);
        if (s.size() == ret) {
            return ret;
        }
    }
    if (s.substr(i, 5) == "erase") {
        ret = vsearch(s, i + 5);
        if (s.size() == ret) {
            return ret;
        }
    }
    if (s.substr(i, 6) == "eraser") {
        ret = vsearch(s, i + 6);
        if (s.size() == ret) {
            return ret;
        }
    }
    return ret;
}

int main() {
    int ans = 0;
    string s;
    cin >> s;

    ans = vsearch(s, 0);
    if (ans == -1) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 2048
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		String S=stdIn.next();
		int dp[][]=new int[S.length()+5][13];
		dp[0][0]=1;
		int z=0;
		while(z<S.length()){
			char a=S.charAt(z);
			int y=0,ki=0;
			if(a=='?'){
				while(y<10){
					while(ki<13){
						dp[z+1][(ki*10+y)%13]+=dp[z][ki];
						dp[z+1][(ki*10+y)%13]%=1000000007;
						ki++;
					}ki=0;
					y++;
				}y=0;
			}
			else{
				y=a-'0';
				while(ki<13){
					dp[z+1][(ki*10+y)%13]+=dp[z][ki];
					dp[z+1][(ki*10+y)%13]%=1000000007;
					ki++;
				}ki=0;
			}
			z++;
		}
		System.out.println(dp[S.length()][5]);
	}
}

Measured memory_bytes: 32148
INF = -float("inf")

def Bellmanford(n, edges):
    dp = [INF] * n
    dp[0] = 0

    for i in range(n):  # たかだかn-1回ループ　n回目でまだ更新できたら負閉路がある
        for u, v, c in edges:
            if dp[u] != INF and dp[u] + c > dp[v]:
                dp[v] = dp[u] + c
                if i == n-1 and v == n-1:
                    return "inf"

    return dp[n-1]


N, M = map(int, input().split())
E = []

for i in range(M):
    a, b, c = map(int, input().split())
    E.append((a-1, b-1, c))

ans = Bellmanford(N, E)

print(ans)

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

int main()
{
    string s;
    while(getline(cin, s))
    {
        while(s.find("this")==s.npos && s.find("that") == s.npos && s.find("the") == s.npos)
        {
            for(int i = 0; i <(int) s.size(); i++)
            {
                if(s[i] > 'z' || s[i] < 'a')
                    continue;
                if(s[i] != 'z')
                    s[i]++;
                else
                    s[i] = 'a';
            }
        }
        cout<<s<<endl;
    }
}



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

int a[26];

int main() {
  string s;
  cin >> s;
  for (char c: s) {
    a[c - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (a[i] >= 2) {
      cout << "no" << endl; return 0;
    }
  }
  cout << "yes" << endl;
}

Measured memory_bytes: 256
// AtCoder165 C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int revcompare(const void* a, const void* b) {
    return *(int*)b- *(int*)a;
}


int main() {
    int i,j;
    int n;
    int* v;
    double new;

    scanf("%d", &n);
    v = (int*)malloc(sizeof(int) * n);
    for(i=0;i<n;i++){
        scanf("%d", v + i);
    }

    qsort(v, n, sizeof(int), compare);

    new = v[0];
    for(i=1;i<n;i++){
        new = (new + v[i]) / 2;
    }

    printf("%f", new);

    return 0;
}

Measured memory_bytes: 128
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    S = sys.stdin.readline().rstrip()
    if int(S[5:7]) < 5:
        print("Heisei")
    else:
        print("TBD")


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

  
int main() {
int N;
cin >> N;
vector<int>v(N);
REP(i, N) cin >> v.at(i);

sort(all(v));
double ans = v.at(0);

REP(i, N - 1){
    ans = (ans + v.at(i + 1)) / 2;
}
print(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,a[111111],the1;
int main()
{
	cin>>n>>m;
	m--;
	for(int i=0;i<n;i++)
		cin>>a[i];
	n--;
	if(n%m!=0)
		cout<<n/m+1<<endl;
	else
		cout<<n/m<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<utility>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MAX 1000000007

using namespace std;

bool cmp(const pair<lli, pair<int,int>> left, pair<lli, pair<int,int>> right) {
	return left.first < right.first;
}

int main() {
	int n;
	cin >> n;
	vector<pair<lli, pair<int,int>>> vec(n);
	
	rep0(i,n)cin >> vec[i].second.first >> vec[i].second.second >> vec[i].first;
	
	sort(rall(vec), cmp);
	
	rep0(i,101)rep0(j,101){
		lli high = abs(vec[0].second.first-i)+abs(vec[0].second.second-j)+vec[0].first;
		int frag=0;
		rep0(k,n){
			if(high != abs(vec[k].second.first-i)+abs(vec[k].second.second-j)+vec[k].first&&!(high - abs(vec[k].second.first-i)-abs(vec[k].second.second-j)<0 && vec[k].first==0)){
				frag=-1;
				break;
			}
		}
		if(frag==0)
		{
			cout << i << ' ' << j << ' ' << high;
			return 0;
		}
	}
}


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

int main(){
	int b,r,g,c,s,t,ans;
	while(true){
		cin >> b >> r >> g >> c >> s >> t;
		if(!b && !r && !g && !c && !s && !t)
			return 0;
		ans = 100;
		ans += b*5*15;
		ans -= b*5*2;
		t -= b*5;
		ans += b*15;
		ans += r*3*15;
		t -= r*3;
		ans -= r*3*2;
		ans += r*15;
		ans += g*7;
		ans += c*2;
		t -= s;
		ans -= t*3;
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Circle Pond
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const double PI = acos(-1.0);

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int r;
  scanf("%d", &r);

  printf("%.20lf\n", PI * r * 2);
  return 0;
}


Measured memory_bytes: 3232
def resolve():
    N = int(input())
    c = input()

    ans = 0
    lp = 0
    rp = N-1
    try:
        while lp < rp:
            while lp < N and c[lp] == "R":
                lp += 1
            while rp > -1 and c[rp] == "W":
                rp -= 1
            if lp < rp:
                ans += 1
                lp += 1
                rp -= 1
    except Exception as err:
        print(err)
        print(c, lp, rp)
    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9492
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#define INF INT_MAX
using namespace std;

int N, K;
int ans;

int main(){
	cin >> N >> K;
	if (N%K == 0){
		cout << "0" << endl;
	}
	else{
		cout << "1" << endl;
	}

	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define IFOR(k,a,b) for(int k=(a); k>=(b); --k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define IREP(k,a) for(int k=a-1; k>=(0);--k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define x first
#define y second
#define INF 1000000001
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define PI 3.1415926535897932384626
#define ERR -987654321
#define MEM(a,b) memset(a,b,sizeof(a));
#define read1(a) scanf("%d",&a)
#define read2(a,b) scanf("%d%d",&a,&b)
#define read3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define readl1(a) scanf("%lld",&a)
#define readl2(a,b) scanf("%lld%lld",&a,&b)
#define readl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

int n, a[MAXN], f[MAXN];
set<int> bit[32];

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int rn = uniform_int_distribution<int>(0, MAXN)(rng);

    cin>>n;
    REP(i,n) cin>>a[i];

    int p = n-1;
    ll res = 0;
    IREP(i,n) {
        int l = i, r = n-1;
        REP(j,31) {
            if(!(a[i] & (1<<j))) continue;
            if(!bit[j].empty()) r = min(r, (*bit[j].begin())-1);
            bit[j].insert(i);
        }
        f[i] = r;
        p = min(p,r);
        res = (res + p - l + 1);
    }
    cout<<res;
    return 0;
}





Measured memory_bytes: 98944
#include<stdio.h>
int main()
{
  int a,b[10000],c,d,s,i;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&b[i]);
  }
  d=a-1;
  for(i=d;i>=0;i--){
    if (i>0)printf("%d ",b[i]);
    else printf("%d",b[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;

int main(){
    int K,X;
    cin >> K;
    cin >> X;
    int s,e;
    s = X - K + 1;
    e = X + K -1;
    for(int i=s;i<=e;i++)
        cout << i << " ";
    cout << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define each(i,mp) for(auto& i:mp)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll n,m;cin>>n>>m;
  ll x;cin>>x;
  ll c[n];
  ll a[n][m];

  rep(i,0,n){
    cin>>c[i];
    rep(j,0,m)cin>>a[i][j];
  }
  ll mi=INF;
  rep(bit,0,(1<<n)){
    ll l[m];CLR(l,0);
    ll cost=0;
    rep(i,0,n){
      if(bit&(1<<i)){
        cost+=c[i];
        rep(j,0,m){
          l[j]+=a[i][j];
        }
      }
    }
    bool e=true;
    rep(j,0,m){
      if(l[j]<x)e=false;
    }

    if(e)chmin(mi,cost);
  }

  if(mi==INF)out(-1);
  else out(mi);


  return 0;
}


Measured memory_bytes: 3640
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;

void main() {
    int n = readln.chomp.to!int;
    iota(1, n+1).filter!(i => i.to!string.length & 1)
                .array
                .length
                .writeln;
}

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

int main(){
  int n,i,j;
  cin>>n;
  int w[n];
  for(i=0;i<n;i++)cin>>w[i];
  int sum1,sum2,mi=1000;
  for(i=0;i<n;i++){
    sum1=0;
    sum2=0;
    for(j=0;j<i;j++){
      sum1+=w[j];
    }
    for(j=i;j<n;j++){
      sum2+=w[j];
    }
    mi=min(mi,(int)abs(sum1-sum2));
  }
  cout<<mi;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll; 
int main(void)
{
	int a,b,c;	
	cin >> a>>b>>c;
	if (a + b + c >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,n,flag=0,flag2=0;
  cin >> x >> n;
  if(n==0){
    cout << x << endl;
    return 0;
  }
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
        cin >> p.at(i);
    }
 sort(p.begin(), p.end());
 for (int i = 0; i < n+1; i++) {
     for (int j = 0;  j< n; j++) {
          if(p.at(j)==(x-i)){
            flag=1;
            }
         }
      if(flag==0){    
         cout << (x-i) << endl;
         return 0;
        }
      if(flag==1&&i!=0){
       // for (int l = 0; l < x; l++) {
           for (int j = 0;  j< n; j++) {
               if(p.at(j)==(x+i)){
                  flag2=1;
                  }
               }
           if(flag2==0){    
              cout << (x+i) << endl;
              return 0;
             }
          flag2=0;
          }
       //}
     flag=0;
     }
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>


using namespace std;
string yn(bool a)
{
  if (a){return "Yes";}
  else{return "No";}
}

int main()
{
  ios::sync_with_stdio(false);
  string s;
  int x,y;
  cin>>s>>x>>y;
  vector<int> a,b;
  bool f=1;
  int tmp=0;
  for(auto itr=s.begin();itr !=s.end();itr++)
  {
    if(*itr=='F'){tmp++;}
    else {
      if(f){a.push_back(tmp);}
      else{b.push_back(tmp);}
      f=!f;
    tmp=0;
  }

  }
  if(f){a.push_back(tmp);}
  else{b.push_back(tmp);}
  x-=a[0];
  x=abs(x);
  y=abs(y);
  a.erase(a.begin());
  int suma=0,sumb=0;
  for(auto itr=a.begin();itr !=a.end();itr++)
  {
    suma+=*itr;
  }
  for(auto itr=b.begin();itr !=b.end();itr++)
  {
    sumb+=*itr;
  }
  int flag=0;
  if((suma-x)%2 or (sumb-y)%2){flag=0;}
  else
  {
    if(suma<x or sumb<y){flag=-2;}
    x=(suma-x)/2;
    y=(sumb-y)/2;
    vector<int> dpx(8001),dpy(8001);
    for(int i=0;i<8001;i++){dpx[i]=0;dpy[i]=0;}
    dpx[0]=1;dpx[suma]=1;
    dpy[0]=1;dpy[sumb]=1;
    for(auto itr1=a.begin();itr1 !=a.end();itr1++)
    {
      for(int i=suma;i>-1;i--)
      {
        if(dpx[i]==1){dpx[i+*itr1]=1;}
      }
      if(dpx[x]!=0 or dpx[suma-x]!=0){flag+=1;break;}

    }
    if(a.size()==0 and x==0){flag+=1;}
    for(auto itr2=b.begin();itr2 !=b.end();itr2++)
    {
      for(int i=sumb;i>-1;i--)
      {
        if(dpy[i]==1){dpy[i+*itr2]=1;}
      }
      if(dpy[y]!=0 or dpy[sumb-y]!=0){flag+=1;break;}
    }
    if(b.size()==0 and x==0){flag+=1;}
  }
  cout<<yn(flag>=2)<<endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define tri(x) (ll)((ll)(x)*(ll)(x)*(ll)(x))
long long ans, mtp;
int main()
{
	int n, k;
	cin>>n>>k;
	int mod = k>>1;
	for(int i=1; i<=n; i++)
	{
		ans += i%k == mod;
		mtp += i%k == 0;
	}
	if(k&1)
		cout<<tri(mtp);
	else
		cout<<tri(ans)+tri(mtp);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
	int h, w; cin >> h >> w;
	int c[11][11];
	int m[11][11];
	int a[202][202];
	for(int i=0;i<=9;i++){
		for(int j=0;j<=9;j++){
			cin >> c[i][j];
			m[i][j] = c[i][j]; 
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> a[i][j];
		}
	}
	for(int k=0;k<=9;k++){
		for(int i=0;i<=9;i++){
			for(int j=0;j<=9;j++){
				m[i][j] = min(m[i][j], m[i][k]+m[k][j]);
			}
		}
	}
	long long int ans = 0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(a[i][j]==1 || a[i][j]==-1){
				continue;
			}else{
				ans += m[a[i][j]][1];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> l(N),R(N);
  int seat = 0;
  for(int i = 0; i < N; i++){
    cin >> l.at(i) >> R.at(i);
    seat += R.at(i) - l.at(i) + 1;
  }
  cout << seat << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

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

typedef long long ll;

int main() {
	int X, A;
	cin >> X >> A;
	if (X < A) { cout << 0; }
	else {
		cout << 10;
	}
	return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
A = [0] * (N + 1)
for i in range(N):
    if S[i] == '<':
        A[i + 1] = A[i] + 1
for i in range(N - 1, -1, -1):
    a = A[i + 1] + 1
    if S[i] == '>' and a > A[i]:
        A[i] = a
print(sum(A))


Measured memory_bytes: 28984
#include <bits/stdc++.h>
int e,n,c,k,i;
using namespace std;
int main() {
  cin>>e;
  while(e--){
    cin>>n;
    c=0;
    while(n>9){
      int m=0,b=1;
      for(c++,i=0;i<5;i++){
        b*=10;
        k=(n/b)*(n%b);
        if(k>m)m=k;
      }
      n=m;
    }
    cout<<c<<endl;
  }
}

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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n; 
    int ans=0;
    for(int i=0; i<n; i++){
        int l, r; cin>>l>>r;
        ans+=(r-l+1);
    }
        
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#define rep(a,b,c) for(ll a=b;a<=c;a++)
#define per(a,b,c) for(ll a=b;a>=c;a--)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
const int inf = 0x3f3f3f3f;
const int N = 1e5+5;
int n, m;
struct node{
    ll a, b;
}s[N];
bool cmp(node p, node q){
    if(p.b != q.b) return p.b > q.b;
    return p.a > q.a;
}

int pre[N];
int Find(int x){
    return x == pre[x] ? x : pre[x] = Find(pre[x]);
}
void join(int x, int y){
    int fx = Find(x);
    int fy = Find(y);
    if(fx != fy) pre[fx] = fy;
}

int cnt[N];
int main(){
    scanf("%d%d", &n, &m);
    rep(i,1,n){
        scanf("%lld%lld", &s[i].a, &s[i].b);
    }
    rep(i,1,m+1) pre[i] = i;
    sort(s+1,s+1+n,cmp);
    ll ans = 0;
    rep(i,1,n){
        if(s[i].a > m) continue;
        if(!cnt[s[i].a]){
            cnt[s[i].a] = 1;
            pre[s[i].a] = Find(s[i].a+1);
            ans += s[i].b;
        }
        else{
            int p = Find(s[i].a);
            if(p <= m){
                cnt[p] = 1;
                pre[p] = Find(p+1);
                ans += s[i].b;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

const int INF = 1001001001;

int main() {
	vector<int> v(5);
	rep(i, 5) cin >> v[i];
	int last_order = 0;
	int r, tmp, last_order_num;
	rep(i, 5) {
		if (v[i]%10 != 0) r = v[i]%10;
		else continue;
		tmp = 10-r;
		if (tmp > last_order) {
			last_order = tmp;
			last_order_num = i;
		} else continue;
	}
	int ans = 0;
	rep(i, 5) {
		if (i == last_order_num) continue;
		ans += ((v[i]+(10-1))/10)*10;
	}
	ans += v[last_order_num];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
def resolve():
    '''
    code here
    '''
    import collections
    N, X, Y = [int(item) for item in input().split()]
    X -= 1
    Y -= 1

    edges = [[] for _ in range(N)]
    for i in range(N-1):
        edges[i].append(i+1)
        edges[i+1].append(i)
    edges[X].append(Y)
    edges[Y].append(X)


    fp = [-1 for _ in range(N)]

    res_memo = [0 for _ in range(N)]
    for i in range(N):
        fp = [-1 for _ in range(N)]
        que = collections.deque([[i, 0]])
        fp[i] = 0
        while que:
            node, dist = que.popleft()
            for to_node in edges[node]:
                if fp[to_node] == -1:
                    que.append([to_node, dist+1])
                    fp[to_node] = dist+1

        for item in fp:
            res_memo[item] +=1
    
    for item in res_memo[1:]:
        print(item//2)



if __name__ == "__main__":
    resolve()


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

int main(){
    int N, K;  cin >> N >> K;
    vector<ll> a(N+1);
    for(int i=1; i<=N; i++) cin >> a[i];

    ll mod = 1000000007;
    vector<vector<ll>> dp;
    dp = vector<vector<ll>>(N+1, vector<ll>(K+1, 0));
    for(int i=0; i<=N; i++) dp[i][0] = 1;

    for(int i=1; i<=N; i++){
        for(int j=1; j<=K; j++){    
            if(j-a[i]-1>=0){
                dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-a[i]-1] + mod)%mod;
            }else{
                dp[i][j] = (dp[i][j-1] + dp[i-1][j])%mod;
            }
        }
    }
    cout << dp[N][K] << endl;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define dbg() cerr <<
#define name(x) (#x) << ": " << (x) << ' ' <<

using namespace std;

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

  string s; cin >> s;
  for (auto &c : s) {
    if (c == '?') c = 'D';
  }
  cout << s << endl;
}


Measured memory_bytes: 3700
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>

using namespace std;
using ll = long long int;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 10000007 //10^9+7

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


int main(void){
  
  ll n,m;
  cin>>n>>m;
  ll ans = n;

  REP(i, m){
    int x;
    cin>>x;
    ans -= x;
  }
  if(ans>=0)cout<<ans<<endl;
  else cout<<"-1"<<endl;
  return 0;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    int ans = 1e8;
    for (int i=1; i<=100; ++i) {
        int tmp = 0;
        for (int j=0; j<n; ++j) {
            tmp += pow(x[j]-i, 2);
        }
        chmin(ans, tmp);
    }
    cout << ans << endl;
    // int mean1 = mean / n;
    // int mean2 = (mean+n-1)/n;
    // int ans = 0;
    // rep(i, n) ans += pow((x[i]-mean), 2);
    // int ans2 = 0;
    // rep(i, n) ans2 += pow(x[i]-mean2, 2);
    // cout << min(ans, ans2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll foo[100001][4];
ll n;
ll a[100001];
ll b[100001];
ll c[100001];
ll trump(ll x,ll p){
    if(x>n)return 0;
    if(foo[x][p]!=-1)return foo[x][p];
    ll a1=0,b1=0,c1=0;
    if(p==2||p==3||p==0){
        a1=a[x]+trump(x+1,1);
    }
    if(p==1||p==3||p==0){
        b1=b[x]+trump(x+1,2);
    }
    if(p==1||p==2||p==0){
        c1=c[x]+trump(x+1,3);
    }
    a1=max(a1,b1);
    a1=max(a1,c1);
    return foo[x][p]=a1;
}
int main(){
    //memset(foo,-1,sizeof(foo));
    for(int i=0;i<100001;i++)for(int j=0;j<4;j++)foo[i][j]=-1;
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    cout<<trump(1,0)<<endl;
    return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;
ll l[1001],r[1001],w[1001];
vector<ll> rs[400];
vector<ll> wss[400];
vector<ll> ids[400];
ll dp[401][1001];

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    rep(i,400){
      rs[i].clear();
      wss[i].clear();
      ids[i].clear();
    }
    repl(i,1,n+1){
      cin>>l[i]>>r[i]>>w[i];
      l[i]--; r[i]--;
      r[i]++;
      rs[l[i]].push_back(r[i]);
      wss[l[i]].push_back(w[i]);
      ids[l[i]].push_back(i);
    }
    rep(i,401)rep(j,1001)dp[i][j]=-INF;
    dp[0][0]=0;
    rep(i,400)rep(j,1001){
      if(dp[i][j]<0)continue;
      if(j==0){
        maxch(dp[i+1][j],dp[i][j]);
        rep(k,rs[i].size()){
          maxch(dp[i][ids[i][k]],dp[i][j]+wss[i][k]);
        }
      }else{
        if(r[j]==i+1)maxch(dp[i+1][0],dp[i][j]);
        else maxch(dp[i+1][j],dp[i][j]);
        rep(k,rs[i].size()){
          if(ids[i][k]==j)continue;
          ll mn=min(r[j],rs[i][k]);
          ll mx=max(r[j],rs[i][k]);
          if(mn==mx)maxch(dp[mn][0],dp[i][j]+wss[i][k]);
          else{
            maxch(dp[mn][(r[j]==mx?j:ids[i][k])],dp[i][j]+wss[i][k]);
          }
        }
      }
    }
    ll res=-INF;
    rep(i,401)rep(j,1001)maxch(res,dp[i][j]);
    cout<<res<<endl;
  }
  return 0;
}



Measured memory_bytes: 6360
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
typedef long long ll;
using namespace std;

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 long long INF = 1LL << 60;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
ll ma = 1000000000 + 7;


ll n, k;
int main() {
	cin >> n >> k;ll res = 0;
	vector<ll> t(n);
	for (ll i = 0;i < n;i++) {
		cin >> t[i];
	}
	for (ll i = 1;i < n;i++) {
		res += min(k, t[i] - t[i - 1]);
	}
	cout << res+k << endl;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int n, m, x; cin >> n >> m >> x;

	vector<vi> arr(n, vi(m));
	vi cost(n);

	for (int i = 0; i < n; ++i)
	{
		cin >> cost[i];
		for (int j = 0; j < m; ++j)
			cin >> arr[i][j];
	}

	int ans = inf;

	for (int mask = 0; mask < (1 << n); ++mask)
	{
		vi cur(m, 0);
		int cst = 0;
		for (int i = 0; i < n; ++i)
		{
			if ((mask >> i) & 1)
			{
				cst += cost[i];

				for (int j = 0; j < m; ++j)
					cur[j] += arr[i][j];
			}
		}

		int can = 1;

		for (int i = 0; i < m; ++i)
			if (cur[i] < x)
				can = 0;

		if (can)
			ans = min(ans, cst);
	}

	if (ans == inf)
		ans = -1;

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

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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("lld", &x); return (x); }

int main()
{
	int totalPrice = 0;
	int totalNum = 0;
	int price;
	int num;
	int count = 0;

	while( scanf("%d,%d", &price, &num) != EOF )
	{
		totalPrice += price * num;
		totalNum += num;
		count++;
	}
	printf("%d\n%d\n", totalPrice, (int)round((double)totalNum / count));
	return (0);
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

int main() {
    int x,n;
    cin >> x >> n;
    int p;
    vector<int> l(101,0);
    if(n == 0) {
        cout << x << endl;
        return 0;
    }
    rep(i,n){
        cin >> p;
        l[p] = 1;
    }
    int ans = -10000;
    int tmp = 10000;
    for(int i = -200;i<201;i++ ){
        if(l[i]==0){
            if(abs(x-ans)>=abs(x-i)){
                if(abs(x-i)<tmp){
                    tmp = abs(x-i);
                    ans = i;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long LL;
#define MAXN 100001

int A[MAXN];
int n;

int main()
{
	//freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);

	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &A[i]);
	}

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (A[i] == i) {
			if (i == 1) 
				swap(A[i], A[i+1]);
			else if (i == n) 
				swap(A[i], A[i-1]);
			else if (A[i+1] != i)
				swap(A[i], A[i+1]);
			else
				swap(A[i], A[i-1]);
			ans++;
		}
	}

	printf("%d", ans);

	return 0;
}

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

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top,s[1000];

void push(int x){
  s[++top]=x;
}
int pop(){
  top--;
  return s[top+1];
}

int main(){
  int a,b;
  char c[100];
  top=0;
  while(scanf("%s",c)!=EOF){
    if(c[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(c[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }
    else if(c[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else {
      push(atoi(c));
    }

  }
  printf("%d\n",pop());
  return 0;
}



Measured memory_bytes: 2108
#include<iostream>
using namespace std;
int main(){
	int n,a,b,c;
	while(cin>>n,n){
		while(n--){
			cin>>a>>b>>c;
			if((a==100||b==100||c==100)||a+b>=180||a+b+c>=240)
			cout<<'A'<<endl;
			else if(a+b+c>=210||(a+b+c>=150&&(a>=80||b>=80)))
			cout<<"B"<<endl;
			else cout<<"C"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0