akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());
	string ans = "NO";
	if(a[0] == 5 && a[1] == 5 && a[2] == 7)ans = "YES";
	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
T,A = map(int, input().split())
h = map(float, input().split())
H = list(map(lambda x: abs(A - (T - (x * 0.006))), h))

ans = -1
tar = 999999999999
for i,v in enumerate(H):
    if tar > v:
        tar = v
        ans = i
print(ans + 1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long
//#define d double
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
#define M 100000007
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)

#include <bits/stdc++.h>
using namespace std;
vector<int>adj[N];
ll lazy[N];

void dfs(int curr,ll prev)
{
    lazy[curr]+=lazy[prev];
   for(int i=0;i<adj[curr].size();i++)
   {
       int v=adj[curr][i];
       if(v==prev)continue;
       dfs(v,curr);
   }
}

int main()
{
    FastIO;
    int n,q;
    cin>>n>>q;


    int a,b;
    for(int i=1;i<=n-1;i++)
    {
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    ll ver,val;
    while(q--)
    {
    cin>>ver>>val;
    lazy[ver]+=val;
    }
dfs(1,0);
for(int i=1;i<=n;i++)
    cout<<lazy[i]<<" ";
}


Measured memory_bytes: 24320
#include <iostream>
#include <string>
using namespace std;
#pragma warning (disable: 4996)
 
 //分布にすることが本質
 //前から決め打つ
 //個数の分布管理に帰着させてみよ
 //複数おける（選べる）ものがある場合, 分布にするというのが本質
int N, A[1 << 18], C[3];
long long sum = 1;
 
int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
 
	for (int i = 1; i <= N; i++) {
		long long cnt = 0, id = -1;
		if (A[i] == C[0]) { cnt++; id = 0; }
		if (A[i] == C[1]) { cnt++; id = 1; }
		if (A[i] == C[2]) { cnt++; id = 2; }
		if (id == -1) {
			cout << "0" << endl;
			return 0;
		}
		sum *= cnt; C[id]++;
		sum %= 1000000007;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
ans=0
before=a[0]
cnt=1
for i in range(1,n):
    if a[i]==before:
        cnt+=1
    else:
        if before<cnt:
            ans+=abs(cnt-before)
        elif before>cnt:
            ans+=cnt
        before=a[i]
        cnt=1
if before<cnt:
    ans+=abs(cnt-before)
elif before>cnt:
    ans+=cnt
print(ans)


Measured memory_bytes: 14692
#include<stdio.h>
#include<string.h>
#define MAX(x,y) ((x>y)?x:y)
typedef struct g{
	int d,s,e;
}G;
G a[12];
typedef struct p{
	int x,y,z,f;
}P;
P q[50000],sq[50000],cp;
int qn,sqn;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
char map[25][25];
int func(int d,P p){
	p.x+=dx[d];p.y+=dy[d];
	int m=map[p.y][p.x]-'0';
	if(0<=m && m<=9 && !(p.f&(1<<m)))return m;
	else return -1;
}
void func2(int f){
	int i;
	for(i=0;i<10;i++){
		if((f>>i)&1)printf("1");
		else printf("0");
	}
	printf("\n");
}
int main(){
	int i,j,k,w,h,n,m,mt,t,ans;
	char s;
	
	while(1){
		scanf("%d %d\n",&w,&h);
		if(w+h==0)break;
		for(i=0;i<=h+1;i++)map[i][0]=map[i][w+1]='#';
		for(i=1;i<=w  ;i++)map[0][i]=map[h+1][i]='#';
		for(i=1;i<=h;i++){
			for(j=1;j<=w;j++){
				scanf("%c ",&map[i][j]);
				if(map[i][j]=='P'){
					q[0]=(P){j,i,0,0};
					map[i][j]='.';
				}
			}
		}
		//for(i=0;i<=h+1;i++)printf("%s\n",map[i]);
		mt=0;
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&m);
			scanf("%d%d%d",&a[m].d,&a[m].s,&a[m].e);
			mt=MAX(mt,a[m].e);
		}
		qn=1;
		t=1;
		for(i=0;i<4;i++){
			m=func(i,q[0]);
			if(m!=-1 && a[m].s<=0 && 0<a[m].e){
				q[0].z+=a[m].d;
				q[0].f=q[0].f|(1<<m);
			}
		}
		while(t<=mt+1){
			sqn=0;
			for(i=0;i<qn;i++){
				//printf("%2d %2d %3d ",q[i].x,q[i].y,q[i].z);
				//func2(q[i].f);
				for(j=0;j<4;j++){
					cp=q[i];
					cp.x+=dx[j];
					cp.y+=dy[j];
					if(map[cp.y][cp.x]=='.'){
						for(k=0;k<4;k++){
							m=func(k,cp);
							if(m!=-1 && a[m].s<=t && t<a[m].e){
								cp.z+=a[m].d;
								cp.f=cp.f|(1<<m);
							}
						}
						for(k=0;k<sqn;k++){
							//if(sq[k].x==cp.x && sq[k].y==cp.y && (sq[k].z>cp.z || sq[k].f==cp.f))break;
							if(sq[k].x==cp.x && sq[k].y==cp.y){
								if(cp.f>sq[k].f && !((~cp.f)&sq[k].f)){
									sq[k]=cp;
									break;
								}
								if(cp.f==sq[k].f)break;
								if(cp.f<sq[k].f && !(cp.f&(~sq[k].f)))break;
							}
						}
						if(k==sqn)sq[sqn++]=cp;
					}
				}
			}
			memcpy(q,sq,sizeof(P)*sqn);
			qn=sqn;
			t++;
			//printf("\n");
		}
		ans=0;
		//printf("%d\n",sqn);
		for(i=0;i<qn;i++)ans=MAX(ans,q[i].z);
		printf("%d\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 432
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static boolean[] isPrime = new boolean[51001];
	static{
		Arrays.fill(isPrime, true);
		isPrime[0]=isPrime[1]=false;
		for(int i = 2; i*i<=isPrime.length; i++){
			if(isPrime[i]){
				for(int j = i+i; j < isPrime.length; j+=i){
					isPrime[j]=false;
				}
			}
		}
	}
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			int n = cin.nextInt();
			for(int i = n-1 ; i >= 0; i--){
				if(isPrime[i]){
					System.out.print(i+" ");
					break;
				}

			}

			for(int i = n+1 ; i < isPrime.length; i++){
				if(isPrime[i]){
					System.out.println(i);
					break;
				}
			}
		}
	}

}

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

