akhauriyash/Code-Regression huggingface dataset:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
A = LIST()
A.sort()
plus = 0
minus = 0
zero = 0
plus_lis = []
minus_lis = []

for n in A:
	if n == 0:
		zero += 1
	elif n > 0:
		plus += 1
		plus_lis.append(n)
	else:
		minus += 1
		minus_lis.append(n)

plus, minus, zero = plus*(plus-1)//2+minus*(minus-1)//2, plus*minus, plus*zero+minus*zero+zero*(zero-1)//2

if K <= minus:  # 答えは負
	l = -10**18-1
	r = 0

	def count(x):  # xより小さいペアの数を返す
		total = 0
		idx = 0
		for i in range(len(plus_lis)):
			while idx < len(minus_lis):
				if plus_lis[i] * minus_lis[idx] < x:
					idx += 1
				else:
					total += idx
					break
			else:
				total += idx

		return total

	while l+1 != r:
		m = (l+r)//2
		if count(m) >= K:
			r = m
		else:
			l = m
	print(l)

elif minus <= K <= minus+zero:
	print(0)

else:  # 答えは正
	l = 0
	r = 10**18+1

	def count(x):  # xより小さいペアの数を返す
		total = minus+zero
		tmp = 0
		idx = 0

		### プラスとマイナスを別々に数え上げる
		for i in range(len(plus_lis))[::-1]:
			while idx < len(plus_lis):
				if plus_lis[i] * plus_lis[idx] < x:
					idx += 1
				else:
					tmp += idx
					break
			else:
				tmp += idx
			if plus_lis[i] * plus_lis[i] < x: tmp -= 1  # 重複してる分引く
		tmp //= 2
		total += tmp
		tmp = 0
		idx = 0 
		for i in range(len(minus_lis)):
			while idx < len(minus_lis):
				if minus_lis[i] * minus_lis[-idx-1] < x:
					idx += 1
				else:
					tmp += idx
					break
			else:
				tmp += idx
			if minus_lis[i] * minus_lis[i] < x: tmp -= 1
		tmp //= 2
		total += tmp

		return total

	while l+1 != r:
		m = (l+r)//2
		if count(m) >= K:
			r = m
		else:
			l = m
	print(l)


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];

    vector<int> per(N);
    rep(i, N) per[i] = i + 1;
    int s, e;
    int num = 0;
    do
    {
        num++;
        bool ok1 = true, ok2 = true;
        rep(i, N)
        {
            if(P[i]!=per[i]){
                ok1 = false;
            }
            if (Q[i] != per[i])
            {
                ok2 = false;
            }
        }
        if(ok1){
            s = num;
        }
        if(ok2){
            e = num;
        }
    } while (next_permutation(all(per)));
    
    cout << abs(s-e) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<string> vs;
Def inf = sizeof(Def) == sizeof(ll) ? 2e15:1e9+10;

#include<complex>
typedef complex<double> P;
typedef vector<P> G;
const double PI=acos(-1);
const double EPS=1e-7;

struct L: public vector<P> {
	L(const P &a,const P &b){
		push_back(a);push_back(b);
	}
};
struct C{
	P c;double r;
	C(const P &c,double r):c(c),r(r){}
};
namespace std{
	bool operator < (const P &a, const P &b){
		return real(a) != real(b) ? real(a)<real(b) :imag(a)<imag(b);
	}
	bool operator == (const P &a, const P &b){
		return a.real() == b.real() && a.imag() == b.imag();
	}
}


double dot(P a,P b){
	return real(conj(a)*b);
}

P projection(L a, P p){
	double t=dot(p-a[0],a[0]-a[1])/norm(a[0]-a[1]);
	return a[0]+t*(a[0]-a[1]);
}

double distanceLP(const L &l, const P &p){
	return abs(p-projection(l,p));
}


P turn(P p,double t){
	return p*exp(P(.0,t*PI/180.0));
}

