akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
	int i, n, mini, min=9999999, maxi, max=-9999999;

	cin>>n;

	vector<int> a(n);

	for(i=0; i<n; i++){
		cin>>a[i];
		if(min>a[i]){
			min=a[i]; mini=i;
		}
		if(max<a[i]){
			max=a[i]; maxi=i;
		}
	}
	if(min>=0){
		cout<<n-1<<endl;
		for(i=0; i<n-1; i++){
			cout<<i+1<<" "<<i+2<<endl;
		}
	}else if(max<0){
		cout<<n-1<<endl;
		for(i=n-1; i>=1; i--){
			cout<<i+1<<" "<<i<<endl;
		}
	}else if(abs(max)>abs(min)){
		cout<<2*n-1<<endl;
		for(i=0; i<n; i++){
			cout<<maxi+1<<" "<<i+1<<endl;
		}
		for(i=0; i<n-1; i++){
			cout<<i+1<<" "<<i+2<<endl;
		}
	}else{
		cout<<2*n-1<<endl;
		for(i=0; i<n; i++){
			cout<<mini+1<<" "<<i+1<<endl;
		}
		for(i=n-1; i>=1; i--){
			cout<<i+1<<" "<<i<<endl;
		}
	}
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    a = list(map(int, readline().split()))
    money = 1000
    stock = 0

    day = 0

    while day < n - 1:
        if stock == 0:
            cur = a[day]
            buy_day = day
            for i in range(day + 1, n):
                if cur >= a[i]:
                    cur = a[i]
                else:
                    buy_day = i - 1
                    break
            else:
                break
            stock += money // a[buy_day]
            money -= a[buy_day] * stock
            day = buy_day
        else:
            sell_day = 0
            cur = a[day]
            for i in range(day + 1, n):
                if cur <= a[i]:
                    cur = a[i]
                else:
                    sell_day = i - 1
                    break
            else:
                sell_day = n - 1
            money += a[sell_day] * stock
            stock = 0
            day = sell_day

    print(money)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61800
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
    int k;
    cin >> k;
    ll ans=0;
    rep(i,k)rep(j,k)rep(l,k)ans+=__gcd(i+1,__gcd(j+1,l+1));
    cout << ans << endl;
}


Measured memory_bytes: 3636
n=gets.to_i
s=gets.chomp

st=[]
s.chars.each do |c|
  if st.empty?
    st<< c
  else
    if st.last=='(' and c==')'
      st.pop
    else
      st<< c
    end
  end
end

a=st.count(')')
b=st.count('(')

puts '('*a+s+')'*b


Measured memory_bytes: 1788
import Control.Monad
import Data.Char
import Data.Maybe
import qualified Data.Vector as V
import qualified Data.Set as S
main=print.solve=<<(getLine>>getLine)
solve s=length.mapMaybe f$replicateM 3[0..9]where
  ns=V.accum(flip S.insert)(V.replicate 10 S.empty).(`zip`[0..]).map digitToInt$s
  f=foldM(\k i->S.lookupGT k$ns V.! i)(-1)

Measured memory_bytes: 12116
#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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll l, r; cin >> l >> r;
  ll ans = 1e9;
  r = min(r, l+4038);
  for(ll i = l; i < r; ++i) {
    for(ll j = i+1; j <= r; ++j) {
      ans = min(ans, (i*j)%(2019));
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int main (void) {
    ll N, M;

    cin >> N >> M;

    ll ans = 0;
    if (M <= 2 * N) ans = M / 2;
    else {
        M -= 2 * N;
        ans += N;
        ans += M / 4;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vec<ll> A(N + 1), S(N + 2);
    rep(i, N + 1) cin >> A[i];

    for (int i = N; i >= 0; --i) {
        S[i] = S[i + 1] + A[i];
    }

    ll ans  = 0;
    ll next = 1;
    rep(i, N + 1) {
        ans += next;
        next -= A[i];
        if (next < 0) {
            cout << -1 << endl;
            return 0;
        }
        next = min(next * 2, S[i + 1]);
    }
    cout << ans << endl;
}


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

int dp[1009][1009];

int main() {
    string s[1009];
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>s[i];
    if(s[0][0]=='#'){
        cout<<0<<endl;
        return 0;
    }
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i][j]=='#')
                continue;
            if(i-1>=0)
                dp[i][j]+=dp[i-1][j];
            if(j-1>=0)
                dp[i][j]+=dp[i][j-1];
            dp[i][j]%=1000000007;
        }
    }
    cout<<dp[n-1][m-1]<<endl;
}


Measured memory_bytes: 5248
#include <stdio.h>