//#define int long long
#define all(x) x.begin(), x.end()
#define arr(x) x,x+n
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define mp make_pair
#define pb push_back
#define precise cout<<fixed<<setprecision(20)
#define ff first
#define ss second
#define T int t;cin>>t;while(t--)
#define watch(x) cerr <<"\n"<<(#x)<<"is"<<(x)<<endl;

typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;

const int N=100001;
int mod=1000000007;
int mod2=998244353;

int min(int a,int b){if(a<b) return a; else return b;}
int max(int a,int b){if(a>b) return a; else return b;}
int power(int a,int b){int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int p, int q){if(p%q==0) return q; else{return gcd(q,p%q);}} 
int mul(int a,int b){return ((a%mod)*(b%mod))%mod;}
int sub(int a,int b){return (((a-b)%mod)+mod)%mod;}

void solve()
{
	int n,ac=0,wa=0,tle=0,ra=0;
	cin>>n;
	rep(i,0,n)
	{
		string s;
		cin>>s;
		if(s=="RE")
		ra++;
		else if(s=="TLE")
		tle++;
		else if(s=="WA")
		wa++;
		else
		ac++;
	}
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<ra<<endl;
}

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

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int r,D,x;
    cin>>r>>D>>x;
    rep(i,10){
        x=r*x-D;
        cout<<x<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        #include<iostream>
        #include<cstdio>
        #include<vector>
        #include<queue>
        #include<map>
        #include<cstring>
        #include<string>
        #include <math.h>
        #include<algorithm>
    //    #include <boost/multiprecision/cpp_int.hpp>
        #include<functional>
 //     #define int long long
        #define inf  1000000007
        #define pa pair<int,int>
#define ll long long
        #define pal pair<ll,ll>
        #define ppa pair<int,pa>
        #define  mp make_pair
        #define EPS (1e-10)
        #define equals(a,b) (fabs((a)-(b))<EPS)

        using namespace std;

        class Point{
        	public:
        	double x,y;
        	Point(double x=0,double y=0):x(x),y(y) {}
        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
        	Point operator * (double a) {return Point(x*a,y*a);}
        	Point operator / (double a) {return Point(x/a,y/a);}
        	double absv() {return sqrt(norm());}
        	double norm() {return x*x+y*y;}
        	bool operator < (const Point &p) const{
        		return x != p.x ? x<p.x: y<p.y;
        	}
        	bool operator == (const Point &p) const{
        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
        	}
        };
        typedef Point Vector;

        struct Segment{
        Point p1,p2;
        };

    double hen(Vector a){
    if(fabs(a.x)<EPS && a.y>0) return acos(0);
    else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
    else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
    else if(fabs(a.y)<EPS && a.x>0) return 0.0;
    else if(a.y>0) return acos(a.x/a.absv());
    else return 2*acos(0)+acos(-a.x/a.absv());

    }

        double dot(Vector a,Vector b){
        	return a.x*b.x+a.y*b.y;
        }
        double cross(Vector a,Vector b){
        	return a.x*b.y-a.y*b.x;
        }
        int dx[4] = {1, 0, -1, 0};
        int dy[4] = {0, 1, 0, -1};
        //----------------kokomade temple------------

int t[100002];

signed main(){
int n;
	cin>>n;
	
	for(int i=1;i<=n;i++) cin>>t[i];
	int ans=0;
	for(int i=1;i<=n;i++){
	//	cout<<" "<<t[t[i]]<<endl;
		if(t[t[i]]==i) {
			ans++;
	//		cout<<i<<endl;
		}
		
	}
	cout<<ans/2<<endl;
	
	return 0;
}

//printf("%.10f\n",ans);


Measured memory_bytes: 640
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int m = scan.nextInt();
        int f = scan.nextInt();
        int b = scan.nextInt();

        if (m >= b) {
            System.out.println("0");
        } else if (m + f >= b) {
            System.out.println(b - m);
        } else {
            System.out.println("NA");
        }
    }
}