vector<L> tangentCC(C a, C b){
	if(a.r<b.r)swap(a,b);
	double d=abs(a.c-b.c);
	vector<L> l;
	if(d<EPS)return l;
	if(a.r+b.r<d-EPS){
		double t=acos((a.r+b.r)/d);
		t=t*180/PI;
		l.pb(L(a.c+turn(a.r/d*(b.c-a.c),t),b.c+turn(b.r/d*(a.c-b.c),t)));
		l.pb(L(a.c+turn(a.r/d*(b.c-a.c),-t),b.c+turn(b.r/d*(a.c-b.c),-t)));
	}else if(a.r+b.r<d+EPS){
		P p=a.c+a.r/d*(b.c-a.c);
		l.pb(L(p,p+turn(b.c-a.c,90)));
	}
	
	if(abs(a.r-b.r)<d-EPS){
		double t1=acos((a.r-b.r)/d);
		t1=t1*180/PI;
		double t2=180-t1;
		l.pb(L(a.c+turn(a.r/d*(b.c-a.c),t1),b.c+turn(b.r/d*(a.c-b.c),-t2)));
		l.pb(L(a.c+turn(a.r/d*(b.c-a.c),-t1),b.c+turn(b.r/d*(a.c-b.c),t2)));	
	}else if(abs(a.r-b.r)<d+EPS){
		P p=a.c+a.r/d*(b.c-a.c);
		l.pb(L(p,p+turn(b.c-a.c,90)));
	}
	return l;
}

int main(){
	int n,m;
	while(cin>>n>>m,n){
		vvi L(n,vi(n,inf));
		vvi S(n,vi(n,inf));
		rep(i,n)L[i][i]=S[i][i]=0;
		rep(i,m){
			ll a,b,c;char d;
			cin>>a>>b>>c>>d;
			a--;b--;
			if(d=='L')L[a][b]=L[b][a]=min(L[a][b],c);
			if(d=='S')S[a][b]=S[b][a]=min(S[a][b],c);
		}
		rep(k,n)rep(i,n)rep(j,n){
			L[i][j]=min(L[i][j],L[i][k]+L[k][j]);
			S[i][j]=min(S[i][j],S[i][k]+S[k][j]);
		}
		int R;cin>>R;
		vi r(R);
		rep(i,R)cin>>r[i];
		rep(i,R)r[i]--;
		vvi dp(R,vi(n,inf));
		dp[0][r[0]]=0;
		rep(i,R-1)rep(j,n){
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]+L[r[i]][r[i+1]]);
			rep(k,n){
				dp[i+1][k]=min(dp[i+1][k],dp[i][j]+L[r[i]][j]+S[j][k]+L[k][r[i+1]]);
			}
		}
//		rep(i,R){rep(j,n)cout<<" "<<dp[i][j];cout<<endl;}
		ll out=inf;
		rep(i,n)out=min(out,dp[R-1][i]);
		cout<<out<<endl;
	}
}







Measured memory_bytes: 5236
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
 
struct UnionFind{
    int n;
    vi p,r;
    UnionFind(int N):n(N){
        p.resize(n);
    	iota(all(p),0);
        r.resize(n);
        fill(all(r),0);
    }
    void unite(int a, int b){
        int c=root(a),d=root(b); 
        if(c!=d) {
            if(r[c]<r[d]){
                p[c]=d;
            }else{
                p[d]=c;
                if(r[c]==r[d])r[c]++;
            }
        }
    }
    int root(int a){return p[a]=(p[a]==a?a:root(p[a]));}
    bool same(int a, int b){return root(a)==root(b);}
};

int main(){
	int n,m;
	cin>>n>>m;
	vector<set<int>> s(m+1);
	rep(i,n){
	    int p;cin>>p;
	    rep(j,p){
	        int q;cin>>q;
	        s[q].insert(i+1);
	    }
	}

	UnionFind u(n+1);
	rep(i,m+1){
	    auto t=s[i];
	    if(t.size()<2)continue;
	    auto eitr=t.end();
	    eitr--;
	    for(auto itr=t.begin();itr!=(--t.end());){
	        u.unite(*++itr,*itr);
	    }
	    //range(j,1,n+1){cout<<u.p[j];}cout<<endl;
	}
	bool ans=true;
	range(i,2,n+1) {
	    ans&=u.same(1,i);
    }
    cout<<(ans?"YES":"NO")<<endl;
	return 0;
}


Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <set>
#include <math.h>
#define pai acos(-1)
#define keta(n) cout << fixed << setprecision((n))
#define ll long long
int main()
{
  int a,b;
  cin>>a>>b;
  if((a*b)%2==0)cout<<"No";
  else cout<<"Yes";

}



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

