akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <time.h>
int main(){
    int i,n,ans=0;
    char s[55]={};
    scanf("%d %s",&n,s);
    for(i=0; i<n-2; i++){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')ans++;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1708
n, m = map(int, input().split())
problems = [0 for _ in range(n)]
was = [0 for _ in range(n)]

for _ in range(m):
  num, ans = input().split()
  num = int(num) - 1
  if ans == 'AC':
    if problems[num] == 0:
      problems[num] = 1
  else:
    if problems[num] == 0:
      was[num] += 1
      
for i, problem in enumerate(problems):
  if problem == 0:
    was[i] = 0

print('{} {}'.format(sum(problems), sum(was)))


Measured memory_bytes: 4752
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
#define dcml(n) fixed<<setprecision(n)

 
ll GCD(ll a,ll b) { return b ? GCD(b,a%b) : a; } 
ll LCM(ll a,ll b) { return a/GCD(a,b)*b; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 
using namespace std;
//-------------------------------------------
typedef pair<ll,ll> P;
int main(void){
    ll N;cin>>N;
    priority_queue<ld,vector<ld>,greater<ld>> v;
    ll v0=0;
    REP(i,N){
        cin>>v0;
        v.push(v0);
    } 

    ld ans=0;
    REP(i,N){
        
        ld q=v.top();v.pop();
        if(v.empty()){
            ans=q;
            break;
        }
        ld q2=v.top();v.pop();
        if(v.empty()){
            ans=((q+q2)/2.0);
            break;
        }
        v.push((q+q2)/2.0);
    }
    cout<<ans<<"\n";
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<int> A(N, 0);
	rep (i, N) cin >> A[i];

	int g = __gcd(A[0],A[1]);
	for (int i = 2; i < N; ++i){
		g = __gcd(g,A[i]);
	} // end for

	cout << g << endl;
	
	return 0;
}

Measured memory_bytes: 640
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""


n = l()

for i in range(5):
	if n[i] == 0:
		print(i+1)
		exit()

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

int main() {
  ll N, T;
  cin >> N >> T;
  vector<ll> t(N);
  for (int i = 0; i < N; i++) cin >> t[i];
  ll ans = T;
  for (int i = 0; i < N-1; i++) {
    ans += min(T, t[i+1]-t[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4804
import Control.Monad
import Control.Applicative

calcPath :: Int -> Int -> [(Int, Int)] -> IO Int
calcPath 0 _ _  = return 1
calcPath _ _ [] = return 0
calcPath l n xs = sum <$> (forM nextXs' $ (\i -> do
  --putStrLn $ show (l, n, xs ,nextXs, map snd nextXs')
  --(putStrLn . show) =<< calcPath 2 3 [(2,3),(3,4),(2,4)]
  calcPath (l - 1) i nextXs))
  where nextXs  = [xs' | xs' <- xs, not.fst.includeN xs' $ n]
        nextXs' = map (snd.flip includeN n) [xs'|xs' <-xs,fst$includeN xs' n] 

includeN :: (Int, Int) -> Int -> (Bool, Int)
includeN (x, y) n
  | x == n    = (True, y)
  | y == n    = (True, x)
  | otherwise = (False, 0)


main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  numPares <- replicateM m $ do
              [a, b] <- map read . words <$> getLine
              return (a, b)
  putStrLn =<< (show <$> calcPath (n - 1) 1 numPares)

Measured memory_bytes: 1532
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	int a,b;
	cin>>a>>b;
	if((abs(a+b)&1)==1){
		cout<<"IMPOSSIBLE";
	}
	else{
		if(a<b) swap(a,b);
		cout<<abs(a+b)/2;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define l(x) x
#define r(x) x + n
using namespace std;
const int N = 2100;
struct edge
{
    int to, nxt;
}e[N];
int head[N], tot = 0;
int n, m;
int fa[N * 2], siz[N * 2];
int vx[N], vy[N], link1[N], link2[N];
void addedge(int u, int v)
{
    // cout << u << " "<< v<<endl;
    tot++;
    e[tot] = edge{v, head[u]};
    head[u] = tot;
    return ;
}
int find(int x)
{
    if(fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}

void merge(int u,int v)
{
    u = find(u), v = find(v);
    if(u == v) return;
    fa[u] = v;
    return;
}

int dfs(int u)
{
    // cout<<u<<endl;
    vx[u] = 1;
    for(int i = head[u]; i; i = e[i].nxt)
    {
        int v = e[i].to;
        if(vy[v]) continue;
        vy[v] = 1;
        if(!link2[v] || dfs(link2[v]))
        {
            link2[v] = u;
            link1[u] = v;
            return 1;
        }
    }
    return 0;
}

int hungary(int n)
{
    for(int i = 1; i <= n; i++) link1[i] = link2[i] = 0;
    int res = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++) vx[j] = vy[j] = 0;
        res += dfs(i);
    }
    return res;
}
int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= 2 * n; i++) fa[i] = i;
    int x, y;
    for(int i = 1; i <= m; i++)
    {
        scanf("%d%d", &x, &y);
        merge(l(x), r(y));
        siz[l(x)] = siz[r(y)] = 1;
        addedge(l(x), r(y));       
    }
    int mx = 0;
    for(int i = 1; i <= n * 2; i++) if(find(i) == i&&siz[i]) mx++;
    printf("%d ", m - hungary(n * 2));
    printf("%d\n",m - mx);
    return 0;
}


Measured memory_bytes: 3304
/*
  AUTHOR:SOURABH
  CREATED:07:03:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll t,n,q,i,g,ti,fi;
    string s,temp;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>s;
        cin>>q;
        stack<string> q1,q2;
        g=1;
        W(q--)
        {
            cin>>ti;
            if(ti==1)
            {
                g=!g;
            }
            else
            {
                cin>>fi>>temp;
                if((fi==1 && g==1) || (fi==2 && g==0))
                {
                    q1.push(temp);
                }
                else
                {
                    q2.push(temp);
                }
            }
        }
        if(g==1)
        {
            W(!q1.empty())
            {
                cout<<q1.top();
                q1.pop();
            }
            cout<<s;
            temp="";
            W(!q2.empty())
            {
                temp+=q2.top();
                q2.pop();
            }
            reverse(temp.begin(),temp.end());
            cout<<temp;
        }
        else
        {
            W(!q2.empty())
            {
                cout<<q2.top();
                q2.pop();
            }
            reverse(s.begin(),s.end());
            cout<<s;
            temp="";
            W(!q1.empty())
            {
                temp+=q1.top();
                q1.pop();
            }
            reverse(temp.begin(),temp.end());
            cout<<temp;
        }
    }
    return 0;
}















Measured memory_bytes: 11600
n = int(input())
data = [list(map(int, input().strip().split())) for _ in range(n)]

data = sorted(data, key=lambda d: d[1])

work_time = 0
impossible = False
for a, b in data:
    deadline = b
    work_time += a
    if work_time > b:
        impossible = True
        break

if impossible:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 55248
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bn begin()
#define en end()
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007LL
#define pi 3.141592653589
using namespace std;

int power(int x, int y) ;
int gcd(int a, int b) ;

signed main() {
    quickie
    int x, n ;
    cin >> x >> n ;
    int a[n] ;
    mi m ;
    rep(i, 0, n) {
        cin >> a[i] ;
        m[a[i]]++ ;
    }
    int xx, mn = 10000000000 ;
    rep(i, 0, 1000) {
        if(m[i] == 0) {
            int ans = abs(x-i) ;
            if(ans < mn) {
                mn = ans ;
                xx = i ;
            }
        }
    }
    cout << xx << "\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

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


Measured memory_bytes: 3720
#include<iostream>
#include <string>
#include<vector>
typedef long long ll;

using namespace std;
int main()
{
	int r;
	cin >> r;
	if (r < 1200) {
		cout << "ABC";
	}
	else if (r < 2800) {
		cout << "ARC";
	}
	else {
		cout << "AGC";
	}
	return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll R;
int main(){
    scanf("%lld", &R);
    printf("%lld", R * R);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	
	int i ,sum = 0;
	string S,T;
	cin>>S>>T;
	for(i =0;i<3;i++)
	{
		if(S[i]==T[i]) sum++;
	}
	
	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
count = 0

for i in range(1,N-1):
    if P[i] > P[i-1] and P[i+1] > P[i] or P[i-1] > P[i] and P[i] > P[i+1]:
        count += 1

print(count)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	int a[1005];
	int n, m;
	int sum = 0;
	int num = 0;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	for (int i = 0; i < n; i++)
	{
		if (a[i] >= (sum*1*1.0 / (4 * m))) num++;
	}
	if (num >= m) cout << "Yes";
	else cout << "No";
	return 0;
}

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

int main() {
    int n, h[100000], m = 0, k = 0;
    cin >> n;
    for (int i = 0; i < n;i++) {
        cin >> h[i];
    }
    for (int i = 1; i < n; i++) {
        if (h[i - 1] < h[i]) m = 0;
        else {
            m++;
            if (k < m) k = m;
        }
    }
    cout << k << endl;
}

Measured memory_bytes: 640
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N := sc.nextInt()
	H := sc.nextIntSlice(N)
	all := true
	before := H[0] - 1
	for i := 1; i < N; i++ {
		if before <= H[i]-1 {
			before = H[i] - 1
		} else if before <= H[i] {
			before = H[i]
		} else {
			all = false
			break
		}
	}
	if all {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  int m,n;
  cin>>m>>n;
  vector<string> f(m+2);
  REP(i,m) {
    string l;
    cin>>l;
    f[i+1] = " " + l + " ";
  }
  f[0] = f[m+1] = string(n+2, ' ');
  vector<string> s(2);
  REP(i,2)cin>>s[i];
  int sum = 0;
  REP(i,m-1)REP(j,n-1) {
    bool iss = true;
    REP(k,2)REP(l,2)
      if(f[i+k+1][j+l+1] != s[k][l]) iss = false;
    if (iss) ++sum;
  }
  int mx = 0;
  REP(i,m)REP(j,n) {
    string joi = "JOI";
    char old = f[i+1][j+1];
    int oldff = 0;
    int ffmx = 0;
    REP(k,3) {
      f[i+1][j+1] = joi[k];
      int ff = 0;
      REP(o,2)REP(p,2) {
        bool ok = true;
        REP(q,2)REP(r,2)
          if (f[i+o+q][j+p+r] != s[q][r]) ok = false;
        if (ok) ++ff;
      }
      if (joi[k] == old) oldff = ff;
      ffmx = max(ffmx, ff);
    }
    f[i+1][j+1] = old;
    mx = max(mx, ffmx-oldff);
  }
  cout << sum + mx << endl;
  return 0;
}

Measured memory_bytes: 3112
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int MAX = 200000;
class shuturyoku_unko {
public:
	char C[100], D[100];
	constexpr shuturyoku_unko() : C(), D() {
		for (int i = 10; i < 100; i++) {
			C[i] = '0' + i / 10;
			D[i] = '0' + i % 10;
		}
	}
} f;

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X < 10) {
		*di++ = '0' + X;
		*di++ = '\n';
		return;
	}
	*di++ = '0' + f.C[X];
	*di++ = '0' + f.D[X];
	*di++ = '\n';
}

char S[200010];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = 0;
	char c;
	while ((c = getchar_unlocked()) >= '0') N = N * 10 + c - '0';
	fread(S, 1, 200000, stdin);
	

	int cnt = 0;
	rep(i, N) cnt += (S[i] == '1');

	int mod1 = cnt + 1;
	int mod2 = cnt - 1;

	ll kazu1 = 0;
	ll kazu2 = 0;

	rep(i, N) {
		kazu1 = (kazu1 * 2 + (S[i] - '0')) % mod1;
	}
	if (mod2 > 0) {
		rep(i, N) {
			kazu2 = (kazu2 * 2 + (S[i] - '0')) % mod2;
		}
	}
	ll are1[200000], are2[200000];
	are1[N - 1] = 1;
	are2[N - 1] = 1;
	for (int i = N - 2; i >= 0; i--) {
		are1[i] = are1[i + 1] * 2 % mod1;
		if (mod2 > 0) are2[i] = are2[i + 1] * 2 % mod2;
	}

	rep(i, N) {
		if (S[i] == '0') {
			ll tmp = kazu1 + are1[i];
			tmp %= mod1;

			int kotae = 1;
			while (tmp) {
				int k = __builtin_popcount(tmp);
				tmp = tmp % k;
				kotae++;
			}
			putint(kotae);
		}
		else {
			if (mod2 == 0) {
				putint(0);
			}
			else {
				ll tmp = kazu2 - are2[i] + mod2;
				tmp %= mod2;

				int kotae = 1;
				while (tmp) {
					int k = __builtin_popcount(tmp);
					tmp = tmp % k;
					kotae++;
				}
				putint(kotae);
			}
		}
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 7260
#include <iostream>
using namespace std;
using ll = long long;
int main() {
    ll n,m;
    cin >> n >> m;
    ll ans = 1;
    ll mod=1000000007;
    for (int i = 0; i < n; i++) {
        ans *= (m - i);
        ans %= mod;
    }
    ll p = 1;
    ll q = 0;
    for (int i = 0; i < n; i++) {
        ll qq = q;
        q = (qq+p) * (n - i - 1);
        p *= (m - n);
        p += qq * (m - n + 1);
        p %= mod;
        q %= mod;
    }
    cout << ans*p%mod<< endl;
}

Measured memory_bytes: 3636
// -*- coding: utf-8 -*-
//import java.awt.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    InputStream inputStream;
    if (args.length > 0 && args[0].equals("devTesting")) {
      try {
        inputStream = new FileInputStream(args[1]);
      } catch(FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    } else {
      inputStream = System.in;
    }
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskD solver = new TaskD();
    solver.solve(1, in, out);
    out.close();
  }
  
  static class TaskD {    
    int n, a, b;
    int[] x;
    
    void solve(int testNumber, InputReader in, PrintWriter out) {
      n = in.nextInt();
      x = new int[n];
      a = in.nextInt();
      b = in.nextInt();
      for (int i = 0; i < n; ++i) {
        x[i] = in.nextInt();
      }
      int[] diff = new int[n - 1];
      for (int i = 1; i < n; ++i) {
        diff[i - 1] = x[i] - x[i - 1];
      }
      Arrays.sort(diff);
      long[] summ = new long[n];
      for (int i = 1; i < n; ++i) {
        summ[i] = diff[i - 1] + summ[i - 1];
      }
      long ans = Long.MAX_VALUE / 2;
      for (int i = 0; i < n; ++i) {
        ans = Math.min(ans, summ[i] * a + (long) (n - i - 1) * b);
      }
      out.println(ans);
    }
    
    int i(long x) {
      return (int) x;
    }
    
    <T> void heapsort(T[] a, int s, int e) {
      Queue<T> queue = new PriorityQueue<>();
      for (int i = s; i <= e; ++i)
        queue.add(a[i]);
      for (int i = s; i <= e; ++i)
        a[i] = queue.poll();
    }    
    
  }
      
  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream));
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }
    
    public String nextLine() {
      try {
        return reader.readLine();
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }
    
    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public boolean hasInput() {
      try {
        if (tokenizer != null && tokenizer.hasMoreTokens()) {
          return true;
        }
        reader.mark(1);
        int ch = reader.read();
        if (ch != -1) {
          reader.reset();
          return true;
        }
        return false;
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }
    
  }
}


Measured memory_bytes: 25824
'''
Created on 2020/08/28

@author: harurun
'''
def main():
  import collections
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  S=pin()[:-1]
  a=0
  b=0
  c=0
  for i in S:
    if i=="a":
      a+=1
    elif i=="b":
      b+=1
    else:
      c+=1
  if max(a,b,c)-min(a,b,c)<=1:
    print("YES")
  else:
    print("NO")
  return 
main()
#解説AC

Measured memory_bytes: 9448
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  long x;
  cin >> n >> x;
  vector<long>a(n);
  int i;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  int ans = 0;
  sort(a.begin(),a.end());
  for(i=0;i<n-1;i++){
    if(x>=a[i]){
      x-=a[i];
      ans++;
    }else break;
  }
  if(x==a[n-1])ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := range a {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}
	ans := 1
	n -= k
	for n > 0 {
		n -= (k - 1)
		ans++
	}
	fmt.Println(ans)
}


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

int main() {
	int n;
	int h;
	int a;
	vector<int> b;
	cin >>n>>h;

	int ma = 0;
	for (int i=0;i<n;i++) {
	cin >> a;
	int sub;
	cin >> sub;
	b.push_back(sub);
	ma = max(ma, a);
	}

	sort(b.begin(),b.end());
	reverse(b.begin(), b.end());
	int cnt = 0;

	for (int i=0;i<n;i++) {
	
	if (b[i]>ma) {
	h -= b[i];
	cnt++;
//	cout << cnt << endl;
	} 
	if (h<=0) {
	cout << cnt << endl;
	return 0;
	}
	} 	
	cnt += h/ma;
	if (h%ma){
		cnt++;
	}
	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 892
n = gets.chomp.to_i
pp = gets.chomp.split().map(&:to_i)

i = 0
count = 0
min = []
while true
    if i == 0
        min.push(pp[i])
    else
        if min[(i-1)] > pp[i]
            min.push(pp[i])
        else
            min.push(min[i-1])
        end
    end
    i += 1
    if i == n
        break
    end
end

j = 0
while true
    q = pp[j]
    if min[j] >= q
        count +=1
    end
    j += 1
    if j == n
        break
    end
end

print count

Measured memory_bytes: 30208
/*  ***  In The Name of God ... ***  */
#include <bits/stdc++.h>

using namespace std ;
 
typedef long long ll ;
typedef long double ld ;


#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

string s ;
int n ;
vector < int > all ; 

int32_t main()                     
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s ;
	n = ( int ) s . size ( ) ;
	all . push_back ( 1 ) ;
	for ( int i = 1 ; i < n ; ++ i ) {
		if ( s [ i ] == s [ i - 1 ] )
			all . back ( ) ++ ;
		else
			all . push_back ( 1 ) ; 
	}
	if ( s [ 0 ] == 'T' ) {
		int res = 0 ; 
		for ( int i = 1 ; i + 1 < ( int ) all . size ( ) ; i += 2 ) {
			if ( all [ i ] < all [ i + 1 ] ) {
				res += all [ i ] ; 
			}
			else {
				res += all [ i + 1 ] ;
				if ( i + 2 < ( int ) all . size ( ) )
					all [ i + 2 ] += all [ i ] - all [ i + 1 ] ; 
			}
		}
		res <<= 1 ;
		cout << n - res << endl ; 
	}
	else {
		int res = 0 ;
		for ( int i = 0 ; i + 1 < ( int ) all . size ( ) ; i += 2 ) {
			if ( all [ i ] < all [ i + 1 ] ) {
					res += all [ i ] ; 
			}
			else {
				res += all [ i + 1 ] ;
				if ( i + 2 < ( int ) all . size ( ) )
					all [ i + 2 ] += all [ i ] - all [ i + 1 ] ; 
			}
		}
		cout << n - 2 * res << endl ; 
	}
}


Measured memory_bytes: 1680
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main(void) {
  bool isYes = true;
  long int N, i, j, tmp;
  vector<long int> H;
  vector<bool> H_check;
  cin >> N;
  for(i = 0; i < N; i++) {
    cin >> tmp;
    H.push_back(tmp);
    H_check.push_back(false);
  }
  for(i = 0; i < N; i++) {
    // 単調非減少でないなら高さを減らす
    if(i != (N-1) && H[i] > H[i+1] && !H_check[j]) {
      // 前の要素と今の要素の値が同じときに高さを減らすと不都合が起こるので忖度
      j = i - 1;
      while(j != -1 && H[i] == H[j] && !H_check[j]) {
        H[j]--;
        H_check[j] = true;
        j--;
      }
      H[i]--;
      H_check[i] = true;
    }
    // 単調非減少かどうかのチェック
    if( (i != (N-1) && H[i] > H[i+1]) || 
       (i != 0 && H[i-1] > H[i])
      ) {
      isYes = false;
      break;
    }
  }
  // 結果
  if(isYes) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

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

using namespace std;

void test()
{
   int a,b,c;
   cin>>a>>b>>c;
   
   int remain=a-b;
   
   if(remain>c)
    cout<<0<<"\n";
   else
    cout<<c-remain;
}

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

    test();

    return 0;
}


Measured memory_bytes: 3644
N, M = map(int, input().split())

A = [input() for _ in range(N)]
B = [input() for _ in range(M)]


def f(i, j):
  for k in range(M):
    for l in range(M):
      if A[i+k][j+l] != B[k][l]:
        return False
  return True

def slv():
  for i in range(N-M+1):
    for j in range(N-M+1):
      if f(i, j):
        return 'Yes'
  return 'No'
print(slv())
      


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 55
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

bool used[310];

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

    int N,M;
    cin>>N>>M;
    vector<queue<int>> V(N);
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            int a;
            cin>>a;
            V[i].push(a);
        }
    }
    int ans=300;
    for(int i=0;i<M;i++){
        vector<int> count(M+1,0);
        for(int j=0;j<N;j++){
            while(used[ V[j].front() ]){
                V[j].pop();
            }
            count[V[j].front()]++;
        }
        int maxC=0,num=1;
        for(int i=1;i<=M;i++){
            if(maxC<count[i]) maxC=count[i],num=i;
        }
        //cout<<maxC<<" "<<num<<endl;
        chmin(ans,maxC);
        used[num]=true;
    }
    cout<<ans<<endl;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int64_t> X(N), Y(N), Z(N);
  for(int i=0; i<N; i++){
    cin >> X.at(i) >> Y.at(i) >> Z.at(i);
  }
  int64_t Ans=0;
  int64_t Ansx=0, Ansy=0, Ansz=0;
  vector<pair<int64_t, int>> P(N);
  vector<vector<int>> T(8);
  T.at(0)={1, 1, 1};
  T.at(1)={1, 1, -1};
  T.at(2)={1, -1, 1};
  T.at(3)={1, -1, -1};
  T.at(4)={-1, 1, 1};
  T.at(5)={-1, 1, -1};
  T.at(6)={-1, -1, 1};
  T.at(7)={-1, -1, -1};
  for(int j=0; j<8; j++){
    Ansx=0;
    Ansy=0;
    Ansz=0;
  	for(int i=0; i<N; i++){
    	P.at(i)=make_pair(T.at(j).at(0)*X.at(i)+T.at(j).at(1)*Y.at(i)+T.at(j).at(2)*Z.at(i), i);
  	}
  	sort(P.begin(), P.end());
  	for(int i=N-M; i<N; i++){
    	Ansx+=X.at(P.at(i).second);
    	Ansy+=Y.at(P.at(i).second);
    	Ansz+=Z.at(P.at(i).second);
  	}
  	Ans=max(Ans, abs(Ansx)+abs(Ansy)+abs(Ansz));
  }
  cout << Ans << endl;
}

Measured memory_bytes: 256
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

s = input()
if s.isupper():
    print("A")
else:
    print("a")

Measured memory_bytes: 9056
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

vvi candi;
int N,M,q;
void dfs(int k,int last,vi A) {
  if(k==N) {
    candi.push_back(A);
    return;
  }
  srep(i,last,M+1) {
    vi B(A);
    B.push_back(i);
    dfs(k+1,i,B);
  }
}
vi acc;

void calc(int a,int b,int c,int d) {
  a--;b--;
  rep(i,sz(candi)) {
    if(candi[i][b]-candi[i][a]==c) {
      acc[i]+=d;
    }
  }
}
  
int main() {
  cin >> N >> M >> q;
  dfs(0,1,vi{});
  acc = vi(sz(candi),0);
  rep(i,q) {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    calc(a,b,c,d);
  }
  int ans = 0;
  rep(i,sz(candi)) {
    chmax(ans,acc[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
vector<int> nodeCount;

// 木上の探索
// v: 現在探索中の頂点、p: v の親 (v が根のときは -1)
void dfs(const Graph &G, int v, int p=-1) {
	for (auto new_v : G[v]) {
		if (new_v == p) continue; // nv が親 p だったらスルー
		nodeCount[new_v] += nodeCount[v];
		dfs(G, new_v, v); // v は新たに new_v の親になります
	}
}

int main() {

	// 頂点数 (木なので辺数は N-1 で確定)
	int n; cin >> n;
	
	nodeCount.assign(n, 0);

	int q; cin >> q;
	
	Graph G(n);
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	for (int i = 0; i < q; ++i) {
		int p, x;
		cin >> p >> x;
		nodeCount[--p] += x;
	}

	int root = 0;
	dfs(G, root);

	for (int i = 0; i < n; ++i)
		cout << nodeCount[i] << " ";
	return 0;
}

Measured memory_bytes: 26624
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  n += 2;
  uint8_t *p = ALLOC (n + 1, uint8_t);
  for (i32 i = 2; i <= n; ++i) {
    p[i] = 1;
  }
  for (i32 i = 2; i * i <= n; ++i) {
    if (!p[i]) continue;
    for (i32 j = i * i; j <= n; j += i) {
      p[j] = 0;
    }
  }
  i32 ans = 0;
  for (i32 i = 5; i <= n; i += 2) {
    ans += p[i] & p[i - 2];
  }
  ans *= 2;
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}



Measured memory_bytes: 11492
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll n, p;
	cin >> n >> p;

	vector<ll> a(n);
	ll even = 0;
	ll odd = 0;
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];

		if (a[i] % 2 == 0)
		{
			even++;
		}
		else
		{
			odd++;
		}
	}

	ull res = 1;
	if (p == 1 && odd == 0)
	{
		if (odd == 0)
		{
			res = 0;
		}
	}
	else
	{
		for (ll i = 0; i < even; i++)
		{
			res *= 2;
		}

		for (ll i = 0; i < odd - 1; i++)
		{
			res *= 2;
		}
	}

	println(res);
}


Measured memory_bytes: 256
/* winners never quit and quitters never win.
      #swap                                 */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define mod 1000000007
#define inf 100000000000000000
#define rk 256
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(v) v.begin(),v.end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)
/*ll ncr[5001][5001];
void coeff()
{
    for(ll a=0;a<5001;a++)
    {
        for(ll b=0;b<5001;b++)
        {
            ncr[a][b]=0;
        }
        ncr[a][0]=1;
    }
    for(ll a=1;a<5001;a++)
    {
        for(ll b=1;b<=a;b++)
        {
            ncr[a][b]=(ncr[a-1][b]+ncr[a-1][b-1])%mod;
        }
    }
}*/
ll fast_exp(ll base, ll exp1) {
    ll res=1;
    while(exp1>0) {
       if(exp1&1) res=(res*base)%mod;
       base=(base*base)%mod;
       exp1/=2;
    }
    return res%mod;
} 
ll pr[1000001]={0};
void isprime()
{
    pr[0]=1;
    pr[1]=1;
    for(ll a=2;a<1000001;a++)
    {
        if(!pr[a])
        {
            for(ll b=a*2;b<1000001;b+=a)
            {
                pr[b]=1;
            }
        }
    }
}
ll comp=1,tim=0;
struct vertex
{
    vc<ll> adj;
    ll vis=0;
    ll parent=-1;
    ll dist=0;
    ll component=0;
    ll in=0;
    ll out=0;
    ll low=0;
    ll child=0;
    ll indeg=0;
    ll outdeg=0;
    bool AP=false;
};
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll n;
    cin>>n;
    ll x[n];
    for(ll a=0;a<n;a++)
        cin>>x[a];
    ll dp[n]={0};
    dp[0]=0;
    if(n>1)
        dp[1]=llabs(x[1]-x[0]);
    for(ll a=2;a<n;a++)
    {
        dp[a]=min(dp[a-1]+llabs(x[a]-x[a-1]),dp[a-2]+llabs(x[a]-x[a-2]));
    }
    cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
