akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N, M; cin >> N >> M;
    vector<int>a(N);
    vector<int>b(N);
    vector<int>c(M);
    vector<int>d(M);
    rep(i, N)cin >> a[i] >> b[i];
    rep(i, M)cin >> c[i] >> d[i];
    rep(i, N) {
        int e = abs(a[i] - c[0]) + abs(b[i] - d[0]);
        int f = 0;
        REP(j, M)e = min(e, abs(a[i] - c[j]) + abs(b[i] - d[j]));
        rep(j, M) {
            if (e == abs(a[i] - c[j]) + abs(b[i] - d[j])) {
                cout << j+1 << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

#define VECTOR_LIMIT (100000+5)

int x[VECTOR_LIMIT] = { 0 };

int main() {

	long long res = 0;
	long long s[2] = { 0,0 };
	int n,i,a=0;

	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> x[i];
	}

	sort(x, x+n, greater<int>());

	for (i = 0; i < n; i++) {
		if (x[i] == x[i + 1]) {
			s[a] = x[i];
			i++;
			a++;
		}
		if (a > 1) {
			break;
		}
	}

	res = s[0] * s[1];
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
x, y, a, b, c = map(int, input().split())
p = [0]+list(map(int, input().split()))
q = [0]+list(map(int, input().split()))
r = [0]+list(map(int, input().split()))
p.sort()
q.sort()
r.sort()
ans = 0
num = x+y
for _ in range(num):
    if x > 0 and y > 0:
      i, j, k = p[-1], q[-1], r[-1]
      if i >= j and i >= k:
          ans += i
          p.pop()
          x -= 1
      elif j >= i and j >= k:
          ans += j
          q.pop()
          y -= 1
      else:
          ans += k
          r.pop()
    elif x > 0:
        i, j = p[-1], r[-1]
        x -= 1
        if i >= j:
            ans += i
            p.pop()
        else:
            ans += j
            r.pop()
    elif y > 0:
        y -= 1
        i, j = q[-1], r[-1]
        if i >= j:
            ans += i
            q.pop()
        else:
            ans += j
            r.pop()
    
print(ans)


Measured memory_bytes: 28908
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h = I()
ans = 0
cnt = 0
while h > 1:
    h //= 2
    ans += 2**cnt
    cnt += 1
ans += 2**cnt
print(ans)

Measured memory_bytes: 38256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }

int main(){
    LL n;
    cin >> n;
    vector<pair<LL,LL>> a(n);
    for(LL i = 0; i < n; ++i){
        LL x, l;
        cin >> x >> l;
        a[i].first = x-l;
        a[i].second = x+l;
    }
    sort(a.begin(), a.end());
    map<LL,LL> update;
    LL ans = 0;


    for(auto p: a){
        while(!update.empty() && p.first >= update.begin()->first){
            ans = max(ans, update.begin()->second);
            update.erase(update.begin());
        }
        update[p.second] = max(ans+1, update[p.second]);
    }
    while(!update.empty()){
        ans = max(ans, update.begin()->second);
        update.erase(update.begin());
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define endl "\n"
#define ENGZ ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);cin.tie(0) , cout.tie(0) ;
#define mod (ll)(1e9+7)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define F first
#define S second
#define PB push_back
#define pb pop_back()
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rREP(i,a,b) for(int i=a;i>=b;i--)
#define MAX 500002
#define MOD 1000003
#define EPS 1e-6
#define PI 3.1415926535
using namespace std;

typedef long long ll;
typedef unsigned long long ull ;
typedef vector<int> vi;
typedef pair<int,int> pi;

ll FP(ll a, ll x){
    if(x==0) return 1;
    if(x==1) return a;
    ll ans = FP(a, x/2) ;
    ans = ans * ans ;
    if(x%2!=0)
        ans = ans * a ;
    return ans ;
}

int main(){
    ENGZ
    int n , m ;
    int x;
    cin >> n >> m ;
    priority_queue<int> pq ;
    REP(i,0,n){
        cin >> x ;
        pq.push(x);
    }
    int curr , cnt = 1;
    while(m--){
        curr = pq.top() ;
        pq.pop();
        curr -= ceil(curr / 2.0) ;
        //cout << curr << endl;
        pq.push(curr);
    }
    ll ans = 0 ;
    while(!pq.empty()){
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

int main() {
    int n, m;
    cin >> n >> m;
    pii ab[n];
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        ab[i] = pii(a, b);
    }
    sort(ab, ab+n);

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += 1ll * ab[i].first * min(ab[i].second, m);
        m -= ab[i].second;
        if (m <= 0) {
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

long long abs(long long A);
int main(void)
{
    long long X,K,D,q,r,ans=0;
    scanf("%lld %lld %lld",&X,&K,&D);
    X=abs(X);
    D=abs(D);
    q=X/D;
    r=X%D;

    if(K<=q){
        ans=X-K*D;
        // printf("A");
    } else {
        if((K-q)%2==0){
            ans=X%D;
            // printf("B");
        } else {
            ans=abs(D-r);
            // printf("C");
        }
    }
    printf("%lld",ans);
    return 0;
}

long long abs(long long A)
{
    if(A<0) A=(-1)*A;
    return A;
}


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

int main(){
	int n;
	cin >> n;
	vector<int> c(9, 0);
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		c[min(a/400, 8)]++;
	}
	int ans=0;
	for(int i=0; i<8; i++){
		if(c[i]!=0){
			ans++;
		}
	}
	cout << max(ans, 1) << " " << ans+c[8] << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    var m = sc.nextInt()
    var ans = m

    for (i in 1..n) {
        m += sc.nextInt() - sc.nextInt()
        if (m < 0) { ans = 0; break }
        ans = Math.max(ans, m)
    }
    println(ans)
}


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

using namespace std;

typedef long long llong;

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

    llong k, q;
    cin >> k >> q;

    vector<llong> d(k);
    for (llong i = 0; i < k; i++)
        cin >> d[i];

    while (q--)
    {
        llong n, x, m;
        cin >> n >> x >> m;
        x %= m;

        llong result = n - 1;
        llong total_sum = 0;

        for (llong i = 0; i < k; i++)
        {
            llong total_times = (n - 2 - i + k) / k;

            llong d_mod = d[i] % m;
            total_sum += total_times * d_mod;

            if (d[i] % m == 0)
                result -= total_times;
        }

        result -= (x + total_sum) / m;
        cout << result << "\n";
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
using namespace std;
ll h,n,a,sm=0;
int main(){
	ll i;
	cin>>h>>n;
	for(i=0;i<n;i++)
	{
		cin>>a;
		sm+=a;
	}
	if(sm>=h)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{	
	int n;
	cin >> n;
	n%=10;
	string ans;
	if(n == 3){
		ans = "bon";
	} else if(n == 1 || n == 0 || n == 6 || n == 8){
		ans = "pon";
	} else ans = "hon";
	cout << ans << endl;
}


Measured memory_bytes: 3604
import numpy as np
n,c=map(int, input().split())
a=[list(map(int, input().split())) for  i in range(n)]
a.sort(key=lambda x: (x[2],x[0]))
ans=np.array([0]*3*10**5)
channel,last=0,0
for i,j,k in a:
    if channel==k and last==i:
        ans[i*2+1:j*2+1]+=1
        last=j
    else:
        ans[i*2-1:j*2+1]+=1
        last=j
        channel=k
print(ans.max())

Measured memory_bytes: 47568
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N;
    cin >> N;
    
    vector<string> W(N);
    REP(i, N) cin >> W[i];
    
    set<string> st;

    bool ans = true;
    REP(i, N) {
        if (st.count(W[i])) ans = false;
        else st.insert(W[i]);
        if (i == N-1) break;
        if (W[i][W[i].size()-1] != W[i+1][0]) ans = false;
    }

    cout << (ans ? "Yes" : "No") << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(b<=c||a>=d){
        cout << 0;
        return 0;
    }
    if(b>=d){
        if(a>=c){
            cout << d-a;
        }else{
            cout << d-c;
        }
    }else{
        if(a>=c){
            cout << b-a;
        }else{
            cout << b-c;
        }
    }
}

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

int main() {
	int n, l;
	cin >> n >> l;
	vector<int> a(n);
	rep(i, n) {
		a[i] = l + i;
	}
	int s = 0;
	rep(i, n) s += a[i];
	int ans = 1e9;
	rep(i, n) {
		int t = s - a[i];
		if (abs(t - s) < abs(ans - s))ans = t;
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

typedef double ll;

struct Point
{
    ll x,y;
    Point(){ x = y = 0.0; }
    Point(ll _x, ll _y) : x(_x), y(_y){}

    Point operator+ (Point p)
    {
        return Point(p.x + x, p.y + y);
    }

    Point operator- (Point p)
    {
        return Point(x - p.x, y - p.y);
    }

    ll operator* (Point p)
    {
        return p.x * x + p.y * y;
    }

    Point operator* (ll t)
    {
        return Point(x*t, y*t);
    }

    ll operator~ ()
    {
        return x * x + y * y;
    }

    ll operator% (Point p)
    {
        return x * p.y - y * p.x;
    }

};

Point polygon[200];
int n;

bool ccw(Point a, Point b, Point p)
{
    return ( (b-a)%(p-a) ) < 0;
}

bool isConvex()
{
    if(n+1 <= 3) return false;
    bool isLeft = ccw(polygon[0], polygon[1], polygon[2]);
    for(int i = 1 ; i < n; i++)
        if(ccw(polygon[i-1],polygon[i],polygon[i+1]) != isLeft)
            return false;
    return true;

}

int main()
{
    cout << fixed;
    cout.precision(1);
    ios::sync_with_stdio(0); cin.tie(0);
    Point p;
    cin >> n;
    for(int i = 0 ; i < n ; i++)
        cin >> polygon[i].x >> polygon[i].y;
    polygon[n] = polygon[0];
    cout << isConvex() << '\n';
    return 0;
}

Measured memory_bytes: 3272
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
                
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pretime float(clock()-clk)/CLOCKS_PER_SEC
#define rep(i,a,b) for(i=a;i<=b;++i)
#define rev(i,a,b) for(i=a;i>=b;--i) 
#define max2(a,b) ((a)>(b)?(a):(b))   
#define min2(a,b) ((a)<(b)?(a):(b)) 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define ll long long int 
#define ins insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
#define inf 1000000000000000
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'

using namespace std;
typedef pair<ll,ll>     pll;
typedef pair<int,int>   pii;
typedef vector<ll>      vll;
typedef vector<int>      vi;
typedef vector< pll >  vpll;
typedef vector< pii >  vpii;
typedef set<ll>         sll;
typedef set<int>         si;
typedef set< pll >     spll;
typedef set< pii >     spii;
clock_t clk=clock();       

ll i,j,k;
void solve(void);

int main()
{
  speedio;
   int t=1;  
  // cin>>t;
   while(t--)
     solve();

  return 0;
}
// #define cerr if(0)cerr

void solve()
{
	int n; cin>>n;
	int p[n];
	rep(i,0,n-1) cin>>p[i];

int ct=0;
	rep(i,1,n-2)
	{
		sll t;
		t.ins(p[i-1]); t.ins(p[i]); t.ins(p[i+1]);
		if(sz(t)==3)
		{
			auto it=t.begin(); ++it;
			if(*it==p[i]) ++ct;
		}
	}
	cout<<ct<<'\n';
}

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

int n;
string s;

bool dp[1010][3][3];

int main()
{
	cin >> s;
	n = s.size();

	for(int i = 0;i < 1010;i++)
	{
		for(int j = 0;j < 3;j++)
		{
			for(int k = 0;k < 3;k++)
			{
				dp[i][j][k] = false;
			}
		}
	}

	dp[0][1][1] = true;

	for(int i = 1;i <= n;i++)
	{
		char c = s[i - 1];

		if(c == 'N')
		{
			for(int y = 0;y < 3;y++)
			{
				dp[i][0][y] = dp[i - 1][0][y];
				dp[i][1][y] = dp[i][1][y] || dp[i - 1][0][y];
				dp[i][2][y] = dp[i][2][y] || dp[i - 1][1][y] || dp[i - 1][0][y];
			}
		}
		if(c == 'S')
		{
			for(int y = 0;y < 3;y++)
			{
				dp[i][2][y] = dp[i - 1][2][y];
				dp[i][1][y] = dp[i][1][y] || dp[i - 1][2][y];
				dp[i][0][y] = dp[i][0][y] || dp[i - 1][1][y] || dp[i - 1][2][y];
			}
		}
		if(c == 'W')
		{

			for(int x = 0;x < 3;x++)
			{
				dp[i][x][2] = dp[i - 1][x][2];
				dp[i][x][1] = dp[i][x][1] || dp[i - 1][x][2];
				dp[i][x][0] = dp[i][x][0] || dp[i - 1][x][1] || dp[i - 1][x][2];
			}
		}
		if(c == 'E')
		{

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

	if(dp[n][1][1])
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}





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

using namespace std;

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

	int sum = 0;
	while (s != "0") {
		sum = 0;
		for (int i = 0; i < s.length(); i++) {
			sum += s[i] - '0';
		}
		cout << sum << endl;

		cin >> s;
	}
	
	return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())

int main()
{
    int a,b,h,m;
    cin >> a >> b >> h >>m;

    double akaku, bkaku;
    akaku = 2*M_PI*(h*60+m)/12/60;
    bkaku = 2*M_PI*m/60;

    double ax,ay,bx,by;
    int alphax=1;
    int alphay=1;

    if(akaku >= M_PI/2 && akaku < M_PI){
      akaku = M_PI-akaku;
      alphay = -1;
    }else if(akaku >= M_PI && akaku < 3*M_PI/2){
      akaku = akaku-M_PI;
      alphax = -1;
      alphay = -1;
    }else if(akaku >= 3*M_PI/2){
      akaku = 2*M_PI-akaku;
      alphax = -1;
    }

    ax = alphax * a * sin(akaku);
    ay = alphay * a * cos(akaku);

    alphax=1;
    alphay=1;

    if(bkaku >= M_PI/2 && bkaku < M_PI){
      bkaku = M_PI-bkaku;
      alphay = -1;
    }else if(bkaku >= M_PI && bkaku < 3*M_PI/2){
      bkaku = bkaku-M_PI;
      alphax = -1;
      alphay = -1;
    }else if(bkaku >= 3*M_PI/2){
      bkaku = 2*M_PI-bkaku;
      alphax = -1;
    }
    bx = alphax * b * sin(bkaku);
    by = alphay * b * cos(bkaku);
    
    double ans = sqrt((bx-ax)*(bx-ax) + (by-ay)*(by-ay)); 
    printf("%.20lf\n", ans);
}


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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;

lli n,z,w;
vll a;

int main(){
  cin >> n >> z >> w;
  a = vll(n+1);
  a[0] = w;
  for(lli i = 1;i <= n;i++) cin >> a[i];
  cout << max(abs(a[n]-w),abs(a[n-1]-a[n])) << endl;
}


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

int main() {
    int x, y;
    cin >> x >> y;

    int ans = 0;
    if (x <= 3) {
       if (x == 3) {
           ans += 100000;
       } else if (x == 2) {
           ans += 200000;
       } else if (x == 1) {
           ans += 300000;
       }
        
    }
    if (y <= 3) {
       if (y == 3) {
           ans += 100000;
       } else if (y == 2) {
           ans += 200000;
       } else if (y == 1) {
           ans += 300000;
       }
    }
    if (x == 1 && y == 1) {
         ans += 400000;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#define int long long int

using namespace std;

signed main(){
    int N, A, B;
    cin >> N >> A >> B;

    if(A*N < B){
        cout << A*N << endl;
    }else{
        cout << B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
 int A=0,B=0;
 char s[100001]={};
 scanf("%s",s);
 for (int i=0;i<strlen(s);i++)
  if((i%2==0&&s[i]=='1')||(i%2==1&&s[i]=='0'))
   A++;
  else
   B++;
 printf("%d\n",A>B?B:A);
 return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
  int min = 10000, min2 = 10000;
  for(int i=0; i<3; i++) {
    int a;
    scanf("%d",&a);
    if ( a < min ) {
      min2 = min;
      min = a;
    } else if (a < min2) {
      min2 = a;
    }
  }

  printf("%d\n",min+min2);
  return 0;
}


Measured memory_bytes: 128
n=gets.to_i
a=gets.split.map(&:to_i)
b=gets.split.map(&:to_i)
c=gets.split.map(&:to_i)
 
b_sum=b.reduce(0,:+)
c_sum=a.each_cons(2).select{|x,y| x+1==y }.map{|x,_|c[x-1]}.reduce(0,:+)
 
print(b_sum+c_sum)

Measured memory_bytes: 3836
time = [int(input()) for _ in range(5)]

import math
ans = 0
minmod = 10
for i in range(5):
  if time[i]%10!=0:
    minmod = min(minmod,time[i]%10)
  else:
    minmod = min(minmod,10)
  ans += math.ceil(time[i]/10)*10

ans -= (10-minmod)
print(ans)

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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

int n,m;
int a,b;
int vis[200001];
vector<int> edges[200001];

int dfs(int d){
	vis[d]=1;
	int num=1;
	forn(i,0,edges[d].size())
		if (!vis[edges[d][i]])
			num+=dfs(edges[d][i]);
	return num;
}

signed main(){
	ios::sync_with_stdio(false);
   	cin.tie(0);

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	cin>>n>>m;
	while (m--){
		cin>>a>>b;
		a--,b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	int ans=-1;
	forn(i,0,n){
		if (!vis[i])
			ans=max(ans,dfs(i));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 25432
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
#define INF = 1000000000;
#define LLINF = 1LL << 62;
#define mod = 1000000007;
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 gcd(int a, int b) {
    while (1) {
        if (a < b) swap(a, b);
        if (!b) break;
        a %= b;
    }
    return a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int main() {
    int x, y;
    cin >> x >> y;
    cout << x + 1 + y - gcd(x, y) << endl;
}



Measured memory_bytes: 3104
#include <iostream>
using namespace std;
int main(){
  int N,X;cin>>N>>X;
  int sm = 0;
  int min = X;
  for(int i = 0; N > i; i++){
    int tmp;cin>>tmp;
    if(min > tmp)min = tmp;
    sm += tmp;
  }
  X-=sm;
  cout << N+X/min<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int fibonacci(int );


int F[45];

int main(){

  int n;

  scanf("%d",&n);
  printf("%d\n",fibonacci(n));


  return 0;
}


int fibonacci(int n){

  if( n==0 ||  n == 1 ) return  F[n]= 1; 

  if( F[n]  != 0 )return F[n];

  return F[n] = fibonacci( n - 2 ) + fibonacci( n -1 );

}



Measured memory_bytes: 2108
import itertools

N = int(input())
As = []
xys = []
for _ in range(N):
    a = int(input())
    As.append(a)
    xys.append([tuple(map(int, input().split())) for _ in range(a)])


ans = -1
for is_shoziki in itertools.product([1, 0], repeat=N):
    n = sum(is_shoziki)
    if n <= ans:
        continue
    flg = True
    for i in range(N):
        if not flg:
            break
        if is_shoziki[i] == 0:
            continue
        for x, y in xys[i]:
            if is_shoziki[x - 1] != y:
                flg = False
                break
    if flg:
        ans = n

print(ans)


Measured memory_bytes: 74760
if __name__ == '__main__':
	n = int(input())
	t,a = map(int,input().split())
	H = list(map(int,input().split()))

	A = [t - x * 0.006 for x in H]

	tmp = abs(a - A[0])
	ind = 0
	for i,y in enumerate(A,1):
		if tmp >= abs(a - y):
			tmp = abs(a - y)
			ind = i
		
	print(ind)


Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int k;
int r[10], c[10];
int dx[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
int dy[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
vector<vector<bool>> ans;
bool f;


auto paint(int y, int x, const vector<vector<bool>>& b){
    auto res = b;
    rep(i, 0, 8){
        int Y = y;
        int X = x;
        while(isin(Y, 0, 8) and isin(X, 0, 8)) res[Y][X] = true, Y += dy[i], X += dx[i];
    }
    return res;
}


bool jdg(const vector<vector<bool>>& res){
    int c = 0;
    rep(i, 0, 8) rep(j, 0, 8) if(res[i][j]) c++;
    return c == 8;
}


void dfs(int y, int x, const vector<vector<bool>>& preb, const decltype(preb)& _res){
    auto b = paint(y, x, preb);
    auto res = _res;
    res[y][x] = true;
    if(jdg(res)){ ans = res; f = true; return; }
    rep(i, 0, 8) rep(j, 0, 8) if(!f and !b[i][j]) dfs(i, j, b, res);
}


signed main(){
    cin >> k;
    rep(i, 0, k) cin >> r[i] >> c[i];

    vector<vector<bool>> ini(10, vector<bool>(10));
    auto inir = ini;
    rep(i, 0, k) ini = paint(r[i], c[i], ini), inir[r[i]][c[i]] = true;

    rep(i, 0, 8) rep(j, 0, 8)
        if(!ini[i][j]) dfs(i, j, ini, inir);

    if(!f) ans = inir;
    rep(i, 0, 8){
        rep(j, 0, 8)
            if(ans[i][j]) cout << 'Q';
            else cout << '.';
        cout << endl;
    }

    return 0;
}


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

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

	bool f = true;

	for (int i = 0; i < s.size(); i += 2)
	{
		f &= (s[i] == 'R') || (s[i] == 'U') || (s[i] == 'D');
	}
	for (int i = 1; i < s.size(); i += 2)
	{
		f &= (s[i] == 'L') || (s[i] == 'U') || (s[i] == 'D');
	}

	cout << (f ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int A[200011];
int B[200011];
bool in[200011];

VI st;
void add(int v) {
    if (!in[v]) {
	st.push_back(v);
	in[v] = true;
    }
}

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);
    REP (i, N) scanf("%d", B+i);

    LL ans = 0;

    REP (i, N) {
	add(i);
    }
    while (!st.empty()) {
	int v = st.back();
	st.pop_back();
	in[v] = false;
	int left = (v+N-1) % N;
	int right = (v+1) % N;
	if (B[v] > B[left] + B[right]) {
	    LL t = (B[v] - A[v]) / (B[left] + B[right]);
	    if (t > 0) {
		B[v] = B[v] - (B[left] + B[right]) * t;
		ans += t;
		add(left);
		add(v);
		add(right);
	    }
	}
    }

    bool yes = true;
    REP (i, N) if (A[i] != B[i]) yes = false;
    if (yes) {
	printf("%lld\n", ans);
    } else {
	puts("-1");
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector< vector<int> > a(H, vector<int>(W)), b(H, vector<int>(W));
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> b[i][j];
        }
    }

    vector< vector< bitset<30001> > > dp(H, vector< bitset<30001> >(W));
    constexpr int geta = 15000;
    dp[0][0].set(abs(a[0][0] - b[0][0]) + geta);
    dp[0][0].set(-abs(a[0][0] - b[0][0]) + geta);
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (i > 0) dp[i][j] |= ((dp[i - 1][j] << abs(a[i][j] - b[i][j])) | (dp[i - 1][j] >> abs(a[i][j] - b[i][j])));
            if (j > 0) dp[i][j] |= ((dp[i][j - 1] << abs(a[i][j] - b[i][j])) | (dp[i][j - 1] >> abs(a[i][j] - b[i][j])));
        }
    }
    
    int ans = geta;
    for (int i = -geta; i <= geta; ++i) {
        if (dp[H - 1][W - 1][i + geta]) {
            ans = min(ans, abs(i));
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	priority_queue<int> Q;
	for(int i = 0; i < 10; i++) {
		int a;
		cin >> a;
		Q.push(a);
	}
	for(int i = 0; i < 3; i++) {
		cout << Q.top() << endl;
		Q.pop();
	}
}

Measured memory_bytes: 1208
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int minv = min(a, b);
    for (int i = 0; i < max(a, b); ++i) {
        cout << minv;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int h, w, n, a, b[10010];
int main() {
	cin >> h >> w >> n;
	int sum = 1;
	rep(i, n) {
		b[sum]++;
		cin >> a;
		sum += a;
	}
	for (int i = 1; i <= h * w; i++) {
		b[i] += b[i - 1];
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w - 1; j++) {
			if (i % 2)cout << b[i * w + w - j] << " ";
			else cout << b[i * w + j + 1] << " ";
		}
		if(i % 2)cout << b[i * w + 1] << endl;
		else cout << b[(i + 1) * w] << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define f first
#define s second
#define int long long
#define pb push_back
#define pencho ios_base::sync_with_stdio(false);cin.tie(NULL);
#define N 405
#define MOD 1000000007

int a[N];
int dp[N][N];
int prefix[N] = {0};

int solveDp(int beg, int end) {
       if (beg >= end)      return 0;
       if (dp[beg][end] != -1) return dp[beg][end];

       dp[beg][end] = solveDp(beg, end - 1) + solveDp(end, end) + prefix[end] - prefix[beg - 1];
       for (int i = end - 1; i >= beg; i--)
              dp[beg][end] = min(dp[beg][end], solveDp(beg, i) + solveDp(i + 1, end) + prefix[end] - prefix[beg - 1]);
       return dp[beg][end];
}


void solve() {
       int n; cin >> n;
       for (int i = 1; i <= n; i++) cin >> a[i];
       for (int i = 1; i <= n; i++) prefix[i] = prefix[i - 1] + a[i];
       memset(dp, -1, sizeof(dp));
       for (int i = 0; i < n; i++) dp[i][i] = 0;
       cout << solveDp(1, n);
}


signed main()
{
#ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("o.txt", "w", stdout);
#endif

       solve();
}

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

typedef long long LL;
typedef pair<int, int> II;

int main() {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;

    for (int i = 0; i < (int)a.size(); ++i) {
        cout << a[i] << b[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int n, m; cin >> n >> m;
    vector<bool> reachable(n, false);
    REP(i, m){
        int a, b; cin >> a >> b;
        if(a == 1){
            if(reachable[b]){
                cout << "POSSIBLE\n";
                return 0;
            }
            else reachable[b] = true;
        }
        if(b == n){
            if(reachable[a]){
                cout << "POSSIBLE\n";
                return 0;
            }
            else reachable[a] = true;
        }
    }
    cout << "IMPOSSIBLE\n";
    return 0;
}

Measured memory_bytes: 256
#coding: utf-8
a, b = map(int, input().split())

intt_array = [0] * 3
intt_array[0] = a + b
intt_array[1] = a - b
intt_array[2] = a * b
# intt_array[3] =

intt_array.sort(reverse=True)
print(intt_array[0])


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
char a[105][105];
int n,m;
int nx,ny;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void dfs(int x,int y,char z)
{
    a[x][y]='1';
    for(int k=0;k<4;k++)
    {
        nx=x+dx[k];
        ny=y+dy[k];
        if(nx>=0&&nx<n&&ny>=0&&ny<m&&a[nx][ny]==z)
            dfs(nx,ny,z);
    }

}
int main()
{
    while(cin>>n>>m&&(n!=0||m!=0))
    {
        int num=0;
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                cin>>a[i][j];
                for(int i=0;i<n;i++)
                    for(int j=0;j<m;j++)
                    if(a[i][j]!='1')
                {
                    dfs(i,j,a[i][j]);
                    num++;
                }
                cout<<num<<endl;
    }
    return 0;
}



Measured memory_bytes: 3544
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        if ((C-A+B)<=0){
            System.out.println(0);
        }else {
            System.out.println(C-A+B);
        }
        
    }
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef pair<int,int> P;
struct st{
  int h,w;
  vector<string> vs;
  st(){}
  st(int h1,int w1,vector<string> ts){
    vs.push_back(string(w1+2,'.'));
    for(int i=0;i<h1;i++) vs.push_back('.'+ts[i]+'.'); 
    vs.push_back(string(w1+2,'.'));
    h=h1+2;w=w1+2;
    construct();
  }
  int ax[8]={1,-1,0,0,1,1,-1,-1};
  int ay[8]={0,0,1,-1,1,-1,1,-1};
  int color[111][111];
  int cnt;
  void construct(){
    //for(int i=0;i<h;i++) cout<<vs[i]<<endl;cout<<endl;
    memset(color,-1,sizeof(color));
    cnt=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(~color[i][j]) continue;
	queue<P> q;
	q.emplace(i,j);
	color[i][j]=cnt;
	while(!q.empty()){
	  P p=q.front();q.pop();
	  int y=p.first,x=p.second;
	  for(int k=0;k<4+4*(vs[i][j]=='#');k++){
	    int ny=y+ay[k],nx=x+ax[k];
	    if(ny<0||h<=ny||nx<0||w<=nx) continue;
	    if(vs[y][x]!=vs[ny][nx]) continue;
	    if(~color[ny][nx]) continue;
	    color[ny][nx]=cnt;
	    q.emplace(ny,nx);
	  }
	}
	cnt++;
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	int y=i,x=j;
	for(int k=0;k<4;k++){
	  int ny=y+ay[k],nx=x+ax[k];
	  if(ny<0||h<=ny||nx<0||w<=nx) continue;
	  if(color[y][x]!=color[ny][nx]){
	    G[color[y][x]].insert(color[ny][nx]);
	    G[color[ny][nx]].insert(color[y][x]);
	  }
	}
      }
    }
  }
   
  set<int> G[11111];
  string dfs(int v,int p=-1){
    if(G[v].empty()) return "()";
    string res;
    vector<string> x;
    for(int i:G[v]) if(i!=p) x.push_back(dfs(i,v));
    sort(x.begin(),x.end());
    for(string i:x) res+=i;
    return "("+res+")";
  }
  string hash(){
    return dfs(0);
  }
};
signed main(){
  int h,w;
  while(cin>>h>>w,h||w){
    vector<string> vs(h);
    for(int i=0;i<h;i++) cin>>vs[i];
    st t1(h,w,vs);
    cin>>h>>w;
    vs.clear();vs.resize(h);
    for(int i=0;i<h;i++) cin>>vs[i];
    st t2(h,w,vs);
    if(t1.hash()==t2.hash()) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

Measured memory_bytes: 4500
N,K=map(int,input().split())

chk=[0 for _ in range(N)]

for i in range(K):
    d=int(input())
    A=list(map(int,input().split()))
    for j in range(d):
        a=A[j]-1
        chk[a]=1

ans=0
for i in range(N):
    if chk[i]==0:
        ans+=1

print(ans)

Measured memory_bytes: 9196
A, B, C, D = gets.chomp.split('')
(0...8).each do |i|
    op = []
    3.times do |j|
        op[j] = i % 2 == 1 ? '+' : '-'
        i /= 2
    end
    eq = A + op[0] + B + op[1] + C + op[2] + D
    if eval(eq) == 7
        puts eq + '=7'
        exit
    end
end

Measured memory_bytes: 3836
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int h,w; cin>>h>>w;
    int board[53][53]={},board2[53][53]={};
    string s;
    for(int i=0;i<h;i++){
        cin>>s;
        for(int j=0;j<w;j++){
            if(s[j]=='#'){
                board[i+1][j+1]=1;
            }
        }
    }
    for(int i=1;i<h+1;i++){
        for(int j=1;j<w+1;j++){
            if(board[i][j]==0){
                for(int k=-1;k<=1;k++){
                    for(int m=-1;m<=1;m++){
                        board2[i][j]+=board[i+k][j+m];
                    }
                }
            }else{
                board2[i][j]=99;
            }
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(board2[i][j]==99){
                cout<<"#";
            }else{
                cout<<board2[i][j];
            }
        }
        cout<<endl;
    }
    return 0;
}


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

int c[26];

int main(){
	string s;
	cin >> s;
	for(int i = 0; i < (int)s.size(); i++){
		c[s[i] - 'a'] = 1;
	}

	int flag = 1;
	for(int i = 0; i < 26; i++){
		if(c[i] == 0){
			flag = 0;
			char ans = i + 'a';
			cout << ans << endl;
			break;
		}
	}
	if(flag) cout << "None" << endl;

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define N 2000001
#define MOD 998244353
int n,m,t[N],mx[N],fa[N],cur,f[N];
map<int,int>id;
vector<int>d[N];
struct rua
{
	int d,x,r;
	void read(){scanf("%d%d",&d,&x);id[d]=id[d+x-1]=1;r=d+x-1;}
	bool operator <(const rua&t){return d<t.d;}
}a[N];
#define ls x*2
#define rs x*2+1
void Build(int x,int l,int r)
{
	if(l==r){mx[x]=l;return;}
	int mid=l+r>>1;
	Build(ls,l,mid);
	Build(rs,mid+1,r);
    mx[x]=max(mx[ls],mx[rs]);
}
int getMax(int L,int R,int x,int l,int r)
{
	if(L<=l && r<=R)return mx[x];
	int mid=l+r>>1,res=0;
	if(L<=mid)res=max(res,getMax(L,R,ls,l,mid));
	if(R>mid)res=max(res,getMax(L,R,rs,mid+1,r));
	return res;
}
void Change(int i,int c,int x,int l,int r)
{
	if(l==r){mx[x]=c;return;}
	int mid=l+r>>1;
	if(i<=mid)Change(i,c,ls,l,mid);
	else Change(i,c,rs,mid+1,r);
	mx[x]=max(mx[ls],mx[rs]);
}
void dfs(int x)
{
	f[x]=1;
	for(auto y:d[x])
	  dfs(y),f[x]=1ll*f[x]*f[y]%MOD;
	if(x)f[x]=(f[x]+1)%MOD;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  a[i].read();
	for(auto pi:id)id[pi.first]=++m;
	sort(a+1,a+n+1);
	Build(1,1,m);
	for(int i=n;i>=1;i--)
	  Change(id[a[i].d],a[i].r=getMax(id[a[i].d],id[a[i].r],1,1,m),1,1,m),a[i].d=id[a[i].d];
    stack<int>st;
	for(int i=1;i<=n;i++)
	  {
	  while(!st.empty() && a[i].d>st.top())st.pop(),cur=fa[cur];
	  d[cur].push_back(i);
	  st.push(a[i].r);
	  fa[i]=cur;
	  cur=i;
	  }
	dfs(0);
	printf("%d\n",f[0]);
}

Measured memory_bytes: 99968
#include <iostream>
using namespace std;
int main(){
    int n,x;
    cin >> n >> x;
    long long a[n+1];
    a[0]=0;
    long long eat=0;
    for (int i=1; i<n+1; i++){
        long long y;
        cin >> y;
        if (y+a[i-1]>x){
            eat+=y+a[i-1]-x;
            a[i]=x-a[i-1];
        }
        else {
            a[i]=y;
        }
    }
    cout << eat << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

int main() {
	int a, b;
	cin >> a >> b;
	cout << max(0, a - 2 * b) << endl;
}

Measured memory_bytes: 256
N = int(input().strip())

A = []
for _ in range(N):
  A.append(int(input().strip()))
  
A = list(sorted(A))

if N % 2 == 1:
  coef = [-2] * ((N - 2) // 2) + [-1, -1] + [2] * ((N - 2) // 2 + 1)
  s1 = sum(c * a for c, a in zip(coef, A))
  coef = [-2] * ((N - 2) // 2 + 1) + [1, 1] + [2] * ((N - 2) // 2)
  s2 = sum(c * a for c, a in zip(coef, A))
  print(max(s1, s2))
else:
  coef = [-2] * ((N - 2) // 2) + [-1, 1] + [2] * ((N - 2) // 2)
  print(sum(c * a for c, a in zip(coef, A)))


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

using namespace std;

int main()
{
	int N, K;
	string S;
	cin >> N >> K >> S;

	vector<int> stand, rev;

	int count = 1;
	for (int i = 1; i < N; i++)
	{
		if (S[i] != S[i - 1])
		{
			if (S[i - 1] == '0')
			{
				stand.push_back(count);
			}
			else
			{
				rev.push_back(count);
			}

			count = 1;
		}
		else
		{
			count++;
		}
	}
	if (S[N - 1] == '0')
	{
		stand.push_back(count);
	}
	else
	{
		rev.push_back(count);
	}


	if (rev.size() == 1 && stand.size() <= 1)
	{
		if (stand.size() == 1)
		{
			cout << rev[0] + stand[0] << endl;
			return 0;
		}
		else
		{
			cout << rev[0] << endl;
			return 0;
		}
	}

	if (stand.size() <= K)
	{
		cout << N << endl;
		return 0;
	}

	if (S[0] == '0')
	{
		rev.insert(rev.begin(), 0);
	}

	if (S[N - 1] == '0')
	{
		rev.push_back(0);
	}

	int ans = 0;

	for (int i = 0; i < rev.size() - K; i++)
	{
		int sum = 0;
		for (int k = 0; k <= K; k++)
		{
			sum += rev[k + i];
		}

		for (int k = 0; k < K; k++)
		{
			sum += stand[k + i];
		}

		ans = max(sum, ans);
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1020
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    if(B%A == 0):
        print(A+B)
    else:
        print(B-A)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<stdio.h>
int main(void){	
	int n,m,max,min,cal;
	scanf("%d %d",&n,&m);
	int l[m],r[m];
	max = 1;min = n;
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d",&l[i],&r[i]);
		if (l[i]>max)
		{
			max = l[i];
		}
		if (r[i]<min)
		{
			min = r[i];
		}
	}
	cal = min-max+1;
	if (cal>=0)
	{
		printf("%d\n",min-max+1);
	}else{
		printf("0\n");
	}
	
	return 0;
}


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

using namespace std;

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

int main(){
    int N;
    cin >> N;
    int A[N];
    
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    int gcdA = A[0];
    for(int i = 1; i < N; i++){
        gcdA = gcd(gcdA,A[i]);
    }


    cout << gcdA << endl;
    
    
    return 0;
}

    


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <cmath>
#include <climits>

using namespace std;

struct Data {
    int s, r;
};

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

    int k;
    cin >> k;
    int ck = k, sum = 0;
    while(ck) {
        sum += (ck % 10);
        ck /= 10;
    }

    vector<vector<bool>> visited(sum + 1, vector<bool> (k, 0));
    queue<Data> q;
    q.push({0, 0});
    visited[0][0] = 1;

    int summin = sum;
    while(q.size()) {
        auto x = q.front();
        q.pop();

        if(x.s < summin && x.r == 0 && x.s != 0)
            summin = x.s;


        for(int cif = 0; cif < 10; cif ++) {
            if(x.s + cif <= sum && !visited[x.s + cif][(x.r * 10 + cif) % k]) {
                visited[x.s + cif][(x.r * 10 + cif) % k] = 1;
                q.push({x.s + cif, (x.r * 10 + cif) % k});
            }
        }
    }
    cout << summin;

    return 0;
}


Measured memory_bytes: 13112
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int x, y;
  cin >> x >> y;
  cout << x + y / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   long a;
   cin>>a;
   if(a<=9)cout<<a<<endl;
   else if(a>9 && a<=99)cout<<"9"<<endl;
   else if(a>99 && a<=999)cout<<(a-90)<<endl;
   else if(a>999 && a<=9999)cout<<"909"<<endl;
   else if(a>9999 && a<=99999)cout<<(a-9090)<<endl;
   else cout<<"90909"<<endl;
return 0;
}



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

int main(){
	int s;

	scanf("%d", &s);

	std::vector<int> vec;
	vec.push_back(s);

	int i;
	for (i = 1; i < 1000000; i++) {
		int tmp = vec.at(i - 1);
		int push;
		if (tmp % 2 == 0) {
			push = tmp / 2;
		} else {
			push = tmp * 3 + 1;
		}

		if (std::find(vec.begin(), vec.end(), push) != vec.end()) {
			break;
		} else {
			vec.push_back(push);
		}
	}
	printf("%d\n", i + 1);

	return 0;
}


Measured memory_bytes: 256
fn func(input_str: &str) {
    let mut iter = input_str.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut b_s = Vec::new();
    for _ in 0..(n - 1) {
        let b: u32 = iter.next().unwrap().parse().unwrap();
        b_s.push(b);
    }

    let ans = b_s[0]
        + (0..(n - 2))
            .map(|i| std::cmp::min(b_s[i], b_s[i + 1]))
            .sum::<u32>()
        + b_s[n - 2];
    println!("{}", ans);
}

use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    func(&buf[..]);
}


Measured memory_bytes: 4352