int main(void) {

	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if (a >= c) {
		printf("0\n");
	}
	else if ((a + b) < c) {

		printf("NA\n");
	}
	else {
		printf("%d\n", c - a);

	}
	return 0;
}


Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
double ans=1000000;
struct point
{
  double x, y, val;
  point() {}
  point(double x, double y, double val) : x(x), y(y), val(val){};
  point(double x, double y) : x(x), y(y), val(0){};
};
struct vec
{
  double x, y;
  vec() {}
  vec(double x, double y) : x(x), y(y){};
  vec(point a, point b) : x(b.x - a.x), y(b.y - a.y){};
  double size() { return sqrt(x * x + y * y); };
};
bool threepoint(point a,point b,point c){
  return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x)==0;
}
//先に一直線上にないか確認
point threepoint_circle(point a,point b,point c){
  point p;
  double k=((c.x-a.x)*(c.x-b.x)+(c.y-a.y)*(c.y-b.y))/((b.y-a.y)*(c.x-a.x)-(b.x-a.x)*(c.y-a.y));
  p.x=(a.x+b.x+k*(b.y-a.y))/2;
  p.y=(a.y+b.y-k*(b.x-a.x))/2;
  p.val=sqrt(p.x*p.x+p.y*p.y-a.x*b.x-a.y*b.y-k*a.x*(b.y-a.y)+k*a.y*(b.x-a.x));
  return p;
}

int main()
{
ll n ;
cin >> n ;
vector<point> v(n);
rep(i, n){
  cin >> v[i].x >> v[i].y;
}
vector<point> p;
rep(i,n-1)for (ll j = i+1; j < n; j++)
{
  p.emplace_back(v[i].x+vec(v[i],v[j]).x/2,v[i].y+vec(v[i],v[j]).y/2,vec(v[i],v[j]).size()/2);
}
rep(i,n-2)for (ll j = i+1; j < n-1; j++)for (ll k = j+1; k < n; k++){
  if(threepoint(v[i],v[j],v[k]))continue;
  p.push_back(threepoint_circle(v[i],v[j],v[k]));
}
for(auto r:p){
  bool ok=1;
  rep(i,n){
    if(vec(r,v[i]).size()>r.val){ok=0;break;}
  }
  if(ok)ans=min(ans,r.val);
}
cout<<fixed<<setprecision(12)<<ans<<endl;
return 0;
}

Measured memory_bytes: 1148
from itertools import accumulate

N = int( input())
A = list( map( int, input().split()))
a, b = 0, 2
ans = 10**9 + 1
S = list(accumulate(A))
for i in range(1,N-2):
    while S[a] < S[i] - S[a+1]:
        a += 1
    b = max(b,i+1)
    while S[b] - S[i] < S[-1] - S[b+1]:
        b += 1
    ans = min( ans, max(S[a], S[i] - S[a], S[b] - S[i], S[-1] - S[b]) - min(S[a], S[i] - S[a], S[b] - S[i], S[-1] - S[b]))
print(ans)

Measured memory_bytes: 24176
#include <iostream>
using namespace std;
int main(void){
    string S;
    cin >> S;
    int N = S.size() - 1;
    int X = 0;
    for(int i = 0;i < S.size()/2; i++){
        if(S.at(i) != S.at(N-i)){
            X++;
        }
    }
    cout << X << endl;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    res = b[a[0]-1]
    for i in range(1, n):
        res += b[a[i]-1]
        if a[i] - a[i-1] == 1:
            res += c[a[i]-2]
    print(res)



if __name__ == '__main__':
    main()

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


#define ll long long int
#define ld long double
#define mod 1000000007
#define big 1e18+10
#define small -big
#define pb push_back



template <typename T>

void prarr(T a)
{
     cerr << "[ ";
     
     for(auto i : a){
         cerr << i << " ";
     }
     
     cerr << "]" << endl;
}


#define trace(...) _er(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void _er(const char* name, Arg1&& arg1){
	cerr << "[" << name << " : " << arg1 << "]" << endl;
}

template <typename Arg1, typename... Args>

void _er(const char* names, Arg1&& arg1, Args&&... args){
    
	const char* comma = strchr(names + 1, ',');
	cerr << "[" ; cerr.write(names, comma - names) << " : " << arg1 << "] ";
	_er(comma+2, args...);
}




vector<ll> A[200005];

void solve() {
    
    
            ll N;
            cin >> N;
            
            for(ll i = 1; i <= N; i++) {
                    A[i].clear();
            }
            
            for(ll i = 1; i <= (N - 1); i++) {
                        ll a, b;
                        cin >> a >> b;
                        A[a].pb(b);
                        A[b].pb(a);
            }
            
            for(ll i = 1; i <= N; i++) {
                    sort(A[i].begin(), A[i].end());
            }
            
            ll c = 1;
            
            ll prev = 1;
            
            for(ll i = N - 1; i >= 1; i--) {
                       
                     
                                ll te = 0;
                                ll now = 1;
                                ll er1 = i;
                                
                                for(auto it : A[i]) {
                                        if(it > i) {
                                             te += ((it - er1) * now);
                                             now--;
                                             er1 = it;
                                        }
                                }
                                te += ((N + 1 - er1) * now);
                                
                                prev += te;
                                c += prev;
                                
                       
                        
                      
            }
            
            cout << c << endl;
            
           
            
           
}


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

    int t=1;
   // cin >> t;

    for(int i = 1; i <= t; i++) {  
   
         solve();
    }


    return 0;
        
}


Measured memory_bytes: 15816
#include<bits/stdc++.h>
using namespace std;
struct edge{
  int cost, to;
};