Measured memory_bytes: 26196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
#define scl(n) scanf("%lld", &n)
#define pcl(n) printf("%lld\n", n)
#define pcl1(n) printf("%lld ", n)
#define nln printf("\n")
#define dev(x) cout << #x << " " << x << " ";
#define PTT pair<ll, ll>

map<ll, ll> mp, mp1;
map<ll, ll>::iterator itr;

int main()
{
    ll t, n, k, x;
    ll a, b, c, d;
    scl(a);
    scl(b);
    scl(c);
    scl(d);
    ll mx = -1e18;
    mx = max(mx, a * c);
    mx = max(mx, a * d);
    mx = max(mx, b * c);
    mx = max(mx, b * d);
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 3764
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
b = sorted(a, reverse=True)
for i in range(n):
    print(b[0]) if b[0] != a[i] else print(b[1])

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

const int Maxn = 100005;

int n;
int d[Maxn];

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


Measured memory_bytes: 640
#!/usr/bin/env ruby

def gcd(a, b)
    gcd(b, a) if b > a
    return b if (r = a % b).zero?
    gcd(b, r)
end


n, x = gets.split.map &:to_i
points = gets.split.map &:to_i
points.unshift(x)

diffs = []

points.each_with_index do |pos, idx|
    break if idx == points.size - 1
    diffs.push (points[idx + 1] - points[idx]).abs
end

current_divide = diffs[0]
diffs.each do |d|
    current_divide = gcd(current_divide, d)
end

puts current_divide

Measured memory_bytes: 9732
N = int(input())

ans = N
for i in range(N+1):
    cc = 0
    t = i
    while t > 0:
        cc += t%6
        t //= 6
    t = N-i
    while t > 0:
        cc += t%9
        t //= 9
    if ans > cc: ans = cc
print(ans)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    String ans;
    if (a+b == 15) {
      ans = "+";
    } else if (a*b == 15) {
      ans = "*";
    } else {
      ans = "x";
    }
    System.out.println(ans);
  }
}

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

