akhauriyash/Code-Regression huggingface dataset:
function main(input) {
  input = input.split(' ');
  var N = parseInt(input[0]);
  var A = parseInt(input[1]);
  var B = parseInt(input[2]);
  if(N * A <= B){
    console.log(N*A);
  } else {
    console.log(B);
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7624
#include<iostream>
#define ll long long
using namespace std;

ll A,B,N,res;
ll ans;
int main(){
    scanf("%lld%lld%lld",&A,&B,&N);
    if( N >= B ){
        res = B-1;
    }else{
        res = N;
    }
    ans = (A*res/B) - A *(res/B);
    printf("%lld\n",ans);
}

Measured memory_bytes: 3784
#include <stdio.h>

int main(void) {
	int i,j,a,n,at[256][8],bk[128],sc[256] = {0};
	scanf("%d",&n);
	for(i = 1;i <= n;i++){
		scanf("%d%d%d",&at[i][1],&at[i][2],&at[i][3]);
	}
	for(i = 1;i <= 3;i++){
		for(j = 0;j <= 127;j++){bk[j]=0;}
		for(j = 1;j <= n;j++){a = at[j][i];bk[a]++;}
		for(j = 1;j <= n;j++){
			a = at[j][i];
			if(bk[a] == 1){sc[j]+=a;}
		}
	}
	for(i = 1;i <= n;i++){
		printf("%d\n",sc[i]);
	}
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	auto a = vector<int>(n);
	for(auto& b : a){
		cin >> b;
	}
	sort(a.begin(), a.end());
	int d = 0;
	for(auto i = 0; i < n; ++i){
		d += (i % 2 == 0 ? a[i] : -a[i]);
	}
	cout << (d > 0 ? d : -d) << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var x,ans int
	fmt.Scan(&x)
	
	for i := x; i < 100004; i++ {
		judge := true
		for j := 2; j < i; j++ {			
			if i % j == 0 {
				judge = false
				break
			}

		}
		if judge {
			ans = i
			break
		}
	}
	fmt.Println(ans)
}

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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int count(int a){

	int ans = 0;
	while(a % 2 == 0){
		ans++;
		a /= 2;
	}
	return ans;
}

int main(void){

	int N; cin >> N;
	vector<int> a(N);
	REP(i,N) cin >> a[i];

	int ans = 0;
	REP(i,N){
		ans += count(a[i]);
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)

class Segtree():
    INT_MAX=2**31-1

    def __init__(self,size):
        self.size=1
        while self.size<size:
            self.size=self.size*2
        self.node=[self.INT_MAX]*(2*self.size-1)

    def min_update(self,k,a):
        k+=self.size-1
        self.node[k]=a
        while k>0:
            k=(k-1)/2
            self.node[k]=min(self.node[k*2+1],self.node[k*2+2])

    def get_min(self,queryL,queryR,k=0,nodeL=0,nodeR=-1):
        if nodeR==-1:nodeR=self.size
        if (nodeR<=queryL or queryR<=nodeL):return self.INT_MAX
        if (queryL<=nodeL and nodeR<=queryR):return self.node[k]
        else:
            nodeM=(nodeL+nodeR)/2
            vl=self.get_min(queryL,queryR,k*2+1,nodeL,nodeM)
            vr=self.get_min(queryL,queryR,2*k+2,nodeM,nodeR)
            return min(vl,vr)

n,q=map(int,raw_input().split())
st=Segtree(n)
for i in xrange(q):
    com,x,y=map(int,raw_input().split())
    if com==0:
        st.min_update(x,y)
    if com==1:
        print(st.get_min(x,y+1))

Measured memory_bytes: 9204
s = input()
S = list(s)
K = int(input())
cnt1 = 0
cnt2 = 0
if len(set(S)) == 1:
  print(len(S) * K // 2)
  exit()
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    S[i+1] = "#"
    cnt1 += 1
SS = list(s + s)
for i in range(len(SS)-1):
  if SS[i] == SS[i+1]:
    SS[i+1] = "#"
    cnt2 += 1
print(cnt1 + (cnt2 - cnt1) * (K - 1))

Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{ int p, l, r; };
struct Node T[MAX]; 
int n;

void preParse(int u){
	if( u == NIL ) return;
	printf(" %d",u);
	preParse(T[u].l);
	preParse(T[u].r);	
}

void inParse(int u){
	if( u == NIL ) return ;
	inParse(T[u].l);
	printf(" %d",u);
	inParse(T[u].r);
}

void postParse(int u){
	if( u == NIL ) return;
	postParse(T[u].l);
	postParse(T[u].r);
	printf(" %d", u);
}

int main(){
	int i, v, l, r, root;
	
	scanf("%d",&n);
	for( i = 0; i < n; i++)
	T[i].p = NIL;
	
	for( i = 0; i< n; i++ ){
		scanf("%d %d %d", &v, &l, &r);
		T[v].l = l;
		T[v].r = r;
		if( l != NIL ) T[l].p = v;
		if( r != NIL ) T[r].p = v;
	}
	
	for( i = 0; i < n; i++ ) if( T[i].p == NIL ) root = i;
	printf("Preorder\n");
	preParse(root);
	printf("\n");
	printf("Inorder\n");
	inParse(root);
	printf("\n");
	printf("Postorder\n");
	postParse(root);
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 2100
// C - Guess The Number
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
int N,M;
vi S,C;

auto solve(){
	string T(N,'-');
	rp(i,0,M) T[S[i]-1] = C[i]+'0';
	rp(i,0,M) if(T[S[i]-1] != C[i]+'0') return -1;
	if(N!=1 && T[0]=='0') return -1;
	int ans = INT_MAX;
	rp(i,0,999){
		string A = to_string(i);
		if(A.size() != N) continue;
		int j;
		for(j=0; j<N; ++j) if(T[j]!='-' && T[j]!=A[j]) break;
		if(j==N) ans = min(ans, i);
	}
	return ans;
}

int main(){
	cin>>N>>M;
	S.resize(M);
	C.resize(M);
	rp(i,0,M) cin>>S[i]>>C[i];
	cout<< solve() <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main() {
    char str[300001];
    char str_mae[300001]={};
    char str_ato[300001]={};
    int Q;
    int q1;
    int q2;
    char q3;
    int count = 0;
    int count_mae = 0;
    int count_ato = 0;
    int count_str = 0;

    scanf("%s", &str);
    count_str = strlen(str);

    scanf("%d", &Q);

    for (int i = 0; i < Q; ++i) {
        scanf("%d",&q1);
        if(q1 == 1){
            count++;
        }
        else{
            scanf("%d %c",&q2,&q3);
            if(( q2 + count) % 2 == 1){
                str_mae[count_mae] = q3;
                count_mae++;
            }
            else{
                str_ato[count_ato] = q3;
                count_ato++;
            }
        }
    }

    if(count % 2 == 0){
        for(int i = 0; i < count_mae; ++i){
            printf("%c",str_mae[count_mae-1-i]);
        }
        printf("%s",str);
        printf("%s",str_ato);
        }
    else{
        for(int i = 0; i < count_ato; ++i){
            printf("%c",str_ato[count_ato-1-i]);
        }
        for(int i = 0; i < count_str; ++i){
            printf("%c",str[count_str-1-i]);
        }
        printf("%s",str_mae);
    }
}

int A(){
    char S[3];
    scanf("%s",&S);
    if(S[0] != S[1] || S[0] != S[2] || S[1] != S[2]){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}

int B(){
    long long int  N;
    long long int RED,BLUE;
    long long int count;

    scanf("%lld %lld %lld",&N,&RED,&BLUE);
    count = N /(RED+BLUE) ;
    if(N % (RED +BLUE) >=RED){
        printf("%lld",count*RED +RED);
    }
    else{
        printf("%lld",count*RED + (N%(RED +BLUE)) );
    }
    return 0;
}

int C(){
    int tax8,tax10;
    int a,b;

    scanf("%d %d",&tax8,&tax10);

    for(int i = 1; i <= 10000; ++i){
        a = i * 0.08;
        b = i * 0.1;
        if(tax8 == a && tax10 == b){
            printf("%d",i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define N 200009
using namespace std;

int n,h[N],a[N],b[N],c[N];
int check(int x){
	int i;
	for (i=1; i<n; i++) b[i]=(a[i]>=x);
	memset(c,-1,sizeof(c));
	for (i=2; i<n; i++) if (b[i]==b[i-1]) c[i]=c[i-1]=b[i];
	int head=0,tail=0;
	for (i=1; i<n; i++) if (c[i]!=-1) h[++tail]=i;
	if (!tail) return b[1];
	while (head<tail){
		x=h[++head];
		if (x>1 && c[x-1]==-1){
			c[x-1]=c[x]; h[++tail]=x-1;
		}
		if (x+1<n && c[x+1]==-1){
			c[x+1]=c[x]; h[++tail]=x+1;
		}
	}
	return c[n>>1];
}
int main(){
	scanf("%d",&n); n<<=1;
	int i;
	for (i=1; i<n; i++) scanf("%d",&a[i]);
	int l=1,r=n-1,mid;
	while (l<r){
		mid=l+r+1>>1;
		if (check(mid)) l=mid; else r=mid-1;
	}
	printf("%d\n",l);
	return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
typedef long long LL;

int n;
vector<int> a;
vector<int> w;

LL merge_count(int l, int r) {
	if (r - l <= 1)
		return 0;
	else if (r - l == 2) {
		if (a[l] <= a[r-1])
			return 0;
		else {
			swap(a[l], a[r-1]);
			return 1;
		}
	}
	else {
		int m = (l + r) / 2;
		LL cl = merge_count(l, m);
		LL cr = merge_count(m, r);
		LL c = 0;
		int i=l, j=m;
		int k = l;
		while (i < m && j < r) {
			if (a[i] <= a[j])
				w[k++] = a[i++];
			else {
				w[k++] = a[j++];
				c += m-i;	//整列されているので、a[i] > a[j]のときa[i]からa[m-1]まで全てa[j]より大。
			}
		}
		while (i < m)
			w[k++] = a[i++];
		while (j < r)
			w[k++] = a[j++];
		assert(k == r);
		copy(w.begin() + l, w.begin() + r, a.begin() + l);
		return cl + cr + c;
	}
}

int main() {
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	w.resize(n);
	cout << merge_count(0, n) << endl;
}


Measured memory_bytes: 4332
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    String t = sc.next();
    
    char[] s2 = s.toCharArray();
    char[] t2 = t.toCharArray();
    
    int cnt = 0;
    
    if(s2[0] == t2[0])
      cnt++;
    if(s2[1] == t2[1])
      cnt++;
    if(s2[2] == t2[2])
      cnt++;

    System.out.println(cnt);
    
  }
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<math.h>
int main(){
    int a,b,c,d,m=0;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a>=b&&a>=c) printf("%d",a*(int)pow(2,d)+c+b);
    else if(b>=a&&b>=c) printf("%d",b*(int)pow(2,d)+c+a);
    else if(c>=b&&c>=a) printf("%d",c*(int)pow(2,d)+a+b);
    return 0;
}

Measured memory_bytes: 128
import math


def main():
    n = int(input())
    # n, m = map(int, input().split())
    # a = list(map(int, input().split()))
    # s = input()
    # h = [int(input()) for _ in rane(n)]

    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())
    print(math.ceil(n / min(a, b, c, d, e)) + 4)


if __name__ == '__main__':
    main()



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

int main() {
  string S;
  cin >> S;
  int A=1;
  int B=1;
  int N = S.size();
  for(int i=0;i<N;i+=2){
    if(S[i]=='L'){
      A*=0;
      break;
    }
    else{
      A*=1;
    }
  }
  for(int i=1;i<N;i+=2){
    if(S[i]=='R'){
      B*=0;
      break;
    }
    else{
      B*=1;
    }
  }
  if(A==1&&B==1){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define ms(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///
bool fld[200][200];
int cnt[200][200];
int dx[] = { 0, -1, -1, 0, 1, 1 };
int dy[] = { 1, 0, -1, -1, 0, 1 };

int main()
{
	int n, t;
	while (cin >> t >> n, t)
	{
		REP(i, 200)REP(j, 200) cnt[i][j] = INF;
		ms(fld, true);
		REP(i, n)
		{
			int x, y;
			cin >> x >> y;
			fld[x + 100][y + 100] = false;
		}
		int sx, sy;
		cin >> sx >> sy;
		sx += 100; sy += 100;
		queue<P> que;
		que.push(P(sx, sy));
		cnt[sx][sy] = 0;

		while (!que.empty())
		{
			int x = que.front().first;
			int y = que.front().second;
			que.pop();
			if (cnt[x][y] >= t) break;
			REP(i, 6)
			{
				int nx = x + dx[i];
				int ny = y + dy[i];
				if (fld[nx][ny] && cnt[nx][ny]==INF)
				{
					cnt[nx][ny] = cnt[x][y] + 1;
					que.push(P(nx, ny));
				}
			}
		}
		int ans = 0;
		REP(i, 200)REP(j, 200)
		{
			if (cnt[i][j] != INF) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1416
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

const int MX=102;
map <int,int> mp;
int a[MX];

int main()
{
    int x,n,m=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        int y=++mp[x];
        if(y==1) a[m++]=x;
    }
    sort(a,a+m);
    int ans=0;
    for(int i=0;i<m;i++){
        for(int j=i+1;j<m;j++){
            for(int k=j+1;k<m;k++){
                if(a[i]+a[j]>a[k]){
                    ans+=mp[a[i]]*mp[a[j]]*mp[a[k]];
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3836
#include <cstdio>

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)

int main()
{
    int x_cities, y_cities, x_capital, y_capital;
    scanf("%d %d %d %d", &x_cities, &y_cities, &x_capital, &y_capital);

    const int oo = 1e9;

    int max_x_city = -oo;
    while(x_cities--)
    {
        int x;
        scanf("%d", &x);

        max_x_city = max(max_x_city, x);
    }

    int min_y_city = oo;
    while(y_cities--)
    {
        int y;
        scanf("%d", &y);

        min_y_city = min(min_y_city, y);
    }

    printf(x_capital < y_capital && max_x_city < min_y_city && max_x_city < y_capital && x_capital < min_y_city ? "No War\n" : "War\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  auto f = [&](ll i) {
    if (i == -1) {
      return 0LL;
    }
    return i / x + 1;
  };
  cout << f(b) - f(a - 1) << endl;
}

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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint>PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};

int N,K;
int a[100010],b[100010];

int f(int n){
    int sum=0;
    rep(i,0,N){
        if((n&a[i])==a[i]){
            sum+=b[i];
        }
    }
    return sum;
}

signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>N>>K;
    rep(i,0,N){
        cin>>a[i]>>b[i];
    }
    
    int ans=f(K);
    
    rep(i,0,30){
        if((K>>i)&1ll){
            int j=(K^(1ll<<i));
            j|=(1ll<<i)-1;
            ans=max(ans,f(j));
        }
    }
    
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int length = in.nextInt();
        int[] a = new int[length];
        for (int i = 0; i < length; i++) {
            a[i] = in.nextInt();
        }
        insertionSort(a);
    }

    private static void insertionSort(int[] a) {
        int length = a.length;
        System.out.println(printArray(a));
        for (int i = 1; i < length; i++) {
            int key = a[i];
            int j = i - 1;
            while (j >= 0 && a[j] > key) {
                a[j+1] = a[j];
                j--;
            }
            a[j+1] = key;
            System.out.println(printArray(a));
        }
    }

    private static String printArray(int[] a) {
        int length = a.length;
        String arrayString = "";
        for (int i = 0; i < length - 1; i++) {
            arrayString = arrayString + a[i] + " ";
        }
        arrayString = arrayString + a[length - 1];
        return arrayString;
    }
}


Measured memory_bytes: 45252
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frn(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>
#define test int t;cin>>t; while(t--)
#define mp make_pair
#define pb push_back
#define pu push
#define fi first
#define se second
#define mod 1000000007
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> seti;
void fast() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
    //fast();
    int n;
    cin>>n;
    int a[n+1];
    fr(i,0,n) cin>>a[i];
    int ans = 0;
    sort(a,a+n);
    fr(i,0,n-2){
        fr(j,i+1,n-1){
            fr(k,j+1,n){
                if(a[i]==a[j] ||a[j]==a[k]) continue;
                if(a[i]+a[j]>a[k]) ans++;
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;




int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================
	
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	ll ans = LLINF;
	for (int i = -100; i <= 100; i++) {

		ll localAns = 0;
		for (int j = 0; j < N; j++) {
			localAns += (i - A[j]) *(i - A[j]);
		}
		ans = min(ans, localAns);

	}

	cout << ans;

}	




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long int ll;

int main()
{
    vector<ll> a = {0, 0, 0, 0};
    for (ll i = 0; i < 6; i++)
    {
        ll temp;
        cin >> temp;
        a[temp - 1]++;
    }

    for (ll i = 0; i < 4; i++)
    {
        if (a[i] > 2 || a[i] < 1){
            cout << "NO" << endl;
            exit(0);
        }
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;

ll N,M;

int main() {
    cin>>N>>M;
    if(N==1&&M==1){
        p(1);
    }
    else if(N==1){
        p(M-2);
    }else if(M==1){
        p(N-2);
    }
    else p((N-2)*(M-2));

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; 
 
int main(void){
  
  // 以下エラトステネスの篩のコピペ　
  // pが素数の数、prime[i-1]でi番目の素数
  // prime[0]=2, prime[1]=3, ....であることに気を付ける
  // 特に、prime[-1]=0, prime[p]=0なので注意！！
  // 
    ll N= 1000*1000  ;
    ll prime[N];
    bool is_prime[N+1]; 
    ll p=0;
      
  for(ll i=0; i<=N; i++) is_prime[i]=true;
  is_prime[0] = is_prime[1]=false;
  for(ll i=2; i<=N; i++){
    if(is_prime[i]){
      prime[p++] =i;
      for(ll j=2*i ; j<= N; j+= i ) is_prime[j] = false; 
    }
  }
  //コピペ終了　
  //以下この問題特有
  int NN;
  cin>> NN;
  int i =0;
  while(NN>0){
    if((prime[i]%5)==1){
      cout<< prime[i] <<" "<< endl; 
      NN--; 
    }
    i++; 
  }
  
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while(0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll t[2],a[2],b[2],c[2];

signed main() {
  rep(i,2) cin >> t[i];
  rep(i,2) cin >> a[i];
  rep(i,2) cin >> b[i];

  c[0] = a[0]*t[0] - b[0]*t[0];
  c[1] = a[1]*t[1] - b[1]*t[1];

  if (c[0]+c[1] == 0) {
    cout << "infinity" << endl;
    return 0;
  }

  if (c[0] < c[1]) {
    c[0] *= -1;
    c[1] *= -1;
  }

  if (c[0] > 0 && c[1] > 0 || c[0] < 0 && c[1] < 0) {
    cout << 0 << endl;
    return 0;
  }

  // 半周期ごとにc[0]、1周期ごとにc[1]だけずれていく
  c[1] += c[0];
  //printf("c[0]=%lld c[1]=%lld\n", c[0],c[1]);

  // 交わる周期数nは、c[0]/c[1] の切り上げ
  ll ans = 0;
  ll n = (c[0]-1) / (-c[1]) + 1;

  //cout << "n=" << n << endl;
  if (n <= 0) {
    cout << 0 << endl;
    return 0;
  }

  if (c[0] % (-c[1]) == 0) {
     ans =  n * 2;
  } else {
     ans =  n * 2 - 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
a=[]
b=[]
a[0]=0
a[1]=0
for i in 2...50100
  a[i]=1
end
for i in 2...50100
  if a[i]==1 then
    j=i*2
    while j < 50100 do
    a[j]=0
    j=j+i
    end
  end
end

while gets do
  inp=$_.to_i
  i=inp-1
  while 1 do
    if a[i]==1 then
      print i," "
      break
    end
    i=i-1
  end
i=inp+1
  while 1 do
    if a[i]==1 then
    print i,"\n"
    break
    end
  i=i+1
  end
end

Measured memory_bytes: 6608
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int INF = 1e9 + 7;

map<int, int> v, parent, dist;
map<string, int> M;

// P(parent, dist)
P find(int a){
  if(parent[a] == a) return P(a, dist[a]);
  P p = find(parent[a]);
  parent[a] = p.first;
  dist[a] += p.second;
  return P(p.first, dist[a]);
}

bool same(int a, int b){ return find(a).first == find(b).first; }

void merge(int a, int b, int dd){
  if(same(a, b)) return ;
  P pa = find(a), pb = find(b);
  int d = dd - pb.second + pa.second;
  if(d < 0){
    d *= -1;
    swap(pa, pb);
  }
  parent[pb.first] = pa.first;
  dist[pb.first] = d;
}

int distance(int a, int b){
  if(!same(a, b)) return INF;
  return find(b).second - find(a).second;
}

void init_union_find(){
  v = map<int, int>();
  parent = map<int, int>();
  dist = map<int, int>();
  M = map<string, int>();
}

int number(string &s){
  if(M.find(s) != M.end()) return M[s];
  int num = M.size();
  M[s] = num;
  parent[num] = num;
  return num;
}

int get_distance(string &s){
  int idx = 0;
  while(s[idx++] != '^') ;
  return atoi(s.substr(idx).c_str());
}

void input(string &as, int &d, string &bs){
  string s, tmp;
  cin >>tmp >>as >>tmp >>s >>bs;
  d = get_distance(s);
}

int main() {
  int N;
  while(cin >>N && N){
    init_union_find();
    bool ans = true;
    REP(i, N){
      string as, bs; int d;
      input(as, d, bs);
      int a = number(as), b = number(bs);
      if(same(a, b)) { if(distance(a, b) != d) ans = false; }
      else merge(a, b, d);
    }
    cout <<(ans ? "Yes" : "No") <<endl;
  }
  return 0;
}

Measured memory_bytes: 1260
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (10000010)

int a[MAXN];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i < MAXN; i++) {
		for (int j = i; j < MAXN; j += i) {
			a[j]++;
		}
	}
	ll ret = 0;
	for (int i = 1; i <= n; i++) {
		ret += (ll)i * a[i];
	}
	cout << ret << endl;
	return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (1e10)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);}} premain;

#define N_MAX (100100)
int N, K;
int a, b;
vector<vector<int>> graph(N_MAX);

ll dfs(int K, int now, int from) {
  int can_use_color_num = K-2;
  if (-1 == from) {
    can_use_color_num = K-1;
  }

  if (K < graph[now].size()) {
    return 0;
  }

  ll case_num = 1;
  for (auto e : graph[now]) {
    if (e == from) continue;
    
    case_num *= can_use_color_num;
    case_num %= MOD;
    can_use_color_num--;
  }

  for (auto e : graph[now]) {
    if (e == from) continue;
    
    case_num *= dfs(K, e, now);
    case_num %= MOD;
  }
  return case_num;
}

int main() {
  cin >> N >> K;

  REP(i, N-1) {
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  
  ll ans = K * dfs(K, 1, -1);
  ans %= MOD;
  print(ans);
}


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

int main(){
    vector<int> num(3);
    string in;
    cin >> in;
    for(int i=0;i<3;i++){
        num[i] = stoi(in.substr(i,1));
        if(num[i] == 9){
            cout << 1 ;
        }
        else{
            cout << 9;
        }
        
    }
    cout<<endl;

}

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

int main() {
    int N, Q;
    string s;
    cin >> N >> Q >> s;
    vector<pair<char, char>> td(Q);
    for(auto& e : td) {
        cin >> e.first >> e.second;
    }
    reverse(td.begin(), td.end());
    int l = 0, r = N;
    for(auto& e : td) {
        if(e.second == 'R') {
            if(s[l-1] == e.first && l > 0) l--;
            if(s[r-1] == e.first) r--;
        } else {
            if(s[l] == e.first) l++;
            if(s[r] == e.first && r < N) r++;
        }
    }
    cout << r - l << endl;
}

Measured memory_bytes: 900
a,b = map(int, input().split())
n = 0
for i in range(a, b + 1):
    f = True
    s = str(i)
    l = len(s)
    for j in range(l//2 + 1):
        if s[j] != s[- j - 1]:
            f = False
            break
    if f:
        n += 1
print(n)

Measured memory_bytes: 2940
/*
*
*   Bismillah Hir Rahman Nir Raheem
*   Name: Jaied Al Sabid
*
*/
#include <bits/stdc++.h>

using namespace std;

#define pf printf
#define sf scanf
#define elif else if
#define unint unsigned int
#define sint short int
#define lint long long int
#define Size 100000

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int h,n,m[Size],tot=0;
    cin>>h>>n;
    for(int i = 0; i < n; i++)
    {
        cin>>m[i];
        tot+=m[i];
    }
    if(tot>=h)
    {
        cout<<"Yes"<<endl;
    }
    else{cout<<"No"<<endl;}
    return 0;
}


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

int main(){
  string str;
  cin >> str;
  string s = "CODEFESTIVAL2016";
  int cnt = 0;
  for(int i=0;i<s.size();i++){
    if(s[i] != str[i]){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
/*
Author: Babin Dutta
*/

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define endl "\n"
#define inf 1e18

vector<int> ad[100001];
int h[100001];

void solve(int tt){
	int n,m; cin>>n>>m;
	f(i,n) cin>>h[i+1];
	int a,b;
	f(i,m){
		cin>>a>>b;
		ad[a].pb(b);
		ad[b].pb(a);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		int f=1;
		for(int j=0;j<ad[i].size();j++){
			int x = ad[i][j];
			if(h[i] <= h[x]){
				f=0;
				break;
			}
		}
		if(f) ans++;
	}
	cout<<ans<<endl;
}


int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve(i);
	return 0;
}

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b,k;
cin>>a>>b>>k;
reps(i,b+1,a){
    if(i<a+k||b-k<i){
        cout<<i<<endl;
    }
}
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;
typedef long long ll;
int main(){
	int n,a[101],i,j,k;
	ll p,q,w,sum=0;
	cin>>n;
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			for(k=0;k<n;k++){
				if(a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i]&&i>j&&j>k){
					p=a[i]+a[j];
					q=a[i]+a[k];
					w=a[k]+a[j];
					if(p>a[k]&&q>a[j]&&w>a[i])
					sum++;
				}
			}
		cout<<sum;
}
	

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

using namespace std;

#define USE_IOSTREAM \
{\
	ios::sync_with_stdio(false);\
	cin.tie(0);\
	cout.tie(0);\
}

#define pii pair<int, int>
#define mp make_pair

typedef long long ll;

const int N = 1e5 + 100;
const ll MOD = 1e9 + 7;
const ll LINF = 2e18;

ll a[N];
ll A, B;
int n;

ll sum[2][N];
vector<int> posVec[2];

void update(ll &res, ll add)
{
	res = res + add;
	if (res >= MOD)
	{
		res -= MOD;
	}
}

int main()
{
	USE_IOSTREAM;
	cin >> n >> A >> B;
	
	int i;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	a[0] = -LINF;
	a[n + 1] = LINF;
	
	sum[0][0] = 1;
	sum[1][0] = 1;
	posVec[0].push_back(0);
	posVec[1].push_back(0);
	
	int pos;
	for (i = 2; i <= n; i++)
	{
		pos = upper_bound(a, a + i - 1, a[i] - B) - a - 1;
		ll tmp = sum[0][pos];
		
		if (a[i] - a[i - 1] < A)
		{
			for (auto pos : posVec[0])
			{
				sum[0][pos] = 0;
			}
			posVec[0].clear();
		}
		
		pos = upper_bound(a, a + i - 1, a[i] - A) - a - 1;
		sum[0][i - 1] = sum[0][i - 2];
		update(sum[0][i - 1], sum[1][pos]);
		posVec[0].push_back(i - 1);
		
		if (a[i] - a[i - 1] < B)
		{
			for (auto pos : posVec[1])
			{
				sum[1][pos] = 0;
			}
			posVec[1].clear();
		}
		
		sum[1][i - 1] = sum[1][i - 2];
		update(sum[1][i - 1], tmp);
		posVec[1].push_back(i - 1);
	}
	
	ll ans = (sum[0][n - 1] + sum[1][n - 1]) % MOD;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3572
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
		String n = sc.next();
      	String[] ary = n.split("");
      
      	for(int i = 0; i < ary.length; i++) {
        	if(ary[i].equals("1")) {
            	ary[i] = "9";
            } else if(ary[i].equals("9")) {
              	ary[i] = "1";
            }
  			System.out.print(ary[i]);
        }
    }
}

Measured memory_bytes: 22740
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#define for(i,n) for(int i=0; i<(n); i++)
#define lint long long
#define mod 1000000007
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000
#define endl '\n'
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; }
using namespace std;
lint a, b, c, d;
double e, f, g, h;

int main() {
	cin >> e >> f;
	cout << e / f << endl;
	return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー


Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std; 
int a;
int main(){
    cin>>a;
    if (a<1200) cout<<"ABC"<<endl;
       else if (a<2800) cout<<"ARC"<<endl;
            else cout<<"AGC"<<endl;
    return 0;
} 

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

int main() {
    int n, a;
    long long int ans = 0;
    cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; ++i) {
        cin >> a;
        mp[a]++;
    }
    auto begin = mp.begin(), end = mp.end();
    for(auto iter = begin; iter != end; iter++) {
        //cerr << iter->first << " " << iter->second << endl;
        if(iter->first < iter->second) ans += iter->second - iter->first;
        else if(iter->first > iter->second) ans += iter->second;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 4736
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in = sc.nextLine();
		if (Pattern.compile("[A-Z]*").matcher(in).matches()) {
			System.out.println("A");
		} else {
			System.out.println("a");
		}
	}
}


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

#include <bits/stdc++.h>

using namespace std;

void solve(istream &in, ostream &out) {
    int a1, a2, a3;
    in >> a1 >> a2 >> a3;

    if (a1 + a2 + a3 >= 22)
        out << "bust" << '\n';
    else
        out << "win" << '\n';
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solve(in, out);
}


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

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h, w, n;
    cin >> h >> w >> n;
    cout << (n - 1) / max(h, w) + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	ll x,y; cin>>x>>y; n--;
	for (int i=0; i<n; i++) {
		ll a,b; cin>>a>>b;
		ll p=(x+a-1)/a, q=(y+b-1)/b;
		vector<ll> u(2), v(2);
		u[0]=p*a, v[0]=p*b;
		u[1]=q*a, v[1]=q*b;
		ll xx=-1, yy=-1;
		for (int i=0; i<2; i++) {
			if(u[i]<x||v[i]<y)
				continue;
			if(xx==-1&&yy==-1) xx=u[i], yy=v[i];
			else {
				if(u[i]+v[i]<xx+yy) xx=u[i], yy=v[i];
			}
		}
		x=xx, y=yy;
	}
	cout<<x+y<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int N=2e5+10;
int n,Q;
char s[N],t[N],d[N];
int Drop(int x)
{
    for(int i=1;i<=Q;i++)
    {
        if(s[x]==t[i]) x+=(d[i]=='R')?1:-1;
        if(x>n) return -1;
        if(x<1) return 1;
    }
    return 0;
}
int main()
{
    cin>>n>>Q;
    scanf("%s",s+1);
    for(int i=1;i<=Q;i++) cin>>t[i]>>d[i];
    int l=1,r=n,la=0,ra=n+1;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(Drop(mid)==1) la=mid,l=mid+1;
        else r=mid-1;
    }
    l=1,r=n;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(Drop(mid)==-1) ra=mid,r=mid-1;
        else l=mid+1;
    }
    cout<<ra-la-1<<endl;
}

Measured memory_bytes: 768
// AOJ 2751 Baseball
// 2018.2.2 bal4u

#include <stdio.h>

#define M 1000000007
#define N1 4000000
#define N2 2999999

int fact[N1+2], inv[N2+2], factinv[N2+2];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int comb(int n, int k)
{
	if (n < 0 || k < 0) return 0;
	return (int)((long long)fact[n] * factinv[k] % M * factinv[n-k] % M);
}

int H(int n, int k)
{
	if (!n && !k) return 1;
    return comb(n+k-1, k);
}

int main()
{
	int a, b, c, sx, sy, i;
	long long ans, t;

	fact[0] = 1; for (i = 1; i <= N1; i++)
		fact[i] = (long long)fact[i-1] * i % M;
	inv[1] = 1; for (i = 2; i <= N2; i++)
		inv[i] = M - (M / i) * (long long)inv[M % i] % M;
	factinv[0] = 1; for (i = 1; i <= N2; i++)
		factinv[i] = (long long)factinv[i-1] * inv[i] % M;

	while (1) {
		a = in(), b = in(), c = in(), sx = in(), sy = in();
		if ((a|b|c|sx|sy) == 0) break;

		ans = 0;
		for (i = a; i <= sx; i++) {
			t = H(a, i-a);
			t = t * H(b, sy-sx+i-b) % M;
			t = t * H(a+b+c, sx-i) % M;
			ans += t;
			if (ans >= M) ans -= M;
		}
		ans = ans * comb(a+b+c, a) % M;
		ans = ans * comb(b+c, b) % M;
		printf("%d\n", (int)ans);
	}
    return 0;
}


Measured memory_bytes: 40828
import java.util.*;

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


	public void run() {
		Scanner sc = new Scanner(System.in);
		TreeMap<Long,Long> m = new TreeMap<>();
		int N=sc.nextInt();
		for(int i=0; i<N; i++) {
			long a = sc.nextLong();
			long b = sc.nextLong();
			m.put(b, m.containsKey(b) ? m.get(b)+a : a);
		}
		long sub = 0;
		for(Map.Entry<Long, Long> e : m.entrySet()) {
			long b = e.getKey();
			long a = e.getValue();
			if(b-sub<a) {
				System.out.println("No");
				sc.close();
				return;
			}
			sub += a;
		}
		System.out.println("Yes");
		sc.close();
	}
}


Measured memory_bytes: 77160
import java.util.*;

public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
     	int sum = 0;
      	int max = 0;
      	while (N > 0) {
        	int temp = sc.nextInt();
          	sum += temp;
          	max = Math.max(max, temp);
          	N--;
        }
      	if (sum - max > max) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int Q,H,S,D;
    int N;
    cin >> Q >> H >> S >> D >> N;
    // Q*4 Q*2+H H*2 S = 1L
    int mi = min({Q*4,Q*2+H,H*2,S});
    if(mi*2 >= D) {
        cout << N/2*D+N%2*mi << endl;
    }
    else {
        cout << N*mi << endl;
    }
}


Measured memory_bytes: 3532
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	int n, m;
	cin >> n >> m;
	int a[n], b[n];
	rep (i, n) cin >> a[i] >> b[i];
	int c[m], d[m];
	rep (i, m) cin >> c[i] >> d[i];

	vector<int> ans(n, -1);
	rep (i, n) {
		int min = 1000000009;
		rep (j, m) {
			if (chmin(min, abs(a[i] - c[j]) + abs(b[i] - d[j]))) ans[i] = j;
		}
	}

	rep (i, n) cout << ans[i] + 1 << endl;
	return 0;
}

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

int main()
{
    int N, K;
    cin >> N >> K;
    long double p[N];
    for (int i = 0; i < N; i++) {
        cin >> p[i];
        p[i] = (p[i] + 1) / 2.0;
    }

    long double sum = 0;
    for (int i = 0; i < K; i++) {
        sum += p[i];
    }
    long double ans = sum;
    for (int i = 0; i < N - K; i++) {
        sum = sum - p[i] + p[K + i];
        ans = max(ans, sum);
    }
    cout << setprecision(20) << ans << endl;
    return 0;
}

Measured memory_bytes: 6780
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin>>N;
  vector<int> d(N);
  for(int i=0;i<N;i++) cin>>d[i];

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

  cout<<d[N/2]-d[N/2-1]<<endl;

  return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import math
import itertools

N = int(input().split()[0])

# 6を使うパターンを列挙
i = 0
p_6_list = []
while 6 ** i <= N:
    p_6_list.append(6 ** i)
    i += 1

p_9_list = []
i = 0
while 9 ** i <= N:
    p_9_list.append(9 ** i)
    i += 1

p_6_gen = list(itertools.product(range(0, 6), repeat=len(p_6_list)))
min_count = float("inf")

for p_6 in p_6_gen:
    x = sum([x * i for x, i in zip(p_6_list, list(p_6))])
    c = sum(list(p_6))

    if c >= min_count:
        # この時点ですでに最小記録更新できないとわかるので、
        # あとの計算は実施しない
        continue

    balance = N - x
    if balance < 0:
        continue

    for y in reversed(p_9_list):
        # 大きい方から払えるだけ払う
        y_count = balance // y
        balance -= y * y_count
        c += y_count
        if balance == 0:
            break

    min_count = min(min_count, c)

ans = min_count
print(ans)


Measured memory_bytes: 34856
/*

*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <vector>

using namespace std;

#define long long long
#define foe(i , v) for(__typeof(v.begin()) i = v.begin() ; i != v.end(); i++)
#define fi first
#define se second
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(0)
#define task "test"
#define ini freopen(task".inp","r",stdin); freopen(task".out","w",stdout)
#define fo(i , a , b) for(int i = a ; i <= b ; i ++)
#define fu(i , a , b) for(int i = a ; i >= b ; i --)
#define db(a) cout << a << ' '
#define de(a) cout << a << endl
#define all(a) a.begin() , a.end()
#define oo (int) 2e9 + 1

typedef vector <int> vi;
typedef pair <long , long> pll;
typedef vector <pll > vll;
typedef unsigned long ull;

const int N = (int) 1e6 + 4;
const int dx[] = {-1 , 0 , 1 , 0};
const int dy[] = {0 , -1 , 0 , 1};

int n , m , a[N] , b[N];

void init() {
    //ini;
    fio;
    cin >> n;
    if (n < 1200) cout << "ABC";
    else if (n < 2800) cout << "ARC";
    else cout << "AGC";
}

void solve() {

}

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



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

int main(){
    int n,k;
    cin>>n>>k;
    vector<double> p(n);
    for(int i=0;i<n;++i) cin>>p[i];
    
    vector<double> e(n+1);
    for(int i=0;i<n;++i){
        double t=p[i];
        e[i+1]=(t+1)/2.0;
    }

    for(int i=0;i<n;++i) e[i+1]+=e[i];

    double ans=0.0;
    for(int i=0;i<n-k+1;++i){
        ans=ans<e[i+k]-e[i]?e[i+k]-e[i]:ans;
    }

    cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 6352
class BaseBall
  def initialize
    @first=false
    @second=false
    @third=false
    @out=0
  end

  def hit
    if @third then
      point=1
    else
      point=0
    end
    @third = false
    @third  = true if @second
    @second = true if @first
    @first = true
    return point
  end

  def homerun
    point= [@first,@second,@third].select{|x| x}.length + 1
    @first,@second,@third =false
    return point
  end

  def out
    @out += 1
    if @out>= 3 then
      @out=0
      return true
    else
      return false
    end
  end
end
if true then
  fh=STDIN
else
  fh=open("in0103.txt")
end
n= fh.gets.chomp.to_i
0.upto(n-1) { |i|
  point=0
  bb = BaseBall.new
  while fh.gets do
    s = $_.chomp
    if s=="HIT" then
      point += bb.hit
    elsif s=="HOMERUN" then
      point += bb.homerun
    elsif s=="OUT" then
      if bb.out then
        puts point
        break
      end
    end
  end
}

Measured memory_bytes: 8656
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }
inline int mul(int x, int y) { return (1LL*x*y)%MOD; }
int modpow(int x, int k) {
  int a = 1;
  while (k) {
    if (k&1) a = mul(a, x);
    x = mul(x, x);
    k>>=1;
  }
  return a;
}

int N;
int A[100];

int V;
int dp1[100], dp2[100];
int W[100], H[100];
vector<int> G[100];

int f(int l, int r, int base) {
  int m = INF;
  for (int i=l; i<=r; i++) m = min(m, A[i]);

  int id = V++;
  W[id] = r-l+1;
  H[id] = m-base;
  assert(H[id]>0);

  int lp = -1;
  for (int i=l; i<=r; i++) {
    if (A[i] > m) {
      if (lp == -1) lp = i;
    }
    else {
      if (lp != -1) G[id].pb(f(lp, i-1, m)), lp = -1;
    }
  }
  if (lp != -1) G[id].pb(f(lp, r, m));
  return id;
}
void dfs(int x) {
  int rest = W[x];
  for (int t : G[x]) dfs(t), rest -= W[t];
  // g = 2*Πdp1[t]
  // dp1[x] = 2^(h-1) * g
  // dp2[x] = (2^rest * Π(2*dp1[t]+dp2[t])) - g
  int g = 2;
  for (int t : G[x]) g = mul(g, dp1[t]);
  dp1[x] = mul(modpow(2, H[x]-1), g);
  dp2[x] = modpow(2, rest);
  for (int t : G[x]) dp2[x] = mul(dp2[x], (mul(2, dp1[t])+dp2[t])%MOD);
  add(dp2[x], MOD-g);
  //cout<<"w="<<W[x]<<", h="<<H[x]<<", dp1="<<dp1[x]<<", dp2="<<dp2[x]<<"\n";
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> A[i];
  vector<int> xs;
  rep(i, N) xs.pb(A[i]);
  sort(all(xs)); uniq(xs);

  int root = f(0, N-1, 0);
  dfs(root);
  cout << (dp1[root]+dp2[root])%MOD << "\n";
  return 0;
}


Measured memory_bytes: 256