akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

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

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

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;


map<string, int> memo;

using P=pair<int, int>;




/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/

ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n)cin >> a[i];
	sort(a.rbegin(), a.rend());
	int ans = a[0]/2;
	for (int i = 1; i < n; i++)ans += a[i];
	cout << ans << endl;
	return 0;
}













Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e18;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()
struct UnionFind {
    vector<int> par,si; 

    UnionFind(int N) : par(N), si(N,1) { 
        rep(i,0,N) par[i] = i;
    }

    int root(int x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        x = root(x); 
        y = root(y); 
        if (x == y) return; 
        si[y]+=si[x];
        par[x] = y; 
    }

    bool same(int x, int y) { 
      return root(x)== root(y);
    }
    int size(int x){
       return si[root(x)];
    }

};


void solve(){
  ll n,q;
  cin >> n >> q;
  UnionFind x(n+1);
  while(q--){
   ll t,u,v;
    cin >> t >> u >> v;
    if(t==0) x.unite(u,v);
    else cout << (x.same(u,v)?1:0) << endl;
    
  }
  
 
 
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 4688
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, ll> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;

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

    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }

    ll res = 0;
    for(int d = 0; d < 60; ++d){
        ll one_cnt = 0, zero_cnt = 0;
        for(int i = 0; i < n; ++i){
            if((a[i] >> d) & 1) ++one_cnt;
            else    ++zero_cnt;
        }
        ll tmp = (1ll << d) % mod;
        ll cnt = one_cnt * zero_cnt % mod;
        tmp = tmp * cnt % mod;
        res = (res + tmp) % mod;
    }
    cout << res << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }

long long clac(long long in,long long b){
    if(in == -1)return 0;
    else return in/b + 1;
}

//ミョ(-ω- ?)
int main() {
    ll a,b,x;
    cin >> a >> b >> x;
    cout << clac(b,x) - clac(a-1,x) << endl;
    return 0;
}

Measured memory_bytes: 256
a, b, c = list(map(int, input().split()))
if a == b and b == c and c == a:
    print(1)
elif a != b and b != c and c == a:
    print(2)
elif a == b and b != c and c != a:
    print(2)
elif a != b and b == c and c != a:
    print(2)
else:
    print(3)

Measured memory_bytes: 3060
import math

n = int(input())
c, s, f = [], [], []
for i in range(n-1):
    c_, s_, f_ = list(map(int, input().split()))
    c.append(c_)
    s.append(s_)
    f.append(f_)

for i in range(n-1):
    t = s[i]
    t += c[i]
    for j in range(i+1, n-1):
        if t < s[j]:
            t = s[j]
        else:
            t = f[j]*math.ceil(t/f[j])
        t += c[j]
    print(t)
print(0)


Measured memory_bytes: 3188
use whiteread::parse_line;

fn main() {
    let s: String = parse_line().unwrap();
    let ss: Vec<_> = s.chars().collect();
    let t: Vec<_> = "abcdefghijklmnopqrstuvwxyz".chars().collect();
    let mut b: bool = true;

    for e in t {
        if !ss.contains(&e) {
            println!("{}", e);
            b = false;
            break;
        }
    }
    if b {
        println!("None");
    }
}


Measured memory_bytes: 2652
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#define ll long long
#define INF 0x3f3f3f3f
#define SIS std::ios::sync_with_stdio(false)
using namespace std;
ll fast_pow(ll a,ll b,ll mod)
{
    ll c=1;
    while(b>=2)
    {
        if(b%2==0)
            a*=a,b/=2;
        else
            c*=a,a*=a,b--,b/=2;
        a%=mod,c%=mod;
    }
    return (a*c)%mod;
}