int main() {
	int N;
	int A[101];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	int minv = A[0];
	int maxv = 0;
	for (int i = 0; i < N; i++) {
		if (minv > A[i]) minv = A[i];
		if (maxv < A[i]) maxv = A[i];
	}
	cout << maxv - minv << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=2e5+5;
ll n,T,b[N],ans,f[N],tot1,tot2;
struct node
{
	ll x,y;
}a[N];
bool mycmp(node x,node y)
{
	return x.x*(y.y+1)>y.x*(x.y+1);
}
int main()
{
	scanf("%lld%lld",&n,&T);
	for(ll i=1;i<=n;i++)
	{
		ll x,y;
		scanf("%lld%lld",&x,&y);
		if(x==0) b[++tot2]=y+1;
		else a[++tot1]={x,y};
	}
	sort(a+1,a+tot1+1,mycmp);
	sort(b+1,b+tot2+1);
	for(ll i=1;i<=35;i++) f[i]=T+1;
	for(ll i=1;i<=tot1;i++)
		for(ll j=35;j>=1;j--)
			f[j]=min(f[j],(f[j-1]+1)*(a[i].x+1)+a[i].y);
	for(ll i=1;i<=tot2;i++) b[i]+=b[i-1];
	for(ll i=0;i<=35;i++)
	{
		if(f[i]>T) continue;
		ll x=0;
		if(tot2) x=upper_bound(b+1,b+tot2+1,T-f[i])-(b+1);
		ans=max(ans,i+x);
	}
	printf("%lld\n",ans);
	return 0;
}

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

int N;
int A[2000];

bool isOK(int index, int key) {
    if (A[index] < key) return true;
    else return false;
}

int main() {
  cin >> N;
  rep(i,0,N) cin >> A[i];
  sort(A,A+N);

  int cnt = 0;
  rep(i,0,N-2) rep(j,i+1,N-1) {
    // [L,R)
    int L = j, R = N;
    int key = A[i] + A[j];
    while (R - L > 1) {
      int mid = (L + R) / 2;
      (isOK(mid,key) ? L : R) = mid;
    }
    cnt += L - j;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>

//AOJ0069
#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int atri(int ind, int d, string wam[]){
	int z = ind;
	rep2(i,1,d+1){
		if(wam[i][z-1]=='1')  z--;
		else if(wam[i][z]=='1') z ++;
	}
	return z;
}

int main(void){
int n,hi,at,d;
string ws,am[32];
	
	while(cin >> n){
		if(n==0 || cin.eof()) break;
		cin >> hi >> at >> d;
		rep(i,d){
			cin >> ws;
//			if(ws == "0" ) break;
			am[i+1] = "0" + ws + "0";
		}
		
		int svat=atri(hi,d,am);
//		printf("ss:%d %d \n",hi, svat);
		int ngsw = 0,  ans = -1;
		if(svat == at){
			ans = 0;
		}else{
			rep2(i,1,d+1) rep2(j,1,n+1){
				if( am[i][j-1] =='1') continue;
				if( am[i][j+1] =='1') continue;
				if( am[i][j] =='1' ) continue;
				
				am[i][j] = '1';
				if(at == atri(hi,d,am)){
					cout << i << " " << j <<endl;
					ngsw=1;
					goto HITEND;
				}
				am[i][j] = '0';
			}
			if(ngsw==0) ans = 1;
		}
		if(ngsw==0) cout << ans <<endl;	
		HITEND:	;
	}
	return 0;
	
}

Measured memory_bytes: 1212
macro_rules! input {
     (source = $s:expr, $($r:tt)*) => {
         let mut iter = $s.split_whitespace();
         input_inner!{iter, $($r)*}
     };
     ($($r:tt)*) => {
         let s = {
             use std::io::Read;
         let mut s = String::new();
         std::io::stdin().read_to_string(&mut s).unwrap();
         s
     };
     let mut iter = s.split_whitespace();
     input_inner!{iter, $($r)*}
     };
}
     
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
//#[allow(unused_imports)]
//use proconio::marker::{Isize1, Usize1, Bytes, Chars};
//#[proconio::fastout]
fn main() {
    input!{
        o: String,
        e: String,
    }
    let is_longer = o.len() > e.len();
    let (mut o, e) = (o.chars(), e.chars());
    let mut pwd = String::new();
    if is_longer {
        pwd.push(o.next().unwrap());
        for (e, o) in e.zip(o) {
            pwd.push(e);
            pwd.push(o);
        }
    } else {
        for (o, e) in o.zip(e) {
            pwd.push(o);
            pwd.push(e);
        }
    }
    println!("{}", pwd);
}


Measured memory_bytes: 4476
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String S = sc.next();
        S = "*"+S;
        char[] s = S.toCharArray();
        int Q = sc.nextInt();
        //int[] k = new int[Q];
        for(int i=0;i<Q;i++){
            int k = sc.nextInt();
            long ans = solve(s,k);
            System.out.println(ans);
        }
    }
    static long solve(char[] s, int k){
        int n = s.length-1;
        long[] D = new long[n+1];
        for(int end=1;end<=n;end++){
            D[end] += D[end-1];
            if(s[end]=='D') D[end]++;
            if(end+2-k>=0&&s[end+2-k]=='D') D[end]--;
        }
        long[] M = new long[n+1];
        for(int end=1;end<=n;end++){
            M[end] += M[end-1];
            if(s[end]=='M') M[end]++;
            if(end+2-k>=0&&s[end+2-k]=='M') M[end]--;
        }
        long[] DM = new long[n+1];
        for(int end=2;end<=n;end++){
            DM[end] += DM[end-1];
            if(s[end]=='M') DM[end] += D[end-1];
            if(end+1-k>=0&&s[end+1-k]=='D') DM[end] -= M[end-1];
        }
        long ans = 0;
        for(int i=3;i<=n;i++){
            if(s[i]=='C') ans += DM[i-1];
        }
        return ans;
    }
}

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