void hasInputEdge(vector<vector<edge> > &ing, edge e, int v){
  for (int j = 0; j < ing[e.to].size(); j++) {
    if(ing[e.to][j].to == v){
      ing[e.to].erase(ing[e.to].begin() + j);
    }
  }
}


vector<int> tpSort(vector<vector<edge> > ing,
                   vector<vector<edge> > outg){
  queue<int> que;
  for (int i = 0; i < ing.size(); i++) {
    if(ing[i].size() == 0) que.push(i);
  }
  vector<int> res;
  while(que.size()){
    int v = que.front(); que.pop();
    res.push_back(v);
    for (int i = 0; i < outg[v].size(); i++) {
      edge e = outg[v][i];
      hasInputEdge(ing, e, v);
      if(ing[e.to].size() == 0) que.push(e.to);
    }
  }
  return res;
}
  
int main(int argc, char *argv[]){
  int n, m;
  cin >> n >> m;
  vector<vector<edge> >outg(n); 
  vector<vector<edge> >ing(n);
  for (int i = 0; i < m; i++) {
    int from;
    edge e;
    cin >> from >> e.to >> e.cost;
    outg[from].push_back(e);
    ing[e.to].push_back((edge){e.cost, from});
  }
  vector<int> tp = tpSort(ing, outg);
  // std::cout << "tp:" << std::endl;
  // for (int i = 0; i < n; i++) {
  //   std::cout << tp[i] << " ";
  // }
  //   std::cout << std::endl;
  // std::cout << "outg:" << std::endl;
  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < outg[i].size(); j++) {
  //     std::cout << outg[i][j].to << " ";
  //   }
  //   std::cout << std::endl;
  // }
  // std::cout << std::endl;
  int dp[n];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < outg[tp[i]].size(); j++) {
      int nv = outg[tp[i]][j].to;
      dp[nv] = max(dp[nv],
                   dp[tp[i]] + outg[tp[i]][j].cost);
    }
  }
  // for (int i = 0; i < tp.size(); i++) {
  //   std::cout << dp[i] << " ";
  // }
  std::cout << dp[n - 1] << std::endl;
  return 0;
}

