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

using namespace std;

#define pb push_back

const int N = 3005;
int n, order[N << 1];
string s, ans = "";
vector<string> a, dp;

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

    cin >> n >> s;

    int cnta = 0, cntb = 0;
    for (int r = 0, l = 0; r < (int)s.size(); ++r) {
        if (s[r] == 'a') {
            ++cnta;
            order[r] = cnta;
        }
        else {
            ++cntb;
            order[r] = cntb;
        }
        if (cnta == cntb) {
            string t = "";
            if (s[l] == 'a') {
                for (int i = l, lim = 0; i <= r; ++i) {
                    if (lim == order[i]) lim = 0;
                    if (!lim && s[i] == 'a') {
                        t += "ab";
                        lim = order[i];
                    }
                }
            }
            else {
                for (int i = order[l]; i <= order[r]; ++i) {
                    string str = "";
                    for (int j = l; j <= r; ++j) if (order[j] >= i) str += s[j];
                    t = max(t, str);
                }
            }
            a.pb(t);
            l = r + 1;
        }
    }

    dp.assign(a.size(), "");

    for (int i = 0; i < (int)a.size(); ++i) {
        dp[i] = a[i];
        for (int j = 0; j < i; ++j) dp[i] = max(dp[i], dp[j] + a[i]);
        ans = max(ans, dp[i]);
    }

    cout << ans;

    return 0;
}


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A);
  for (auto &ai : a)
    cin >> ai;
  vector<int> b(B);
  for (auto &bi : b)
    cin >> bi;
  vector<int> x(M), y(M), c(M);
  for (int i = 0; i < M; i++)
  {
    cin >> x[i] >> y[i] >> c[i];
    x[i]--, y[i]--;
  }
  vector<int> d = a, e = b;
  sort(d.begin(), d.end());
  sort(e.begin(), e.end());
  int ans = d[0] + e[0];
  for (int i = 0; i < M; i++)
  {
    ans = min(ans, a[x[i]] + b[y[i]] - c[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3072
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7



n = I()
A = LI()
B = LI()
rem = []
ret = 0
ans = 0
for i in range(n):
    if B[i] > A[i]:
        ret += B[i] - A[i]
        ans += 1
    elif B[i] < A[i]:
        rem += [A[i] - B[i]]



rem.sort()
if sum(rem) < ret:
    print(-1)
    exit()


while ret > 0:
    ret -= rem.pop()
    ans += 1


print(ans)





Measured memory_bytes: 65360
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000

int main() {
    int X, order = 1, flag = 0;
    cin >> X;
    vector<int> prime(MAX);
    prime.at(0) = 2;
    if (X == 2) {
        cout << 2 << endl;
        return 0;
    }
    for (int i = 3; i <= MAX; i++) {
        for (int j = 0; j < order; j++) {
            if (i % prime.at(j) == 0) {
                flag++;
            }
        }
        if (flag == 0) {
            prime.at(order) = i;
            if (X <= i) {
                cout << i << endl;
                break;
            }
            order++;
        }
        flag = 0;
    }
}

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

int main(){
    
    // 1. 入力情報.
    int N, H, W;
    scanf("%d %d %d", &N, &H, &W);
    
    // 2. 張り出す場所の選び方.
    printf("%d\n", (N - H + 1) * (N - W + 1));
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int i=0,j=0,n,a=0,x,z,c,ans=0,m1,p=1;
    string b,b2;
    cin >> a >> b2;
    if(a==1 && b2=="0.01")
    {
        cout << "0" << endl;
        return 0;
    }
    b2=b2.erase(1,1);
    p=stoi(b2);
    n=a*p;
    b=to_string(n);
    p=b.size();
    if(p>2)
    {
        b=b.erase(p-2);
    }
    cout << b << endl;   
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdlib>

using namespace std;

const int mod=100000;
int main(){
    int n,m,st[100000],mv,t;
    cin>>n>>m;
    int acc=0,sum=0,pos=0;
    st[0]=acc;
    for(int i=1;i<n;++i){
        cin>>t;
        acc +=t;
        st[i]=acc;
    }
    for(int i=0;i<m;++i){
        cin>>mv;
        sum =sum+abs(st[mv+pos]-st[pos]);
        pos +=mv;
        if(i%200==0) sum %=mod;
    }
    cout<<sum%mod<<endl;
    return 0;
}

Measured memory_bytes: 3488
n, k = map(int, input().split())
func = [1]*(n+2)
for i in range(1, n+2):
    func[i] = func[i-1]*i

mod = 10**9+7


def c(a, b):
    if a<0 or b < 0:
        return 1
    return func[a] // func[a-b] // func[b]


for i in range(1,k+1):
    if n-k+1 < i:
        print(0)
        continue
    b = c(k-1, i-1)
    r = 0
    if i == 1:
        r = n-k+1
    elif i+1 <= n-k:
        r += c(n-k-1, i-2)
        r += 2 * c(n-k-1, i-1)
        r += c(n-k-1, i)
    elif i == n-k:
        r += c(n-k-1, i-2)
        r += 2 * c(n-k-1, i-1)
    elif i-1 == n-k:
        r += c(n-k-1, i-2)
    else:
        r += 0
    # print(b,r)
    print(b*r % mod)


Measured memory_bytes: 45680
#include<stdio.h>

int main(){

    int i, j, W, H;

    while(1){
	    scanf("%d %d", &W, &H);
	    if ((W == 0) && (H == 0)) {
	    	break;
	    }
	    for ( i = 0 ; i < W ; i++ ) {
	    	for ( j = 0 ; j < H ; j++ ) {
	    		if ((i == 0) || (i == W - 1) || (j == 0) || (j == H -1)){
		    		printf("#");
	    		} else {
	    			printf(".");
	    		}
	    	}
		    printf("\n");
	    }
	    printf("\n");
	}
    return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	
	long long int A,B,X;
	cin>>A>>B>>X;
	long long int ans=0;
	A--;
	if(A==-1){
		ans=B/X+1;
	}
	else
		ans=(B/X+1)-(A/X+1);

	
	cout<<ans<<endl;
		
	return 0;
	
}
	

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[1000001];//動的計画法
int prime[1000001];
int main(){
   int sl[101];
   int cnt,n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>sl[i];
    }
    int tmp=1;
    while(tmp!=n){
        if(sl[tmp]==sl[tmp-1]){
            cnt++;
            sl[tmp]=10000-sl[tmp];
        }
        tmp++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int x,y;
  char c;
  int sum=0,ave=0;
  int cnt = 0;
  while(  cin >> x >> c >> y){
    sum+=x*y;
    ave+=y; 
    cnt++;
  }
  ave = (double)ave/cnt + 0.5;
  cout << sum << "\n" << ave << endl;
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
    int n, m;
    cin >> n >> m;

    if (n == m) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;

int main() {
    ll n;
    cin >> n;
    vector<ll> even(100010, 0), odd(100010, 0); 
    for (ll i = 0; i < n; i++) {
        ll v;
        cin >> v;
        if (i % 2 == 0) even[v]++;
        else odd[v]++;
    }

    vector<pair<ll, ll>> pe, po;
    for (ll i = 1; i <= 100010; i++) {
        pe.push_back(make_pair(even[i], i));
        po.push_back(make_pair(odd[i], i));
    }
    sort(pe.begin(), pe.end(), greater<pair<ll, ll>>());
    sort(po.begin(), po.end(), greater<pair<ll, ll>>());

    ll ans;
    if (pe[0].second != po[0].second) ans = n - pe[0].first - po[0].first;
    else ans = min(n - pe[0].first - po[1].first, n - pe[1].first - po[0].first);

    cout << ans << endl;
}

Measured memory_bytes: 5220
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {

	N := nextInt()
	R := nextInt()

	if N > 10 {
		N = 10
	}
	fmt.Println(R + 100*(10-N))
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int A[3],a,b,ans;
	cin>>a>>b;
	A[0]=a+b;
	A[1]=a-b;
	A[2]=a*b;
	sort(A,A+3);
	ans=A[2];
	cout<<ans<<endl;
}


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

int main(){
    int a;
    cin >> a;
    int a2 = a*a;
     int a3 = a*a2;
    cout << a + a2 + a3 << endl;
    return 0;
}

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n, a[52], b[52], c[52];
	long long s = 0;
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> a[i];
	for(int i = 1; i <= n; ++i) cin >> b[i];
	for(int i = 1; i <= n - 1; ++i) cin >> c[i];
	c[n] = 0;
	s += b[a[0]];
	for(int i = 1; i < n; ++i){
	    s += b[a[i]];
	    if(a[i] - a[i - 1] == 1) s += c[a[i - 1]];
	}
	cout << s;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(void) {
  char cls[9][15];
  int m[9], a[9];
  int sum[9], msum[9], asum[9], vsum[9];
  
  for(int i = 0 ; i < 9 ; i++) {
    scanf("%s %d %d", cls[i], &m[i], &a[i]);
    sum[i] = m[i] + a[i];
    msum[i] = 200 * m[i];
    asum[i] = 300 * a[i];
  }
  for(int i = 0 ; i < 9 ; i++) {
    printf("%s %d %d\n", cls[i], sum[i], msum[i]+asum[i]);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <numeric>

int main() {
    int N, K;
    std::cin >> N >> K;
    std::vector<int> ln;
    for (int i = 0; i < N; ++i) {
        int l;
        std::cin >> l;
        ln.push_back(l);
    }
    std::sort(ln.rbegin(), ln.rend());
    std::cout << std::accumulate(ln.begin(), std::next(ln.begin(), K), 0) << std::endl;
    return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

typedef struct UnionFind{
	vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
	vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

	UnionFind(int N){/*最初はすべてが根であると初期化*/
		REP(i,0,N){
			par.push_back(i);
			size.push_back(1);
		}
	}

	lli root(lli x){/*データxが属する木の根を再起で得る root(x) = {xの木の根}}*/
		if(par[x] == x)return x;
		return par[x] = root(par[x]);
	}

	void unite(lli x,lli y){/*xとyの併合*/
		lli rx = root(x);
		lli ry = root(y);
		if(rx == ry)return;
		par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
		lli resize = size[rx] + size[ry];
		size[rx] = resize;
		size[ry] = resize;
	}

	bool same(lli x,lli y){
		lli rx = root(x);
		lli ry = root(y);
		return rx == ry;
	}

	lli getSize(lli x){
		lli rx = root(x);
		return size[rx];
	}
};

void func(long long N, long long M, std::vector<long long> X, std::vector<long long> Y, std::vector<long long> Z){
    UnionFind uf(N);

    REP(i,0,M){
        uf.unite(X[i],Y[i]);
    }

    set<lli> s;
    REP(i,0,N){
        s.insert(uf.root(i));
    }

    cout<<s.size()<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> X(M);
    std::vector<long long> Y(M);
    std::vector<long long> Z(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&Y[i]);
        scanf("%lld",&Z[i]);
        X[i]--,Y[i]--;
    }
    func(N, M, std::move(X), std::move(Y), std::move(Z));
    return 0;
}


Measured memory_bytes: 8812
#include <stdio.h>
int main()
{
  int box[1000],box1[1000],box2[1000],N,n,i,max;
  scanf("%d",&N);
  for(i=0;i<N;i++)
  {
    scanf("%d %d %d",&box[i],&box1[i],&box2[i]);
    if(box[i]>=1 && box1[i]>=1 && box2[i]>=1 && box[i]<=1000 && box1[i]<=1000 && box2[i]<=1000)
    {
      if(box[i]*box[i]==box1[i]*box1[i]+box2[i]*box2[i])printf("YES\n");
      else if(box2[i]*box2[i]==box1[i]*box1[i]+box[i]*box[i])printf("YES\n");
      else if(box1[i]*box1[i]==box[i]*box[i]+box2[i]*box2[i])printf("YES\n");
      else printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 588
h,w,k=gets.split.map &:to_i
C=$<.map &:chomp
c=0
(1<<h).times{|v|
(1<<w).times{|w|
b=0
h.times{|i|
w.times{|j|
b+=1 if C[i][j]=="#" && (v[i]==1 && w[j]==1)
}
}
c+=1 if b==k
}
}
p c

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int k, n;
	cin >> k >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = k - (a[0] + k - a[n - 1]);
	for (int i = 1; i < n; i++) {
		ans = min(ans, k - (a[i] - a[i - 1]));
	}
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 1024
N=list(map(int,list(input())))

for n in range(2**3):
    sum_N=N[0]
    l=[]
    for i in range(3):
        if (n>>i)&1==1:
            sum_N+=N[i+1]
            l.append("+")
        else:
            sum_N-=N[i+1]
            l.append("-")
    if sum_N==7:
        break
print("{}{}{}{}{}{}{}".format(N[0],l[0],N[1],l[1],N[2],l[2],N[3])+"=7")

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

int main() {
  int a, b, c, x; cin >> a >> b >> c >> x;
  int answer = 0;
  
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        if (x == 500 * i + 100 * j + 50 * k) {
          answer++;
          break;
        }
      }
    }
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n, x, now, ans;

int main()
{
	cin >> n >> x;
	ans = 1;
	for (int i = 1; i <= n; i++)
	{
		int sb;
		cin >> sb;
		now += sb;
		if (now <= x) ans++;
	}
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int tmp,case_num = 1;
 
        while((tmp = sc.nextInt()) != 0){
            System.out.printf("Case %d: %d\n",case_num++, tmp);
        }
    }
}


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

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

    for (int i = 0; i < k; i++) {
        if (b <= a) {
            b *= 2;
        }
        else if (c <= b) {
            c *= 2;
        }
    }

    if (b > a && c > b) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[4]={0},i;
	char b[4];
	for(i=0;i<3;i++)
	{
		scanf("%c",&b[i]);
		if(b[i]=='a')
		{
			a[0]++;
		}
		if(b[i]=='b')
		{
			a[1]++;
		}
		if(b[i]=='c')
		{
			a[2]++;
		}
	}
	if(a[0]==1&&a[1]==1&&a[2]==1)
		printf("Yes");
	else
		printf("No");
	return 0;
}

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

int N, W, w[105], v[105];
ll d[105][100005];

int main(){
    scanf("%d %d", &N, &W);
    for(int i = 1; i <= N; i++) scanf("%d %d", &w[i], &v[i]);
    for(int j = 1; j <= 100000; j++) d[0][j] = 1ll << 60;
    for(int i = 1; i <= N; i++) for(int j = 0; j <= 100000; j++){
        d[i][j] = d[i - 1][j];
        if(j >= v[i]) d[i][j] = min(d[i][j], d[i - 1][j - v[i]] + w[i]);
    }
    for(int j = 100000; j >= 0; j--) if(d[N][j] <= W){ printf("%d", j); break; }
    return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;
#define MAXN 200005

int res[MAXN];

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

    int n,a;
    cin >> n;
    for(int i=0;i<n-1;i++)
    {
        cin >> a;
        res[a-1]++;
    }

    for(int i=0;i<n;i++)
        cout << res[i] << ' ';
    cout << '\n';

    return 0;
}


Measured memory_bytes: 4396
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)


def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: x - 1, map(int, input().split()))


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def functional(N, mod):
    F = [1] * (N + 1)
    for i in range(N):
        F[i + 1] = (i + 1) * F[i] % mod
    return F


def add(S):
    S2 = []
    for n, s in S:
        for m in range(0, n + 1):
            w = chr(ord("a") + m)
            if m == n:
                S2.append((n + 1, s + w))
            else:
                S2.append((n, s + w))
    return S2


def main():
    N = int(input())

    S = [(0, "")]
    for _ in range(N):
        S = add(S)
    
    for _, s in S:
        print(s)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 21552
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a,b,x;
	
	cin>>a>>b;
	
	if((a+b)%2==1)
		x=(a+b)/2+1;
	else
	    x=(a+b)/2;
	
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

long long modpow(long long a,long long n){
    long long x=1;
    while(n>0){
        //nの2進数表記の右端が1
        if(n&1){
            x=x*a%MOD;
        }
        a=a*a%MOD;
        n>>=1; //nを右に1bitずらす
    }
    return x;
}
int main(){
    int n; cin>>n;
    int b[n]={};
    rep(i,n){
        int a; cin>>a;
        b[a]++;
    }
    if(n%2){
        if(b[0]==1){
            for(int i=1;i<n;i++){
                if((i%2==1&&b[i]>0)||(i%2==0&&b[i]!=2)){
                    cout<<0<<endl;
                    return 0;
                }
            }
            cout<<modpow(2,n/2)<<endl;
        }else{
            cout<<0<<endl;
        }
    }else{
        if(b[0]==0){
            for(int i=1;i<n;i++){
                if((i%2==1&&b[i]!=2)||(i%2==0&&b[i]>2)){
                    cout<<0<<endl;
                    return 0;
                }
            }
            cout<<modpow(2,n/2)<<endl;
        }else{
            cout<<0<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;
void CatsAndDogs() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c && c <= a + b) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}
int main() {
	CatsAndDogs();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
using ll =long long;
using namespace std;

int main(){
    int n;
    cin>>n;
    int a[20];
    rep(i,n){
        cin>>a[i];
    }
    int q;
    cin>>q;
    int m[200];
    rep(i,q){
        cin>>m[i];
    }
    int sum[1<<20]={};
    rep(i,1<<n){
        rep(j,n){
            if((i>>j)&1==1){
                sum[i]+=a[j];
            }
        }
    }
    rep(i,q){
        int j;
        for(j=0;j<(1<<n);j++){
            if(m[i]==sum[j]){
                cout<<"yes"<<endl;
                break;
            }
        }
        if(j==(1<<n)){
            cout<<"no"<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 7196
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;
int a[N];
int b[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int w, h, n;
	cin >> w >> h >> n;
	while (n--)
	{
		int x, y, o;
		cin >> x >> y >> o;
		if (o == 1)
			for (int i = 1; i <= x; i++) a[i] = 1;
		if (o == 2)
			for (int i = x + 1; i <= w; i++) a[i] = 1;
		if (o == 3)
			for (int i = 1; i <= y; i++) b[i] = 1;
		if (o == 4)
			for (int i = y + 1; i <= h; i++) b[i] = 1;
	}
	int ans = w * h;
	for (int i = 1; i <= w; i++)
	{
		for (int j = 1; j <= h; j++)
		{
			ans -= a[i] | b[j];
		}
	}
	cout << ans << endl;
	return 0;
}

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

int n,ans,sum;
int h[100009];
int f[100009];
signed main() {
	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>h[i];
	}
	for(int i=1;i<=n;i++){
		f[i]=1;
	}
	for(int i=2; i<=n; i++) {
		if(h[i]<=h[i-1]) {
			f[i]=(int)max(f[i],f[i-1]+1);
		}
	}
	for(int i=1; i<=n; i++) {
		ans=(int)max(ans,f[i]);
	}
	ans--;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n, k) for (int i = n; i < k; i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v)                      \
    for (int i = 0; i < v.size(); i++) \
        P(v[i]);
#define printt(a, b) cout << a << " " << b << endl;
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int MOD = 1e9 + 7;

void solve()
{
    int a, b, c, n;
    cin >> a >> b >> c >> n;
    int count = 0;
    rep(i, n / a + 1)
    {
        if (a * i < n)
        {
            rep(j, (n - (a * i)) / b + 1)
            {
                if (a * i + b * j < n)
                {
                    if ((n - a * i - b * j) % c == 0)
                    {
                        count++;
                    }
                }
                else if (a * i + b * j == n)
                {
                    count++;
                }
            }
        }
        else if (a * i == n)
        {
            count++;
        }
    }
    P(count);
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s[3];
  int cnt[3] = {0};
  int f = 0;
  cin >> s[0] >> s[1] >> s[2];
  while(cnt[f] != s[f].size()){
    int temp = s[f][cnt[f]] - 'a';
    cnt[f]++;
    f = temp;
  }
  cout << (char)(f + 'A') << endl;
  return 0;
}


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

using namespace std;

int main()
{
  long long N;
  string ans;
  cin >> N;
  while (N)
  {
    N--;
    ans.push_back(N % 26 + 'a');
    N /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
  int N,M;

  cin >> N  ;

  int64_t sum_before,sum_after;


  vector<int64_t> A(N+1);
  vector<int64_t> B(N);
  //vector<int> C(N);
  //vector<vector<int>> A(N, vector<int>(30));

  
  for (int i = 0; i < N+1; i++)
  {
    cin >> A.at(i);
  }

  for (int i = 0; i < N; i++)
  {
    cin >> B.at(i);
  }


  sum_before = 0;
  sum_after = 0;
  for (int i = 0; i < N+1; i++)
  {
    sum_before += A.at(i);

  }
  //cout << sum_before << endl;

  for (int i = 0; i < N; i++)
  {
    if (B.at(i) >= A.at(i))
    {
      A.at(i + 1) -= B.at(i) - A.at(i);
      A.at(i) = 0;
      if(A.at(i+1)<0){
        A.at(i + 1) = 0;
      }
    }
    else
    {
      A.at(i) -= B.at(i);
    }
  }

  /* for (int i = 0; i < N + 1;i++){
    cout << A.at(i) << endl;
  }*/

    for (int i = 0; i < N + 1; i++)
    {
      sum_after += A.at(i);
    }
  //cout << sum_after << endl;

  cout << sum_before - sum_after << endl;
}

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

using namespace std;

int my_max(int a, int b) {
    return a > b ? a : b;
}

int my_abs(int x) {
    return x < 0 ? -x : x;
}

int main() {

    int n;
    cin >> n;

    vector<string> s(n);
    for(int i=0; i<n; i++) {
        cin >> s[i];
    }

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

    string temp = s[0];
    int sum = 1;

    for(int i=1; i<s.size(); i++) {
        if(s[i] != temp) {
            sum++;
            temp = s[i];
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

int main()
{
    ll n, m;
    cin >> n >> m;
    ll maL = -1;
    ll miR = n + 10;
    rep(i, m)
    {
        ll l, r;
        cin >> l >> r;
        maL = max(maL, l);
        miR = min(miR, r);
    }

    ll ans = max((ll)0, miR - maL + 1);
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define ll          long long
#define pii         pair<int, int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int, int>
#define mii         map<pii, int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define lb          lower_bound
#define ub          upper_bound

#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)
 
#define track(x)                 cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
 
#define ed(i)       i.end()
#define mem(a)	    memset(a, 0, sizeof(a))

#define MOD         1000000007
int mult(int a,int b, int p=MOD){return ((a%p)*(b%p))%p;}
int add(int a, int b, int p=MOD){return (a + b + p)%p;}
int fpow(int n, int k, int p = MOD) {int r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int b) {a = max(a, b); }
void self_min(int &a, int b) {a = min(a, b); }
void self_add(int &a, int b, int p = MOD) { a += b; if(a >= p) a -= p;}
void self_sub(int &a, int b, int p = MOD) { a -= b; if(a < 0) a += p;}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
const int INF = 1e9 + 5;
#define N	    	400001

void solve(){
    string s;
    cin>>s;
    if(s == "ABC")
        cout<<"ARC"<<endl;
    else
        cout<<"ABC"<<endl;

}
int main() {
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin>>t;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 3596
from collections import deque


def solve(maze, init_y, init_x, H, W):
    distances = [[-1 for _ in range(W)] for _ in range(H)]
    distances[init_y][init_x] = 0

    def is_inside(y, x):
        return 0 <= x < W and 0 <= y < H

    def need_to_search(y, x):
        return maze[y][x] != "#" and distances[y][x] == -1

    four_directions = [
        (-1, 0),
        (1, 0),
        (0, -1),
        (0, 1),
    ]

    q = deque()
    q.appendleft([init_y, init_x])

    while q:
        y, x = q.pop()
        d = distances[y][x]

        for dy, dx in four_directions:
            ny, nx = y+dy, x+dx
            if not is_inside(ny, nx):
                continue
            if need_to_search(ny, nx):
                q.appendleft([ny, nx])
                distances[ny][nx] = d+1

    farthest = 0
    for i in range(H):
        for j in range(W):
            # if maze[i][j] != "#":
            farthest = max(farthest, distances[i][j])
    return farthest


def main():
    H, W = map(int, input().split())
    maze = [input() for _ in range(H)]

    farthest = 0
    for i in range(H):
        for j in range(W):
            if maze[i][j] == "#":
                continue
            distance = solve(maze, i, j, H, W)
            farthest = max(distance, farthest)

    print(farthest)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

vvi e;
ll k, ans;
V<bool> vis;

void dfs(int v) {
	vis[v] = true;

	int h = 0;
	if (v == 0)for (int vv : e[v]) {
		if (vis[vv])continue;
		ans *= max(k - 1 - h, 0LL);ans %= MOD;
		h++;
	}
	else for (int vv : e[v]) {
		if (vis[vv])continue;
		ans *= max(k - 2 - h, 0LL);ans %= MOD;
		h++;
		
	}
	
	for (int vv : e[v])if(!vis[vv])dfs(vv);

}

int main() {

	int n;
	cin >> n >> k;
	e.resize(n);
	vis.resize(n);
	ans = k;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--;b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}

	dfs(0);

	cout << ans << endl;

}

Measured memory_bytes: 9216
import java.util.*;
import java.text.DecimalFormat;

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail


public class Main {
    public static void main(String args[] ) throws Exception {
        Scanner in = new Scanner(System.in);
        
        DecimalFormat numberFormat = new DecimalFormat("0.00000");
        int n = in.nextInt();
        float[] A = new float[n];
        for(int i=0;i<n;i++) {
        	A[i] = in.nextFloat();
        }
        Arrays.sort(A);
        double ans = (A[0]+A[1])/2;
        if(n==2) {
        	System.out.println(numberFormat.format(ans));
        	return;
        }
        for(int i=2;i<n;i++) {
        	ans  = (ans+A[i])/2;
        }
        
        
        
        System.out.println(numberFormat.format(ans));
        		
    }
            
        


    
    
   
}


Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 9e3+9, M = 1e5+9, OO = 0x3f3f3f3f;
int memo[N][N],n,m;
char a[N],b[N];
int solve(int i=0,int j=0)
{
  if(i==n || j==m) return 0;

  int &ret = memo[i][j];
  if(~ret) return ret;
  ret = max(solve(i+1,j),solve(i,j+1));
  if(a[i]==b[j]) ret = max(ret,solve(i+1,j+1)+1);

  return ret;
  
}
void print(int i=0,int j=0)
{
  if(i==n || j==m) return ;

  int ret = solve(i,j);
  if (ret == solve(i+1,j))
  {
    print(i+1,j);
    return;
  }
  else if (ret==solve(i,j+1))
  {
    print(i,j+1);
    return;
  }
  else if(ret == solve(i+1,j+1)+1)
  {
    printf("%c",a[i]);
    print(i+1,j+1);
    return;
  }
  
}
int main()
{
  memset(memo,-1,sizeof memo);
  scanf("%s",a);
  scanf("%s",b);
  n = strlen(a);
  m = strlen(b);
  solve();
  print();
  puts("");
  
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 317696
#include <iostream>

using namespace std;

int main()
{
  string S;
  cin >> S;
  bool flg = false;
  for(int i=1;i<4;i++){
    if (S[i-1] == S[i]){
      flg = true;
    }
  }
  
  if(flg) cout << "Bad" << endl;
  else  cout << "Good" << endl;
  
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N = int(input())
A = [int(v) - 1 for v in input().split()]
B = [int(v) for v in input().split()]
C = [int(v) for v in input().split()]

ans = 0
for v in A:
    ans += B[v]

for i in range(N - 1):
    if A[i] + 1 == A[i + 1]:
        ans += C[A[i]]

print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n, m;
    cin >> n >> m;
    set<int> a, b;
    rep(i, n) {
        int x;
        cin >> x;
        a.insert(x);
    }
    rep(i, m) {
        int x;
        cin >> x;
        b.insert(x);
    }
    set<int> x, y;
    for(auto&& i : a) x.insert(i);
    for(auto&& i : b) x.insert(i);
    for(auto&& i : a) if(b.count(i)) y.insert(i);
    cout << y.size() << " " << x.size() << endl;
    for(auto&& i : y) cout << i << endl;
    for(auto&& i : x) cout << i << endl;
    return 0;
}


Measured memory_bytes: 25920
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();

        int min = x - (k - 1);
        int max = x + (k - 1);

        for(int i = min; i <= max; i++){
            System.out.println(i);
        }
    }
}


Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {

    private static final Scanner SCANNER = new Scanner(System.in);

    static int readOneInt() {
        String line = SCANNER.nextLine();
        return Integer.parseInt(line);
    }

    public static void main(String[] args) {

//        int tc = Integer.parseInt(SCANNER.nextLine());
        int tc = 1;
        for (int i = 0; i < tc; ++i) {
            int k = readOneInt();
            String s = SCANNER.nextLine();
            test(s, k);
        }
    }

    private static void test(String s, int k) {
        if (s.length() <= k) {
            System.out.println(s);
        } else {
            System.out.println(s.substring(0, k) + "...");
        }

    }
}



Measured memory_bytes: 38512
#include<stdio.h>
int main()
{
    int n,i,ai,min,max;
    n <= 10000;
    long long sum = 0;
    min = 1000000;
    max = -1000000;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&ai);
        sum += ai;
        if(max < ai){
            max = ai;
        }
        if(min > ai){
            min = ai;
        }

    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=1;i<=n;i++){
    v.at(i-1) = i;
  }
  
  vector<int> p(n),q(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  for(int i=0;i<n;i++){
    cin >> q.at(i);
  }
  
  int a=-1,b=-1;
  ll cnt=0;
  do{
    if(v == p){
      a = cnt;
    }
    if(v == q){
      b = cnt;
    }
    cnt++;
  }while(next_permutation(v.begin(),v.end()) && (a == -1 || b == -1));
  
  cout << abs(a-b) << endl;
  return(0);
}

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

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int n, k;
vector<vector<int>> to;
ll ans = 1;

// p:親のID
// b:既に訪れた兄弟の数
// is_grand:親の親がいるか
void dfs(int x, int p, int b, bool is_grand) {
    if (p == -1) ans = (ans * k) % mod;
    else if (!is_grand) ans = (ans * (k - 1 - b)) % mod;
    else ans = (ans * (k - 2 - b)) % mod;

    int b_next = 0;
    for (auto v : to[x]) {
        if (v == p) continue;
        bool is_grand_next = (p != -1);
        dfs(v, x, b_next, is_grand_next);
        b_next++;
    }
    return;
}

int main()
{
    cin >> n >> k;
    to.resize(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    dfs(0, -1, 0, false);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12100
S = input()
K = int(input())

tmp = 1
tmp_idx = -1
for i in range(len(S)):
    if S[i] != "1":
        tmp = S[i]
        tmp_idx = i
        break
if tmp_idx == -1:
    print(1)
else:
    if K > tmp_idx:
        print(tmp)
    else:
        print(1)


Measured memory_bytes: 9160
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("Ofast")
#define x first
#define y second
#define mp make_pair
#define all(a) a.begin(), a.end()
#define pub push_back
#define ll long long
		
using namespace std;

const int p1 = 31;
const int p2 = 43;
const int mod1 = (int)1e9 + 7;
const int mod2 = (int)1e9 + 9;

int main(){
	//freopen("input.txt", "r", stdin);
	ios_base::sync_with_stdio(0); cin.tie(0);

	ll n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	ll x = b - a;
	n--;
	for (int i = 0; i <= n; i++){
		int j = n - i;
		ll l1 = i * (ll)c, r1 = i * (ll)d;
		ll l2 = j * (ll)c, r2 = j * (ll)d;
		ll ls = l1 - r2;
		ll rs = r1 - l2;
		if (x >= ls && x <= rs) cout << "YES", exit(0);
	}
	cout << "NO";
}

Measured memory_bytes: 256
N = int(input())
TA = [tuple(map(int, input().split())) for i in range(N)]

def floordiv(a,b):
    return (a+b-1)//b

tak = TA[0][0]
aok = TA[0][1]
for i in range(1,N): 
    mul = max(floordiv(tak,TA[i][0]), floordiv(aok,TA[i][1]))
    tak = TA[i][0] * mul
    aok = TA[i][1] * mul

print(tak+aok)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,s=0,p;
	cin>>n;
	vector<int>a(n,0);
	cin>>p;
	for(int i=1;i<n;i++)cin>>a[i];
	for(int i=1;i<n;i++){
		if(p>a[i])s+=p-a[i];
		else p=a[i];
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 3976
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <numeric>
#include <regex>
#include <locale>
#include <fstream>
#include <stdlib.h>
#include <cctype>

//#include <map>

using namespace std;

enum s { t, f, r }; // top , front, right

class cDise
{
	vector<int> X;
	vector<int> Y;
	vector<int> vLabel;
	vector<int> vRep;

	void rotateDice(char d)
	{
		int t;

		switch (d)
		{
			case 'N':
				t = X[0];
				X[0] = Y[0] = Y[1];
				Y[1] = 7 - t;
				break;
			case 'S':
				t = Y[1];
				Y[1] = Y[0];
				X[0] = Y[0] = 7 - t;
				break;
			case 'W':
				t = X[0];
				X[0] = Y[0] = X[1];
				X[1] = 7 - t;
				break;
			case 'E':
				t = X[1];
				X[1] = X[0];
				X[0] = Y[0] = 7 - t;
				break;
			default:break;
		}
	}

public:

	cDise(string l)
	{
		X = { 1, 3 };
		Y = { 1, 2 };

		istringstream iss(l);
		while (!iss.eof())
		{
			int t;
			iss >> t;
			vLabel.push_back(t);
			iss.ignore();
		}

		for (int i = 0; i < vLabel.size(); i++)
		{
			vRep.push_back(0);
			for (int j = 0; j < vLabel.size(); j++)
			{
				if (vLabel.at(i) == vLabel.at(j) && i != j)
				{
					vRep.at(i)++;
				}
			}
		}
	}

	void rotateByStr(string dir)
	{
		istringstream iss(dir);
		vector<char> vc;
		int char_size = 1;

		for (string::iterator it = dir.begin(); it != dir.end(); it += char_size)
		{
			int t;
			rotateDice(*it);
		}
	}

	void rotateAndFindTop(string dir,int t)
	{
		istringstream iss(dir);
		vector<char> vc;
		int char_size = 1;

		for (string::iterator it = dir.begin(); it != dir.end(); it += char_size)
		{
			rotateDice(*it);
			if (getCurrentTop() == t)break;
		}
	}

	vector<int> getRep()
	{
		return vRep;
	}

	vector<int> getLabel()
	{
		return vLabel;
	}

	int getCurrentTop()
	{
		if (X[0] == Y[0])
		{
			return vLabel.at(X[0] - 1);
		}
		return -1;
	}
	
	int getCurrentFront()
	{
		if (X[0] == Y[0])
		{
			return vLabel.at(Y[1] - 1);
		}
		return -1;
	}
	
	int getCurrentRight()
	{
		if (X[0] == Y[0])
		{
			return vLabel.at(X[1] - 1);
		}
		return -1;
	}
};

int main()
{
	string lb;
	getline(cin, lb);
	cDise cd1(lb);
	getline(cin, lb);
	cDise cd2(lb);

	string qstr;
	int top, front;

	bool isSame;

	vector<int> v = cd1.getRep();

	for (int i = 0; i < v.size(); i++)
	{
		if (v.at(i) == 0)
		{
			cd1.rotateAndFindTop("NNNNENNN",cd1.getLabel().at(i));
			cd2.rotateAndFindTop("NNNNENNN",cd1.getCurrentTop());
			int first = cd2.getCurrentFront();
			while (cd2.getCurrentFront() != cd1.getCurrentFront())
			{
				cd2.rotateByStr("NES");
				if (first == cd2.getCurrentFront())
				{
					isSame = false;
					break;
				}
			}
			for (int j = 0; j < 4; j++)
			{
				cd1.rotateByStr("N");
				cd2.rotateByStr("N");
				if (cd1.getCurrentTop() == cd2.getCurrentTop() &&
					cd1.getCurrentFront() == cd2.getCurrentFront() &&
					cd1.getCurrentRight() == cd2.getCurrentRight()
					)
				{
					isSame = true;
				}
				else
				{
					isSame = false;
					break;
				}
			}
		}
	}

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

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

namespace AOJ.Codes
{
    //問題の名称... 0079:   Area of Polygon
    //問題文のURL... http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0079&lang=jp
    //所要時間... AAA
    //学んだこと... AAA
    //教室内の大まかな着席位置... {左，中央，右} x {前，中央，奥}

    class AreaofPolygon
    {
        static void Main(string[] args)
        {
            //読み込み
            var Ps = new List<P>();

            try
            {
                while (true)
                {
                    var x = Console.ReadLine().Split(',').Select(double.Parse).ToArray();
                    Ps.Add(new P(x[0], x[1]));
                }
            }
            catch (Exception)
            {
            }

            //計算
            var N = Ps.Count;
            var sum = 0d;
            var A = Ps[0];
            for (int i = 1; i < N - 1; i++)
            {
                //外積を求めて加算していく。
                var B = Ps[i];
                var C = Ps[i + 1];
                var AB = B - A;
                var AC = C - A;
                sum += P.GetCross(AB, AC)/2; //三角形の面積なので外積を2で割る。
            }


            //出力
            Console.WriteLine(Math.Abs(sum));

            //Enterを押して終了
            Console.ReadLine();
        }
    }

    struct P
    {
        public double x { get; set; }
        public double y { get; set; }

        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public P(double x, double y)
        {
            this.x = x;
            this.y = y;
        }

        /// <summary>
        /// 差分を計算
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <returns></returns>
        public static double GetCross(P p1, P p2)
        {
            return p1.x * p2.y - p1.y * p2.x;
        }

        /// <summary>
        /// 外積を計算
        /// </summary>
        /// <param name="v1"></param>
        /// <param name="v2"></param>
        /// <returns></returns>
        public static P operator -(P v1, P v2)
        {
            return new P((v1.x - v2.x), (v1.y - v2.y));
        }
    }
}



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

int main(){
	using namespace std;

	string s,output;
	output = "";
	cin >> s;
	for(auto iter=s.begin();iter!=s.end();iter++){
		if(*iter == '0' || *iter == '1'){
			output.push_back(*iter);
		}else{
			if(!output.empty()){
				output.pop_back();
			}
		}
	}

	cout << output << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

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

void solve(ll N, vector<ll> a) {

  bitset<35> sum(0);
  REP(i, N)
    sum ^= bitset<35>(a[i]);

  REP(i, N)
    cout << (i > 0 ? " " : "") << (sum ^ bitset<35>(a[i])).to_ullong();
  cout << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> a(N);
  REP(i, N) {
    cin >> a[i];
  }

  solve(N, move(a));

  return 0;
}


Measured memory_bytes: 4688