const int maxn = 3e5 + 10;
int n, mn = maxn, a[maxn][2], b[maxn][2];
string s;

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> s;
    for (int i = 0; i < s.length(); i++) {
        a[i][0] = (i == 0 ? (s[i] == 'W') : a[i - 1][0] + (s[i] == 'W'));
        a[i][1] = (i == 0 ? (s[i] == 'E') : a[i - 1][1] + (s[i] == 'E'));
    }
    for (int i = s.length() - 1; i >= 0; i--) {
        b[i][0] = (i + 1 == s.length() ? (s[i] == 'W') : b[i + 1][0] + (s[i] == 'W'));
        b[i][1] = (i + 1 == s.length() ? (s[i] == 'E') : b[i + 1][1] + (s[i] == 'E'));
    }
    for (int i = 0; i < s.length(); i++) {
        mn = min(mn, (i == 0 ? 0 : a[i - 1][0]) + (i + 1 == s.length() ? 0 : b[i + 1][1]));
    }
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 5396
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int n;
int k;
set<string> st;
string ss[11];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		st.clear();
		cin >> n >> k;
		if(!n)break;
		for(int i=0;i<n;i++){
			cin >> ss[i];
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				for(int p=0;p<n;p++){
					for(int q=0;q<n;q++){
						if(k==2){
							if(i!=j){
								st.insert(ss[i]+ss[j]);
							}
						}
						else if(k==3){
							if(i!=j&&j!=p&&i!=p){
								st.insert(ss[i]+ss[j]+ss[p]);
							}
						}
						else{
							if(i!=j&&i!=p&&i!=q&&j!=p&&j!=q&&p!=q){
								st.insert(ss[i]+ss[j]+ss[p]+ss[q]);
							}
						}
					}
				}
			}
		}
		printf("%d\n",st.size());
	}
}


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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n+1, false);
    for (int i = 0; i < m; i++){
        int num;
        cin >> num;
        a[num] = true;
    }
    vector<int> dp(n+2, 0);
    dp[n] = 1;
    for (int i = n - 1; i >= 0; i--){
        if(a[i]){
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
        //cout << dp[i] << endl;
    }
    cout << dp[0] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int         long long   
#define double      long double
#define endl        "\n"
#define pb          push_back
#define PI          3.1415926535897932384626433832795l
#define F           first
#define S           second
#define mp          make_pair
#define f(i,n)      for(int i=0;i<n;i++)
#define fastio      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)      (v).begin(),(v).end()
#define sort(v)     sort((v).begin(),(v).end())
#define rall(v)     (v).rbegin(),(v).rend()
#define rsort(v)     sort((v).rbegin(),(v).rend())
#define gcd(a,b)    __gcd((a),(b))
#define minn(v)     *min_element(v.begin(), v.end());
#define maxx(v)     *max_element(v.begin(), v.end());
#define print(x)    cout<<(x)<<endl;
typedef pair<int,int> pii;  
typedef vector<int> vi;
struct type{
    int i, j, k;
};
bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

signed main() 
{
    
    fastio;
    int n;
    cin>>n;
    vi a(n);
    f(i,n)cin>>a[i];
    bool flag=true;
    for (auto x:a)
    {
        if((x%2==0) and ((x%3!=0) and (x%5!=0)))
        {
            flag=false;
            break;
        }
    }
    if(flag)cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 int N,D,X;
static const int MAX_N  =100;
int A[MAX_N];

int main() {
cin >> N>>D>>X;
    int ans =0;
  for(int i=0;i<N;i++) cin >> A[i];

  
  for(int i=0;i<N;i++){
    int k=0;
   while(D >= k*A[i] + 1){
     ans++;
     k++;
   }
    
  }
  cout << ans + X <<endl;
  
}




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

int main() {
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  long long p;
  long long c = 0;
  int k;
  cin >> k;

  cout << a[k-1] << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

struct Food {
  int a;
  int b;

  Food(int a = -1, int b = -1) {
    this->a = a;
    this->b = b;
  }

  bool operator>(const Food &f) const {
    return a > f.a;
  }
};

const int MAX_TIME = 3010;

int main() {
  int N, T;
  cin >> N >> T;
  int dp[T + MAX_TIME];
  memset(dp, 0, sizeof(dp));

  priority_queue <Food, vector<Food>, greater<Food> > foods;

  int a, b;
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a >> b;
    foods.push(Food(a, b));
  }

  while(!foods.empty()) {
    Food food = foods.top();
    foods.pop();

    // cerr << food.a << endl;

    for (int t = T + food.a; t >= food.a; --t) {
      int nt = t - food.a;
      if (nt >= T) continue;
      dp[t] = max(dp[t], dp[nt] + food.b);
      ans = max(ans, dp[t]);
    }
  }

  /*
  for (int t = 0; t <= T; ++t) {
    cerr << dp[t] << " ";
  }
  cerr << endl;
  */
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#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: 620
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() {
	ll n,a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;
	int x = 0;
	if (n % min(a, min(b, min(c, min(d, e)))) != 0) {
		x = 1;
	}
	cout << n / min(a, min(b, min(c, min(d, e)))) + 5 - 1 + x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
struct Node{
  Node *L=nullptr, *R=nullptr;
};
Node* HEAD;
int n;
ll l, ans;
string s;
void dfs(Node* node, ll d){
  if(node == nullptr){
    ans ^= d&-d;
    return;
  }
  dfs(node->L, d-1);
  dfs(node->R, d-1);
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> l;
  HEAD = new Node();
  FOR(i, 0, n){
    cin >> s;
    Node* t = HEAD;
    FOR(j, 0, sz(s)){
      if(s[j]=='0'){
        if(t->L==nullptr) t->L = new Node();
        t = t->L;
      }else{
        if(t->R==nullptr) t->R = new Node();
        t = t->R;
      }
    }
  }
  dfs(HEAD, l+1);
  cout << (ans ? "Alice" : "Bob") << endl;
}

Measured memory_bytes: 5072
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u64 = read();
    let mut a: Vec<u64> = (0..n).map(|_| 0).collect();

    for _ in 0..(n - 1) {
        let b: usize = read::<usize>() - 1;
        a[b] += 1;
    }

    for i in &a {
        println!("{}", i);
    }
}


Measured memory_bytes: 3576
import java.util.*;
import java.io.*;
public class Main {
    public static int mod = 1000000007;
    public static long sum[] = new long[1<<16];
    public static long dp[] = new long[1<<16];
    public static long calculate(long arr[][] , int subset){
        long ans = 0;
        
        for(int i = 0 ; i < 17 ; i++){
            for(int j = i+1 ; j < 17 ; j++){
                if((subset&(1<<i))!=0 &&( subset&(1<<j))!=0)
                    ans += arr[i][j];
            }
        }
        return ans;
    }

    public static void prepareSum(long arr[][] , int n){
        for(int subset = 1 ; subset < (1 << n) ; subset++)
            dp[subset] = Integer.MAX_VALUE;
        for(int subset = 1 ; subset < (1 << n) ; subset++){
            sum[subset] = calculate(arr , subset);
        }
    }

    public static long solve(long arr[][] , int mask){
        long ans = 0;

        if(dp[mask] != Integer.MAX_VALUE) return dp[mask];
        
        for(int subset = mask ; subset!=0 ; subset=(subset-1)&mask){
            ans = Math.max(ans , sum[subset] + solve(arr , mask^subset));
        }

        return dp[mask] = ans;
    }

    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        long arr[][] = new long[n+1][n+1];
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                arr[i][j] = s.nextLong();
            }
        }
        prepareSum(arr , n);
        System.out.println(solve(arr , (1<<n)-1));
    }
}