int main(){
    ll a,b;
    cin>>a>>b;
    if(a<=9 and b<=9){
        cout<<a*b<<endl;
    }else{
        cout<<-1<<endl;
    }
}

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



int main(){
  string s;
  std::cin >> s;
  int q;
  std::cin >> q;

  deque<char>s2;
  rep(i,s.size()){
    s2.push_back(s[i]);
  }

  int dir=1;
  rep(i,q){
    int t;
    std::cin >> t;
    if(t==1){
      dir=(dir+1)%2;
    }
    else{
      int f;char c;
      std::cin >> f>>c;
      if((dir==1 && f==1 )|| (dir==0 && f==2)){
        s2.push_front(c);
      }
      else {
        s2.push_back(c);
      }
    }
  }

  if(dir==1){
    while (!s2.empty()) {
      std::cout << s2.front();
      s2.pop_front();
    }
  }else {
    while (!s2.empty()) {
      std::cout << s2.back();
      s2.pop_back();
    }
  }
  std::cout << "" << '\n';




  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
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;
}

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

signed main(){
    int n,x;cin>>n>>x;
    if(abs(n-x)>n-2){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    if(n-x==0){
        REPS(i,2*n-1)cout<<i<<endl;
    }
    if(n-x<=-1){
        REPS(i,2*n-1-(x-n))cout<<i+x-n<<endl;
        REPS(i,x-n)cout<<i<<endl;
    }
    if(n-x>=1){
        REPS(i,n-x)cout<<2*n-1-(n-x)+i<<endl;
        REPS(i,2*n-1-(n-x))cout<<i<<endl;
    }
}

Measured memory_bytes: 1536
/*
...........__________                                                                           ___  __
.............|       |                                                                           |   /
.............|       |                                                                           |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
...........__|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
void read_And_write(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

void raushan_kumar(){
    int d=0,e=0,f=0,g=0,p=0,w=0,flag=0,ans=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    string s;cin>>s;
    set<char> set;
    fo0(i,s.length()){
    	set.insert(s[i]);
    }
    if(set.find('N')!=set.end() and set.find('S')==set.end()){
    	cout<<"No";
    }
    else if(set.find('E')!=set.end() and set.find('W')==set.end()){
    	cout<<"No";
    }
    else if(set.find('S')!=set.end() and set.find('N')==set.end()){
    	cout<<"No";
    }
    else if(set.find('W')!=set.end() and set.find('E')==set.end()){
    	cout<<"No";
    }
    else
    	cout<<"Yes";
}

int32_t main()
{
   fast;int t=1;
    // cin>>t;
    while(t--){raushan_kumar();}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define SZ(a) ((int)(a.size()))

int n;
int dn;
int d[1000];

vector<vector<int> > ans;

int len[22];

void dfs(int ne){
  if(ne == n){
    vector<int> ap;
    rep(j, n) ap.pb(len[j]);
    sort(ALL(ap));
    ans.pb(ap);
    return;
  }
  
  for(int j = 410; j >= 0; --j){
    if(!d[j]) continue;
    
    len[ne] = j;
    bool ok;
    ok = true;
    rep(k, ne){
      ok &= --d[abs(j - len[k])] >= 0;
    }
    if(ok) dfs(ne + 1);
    rep(k, ne){
      ++d[abs(j - len[k])];
    }    
    
    
    len[ne] = len[1] - j;
    ok = true;
    rep(k, ne){
      ok &= --d[abs(len[ne] - len[k])] >= 0;
    }
    if(ok) dfs(ne + 1);
    rep(k, ne){
      ++d[abs(len[ne] - len[k])];
    }    
    
    break;
  }
}

void solve(){
  dn = n * (n - 1) / 2;
  memset(d, 0, sizeof(d));
  int p = 0;
  rep(i, dn){
    int t;
    cin >> t;
    ++d[t];
    p = max(p, t);
  }
  ans.clear();
  len[0] = 0;
  len[1] = p;
  --d[p];
  dfs(2);
  //cout << SZ(ans) << endl;
  sort(ALL(ans));

  ans.erase(unique(ALL(ans)),ans.end());
  
  for(const auto& e : ans){
    rep(i, n - 1){
      if(i) cout << ' ';
      cout << e[i+1] - e[i];
    }
    cout << endl;
  }
  
  cout << "-----" << endl;
}

int main(int argc, char *argv[])
{
  while(cin >> n && n) solve();
  return 0;
}

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

int main()
{
  int N;
  string S[100];
  int P[100];
  int num[100];
  int i;
  int k;
  int tmpn;
  string tmps;

  cin >> N;
  for (i=0;i<N;i++){
    cin >> S[i];
    cin >> P[i];
    num[i] = i+1;
  }

  for (i=0;i<N-1;i++){
    for (k=N-1;k>i;k--){
      if (S[k] < S[k-1]){
        tmps = S[k];
        S[k] = S[k-1];
        S[k-1] = tmps;
        tmpn = P[k];
        P[k] = P[k-1];
        P[k-1] = tmpn;
        tmpn = num[k];
        num[k] = num[k-1];
        num[k-1] = tmpn;
      }
      if (S[k] == S[k-1] && P[k] > P[k-1]){
        tmps = S[k];
        S[k] = S[k-1];
        S[k-1] = tmps;
        tmpn = P[k];
        P[k] = P[k-1];
        P[k-1] = tmpn;
        tmpn = num[k];
        num[k] = num[k-1];
        num[k-1] = tmpn;
      }
    }
  }

  for (i=0;i<N;i++){
    cout << num[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<62;
const double eps=1e-5;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	int n,k;cin>>n>>k;
	if(n/2+n%2>=k){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define REP(i,a,b) for(int i=a; i<=b; i++)
using namespace std;

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

const int LIM = 2000111;
int y[LIM]={0};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,a;
    cin >> n;
    vector<int> x(n);
    int mx=0;
    for(int i=0; i<n; i++){
        cin >> x[i];
        mx=max(mx,x[i]);
        y[x[i]]++;
    }
    int ans = 0;
    sort(x.begin(),x.end());
    for(int i=0; i<n; i++){
        if(y[x[i]]==1){
            //cout << x[i] << " ";
            ans++;
        }
        for(int j=x[i]*2; j<=mx; j+=x[i]) y[j]++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 7796
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>

#define st first
#define nd second

using namespace std;
using ll = long long;
using ld = long double;

const int MAXN = 1e6+5, inf = 1e9;
const ll INF = 1e18;

constexpr int mod = 1e9+7;
constexpr ll MOD = 1e9+7;

ll tab[MAXN];
set<int> S;
map<int, int> M;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    /////////////////////////////
    ll a, b;
    cin >> a >> b;
    cout << ((a * b) & 1 ? "Odd" : "Even") << "\n";

}


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

string transportStr( string s )
{
    string res = "";
    res += s[0];

    for( int i = 1; i < s.size(); i++ )
        if( s[i-1] == 'a' || s[i-1] == 'i' || s[i-1] == 'u' || s[i-1] == 'e' || s[i-1] == 'o' )
            res += s[i];
    return res;
}

int main()
{
    int n;
    string s;

    while( cin >> n )
    {
        if( !n )
            break;

        string m[n];

        int min = 10000;
        for( int i = 0; i < n; i++ )
        {
            cin >> s;
            m[i] = transportStr( s );
            if( min > m[i].size() )
                min = m[i].size();
        }

        int k = 0;
        bool judge = true;
        while( judge && k <= 50 )
        {
            k++;
            judge = false;
            for( int i = 0; i < n - 1; i++ )
                for( int j = i + 1; j < n; j++ )
                    if( m[i].substr( 0, k ) == m[j].substr( 0, k ) )
                        judge = true;
        }
        if( k == 51 )
            cout << -1 << endl;
        else
            cout << k << endl;
    }
    return 0;
}



Measured memory_bytes: 3232
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>

#include <numeric>

#include <map>

using namespace std;

typedef long long LL;

int n;

map<string, int> m;
int mm;

int main() {

   cin >> n;
   for (int i = 1; i <= n; ++i) {
       string str;
       cin >> str;
       m[str] += 1;
       mm = max(mm, m[str]);
   }

   for (auto it = m.begin(); it != m.end(); ++it) {
       if (it->second == mm) {
           cout << it->first << endl;
       }
   }
    
}

Measured memory_bytes: 25856
#include <bits/stdc++.h>
using namespace std;
int a[25];
long long calc()
{
	//cout<<"{"<<endl;
	long long ans=0;
	long long lst=0;
	for(int i=0;a[i]!=-3;i++)
	{
		if(a[i]==-1);
		else if(a[i]==-2)
		{
			ans+=lst;
			lst=0;
		}
		else
			lst=lst*10+a[i];
	}
	ans+=lst;
	//cout<<"}"<<endl;
	return ans;
}
long long dfs(int i)
{
	//cout<<i<<endl;
	if(a[i]==-3)
		return calc();
	long long ans=0;
	a[i+1]=-1;
	ans+=dfs(i+2);
	a[i+1]=-2;
	ans+=dfs(i+2);
	return ans;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	string s;
	cin>>s;
	for(int i=0;i<(int)s.size();i++)
		a[i*2]=s[i]-'0';
	a[s.size()*2-1]=-3;
	a[s.size()*2]=-3;
	cout<<dfs(0)/2<<endl;
	//for(int i=0;a[i]!=-3;i++)
	//	cout<<a[i]<<' ';
	//cout<<endl;
}

Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from itertools import combinations_with_replacement
def resolve():
    n, m, q = map(int, input().split())
    ABCD = [tuple(map(int, input().split())) for _ in range(q)]
    ans = 0
    for I in combinations_with_replacement(range(m), n):
        score = 0
        for a, b, c, d in ABCD:
            if I[b - 1] - I[a - 1] == c:
                score += d
        ans = max(ans, score)
    print(ans)
resolve()

Measured memory_bytes: 67828
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, Q;
        public string S;
        public int[] K;
        public long MOD = 1000000007;

        public void Run()
        {
            N = Input.ReadInt();
            S = Console.ReadLine();
            Q = Input.ReadInt();
            K = Input.ReadIntArray();

            for (int q = 0; q < Q; q++)
            {
                long r = 0;
                int k = K[q];

                long d = 0;
                long dm = 0;
                long m = 0;

                for (int i = 0; i < N; i++)
                {
                    {
                        if (S[i] == 'D')
                        {
                            d++;
                        }

                        if (S[i] == 'M')
                        {
                            m++;
                            dm += d;
                        }

                        if (S[i] == 'C')
                        {
                            r += dm;
                        }
                    }

                    if (i >= k - 1)
                    {
                        if (S[i - k + 1] == 'D')
                        {
                            d--;
                            dm -= m;
                        }

                        if (S[i - k + 1] == 'M')
                        {
                            m--;
                        }
                    }
                }
                Console.WriteLine(r);
            }
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

int		main(void)
{
	int	X, A, B;	cin >> X >> A >> B;
	if (A < B)
		cout << (X < B - A ? "dangerous" : "safe") << endl;
	else
		cout << "delicious" << endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<int>l(n);
	for (int i = 0; i < n; i++)cin >> l.at(i);
	sort(l.begin(), l.end());
	ll sum = 0;
	for (int i = 0; i < n - 1; i++)sum += l.at(i);
	if (sum > l.at(n - 1))cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
"""
双方向連結リスト
どっちからでもつけられるよ
"""
from collections import deque
d = deque([])
n = int(input())
for _ in range(n):
    
    com = input()
    if com == "deleteFirst" and len(d)>0:
        d.popleft()
    elif com == "deleteLast" and len(d)>0:
        d.pop()
    elif com != "deleteFirst" and com != "deleteLast":
        com, num = com.split(" ")
        if com == "insert":
            d.appendleft(int(num))
        elif com == "delete":
            try:
                d.remove(int(num))
            except:
                continue
    
ans = " ".join([str(s) for s in list(d)])
print(ans)





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

using namespace std;

struct restaurant
{
  int number;
  string place;
  int point;
};

int main(void)
{
  int N;
  struct restaurant restaurant[100];
  struct restaurant *smallest;
  struct restaurant remain;
  cin >> N;
  for(int i = 0; i < N; i++)
  {
    restaurant[i].number = i + 1;
    cin >> restaurant[i].place >> restaurant[i].point;
  }
  for(int i = 0; i < N - 1; i++)
  {
    smallest = &restaurant[i];
    for(int j = i + 1; j < N; j++)
      if(smallest->place > restaurant[j].place)
        smallest = &restaurant[j];
      else if((smallest->place == restaurant[j].place) && (smallest->point < restaurant[j].point))
        smallest = &restaurant[j];
    remain = restaurant[i];
    restaurant[i] = *smallest;
    *smallest = remain;
  }
  for(int i = 0; i < N; i++)
    cout << restaurant[i].number << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 405
using namespace std;
 
typedef long long ll;
typedef pair < int , int > ii;
 
int n, m, k, say;
char a[N][N];
int ans[N][N];
vector < char > x;
 
void coz(){
	scanf("%d %d %d",&n ,&m ,&k);
	say = 0;
	for(int i = 1; i <= n; i++)
		scanf("%s",a[i] + 1);



	for(int i = 1; i <= n; i++){

		int kac = 0;
		for(int j = 1; j <= m; j++)
			if(a[i][j] == '#')
				kac++;
		if(!kac)
			continue;

		say++;
		int su = say;

		for(int j = 1; j <= m; j++){
			ans[i][j] = say;
			if(say < su + kac - 1 and a[i][j] == '#')
				say++;
		}
	}

	for(int i = n; i >= 1; i--)
		for(int j = 1; j <= m; j++)
			if(ans[i][j] == 0)
				ans[i][j] = ans[i + 1][j];

	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			if(ans[i][j] == 0)
				ans[i][j] = ans[i - 1][j];

	for(int i = 1; i <= n; i++, puts(""))
		for(int j = 1; j <= m; j++)
			printf("%d ", ans[i][j]);
 
}
 
int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	// for(char i = 'a'; i <= 'z'; i++)x.pb(i);
	// for(char i = 'A'; i <= 'Z'; i++)x.pb(i);
	// for(char i = '0'; i <= '9'; i++)x.pb(i);
		coz();
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#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 fcout cout << fixed << setprecision(10)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;


int N;
VI c;
int dp[100010];


signed main(){
    cin >> N;

    repif(i, 1, POW(6, i) <= N) c.pb(POW(6, i));
    repif(i, 1, POW(9, i) <= N) c.pb(POW(9, i));
    c.pb(1);
    sort(ALL(c));

    fill(RNG(dp, 0, 100010), INF);

    dp[0] = 0;
    repe(i, 0, N){
        rep(j, 0, SIZE(c)){
            if(N < i+c[j]) break;
            chmin(dp[i+c[j]], dp[i]+1);
        }
    }

    cout << dp[N] << endl;

    return 0;
}

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

const ll mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with "n" of "nCk" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }

    // nPk - permutation
    mint p(int n, int k) {
        return fact[n] * ifact[n - k];
    }
};

int main() {
    ll n, k;
    cin >> n >> k;
    combination nck(100100);
    vector<mint> dp(k + 1);
    for (ll i = 1; i <= k; i++) {
        dp[i] = mint(k / i).pow(n);
    }
    mint ans;
    vector<mint> exact(k + 1);
    for (ll i = k; i > 0; i--) {
        exact[i] = dp[i];
        for (ll g = i * 2; g <= k; g += i) {
            exact[i] -= exact[g];
        }
        ans += mint(i) * exact[i];
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 6348
# https://atcoder.jp/contests/abc127/submissions/5606400

from functools import reduce


def mod_mul(a, b):
    return (a * b) % MOD


def cmb(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    if r == 1:
        return n

    f = reduce(mod_mul, range(n - r + 1, n + 1))  # n!/(n-r)!
    d = reduce(mod_mul, range(2, r + 1))  # r!
    return (f * pow(d, MOD - 2, MOD)) % MOD


MOD = 10 ** 9 + 7

N, M, K = map(int, input().split())

ans_x = 0
for i in range(M):
    ans_x += i * (M - i)
ans_x *= N ** 2

ans_y = 0
for i in range(N):
    ans_y += i * (N - i)
ans_y *= M ** 2

ans = ans_x + ans_y

pat = cmb(N * M - 2, K - 2)
ans = (ans * pat) % MOD

print(ans)


Measured memory_bytes: 3828
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

using lint = long long;
#define rep(i, n) for(lint i = 0; i < lint(n); i++)
#define repu(i, a, b, s) for(lint i = lint(a); i < lint(b); i += lint(s))
#define repd(i, a, b, s) for(lint i = lint(a); i > lint(b); i += lint(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

void solve() {
    lint N, D;
    cin >> N >> D;
    two_sat ts(N);

    vector<lint> x(N), y(N);
    rep(i, N) { cin >> x[i] >> y[i]; }

    rep(i, N) {
        repu(j, i + 1, N, 1) {
            if(abs(x[i] - x[j]) < D) {
                ts.add_clause(i, false, j, false);
            }
            if(abs(x[i] - y[j]) < D) {
                ts.add_clause(i, false, j, true);
            }
            if(abs(y[i] - x[j]) < D) {
                ts.add_clause(i, true, j, false);
            }
            if(abs(y[i] - y[j]) < D) {
                ts.add_clause(i, true, j, true);
            }
        }
    }

    if(!ts.satisfiable()) {
        cout << "No" << endl;
        exit(0);
    }

    cout << "Yes" << endl;
    auto ans = ts.answer();
    rep(i, N) {
        if(ans[i]) {
            cout << x[i] << endl;
        } else {
            cout << y[i] << endl;
        }
    }
}

int main(int argc, char *argv[]) {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}

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

using namespace std;

int main(){
	int n; cin >> n;
	vector <int> v(n), ans(n);
	for(int i = 0;i < n;i++){
		cin >> v[i];
		ans[i] = v[i];
	}
	sort(ans.begin(), ans.end());
	if(v == ans){
		cout << "YES";
		return 0;
	}
	for(int i = 0;i < n;i++){
		for(int j = i + 1;j < n;j++){
			swap(v[i], v[j]);
			if(v == ans){
				cout << "YES";
				return 0;
			} else {
				swap(v[i], v[j]);
			}
		}
	}
	cout << "NO";
	return 0;
}


Measured memory_bytes: 256
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> A;

 A = A - 400;
  return 8 - A / 200;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}


Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int check(int x) {
	if (x == 2) {
		return 3;
	}
	if (x == 4 || x == 6 || x == 9 || x == 11) {
		return 2;
	}
	return 1;
}

int main(void) {
	int x,y;
	cin >> x >> y;
	if (check(x) == check(y)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 505;

int N, a[maxn][maxn];
int h[maxn][maxn];
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};

void dfs(int i, int j)
{
  int v = h[i][j] + a[i][j];
  auto ins = [&](int i, int j)
  {
    return 1 <= i && i <= N && 1 <= j && j <= N;
  };
  for(int t = 0; t < 4; ++t){
    int x = i + dx[t], y = j + dy[t];
    if(ins(x, y)){
      if(h[x][y] > v){
        h[x][y] = v;
        dfs(x, y);
      }
    }
  }
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N;
  for(int i = 1; i <= N; ++i){
    for(int j = 1; j <= N; ++j){
      h[i][j] = min({i - 1, j - 1, N - i, N - j});
      a[i][j] = 1;
    }
  }
  int res = 0;
  for(int i = 1; i <= N * N; ++i){
    int id; cin >> id;
    int x, y;
    if(id % N == 0) x = id / N;
    else x = id / N + 1;
    y = id % N;
    if(y == 0) y = N;
    a[x][y] = 0;
    res += h[x][y];
    dfs(x, y);
  }
  cout << res;

}


Measured memory_bytes: 24492
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[])throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		int[] ball = {1,0,0};
		String line;
		String[] splitLine;
		int tmp;
		int[] change = new int[2];
		
		while(true){
			line = br.readLine();
			if(line == null || line.isEmpty()){
				break;
			}
			splitLine = line.split(",");
			if(splitLine[0].equals("A")){
				change[0] = 0;
			}else if(splitLine[0].equals("B")){
				change[0] = 1;
			}else{
				change[0] = 2;
			}
			
			if(splitLine[1].equals("A")){
				change[1] = 0;
			}else if(splitLine[1].equals("B")){
				change[1] = 1;
			}else{
				change[1] = 2;
			}
			
			tmp = ball[change[0]];
			ball[change[0]] = ball[change[1]];
			ball[change[1]] = tmp;
		}
		
		if(ball[0] == 1){
			System.out.println("A");
		}else if(ball[1] == 1){
			System.out.println("B");
		}else{
			System.out.println("C");
		}
	}
}

Measured memory_bytes: 16964
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc059_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            string a = str[0].Substring(0, 1);
            string b = str[1].Substring(0, 1);
            string c = str[2].Substring(0, 1);
            string rya = a + b + c;
            Console.WriteLine(rya.ToUpper());
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

int n;
vector<string> v;

void dfs(int d, vector<int> x) {
  if (d + 1 >= n) {
    string s;
    rep(i, sz(x)) s += 'a' + x[i];
    v.eb(s);
    return;
  }
  rep(i, *max_element(all(x)) + 2) {
    x.eb(i);
    dfs(d + 1, x);
    x.pop_back();
  }
}

void solve() {
  cin >> n;
  vector<int> x;
  x.eb(0);
  dfs(0, x);
  sort(all(v));
  rep(i, sz(v)) cout << v[i] << endl;
}


Measured memory_bytes: 9716
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

ans = 0
if A > B+C:
    poi = B+C+1
else:  # A<B+C
    poi = A

anti = B
print(anti+poi)


Measured memory_bytes: 2940
r1, c1, r2, c2 = map(int, input().split())

MOD = 10**9 + 7
MAX = r2 + c2 + 10
fact = [1] * (MAX + 1)  # i!
finv = [1] * (MAX + 1)  # (i!)^{-1}
iinv = [1] * (MAX + 1)  # i^{-1}
for i in range(2, MAX + 1):
    fact[i] = fact[i - 1] * i % MOD
    iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * iinv[i] % MOD


def comb(n: int, k: int) -> int:
    if n < k or n < 0 or k < 0:
        return 0
    return (fact[n] * finv[k] % MOD) * finv[n - k] % MOD


def func(a, b):
    res = 0
    for i in range(a + 1):
        res += comb(i + b + 1, i + 1)
        res %= MOD
    return res


ans = func(r2, c2) - func(r2, c1 - 1) - func(r1 - 1, c2) + func(r1 - 1, c1 - 1)
ans %= MOD
print(ans)


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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    lli n;
    cin1(n);
    double ans = 0;
    REP(i, 0, n) {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY")
            ans += x;
        else
            ans += x * 380000.0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <utility>

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int N, X, L[101], D[101]={}, count=1;
	
	cin >> N >> X;
	
	for(int i=0; i<N; i++)
		cin >> L[i];
	
	for(int i=0; i<=N; i++){
		D[i+1] = D[i]+L[i];
		if(D[i+1] <= X)
			count++;
	}
	
	cout << count;
	
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int K;
    cin >> K;
    int N;
    N=(K+1)/2;
    if(N%2){
        N++;
    }
    if(N==2){
        cout << K << endl;
        rep(i,K){
            rep(j,K){
                cout << j+1 << (j==K-1?'\n':' ');
            }
        }
        return 0;
    }
    vvl A(N,vl(N));
    cout << N << endl;
    rep(i,N){
        rep(j,N){
            if(j%2==0){
                A[i][j]=(i+j)%N+1;
            }
            else{
                A[i][j]=(i+j)%N+N+1;
                while(A[i][j]>K){
                    A[i][j]-=N;
                }
            }
        }
    }
    rep(i,N){
        rep(j,N){
            cout << A[i][j] << (j==N-1?'\n':' ');
        }
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 5220
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

x = int(input())
for i in range(-1000, 1001):
    for j in range(-1000, 1001):
        if i**5-j**5 == x:
            print(i, j)
            exit()


Measured memory_bytes: 69128
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

bool isprime(int n) {
    if(n <= 1) return false;
    repeat(i, 2, n - 1) {
        if(n % i == 0) return false;
    }
    return true;
}

void solve() {
    int x;
    std::cin >> x;
    x--;
    while(true) {
        x++;
        if(isprime(x)) {
            std::cout << x << std::endl;
            return;
        }
    }
}

int main() {
    // std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(int & v : a) cin >> v;
  sort(a.rbegin(), a.rend());
  int s0 = 0, s1 = 0;
  for(int i = 0; i < n; i++){
    if(i&1) s1 += a[i];
    else s0 += a[i];
  }
  cout << s0 - s1 << endl;
  return 0;
}

Measured memory_bytes: 256