bool dp[51][110][51][110];
int main(){
	int n,m;
	int dx[]={1,0,-1,0};
	int dy[]={0,1,0,-1};
	while(cin>>m>>n,n+m){
		vector<string>in(n);
		getline(cin,in[0]);
		rep(i,n)getline(cin,in[i]);
		m=in[0].size();
		rep(i,n)rep(j,m)if(in[i][j]==' ')in[i][j]='#';
		pair<pii,pii>w;
		rep(i,n)rep(j,m)if(in[i][j]=='L')
			w.first=pii(i,j);
		else if(in[i][j]=='R')
			w.second=pii(i,j);
		queue<pair<pii,pii> >q;
		q.push(w);
		rep(i,51)rep(j,110)rep(k,51)rep(l,110)dp[i][j][k][l]=false;
		dp[w.first.first][w.first.second][w.second.first][w.second.second]=true;
		while(!q.empty()){
			pair<pii,pii>r=q.front();
			q.pop();
			pii a=r.first,b=r.second;
			rep(i,4){
				pii na=pii(a.first+dx[i],a.second+dy[i]);
				pii nb=pii(b.first+dx[i],b.second-dy[i]);
				if(na.first<0||na.second<0||na.first>=n||na.second>=m||in[na.first][na.second]=='#')
					na.first-=dx[i],na.second-=dy[i];
				if(nb.first<0||nb.second<0||nb.first>=n||nb.second>=m||in[nb.first][nb.second]=='#')
					nb.first-=dx[i],nb.second+=dy[i];
				if(in[na.first][na.second]=='%'&&in[nb.first][nb.second]=='%'){
					cout<<"Yes"<<endl;
					goto end;
				}
				if(in[na.first][na.second]=='%')continue;
				if(in[nb.first][nb.second]=='%')continue;
				if(dp[na.first][na.second][nb.first][nb.second]==0){
					dp[na.first][na.second][nb.first][nb.second]=true;
					q.push(pair<pii,pii>(na,nb));
				}
			}
		}
		cout<<"No"<<endl;
		end:;
	}
}