Measured memory_bytes: 37164
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public bool ret { get; set; }
    public string s { get; set; }
    public int point { get; set; }
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var h = int.Parse(line[0]);
            if (h == 0) break;
            var map = new string[h, 5];
            for (int i = 0; i < h; i++)
            {
                line = Console.ReadLine().Trim().Split(' ');
                for (int j = 0; j < 5; j++) map[i, j] = line[j];
            }
            var ret = 0;
            while (true)
            {
                var x = getPoint(map);
                if (x == 0) break;
                else ret += x;
                goDown(map);
            }
            Console.WriteLine(ret);
        }
    }
    public static void goDown(string[,] map)
    {
        var h = map.GetLength(0);
        for (int i = 0; i < 5; i++)
        {
            var t = new List<string>();
            for (int j = h - 1; j >= 0; j--)
                if (map[j, i] != "0") t.Add(map[j, i]);
            var p = 0; var pmax = t.Count();
            for (int j = h - 1; j >= 0; j--)
                map[j, i] = p < pmax ? t[p++] : "0";
        }
    }
    public static int getPoint(string[,] map)
    {
        var h = map.GetLength(0);
        var ret = 0;
        for (int i = 0; i < h; i++)
        {
            var s = "";
            for (int j = 0; j < 5; j++) s += map[i, j];
            var p = checkS(s);
            if (p.ret)
            {
                ret += p.point;
                for (int j = 0; j < 5; j++) map[i, j] = p.s.Substring(j, 1);
            }
        }
        return ret;
    }
    public static P checkS(string s)
    {
        var ret = new P();
        for (int i = 5; i >= 3; i--)
            for (int j = 1; j <= 9; j++)
            {
                var w = new string(j.ToString()[0], i);
                var p = s.IndexOf(w);
                if (i == 5 && p == 0)
                {
                    ret.ret = true;
                    ret.point = 5 * j;
                    ret.s = "00000";
                    return ret;
                }
                else if (i == 4 && p >= 0)
                {
                    ret.ret = true;
                    ret.point = 4 * j;
                    ret.s = s.Replace(w, "0000");
                    return ret;
                }
                else if (i == 3 && p >= 0)
                {
                    ret.ret = true;
                    ret.point = 3 * j;
                    ret.s = s.Replace(w, "000");
                    return ret;
                }
            }
        return ret;
    }
}



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

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true;string res = "{"; for (const auto &x : v) {if (!first) {res += ", ";} first = false; res += to_string(x);} res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
  int a, b;
  cin >> a >> b;
  int low = min(round(a/0.08), round(b/0.1));
  int high = max(round(a/0.08), round(b/0.1));
  debug(low, high);
  while (low <= high) {
    if (floor(low*0.08) == a && floor(low*0.1) == b) {
      cout << low;
      return 0;
    }
    else {
      low++;
    }
  }
  cout << -1;
}


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

int main() {
  LL n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a --, b --, c --, d --;
  string s;
  cin >> s;

  bool sunuke = true, funuke = true;
  if (c < d) {
    for (int i = b + 1; i <= d; i ++) {
      if (s[i] == '#' && s[i - 1] == '#') {
        funuke = false;
        break;
      }
    }
    for (int i = a + 1; i <= c; i ++) {
      if (s[i] == '#' && s[i - 1] == '#') {
        sunuke = false;
        break;
      }
    }
  } else {
    for (int i = b + 1; i <= d; i ++) {
      if (s[i] == '#' && s[i - 1] == '#') {
        funuke = false;
        break;
      }
    }
    bool check = false;
    for (int i = a + 1; i <= c; i ++) {
      if (s[i] == '.' && s[i - 1] == '.' && s[i - 2] == '.' && i - 1 >= b && i <= d + 1) check = true;
      if (s[i] == '#' && s[i - 1] == '#') {
        sunuke = false;
        break;
      }
    }
    if (!check) sunuke = false;
  }

  string ans;
  if (sunuke && funuke) ans = "Yes";
  else ans = "No";
  cout << ans << endl;
}

Measured memory_bytes: 640
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = 10 ** 12
for i in range(n-k+1):
    ans = min(ans,abs(x[i])+(abs(x[i+k-1]-x[i])),abs(x[i+k-1])+(abs(x[i+k-1]-x[i])))
