akhauriyash/Code-Regression huggingface dataset:
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int D,G,ans=mod,i,j;cin>>D>>G;G/=100;
	vector<int>p(D+1),c(D+1);
	for(i=1;i<=D;i++){cin>>p[i]>>c[i];c[i]/=100;}
	for(int bi=0;bi<1024;bi++){
		int gen=0,np=0;
		for(i=1;i<=D;i++){
			if((bi&(1<<(i-1)))){gen+=p[i];np+=p[i]*i+c[i];}
		}
		for(i=D;i>=1;i--){
			if(np>=G){break;}
			if((bi&(1<<(i-1)))){continue;}
			int mon=(G-np+i-1)/i;
			mineq(mon,p[i]);
			gen+=mon;np+=mon*i;
		}
		if(np>=G){mineq(ans,gen);}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
  // 入力
  int N, M;
  cin >> N >> M;
  
  vector<pair<int,int>> p(M);
  for (int i = 0; i < M; i++) {
    cin >> p.at(i).first >> p.at(i).second;
  }
  
  // 頂点
  vector<int> edge(N);
  for (int i = 0; i < N; i++) {
    edge.at(i) = (i + 1);
  }  
  
  int count = 0;
  do {
    bool o = true;
    for (int i = 0; i < (N - 1); i++) {
      int pos1 = edge.at(i);
      int pos2 = edge.at(i + 1);
      
      bool ok = false;
      for (int j = 0; j < M; j++) {
        if ((p.at(j).first == pos1 && p.at(j).second == pos2) ||
            (p.at(j).first == pos2 && p.at(j).second == pos1)
           ) {
          ok = true;
          break;
        }
      }
      if (!ok) { // 対応する辺が見つからなかった
        o = false;
        break;
      }
    } 
    if (o) {
      count++;
    }
  } while (next_permutation(edge.begin() + 1, edge.end()));
  
  cout << count << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

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

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  ll N,K;  cin>>N>>K;
  ll ans = K;
  rep(i,0,N-1){
    ans *= (K-1);
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    double height = y2 - y1;
    double width = x2 - x1;
    cout << fixed << setprecision(8) << sqrt(pow(height, 2.0)+pow(width, 2.0)) << endl;
}


Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
map<int,int>::iterator m_it;
int main()
{
	int i,n,k,sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&k);
		m.count(k)==0?m[k]=1:m[k]++;
	}
	for(m_it=m.begin();m_it!=m.end();++m_it)
	{
		if(m_it->first<=m_it->second)
			sum+=m_it->second-m_it->first;
		else
			sum+=m_it->second;
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 4736
N,K = map(int,input().split())
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
x10 = 35
x2 = Base_10_to_n(N, K)
print( len(x2) )

Measured memory_bytes: 9052
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
#define debug(V) rep(i, V.size()) cout << V[i] << " ";
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*988244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v;
string S, T;
vl A, B;
void solve() {
    cout<<S.substr(0,3)<<endl;
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>S;
    solve();
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t,k;

int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n>>k;
      ll a[n],ans=0;
      for(int i=0;i<n;i++)
      {
        cin>>a[i];
      }
      sort(a,a+n);
      for(int i=0;i<k;i++)
      {
        ans+=a[i];
      }
      cout<<ans;
      
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vpl a(n);
  rep(i,n){
    int tmp;
    cin >> tmp;
    a[i] = mp(tmp,i);
  }

  ll ans = 0;
  sort(all(a));
  rep(i,n){
    if(!(i%2 == 0 && a[i].second%2 == 0)
       && !(i%2 != 0 && a[i].second%2 != 0)){
      ans++;
    }
  }
  cout << ans/2 << endl;
  return 0;
}


Measured memory_bytes: 1920
//One Quadrillion and One Dalmatians

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    vector<int>ans;
    int n;cin>>n;
    int amari = n-1;
    while(amari>=0){
        ans.pb(amari%26);
        amari=amari/26;
        amari-=1;
    }
    reverse(range(ans));
    string t;
    rep(i,0,ans.size()){
        t.pb(ans[i]+97);
    }
    cout<<t<<nnn;
    return 0;
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    int a,h=0,l=1000;
    for (int i=0;i<N;i++){
	cin >> a;
	h=max(h,a);
	l=min(l,a);
    }

    cout << h-l << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define int long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define err(A) cout << #A << " = " << (A) << endl
using namespace std;



int32_t main(){
    ll n,m;
    cin >> n >> m;
    ll l=0,r=(ll)1e15;
    while(r-l>1){
        ll mid=(r+l)/2;
        ll z=max((ll)0,mid-n);

        ll p=m-2*z;
        if (p/2>=mid){
            l=mid;
        }
        else{
            r=mid;
        }
    }
    cout << l;

}











Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    S = list(input())
    T = list(input())

    LCS = [[0 for _ in range(len(T) + 1)] for _ in range(len(S) + 1)]
    for i in range(1, len(S) + 1):
        for j in range(1, len(T) + 1):
            x = 1 if S[i - 1] == T[j - 1] else 0
            LCS[i][j] = max(LCS[i - 1][j - 1] + x, LCS[i - 1][j], LCS[i][j - 1])

    res = []
    i, j = len(S), len(T)
    while i > 0 and j > 0:
        if LCS[i][j] == LCS[i - 1][j]:
            i -= 1
        elif LCS[i][j] == LCS[i][j - 1]:
            j -= 1
        else:
            res.append(S[i - 1])
            i -= 1
            j -= 1

    print("".join(res[::-1]))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 121820
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;

//ここから

ll n,k;
vector<ll>a;

void solve(){
  cin>>n>>k;
  a.resize(n);
  k*=2;
  rep(i,n){
    cin>>a[i];
  }
  sort(all(a));
  ll l=-1e18-1,r=1e18;
  while(abs(r-l)>1){
    ll mid=(l+r)/2;
    ll sum=0;
    rep(i,n){
      if(a[i]*a[i]<=mid)--sum;
      if(a[i]>0){
        ll pos;
        if(mid>=0)pos=upper_bound(all(a),mid/a[i])-a.begin();
        else pos=upper_bound(all(a),-((-mid+a[i]-1)/a[i]))-a.begin();
        sum+=pos;
      }
      else if(a[i]<0){
        ll pos;
        if(mid>=0)pos=a.end()-lower_bound(all(a),-(mid/-a[i]));
        else pos=a.end()-lower_bound(all(a),(-mid-a[i]-1)/-a[i]);
        sum+=pos;
      }
      else {
        if(mid>=0)sum+=n;
      }
    }
    if(sum>=k)r=mid;
    else l=mid;
  }
  cout<<r<<"\n";
}

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

Measured memory_bytes: 1792
n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
ans=0
for i in range(n-1,-1,-1):
  if arr1[i+1]>arr2[i]:
    ans+=arr2[i]
    continue
  else:
    ans+=arr1[i+1]
    arr2[i]-=arr1[i+1]
    if arr1[i]>arr2[i]:
      ans+=arr2[i]
      arr1[i]-=arr2[i]
    else:
      ans+=arr1[i]
      arr1[i]=0
print(ans)

Measured memory_bytes: 19900
#include <bits/stdc++.h>
//#include <ext/numeric>
#define oo 0x3f3f3f3f
#define long long long

using namespace std;
//using namespace __gnu_cxx;

long calc(long n, int b) {
    long ret = 0;
    while (n) {
        ret += n % b;
        n /= b;
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed;

    long s, n;
    cin >> n >> s;
    if (s > n) {
        cout << -1 << '\n';
        return 0;
    }
    if (s == n) {
        cout << n + 1 << '\n';
        return 0;
    }

    long ans = LLONG_MAX;
    for (int b = 1; 1ll * b * b <= n; ++b) {
        if (b > 1) {
            long x = calc(n, b);
            if (x == s) {
                cout << b << '\n';
                return 0;
            }
        }
        if (b <= s && 1LL * b * b < n) {
            long r = n / b;
            long l = n / (b + 1) + 1;
            long m = b + n % r;
            if (m <= s) {
                m = s - m;
                if (m % b == 0 && m / b <= r - l) {
                    ans = r - m / b;
                }
            }
        }
    }

    if (ans == LLONG_MAX) {
        cout << -1 << '\n';
        return 0;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;

class Main {
    private static int gcd(int a, int b) {
        if (a % b == 0) {
            return b;
        } else {
            return gcd(b, a % b);
        }
    }

    private static void solve() {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            int p = scanner.nextInt();
            int n = scanner.nextInt();
            if (p == 0 && n == 0) {
                break;
            }
            int u = 1;
            int v = n;
            int x = n;
            int y = 1;

            for (int i = 1; i <= n; i++) {
                int num = (int) (i * Math.sqrt(p));
                int den = i;
                if (num > n) {
                    break;
                }
                if ((double) num / den > (double) u / v && gcd(num, den) == 1) {
                    u = num;
                    v = den;
                }
                num++;
                if (num > n) {
                    continue;
                }
                if ((double) num / den < (double) x / y && gcd(num, den) == 1) {
                    x = num;
                    y = den;
                }
            }
            System.out.println(String.format("%d/%d %d/%d", x, y, u, v));
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >>n;
  vector<int>a(n+1);
  for(int i=0;i<n+1;i++)cin>>a[i];
  vector<int>b(n);
  for(int i=0;i<n;i++)cin>>b[i];
  long long kotae=0;
  for(int i=0;i<n;i++){
    if(b[n-1-i]>a[n-i]){
      kotae+=a[n-i];
      b[n-1-i]-=a[n-i];
      //cout<<"0:"<<a[n-i]<<" ";
      if(b[n-i-1]>a[n-i-1]){
        kotae+=a[n-i-1];
        //cout<<"1:"<<a[n-i-1]<<" ";
        a[n-i-1]=0;
      }else{
        kotae+=b[n-i-1];
        a[n-i-1]-=b[n-i-1];
        //cout<<"2:"<<b[n-i-1]<<" ";
      }
    }else{
      kotae+=b[n-i-1];
      //cout<<"3:"<<b[n-i-1]<<" ";
    }
  }
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 1024
#B - Palindromic Numbers
A,B = map(int,input().split())
count = 0
for i in range(A,B+1):
    i = str(i)
    if i[0] == i[1] == i[3] == i[4] or (i[0] == i[4] and i[1] == i[3]):
        count += 1
print(count)

Measured memory_bytes: 67964
import math


def get_pseudo_input():
    N = 3
    A = [6, 10, 16]
    return N, A


def get_input():
    N = int(input())
    A = [int(x) for x in input().split()]
    return N, A


def sieve_of_eratosthenes(x: int):
    ret = [-1] * (x + 1)
    for i in range(1, x + 1):
        ret[i] = i
    p_max = int(math.sqrt(x))
    for p in range(2, p_max + 1):
        if ret[p] < p:  # p is not a prime number
            continue
        for i in range(p, x + 1, p):
            if ret[i] > p:
                ret[i] = p
    return ret


A_max = 10 ** 6
p_table = sieve_of_eratosthenes(A_max)

N, A = get_input()
# Store a number of unique Ais using the prime number
p_nums = [0] * (A_max + 1)
p_nums[1] = N
max_p_nums = 0
for a in A:
    # print(f"a={a}")
    while a > 1:
        p = p_table[a]
        while a % p == 0:
            a = a // p
        # print(f"  a={a}")
        p_nums[p] += 1
        if max_p_nums < p_nums[p]:
            max_p_nums = p_nums[p]
# print(max_p_nums)
if max_p_nums <= 1:
    # GCD of A is 1
    print('pairwise coprime')
elif max_p_nums == N:
    # GCD of A is not 1
    print('not coprime')
else:
    print('setwise coprime')

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

ll costleft(ll n, ll a, ll b) {
    if (a > b)
        swap(a, b);
    ll cost = 0;
    cost += a - 1;
    b -= a - 1;
    a -= a - 1;
    b--;
    cost++;
    cost += (b - a) / 2;
    return cost;
}

ll costright(ll n, ll a, ll b) { return costleft(n, n - a + 1, n - b + 1); }

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

    long long n, a, b;
    cin >> n >> a >> b;
    if ((b - a) % 2 == 0) {
        cout << (b - a) / 2 << endl;
    } else {
        cout << min(costleft(n, a, b), costright(n, a, b)) << endl;
    }
}

Measured memory_bytes: 256
r, c = gets.split.map(&:to_i)
ary = []
r.times{|i|
    ary.push(gets.split.map(&:to_i))
    ary[i].push(ary[i].inject(:+))
}

ary.push([])

ary[0].length.times{|i|
    sum = 0
    r.times{|j|
        sum += ary[j][i]
    }
    ary[-1].push(sum)
}

ary.each{|col|
    puts col.join(" ")
}

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

char c[1010][1010];
queue < pair<pair<int,int>,int> > Q;
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
bool vis[1010][1010];
int n,m;

bool check(int x,int y){
	return x>=0&&x<n&&y>=0&&y<m;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>c[i][j];
			if(c[i][j]=='#'){
				vis[i][j]=1;
				Q.push(make_pair(make_pair(i,j),0));
			}
		}
	}
	int ans=0;
	while(!Q.empty()){
		int x=Q.front().first.first;
		int y=Q.front().first.second;
		int d=Q.front().second;
		ans=max(ans,d);
		Q.pop();
		for(int i=0;i<4;i++){
			int nx=x+dx[i];
			int ny=y+dy[i];
			if(check(nx,ny)){
				if(!vis[nx][ny]&&c[nx][ny]=='.'){
					vis[nx][ny]=1;
					Q.push(make_pair(make_pair(nx,ny),d+1));
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 14352
mod = 10**9+7
rng = 2000100
fctr = [1]+[0]*(rng-1)
for i in range(1,rng):
  fctr[i] = fctr[i-1]*i%mod
def finv(x):
  return pow(fctr[x],mod-2,mod)
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv(n-k)*finv(k)%mod

x1,y1,x2,y2 = map(int,input().split())
print((cmb(x2+y2+2,x2+1)-cmb(x2+y1+1,y1)-cmb(x1+y2+1,x1)+cmb(x1+y1,x1))%mod)

Measured memory_bytes: 82152
import java.util.*;

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

        int s = sc.nextInt();
        int w = sc.nextInt();

        if(w >= s){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }
    }
}


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

int n,q,Mi,A[1000];

// mがつくれるかどうか判定
int check ( int i , int m ) {
  if ( m == 0 ) return 1; //mがつくれる場合
  if ( i >= n ) return 0; //mがつくれない場合
  int rec = check ( i + 1, m ) || check ( i + 1, m - A[i] );
  //i番目の要素を選ぶか選ばないかで場合分け
  return rec;
}

int main() {
  
  cin >> n;
  for ( int i = 0; i < n; i++ ) cin >> A[i];

  cin >> q;
  for ( int i = 0; i < q; i++ ) {
    cin >> Mi;
    if ( check( 0, Mi ) ) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1156
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
typedef long long LL;
#define ms(a,b) memset(a,b,sizeof(a))

int parent[55];
int root(int x)//查
{
     return  parent[x] == x ?  x : parent[x]=root( parent[x] );
}
int merge(int x, int y)//并
{
      int rx=root(x);
      int ry=root(y);
      if(rx!=ry)
            parent[rx]=ry;
}
int main()
{
    int n,m;
    int a[55],b[55];
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
        scanf("%d%d",&a[i],&b[i]);
    int ans=0;
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<=n;j++) parent[j]=j;//初始化
        for(int j=0;j<m;j++){//合并
            if(i!=j) merge(a[j],b[j]);
        }
        int father=root(1);
        for(int j=1;j<=n;j++){//判断图是否连通
            if(root(j)!=father){
                ans++;break;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

const int MAX_N = 100000;

struct Node
{
int iP;
int iRank;
};

Node nd[ MAX_N + 5 ];

int Find( const int A )
{
int i;

	i = A;
	while( i != nd[ i ].iP ) i = nd[ i ].iP;

	return i;
}

void Unite( const int A, const int B )
{
int iGa;
int iGb;
int iRa;
int iRb;

	iGa = Find( A );
	iGb = Find( B );
	if( iGa == iGb ) return;

	iRa = nd[ iGa ].iRank;
	iRb = nd[ iGb ].iRank;
	if( iRa > iRb )
		nd[ iGb ].iP = iGa;
	else if( iRa < iRb )
		nd[ iGa ].iP = iGb;
	else
	{
		nd[ iGb ].iP = iGa;
		nd[ iGa ].iRank++;
	}
}

bool Same( const int A, const int B )
{
	return ( Find( A ) == Find( B ) );
}

int p[ 100010 ];

int main()
{
int i;
int N;
int M;
int x;
int y;
int iCnt;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	cin >> M;

	for( i = 1; i <= N; i++ )
	{
		nd[ i ].iP = i;
		cin >> p[ i ];
	}

	for( i = 0; i < M; i++ )
	{
		cin >> x;
		cin >> y;
		Unite( x, y );
	}

	iCnt = 0;
	for( i = 1; i <= N; i++ )
	{
		if( Same( i, p[ i ] ) ) iCnt++;
	}

	cout << iCnt << endl;

	return 0;
}








Measured memory_bytes: 1408
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int a,b,c, n;
  cin>>a>>b>>c>>n;
  int ret = 0;
  int tt = min(a,n);
  ret += tt;
  n-=tt;
  tt = min(b,n);
  n-=tt;
  tt = min(c, n);
  ret -=tt;
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

string s, t;
int dp[4001][4001];

int main(){
	while(cin >> s >> t){
		rep(i, s.size() + 1){
			dp[i][0] = 0;
		}
		rep(i, t.size() + 1){
			dp[0][i] = 0;
		}
		for(int i = 1; i <= s.size(); ++i){
			for(int j = 1; j <= t.size(); ++j){
				dp[i][j] = s[i - 1] == t[j - 1] ? dp[i - 1][j - 1] + 1 : 0;
			}
		}
		int ans = 0;
		rep(i, s.size() + 1){
			ans = max(*max_element(dp[i], dp[i] + t.size() + 1), ans);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 63740
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BTreeMap;

fn main() {
    input!{
        n: usize,
        vs: [i64; n],
    }

    let mut m0 = BTreeMap::new();
    let mut m1 = BTreeMap::new();

    for i in 0..n {
        if i % 2 == 0 {
            *m0.entry(vs[i]).or_insert(0) += 1;
        } else {
            *m1.entry(vs[i]).or_insert(0) += 1;
        }
    }

    let mut p0 = m0.into_iter().map(|(k, v)| (v, k)).collect::<Vec<_>>();
    let mut p1 = m1.into_iter().map(|(k, v)| (v, k)).collect::<Vec<_>>();

    p0.sort();
    p1.sort();
    p0.reverse();
    p1.reverse();

    let ans = if p0[0].1 != p1[0].1 {
        n - p0[0].0 - p1[0].0
    } else {
        std::cmp::min(
            n - p0[0].0 - if p1.len() > 1 { p1[1].0 } else { 0 },
            n - if p0.len() > 1 { p0[1].0 } else { 0 } - p1[0].0,
        )
    };

    println!("{}", ans);
}


Measured memory_bytes: 10492
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int dp[32] = {0}, n;
	dp[0] = 1;
	dp[1] = 1;
	dp[2] = 2;

	for(int i = 3; i < 31; i++)
	{
		dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
	}

	while(cin >> n, n)
	{
		cout << (dp[n]/365)/10 + 1 << endl;
	}
}

Measured memory_bytes: 1160
#include<stdio.h>

int main(void){
  int min=10000,max=0;
  int i,n,x;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&x);
    if(x<min) min=x;
    if(x>max) max=x;
  }

  printf("%d\n",max-min);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


int n;
string bar;
string str;

bool judge(string str) {
    int b = bar.size();
    for (int i = 0; i < str.size(); ++i) {
        for (int j = i+1; i + (j-i)*(b-1) < str.size(); ++j) {
            string tmp = "";
            for (int k = 0; k < b; ++k) {
                int ind = i + (j-i)*k;
                tmp += str[ind];
            }
            if (bar == tmp) return true;
        }
    }
     
    return false;
}

int main() {
    while (cin >> n) {
        cin >> bar;
        int res = 0;
        for (int i = 0; i < n; ++i) {
            cin >> str;
            if (judge(str)) ++res;
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1224
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <complex>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const double PI = 3.141592653589793238462643383279502884L;
const int LARGE_PRIME = 1000000007;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i,a,cont,next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i,a,b,s) repfn(i,a,i<b,i+s)
#define repab(i,a,b) repby(i,a,b,1)
#define rep(i,b) repab(i,0,b)
#define pb push_back
#define sz(c) int((c).size())

long factorial(long n)
{
  if (n)
    return n * factorial(n-1);
  else
    return 1;
}
int main(int argc, char **argv)
{
  long n;
  cin >> n;
  cout << factorial(n) << endl;
  return 0;
}

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

int main () {
  int N;
  cin >> N;
  vector<int> C(N-1), S(N-1), F(N-1);
  for (int i = 0; i < N-1; i++) {
    cin >> C.at(i) >> S.at(i) >> F.at(i);
  }
  for (int i = 0; i < N-1; i++) {
    int ans = S.at(i)+C.at(i);
    if (i != N-2){
      for (int j = i+1; j < N-1; j++) {
        if (ans < S.at(j)) ans = S.at(j)+C.at(j);
        else if (ans%F.at(j) == 0) ans += C.at(j);
        else ans += (F.at(j)-ans%F.at(j))+C.at(j);
      }
    }
    cout << ans << endl;
  }
  cout << 0 << endl;
}

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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e16;

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

  LL ans = 0;
  int N, K;
  cin >> N >> K;
  vector<int> count(N + 1, 0);
  int kind = 0;
  FOR(i, 0, N) {
    int A;
    cin >> A;

    if (count[A] == 0) {
      kind++;
    }
    count[A]++;
  }

  if (kind <= K) {
    cout << ans << '\n';
    return 0;
  }

  sort(count.begin(), count.end());

  FOR(i, 0, N + 1) {
    if (count[i] == 0) {
      continue;
    }

    ans += count[i];
    kind--;

    if (kind <= K) {
      break;
    }
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ip pair<ll,ll>
#define vii vector<ll>
#define vpp vector<ip>
#define vdd vector<ld>
#define vb vector<bool>
#define pi  pair<ll,ip>
#define sc(x) scanf("%lli",&x)
#define c(x) cin >> x
#define fo(i,k,n) for( int i=k;i<n;i++)
#define hu 200010
#define pq priotity_queue<ll>
#define pqs priority_queue<ll,vii,greater<ll>>
#define ppq priority_queue<ip,vpp,greater<ip>>
#define INF INT_MAX
#define ff first
#define ss second
using namespace std;
const ll M = 1000000000+7;
//Grid Movement
ll dx[] = {-1, 0, 1, 0};
ll dy[] = {0, -1, 0, 1};

ld Pi= acos(-1);

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

ll mex(ll x, ll y) 
{ 
	ll res = 1;	  
	x = x % M; 
	if (x == 0) return 0; 
	while (y > 0) 
	{ 
		if (y & 1) 
		res = (res*x) % M; 
		y = y>>1; 
		x = (x*x) % M; 
	} 
	return res; 
} 

bool comp(ll comp1,ll comp2)
{
    return comp1>comp2;
}

void yes()
{
    printf("Yes\n");
}

void no()
{
    printf("No\n");
}

ll inv(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
 
    if (m == 1)
      return 0;
 
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
 
    if (x < 0)
       x += m0;
 
    return x;
}

void sieve(ll n)
{
    vii primes(n+1);
    vb is_prime(n+1);
	is_prime.resize(n+1);
	primes.resize(n+1);
 
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i<=n; i++)
	{
	    if(is_prime[i])
	    {
	    	primes.pb(i);
	        for (int j = i*i; j<=n; j+=i)
	            is_prime[j] = false;
	    }
	}
}

void solve()
{
    ll x;
    sc(x);
    ld d;
    cin >> d;
    d=d*d;
    ll ans =0;
    fo(i,0,x)
    {
        ll p,q;
        sc(p);
        sc(q);
        if(p*p + q*q <=d)ans++;
    }
    printf("%lli",ans);
}

int main()
{
    ll t=1;
  //  sc(t);
    while(t--) solve();
}





Measured memory_bytes: 3900
#include <iostream>
using namespace std;
int h, w, d[2000][2000][4], ans = 0;
string s[2000];

int main(void){
    cin >> h >> w;
    for(int i=0;i<h;i++){
        cin >> s[i];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i > 0 && s[i-1][j] == '.'){
                d[i][j][0] = d[i-1][j][0] + 1;
            }else{
                d[i][j][0] = 0;
            }
            if(j > 0 && s[i][j-1] == '.'){
                d[i][j][1] = d[i][j-1][1] + 1;
            }else{
                d[i][j][1] = 0;
            }
        }
    }
    for(int i=h-1;i>=0;i--){
        for(int j=w-1;j>=0;j--){
            if(i < h-1 && s[i+1][j] == '.'){
                d[i][j][2] = d[i+1][j][2] + 1;
            }else{
                d[i][j][2] = 0;
            }
            if(j < w-1 && s[i][j+1] == '.'){
                d[i][j][3] = d[i][j+1][3] + 1;
            }else{
                d[i][j][3] = 0;
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j] == '.'){
                ans = max(ans, 1 + d[i][j][0] + d[i][j][1] + d[i][j][2] + d[i][j][3]);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 66816
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  
  ll A,B,C,K;
  cin >> A >> B >> C >> K;
  if(K % 2 == 0){
    cout << (A-B) << endl;
  }else
    cout << (B-A) << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


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

#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

//プロトタイプ宣言
void faster(void);
ll gcd(auto , auto);
ll get_digent(auto);
ll POW(auto , auto);
ll vec_max(auto & , string);
ll vec_min(auto & , string);

int main(){
  faster();
  ll n;
  cin >> n;
  vl a(n);
  rep(i,n) cin >> a[i];
  ll ans=0;
  bool flag_p = false , flag_m = false;
  rep(i,n-1){
    if(flag_p){
      if(a[i] > a[i+1]){
        ans++;
        flag_p = false;
        continue;
      }
    }
    if(flag_m){
      if(a[i] < a[i+1]){
        ans++;
        flag_m = false;
        continue;
      }
    }
    if(a[i] == a[i+1]) continue;
    if(a[i] < a[i+1]) flag_p = true;
    if(a[i] > a[i+1]) flag_m = true;
  }
  cout << ans+1 << endl;
}


























//以下、ライブラリ

//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
ll gcd(auto a, auto b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
ll get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
ll POW(auto x, auto y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 

//配列内の最大要素の添え字取得or要素取得
ll vec_max(auto &v, string s){
  auto itr = max_element(v.begin(),v.end());
  ll element = *itr;
  ll place = itr - v.begin();
  if(s == "element") return element;
  else if(s == "place") return place;
  else return -1;
}

//配列内の最小要素の添え字取得or要素取得
ll vec_min(auto &v, string s){
  auto itr = min_element(v.begin(),v.end());
  ll element = *itr;
  ll place = itr - v.begin();
  if(s == "element") return element;
  else if(s == "place") return place;
  else return -1;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }


int main() {
  int n; cin>>n;
  vector<long long> a(n);
  rep(i, n) cin>>a[i];
  map<long long, long long> ma;
  long long ans = 0;
  ma[a[0]+1] = 1;
  REP(i, 1, n) {
    long long now = (i+1) - a[i];
    ans += ma[now];
    ++ma[(i+1) + a[i]];
  }
  print(ans);

  return 0;
}

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

int main() {
	long long N;
	cin >> N;
	if (1 == N%2) {
		cout << 0 << endl;
	}
	else {
		N /= 2;
		long long ans = 0;
		while (0 != N) {
			ans += N / 5;
			N /= 5;
		}
		cout << ans << endl;
	}
	return 0;
}	

Measured memory_bytes: 3528
#include <iostream>
#include <cstring>
using namespace std;
int main(){

    string s;
    cin >> s;

    if(s.length() == 2){
        
    }
    else{
        char a = s[2];
        s[2] = s[0];
        s[0] = a;
    }
    cout << s << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()
#define pb push_back


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

const int MAXN = 2002;
ll fact[MAXN], inv[MAXN], finv[MAXN];
const ll mod = 1e9 + 7;


ll calc(ll n, ll i, ll k) {
    ll r = n-k+1;
    if (r-i < 0) return 0;
    ll x =  (((fact[r] * finv[r-i]) % mod) * finv[i]) % mod;
    ll y = (((fact[k-1] * finv[k-1-(i-1)]) % mod) * finv[i-1]) % mod;
    return (x*y) % mod;
}

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, k; cin >> n >> k;
    fact[0] = fact[1] = 1;
    for (int i = 2; i < MAXN; ++i) {
        fact[i] = (i * fact[i-1]) % mod;
    }

    inv[0] = inv[1] = 1;
    for (int i = 2; i < MAXN; ++i) {
        inv[i] = (inv[mod%i] * (mod-mod/i)) % mod;
    }
    
    finv[0] = finv[1] = 1;
    for (int i = 2; i < MAXN; ++i) {
        finv[i] = (finv[i-1] * inv[i]) % mod;
    }

    for (ll i = 1; i <= k; ++i) {
        cout << calc(n,i,k) << endl;
    }

    return 0;
}



Measured memory_bytes: 384
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    A = list(map(int,input().split()))
    A.sort(reverse = True)
    ans = A[0]
    for i in range(n-2):
        ans += A[i//2 + 1]
    print(ans)

if __name__=='__main__':
    main()

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

int main() {
  int A,B;
  cin>>A>>B;
  if(A>=13){
    cout<<B<<endl;
  }
  if(A<13 && A>=6){
    cout<<B/2<<endl;
  }
  if(A<6){
    cout<< 0 <<endl;
  }
}


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

int main(){
	int n,q,i,time=0;
	cin >> n >> q;
	queue<int> Q;
	
	int input_Num[n];
	string input_Str[n];
	for (i=0;i<=n-1;i++){
		cin >> input_Str[i];
		cin >> input_Num[i];
	}
	
	for (i=0;i<=n-1;i++){
		Q.push(i);
	}
	
	while (!Q.empty()){
		i=Q.front();
		Q.pop();
		if (input_Num[i]>q){
			input_Num[i]-=q;
			Q.push(i);
			time+=q;
		}else{
			time+=input_Num[i];
			cout << input_Str[i] << " " <<time << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 4360
using System;
using System.Numerics;
using System.Linq;

class Program
{
    static long mod = 1000000000 + 7;


    static void Main(string[] args)
    {

        var l1 = ReadLongArray();

        long N = l1[0];
        long a = l1[1];
        long b = l1[2];

        long numMax = Math.Min(N, 200000);
        long total = Pow_mod(2, N, mod) -1;
        total -= Combination(N, a, mod);
        if (total < 0) total += mod;

        total -= Combination(N, b,mod);
        if (total < 0) total += mod;

        var result = total;

        Console.WriteLine(result);
    }



    public static long Combination(long n, long r, long mod)
    {
        if (n < 0 || r < 0 || r > n) throw new ArgumentException("不正な引数です．");

        if (n - r < r) r = n - r;
        if (r == 0) return 1;
        if (r == 1) return n;

        long[] numerator = new long[r];
        long[] denominator = new long[r];

        for (int k = 0; k < r; k++)
        {
            numerator[k] = n - r + k + 1;
            denominator[k] = k + 1;
        }

        for (int p = 2; p <= r; p++)
        {
            long pivot = denominator[p - 1];
            if (pivot > 1)
            {
                long offset = (n - r) % p;
                for (int k = p - 1; k < r; k += p)
                {
                    numerator[k - offset] /= pivot;
                    denominator[k] /= pivot;
                }
            }
        }

        long result = 1;
        for (int k = 0; k < r; k++)
        {
            if (numerator[k] > 1)
            {
                result *= numerator[k];
                result %= mod;
            }
        }

        return result;
    }


    static long Pow_mod(long a, long n, long mod)
    {
        long res = 1;
        while (n > 0)
        {
            var bit = n & 1;
            if (bit != 0) res = res * a % mod;
            a = a * a % mod;
            n >>= 1;
        }
        return res;
    }




    static string[] ReadStringArray()
    {
        return Console.ReadLine().Trim().Split(' ');
    }

    static int[] ReadIntArray()
    {
        return ReadStringArray().Select(_ => int.Parse(_)).ToArray();
    }

    static long[] ReadLongArray()
    {
        return ReadStringArray().Select(_ => long.Parse(_)).ToArray();
    }
}
 


Measured memory_bytes: 17376
#include <stdio.h>

int
main(void)
{
	char line[80];
	int n;

	if (fgets(line, sizeof line, stdin)) {
		if (sscanf(line, "%d", &n) == 1) {

			long long r = 1;
			for (int i = 2; i <= n; i++) {
				r *= i;
			}
			
			printf("%lld\n", r);
		}
	}

	return 0;
}

Measured memory_bytes: 1032