Measured memory_bytes: 32896
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int a, b;
    cin >> a >> b;
    if (1 != a && 1 != b) {
        cout << 1 << endl;
    } else if (2 != a && 2 != b) {
        cout << 2 << endl;
    } else if (3 != a && 3 != b) {
        cout << 3 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  ll q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  ll rq, rh, rs, rd;
  rq = q;
  rh = min(h, 2 * rq);
  rs = min(s, 2 * rh);
  rd = min(d, 2 * rs);
  ll sum = 0;
  sum += n / 2 * rd;
  n %= 2;
  sum += n * rs;
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int n,a,b,c,d,s;
  bool f=false;
  for(;;){
    cin >> n;
    if(n==0)break;
    if(f) cout << endl;
    cin >> a >> b >> c >> d;
    s = a * 10 + b * 50 + c * 100 + d * 500 - n;
    n = a - (s % 50) / 10;
    if(n>0) cout << "10 " << n << endl;
    n = b - (s % 100) / 50;
    if(n>0) cout << "50 " << n << endl;
    n = c - (s % 500) / 100;
    if(n>0) cout << "100 " << n << endl;
    n = d - s / 500;
    if(n>0) cout << "500 " << n << endl;
    f = true;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int n, x;
    cin >> n >> x;
    vi a(n);

    fo(i, n) cin >> a[i];

    sort(all(a));

    int at = 0;
    while ( x > 0 and at < n ) {
        if ( at == n - 1 ) {
            if ( a[at] == x ) at++;
            else break;
        }
        if ( a[at] <= x ) {
            x -= a[at];
            at++;
        } else break;
    }

    at = (at > n) ? n : at;
    cout << at << endl;

    return 0;
}

Measured memory_bytes: 256
#/usr/bin/ruby
#encoding: utf-8

# input
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

ans = 0
(0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      if x == 500*i + 100*j + 50*k
        ans += 1
      end
    end
  end
end

puts ans

Measured memory_bytes: 1916
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 next_permutation<T: std::cmp::PartialOrd>(arr: &mut std::vec::Vec<T>) -> bool {
    let mut i = arr.len() - 1;
    while i > 0 && arr[i - 1] >= arr[i] {
        i -= 1;
    }
    if i <= 0 {
        return false;
    }

    let mut j = arr.len() - 1;
    while arr[j] <= arr[i - 1] {
        j -= 1;
    }
    arr.swap(i - 1, j);

    arr[i..].reverse();

    return true;
}

#[derive(Debug)]
struct App {
    // input
    n: i32,
    m: i32,
    a: Vec<(i32, i32)>,
}

impl App {
    fn input() -> App {
        let n: i32 = read();
        let m: i32 = read();
        return App {
            n: n,
            m: m,
            a: (0..m).map(|_| (read::<i32>() - 1, read::<i32>() - 1)).collect(),
        };
    }

    fn solve(&mut self) {
        let mut mat = vec![vec![false; self.n as usize]; self.n as usize];
        for &(u, v) in &self.a {
            mat[u as usize][v as usize] = true;
            mat[v as usize][u as usize] = true;
        }

        let mut a: Vec<i32> = (0..self.n).collect();
        let mut ans = 0;
        loop {
            if a[0] == 0 {
                let mut ite = a.windows(2).map(|e| mat[e[0] as usize][e[1] as usize]);
                if ite.all(|f| f) {
                    ans += 1;
                }
            }

            if !next_permutation(&mut a) {
                break;
            }
        }

        println!("{}", ans);
    }
}

fn main() {
    let mut app = App::input();
    app.solve();
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N,K; cin >> N >> K;
    vector<int> l(N);
    REP(i,N) cin >> l[i];
    sort(ALL(l), greater<int>());
    int ans = 0;
    REP(i,K){
        ans += l[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  getline(cin,s);
  
  for(int i=0;i<s.size();i++){
    if(s[i]=='a' && s[i+1]=='p' && s[i+2]=='p' && s[i+3]=='l' && s[i+4]=='e'){
      s[i]='p';
      s[i+1]='e';
      s[i+2]='a';
      s[i+3]='c';
      s[i+4]='h';
    }else if(s[i]=='p' && s[i+1]=='e' && s[i+2]=='a' && s[i+3]=='c' && s[i+4]=='h'){
      s[i]='a';
      s[i+1]='p';
      s[i+2]='p';
      s[i+3]='l';
      s[i+4]='e';
    }
  }
  cout<<s<<endl;
}

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

typedef long long ll;

int main(){
	ll A,B,C,D;
	cin >> A >> B >> C >> D;
	A--;
	ll lcm = C*D / __gcd(C,D);
	ll ac = A/C;
	ll ad = A/D;
	ll acd = A/lcm;
	ll bc = B/C;
	ll bd = B/D;
	ll bcd = B/lcm;
	cout <<	(B-bc-bd+bcd) - (A-ac-ad+acd) << endl;
	return 0;
}




Measured memory_bytes: 256
def main():
    X,N = map(int, input().split())
    P = list(map(int, input().split()))
    numup = X
    numdown = X
    a = True
    while a:
        if numdown not in P:
            a = False
            return print(numdown)
        elif numup not in P:
            a = False
            return print(numup)
        else:
            numdown -= 1
            numup += 1
main() 

Measured memory_bytes: 9056
N = int(input())
c = input()
total_r = 0
total_w = 0
ans = 0
for i in range(len(c)):
    if c[i] == 'R':
        total_r += 1
    else:
        total_w += 1
for i in range(total_r):
    if c[i] == "W":
        ans += 1
print(ans)
    

Measured memory_bytes: 9472
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

int n,m,a,b,c,d[100005] = {};
string s,w;


int main(){

  /*  cin >> s;

    rep(i,0,sz(s)){
        if(i == 3)cout << "8";
        else cout <<s[i];
    }
    cout << endl;*/

    cin >> n;
    rep(i,0,n)cin >> d[i];

    sort(d,d+n);

    int ans = 0,t = 1;
    rep(i,0,n-1){
        if(d[i] < d[i+1])t++;
        //else ans = max(ans,t);
    }
   // ans = max(ans,t);
    P(t);
	
	return  0;
}

Measured memory_bytes: 256