print(ans)

Measured memory_bytes: 20132
/*input
3
2 3 1
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=20005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int a[maxn],b[maxn],arr[maxn];
int main() {
    int n;
    cin>>n;
    REP(i,n){
        int x;
        cin>>x;
        arr[x]=i+1;
    }
    REP(i,n){
        int x=arr[i+1];
        a[x]=30000*x;
        b[x]=30000*(n-x)+arr[x];
    }
    REP(i,n) cout<<a[i+1]<<' ';
    cout<<'\n';
    REP(i,n) cout<<b[i+1]<<' ';
}

Measured memory_bytes: 896
#include <array>
#include <functional>
#include <iostream>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  std::vector<std::vector<int>> G(N);
  for (int i = 0; i < N - 1; ++i) {
    int x, y;
    std::cin >> x >> y;
    x--, y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  int mod = 1000000007;

  std::vector<std::array<long long, 2>> dp(N, std::array<long long, 2>({0, 0}));

  std::function<void(int, int)> dfs = [&](int v, int pv) {
    dp[v][0] = dp[v][1] = 1;
    for (auto &nv : G[v]) {
      if (nv == pv)
        continue;
      dfs(nv, v);
      dp[v][1] = (dp[v][1] * dp[nv][0]) % mod;
      dp[v][0] = (dp[v][0] * (dp[nv][0] + dp[nv][1])) % mod;
    }
  };
  dfs(0, -1);
  long long res = (dp[0][0] + dp[0][1]) % mod;
  std::cout << res << std::endl;
}


Measured memory_bytes: 14208
N = int(input())

A_list = list(map(int, input().split()))

def check():
	b_max = 0
	b_min = 0
	b_max_list = [0]
	for a in reversed(A_list):
#		print(b_min, b_max)
		b_max = a + b_max
		b_max_list.append(b_max)
		b_min = (a + b_min + 1) // 2
	
	b_max_list.pop()
	
	count = 0
	branches = 1
	for a, b_max in zip(A_list, reversed(b_max_list)):
		if branches < a:
			return -1
#		print(a, b_max)
		if branches <= 0:
			return -1
#		print("b>", branches)
		count += branches
		branches = min(b_max, (branches - a) * 2)
	
	return count

result = check()
if result != None:
	print(result)
else:
	print(-1)


Measured memory_bytes: 20144
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint A, B; cin >> A >> B;
    cout << (A-1)*(B-1) << endl;
    
    return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
 
using namespace std;
 
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
 
#define SEND_HELP ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
inline void setPrecision(int n){cout.precision(n);}
 
//DEBUG
#define BR cerr<<endl
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
 
ll INF = 1e10;
int MOD = 1e9+7;

int main(){
    #ifndef ONLINE_JUDGE
        freopen("inputf.in", "r", stdin);
    #endif
    SEND_HELP

    ll a, b, c;
    cin >> a >> b >> c;

    ll cnt = 0;
    cnt += (2 * min(b, c));
    ll t = c;
    c -= min(b, c);
    b -= min(b, t);

    if(c > 0){
        cnt += min(c, a);
        t = c;
        c -= min(c, a);
        if(c > 0)
            cnt ++;
    }
    else{
        cnt += b;
    }

    cout << cnt;
    return 0;
}

/*

*/

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<string>

using ll = long long;

int main(){
    int n, k;
    std::cin >> n >> k;

    ll sum = 0;
    for(int a = 1; a <= n; a++){
        // a + b, a + cの条件より
        int r;
        if(a % k == 0) r = 0;
        else r = k - a % k;
        // b + cはkの倍数の条件より
        if((r + r) % k != 0) continue;
        // b = r, r + k, r + 2k, ..., r + interval * k
        // c = 同上
        ll interval = (n - r) / k;
        if(r == 0){
            // このときはb = rとかはNG
            sum += interval * interval;
        }else{
            // b = rもOK
            sum += (interval + 1) * (interval + 1);
        }
    }

    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static boolean[] isPrime;
	static int[] prime,sum;
	static{
		isPrime=new boolean[10001];
		Arrays.fill(isPrime,true);
		isPrime[0]=isPrime[1]=false;
		for(int i=2;i*i<=isPrime.length;i++){
			if(isPrime[i]){
				for(int j=i+i;j<isPrime.length;j+=i){
					isPrime[j]=false;
				}
			}
		}int cnt=0;
		for(int i=0;i<100;i++){
//			System.out.println(i+" "+isPrime[i]);
		}
		for(int i=0;i<isPrime.length;i++){
			if(isPrime[i])
				cnt++;
		}
		prime=new int[cnt];
		sum=new int[cnt+1];
		cnt=0;
		for(int i=0;i<isPrime.length;i++){
			if(isPrime[i]){
				prime[cnt++]=i;
				sum[cnt]=sum[cnt-1]+i;
			}
		}
		for(int i=0;i<sum.length;i++){
//			System.out.println(sum[i]);
		}
	}
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		for(;;){
			int n=cin.nextInt();
			if(n==0)break;
			int ans=0;
			for(int i=0;i<sum.length;i++){
				for(int j=i+1;j<sum.length;j++){
					if(sum[j]-sum[i]==n)
						ans++;
				}
			}
			
			System.out.println(ans);
			
			
		}

	}

}

