akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){

    int N;
    cin >> N;
    vector<pair<int, int> > ab(N), cd(N);
    for(int i = 0; i < N; i++){
        int a, b;
        cin >> a >> b;
        ab[i] = make_pair(a, b);
    }
    for(int i = 0; i < N; i++){
        int c, d;
        cin >> c >> d;
        cd[i] = make_pair(c, d);
    }

    sort(ab.begin(), ab.end());
    sort(cd.begin(), cd.end());

    int ans = 0;
    for(int i = 0; i < N; i++){
        int index = -1, max_y = -1;
        for(int j = 0; j < ab.size(); j++){
            if(ab[j].first < cd[i].first && ab[j].second < cd[i].second && max_y < ab[j].second){
                max_y = ab[j].second;
                index = j;
            }
        }
        if(index != -1){
            ans++;
            ab.erase(ab.begin() + index);
        }
    }

    cout << ans << 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 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>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<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; }



int main(int argc, char const *argv[]) {
  int a, b;
  cin >> a >> b;
  if (a > b) rep(i, a) cout << b;
  else
    rep(i, b) cout << a;
  return 0;
}

Measured memory_bytes: 3536
#include <stdio.h>

int main(void) {
	int n;
	scanf("%d", &n);
	float k,m;
	if (n % 2 == 1) {
		m = 1 + n;
	}
	else {
		m = n;
	}
	k = (m / 2)/n ;
	printf("%f",k);
	return 0;
}

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

using namespace std;

int bob_r = 0;
int alice_r = 0;
int N;
vector<int> c;

int max(vector<int> &v) {
	int max = 0;
	for (int i = 0; i < (int)v.size(); i++) {
		if (v[i] > max) {
			max = v[i];
		}
	}
	
	return max;
}

int main() {

	cin >> N;
	for (int a = 0; a < N; a++) {
		int n;
		cin >> n;
		c.push_back(n);
	}

	sort(c.begin(), c.end(), greater<int>());

	for (int a = 0; a < N; a++) {
		if (a % 2 == 0) {
			alice_r += c[a];
		} else {
			bob_r   += c[a];
		}
	}
	
	cout << alice_r - bob_r << endl;
	return 0;
	
}


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

using namespace std;

void solve()
{
	long K, A, B, k;
	cin >> K >> A >> B;
	if (K + 1 < A)
	{
		cout << K + 1 << endl;
		return;
	}
	k = K;
	K -= A - 1;
	long ans = A, x = K / 2;
	ans += x * (B-A) + K % 2;
	cout << max(ans, 1 + k) << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n],a2;
  int b[n],b2;
  int c[n],c2;
  int ans,ans2;
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i] >> c[i];
    int m[] = {a[i],b[i],c[i]};
    sort(m,m+3,greater<int>());
    a2 = m[0];
    b2 = m[1];
    c2 = m[2];
    ans = a2 * a2;
    ans2 = b2 * b2 + c2 * c2;
    if(ans==ans2){
      cout << "YES" <<endl;
    }
    else cout << "NO" <<endl;
  }
  return 0;
}

Measured memory_bytes: 1180
#include <iostream>

using namespace std;

int main() {

    float odds = 0, n;

    cin >> n;

    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            odds++;
        }
    }

    float ans = odds/ n;