Measured memory_bytes: 1316
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x)(x)*(x)
#define fz1(i,n) for (i=1;i<=n;i++)
#define fd1(i,n) for (i=n;i>=1;i--)
#define fz0g(i,n) for (i=0;i<=n;i++)
#define fd0g(i,n) for (i=n;i>=0;i--)
#define fz0k(i,n) for (i=0;i<n;i++)
#define fd0k(i,n) for (i=(long long)(n-1);i>=0;i--)
#define fz(i,x,y) for (i=x;i<=y;i++)
#define fd(i,y,x) for (i=y;i>=x;i--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
struct bit{long long arr[400005];int lowbit(int x){return x&(-x);}void add(int x,long long y){for (int i=x;i<=400005;i+=lowbit(i)) arr[i]+=y;}long long query(int x){long long s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;long long sum,add;void update(long long x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,int x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}long long query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;long long ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
long long n,m,i,j,l,r,mid,ans,num[400015],s[400015],sum[400015],f[400015];
vector<long long> all;
bit cnt;
bool asf(long long x)
{
//	return 0;
	long long i,j,ans=0;
	s[0]=200002;
	fz1(i,n)
	{
		if (num[i]<x) f[i]=-1;
		if (num[i]>=x) f[i]=1;
	}
	fz1(i,n) s[i]=s[i-1]+f[i];
	memset(cnt.arr,0,sizeof(cnt.arr));
	fd1(i,n)
	{
		cnt.add(s[i],1);
		ans+=cnt.query(s[i-1]-1);
	}
	return ans<((n*(n+1)/2)/2+1);
}
int main()
{
	scanf("%lld",&n);
	fz1(i,n)
	{
		scanf("%lld",&num[i]);
		all.push_back(num[i]);
	}
	sort(all.begin(),all.end());
	all.resize(unique(all.begin(),all.end())-all.begin());
	fz1(i,n) num[i]=upper_bound(all.begin(),all.end(),num[i])-all.begin();
	l=ans=1;r=((int)all.size())+1;
	while (l<r)
	{
		mid=(l+r)/2;
		if (asf(mid))
		{
			l=mid+1;
			ans=mid;
		}
		else r=mid;
	}
	cout<<all[ans-1]<<endl;
	return 0;
}

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

long long MOD = 1e9 + 7;

long long modPow(long long x, long long a) {
  if (a == 1) return x;
  if (a % 2) return (x * modPow(x, a - 1)) % MOD;
  long long t = modPow(x, a / 2);
  return (t * t) % MOD;
}

long long modInv(long long x) {
  return modPow(x, MOD - 2);
}

long long modPerm(long long n, long long k) {
  long long ret = 1;
  for (long long i = 0; i < k; i++) {
    ret = (ret * (n - i)) % MOD;
  }
  return ret;
}

long long modComb(long long n, long long k) {
  long long a, b;
  a = modPerm(n, k);
  b = modPerm(k, k);
  return (a * modInv(b)) % MOD;
}

int main(){
    long long n, a, b, sum;
    cin >> n >> a >> b;
    sum = modPow(2, n);
    sum -= 1;
    sum -= modComb(n, a);
    sum -= modComb(n, b);
    cout << (MOD * 2 + sum) % MOD;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int n;
  string s;
  cin >> n >> s;
  if(n%2){
    cout << "No" << endl;
    return 0;
  }
  else{
    rep(i,n/2){
      if(s[i]!=s[n/2+i]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin>>s;
    long long i,j,k,x,y,z;
    x=0;
    for (i=0;i<s.length();i++)
    {
    	y=int(s[i])-48;
    	x=x+y;
	}
	if (x%9==0)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 3708
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<62;
const double pi=acos(-1);
const long double eps=1e-7;
const ll mod=1e6+3;
const int dx[8]={0,1,0,-1,-1,-1,1,1},dy[8]={1,0,-1,0,-1,1,-1,1};

int n,h;
vi a;

int main(){
	cin>>n>>h;
	a=vi(n);
	int M=0,t=0;
	for(int i=0;i<n;i++){
		int A;
		cin>>A>>a[i];
		M=max(M,A);
	}
	sort(a.rbegin(),a.rend());
	for(int i=0;i<n;i++) if(a[i]>=M){
		h-=a[i];
		t++;
		if(h<=0){
			cout<<t<<endl;
			return 0;
		}
	}
	cout<<t+(h+M-1)/M<<endl;
}

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

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int N,T; cin >> N >> T;
	ll tot = 0;
	vi t(N);
	F0R(i,N) cin >> t[i];
	int l1 = -MOD, l2 = -MOD;
	F0R(i,N) {
		if (l2+T > t[i]) {
			l2 = t[i];
		} else {
			if (l1 != -MOD) tot += (l2+T-l1);
			l1 = t[i];
			l2 = t[i];
		}
	}
	tot += (l2+T-l1);
	cout << tot;
}

Measured memory_bytes: 1024
import math
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
import networkx as nx

import heapq
import sys

input = sys.stdin.readline


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

def dijkstra_heap(s,edge):
    #始点sから各頂点への最短距離
    d = [10**20] * N
    used = [True] * N #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    path = [-1] * N
    for a,b in edge[s]:
        path[b] = s
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:                
            if used[e[1]]:
                if path[e[1]] == -1:
                    path[e[1]] = v
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d, path

edge = [[] for i in range(N)]

for i in range(M):
    x,y = map(int,input().split())
    edge[x-1].append([1,y-1])
    edge[y-1].append([1,x-1]) 
    

d, path = dijkstra_heap(0, edge)

print("Yes")
for i in range(1,N):
    print(path[i]+1)

Measured memory_bytes: 113780
import java.io.*;
import java.util.*;

public class Main{
   public static void main(String[]args)throws IOException{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      int[] k = new int[10];

      for(int i=0; i < 10; i++)
      k[i] = Integer.parseInt(br.readLine());

      Arrays.sort(k); 


      for(int i=0; i<3; i++)
      System.out.println(k[9-i]);
   }
}

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

ll calc(string s,vector<char> &op){
  ll ans = s.at(s.size()-1) - '0';
  int digit = 0;
  for (int i=s.size()-2; i>=0; i--){
    if (op.at(i) == '+'){
      digit = 0;
      ans += s.at(i) - '0';
    }else{
      digit++;
      int keta = digit;
      ll buf = s.at(i) - '0';
      while(keta>0){
        keta--; buf *= 10;
      }
      ans += buf;
    }
  }
  return ans;
}

void solve(string s,vector<char> &op,ll &ans,int n){
  if (n==op.size()){
    ans += calc(s,op);
    return;
  }
  op.at(n) = '+'; solve(s,op,ans,n+1);
  op.at(n) = '-'; solve(s,op,ans,n+1);
  return;
}

int main() {
  string s; cin >>s;
  vector<char> op(s.size()-1);
  rep (i,s.size()-1) op.at(i) = '.';
  ll ans = 0;
  solve(s,op,ans,0);
  cout <<ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

class UnionFind {
public:
    vector<int> par;

    UnionFind(int n) : par(n, -1) {};

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

    int size(int x) {
        return -par[root(x)];
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (size(rx) < size(ry)) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }

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


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i, 0, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    reverse(all(a));
    reverse(all(b));

    vector<ll> ans(m);

    ans[0] = (ll)(n - 1) * n / 2;

    UnionFind uf(n);
    for (int i = 0; i <= m - 2; i++) {
        if (uf.same(a[i], b[i])) {
            ans[i + 1] = ans[i];
        } else {
            ans[i + 1] = ans[i] - (ll)uf.size(a[i]) * uf.size(b[i]);
            uf.unite(a[i], b[i]);
        }
    }

    reverse(all(ans));
    rep(i, 0, m) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int C = scanner.nextInt();
    long K = scanner.nextLong();
    if (K % 2 == 0) {
      System.out.println(A - B);
    } else {
      System.out.println(B - A);
    }
  }
}


Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long L = sc.nextLong();
		long R = sc.nextLong();

		final int divide = 2019;
		long ans =1000000000;

		if(R - L >= 2019)System.out.println(0);
		else {
			for(long i=L; i<R; i++) {
				for(long j =i+1; j<=R; j++) {
					ans = Math.min(ans, (i*j)%divide);
				}
			}
			System.out.println(ans);
		}
	}

}


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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

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

const int N = 100179;

int k, a[N];

int main() {
    scanf("%d", &k);
    for (int i = 0; i < k; ++i)
        scanf("%d", a+i);

    ll n1 = 2, n2 = 2;
    for (int i = k - 1; i >= 0; --i) {
        n2 = n2 / a[i] * a[i];
        n1 += a[i] - 1;
        n1 = n1 / a[i] * a[i];
        if (n1 > n2) {
            cout << "-1\n";
            return 0;
        }
        n2 += a[i] - 1;
    }
    cout << n1 << " " << n2 << "\n";

    return 0;
}


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

int main(){
    ll n, d, ans = 0, x, y;
    cin >> n >> d;
    while(n--){
        cin >> x >> y;
        if(pow(x, 2) + pow(y, 2) <= d*d){
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

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

    int rest = c - (a - b);
    if (rest < 0) {
        cout << 0 << endl;
    } else {
        cout << rest << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverseA(A.begin(),A.end());

typedef long long ll;

int main(){
  int H,A;
  cin >>H>>A;
  int ans = 0;
  while(H>0){
    H -= A;
    ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int n;
  	cin>>n;
  	vector<int> arr(n);
  	for(int i = 0;i<n;i++){
    	cin>>arr[i];
    }
    vector<vector<long long>> dp(n, vector<long long>(n));
  	for(int s = 1;s<=n;s++){
   		for(int i = 0;i<=n-s;i++){
        	int turn = (n-s)%2;
          	int j = i+s-1;
          	if(turn==0){
              	long long l = j>0 ? dp[i][j-1] + arr[j] : arr[j];
                long long r = i<n-1 ? dp[i+1][j] + arr[i] : arr[i];
            	dp[i][j] = max(l,r);  
            }
         	if(turn==1){
          		long long l = j>0 ? dp[i][j-1] - arr[j] : -arr[j];
                long long r = i<n-1 ? dp[i+1][j] - arr[i] : -arr[i];
            	dp[i][j] = min(l,r);  
           }
        }
      
    }
	cout<<dp[0][n-1]<<endl;
}

Measured memory_bytes: 73384
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin>>N;
  if(400<=N && N<=599) cout<<8<<endl;
  if(600<=N && N<=799) cout<<7<<endl;
  if(800<=N && N<=999) cout<<6<<endl;
  if(1000<=N && N<=1199) cout<<5<<endl;
  if(1200<=N && N<=1399) cout<<4<<endl;
  if(1400<=N && N<=1599) cout<<3<<endl;
  if(1600<=N && N<=1799) cout<<2<<endl;
  if(1800<=N && N<=1999) cout<<1<<endl;
  
}


Measured memory_bytes: 3636
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    long long ans,cnt,i,j,g;
    string s,t;
    ans=1000000;
    cin>>s>>t;
    for(i=0;i<s.length();i++)
    {
        cnt=0;g=5;
        for(j=0;j<t.length();j++)
        {
          if(i+j>=s.length()){g=0;break;}
            if(s[i+j]!=t[j]){cnt++;}
        }
      if(g==0){continue;}
        ans=min(ans,cnt);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int N;
  cin>>N;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];
  sort(all(A));
  ll X[3]={};
  int j=0;
  rep(i,N){
    if(i) if(A[i]!=A[i-1]){
      j++;
      if(j>=3) break;
    }
    X[j]++;
  }
  if(X[0]==N&&A[0]==0) cout<<"Yes"<<endl;
  else if(X[0]*2==X[1]&&X[2]==0&&A[0]==0&&A[N-1]!=0) cout<<"Yes"<<endl;
  else if(X[0]==X[1]&&X[0]==X[2]&&(X[0]+X[1]+X[2]==N)&&((A[0]^A[N/3])==A[N/3*2])&&A[0]!=0&&A[N/3]!=0&&A[N/3*2]!=0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<string,int>Psi;

int main(){
  int n,m;
  cin>>n>>m;
  int l,r;
  int abs_r,abs_l;
  vector<int> v;
  vector<int> w;
  REP(i,m){
    int tmp;
    cin>>tmp;
    v.push_back(tmp);
  }
  sort(ALL(v));
  REP(i,m-1){
    w.push_back(v[i+1]-v[i]);
  }
  //sort(ALL(v));
  sort(ALL(w));
  if(n>=m){
    cout<<0<<endl;
    return 0;
  }
  int sum=v[m-1]-v[0];
  n-=2;
  while(n>=0){
    //cout<<sum<<" "<<w.back()<<endl;
    sum-=w.back();
    w.pop_back();
    n--;
  }

  cout<<sum<<endl;
}

Measured memory_bytes: 1400
// C - City Savers
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);

	int n;
	cin >> n;
	vector<long long> a(n + 1), b(n);
	for (int i = 0; i < n + 1; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	long long ans = 0, t;
	for (int i = 0, j = n; i < j; i++, j--) {
		t = min(a[i], b[i]);
		b[i] -= t;
		a[i] -= t;
		ans += t;
		t = min(a[i + 1], b[i]);
		b[i] -= t;
		a[i + 1] -= t;
		ans += t;
		t = min(a[j], b[j - 1]);
		b[j - 1] -= t;
		a[j] -= t;
		ans += t;
		t = min(a[j - 1], b[j - 1]);
		b[j - 1] -= t;
		a[j - 1] -= t;
		ans += t;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <math.h> 
using namespace std;
int main(){
  int n, x, ans;
  int m[110];
  cin >> n >> x;
  int total = 0;
  for(int i = 0; i < n; i++){
    cin >> m[i];
    total += m[i];
  }

  sort(m, m + n);
  ans = (x - total)/m[0] + n;
  cout << ans << endl;
}

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

int main(void){
 int N, M, C;
  cin >> N >> M >> C;
  long long SUM = 0;
  int count = 0;
  vector<int> B(M);
  for(int i = 0; i < M; i++){
    cin >> B[i];
  }
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M; j++){
      int A;
      cin >> A;
      SUM += A * B[j];
    }
    if(SUM + C > 0) count++;
    SUM = 0;
  }
  
  cout << count;
  return 0;
}

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

char getch()
{
    static char buf[1<<14],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<14,stdin),p1==p2)?EOF:*p1++;
}

void read(int &x)
{
    x=0;
    char c=getch();
    while(c<'0'||c>'9') c=getch();
    while(c>='0'&&c<='9')
    {
        x=(x<<1)+(x<<3)+(c-'0');
        c=getch();
    }
}

int n,sum,m,p,x;
int a[101];

int main()
{
    read(n);
    for(int i=1;i<=n;++i)
    {
        read(a[i]);
        sum+=a[i];
    }
    read(m);
    while(m--)
    {
        read(p);read(x);
        printf("%d\n",sum-a[p]+x);
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力                                                                                                  
        int N = sc.nextInt();
	int S=0;
	int i,l,r;
	for(i=0;i<N;i++){
            l =	sc.nextInt();
            r =	sc.nextInt();
            S=S + r - l + 1;
        }

        System.out.println(S);
    }
}




Measured memory_bytes: 25556
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int N;
string S;
int dp[200000][2];   //黒:0、白:1

void solve() {
	cin >> N >> S;
	if (S[0] == '.') dp[0][0] = 1, dp[0][1] = 0;
	else dp[0][0] = 0, dp[0][1] = 1;
	for (int n = 1; n < N; n++) {
		if (S[n] == '.') {
			dp[n][0] = min(dp[n-1][0],dp[n-1][1]) + 1;
			dp[n][1] = dp[n - 1][1];
		}
		else {
			dp[n][0] = min(dp[n - 1][0], dp[n - 1][1]);
			dp[n][1] = dp[n-1][1] + 1;
		}
	}
	cout << min(dp[N-1][0],dp[N-1][1]) << endl;
	return;
}

Measured memory_bytes: 2180
#include <stdio.h>
#include <math.h>

struct Point{
	double x;
	double y;
};

Point roll(Point div1,Point div2){
	Point tmp_start = { div2.x-div1.x,div2.y-div1.y };
	Point tmp_end = { tmp_start.x*cos(M_PI/3) -tmp_start.y*sin(M_PI/3),
			tmp_start.x*sin(M_PI/3) + tmp_start.y*cos(M_PI/3) };
	Point ret = { tmp_end.x + div1.x,tmp_end.y + div1.y };
	return ret;
}

void outPut(Point point){
	printf("%.8f %.8f\n",point.x,point.y);
}

void calc(Point left,Point right,int count){
	Point div1 = {	(2*left.x + right.x)/3,(2*left.y + right.y)/3 };
	Point div2 = {(2*right.x + left.x)/3,(2*right.y + left.y)/3	};
	Point peek = roll(div1,div2);

	if(count > 1){
		calc(left,div1,count-1);
		calc(div1,peek,count-1);
		calc(peek,div2,count-1);
		calc(div2,right,count-1);
	}else{
		outPut(left);
		outPut(div1);
		outPut(peek);
		outPut(div2);
	}
}

int main(){
	int n;
	Point left = {0,0},right = {100,0};
	scanf("%d",&n);
	if(n == 0){
		outPut(left);
		outPut(right);
	}else{
		calc(left,right,n);
		outPut(right);
	}
}



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

int main() {
    std::string S;
    std::cin >> S;

    if (S == "AAA" || S == "BBB") {
        std::cout << "No" << std::endl;
    } else {
        std::cout << "Yes" << std::endl;
    }
    return 0;
}

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

const long long N = 3e6 + 17;
ll a[N], b[N], cnt, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[N];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> m;
    if(n > m)
    {
        cout << n - 1;
        return 0;
    }
    cout << n;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define MOD2 (lli) 998244353  
#define lli long long int
#define sz(a) int(a.size())
#define M_PI 3.1415
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 
  lli a, b;
  cin >> a >> b;

  lli atual = (a+b)/2;

  for(lli i = atual-10; i<= atual+10;i++){
    if(abs(a-i) == abs(b-i)){
      cout << i << endl;
      return 0;
    }
  }

  cout << "IMPOSSIBLE" << endl;

  return 0;
}

Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val S = next()
    val T = next()
    fun match(s: String, t: String): Boolean {
        for (n in 0 until T.length)
            if (s[n] != '?' && s[n] != t[n]) return false
        return true
    }
    var ans = mutableListOf<String>()
    for (n in 0 until S.length - T.length + 1)
        if (match(S.substring(n until n + T.length), T)) {
            val SS = S.map { it }.toCharArray()
            for (m in 0 until T.length) SS[n + m] = T[m]
            for (m in 0 until S.length) if (SS[m] == '?') SS[m] = 'a'
            ans.add(SS.joinToString(""))
        }
    if (ans.size == 0) return println("UNRESTORABLE")
    println(ans.sorted().first())
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(d: Int = 0) = listOfString().map { Integer.parseInt(it) + d }
fun listOfLong() = listOfString().map(String::toLong)


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

public class Main {
	public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] ab=reader.readLine().split(" ");
        int a=Integer.parseInt(ab[0]);
        int b=Integer.parseInt(ab[1]);
        int c=Integer.parseInt(ab[2]);
        
        if(a<b && b<c){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
	}
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
int n; cin>>n;
set<string> s;
while (n--) {
string x; cin>>x;
s.insert(x);
}
out(s.size());
  

    return 0;
}


Measured memory_bytes: 19252
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll F[2100010];

ll Mul(ll a,  ll b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
ll square(ll x) {
	return (x * x) % mod;
}

ll power(ll x, ll y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

ll Div(ll a, ll b) {
	return Mul(a, power(b, mod - 2));
}
ll P(ll n, ll r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

ll C(ll n, ll r) {
	if (n < r || n < 0 || r < 0) return 0;
	ll ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}

int main()
{
	int X, Y;
	cin >> X >> Y;
	if ((X + Y) % 3 != 0 || abs(X - Y) > (X + Y) / 3) {
		cout << 0 << endl;
	}
	else {
		if (abs(X - Y) > (X + Y) / 3) {
			cout << 0 << endl;
			return 0;
		}
		fact();
		int n = (X + Y) / 3;
		int r = (n - abs(X - Y)) / 2;
		//cout << n << " " << r << endl;
		cout << C(n, r) << endl;
	}
}

Measured memory_bytes: 16640
#include <iostream>

using namespace std;

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

    int* mem = new int[n];
    for(int i = 0; i < q; ++i) {
        int buf;
        cin >> buf;
        ++mem[buf - 1];
    }

    for(int i = 0; i < n; ++i) {
        if(k - q + mem[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    delete mem;
  	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define N 110
using namespace std;
int n;
int a[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int ma=a[n];
	for(int i=ma;i>=ma-ma/2;i--){
		int tot=2;
		if((ma/2)*2==ma) tot--;
		for(int j=1;j<=n;j++){
			if(!tot) break;
			if(a[j]==i){
				a[j]=0;
				tot--;
			}
		}
		if(tot){
			puts("Impossible");
			exit(0);
		}
	}
	for(int i=ma;i>=ma-ma/2+1;i--){
		for(int j=1;j<=n;j++)
			if(a[j]==i)
				a[j]=0;
	}
	for(int i=1;i<=n;i++){
		if(a[i]){
			puts("Impossible");
			exit(0);
		}
	}
	puts("Possible");
	return 0;
}

Measured memory_bytes: 256
//Author : Siriuslight
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0),cout<<setprecision(10)<<fixed;
#define int long long
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const ll inf = 1e9+100, N = 2e5+5;
const ll INF = 1e18+100, MOD = 1e9+7;

ll powmod(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
ll power(ll a,ll b){ll r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
ll gcd(ll a,ll b){if(!b)return a;return gcd(b,a%b);}
ll inv(ll a, ll m = MOD){return powmod(a,m-2,m);}
ll lcm(ll a,ll b){return(a*b)/gcd(a,b);}

//ordered_set X;
//X.insert(3);
//X.order_of_key(3) no of elements less than 3
//*X.find_by_order(n) nth greatest element(0-indexed)

int n, a[N], dp[N], k;

int solve(int id){
    if(id >= n)
        return 0;
    int &res = dp[id];
    if(res != -1) return res;
    res = inf;
    for(int i = 1; id + i <= n && i <= k; ++i){
        res = min(res, abs(a[id] - a[id + i]) + solve(id + i));
    }
    return res;
}
int32_t main(){
    FIO;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    memset(dp, -1, sizeof(dp));
    cout << solve(1);
}


Measured memory_bytes: 7296
import sys
n = int(input())
ans = 1
s = input()
a = [int(x.strip()) for x in s.split(' ')]
if 0 in a:
  print(0)
  sys.exit()
for i in range(n):
  ans *= a[i]
  if ans>1000000000000000000:
    print(-1)
    sys.exit()
print(ans)


Measured memory_bytes: 23752
#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() {
    int A, B; cin >> A >> B;
    int ans = 0, no = 1;
    while(no < B) {
        no += A - 1;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 10000
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll unsigned long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)	for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define form(l, r, i)	for(int i = l; i <= r; ++i)
#define forv(r, l, i)	for(int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
 
const int inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modw = 1e9 + 7;
 
using namespace std;

int main()
{
	barnarnar
	string a;
	cin >> a;
	int d;
	cin >> d;
	vector<vector<ll> > dp(d, vector<ll>(2)); // dp[sum][is_smaller] - 'sum' - sum of digits we chosen and 'is_smaller' then k
	int k = a.si;
	dp[0][0] = 1;
	for(int len = 0; len < k; len++) // len of cur number
	{
		vector<vector<ll> > new_dp(d, vector<ll>(2));
		for(int sum = 0; sum < d; sum++)
		{
			for(bool sm : {false, true})
			{
				for(int digit = 0; digit <= 9; digit++)
				{
					if(digit > a[len] - '0' && !sm)	break;
					new_dp[(sum + digit) % d][sm || (digit < a[len] - '0')] += dp[sum][sm];
					new_dp[(sum + digit) % d][sm || (digit < a[len] - '0')] %= modw;
				}
			}
		}
		dp = new_dp;
	}
	ll ans = (dp[0][0] + dp[0][1]) % modw;
	ans--;
	if(ans == -1)	ans = modw - 1;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iterator>

using namespace std;

struct v {
  vector<int> tos;
  int counter;
};

int main() {

  int n,q;
  cin >> n >> q;
  vector<v> vs(n+1, {vector<int>(), 0});
  
  for (int i = 0; i < n-1; i++) {
    int a,b;
    cin >> a >> b;
    vs[a].tos.emplace_back(b);
  }
  
  int p,x;
  for (int i = 0; i < q; i++) {
    cin >> p >> x;
    vs[p].counter += x;
  }
  
  stack<int> s;
  s.push(1);
  while (s.size() > 0) {
    const auto current = s.top();
    s.pop();
    
    for (const auto& to : vs[current].tos) {
      vs[to].counter += vs[current].counter;
      s.push(to);
    }
  }
  
  for (int i = 1; i <= n; i++) {
    cout << vs[i].counter;
    if (i==n) {
      cout << endl;
    } else {
      cout << " ";
    }
  }

  return 0;
}


Measured memory_bytes: 14848
#include <stdio.h>
int main()
{
	int h, w, i, j, p;
	scanf("%d %d", &h, &w);
	while (h != 0 || w != 0)
	{
		for (i = 0; i < h; i++)
		{
			if (i == 0 || i == h - 1)
			{
				for (j = 0; j < w; j++)
					printf("#");
				printf("\n");
			}
			else
			{
				printf("#");
				for (p = 0; p < w - 2; p++)
					printf(".");
				printf("#\n");
			}
		}
		printf("\n");
		scanf("%d %d", &h, &w);
	}
}


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

int n, m = 1;
string s;

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

	for (int i = 1; i < n; i++)
		if (s[i - 1] != s[i])
			m++;

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+7;
const int maxm=19;
typedef long long ll;
ll go[maxn][2*maxm];
ll last[maxn][2*maxm];
ll N[maxn];
int n,q;
void init()
{
	for(int i=n+1;i>=1;i--)
		for(int j=0;j<maxm;j++)
			go[i][j]=last[i][j]=n+1;
	for(int i=n;i>=1;i--)
	{
		for(int j=0;j<=maxm;j++)
		{
			if((N[i]>>j)&(1))
			{
				last[i-1][j]=i;
				//cout<<"i-1: "<<i-1<<"j: "<<j <<" "<<last[i-1][j]<<endl;
			}
			else last[i-1][j]=last[i][j];
			//cout<<"i-1: "<<i-1<<"j: "<<j <<" "<<last[1][0]<<endl;
		}
	}
	//cout<<last[1][0]<<endl;
	for(int i=n;i>=1;i--)
	{
		for(int j=0;j<=maxm;j++)
		{
			if((N[i]>>j)&(1))
			{
				for(int k=0;k<=maxm;k++)
				{
					go[i][k]=min(go[i][k],go[last[i][j]][k]);
				}
				go[i][j]=i;
			}
		}
	}
}
int main()
{
	cin>>n>>q;
	cout<<(n*3+q)/2<<endl;
}

Measured memory_bytes: 256
H,W,N=map(int,input().split())
s=set()
for i in range(N):
    a,b=map(lambda x:int(x)-1,input().split())
    s.add((a,b))
count=[0]*10

for x,y in s:
    for tx in range(x-2,x+1):
        for ty in range(y-2,y+1):
            if tx<0 or ty<0 or tx+2>=H or ty+2>=W:
                continue
            cnt=0
            for nx in range(tx,tx+3):
                for ny in range(ty,ty+3):
                    if (nx,ny) in s:
                        cnt+=1
            count[cnt]+=1
count=[0]+[count[i]//i for i in range(1,10)]
count[0]=(H-2)*(W-2)-sum(count)
print(*count,sep='\n')

Measured memory_bytes: 89720