akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int n;
    int r = 0,min = 0;
    VI rate(8);
    cin >> n;
    REP(i,n){
        int a;
        cin >> a;
        if(a < 3200) {
            rate[a / 400] = 1;
        }else r++;
    }
    REP(i,8){
        min += rate[i];
    }
    if(min == 0){
        cout << 1 << " " << r << endl;
    }else{
        cout << min << " " << min + r << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	char ch[8][8],hoge[8][8];
	rep(i,8)rep(j,8)cin>>ch[i][j];
	rep(p,3){
		if(p==0)cout<<"90"<<endl;
		if(p==1)cout<<"180"<<endl;
		if(p==2)cout<<"270"<<endl;
		rep(i,8)rep(j,8)hoge[i][j]=ch[8-j-1][i];
		rep(i,8){
			rep(j,8){cout<<hoge[i][j];ch[i][j]=hoge[i][j];}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1136
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int d,g,i,j,k;
    long long ans = 100000000;
    cin >> d >> g;
    vector<int> p(d);
    vector<int> c(d);
    for(i=0;i<d;i++) cin >> p[i] >> c[i];
    for(i=0;i<(1<<d);i++){
        long long tmp=0;
        int cnt = 0;
        for(j=0;j<d;j++){
            if(i&(1<<j)){
                tmp = tmp + 100*(j+1)*p[j]+c[j];
                cnt += p[j];
            }
        }
        if(tmp>=g){
            if(cnt<ans) ans = cnt;
        }
        else{
            for(j=d-1;j>=0;j--){
                if(i&(1<<j)) continue;
                else{
                    for(k=0;k<p[j];k++){
                        if(tmp>=g) break;
                        tmp = tmp + 100*(j+1);
                        cnt++;
                    }
                }
            }
            if(cnt<ans) ans = cnt;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << 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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll n,k; cin>>n>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    /*
    if (k == 0) {
        cout << *max_element(a.begin(), a.end()) << '\n';
        return 0;
    }
    */

    auto check = [&] (ll x) -> bool {
        ll ret = 0;
        rep(i,n) {
            if (a[i] != x) ret += a[i]/x;
        }
        if (ret <= k) return true;
        else return false;
    };

    auto binary_search = [&] () -> ll {
        ll ok = LINF; ll ng = 0ll;
        while (abs(ok-ng) > 1) {
            ll mid = (ok+ng)/2;
            if (check(mid)) ok = mid;
            else ng = mid;
        }
        return ok;
    };

    ll ans = binary_search();
    cout << ans << '\n';

    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  
  ll a[n];
  rep(i,n)
  {
    cin >> a[i];
  }

  int gc = a[0];
  rep(i,n)
  {
    gc = gcd(a[i],gc);
  }
  
  cout << gc << endl;
}


Measured memory_bytes: 4316
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ld long double


#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(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}

typedef long long int ll;
#define int ll
#define endl '\n'
const ll mod =1e9+7;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll inf = 1e18+123;
const int maxn = 2000001;
int32_t main()
{

   IOS
   ll x;
   cin>>x;
   ll y = 100;
    for(int i = 1;i<=10000;i++){
      int rate = y/100;
      y+=rate;
      if(y>=x)
      {
        cout<<i<<endl;
        return 0;
      }
    }
  
} 


Measured memory_bytes: 3644
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main(void){
  int x,y;
  int res=0;
  scanf("%d %d",&x,&y);

  if(x>0&&y>0&&x<y){
    res=y-x;
  }
  else if(x>0&&y>0&&x>y){
    res=x-y+2;
  }
  else if((x>0&&y<0)||(x<0&&y>0)){
    res=abs(abs(x)-abs(y))+1;
  }
  else if(x<0&&y<0&&x<y){
    res=y-x;
  }
  else if(x<0&&y<0&&x>y){
    res=x-y+2;
  }
  else if(x==0){
    if(y>0) res=y;
    else res=abs(y)+1;
  }
  else if(y==0){
    if(x>0) res=x+1;
    else res=abs(x);
  }
  printf("%d\n",res);
  return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <cstring>
#define maxn (ll)1e5+10
using namespace std;
typedef long long ll;
int n,fa[maxn];
bool color[maxn];
vector<int> map[maxn];
int du[maxn];
void dfs(int u,int p) {
	fa[u]=p;
	bool t=false;
	for (int i=0;i<map[u].size();i++) {
		int v=map[u][i];
		if (v==p)
			continue;
		t=true;
		dfs(v,u);
	}
}
int main() {
	//freopen("1.txt","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<n;i++) {
		int a,b;
		scanf("%d %d",&a,&b);
		map[a].push_back(b);
		map[b].push_back(a);
		du[a]++;
		du[b]++;
	}
	dfs(1,0);
	memset(color,0,sizeof(color));
	color[0]=1;
	for (int i=1;i<=n;i++) {
		bool t=false;
		for (int j=1;j<=n;j++)
			if (!color[j]&&!color[fa[j]]&&du[j]==1) {
				color[j]=1;
				color[fa[j]]=1;
				du[j]=0;
				du[fa[j]]=0;
				for (int k=0;k<map[fa[j]].size();k++)
					du[map[fa[j]][k]]--;
				t=true;
			}
		if (!t)
			break;
	}
	/*
	for (int i=1;i<=n;i++)
		printf("%d %d\n",i,color[i]);
	*/
	bool ans=false;
	for (int i=1;i<=n;i++)
		if (!color[i]) {
			ans=true;
			break;
		}
	if (ans)
		printf("First\n");
	else printf("Second\n");
	return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main(void)
{
    int a;
    string s;
    cin >> a >> s;
    cout << (a >= 3200 ? s.c_str() : "red") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int s[5];
int main()
{
	for(int i = 0; i < 4; i++) {
		scanf("%1d", &s[i]);
	}
	if(s[0] == s[1] && s[1] == s[2] || s[1] == s[2] && s[2] == s[3]){
		cout << "Yes";
	}else {
		cout << "No";
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long x = scan.nextLong();
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextLong();
        }
        Arrays.sort(a);
        int answer = 0;
        for (int i = 0; i < N - 1; i++) {
            if (a[i] <= x) {
                answer += 1;
                x -= a[i];
                continue;
            }
            break;
        }
        if (a[N-1] == x) {
            answer += 1;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 22612
/*  AC祈願アンコウ
   　／￣＼
   ○    ／￣￣￣＼ヘ
    　 /・　 ・　 ＼>   
    ／￣￣￣＼　　  Ｖ| 
   ｜  ―――  ｜      ｜|
    ＼＿＿＿／　　  ∧|
    　　＼　　　　／
    　　　￣￣￣￣
*/

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

typedef int64_t ll;
//static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
#define YesNo(x) puts((x)?"Yes":"No")

signed main(){
    int n,x;
    cin >> n >> x;

    int ans = 0;
    int a[114514];
    REP(i,n) scanf("%lld",&a[i]);

    REP1(i,n-1){
        if(a[i-1]+a[i]>x){
            if(a[i-1]>x){
                ans += a[i-1] - x + a[i];
                a[i-1] = x;
                a[i] = 0;
            } else {
                ans += a[i] - (x-a[i-1]);
                a[i] = x - a[i-1];
            }
        }
    }
    printf("%lld\n",ans);

    return 0;
}

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

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; int k;
    cin >> n >> k;
    
    array<int, 100000> stone;
    for (int i =0; i<n; i++){
        int x; cin >>x;   
        stone[i] = x; 
    }

    array<int,100000> dp; 
    dp.fill(2147483647);
    dp[0] = 0;
    
    for (int i = 0; i<n; i++){
        for(int j=i+1; j<i+k+1; j++){
            if (j<n){
                dp[j] = min(dp[j], dp[i]+abs(stone[i]-stone[j]));
            }
        }
    }
    
    cout << dp[n-1];
}

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

using namespace std;

int main() {
    string str;
    int n;
    cin >> str >> n;
    int result = 0;
    for (int i = 0; i < n; ++i) {
        string temp;
        cin >> temp;
        temp += temp;
        if (temp.find(str) == string::npos) continue;
        result++;
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 1212
#!venv/bin/python

# N, K = [ int(x) for x in input().split() ]
S = input()

def is_yymm(str):
    _yy = int(str[0:2])
    mm = int(str[2:4])
    return (1 <= mm and mm <= 12)

def is_mmyy(str):
    mm = int(str[0:2])
    _yy = int(str[2:4])
    return (1 <= mm and mm <= 12)

if is_yymm(S) and is_mmyy(S):
    print ("AMBIGUOUS")
elif is_yymm(S):
    print ("YYMM")
elif is_mmyy(S):
    print ("MMYY")
else:
    print("NA")


Measured memory_bytes: 3060
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n, m = MI()
    A = LI()

    sm = sum(A)
    if n - sm >= 0:
        print(n - sm)
    else:
        print(-1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 10056
#include<stdio.h>
int main(){

   int a,b,c;

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

   if((a + b) == c || (b + c) == a || (a + c) == b){
      printf("Yes\n");
   }else{
      printf("No\n");
   }

   return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void){
  int N, A, B;
  cin >> N >> A >> B;
  //入力終了

  int ans = 0;
  
  //1以上N以下の全探索
  for(int n=1; n<=N; n++){
    int tmp = n;
    int sum = 0;
    //各桁の和を計算
    while(tmp != 0){
      sum += tmp%10;
      tmp /= 10;
    }
    //各桁の和がA以上B以下
    if(A<=sum && sum<=B)
      ans += n;
  }

  //解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3556
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


N = int(input())
ans = 0
# print(factorization(N))
for num, count in factorization(N):
    if num == 1:
        continue
    this_count = count
    start_x = 1
    while this_count - start_x >= 0:
        this_count -= start_x
        ans += 1
        start_x += 1
print(ans)


Measured memory_bytes: 63252
import numpy as np
N = int(input())
H = np.array(list(map(int,input().split())))

ans = 0
while np.max(H) != 0:

    min_h_p = 0
    st = -1
    for i in range(N):
        if st == -1:
            if H[i] > 0:
                st = i
            if i == N-1:
                ans += H[i]
                H[i] = 0
                break
        elif H[i] == 0:
            min_h_p = min(H[st:i])
            ans += min_h_p
            H[st:i] -= min_h_p
            break
        elif i == N-1:
            min_h_p = min(H[st:])
            ans += min_h_p
            H[st:] -= min_h_p
            break
print(ans)


Measured memory_bytes: 12484
#include <stdio.h>
#include <stdlib.h>

int main()
{
	long long a, b, c;
	scanf("%lld %lld %lld", &a, &b, &c);
	
	if (c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b)) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>

using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

string s;
string test[4]={"dream","dreamer","erase","eraser"};


int main(){
	cin>>s;
	bool f =true;
		while(!s.empty()){
			if(s.substr(0,5)==test[0]){
				if(s.substr(0,7)==test[1]){
					if(s[7]=='a'){
						s.erase(s.begin(),s.begin()+5);
					}
					else{
						s.erase(s.begin(),s.begin()+7);
					}
				}
				else{
					s.erase(s.begin(),s.begin()+5);
				}
			}
			else if(s.substr(0,5)==test[2]){
				if(s[5]=='r'){
					s.erase(s.begin(),s.begin()+6);
				}
				else s.erase(s.begin(),s.begin()+5);
			}
			else{
				f =false;
				break;
			}
		}
		
		if(f){
			cout<<"YES"<<endl;
		}
		else cout<<"NO"<<endl;
	
	  return 0;
  }

Measured memory_bytes: 512
while True:
    i = input()
    H, W = map(int,i.split())
    
    if H == 0 and W == 0:
        break
    
    for h in range(H):
        for w in range(W):
            if h == 0 or h == H-1 or w == 0 or w == W-1:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


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

int main(){
    ll INF = 10000000000000;
    int n;
    cin >> n;
    vector<ll> a(n+1);
    for(int i = 0; i < n+1; i++) cin >> a[i];

    vector<ll> ma(n+1);

    ll num_m = 1;
    for(int i = 0; i < n+1; i++){
        ma[i] = num_m - a[i];
        if(ma[i] < 0){
            cout << -1;
            return 0;
        }
        num_m = min(ma[i]*2, INF);
    }
    
    ll num_before = a[n];

    vector<ll> num_b(n);
    for(int i = n-1; i >= 0 ; i--){
        num_b[i] = min(num_before, ma[i]);
        num_before = num_b[i] + a[i];
    }

    ll num_all=a[n];
    for(int i= 0; i < n; i++){
        num_all += num_b[i] + a[i];
    }
    cout << num_all;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=405;
const int mod=998244353;
int n,suma,sumb,ans;
int a[maxn],b[maxn],f[maxn][maxn],g[maxn][maxn],h[maxn][maxn],nf[maxn][maxn],inv[maxn],fac[maxn],ifac[maxn];
int C(int a,int b){
	if(a<b||a<0||b<0)return 0;
	return 1LL*fac[a]*ifac[b]%mod*ifac[a-b]%mod;
}

int main(){
	scanf("%d",&n);
	fac[0]=fac[1]=ifac[0]=ifac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=400;i++){
		fac[i]=1LL*fac[i-1]*i%mod;
		inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod;
	}
	REP(i,400)ifac[i]=1LL*ifac[i-1]*inv[i]%mod;
	rep(i,401)g[i][0]=fac[i];
	REP(i,400)REP(j,400)g[i][j]=(1LL*g[i-1][j]*i+g[i-1][j-1])%mod;
	f[0][0]=1;
	rep(i,n){
		scanf("%d%d",&a[i],&b[i]);
		rep(j,suma+1)rep(k,sumb+1){
			int cur=f[j][k];
			if(!cur)continue;
			nf[j+a[i]][k]+=cur;
			if(nf[j+a[i]][k]>=mod)nf[j+a[i]][k]-=mod;
			int mul=1;
			rep(t,b[i]){
				nf[j][k+t]-=1LL*cur*mul%mod*ifac[t]%mod;
				if(nf[j][k+t]<0)nf[j][k+t]+=mod;
				mul=1LL*mul*a[i]%mod;
			} 
		}
		suma+=a[i];
		sumb+=b[i];
		rep(j,suma+1)rep(k,sumb+1)f[j][k]=nf[j][k],nf[j][k]=0;
	}
	rep(a,suma){
		h[a][0]=1LL*suma*inv[suma-a]%mod;
		REP(k,sumb){
			rep(j,k){
				h[a][k]+=1LL*h[a][j]*C(k,j)%mod;
				if(h[a][k]>=mod)h[a][k]-=mod;
			}
			h[a][k]=1LL*h[a][k]*a%mod*inv[suma-a]%mod; 
		}
	}
	rep(j,suma){
		int mul=1;
		rep(k,sumb+1){
			if(j){
				rep(t,k+1){
					ans-=1LL*g[k][t]*h[j][t]%mod*f[j][k]%mod*mul%mod;
					if(ans<0)ans+=mod;
				}
			}
			else{
				ans-=1LL*fac[k]*f[j][k]%mod*mul%mod;
				if(ans<0)ans+=mod;
			}
			mul=1LL*mul*inv[suma]%mod;
		}
	} 
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n, k; cin >> n >> k;
  ll ans = 0;
  if(k == 0){
    cout <<  (ll)n*n << endl;
    system("pause");
    return 0;
  }
  for(int i = 1; i <= n; i++){
    ans += ((n/i) * max(0, i-k)) +  max(0, (n%i)-k+1);
  }//0 1 2 0 1 2
  cout << ans << endl;
  system("pause");
}


Measured memory_bytes: 504
#include <stdio.h>
#include <string.h>
char a[50];
char t[50];
int main()
{
  int n,r,p,c,i;
  for(;;){
    scanf("%d%d",&n,&r);
    if(n==0 && r==0) break;
    for(i=0;i<n;i++){
      a[i] = n-i;
    }
    for(i=0;i<r;i++){
      scanf("%d%d",&p,&c);
      memcpy(t,a,p+c-1);
      memcpy(a,&t[p-1],c);
      memcpy(&a[c],t,p-1);
    }
    printf("%d\n",a[0]);
  }
  return 0;
}

Measured memory_bytes: 0
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class FManySlimes {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N;
        in >> N;
        int num = 1 << N;
        vector<int> S(num);
        REP(i,0,num) {
            in >> S[i];
            S[i] *= -1;
        }
        multiset<int> slimes(all(S)), created;
        created.insert(*slimes.begin());
        slimes.erase(slimes.begin());

        REP(i,0,N) {
            vector<int> candidates;
            for (const int slime : created) {
                const auto itr = slimes.upper_bound(slime);
                if (itr == slimes.end()) {
                    out << "No" << "\n";
                    return;
                }
                candidates.push_back(*itr);
                slimes.erase(itr);
            }
            for (const int candidate : candidates) created.insert(candidate);
        }
        out << "Yes" << "\n";
    }
};


int main() {
	FManySlimes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 14456
N = int(input())
W = [int(i) for i in input().split()]
Wsum = sum(W)
diff = Wsum - 2*W[0]
if diff > 0 :
    for i in range (N-1):
        diff -= 2*W[1+i]
        if diff < 0:
            print(min(abs(diff),abs(diff+2*W[1+i])))
            break
        elif i == N-2:
            print(diff)
else:
    print(abs(diff))

Measured memory_bytes: 3064
def x():
	return map(int,input().split())
v=list
c=abs
r=range
h,w=x()
p=v(r(h))
a=[v(x())for i in p]
b=[v(x())for i in p]
m=13120
D=[[[0]*m for i in r(w)]for i in p]
for i in p:
	for j in r(w):
		k=c(a[i][j]-b[i][j])
		if i|j:
			for l in r((i+j+1)*80+1):
				e=c(l-k)
				D[i][j][l]=D[i][j-1][e]|D[i][j-1][l+k]|D[i-1][j][e]|D[i-1][j][l+k]
		else:
			D[i][j][k]=1
print(D[-1][-1].index(1))

Measured memory_bytes: 691464
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin, n, m;
    //print(n, m);
    int half = n / 2;
    REP(i, 0, m) {
        int x = half - i;
        int y = half + i + 1;
        if (n % 2 == 0 && y - x >= n - y + x) {
            y++;
        }
        print(x, y);
    }
    return 0;
}


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


int main(){
  int x,a,b;
  cin >> x >> a >>b;
    if(b-a<=0){
      cout <<"delicious" << endl;
    }
    else if(b-a<=x){
      cout <<"safe" << endl;
    }
    else {
      cout <<"dangerous" << endl;
    }
}


Measured memory_bytes: 256
N, x = map(int, input().split())
A = list(map(int, input().split()))

total = 0
for i in range(1, len(A)):
    diff = A[i-1] + A[i] -x
    if diff <= 0:
        continue
    if diff <= A[i]:
        A[i] -= diff
    else:
        A[i-1] -= diff - A[i]
        A[i] = 0
    total += diff

print(total)

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

using namespace std;
typedef long long ll;
int main()
{
    ll n;
    string str;
    cin>>n;
    cin>>str;
    ll ans=0;
    for(ll i=0;i<n-2;i++)
    {
        if(str[i]=='A'&&str[i+1]=='B'&&str[i+2]=='C')
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

s = input()

m = {}
m[0] = 0
index = 0
for i in range(20):
    minx = 10 ** i
    maxx = 10 ** (i + 1) - 1
    F_num = maxx // 3 - minx // 3
    B_num = maxx // 5 - (minx - 1) // 5
    FB_num = maxx // 15 - minx // 15
    P_num = maxx - minx - F_num - B_num + FB_num + 1
    m[i + 1] = m[i] + P_num * (i + 1) + F_num * 4 + B_num * 4
    if s < m[i + 1]:
        s -= m[i]
        index = i + 1
        break

#print index
ans = []
rem = 0

for i in range(index - 1, -1, -1):
    rem *= 10
    lst = range(10)
    if rem == 0:
        lst = range(1, 10)
    for j in lst:
        minx = rem + j * (10 ** i)
        maxx = rem + (j + 1) * (10 ** i) - 1
        F_num = maxx // 3 - (minx - 1) // 3
        B_num = maxx // 5 - (minx - 1) // 5
        FB_num = maxx // 15 - (minx - 1) // 15
        P_num = maxx - minx - F_num - B_num + FB_num + 1
        S_num = P_num * (index) + F_num * 4 + B_num * 4
        #print minx, maxx
        #print S_num
        if s > S_num:
            s -= S_num
        else:
            rem += j
            break
S = ""
for num in range(rem, rem + 100):
    if num % 3 == 0:
        S += "Fizz"
    if num % 5 == 0:
        S += "Buzz"
    if num % 3 != 0 and num % 5 != 0:
        S += str(num)
print S[s - 1:s + 19]


Measured memory_bytes: 5004
x, y, a, b, c = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
xs = sorted(p, reverse = True)[:x] + sorted(q, reverse = True)[:y] + sorted(r, reverse = True)
print(sum(sorted(xs, reverse = True)[:x+y]))


Measured memory_bytes: 115948
#include<stdio.h>
int b[1000];
int c[1000];
int d[1000];
int e[1000];
int main(){
    int a;
    while(scanf("%d",&a),a){
        for(int i=0;i<a;i++)scanf("%d%d%d%d",b+i,c+i,d+i,e+i);
        int p,q,r,s;
        scanf("%d%d%d%d",&p,&q,&r,&s);
        bool ok=false;
        for(int i=0;i<a;i++){
            if(c[i]<=p&&d[i]<=q&&e[i]<=r&&4*c[i]+9*d[i]+4*e[i]<=s){
                ok=true;
                printf("%d\n",b[i]);
            }
        }
        if(!ok)printf("NA\n");
    }
}


Measured memory_bytes: 2704
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main() {
	int N;
	cin >> N;
	int a[110]={};
	int b;
	REP(i,N){
		cin >> a[i];
	}
	int cnt=0;
	FOR(i,1,N){
		if(a[i-1]==a[i]){ a[i]=MOD;cnt++; }
	}
	
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return is_prime
n=int(input())
prime=primes((10**5)+1)
memo=[0]*((10**5)+1)

for i in range(1,(10**5)+1,2):
    if prime[i]==True and prime[(i+1)//2]==True:
        memo[i]=1
      
from itertools import accumulate  
ac=list(accumulate(memo))
#print(ac)

for i in range(n):
    l,r=map(int,input().split())
    if l!=0:
        print(ac[r]-ac[l-1])
    elif l==0:
        print(ac[r])

Measured memory_bytes: 8124
SA=input()
SB=input()
SC=input()

CHECK="a"
countA=0
countB=0
countC=0
LA=len(SA)
LB=len(SB)
LC=len(SC)

for i in range(0,LA+LB+LC):
    if CHECK[i]=="a" and LA>countA:
        CHECK+=SA[countA]
        countA+=1
    elif CHECK[i]=="a" and LA==countA:
        print("A")
        break
    elif CHECK[i]=="b" and LB>countB:
        CHECK+=SB[countB]
        countB+=1
    elif CHECK[i]=="b" and LB==countB:
        print("B")
        break
    elif CHECK[i]=="c" and LC>countC:
        CHECK+=SC[countC]
        countC+=1
    elif CHECK[i]=="c" and LC==countC:
        print("C")
        break


Measured memory_bytes: 3064
#include<algorithm>
#include<bitset>
#include<iostream>
#include<iomanip>
#include<set>
#include<string>
#include<math.h>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;

//--------------
//#define DEBUG
//--------------

#ifdef DEBUG
	#define debugprint(x) cout<<x<<" "
	#define debugendl cout<<endl
	#define debug(x) x
#else
	#define debugprint(x)
	#define debugendl
	#define debug(x)
#endif

class zahyo{
	public:
	int x;
	int y;
	zahyo(){
		x=0;
		y=0;
	}
	zahyo(int x_,int y_){
		x=x_;
		y=y_;
	}
	void print(){
		cout<<x<<" "<<y;
	}
	zahyo operator+(zahyo add){
		add.x=this->x+add.x;
		add.y=this->y+add.y;
		return add;
	}
	zahyo operator-(zahyo add){
		add.x=this->x-add.x;
		add.y=this->y-add.y;
		return add;
	}
	zahyo operator*(int t){
		zahyo temp;
		temp.x=this->x*t;
		temp.y=this->y*t;
		return temp;
	}
	zahyo operator%(int t){
		zahyo temp(this->x%t,this->y%t);
		return temp;
	}
	zahyo operator/(int t){
		zahyo temp(this->x/t,this->y/t);
		return temp;
	}
	bool operator==(const zahyo add) const{
		if(add.x==this->x and add.y==this->y){return true;}
		else{return false;}
	}
	bool operator!=(const zahyo add) const{
		if(add.x==this->x or add.y==this->y){return false;}
		else{return true;}
	}
	bool operator<(const zahyo add) const{
		if(this->x<add.x){return true;}
		else if(this->x==add.x and this->y<add.y){return true;}
		else{return false;}
	}
	bool operator>(const zahyo add) const{
		if(this->x>add.x){return true;}
		else if(this->x==add.x and this->y>add.y){return true;}
		else{return false;}
	}
	void input(){
		cin>>x>>y;
	}
};

zahyo ways[4];

bool IsInBoard(int x,int maxx, int y,int maxy){
	if(x>=0 and x<maxx and y>=0 and y<maxy){
		return true;
	}
	else{
		return false;
	}
}

int main(){
	int fibo[45];
	fibo[0]=1;
	fibo[1]=1;
	for(int i=2;i<45;i++){
		fibo[i]=fibo[i-1]+fibo[i-2];
	}
	int n;cin>>n;
	cout<<fibo[n]<<endl;
	return 0;
}



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

namespace AGC020B {
    class Program {
        static void Main(string[] args) {
            int K = int.Parse(Console.ReadLine());
            int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            bool ok = true;
            if (input[K - 1] != 2) {
                ok = false;
            }
            long min = 2;
            long max = 3;
            for (int i = 1; i < K; i++) {
                if (!ok) {
                    break;
                }
                int num = input[K - 1 - i];
                if (num >= max * 2) {
                    ok = false;
                } else {
                    if (num > min) {
                        min = num;
                    } else {
                        min = (min + num - 1) / num * num;
                    }
                    max = (max / num) * num + (num - 1);
                }
            }
            if(min > max) {
                ok = false;
            }
            if (ok) {
                Console.WriteLine(min.ToString() + " " + max.ToString());
            } else {
                Console.WriteLine(-1);
            }
        }
    }
}


Measured memory_bytes: 24156
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int h, w;
  cin >> h >> w;

  int c[10][10];
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      cin >> c[i][j];
    }
  }

  vector<vector<int>> a(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }

  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        if (c[i][j] > c[i][k] + c[k][j]) {
          c[i][j] = c[i][k] + c[k][j];
        }
      }
    }
  }

  ll ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] != -1) {
        ans += c[a[i][j]][1];
      }
    }
  }

  cout << ans << ln;

  return 0;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using ll = long long int;
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> idx(n, 0);
    for(int i=0; i<n; i++){
        int val; cin >> val; val--;
        idx[val] = i;
    }
    reverse(idx.begin(), idx.end());
    multiset<int> ms{-1,-1,n,n};
    ll ans = 0;
    for(ll i=0; i<n; i++){
        if(i == 0){ms.insert(idx[i]); continue;}
        auto it = ms.lower_bound(idx[i]);
        ll R2 = *++it;
        ll R1 = *--it;
        ll L1 = *--it;
        ll L2 = *--it;
        ans += (L1 - L2) * (R1 - idx[i]) * (n-i);
        ans += (R2 - R1) * (idx[i] - L1) * (n-i);
        ms.insert(idx[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<string>
#include<queue>

using namespace std;
const long long INF=9223372036854775800;

int main(){
    int N;
    long long a[300000];
    cin>>N;
    for(int i=0;i<3*N;i++){
        cin>>a[i];
    }
    priority_queue<long long,vector<long long>,greater<long long> > queL;
    priority_queue<long long> queR;
    long long tmpL=0;
    long long tmpR=0;
    for(int i=0;i<N;i++){
        queL.push(a[i]);
        queR.push(a[2*N+i]);
        tmpL+=a[i];
        tmpR+=a[2*N+i];
    }
    long long ansL[300000];//ansL[i]でiまでの数列の上N個の和
    long long ansR[300000];//ansR[i]でi以上の数列の下N個の和
    ansL[N]=tmpL;
    ansR[2*N]=tmpR;
    for(int i=N+1;i<=2*N;i++){
        queL.push(a[i-1]);
        long long now=queL.top(); queL.pop();
        tmpL=tmpL+a[i-1]-now;
        ansL[i]=tmpL;
    }
    for(int i=2*N-1;i>=N;i--){
        queR.push(a[i]);
        long long now=queR.top(); queR.pop();
        tmpR=tmpR+a[i]-now;
        ansR[i]=tmpR;
    }
    long long ans=-INF;
    for(int i=N;i<=2*N;i++){
        ans = max(ans, ansL[i]-ansR[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9068
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll N,M,sum=0;

int main(){
    cin>>N>>M;
    ll X[M],dist[M-1];
    rep(i,M){
        cin>>X[i];
    }
    sort(X,X+M);
    rep(i,M-1){
        dist[i]=X[i+1]-X[i];
    }
    sort(dist,dist+M-1,greater<ll>());
    for(int i=0;i<min(N-1,M-1);i++){
        dist[i]=0;
    }
    rep(i,M-1){
        sum+=dist[i];
    }
    out(sum);
}


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



int main(){
    string s;
    cin>>s;
    if(s[1]=='R'){
        cout<<"ABC"<<endl;
    }
    else{
        cout<<"ARC"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define pb push_back
#define pii pair<int,int>
#define SZ(x) (int)x.size()
#ifdef __linux__
#define getchar getchar_unlocked
#endif
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=300010;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,f[N],g[N];
LL ans,x[N],t[N],L;
int main()
{
	file();
	read(n),read(L);
	For(i,1,n)read(x[i]);
	ans=1;
	For(i,1,n)read(t[i]),ans+=t[i]/(L<<1),t[i]%=L<<1;
	For(i,1,n)
	{
		if(t[i]==0)f[i]=g[i]=0;
		else ans++,f[i]=((L-x[i])<<1ll)>=t[i],g[i]=(x[i]<<1ll)>=t[i];
	}
	int cnt=0,dcnt=0;
	For(i,1,n-1)
	{
		if(f[i])
		{
			if(cnt>0)
			{
				if(g[i])dcnt++;
				cnt--,ans--;
			}
			else if(dcnt>0&&!g[i])dcnt--,cnt++;
			else if(g[i])cnt++;
		}
		else if(g[i])cnt++;
	}
	if(f[n])ans--;
	printf("%lld\n",2ll*L*ans);
	return 0;
}


Measured memory_bytes: 7296
import java.util.*;	
class Main{	
    public static void main(String[] args){	
        Scanner input=new Scanner(System.in);	
        int a,b;	
        while(true){	
            a=input.nextInt();	
            char op = input.next().charAt(0);	
            b=input.nextInt();	
        if(op == '?')break;	
        else if (op == '+')	
            System.out.println(a + b);	
        else if ( op == '-')	
            System.out.println(a - b);	
        else if (op == '*')	
            System.out.println(a * b);	
        else if(op == '/')	
            System.out.println(a / b);	
        }	
    }	
}	


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

int main() {
    while (1) {
        int m, f, r;
        cin >> m >> f >> r;
        // cout << "m" << m << " f" << f << " r" << r << endl;
        if (m == -1 || f == -1) {
            if (m == -1 && f == -1) break;
            cout << "F" << endl; 
        } else {
            int Total;
            Total = m + f;

            if (Total < 30) {
                cout << "F" << endl;
            } else if (Total < 50 ) {
                if (r >= 50) {
                    cout << "C" << endl;
                } else {
                    cout << "D" << endl;
                }
            } else if (Total < 65) {
                cout << "C" << endl;
            } else if (Total < 80) {
                cout << "B" << endl;
            } else if (Total >= 80) {
                cout << "A" << endl;
            }
        }

   }
    return 0;
}


Measured memory_bytes: 3088
N, K = map(int, input().split())
countlist = []
for i in range(0, K):
	countlist.append(N//K)
for i in range(1, N%K+1):
	countlist[i] += 1
sum = countlist[0] ** 3
for i in range(1, K):
	if i*2 % K == 0:
		sum += (countlist[i]**2)*countlist[K-i]
print(sum)

Measured memory_bytes: 52208
#include <cstdio>
#include <vector>
#include <algorithm>

struct P1
{
    int x, y;

    bool operator<(const P1 o)
    {
        return x + y < o.x + o.y;
    }
};
struct P2
{
    int x, y;

    bool operator<(const P2 o)
    {
        return x - y < o.x - o.y;
    }
};
struct P3
{
    int x, y;

    bool operator<(const P3 o)
    {
        return -x + y < -o.x + o.y;
    }
};
struct P4
{
    int x, y;

    bool operator<(const P4 o)
    {
        return -x - y < -o.x - o.y;
    }
};
int main(void)
{
    int N;
    scanf("%d", &N);

    std::vector<P1> ones;
    std::vector<P2> twos;
    std::vector<P3> threes;
    std::vector<P4> fours;

    int x,y;
    for (int i = 0; i < N; i++)
    {
        scanf("%d%d",&x,&y);
        ones.push_back({x,y});
        twos.push_back({x,y});
        threes.push_back({x,y});
        fours.push_back({x,y});
    }
    std::sort(ones.begin(),ones.end());
    std::sort(twos.begin(),twos.end());
    std::sort(threes.begin(),threes.end());
    std::sort(fours.begin(),fours.end());

    int maxdist = 0;
    for(int i = 1; i < N; i++){
        maxdist = std::max(maxdist,abs(ones[0].x - ones[i].x) + abs(ones[0].y - ones[i].y));
        maxdist = std::max(maxdist,abs(twos[0].x - twos[i].x) + abs(twos[0].y - twos[i].y));
        maxdist = std::max(maxdist,abs(threes[0].x - threes[i].x) + abs(threes[0].y - threes[i].y));
        maxdist = std::max(maxdist,abs(fours[0].x - fours[i].x) + abs(fours[0].y - fours[i].y));
    }

    printf("%d\n",maxdist);

    return 0;
}

Measured memory_bytes: 9248
using System;
namespace ITP1_7_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int i;
            int j;
            int sum = 0;
            int SUM = 0;
            string[] S = Console.ReadLine().Split();
            var r = int.Parse(S[0]);
            var c = int.Parse(S[1]);
            int[,] x = new int[r, c];
            for(i = 0; i < r; i++)
            {
                string[] line = Console.ReadLine().Split();
                for(j = 0; j < c; j++)
                {
                    x[i, j] = int.Parse(line[j]);
                }
            }
            for(i = 0; i < r; i++)
            {
                for(j = 0; j < c; j++)
                {
                    sum = sum + x[i, j];
                    Console.Write(x[i, j] + " ");
                }
                Console.Write(sum);
                sum = 0;
                Console.WriteLine("");
            }
            for(j = 0; j < c; j++)
            {
                for(i = 0; i < r; i++)
                {
                    sum = sum + x[i, j];
                }
                Console.Write(sum + " ");
                SUM = SUM + sum;
                sum = 0;
            }
            Console.WriteLine(SUM);
        }
    }
}


Measured memory_bytes: 15928
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

#define MAX_N 100000000
#define INF 1000000000000

int main(){
  long long a,b,q;
  cin >> a >> b >> q;
  long long s[a+2];
  long long t[b+2];
  long long x[q];
  s[0] = -1*INF;
  s[a+1] = INF;
  t[0] = -1*INF;
  t[b+1] = INF;
  for(int i=0;i<a;i++){
    cin >> s[i+1];
  }
  for(int i=0;i<b;i++){
    cin >> t[i+1];
  }
  for(int i=0;i<q;i++){
    cin >> x[i];
  }
  long long ss[2];
  long long tt[2];
  long long dist = INF;

  for(int i=0;i<q;i++){
    dist = INF;
    int si = lower_bound(s,s+(a+2),x[i]) - s;
    int ti = lower_bound(t,t+(b+2),x[i]) - t;
    ss[0] = s[si-1];
    ss[1] = s[si];
    tt[0] = t[ti-1];
    tt[1] = t[ti];
    for(int ii=0;ii<2;ii++){
      for(int jj=0;jj<2;jj++){
        dist = min(dist,abs(ss[ii]-x[i])+abs(tt[jj]-ss[ii]));
        dist = min(dist,abs(tt[jj]-x[i])+abs(tt[jj]-ss[ii]));
      }
    }
    cout << dist << endl;
  }

  return 0;
}


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

int main()
{int A,B,C;
 cin >> A >> B >> C;
 bool flag = false;
 
 for(int k = 1; k < B; k++)
 {if(A*k % B == C){flag = true;}}
 
 if(flag){cout << "YES" <<endl;}
else{cout << "NO" << endl;}
return 0;
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, T = LI()
    ct = [LI() for _ in range(N)]

    l = [i[0] for i in ct if i[1] <= T]

    if l:
        print(min(l))
    else:
        print('TLE')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10120
from collections import deque

N = int(input())
ad = [[] for _ in range(N*N)]
num = [0] * (N*N)

for i in range(N):
    a = [int(e)-1 for e in input().split()]
    for k in range(N-2):
        j = a[k]
        nj = a[k+1]
        v = N*max(i,j) + min(i,j)
        nv = N*max(i,nj) + min(i,nj)
        ad[v].append(nv)
        num[nv] += 1

S = deque()
L = []

for v in range(N*N):
    if num[v] == 0:
        S.append((v,1))

while S:
    v, d = S.popleft()
    L.append(d)
    for nv in ad[v]:
        num[nv] -= 1
        if num[nv] == 0:
            S.append((nv, d+1))

if len(L) != N*N:
    print(-1)
    exit()

ans = max(L)
print(ans)

Measured memory_bytes: 173284