//    cout <<  n << odds << "\n";
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll fib[90];
    fib[0]=2;
    fib[1]=1;
    for(ll i=2;i<=87;i++)fib[i]=fib[i-1]+fib[i-2];
    ll n;
    while(cin>>n)
    {
        cout<<fib[n]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

M,K=MAP()

if 2**M<=K:
    print(-1)
    exit()

if M==0:
    print(0, 0)
    exit()

if M==1:
    if K==0:
        print(0, 0, 1, 1)
    else:
        print(-1)
    exit()

ans=[]
for i in range(2**M):
    if i!=K:
        ans.append(i)
ans.append(K)
for i in range(2**M-1, -1, -1):
    if i!=K:
        ans.append(i)
ans.append(K)

print(*ans)


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

int main(){
	vector<int> a;
	for(int i = 0; i < 3; i++){
		int x;
		cin >> x;
		a.push_back(x);
	}
	sort(a.begin(), a.end());
	cout << (a[1] - a[0]) + (a[2] - a[1]) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
long N, M;

int main() {
  cin >> N >> M;
  if (N==2 || M==2) {
    cout << 0 << endl;
    return 0;
  }
  if (N==1 && M==1) {
    cout << 1 << endl;
    return 0;
  }
  if (N==1 || M==1) {
    cout << N*M-2 << endl;
    return 0;
  }
  cout << (N-2)*(M-2) << endl;
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var [a,n,m]=input.trim().split(" ").map(Number);
var cnt=0;
var i=1;
while(true){
   var k = Math.pow(i,n);
   if(k>=m)break;
   var ary=(k+"").split("").map(Number);
   var sum = ary.reduce((a,b) => a+b);
   if(Math.pow(a+sum,n)==k)cnt++;
   i++;
}
console.log(cnt);


Measured memory_bytes: 20496
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

int
main(int argc, char **argv)
{
	int md[12] = {0, 31, 59, 90,120,151,181,212,243,273,304,334};
	int y2, m2, d2;
	int y1, m1, d1;

	while (true)
	{
		scanf("%d%d%d%d%d%d", &y1, &m1, &d1, &y2, &m2, &d2);
		if (y1 < 0 || m1 < 0 || d1 < 0 || y2 < 0 || m2 < 0 || d2 < 0)
			break;

		int days2 = 0;
		if (m2 >= 3 && y2 % 4 == 0 && (y2 % 100 != 0 || y2 % 400 == 0))
			days2++;

		y2--;
		days2 += y2 * 365 + md[m2 - 1] + d2 + (y2 / 4 - y2 / 100 + y2 / 400);

		int days1 = 0;
		if (m1 >= 3 && y1 % 4 == 0 && (y1 % 100 != 0 || y1 % 400 == 0))
			days1++;

		y1--;
		days1 += y1 * 365 + md[m1 - 1] + d1 + (y1 / 4 - y1 / 100 + y1 / 400);

		printf("%d\n", days2 - days1);
	}

	return 0;
}

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

using namespace std;
using ll = long long;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = a * c;
    if(ans < a * d) {
        ans = a * d;
    }
    if(ans < b * c) {
        ans = b * c;
    }
    if(ans < b * d) {
        ans = b * d;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>

int main(void)
{
    int N, M;
    int  color[51][3];
    char in_str[51];
    int i, j;
    int w, b, r;
    int nw, nb, nr;
    int min;
    
    scanf("%d%d", &N, &M);
    
    memset(color, 0, sizeof(color));
    for (i = 1; i <= N; i++){
        scanf("%s", in_str);
        for (j = 0; j < M; j++){
            switch (in_str[j]){
              case 'W':
                color[i][0]++;
                break;

              case 'B':
                color[i][1]++;
                break;

              case 'R':
                color[i][2]++;
                break;
            }
        }
    }


    min = N * M;
    nw = 0;
    for (w = 1; w <= N - 2; w++){
        nw += color[w][1] + color[w][2];
        
        nb = 0;
        for (b = w + 1; b <= N - 1; b++){
            nb += color[b][0] + color[b][2];

            nr = 0;
            for (r = b + 1; r <= N; r++){
                nr += color[r][0] + color[r][1];

                
            }
            if (min > nw + nb + nr){
                min = nw + nb + nr;
            }
        }
    }
    
    printf("%d\n", min);
    
    return (0);
}






Measured memory_bytes: 2064
if __name__ == "__main__":
    N, M = map(int, input().split())
    if (N > M):
        N, M = M, N
    if (N == 1):
        print(max(1, M - 2))
        exit(0)
    result = (N - 2) * (M - 2)
    print(result)


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>

using namespace std;

int main() {

  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  cout << ( min( min( a, b ), c ) + min( d, e ) - 50 ) << endl; 
}

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

	int a, b, c, sum=0, i;
	int num, cur;
	scanf("%d%d%d", &a, &b, &c);
	
	for(i=1; i<=a; i++){
		num = 0;
		cur = i;
		num += cur%10; cur /=10;
		num += cur%10; cur /=10;
		num += cur%10; cur /=10;
		num += cur%10; cur /=10;
        num += cur%10; cur /=10;
		if(num >= b && num <=c)
			sum += i;
	
	}
	printf("%d", sum);
	return 0;
}

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

int main()
{
	int k;
	cin >> k;
	bool flag = false;

	ll l = (k % 7 == 0) ? 9 * k / 7 : 9 * k;
	ll n = 1;
	for (ll i = 1; i <= l; i++)
	{
		n = (n % l) * 10 % l;
		if (n == 1)
		{
			cout << i << endl;
			flag = true;
			break;
		}
	}

	if (!flag)
		cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 3588
#include<stdio.h>
	int main(){
		int n,p=0,h,i,d,b;
		scanf("%d",&n);
		while(n!=p++){
			scanf("%d",&h);
			printf("Case %d:\n",p);
			for(i=0;i<10;i++){
				b=h*h/1000000;
				b*=1000000;
				d=(h*h-b)/100;
				
				
				printf("%d\n",d);
				h=d;
			}
		}
		return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#define MAX(a, b) ((a > b) ? (a) : (b))

int main() {
    int n, a, k2 = 0, k4 = 0;
    int j = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a);
        if (a % 4 == 0)      k4++;
        else if (a % 2 == 0) k2++;
    }
    if (((k4 * 2) + MAX((k2 - 1), 0)) >= n - 1) printf("Yes\n");
    else                                printf("No\n");
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};


int main(){
  int n,k; cin >> n >> k;
  vi h(n); rep(i,n) cin >> h[i];
  vi dp(n,1e9);
  dp[0] = 0;
  
  rep(i,n) {
    for(int j = 1; j <= k; j++) {
      if(i+j < n) chmin(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
    }
  }

  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
# 160 B

x = int(input())
n = 0

if x // 500 != 0:
    n += 1000 * (x // 500)
    # print(x // 500)
    x = x % 500

if x // 5 != 0:
    n += 5 * (x // 5)
    # print(x // 5)
    x = x % 5

print(n)


Measured memory_bytes: 9136
#include<iostream>
#include<vector>

using namespace std;

int main()
{
	int N,i,x;
	int sum = 0;
	
	vector<int> C;
	vector<int> V;
	
	cin >> N;
	
	for(i = 0; i < N; i++){
		
		cin >> x;
		
		C.push_back(x);
		
	}
	for(i = 0; i < N; i++){
		
		cin >> x;
		
		V.push_back(x);
	}
	
	for(i = 0; i < N; i++){
		if(C[i] > V[i]){
			sum += C[i] - V[i];
		}
	}
	cout << sum;
	
	return 0;
}

Measured memory_bytes: 256
S = input().strip()

def solve(S):
    a = 0
    move = 0
    i = 0
    while i < len(S)-1:
        if S[i] == 'A':
            a += 1
            i+=1
            continue
        if S[i] == 'B' and S[i+1] == 'C':
            move += a
            i+=2
            continue
        else:
            a = 0
            i+=1
    return move

print(solve(S))


Measured memory_bytes: 3500
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int N,K,latte[2001]={0};
    for(int i=1;i<=2000;i++)
        latte[i]=(i-1)*i;

    cin>>N>>K;
    vector<vector<int> >books(10);
    for(int i=0;i<N;i++){
        int v,j;
        cin>>v>>j;j--;
        books[j].push_back(v);

    }

    for(int i=0;i<10;i++){
        sort(books[i].begin(),books[i].end(),greater<int>());
        for(int j=0;j<books[i].size();j++){
            if(j+1==books[i].size()){
                books[i][j]+=j*(j+1);
                continue;
            }
            books[i][j+1]+=books[i][j];
            books[i][j]+=j*(j+1);
        }
    }

    int dp[11][2001];fill(dp[0],dp[0]+11*2001,-1);
    for(int i=0;i<=10;i++)dp[i][0]=0;
    for(int i=0;i<10;i++){
        for(int j=0;j<=K;j++){
            if(dp[i][j]==-1)break;
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            for(int k=0;k<books[i].size();k++){
                if(j+k+1>K)break;
                dp[i+1][j+k+1]=max(dp[i+1][j+k+1],dp[i][j]+books[i][k]);
            }
        }
    }
    /*
    for(int i=0;i<10;i++){
        if(!books[i].size())continue;
        cout<<i<<":";
        for(int j=0;j<books[i].size();j++)cout<<books[i][j]<<" ";
        cout<<endl;
    }
    cout<<endl<<endl;
    for(int i=0;i<=10;i++){
        for(int j=0;j<=K;j++)cout<<dp[i][j]<<" ";
        cout<<endl;
    }
    */
    cout<<dp[10][K]<<endl;


}

Measured memory_bytes: 1320
using System;
using System.Collections.Generic;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<long,long> soinsuu = new Dictionary<long,long>();

            long n = long.Parse(Console.ReadLine());

            long i = 2;
            long tmp = n;

            while (i * i <= n) //※1
            {
                if (tmp % i == 0)
                {
                    tmp /= i;
                    if (soinsuu.ContainsKey(i)) { soinsuu[i] +=1; } else { soinsuu.Add(i, 1); }//
                }
                else
                {
                    i++;
                }
            }
            if (tmp != 1)
            {
                if (soinsuu.ContainsKey(i)) { soinsuu[i] += 1; } else { soinsuu.Add(i, 1); };//最後の素数も返す
            }
            long kotae = 0;
            foreach (KeyValuePair<long,long> kazu in soinsuu)
            {
                
                long bkotae = 0;
                while(kazu.Value>=(bkotae)*(bkotae+1)/2)
                {
                    bkotae += 1;
                }
                bkotae -= 1;
                kotae += bkotae;
            }
            System.Console.WriteLine(kotae);

        }

       

    }
}


Measured memory_bytes: 27800
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;


struct roadwork {
	long long X;
	int type; // 1: add -1: sub
	long long T; // time
};


int main(int argc, char** argv) {
	int N, Q;

	cin >> N >> Q;

	vector<roadwork> rw(2*N);
	vector<long long> p(Q);

	for (int i = 0; i < N; i++) {
		long long s, t, x;
		cin >> s >> t >> x;
		rw[2 * i + 0].T = s - x;
		rw[2 * i + 0].type = 1;
		rw[2 * i + 0].X = x;
		rw[2 * i + 1].T = t - x;
		rw[2 * i + 1].type = -1;
		rw[2 * i + 1].X = x;
	}
	// sort
	sort(rw.begin(), rw.end(), [](const roadwork& x, const roadwork& y) { return x.T < y.T; });

	for (int i = 0; i < Q; i++) {
		cin >> p[i];
	}

	multiset<long long> now_working;
	int j = 0;

	for (int i = 0; i < Q; i++) {
		// pがいるところまで、rwの位置を進める。
		while (j < rw.size() && p[i] >= rw[j].T) {
			if (rw[j].type == 1) {
				now_working.insert(rw[j].X);
			}
			else {
				auto hit(now_working.find(rw[j].X));
				if (hit != now_working.end()) now_working.erase(hit);
				//now_working.erase(rw[j].X);
			}
			j++;
		}
		if (now_working.empty()) {
			cout << -1 << endl;
		}
		else {
			cout << *now_working.begin() << endl;
		}
	}
}

Measured memory_bytes: 21504
n = int(input())
hl = list(map(int,input().split()))

lst = []
cnt = 0
for i in range(1,n):
    if hl[i-1] >= hl[i]:
        cnt +=1
    else:
        lst.append(cnt)
        cnt = 0
lst.append(cnt)
print(max(lst))


Measured memory_bytes: 20460
n,m = [int(s) for s in input().split()]

p = [-1 for _ in range(m)]
s = [-1 for _ in range(m)]

for i in range(m):
    x = input().split()
    p[i] = int(x[0])
    s[i] = x[1]


dic_ac = {}
dic_wa = {}
dic_wa_num = {}

for i in range(m):
    if(s[i] == "AC"):
        if not (p[i] in dic_ac):
            dic_ac[p[i]] = 1
    
    if(s[i] == "WA" and p[i] not in dic_ac):
        if(p[i] in dic_wa):
            dic_wa_num[p[i]] += 1
        else:
            dic_wa[p[i]] = 1
            dic_wa_num[p[i]] = 1
            

wa = 0
ac = 0

for v in dic_ac.values():
    ac += v

for v in dic_ac:
    if(v in dic_wa_num):
        wa += dic_wa_num[v]

  
print(ac,wa)

Measured memory_bytes: 22676
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if(s.find("9") != string::npos) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int A, B, C, D, R, L;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (L == R) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right"<< endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <iomanip>
using namespace std;

typedef long long ll;

int main()
{
    string S;
    ll K;
    cin >> S >> K;
    char pre, now;
    pre=S[0];
    ll ans=0;
    for(int i=1; i<S.size(); i++){
        now=S[i]; 
        if(pre==now){
            now='A';
            ans++;
        }
        pre=now;
    }
    if(pre!=S[0]) cout << ans * K << endl;
    else{
        ll tmp=1;
        pre='A';
        for(int i=1; i<S.size(); i++){
            now=S[i];
            if(pre==now){
                now='A';
                tmp++;
            }
            pre=now;
        }
        if(pre!='A'){
            cout << ans + (K-1) * tmp << endl;
        }else{
            if(K%2==0) cout << K/2*(ans+tmp) << endl;
            else cout << K/2*(ans+tmp) + ans << endl;
        }
    }



    return 0;
}


Measured memory_bytes: 256
// Karm Karta ja, Phal Ki Chinta na Kar:)
#include <bits/stdc++.h>
using namespace std;
#include<stdio.h>
typedef long long int ll;
#define INF 1e18+3
#define M 1000000007
#define PI 3.14159265358979323846
ll po2[62];
int main()
{
   po2[0]=1;
   ll i,j;
   for(i=1;i<=61;i++)
   {
       po2[i]=((po2[i-1]%M)*(2%M))%M;
   }
   ll b[62]={0};
   ll n;
   cin>>n;
   ll A[n];
   for(i=0;i<n;i++)
   {
       cin>>A[i];
   }
   ll ans=0,Sum=0;
   for(i=0;i<n;i++)
   {
       for(j=0;j<61;j++)
       {
           if((A[i]>>(j))&1)
           {
               ll res=i-b[j];
               ll p=((res%M)*(po2[j]%M))%M;
               ans=(ans%M+p%M)%M;
               b[j]++;
           }
           else
           {
               ll res=b[j];
               ll p=((res%M)*(po2[j]%M))%M;
               ans=(ans%M+p%M)%M;
           }
       }

   }
   cout<<ans;





}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
int main() {
  int N, K; cin >> N >> K;

  int x[N], y[N];
  vector<pii> v;
  rep(i, N) {
    cin >> x[i];
    cin >> y[i];
    v.emplace_back(x[i], y[i]);
  }
  sort(x, x+N); sort(y, y+N);
  ll ans = 1LL * (x[N-1] - x[0]) * (y[N-1] - y[0]);
  rep(l, N) {
    rep(r, l, N) {
      rep(b, N) {
        rep(t, b, N) {
          int count = 0;
          rep(i, N) {
            int X = v[i].first, Y = v[i].second;
            if (x[l] <= X && X <= x[r] && y[b] <= Y && Y <= y[t]) {
              ++count;
            }
          }
          if (count >= K)
            chmin(ans, 1LL * (x[r]-x[l]) * (y[t]-y[b]));
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

typedef long long LL;

const int N=100000,mod=1000000007;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n;

int H(int x,int y){return x*n+y;}

struct side{
  int y,next;
}e[N*8+9];
int lin[2][N*2+9],cs;

void Ins(int id,int x,int y){e[++cs].y=y;e[cs].next=lin[id][x];lin[id][x]=cs;}
void Ins2(int id,int x,int y){Ins(id,x,y);Ins(id,y,x);}

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n<<1;++i){
	int x,y;
	scanf("%d%d",&x,&y);
	Ins2(0,H(0,x),H(1,y));
  }
}

int inv[N*2+9],fac[N*2+9],ifac[N*2+9];

void Get_inv(){
  inv[1]=1;
  fac[0]=fac[1]=1;
  ifac[0]=ifac[1]=1;
  for (int i=2;i<=n<<1;++i){
	inv[i]=mul(mod-mod/i,inv[mod%i]);
	fac[i]=mul(fac[i-1],i);
	ifac[i]=mul(ifac[i-1],inv[i]);
  }
}

int a[N*2+9],vis[N*2+9],ca;
int st,td,ce;

void Dfs_a(int k,int fa){
  vis[a[++ca]=k]=1;
  for (int i=lin[0][k];i;i=e[i].next){
	++ce;
	if (!vis[e[i].y]) Dfs_a(e[i].y,k);
    else if (e[i].y^fa) st=k,td=e[i].y;
  }
}

int pre[N*2+9];

void Dfs_pre(int k,int fa){
  for (int i=lin[0][k];i;i=e[i].next)
	if (e[i].y^fa&&e[i].y^st){
	  pre[e[i].y]=k;
	  Dfs_pre(e[i].y,k);
	}
}

int siz[N*2+9];

void Dfs_siz(int k,int fa){
  siz[k]=1;
  for (int i=lin[1][k];i;i=e[i].next)
	if (e[i].y^fa){
	  Dfs_siz(e[i].y,k);
	  siz[k]+=siz[e[i].y];
	}
}

int deg[N*2+9];

int Get_ans0(){
  int res=fac[ca];
  Dfs_pre(st,td);
  pre[st]=td;
  for (int i=1;i<=ca;++i) lin[1][a[i]]=0,deg[a[i]]=0;
  for (int i=1;i<=ca;++i){
	int t=a[i];
	for (int j=lin[0][t];j;j=e[j].next)
	  if (e[j].y<pre[t]) Ins(1,t,e[j].y),++deg[e[j].y];
  }
  for (int i=1;i<=ca;++i)
	if (!deg[a[i]]) Dfs_siz(a[i],0);
  for (int i=1;i<=ca;++i) smul(res,inv[siz[a[i]]]);
  return res;
}

int ans;

void Get_ans(){
  ans=fac[n<<1];
  for (int i=1;i<=n<<1;++i)
	if (!vis[i]){
	  ca=ce=0;
	  Dfs_a(i,0);
	  if (ca<<1^ce) {ans=0;return;}
	  smul(ans,ifac[ca]);
	  int now=Get_ans0();
	  swap(st,td);
	  smul(ans,add(now,Get_ans0()));
	}
}

void work(){
  Get_inv();
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 14720
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var answer = Math.Ceiling((double)N / 2) / N;
            Console.WriteLine(answer.ToString("f10"));
        }
    }
}


Measured memory_bytes: 11220
#include <stdio.h>
int main(void)
{
    int n,i,a[100],tmp;
    scanf("%d",&n);
    


    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    
    for(i=1;i<=n/2;i++){
        tmp=a[i];
        a[i]=a[n+1-i];
        a[n+1-i]=tmp;
    }
    for(i=1;i<n;i++){
        printf("%d ",a[i]);
    }
    printf("%d",a[n]);
    printf("\n");
    return 0;
}


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

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

    if (a == b) {
        if (b == c) {
            cout << 1 << endl;
        }
        if (b != c) {
            cout << 2 << endl;
        }
    } else {
        if (b == c) {
            cout << 2 << endl;
        } else if (a == c) {
            cout << 2 << endl;
        }
        else {
            cout << 3 << endl;
        }
    }


    return 0;
}

Measured memory_bytes: 256
N=int(input())
X=list(map(int,input().split()))
X_sorted=sorted(X)
Med1=X_sorted[int(N/2)-1]
Med2=X_sorted[int(N/2)]

for i in range(N):
    if X[i]<=Med1:
        print(Med2)
    else:
        print(Med1)

Measured memory_bytes: 25620
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<functional>
#include<algorithm>
using namespace std;
int  sheets[3][10007], tmp[10007];



int main(){
  while(1){
    int n, r;
    int x1, y1, x2, y2, mx = 0, my = 0, menseki = 0, gaishuu = 0;
    vector<pair<int, int> > points;
    map<pair<int ,int> , int> nums;
    scanf("%d%d", &n, &r);
    memset(sheets, 0, sizeof(sheets));
    if(n == 0 && r == 0)return 0;
    for(int i = 0;i < n;i++){
      scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
      x1++,y1++,x2++,y2++;
      points.push_back(make_pair(x1, y1));
      points.push_back(make_pair(x1, y2));
      points.push_back(make_pair(x2, y1));
      points.push_back(make_pair(x2, y2));
      if(nums.count(make_pair(x1, y1)) == 0)nums[make_pair(x1, y1)] = 0;
      if(nums.count(make_pair(x2, y1)) == 0)nums[make_pair(x2, y1)] = 0;
      if(nums.count(make_pair(x1, y2)) == 0)nums[make_pair(x1, y2)] = 0;
      if(nums.count(make_pair(x2, y2)) == 0)nums[make_pair(x2, y2)] = 0;
      nums[make_pair(x1, y1)]++;
      nums[make_pair(x2, y2)]++;
      nums[make_pair(x1, y2)]--;
      nums[make_pair(x2, y1)]--;
      mx = max(mx, x1);
      mx = max(mx, x2);
      my = max(my, y1);
      my = max(my, y2);
    }
    sort(points.begin(), points.end(), greater< pair<int, int> >());
    memset(tmp, 0, sizeof(tmp));
    for(int i = 1;i <= mx ; i++){
      for(int j = 1;j <= my + 1; j++){
	if(points.back().first == i && points.back().second == j){
	  tmp[j] += nums[points.back()];
	  pair<int, int> tmpr = points.back();
	  while(points.back() == tmpr)points.pop_back();
	}
	sheets[i % 3][j] = sheets[i % 3][j - 1] + tmp[j];
	if(sheets[i % 3][j] > 0)menseki++;
	if(r == 2){
	  if(sheets[i % 3][j] > 0 ){
	    if(sheets[(i - 1) % 3][j] == 0)gaishuu++;
	    if(sheets[i % 3][j - 1] == 0)gaishuu++;
	  }
	  if(sheets[i % 3][j] == 0 ){
	    if(sheets[(i - 1) % 3][j] > 0)gaishuu++;
	    if(sheets[i % 3][j - 1] > 0)gaishuu++;
	  }
	}
      }
    }
    printf("%d\n", menseki);
    if(r == 2){
      printf("%d\n", gaishuu);
    }
  }
}

Measured memory_bytes: 3956
import java.util.*;
 
class Main {
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
      String oll = sc.next();String m = oll.substring(5, 7);
      int mo = Integer.parseInt(m);
      
      if(mo<=4){System.out.print("Heisei");}
      else{System.out.print("TBD");}
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int n,a[100010];
string s;
vector<int> check(int x,int y)
{
	vector<int> v;
	v.push_back(x);
	v.push_back(y);
	for(int i=2;i<n;i++)
	{
		if(!a[i-1])
		{
			if(v[i-1]==0)
				v.push_back(v[i-2]);
			else
				v.push_back(1-v[i-2]);
		}
		else
		{
			if(v[i-1]==0)
				v.push_back(1-v[i-2]);
			else
				v.push_back(v[i-2]);
		}
	}
	if((a[n-1])==(v[n-2]^v[n-1]^v[0])&&(a[0])==(v[n-1]^v[0])^v[1])
		return v;
	v.clear();
	return v;
}
void printans(vector<int> v)
{
	for(int i=0;i<v.size();i++)
		cout<<(v[i]==0?'S':'W');
	exit(0);
}
int main()
{
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='o')
			a[i]=0;
		else
			a[i]=1;
	}
	vector<int> v;
	v=check(0,0);
	if(v.size()!=0)
		printans(v);
	v=check(0,1);
	if(v.size()!=0)
		printans(v);
	v=check(1,0);
	if(v.size()!=0)
		printans(v);
	v=check(1,1);
	if(v.size()!=0)
		printans(v);
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 2216
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


int sai[1000];
int ban[1001];

int main(){
	int N,M;
	while(cin>>N>>M){
		if(N==0 && M==0)break;
		
		memset(sai,0,sizeof(sai));
		memset(ban,0,sizeof(ban));
		
		for(int i=1;i<=N;i++){
			cin>>ban[i];
		}
		for(int i=0;i<M;i++){
			cin>>sai[i];
		}
		int cur=1;
		
		for(int i=0;i<M;i++){
			cur+=sai[i];
			cur+=ban[cur];
			if(cur>=N){
				M=i;
				break;
			}
		}
		cout<<M+1<<endl;
	}
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

template<class T> void gc(T &x)
{
    int k, m = 0;
    x = 0;
    while (true)
    {
        k = getchar_unlocked();
        if (k == '-')
        {
            m = 1; break;
        }
        if ('0' <= k && k <= '9')
        {
            x = k - '0';
            break;
        }
    }
    while (true)
    {
        k = getchar_unlocked();
        if (k < '0' || k > '9') break;
        x = x * 10 + k - '0';
    }
    if (m) x = -x;
}

int main()
{
    int N, K;

    gc(N);
    gc(K);

    long long int a;

    vector<long long int> vSM(100001);
    vector<long long int> vZR(100001);

    for (int i = 0; i < N; i++)
    {
        gc(a);
        vSM[i + 1] = vSM[i] + a;
        vZR[i + 1] = vZR[i] + max(a, 0LL);
    }

    long long int score = 0LL;
    for (int i = 0; i < N - K + 1; i++)
    {
        int l = i;
        int r = i + K;

        // 最後に塗るところ以外
        long long int pre = vZR[l] + (vZR[N] - vZR[r]);

        // 最後に白く塗る(0LL)、黒く塗る(vSM[r] - vSM[l])
        score = max(score, pre + max(vSM[r] - vSM[l], 0LL));
    }

    printf("%lld\n", score);
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

/**
 * A
 */
public class Main {

    Node root;

    public void run() {

        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        
        for(int i=0; i<m; i++) {
            String str = sc.next();
            if(str.startsWith("i")) {
                insert(sc.nextInt());
            } else {
                inorder(root);
                System.out.println();
                preorder(root);
                System.out.println();
            }
        }

        sc.close();

    }

    public void insert(int v) {

        Node x = root; // root
        Node y = null; // parent of x
        Node z = new Node(v); // it will be inserted

        while(x != null) {
            y = x;
            if(z.id < x.id) {
                x = x.left;
            } else {
                x = x.right;
            }
        }
        if(y == null) {
            root = z;
        } else if(z.id < y.id) {
            y.left = z;
        } else {
            y.right = z;
        }

    }

    public void inorder(Node tree) {
        
        if(tree == null) {
            return;
        }

        inorder(tree.left);
        System.out.print(" "+tree.id);
        inorder(tree.right);

    }

    public void preorder(Node tree) {

        if(tree == null) {
            return;
        }

        System.out.print(" "+tree.id);
        preorder(tree.left);
        preorder(tree.right);

    }

    public static void main(String[] args) {
        new Main().run();
    }

}

class Node {

    int id;
    Node left;
    Node right;

    Node(int id) {
        this.id = id;
    }

}


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

int main(){
    int INF = 1e8;
    int ans = INF;
    int c[10][1000];
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    rep(div,1<<(h-1)){
        int g=0;
        vector<int> id(h);
        rep(i,h){
            id[i]=g;
            if(div>>i&1)g++;
        }
        g++;
        
        int num = g-1;
        rep(i,g)rep(j,w) c[i][j]=0;
        rep(i,h)rep(j,w) c[id[i]][j] += (s[i][j]-'0');
        vector<int> now(g);
        
        auto add = [&](int j){
            rep(i,g) now[i] += c [i][j];
            rep(i,g) if(now[i]>k) return false;
            return true;
        };
        rep(j,w){
            if(!add(j)){
                num++;
                now = vector<int>(g);
                if(!add(j)){
                    num = INF;
                    break;
                }
            }
        }
        ans = min(ans,num);
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var ans = 0L;
        for (int i = 1; i <= n; i++)
            ans += i * fn(n / i);
        Console.WriteLine(ans);
    }
    static long fn(int n) => (long)n * (n + 1) / 2;
}


Measured memory_bytes: 27520
#include<iostream>
#include<queue>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
using namespace std;
#define N 100000
#define M 300000
#define HT 1000000000
#define INF 2e18
#define int long long
#define MP(i, j) make_pair((i), (j))
typedef pair<int, int> P;
int n, m, x, ans = INF, tree[N + 1];
vector<P> g[N + 1];
int flag[N + 1] = {};


struct S {
	int to, ti, nh;
	S(int i_to, int i_ti, int i_nh) : to(i_to), ti(i_ti), nh(i_nh) {}
	bool operator < (const S & s)const {
	  if(ti != s.ti)
		return ti > s.ti;
	}
};
priority_queue<S> pq;
void dijkstra(int sta) {
	for (int i = 0; i < g[1].size(); i++) {
		if (tree[1] >= g[1][i].second) {
			if (sta >= g[1][i].second) {
				if (sta > g[1][i].second + tree[g[1][i].first]) {
					pq.push({g[1][i].first, sta - tree[g[1][i].first],  tree[g[1][i].first] });
				}
				else {
					pq.push({g[1][i].first, g[1][i].second, sta - g[1][i].second });
				}
			}
			else {
				if (abs(sta - g[1][i].second) <= tree[1])
					pq.push({g[1][i].first, abs(sta - g[1][i].second) + g[1][i].second, 0 });
			}
		}
	}
	while (!pq.empty()) {
		S s = pq.top();
		pq.pop();
		if (flag[s.to] && flag[s.to] <= s.ti) continue;
		flag[s.to] = s.ti;
		if (s.to == n) {
			ans = min(ans, tree[n] - s.nh + flag[s.to]);
			break;
		}
		for (int i = 0; i < g[s.to].size(); i++) {
			if (tree[s.to] >= g[s.to][i].second) {
			  if (s.nh >= g[s.to][i].second) {
					if (s.nh > g[s.to][i].second + tree[g[s.to][i].first]) {
						pq.push({g[s.to][i].first, s.nh - tree[g[s.to][i].first] + s.ti,  tree[g[s.to][i].first] });
					}
					else {
						pq.push({g[s.to][i].first, g[s.to][i].second + s.ti, s.nh - g[s.to][i].second });
					}
				}
				else {
					if (g[s.to][i].second - s.nh <= tree[s.to])
						pq.push({g[s.to][i].first, g[s.to][i].second - s.nh+ g[s.to][i].second + s.ti, 0 });
				}
			}
		}
	}
}
signed main() {
  scanf("%lld%lld%lld", &n, &m, &x);
	for (int i = 1; i <= n; i++)
		scanf("%lld", tree + i);
	for (int i = 0; i < m; i++) {
		int a, b, c;
		scanf("%lld%lld%lld", &a, &b, &c);
		g[a].push_back(MP(b, c));
		g[b].push_back(MP(a, c));
	}
		dijkstra(x);
	if (ans != INF)
		cout << ans << endl;
	else
		cout << -1 << endl;
}

Measured memory_bytes: 33628
MOD = 1_000_000_007
H, W, K = gets.split.map(&:to_i)

if W == 1
  puts 1
else
  # Array dpのインデックスはすべて、問題文の数-1になっていることに注意
  
  # (0番目から数えて)8番目までのフィボナッチ数を作っておく
  # fib[i]は、i本の縦棒があるときの横棒の引き方の総数
  # 縦棒のインデックスがkなら、fib[k+1]が対応
  fib = [1, 1, 2, 3, 5, 8, 13, 21, 34]
  
  dp = Array.new(H).map{Array.new(W).map{Array.new(W, 0)}}
  
  # H = 1の場合
  W.times do |w|
    dp[0][w][0] = fib[w]
    dp[0][w][1] = fib[w-1] if w > 0
  end
  
  # 高さが1つ少ないときのパターン数が分かれば、以下で求められる
  # そのまま降りてくるパターン数 × その前後に横棒を引かない横棒の引き方総数
  # + 1つ前から移動してくる × 1つ前に横棒を引く横棒の引き方総数
  # + 1つ後ろから移動してくる × 1つ後ろに横棒を引く横棒の引き方総数
  1.upto(H-1) do |h|
    W.times do |w|
      0.upto(w) do |k|
        if k == 0
          dp[h][w][k] = (fib[W-1] * dp[h-1][w][0] % MOD) + (fib[W-2] * dp[h-1][w][1] % MOD)
          dp[h][w][k] %= MOD
        elsif k == W-1
          dp[h][w][k] = (fib[W-1] * dp[h-1][w][W-1] % MOD) + (fib[W-2] * dp[h-1][w][W-2] % MOD)
          dp[h][w][k] %= MOD
        else
          dp[h][w][k] = (fib[k] * fib[W-k-1] * dp[h-1][w][k] % MOD) + (fib[k-1] * fib[W-k-1] * dp[h-1][w][k-1] % MOD) + (fib[k] * fib[W-k-2] * dp[h-1][w][k+1] % MOD)
          dp[h][w][k] %= MOD
        end
      end
    end
  end
  
  puts dp[H-1][W-1][K-1]
end


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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    int minM = x + 1;
    for (int i = 0; i < n; i++) {
        cin >> m[i];
        x -= m[i];
        minM = min(minM, m[i]);
    }
    cout << n + x / minM << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main() {
	long long int n = 7, k;
	long long int ans = 1;
	long long int x;
	cin >> k;
	if (k == 1) {
		cout << 1 << endl;
		return 0;
	}
	while (1) {
		if (n % k==0) {
			cout << ans << endl;
			return 0;
		}
		x = n % k;
		n = x * 10 % k; 
		n += 7;
		n = n % k;
		ans++;
		if (ans > 2000000)break;
	}
	cout << -1 << endl;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;

int a,b,t;

int main(){
  cin >> a >> b >> t;
  int times = (int)t/a;
  cout << times * b << endl;
}

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

#define ll long long
#define int ll
#define pii pair<int, int>
#define pb push_back
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

using namespace std;

void solve() {
    int A, B;
    cin >> A >> B;

    print(max(0ll, A - 2*B));
}

signed main() {
    solve();
}


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

using ll = long long;
const ll INF = 1e18;

const int S = 1 << 19;
ll seg[7][2*S];
// half-open
ll query(int z, int l, int r) {
	ll ans = -INF;
	for (int a=S+l, b = S+r; a < b; a /= 2, b /= 2) {
		if (a & 1) {
			ans = max(ans, seg[z][a++]);
		}
		if (b & 1) {
			ans = max(ans, seg[z][--b]);
		}
	}
	return ans;
}
void update(int z, int i, ll v) {
	for (int a = S+i; a; a /= 2) {
		seg[z][a] = max(seg[z][a], v);
	}
}

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

	ll N; int M; ll X, Y; cin >> N >> M >> X >> Y;

	vector<pair<pair<ll, ll>, int>> robots;
	vector<ll> coords;
	for (int i = 0; i < M; i++) {
		int c; ll l, r; cin >> c >> l >> r; l--; c--;
		robots.push_back({{l,r},c});
		coords.push_back(r);
	}
	sort(robots.begin(), robots.end());
	sort(coords.begin(), coords.end());
	coords.resize(unique(coords.begin(), coords.end()) - coords.begin());

	for (int z = 0; z < 7; z++) {
		for (int i = 0; i < 2 * S; i++) {
			seg[z][i] = -INF;
		}
	}

	ll ans = 0;
	for (auto it : robots) {
		ll l = it.first.first, r = it.first.second; int c = it.second;
		int li = int(upper_bound(coords.begin(), coords.end(), l) - coords.begin());
		int ri = int(upper_bound(coords.begin(), coords.end(), r) - coords.begin());

		ll v = 0;
		v = max(v, query(6, 0, li));
		v = max(v, query(3+c, li, ri) + X * l);
		v = max(v, query((c+1)%3, li, ri) + (X + X + Y) * l);
		v = max(v, query((c+2)%3, li, ri) + (X + X + Y) * l);
		v += (r - l) * X;

		ans = max(ans, v);

		update(6, ri-1, v);
		update(3+c, ri-1, v - X * r);
		update(c, ri-1, v - (X + X + Y) * r);
	}
	cout << ans << '\n';

	return 0;
}



Measured memory_bytes: 68608
M, K = map(int, input().split())
if K >= 2**M:
    print(-1)
elif M == 1:
    if K == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
else:
    a = list(range(K)) + list(range(K+1, 2**M))
    ans = a[::-1] + [K] + a + [K]
    print(*ans)

Measured memory_bytes: 63216
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace at
{
    class Program
    {
        static void Main(string[] args)
        {
            int kotae = 0;

            var str = Console.ReadLine().Split(' ');
            int k = int.Parse(str[0]);
            int s = int.Parse(str[1]);

            for (int i = 0; i <= k; i++)
            {
                for (int o = 0; o <= k; o++)
                {
                    int z = s - i - o;
                    if(0<=z && z <= k) kotae++;                    
                }
            }
            Console.WriteLine(kotae);


            
        }        
    }
}

Measured memory_bytes: 11092
import bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(1,n):
    a[i] += a[i-1]
for i in range(1,m):
    b[i] += b[i-1]
ans = 0
for i in range(n):
    if a[i] <= k:
        ans = max(ans,i+1 + bisect.bisect_right(b,k-a[i]))
for i in range(m):
    if b[i] <= k:
        ans = max(ans,i+1 + bisect.bisect_right(a,k-b[i]))
print(ans)

Measured memory_bytes: 40560
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

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

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

    vector<tuple<int, int, int>> x(n * 2);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        x[i*2] = make_tuple(a, i, 0);
        x[i*2+1] = make_tuple(b, i, 1);
    }
    sort(x.begin(), x.end());

    bool a, b;
    a = b = false;
    int ans1 = 0;
    rep(i, n){
        int type = get<2>(x[i]);
        if(type){
            b = true;
        }else{
            a = true;
        }
        ans1 += get<0>(x[i]);
    }

    if(a && b){
        ans1 = INF;
    }

    int ans2 = 0;
    bool dup = false;
    set<int> s;
    rep(i, n-1){
        int id = get<1>(x[i]);
        if(s.find(id) != s.end()){
            dup = true;
        }
        s.insert(id);
        ans2 += get<0>(x[i]);
    }

    if(dup || s.find(get<1>(x[n-1])) != s.end()){
        ans2 += get<0>(x[n-1]);
        cout << min(ans1, ans2) << endl;
        return 0;
    }

    if(dup || s.find(get<1>(x[n])) != s.end()){
        ans2 += get<0>(x[n]);
        cout << min(ans1, ans2) << endl;
        return 0;
    }

    ans2 = 0;
    rep(i, n-2){
        ans2 += get<0>(x[i]);
    }

    ans2 = min(ans2 + get<0>(x[n-2]) + get<0>(x[n+1]), ans2 + get<0>(x[n-1]) + get<0>(x[n]));
    cout << min(ans1, ans2) << endl;

    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a)for(int i=b;i>=a;i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int a,b,c;
  cin>>a>>b>>c;
  cout<<(a+b>=c?"Yes":"No")<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int k, a, b;

int read() {
    int x = 0, f = 1; char s;
    while((s = getchar()) < '0' || s > '9') if(s == '-') f = -1;
    while(s >= '0' && s <= '9') {x = (x << 1) + (x << 3) + (s ^ 48); s = getchar();}
    return x * f;
}

int main() {
    k = read(), a = read(), b = read();
    for(int i = a; i <= b; ++ i)
        if(i % k == 0) {puts("OK"); return 0;}
    puts("NG");
    return 0;
}


Measured memory_bytes: 1528
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)


def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


n, a, b = map(int, readline().split())
mod = 10 ** 9 + 7
print(((pow(2, n, mod) - 1) % mod - (combination(n, a) % mod + combination(n, b) % mod) % mod) % mod)


Measured memory_bytes: 3064
#include<iostream> 
#include<string> // for string class
#include <math.h> 
#include<bits/stdc++.h> 
using namespace std; 
int main() 
{
	string a;
	//int a1,b1;
	//string c;
	cin>> a;//>>b;
	//cin>>a1>>b1;
	//cin>>c;
     //if(a.comapre(c)==1)a1--;
     //else if(b.compare(c)==1)b1--;
     //cout<<a1<<" "<<b1;
     for(int i=1;i<=a.length();i++)
     	cout<<"x";

 return 0;

}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#include <numeric>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
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 N; cin >> N;
    string s; map<string, int>cnt;
    rep(i, N) {
        cin >> s;
        cnt[s]++;
    }
    cout << "AC x " << cnt["AC"] << endl;
    cout << "WA x " << cnt["WA"] << endl; 
    cout << "TLE x " << cnt["TLE"] << endl; 
    cout << "RE x " << cnt["RE"] << endl;
}

    


    


    





















Measured memory_bytes: 3632
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]

for i in range(N - M + 1):
    for j in range(N - M + 1):
        for k in range(M):
            if A[i+k][j:j+M] != B[k][:]:
                break
        else:
            print("Yes")
            exit()

print("No")


Measured memory_bytes: 3060