int main()
{
    string s;
    while(cin>>s)
    {
        if(s[2]==s[3]&&s[4]==s[5])
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

k,x = readints()

print('Yes'if 500*k>=x else'No')

Measured memory_bytes: 38384
#include <iostream>
#include <math.h>

using namespace std;

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

    if(b-a-w>=0) cout<<b-a-w<<endl;
    else if(a-b-w>=0)cout<<a-b-w<<endl;
    else if(a+w>=b||b+w>a) cout<<0<<endl;

    return 0;
}


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

using namespace std;
mt19937_64 rng(58);

long long f(long long k) {
    for (int i = 1, x = 7; i <= k; i++, x = (x * 10 + 7) % k) {
        if (x % k == 0) return i;
    }
    return -1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    long long k;
    cin >> k;
    cout << f(k) << endl;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int q;
    scanf("%d",&q);
    while(q--){
        bool memo[1000001];
        fill(memo,memo+1000001,false);
        int n;
        scanf("%d",&n);
        for(int i=0;true;i++){
            if(n/10==0){
                printf("%d\n",i);
                break;
            }
            int ma=0;
            for(int j=10;n/j;j*=10){
                int v1=n/j,v2=n%j;
                ma=max(ma,v1*v2);
            }
            if(memo[ma]){
                puts("-1");
                break;
            }
            memo[ma]=true;
            n=ma;
        }
    }
    return 0;
}

Measured memory_bytes: 2004
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

int main() {
    string a,s,b;
    cin >> a >> s >>b;
    cout << 'A' << s[0] << 'C' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{

    int n, k;
    cin >> n >> k;
    if (k == 1)
        cout << 0 << endl;
    else
        cout << n - k << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string s;
int n;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	s="1";
	n--;
	while(n){
		int g=0;
		for(int i=sz(s)-1;i>0;i--){
			if(s[i]!=((s[i-1]-'0')+1)+'0'&&s[i]!='9'){
				g=i;
				break;
			}
		}
		if(s[g]!='9'){
			s[g]++;
			forn(i,g+1,sz(s)){
				if(s[i-1]=='0')
				s[i]='0';
				else
				s[i]=((s[i-1]-'0')-1)+'0';
			}
		}else{
			bool f=true;
			for(int i=g;i>=0;i--){
				int x=s[i]-'0';
				if(f)
				x++;
				f=false;
				if(x==10){
					x=0;
					f=true;
				}
				s[i]=x+'0';
				if(!f)
				break;
			}
			forn(i,g+1,sz(s))
			s[i]='0';
			if(f){
				s='1'+s;
			}
		}
		n--;
	}
	cout<<s;
	re 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 51;
int n,m,s,t,b[N],cnt,a[N];

ll C[N][N],pre[N][N];
inline void init(int n){
	C[0][0]=1;
	For(i,1,n){
		C[i][0]=1;
		For(j,1,i) C[i][j]=C[i-1][j-1]+C[i-1][j],pre[i][j]=pre[i][j-1]+C[i][j];
	}
}

ll ans;
bool flag[1<<18|3];
inline ll calc(int x){
	ll ret=0;
	For(i,1,cnt){
		if (flag[x&a[i]]) continue;
		int tot=0;
		For(j,i,cnt) if ((a[j]&x)==(a[i]&x)) ++tot;
		ret+=pre[tot][min(m,tot)];
		flag[x&a[i]]=1;
	}
	For(i,1,cnt) flag[x&a[i]]=0;
	return ret;
}
inline void dfs(int u,int f,int mark){
	if (u==18){
		ans+=f*calc(mark);
		return;
	}
	if (!(s&(1<<u))) dfs(u+1,f,mark);
	else if (t&(1<<u)) dfs(u+1,f,mark);
	else dfs(u+1,f*(-1),mark|(1<<u)),dfs(u+1,f,mark);
}

int main(){
	n=read(),m=read(),t=read(),s=read();
	For(i,1,n) b[i]=read();
	For(i,0,17) if (!(s&(1<<i))&&(t&(1<<i))) return puts("0"),0;
	For(i,1,n){
		bool flag=1;
		For(j,0,17){
			if (!(s&(1<<j))){
				if (b[i]&1<<j) flag=0;
			} else if (t&(1<<j)){
				if (!(b[i]&(1<<j))) flag=0;
			}
		}
		if (flag) a[++cnt]=b[i];
	}
	init(cnt),dfs(0,1,0),printf("%lld\n",ans);
}

Measured memory_bytes: 4052
n = gets.to_i
n -= 1
d = 1
(1..100).each do |i|
  d *= 26
  if n < d
    puts n.to_s(26).rjust(i, '0').chars.map{|c|(c.to_i(26)+10).to_s(36)}.join
    exit
  else
    n -= d
  end
end

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

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

  vector<string> words;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    words.push_back(s);
  }

  vector<string> w(words);
  sort(w.begin(), w.end());
  
  if(w.end() != unique(w.begin(),w.end())){
    cout << "No" << endl;
    return 0;
  }

  for (int i = 1; i < n; i++) {
    if(words[i-1][words[i-1].size()-1]!=words[i][0]){
      cout << "No" << endl;
      return 0;
    }
  }

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


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[]
for i in range(Q):
    B.append(list(map(int,input().split())))
sum=int(0)
AA=[int(0)]
for i in range(100000):
    AA.append(int(0))
for i in A:
    AA[i]+=1 #A.count(int(i))
#for i in range(5):
#    print(AA[i])
sum=int(0)
for i in range(N):
    sum += A[i]
for i in range(Q):
#    AA[(B[i][0])]=A.count(int((B[i][0])))
#    A.replace(B[i][0],B[i][1])
#    AA[(B[i][1])]=A.count(int((B[i][1])))
    sum = sum + B[i][1]*AA[(B[i][0])]-B[i][0]*AA[(B[i][0])]
    AA[(B[i][1])] = AA[(B[i][1])]+AA[(B[i][0])]
    AA[(B[i][0])] = 0
    print(sum)


Measured memory_bytes: 31888
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000000007
#define MOD 1000000007
#define ARRAY_MAX 3005

int main(){

    vector<int> a(4);
    REP(i,4){
        cin >> a[i];
    }
    VSORT(a);
    if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }



    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define pb push_back
#define mp make_pair
#define ms memset
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define lower_bound lb
#define upper_bound ub

int main()
{
    int n; cin >> n;
    int cnt = 0;
    for (int i = 0; i < n; i++){
        int a; cin >> a;
        if (a % 2 == 1 && i % 2 == 0) cnt++;
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3616
// https://serhatgiydiren.github.io

#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(char c) {
  return to_string(string(1,c));
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define D(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define D(...) 404
#endif

void solve(const int &test_id)
{
 long long n,res=0,par=0;
 cin >> n;
 vector < long long > leaf(n+1),maxv(n+1);
 maxv[0]=1;
 for(int i=0;i<n+1;i++)
 {
  cin >> leaf[i];
  if (i)
  {
   long long pos_par=maxv[i-1]-leaf[i-1];
   if (LLONG_MAX/2<pos_par) maxv[i]=LLONG_MAX;
   else maxv[i]=2*pos_par;
  }
 }
 for(int i=n;i>=0;i--)
 {
  if (leaf[i]>maxv[i])
  {
   res=-1;
   break;
  }
  long long total_node=min(maxv[i],leaf[i]+par);
  res+=total_node;
  D(i,leaf[i],total_node,par,res);
  par=total_node;
 }
 cout << res << endl;
}
            
void solve_cases()
{
 int test_cases=1;
 //cin >> test_cases;
 for(int i=1;i<=test_cases;i++) solve(i);
}

void fast_io()
{
 ios::sync_with_stdio(false);
 srand(time(NULL));
 cin.tie(0);
 cout.tie(0);
 cout << fixed << setprecision(15);
 cerr << fixed << setprecision(15);
}

int main()
{
 fast_io();
 solve_cases();
 return EXIT_SUCCESS;
}



Measured memory_bytes: 4784
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;
#define START 0
#define FORWARD 1
#define BACK 2
using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;
bool comp(const pll &a, const pll &b) {
	return a.first < b.first;
}
//*********************************************************
// 最大公約数（Greatest Common Divisor）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
ll gcd(ll a, ll b)
{
	ll tmp, r;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
	//// 引数に０がある場合は０を返す
	//if ((0 == m) || (0 == n))
	//	return 0;

	//// ユークリッドの方法
	//while (m != n)
	//{
	//	if (m > n) m = m - n;
	//	else         n = n - m;
	//}
	//return m;
}//gcd
int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll x[100004] = {};
	ll y[100004] = {};
	ll z[100004] = {};
	ll x2[200][200] = { {} };
	string s;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	//cout << LLONG_MAX<< endl;

	cin >> s;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i]=='x')
		{
			ans++;
		}
	}
	if (ans>=8)
	{
		cout << "NO" << endl;

	}
	else
	{
		cout << "YES" << endl;

	}
	//cout << (a-2)*180 << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//sort(x, x + a, std::greater<ll>());

//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得
//
//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}
//
//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え


/*vector<pair<ll, ll> > hoges(a);
for (int i = 0; i < a; i++)
{
cin >> x[i];
cin >> y[i];
hoges[i] = make_pair(x[i], y[i]);
}
sort(hoges.begin(),hoges.end(),comp);
for (int i = 0; i < a; i++)
{
if (hoges[i].second>=b)
{
ans += hoges[i].first*b;
break;
}
else
{
ans += hoges[i].first*hoges[i].second;
b -= hoges[i].second;

}
}*/

Measured memory_bytes: 256
#include <iostream>
#include <algorithm> //min
typedef long long ll;

using namespace std;

int main() {

	ll L, R; //範囲がintを超える
	cin >> L >> R;

	//余りは最大でも2018
	int mod_min = 2018;

	//余りは2019周期でパターンが同じなのでRの範囲を縮める
	R = min(R, L + 2020);

	for (ll i = L; i < R; i++)
	{
		for (ll j = i + 1; j <= R; j++)
		{

			int mod = (i * j) % 2019;
			//cout << mod << "\n";

			mod_min = min(mod_min, mod);
			//if (mod < mod_min) {
			//	mod_min = mod;
			//}
		}
	}

	cout << mod_min << endl;

	return 0;
}

Measured memory_bytes: 256
c1 = list(map(int,input().split()))
c2 = list(map(int,input().split()))
c3 = list(map(int,input().split()))

a2_a1 = c2[0] - c1[0]
a3_a2 = c3[0] - c2[0]
a1_a3 = c1[0] - c3[0]

b2_b1 = c1[1] - c1[0]
b3_b2 = c1[2] - c1[1]
b1_b3 = c1[0] - c1[2]

if a2_a1 != c2[1] - c1[1] or a2_a1 != c2[2] - c1[2]:
    print("No")
elif a3_a2 != c3[1] - c2[1] or a3_a2 != c3[2] - c2[2]:
    print("No")
elif a1_a3 != c1[1] - c3[1] or a1_a3 != c1[2] - c3[2]:
    print("No")
elif b2_b1 != c2[1] - c2[0] or b2_b1 != c3[1] - c3[0]:
    print("No")
elif b3_b2 != c2[2] - c2[1] or b3_b2 != c3[2] - c3[1]:
    print("No")
elif b1_b3 != c2[0] - c2[2] or b1_b3 != c3[0] - c3[2]:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;

int main(){
    int n, k;
    cin >> n >> k;

    vector<int> h(n+1);
    for(int i=1; i<=n; i++){
        cin >> h[i];
    }

    vector<vector<long long int>> dp(n-k+1, vector<long long int>(n+1, INF));
    // dp[i][j] = min #(operations) with i columns, the last column = j
    dp[0][0] = 0;
    for(int i=1; i<=n-k; i++){
        for(int j=1; j<=n; j++){
            for(int l=0; l<j; l++){
                dp[i][j] = min(dp[i][j], dp[i-1][l] + max(0, h[j] - h[l]));
            }
        }
    }
    
    long long int ans = INF;
    for(int j=0; j<=n; j++){
        ans = min(ans, dp[n-k][j]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4324
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

int N;
int A[100010];
int ans[100010];

void _main() {
    cin >> N;
    REP(i, N) {
        cin >> A[i];
        ans[A[i] - 1] = i + 1;
    }
    REP(i, N) {
        cout << ans[i] << " \n"[i+1==N];
    }
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i'))
            freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o'))
            freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 2432
//arc070_c.cpp
//Fri Nov  2 22:42:16 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int x;
	cin >> x;

	int pos = 0;
	int jikoku = 1;
	while (pos < x){
		pos += jikoku;
		jikoku++;
	}


	cout << jikoku -1 << endl;

}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    int n = N;
    int SN = 0;
    while(n>0){
        SN += n%10;
        n /= 10;
    }

    if(N%SN == 0)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string s;
    cin >> s;
    string ans = "None";
    bool flag = true;
    char k;
    string l;
    for(k='a';k<='z';k++){
        l=k;
        for(int j=0;j<s.length();j++){
            if(l==s.substr(j,1)){
                break;
            }else if(j==s.length()-1){
                ans = l;
                flag = false;
                break;
            }
        }
        if(flag == false){
            break;
        }
    }
    cout << ans << endl;
}

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

using namespace std;
#define PI 3.14159265358979

int main(void)
{

int N;
int a;
int sum =0;
cin>>N;
vector<int> stick;

for(int i=0;i<N;i++)
{
    cin>>a;
    stick.push_back(a);
}
sort(stick.begin(),stick.end());

for(int i=0;i<N;i++)
{
  for(int j=0;j<i;j++)
  {
   int ab = stick[i]+stick[j];
   int r = lower_bound(stick.begin(),stick.end(),ab)-stick.begin();
   
   sum+=r-i-1;
  }

}




cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define lli long long int
#include<vector>
#include<algorithm>
int main(){
  lli n,k,ans=0,i;
  cin>>n>>k;
  vector<lli>v(n+1);
  for(i=1;i<=n;i++){
    cin>>v[i];
    ans+=v[i];
  }
  sort(v.begin()+1,v.end());
  for(i=1;i<=n-k+1;i++){
    ans=min(ans,v[i+k-1]-v[i]);
  }
  cout<<ans;
  return 0;
}

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

Measured memory_bytes: 21972
(* O(|s|) *)
let s = read_line () in
let flags = Array.make 128 false in
String.iter (fun c -> flags.(int_of_char c) <- true) s;
for i = int_of_char 'a' to int_of_char 'z' do
  if not flags.(i) then (Printf.printf "%c" @@ char_of_int i; exit 0)
done;
print_endline "None"

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double db;
typedef vector<ll> VI;
typedef vector<pair<ll,ll> > VII;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
//
#define M 1000000007
#define INF (ll)0x3f3f3f3f3f3f3f3f
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define itr iterator
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}

void error_out() { cerr << endl; }
template <typename Head, typename... Tail>
void error_out(Head H, Tail... T) {
  cerr << " " << H;
  error_out(T...);
}
void time_elapsed(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}
#ifndef ONLINE_JUDGE
#define error(...) cerr << "[" << #__VA_ARGS__ << "]:", error_out(__VA_ARGS__)
#define fioe() fileioe()
#define time() time_elapsed()
#else
#define error(...) 1
#define fioe() 1
#define time() 1
#endif
const int maxr=303;
double dp[maxr][maxr][maxr];
double ways(ll a,ll b,ll c,ll n){
	if(a<0||b<0||c<0){
		return 0;
	}
	if(a+b+c==0){
		return 0;
	}
	double & ans=dp[a][b][c];
	if(ans>-1){
		return ans;
	}
	ans=(((1.0)*n)/(a+b+c));
	ans+=(a*ways(a-1,b,c,n)+b*ways(a+1,b-1,c,n)+c*ways(a,b+1,c-1,n))/(a+b+c);
	return ans;
}
//
int main()
{
	GO
	//fioe();
	ll n;
	cin>>n;
	ll arr[3];
	memset(arr,0,sizeof(arr));
	for(ll i=0;i<n;i++){
		ll a;
		cin>>a;
		arr[a-1]++;
	}
	for(ll i=0;i<maxr;i++)for(ll j=0;j<maxr;j++)for(ll k=0;k<maxr;k++)dp[i][j][k]=-1;
	double ans=ways(arr[0],arr[1],arr[2],n);
	printf("%0.20f",ans);
	time();
	return 0;
}

Measured memory_bytes: 217600
#include<bits/stdc++.h>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

// PMAMP :)
// INL , IIWOIL

int main()
{
    jaldi
    int n;
    cin>>n;
    vector<int> v1(n),v2(n),v(n);
    for(int &x:v1) cin>>x;
    for(int &x:v2) cin>>x;
    for(int i=1;i<=n;i++) v[i-1]=i;
    int i=1;
    int a1,a2;
    do
    {
        if(v==v1) a1=i;
        if(v==v2) a2=i;
        i++;
    } while (next_permutation(v.begin(),v.end()));
    cout<<abs(a1-a2);
    return 0;
}

Measured memory_bytes: 256
// Problem : C - Sum of gcd of Tuples (Easy)
// Contest : AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"
#define lb "lower_bound"
#define ub "upper_bound"
#define bs "binary_search"

int dif(int a,int b){if(a > b)return a - b;else return b - a;}
int min(int a,int b){if(a > b)return b;else return a;}
int max(int a,int b){if(a > b)return a;else return b;}
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    ll n,sum = 0;
    cin>>n;
    for(int i = 1;i <= n;i++)
    {
    	for(int j = 1;j <= n;j++)
    	{
    		for(int k = 1;k <= n;k++)
    		{
    			sum += gcd(i,gcd(j,k));
    		}
    	}
    }
    cout<<sum;
	return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
#define MAX_N 50

void calcBinary(ll num, vll& v){
  //disance from 0
  num++;
  REP(i, 50){
    ll lambda = pow(2, i+1);
    ll f = num / lambda;
    v[i] = (f*lambda/2 + max(num%lambda,lambda/2)-lambda/2) % 2;
  }
}

ll binaryToInt(vll v){
  ll sum = 0;
  REP(i, 50)
    sum += pow(2, i)*v[i];
  
  return sum;
}

int main(){
  ll a,b;
  cin >> a >> b;
  
  vll aBinary(MAX_N, 0), bBinary(MAX_N, 0);
  calcBinary(a-1, aBinary);
  calcBinary(b, bBinary);
  
  ll fa = binaryToInt(aBinary);
  ll fb = binaryToInt(bBinary);
  ll ans = fb ^ fa;
  cout << ans << endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;



void solve() {
	int n; cin >> n;
	int k; cin >> k;
	int v[50]; rep(i, n) cin >> v[i];

	int ans = 0;
	for(int l = 0; l < n; l++) {
		for (int r = l; r <= n; r++) {
			vector<int> have;
			for (int i = 0; i < n; i++) {
				if (i < l || r <= i) have.push_back(v[i]);
			}
			sort(have.begin(), have.end());
			int e = 0;
			int picknum = k - have.size();
			if (picknum < 0) continue;
			for (int i = 0; i < have.size(); i++) {
				if (have[i] < 0 && i < picknum) continue;
				e += have[i];
			}
			ans = max(ans, e);
		}
	}

	cout << ans << endl;
}

int main() {

	solve();

	return 0;
}


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

#define N 200000

int n;
string x;
int remainderDP[3][N], remainderX[3];

int calcRemainder(int k, int num1){
    if(num1<=0){
        return 1;
    }
    remainderDP[k][n-1] = 1 % num1;
    if (x[n-1]=='1'){
        remainderX[k] = remainderDP[k][n-1];
    }
    for (int i = 1; i < n; i++){
        remainderDP[k][n-1-i] = (remainderDP[k][n-i]*2) % num1;
        if (x[n-1-i]=='1'){
            remainderX[k] = (remainderX[k] + remainderDP[k][n-1-i]) % num1;
        }
    }
    return 0;
}

int popcount(){
    int cnt = 0;
    for(int i = 0; i < x.size() ; i++){
        if (x[i]=='1'){
            cnt++;
        }
    }
    return cnt;
}

int main(void){
    cin >> n; 
    cin >> x;
    
    int numOneX = popcount();
    for (int i = 0; i <= 2 ; i++){
        calcRemainder(i, numOneX-1+i); 
    }
    for (int i = 0; i < n; i++){
        int cnt = 0, remainderXi;
        if(x[i] == '1'){
            if (numOneX-1==0){
                cout << 0 << endl;
                continue;
            }
            remainderXi = (remainderX[0] - remainderDP[0][i] + numOneX-1) % (numOneX-1); 
        }
        else{
            remainderXi = (remainderX[2] + remainderDP[2][i]) % (numOneX+1); 
        }
        cnt++;

        while (remainderXi != 0){
            int remainderTmp = remainderXi;
            int numOne2 = 0;
            while(remainderTmp != 0){
                numOne2 += remainderTmp&1;
                remainderTmp = remainderTmp>>1;
            }
            remainderXi = remainderXi % numOne2;
            cnt++;
        }
        
        cout << cnt << endl;
    }

    return 0;
}


Measured memory_bytes: 6044
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        if(t.substring(0, s.length()).equals(s) && t.length()-1==s.length()){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}


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

int main() {
    int X, ans;
    cin >> X;
    while (true) {
        bool yes = true;
        for (int i = 2; i * i <= X; ++i) {
            if (X % i == 0) {
                yes = false;
                break;
            }
        }
        if (yes) {
            ans = X;
            break;
        }
        X++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#define Max 200000
#define Mod 998244353
using namespace std;

long long ans = 1;
int N;
int D[Max], a[Max];




int main()
{
	
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> D[i];
		a[D[i]]++;
	}
	if (D[1] != 0)
		ans = 0;
	for (int j = 2; j <= N; j++)
	{
		ans = ((ans)%Mod * (a[D[j] - 1] % Mod)) % Mod;
	}

	cout << ans%Mod;
}



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

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        double g[n][n];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cin >> g[i][j];
            }
        }
        double dp[101][100] = {};
        for(int i = 0; i < n; i++)  dp[0][i] = 1.0;
        for(int i = 0; i < m; i++){
            for(int j = 0; j < n; j++){
                for(int k = 0; k < n; k++){
                    dp[i+1][k] = max(dp[i+1][k], dp[i][j]*g[j][k]);
                }
            }
        }
        double ans = 0;
        for(int i = 0; i < n; i++)  ans = max(ans, dp[m-1][i]);
        ans = round(ans*100);
        printf("%.2f\n", ans/100);
    }
    return 0;
}


Measured memory_bytes: 3504
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{
	lli n,k,m,t;
	cin>>n>>k;
	m=n/(k);
	t=n-(m*k);
	n=t;
	if(n==0)
	{
		cout<<0;
		return 0;
	}
	if(n<(k-n))
	cout<<n;
	else
		cout<<k-n;
	

  return 0;
}
  
    

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<cstdlib>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;
typedef pair<int,int> P;

string ans;

void ps(int n,char a){
    for(int i=0;i<n;i++) ans+=a;
    return;
}

int sumd(int n){
    int res=0;
    while(n>0){
        res=n%10;
        n/=10;
    }
    return res;
}

int F(ll a,ll b){
    string s,t;
    s=to_string(a);
    t=to_string(b);
    return max(s.size(),t.size());
}

double dis(int x1,int y1,int x2,int y2){
    int s=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    return pow(s,0.5);
}
int main(){
  string s;cin>>s;
  int a[4];
  rep(i,0,4){
    a[i]=(int)(s[i]-'0');
  }
    char op[3];
    for(int bits=0;bits<(1<<3);bits++){
        for(int i=0;i<3;i++){
            if((bits>>i)&1) op[i]='+';
            else op[i]='-';
        }
        int res=a[0];
        rep(i,0,3){
            if(op[i]=='+') res+=a[i+1];
            else res-=a[i+1];
        }
        if(res==7){
            cout<<a[0]<<op[0]<<a[1]<<op[1]<<a[2]<<op[2]<<a[3]<<"=7"<<endl;
            return 0;
        }
    }
}    

Measured memory_bytes: 888
import math
a = [int(input()) for _ in range(5)]
s = 0
m = 10
for i in range(5):
  s += math.ceil(a[i] / 10) * 10
  if a[i] % 10 > 0 and a[i] % 10 < m:
    m = a[i] % 10
print(s-(10-m))


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<cmath>
#include<climits>
using namespace std;

int func(vector<int> &v,int i,int n,int k,vector<int> &memo)
{
    if(i>=n)
        return 0;

    if(i==n-1)
        return 0;

    if(memo[i] == -1)
    {
        int minimum = INT_MAX;
        for(int j = i+1;j<=i+k;j++)
        {
            if(j < n)
            {
            int n1 = abs(v[i] - v[j]) + func(v,j,n,k,memo);
            minimum = min(minimum,n1);
            }
        }

        memo[i] = minimum;
    }
    return memo[i];
    
}

int main()
{
    int n{},k{};
    cin>>n>>k;
    vector<int> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    
    vector<int> memo(n,-1);
    cout<<func(v,0,n,k,memo);
    return 0;
}

Measured memory_bytes: 10368
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;


int main(){
  int r, g;
  cin >> r >> g;
  cout << 2*g - r << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
constexpr ll TEN(ll n){return n==0?1:10ll*TEN(n-1);}

constexpr ll inf = TEN(9)+5;
constexpr ll linf = 3*TEN(18);

signed main()
{
    int N; cin >> N;
    string S; cin >> S;
    ll r = 0, g = 0, b = 0;
    rep(i, N) {
        if (S[i] == 'R') r++;
        if (S[i] == 'G') g++;
        if (S[i] == 'B') b++;
    }

    ll s = r*g*b;

    rep1(d, N) {
        rep(start, N) {
            if (start - d < 0 or start + d >= N) continue;

            if ((S[start - d] != S[start]) and (S[start] != S[start + d]) and (S[start - d] != S[start + d])) s--;
        }
    }

    cout << s << endl;
}


Measured memory_bytes: 3608
//
// Created by yamunaku on 2019/10/22.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n, m;
    cin >> n >> m;
    map<int,int> mp;
    vi l(n),r(n);
    rep(i,n){
        cin >> l[i] >> r[i];
        mp[l[i]]=mp[r[i]]=mp[r[i]+1]=0;
    }
    vi inv;
    int sz = 0;
    for(auto &p: mp) p.second = sz++, inv.push_back(p.first);
    vl rui(sz,0);
    rep(i,n){
        rui[mp[l[i]]]++;
        rui[mp[r[i]+1]]--;
    }
    ll ans = rui[0];
    repl(i,1,sz){
        rui[i]+=rui[i-1];
        ans = max(ans, rui[i]);
    }
    if(ans%2){
        per(i,sz){
            if(rui[i]==ans){
                cout << (ans-1)*m+inv[i] << endl;
                return 0;
            }
        }
    }else{
        rep(i,sz){
            if(rui[i]==ans){
                cout << (ans-1)*m+m-inv[i] << endl;
                return 0;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 39560
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
map<ll,ll>zip;
ll unzip[555555];
ll imos[555555];
vi to[555555];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,L;
  cin>>n>>L;
  vector<pair<ll,ll>>pll(n);
  set<ll>se;
  for(int i=0;i<n;i++){
    cin>>pll[i].F>>pll[i].S;
    se.insert(pll[i].F);
    se.insert(pll[i].S);
  }
  ll cnt=0;
  for(auto a:se){
    zip[a] = cnt;
    unzip[cnt] = a;
    cnt++;
  }
  for(int i=0;i<n;i++){
    to[zip[pll[i].F]].pb(zip[pll[i].S]);
    imos[zip[pll[i].F]]++;
    imos[zip[pll[i].S]]--;
    //cout<<zip[pll[i].F]<<" "<<zip[pll[i].S]<<endl;
  }
  for(int i=0;i<555000;i++)
    imos[i+1]+=imos[i];
  ll mi=llINF;
  for(int i=0;i<cnt-1;i++){
    mi=min(imos[i],mi);
  }
  ll ans=0;
  priority_queue<ll>que;
  /*  for(int i=0;i<to[0].size();i++)
      que.push(to[0][i]);*/
  que.push(0);
  ll now=-1;
  while(now<cnt-1){
    ll num=que.top();
    que.pop();
    // cout<<now<<" "<<num<<endl;
    for(int i=now+1;i<=num;i++){
      for(auto a:to[i])
	que.push(a);
    }
    now=num;
    ans++;
  }

  cout<<ans-1<<" "<<n-mi+1<<endl;
  return 0;
}



Measured memory_bytes: 76588