Measured memory_bytes: 19112
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s=="SUN")
        cout<<7;
    else if(s=="MON")
        cout<<6;
    else if(s=="TUE")
        cout<<5;
    else if(s=="WED")
        cout<<4;
    else if(s=="THU")
        cout<<3;
    else if(s=="FRI")
        cout<<2;
    else if(s=="SAT")
        cout<<1;


}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	long MOD = 1_000_000_000 + 7;
	long[] pow, rev;

	long pow(long n, int k) {
		if (k == 0) {
			return 1;
		}
		if (k % 2 == 0) {
			long t = pow(n, k / 2);
			t %= MOD;
			return t * t % MOD;
		} else {
			long t = pow(n, (k - 1) / 2);
			t %= MOD;
			t *= t;
			t %= MOD;
			return t * n % MOD;
		}
	}

	long combi(int n, int k) {
//		System.out.println("in combi: " + n + " " + k);
		long ret = 1;
		ret *= pow[n];
		ret *= rev[k];
		ret %= MOD;
		ret *= rev[n - k];
		return ret % MOD;
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		int h = sc.nextInt();
		int w = sc.nextInt();
		int hh = sc.nextInt();
		int ww = sc.nextInt();

		pow = new long[h + w + 1];
		rev = new long[h + w + 1];
		pow[0] = 1;
		rev[0] = 1;
		for (int i = 1; i < h + w + 1; i++) {
			pow[i] = pow[i - 1] * i;
			pow[i] %= MOD;
			rev[i] = pow(pow[i], (int) MOD - 2);
		}

//		System.out.println(Arrays.toString(pow));
//		System.out.println(Arrays.toString(rev));

		long ans = 0;
		for (int i = 1; i <= w - ww; i++) {
			long tmp1 = combi(ww - 1 + i + h - hh - 1, h - hh - 1);
			long tmp2 = combi(w - ww - i + hh - 1, hh - 1);
//			System.out.println(tmp1 + " " + tmp2);
			ans += tmp1 * tmp2;
			ans %= MOD;
		}
		System.out.println(ans);
	}

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


Measured memory_bytes: 12500
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        String s=sc.next();
        String t=sc.next();
        int a=sc.nextInt();
        int b=sc.nextInt();
        String ans=sc.next();
        int sum=0;

        if(ans.equals(s)){
            sum=a-1;
            System.out.println(sum+" "+b);
        }
        if(ans.equals(t)){
            sum=b-1;
            System.out.println(a+" "+sum);
        }
        sc.close();
    }
}

Measured memory_bytes: 23252
import std;

long calc(long n) {
    long sum(long n) { return n * (n + 1) / 2; }

    return sum(n) - 3 * sum(n/3) - 5 * sum(n/5) + 15 * sum(n/15);
}

void main() {
    int n; scan(n);
    writeln(calc(n));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define ld double
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
//#define len length()
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect


void solve() {
    int n, x, ans = 0;
    cin >> n;
    set <int> s;
    loop(i, n) {
        cin >> x;
        if (s.lower_bound(x) == s.begin()) ++ans;
        s.insert(x);
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 9600
#include <cstdio>

int A, B;
int h, w;
int a[110][110];

void solve()
{
	int i, j;
	h = w = 100;
	for(i=0; i<h; i++){
		for(j=0; j<w; j++)
			a[i][j] = -1;
	}
	A --;
	B --;
	for(i=0; i<h; i++){
		for(j=0; j<w; j++){
			if(A==0)
				break;
			if(i%2==1){
				a[i][j] = 1;
				continue;
			}
			if(j%2==0){
				a[i][j] = 0;
				A --;
			}
			else
				a[i][j] = 1;
		}
		if(A==0)
			break;
	}
	for(; j<w; j++)
		a[i][j] = 1;
	i ++;
	for(j=0; j<w; j++)
		a[i][j] = 1;
	for(i=h-1; i>=0; i--){
		for(j=0; j<w; j++){
			if(B==0)
				break;
			if(i%2==0){
				a[i][j] = 0;
				continue;
			}
			if(j%2==0){
				a[i][j] = 1;
				B --;
			}
			else
				a[i][j] = 0;
		}
		if(B==0)
			break;
	}
	for(i=0; i<h; i++){
		for(j=0; j<w; j++){
			if(a[i][j]==-1)
				a[i][j] = 0;
		}
	}
	printf("%d %d\n", h, w);
	for(i=0; i<h; i++){
		for(j=0; j<w; j++){
			if(a[i][j]==0)
				putchar('.');
			else
				putchar('#');
		}
		putchar('\n');
	}
}

int main()
{
	scanf("%d%d", &A, &B);
	solve();
	return 0;
}

Measured memory_bytes: 256