akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    ll ans = 0;
    rep(i, N) {
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int N = 523458;
  vector<int> v(N, 1);
  v[0]=v[1]=0;
  REP(i,N) {
    if (v[i])
      for (int j=i*2; j<N; j+=i)
        v[j] = 0;
  }
  int n;
  while(cin>>n,n) {
    int res =0;
    for (int i=n+1; i<=2*n; ++i)
      if (v[i])
        res++;
    cout <<res << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  for (int i = 0; i < N; i++){
  	int l,r;
    cin >> l >> r;
    
    sum += r - l + 1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
n,m=map(int, input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
x,y=[],[]
for s in ab:
    if s[0]==1:
        x.append(s[1])
    if s[1]==n:
        y.append(s[0])

print("POSSIBLE" if len(set(x)&set(y))>0 else "IMPOSSIBLE")

Measured memory_bytes: 61016
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll A;
  string B;
  cin >> A >> B;
  ll num_b = 0;
  int cnt = 0;
  for (ll i = 0; i < B.size(); ++i) {
    if (B[i] == '.') {
      continue;
    }
    num_b += (B[i] - '0') * pow(10, 2 - cnt);
    cnt += 1;
  }
  ll ans = A * num_b;
  ans /= 100;
  cout << ans << "\n";
}


Measured memory_bytes: 3864
#include <stdio.h>
#include <string.h>

int main(void)
{
  char s[100001];
  char c[256] = {};

  fgets(s, sizeof(s), stdin);
  size_t len = strlen(s);
  for (int i = 0; i < len; i++) {
    c[s[i]] |= 1;
  }

  char ans[5] = "None";
  for (char j = 'a'; j <= 'z'; j++) {
    if (c[j] == 0) {
      ans[0] = j;
      ans[1] = '\0';
      break;
    }
  }

  puts(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <list>
using namespace std;
int main()
{
	int n, x, p, l, i, r[11];
	while (cin >> n, (x = n) != -1)
	{
		p = l = 0;
		while (x != 0)
		{
			r[p++] = x % 4;
			x /= 4;
			l++;
		}
		for (i = l-1; i >= 0; i--)
			cout << r[i];
		if (!n) cout << 0;
		cout << endl;
	}
}

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

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

  int mini = 1000000, mx = 0;
  
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A' && i < mini) {
      mini = i;
    }
    if (s[i] == 'Z' && i > mx) {
      mx = i;
    }
  }

  cout << mx - mini + 1 << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
#include <numeric>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long
#define ld long double
#define PI 3.14159265358979l

int gcd(int a, int b) {
	if (a < b) {
		int tmp = a;
		a = b;
		b = tmp;
	}
	int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int main() {
	int n;
	int a[50];
	int v[50];
	int c[50];
	cin >> n;
	int ans = 0;
	rep(i, n) {
		cin >> v[i];
	}
	rep(i, n) {
		cin >> c[i];
	}
	rep(i, n) {
		a[i] = v[i] - c[i];
		
		if (a[i] >= 0)ans += a[i];
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define inf 100100100
ll max(ll a,ll b){return a>b?a:b;}
int main(){
    int n;
    scanf("%d",&n);
    ll a[n];
    for (int i = 0; i < n; i++)
        scanf("%lld",&a[i]);
    ll dp[n + 1][3];
    dp[0][0] = 0;
    dp[0][1] = -inf;
    for(int i = 0; i < n; i++){
        dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
        dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]);
    }
    printf("%lld\n",dp[n][0]);
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){
	double a,b,r,c;
	cin>>a>>b>>r;
	double s,l,h,rad,PI=acos(-1);
	rad=r*PI/180;
	s=(a*b*sin(rad))/2;
	c=sqrt(a*a+b*b-2*a*b*cos(rad));
	h=s*2/a;
	l=a+b+c;
	cout<<fixed<<setprecision(10)<<s<<endl;
	cout<<fixed<<setprecision(10)<<l<<endl;
	cout<<fixed<<setprecision(10)<<h<<endl;
	return 0;
}


Measured memory_bytes: 3612
function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  if(['AAA','BBB'].includes(input[0])){
    console.log('No');
  }else{
    console.log('Yes');
  }
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  



  


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())



void solve(){
    ll N, M;
    cin >> N >> M;

    if (N >= M/2) {
        cout << M/2 << endl;
        return;
    }
    cout << N + (M - 2*N) / 4 << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,n;
	char a[20]="CODEFESTIVAL2016";
	char x[20];
	scanf("%s",x);
	n=0;
	for(i=0;i<16;i++){
		if(x[i]!=a[i]){
			n++;
		}
	}
	printf("%d\n",n);
	return 0;
}

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

int main()
{
  string S, a;
  cin >> S;
  
  if (S == "Sunny")
  {
    a = "Cloudy";
  }
  else if (S == "Cloudy")
  {
    a = "Rainy";
  }
  else if (S == "Rainy")
  {
    a = "Sunny";
  }
  
  cout << a << endl;
}


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

int main() {
	int N, K;
	cin >> N >> K;
	if(N%2) {
		if (N/2+1 >= K) {
			cout << "YES\n";
		} else {
			cout << "NO\n";
		}
		return 0;
	} else {
		if (N/2 >= K) {
			cout << "YES\n";
		} else {
			cout << "NO\n";
		}
		return 0;
	}
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,min,max;

    scanf("%d %d %d",&a,&b,&c);

    min=a;
    if(min>b)
        min=b;
    if(min>c)
        min=c;

    max=a;
    if(max<b)
        max=b;
    if(max<c)
        max=c;

    printf("%d %d %d\n",min,(a+b+c)-(min+max),max);

    return 0;
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    ll N;
    cin >> N;
    auto rootN =  ll(floor(sqrtl(N)));
    ll mini = 20;
    FOR(i,1,rootN+1) {
        if (N%i!=0) continue;
        auto B = N/i;
        chmin(mini,max(ll(to_string(i).size()),ll(to_string(B).size())));
    }
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string inp;
    cin >> inp;
    int j = inp[0];
    for(int i = 1; i < inp.size(); ++i){
        if (inp[i]== j){
            cout<< "Bad"; 
            j = 10000;           
            break;
        }
        else{
            j = inp[i];
        }
    }
    if(j != 10000){
        cout<<"Good";
    }
    return 0 ;
}

Measured memory_bytes: 256
# coding: utf-8
S=list(input())
Acnt=0
Bcnt=0
AList=[]
BList=[]
for i in range(len(S)):
    if i%2==0:
        AList.append(0)
    else:
        AList.append(1)

for j in range(len(S)):
    if j%2==0:
        BList.append(1)
    else:
        BList.append(0)
    
#print(AList)
#print(BList)
    
for k in range(len(S)):
    if int(S[k])!=AList[k]:
        Acnt+=1
    if int(S[k])!=BList[k]:
        Bcnt+=1
        
print(min(Acnt,Bcnt))


Measured memory_bytes: 5544
#include <stdio.h>
 
int main(void) {
    int saikoro[6];
    int q,i;
    int top,front;
    int result;
     
    for(i=0;i<6;i++){
        scanf("%d",&saikoro[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d %d",&top,&front);
        result = dice(saikoro,top,front);
        printf("%d\n",result);
    }
    return 0;
}
int dice(int saikoro[6],int top,int front){
    if(top == saikoro[0]){
        if(front == saikoro[1]) return saikoro[2];
        if(front == saikoro[2]) return saikoro[4];
        if(front == saikoro[3]) return saikoro[1];
        if(front == saikoro[4]) return saikoro[3];
    }
    if(top == saikoro[1]){
        if(front == saikoro[0]) return saikoro[3];
        if(front == saikoro[2]) return saikoro[0];
        if(front == saikoro[3]) return saikoro[5];
        if(front == saikoro[5]) return saikoro[2];
    }
    if(top == saikoro[2]){
        if(front == saikoro[0]) return saikoro[1];
        if(front == saikoro[1]) return saikoro[5];
        if(front == saikoro[4]) return saikoro[0];
        if(front == saikoro[5]) return saikoro[4];
    }
    if(top == saikoro[3]){
        if(front == saikoro[0]) return saikoro[4];
        if(front == saikoro[1]) return saikoro[0];
        if(front == saikoro[4]) return saikoro[5];
        if(front == saikoro[5]) return saikoro[1];
    }
    if(top == saikoro[4]){
        if(front == saikoro[0]) return saikoro[2];
        if(front == saikoro[2]) return saikoro[5];
        if(front == saikoro[3]) return saikoro[0];
        if(front == saikoro[5]) return saikoro[3];
    }
    if(top == saikoro[5]){
        if(front == saikoro[1]) return saikoro[3];
        if(front == saikoro[2]) return saikoro[1];
        if(front == saikoro[3]) return saikoro[4];
        if(front == saikoro[4]) return saikoro[2];
    }
    return 0;
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll A,B,N; cin >> A >> B >> N;
  ll ans = 0;
  ll tmp;
  tmp = min(B-1,N);
  ans = A * tmp / B - A * (tmp / B);
  cout << ans << endl;
}

Measured memory_bytes: 3532
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = Data.List.map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = Data.List.map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	board  <- replicateM 3 readInts
	n <- readInt
	as <- replicateM n readInt
	putStrLn $ if solve board as
		then "Yes"
		else "No"
	
solve board as = runST $ do
	res <- newArray ( 0, 7 ) True :: ST s ( STUArray s Int Bool )
	forM_ [ 0 .. 2 ] $ \i -> do
		forM_ [ 0 .. 2 ] $ \j -> do
			modifyArray res i $ (&&) $
				( board !! i !! j ) `elem` as
			modifyArray res ( 3 + j ) $ (&&) $
				( board !! i !! j ) `elem` as

	forM_ [ 0 .. 2 ] $ \i -> do
		modifyArray res 6 $ (&&) $
			( board !! i !! i ) `elem` as
		modifyArray res 7 $ (&&) $
			( board !! i !! ( 2 - i ) ) `elem` as
	or <$> getElems res

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x, y, ans=0;
    cin >> x >> y;

    if(x==1)
	ans+=300000;
    else if(x==2)
	ans+=200000;
    else if(x==3)
	ans+=100000;

    if(y==1)
	ans+=300000;
    else if(y==2)
	ans+=200000;
    else if(y==3)
	ans+=100000;

    if(x==1 && y==1)
	ans += 400000;

    
    cout << ans << endl;
}



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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using mii = std::map<int, int>;
using mll = std::map<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = 2*(int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
const int dc[4] = {1, -1, 0,  0};
const int dr[4] = {0,  0, 1, -1};
//const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
//const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T> inline
istream& operator>>(istream &is, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) {
        is >> v[i]; 
    }
    return is;
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }

template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n,k;
    cin >> n >> k;
    
    ll ans = 0;
    irep2(b,1,n) {
        int p = n/b;
        int q = n%b;
        ans += p*max(b-k,0);
        ans += max(q-k+1,0);
        if(!k) { ans--; }
    }
    cout << ans << endl;
    return 0;
}
/*atcoder*/


Measured memory_bytes: 3624
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var A = Number(lines[0].split(" ")[0]);
    var B = Number(lines[0].split(" ")[1]);
    var C = Number(lines[0].split(" ")[2]);

    if (A + B >= C) { console.log("Yes") }
    else { console.log("No") }
});

Measured memory_bytes: 7500
#include "bits/stdc++.h"

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define get(x) scanf("%d", &x)
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
template <class T> inline void maxi(T &x,T y) {if (y > x) x = y;}
template <class T> inline void mini(T &x,T y) {if (y < x) x = y;}

const int N = 2e5 + 5, B = 0x7fffffff;
const int M = 1e6;
map <ll, int> comp;
set <ll> nums;
ll ps[N];
ll k;
ll ans;
int a[N];
int n;
int fen[M];
int nn;

void upd(int x){
  for (; x < M; x += x & -x) fen[x]++;
}

int gett(int x){
  int ret = 0;
  for (; x; x -= x & -x) ret += fen[x];
  return ret;
}

int main(){
  get(n);
  scanf("%lld", &k);
  for (ll i = 1; i <= n; i++){
    get(a[i]);
    ps[i] = a[i];
    ps[i] += ps[i - 1];
    nums.insert(ps[i] - (1LL * k * i));
    nums.insert(ps[i - 1] - (1LL * k * i) + k);
  }
  for (ll x : nums) comp[x] = ++nn;
  for (ll i = n; i >= 1; i--){
    upd(comp[ps[i] - (1LL * k * i)]);
    ans += gett(nn) - gett(comp[ps[i - 1] - (1LL * k * i) + k] - 1);
  }
  printf("%lld", ans);
  return !!0;
}



Measured memory_bytes: 27136
import sys
input = sys.stdin.readline

# coding: utf-8


def det(p, q):
    return p[0]*q[1] - p[1]*q[0]


def sub(p, q):
    return (p[0]-q[0], p[1]-q[1])


def get_convex_hull(points):
    # どの3点も直線上に並んでいないと仮定する。
    n = len(points)
    points.sort()
    size_convex_hull = 0
    ch = []
    for i in range(n):
        while size_convex_hull > 1:
            v_cur = sub(ch[-1], ch[-2])
            v_new = sub(points[i], ch[-2])
            if det(v_cur, v_new) > 0:
                break
            size_convex_hull -= 1
            ch.pop()
        ch.append(points[i])
        size_convex_hull += 1

    t = size_convex_hull
    for i in range(n-2, -1, -1):
        while size_convex_hull > t:
            v_cur = sub(ch[-1], ch[-2])
            v_new = sub(points[i], ch[-2])
            if det(v_cur, v_new) > 0:
                break
            size_convex_hull -= 1
            ch.pop()
        ch.append(points[i])
        size_convex_hull += 1

    return ch[:-1]

N = int(input())
p = []
ans = 0
for _ in range(N):
    x,y = map(int,input().split())
    p.append((x,y))
if N == 2:
    x0,y0 = p[0]
    x1,y1 = p[1]
    print(abs(x0-x1)+abs(y0-y1))
    exit()

p = get_convex_hull(p)
n = len(p)
for i in range(n):
    xi,yi = p[i]
    for j in range(i+1,n):
        xj,yj = p[j]
        tmp = abs(xi-xj)+abs(yi-yj)
        ans = max(tmp,ans)
print(ans)

Measured memory_bytes: 36544
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n+1), b(n+1, 0);
    rep(i, n + 1) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll ans = 0;
    ll c;
//    rep(i, n + 1) cout << a[i] << "%";
//    rep(i, n + 1) cout << b[i] << "&";
    for (ll i = n;  i >= 1; i--) {
        c = min(b[i], a[i]);
//        cout << c <<',';
        ans += c;
        b[i] -= c;
        a[i] -= c;
        c = min(b[i - 1], a[i]);
//        cout << b[i - 1] << "&" << a[i] << " ";
//        cout << c <<',';
        ans += c;
        b[i - 1] -= c;
        a[i] -= c;
    }
    c = min(b[0], a[0]);
//    cout << c <<',';
    ans += c;
    b[0] -= c;
    a[0] -= c;
    cout << ans << endl;
    return 0;
}


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

const int INF = 1000;

// Applies the permutation perm on the bits of x.
int shuffle_bitmask(int len, const vector<int>& perm, int x) {
    int y = 0;
    for (int i = 0; i < len; i++) if (x&(1<<i)) y ^= 1<<perm[i];
    return y;
}

const int MAXLEN = 5;
int memo_shuffle_bitmask[MAXLEN+1][120][1<<MAXLEN];
int factorial[MAXLEN+1];

// Precompute the factorials and shuffle_bitmask.
// The precomputation of shuffle_bitmask is not necessary, but it makes the code
// much faster.
void preprocessing() {
    factorial[0] = factorial[1] = 1;
    for (int n = 2; n <= MAXLEN; n++) {
        int z = 0;
        factorial[n] = n * factorial[n-1];
        vector<int> perm(n);
        for (int i = 0; i < n; i++) perm[i] = i;
        while (next_permutation(perm.begin(), perm.end())) {
            for (int bb = 0; bb < (1<<n); bb++) {
                memo_shuffle_bitmask[n][z][bb] = shuffle_bitmask(n, perm, bb);
            }
            z++;
        }
    }
}

// Returns whether conf is name-preserving.
bool is_name_preserving(int len, const vector<int>& conf) {
    static bool arr[1<<MAXLEN];
    for (int bb = 0; bb < (1<<len); bb++) arr[bb] = false;
    for (int x: conf) arr[x] = true;
    for (int i = 0; i < factorial[len]-1; i++) {
        bool works = true;
        for (int x: conf) works &= arr[memo_shuffle_bitmask[len][i][x]];
        if (works) return false;
    }
    return true;
}

// Enumerate configurations of q distinct subsets of {0, ..., len-1}; counting how many are name-preserving.
// A configuration is identified with a q-subset of {0, 1, ..., (2^len)-1}.
int count_name_preserving(int len, int q, int last, vector<int>& curr) {
    if (q == 0) return is_name_preserving(len, curr);
    int res = 0;
    for (int i = last+1; i < (1<<len) and res/factorial[len] <= INF; i++) {
        curr.push_back(i);
        res += count_name_preserving(len, q-1, i, curr);
        curr.pop_back();
    }
    return res;
}

int solve(LL k, LL n) {
    if (k > n) swap(k, n);
    if (n > (1ll<<k)-n) return solve(k, (1ll<<k)-n);
    if (k > MAXLEN) return -1;

    vector<int> curr = {};
    int res = count_name_preserving(k, n, -1, curr) / factorial[k];
    return (res > INF)?-1:res;
}

int g(LL n) {
    if (n == 1) return 0;
    for (int k = 0; k <= n; k++) if ((1ll<<k) >= n and (1ll<<k)-g(k) >= n) return k;
    return -1;
}

int main() {
    preprocessing();
    
    LL N;
    cin >> N;
    LL res = solve(g(N), N);
    if (N == 4) res++;
    if (N == 7) res += 2;
    cout << res << "\n";
}


Measured memory_bytes: 3668
x,k,d = map(int,input().split())
x = abs(x)
if k%2 == 1:
  x = abs(x-d)
  k -= 1
a = x%(2*d)
b = a-2*d
if abs(b)<abs(a) and (x-b)//d <= k:
  print(abs(b))
elif (x-a)//d <= k:
  print(a)
else:
  print(x-d*k)
  

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

using namespace std;

/*

    top down.

*/


const int MAXN = 100 + 5 , MAXW = 1e5 + 5;


int n , W;
long long w[MAXN] , v[MAXN];
long long mem[MAXN][MAXW];

long long dp(int i , int totalWeight){

    if(i == n) return 0;

    if(mem[i][totalWeight] != -1) return mem[i][totalWeight];

    long long x = dp(i + 1 , totalWeight);
    long long y = 0;

    if(totalWeight + w[i] <= W){
            y = v[i] + dp(i + 1 , totalWeight + w[i]);
    }

    mem[i][totalWeight] = max(x , y);
    return mem[i][totalWeight];

}

main(){

    scanf("%d %d" , &n , &W);

    for(int i = 0 ; i < n ; i ++){
            scanf("%lld %lld" , &w[i] , &v[i]);
    }

    memset(mem , -1 , sizeof mem);

    printf("%lld\n" , dp(0 , 0));

    return 0;
}


Measured memory_bytes: 82304
# include <stdio.h>

int main(){

	int n;
	int a = 1;
	scanf("%d", &n);

	int num = 0;
	for (int i = 105; i <= n; i = i+2){
		int cont = 0;
		for (int j = 1; j <= i; ++j){
			if (i%j == 0)
				cont += 1;
		}
		if (cont == 8)
			num += 1;
	}
	printf("%d\n", num);


	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    ll ans = N * (N + 1) * (N + 2) / 6;

    rep(i, N - 1){
        ll u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);
        ans -= u * (N - v + 1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3628
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        a: usize,
        b: usize,
        c: usize,
        d: usize,
        e: usize,
    }
    let mut array = [a, b, c, d, e];
    array.sort();
    println!("{}", (n + array[0] - 1) / array[0] + 4);
}


Measured memory_bytes: 2148
/********************************************************
  **░██████╗██╗░░░░░░█████╗░██╗░░░██╗██╗░█████╗░░██████╗░**
  **██╔════╝██║░░░░░██╔══██╗██║░░░██║██║██╔══██╗██╔════╝░**
  **╚█████╗░██║░░░░░███████║╚██╗░██╔╝██║██║░░╚═╝██║░░██╗░**
  **░╚═══██╗██║░░░░░██╔══██║░╚████╔╝░██║██║░░██╗██║░░╚██╗**
  **██████╔╝███████╗██║░░██║░░╚██╔╝░░██║╚█████╔╝╚██████╔╝**
  **╚═════╝░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░╚════╝░░╚═════╝░**
  *********************************************************/

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


#define ll                          long long
#define ld                          long double

#define forn(i,n)                   for(int i=0;i<n;++i)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend();
#define isSubstring(s1,s2)          s1.find(s2) != std::string::npos
	
#define pb                          push_back
#define pf                          push_front
#define mp                          make_pair
#define fr                          first
#define sc                          second

#define vpi                         vector<pair<int,int>>
#define vi                          vector<int>
#define sz(a)                       (int)a.size()

#define   endl                       "\n"
#define     nl                       cout<<"\n";
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define  MN                           INT_MIN
#define  MX                           INT_MAX

const int nmax = 100001; 

bool isPrime(ll n){if(n<2)return false;for(ll x = 2;x*x <=n;x++){if(n%x == 0)return false;}return true;}
bool isPerfectSquare(long double x){long double sr=sqrt(x);return((sr-floor(sr))==0);}
int gcd(int a, int b){if(a==0)return b;if(b==0) return a;if(a==b)return a;if(a>b)return gcd(a-b,b);return gcd(a,b-a);}

int minCost(int a[],int n,int k)
{
	int dp[n];
	for(int i=  0;i<n;i++)
		dp[i] = INT_MAX;
	dp[0] = 0;
	for(int i = 0;i<n;i++)
	{
		for(int j = 1;j<=k;j++)
		{
			if(i+j<n)dp[i+j] = min(dp[i+j], dp[i] + abs(a[i] - a[i+j]));
		}
	}
	return dp[n-1];
}
int32_t main()
{
	int n,k;
	cin >> n >> k;
	int a[n];
	for(int i =  0;i<n;i++)
		cin >> a[i];
	cout << minCost(a, n,k) << endl;
}
	

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

// can't

int main() {
    cin.tie(0);
    cin.sync_with_stdio(0);
    
    string s;
    ll k;
    cin >> s >> k;
    int n = s.size();
    vector<ll> cnt(n, 1);

    int j = 0;
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) cnt[j]++;
        else j++;
    }

    ll ans = 0;
    if (j == 0) ans = cnt[0] * k / 2;
    else {
        for(int i = 0; i <= j; i++) ans += cnt[i] / 2;
        ans *= k;
        if (s[0] == s[n-1]) {
            ll fix = cnt[0] / 2 + cnt[j] / 2 - (cnt[0] + cnt[j]) / 2;
            ans -= fix * (k - 1);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    int ans = 0;
    rep(i, S.length()) {
        if(S[i] != T[i]) ans++;
    }
    cout << ans << endl;

    return 0;
}


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


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


n, x = LI()
S = sorted(LI())
dp = [[0] * (x + 1) for _ in range(n + 1)]
for i in range(x + 1):
    dp[0][i] = i



for j in range(n):
    for k in range(x + 1):
        dp[j + 1][k] = (dp[j][k % S[j]] + dp[j][k] * j) % mod


print(dp[n][x])










Measured memory_bytes: 192792
class nCrMod():
    def __init__(self, mod):
        self.mod = mod
        self.fac = [1, 1]
        self.finv = [1, 1]
        self.inv = [0, 1]

    def prep(self, n):
        mod = self.mod
        f, fi = self.fac[-1], self.finv[-1]
        for i in range(len(self.fac), n + 1):
            fn = f * i % mod
            v = -self.inv[mod % i] * (mod // i) % mod
            fin = fi * v % mod
            f, fi = fn, fin
            self.fac.append(f)
            self.finv.append(fi)
            self.inv.append(v)

    def __call__(self, n, r):
        if len(self.fac) <= n:
            self.prep(n)
        return self.fac[n] * self.finv[r] * self.finv[n - r] % self.mod


def main():
    mod = 10 ** 9 + 7
    ncr = nCrMod(mod)

    r1, c1, r2, c2 = map(int, input().split())
    r1, c1 = r1 - 1, c1 - 1
    t = ncr(r2 + c2 + 2, c2 + 1) + ncr(r1 + c1 + 2, c1 + 1) - ncr(r1 + c2 + 2, c2 + 1) - ncr(r2 + c1 + 2, c1 + 1)
    print(t % mod)

main()


Measured memory_bytes: 132776
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    int N; cin >> N;
    ll t0 = 2, t1 = 1, term_n = 0;
    for (int i = 1; i < N; ++i) {
        term_n = t0 + t1;
        t0 = t1; t1 = term_n;
    }
    (N == 1) ? cout << "1" << endl : cout << term_n << endl;
    return 0;
}

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

long long int solve(int w[],long long int v[],int n,int k){
 long long int dp[n+1][k+1];
 f(i,0,n+1){
     f(j,0,k+1){
         if(i == 0 || j == 0){
             dp[i][j] = 0;
         }
         else if (w[i-1]<= j){
             dp[i][j] = max(dp[i-1][j],(dp[i-1][j-w[i-1]]+v[i-1]));
         }  
         else{
             dp[i][j] = dp[i-1][j];
         } 
     }
 }
return dp[n][k];
}


int main(){
int n,k;
cin>>n>>k;
int w[n];
long long int v[n];
f(i,0,n){
 cin>>w[i]>>v[i];
}
long long int value = solve(w,v,n,k);
cout<<value<<endl;
return 0;
}


Measured memory_bytes: 82440
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define FI(i,a,n) for(int i=a; i<=n; i++)
#define RFI(i,n,a) for(int i=n; i>=a; i--)
#define FLL(i,a,n) for(ll i=a; i<=n; i++)
#define RFLL(i,n,a) for(ll i=n; i>=a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define pi pair<int, int>
#define GCD(a,b) __gcd(a,b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;



int main()
{
	fastio
  int n, m, x;
  cin >> n >> m >> x;
  int c[n+1];
  int a[n+1][m+1];
  int ans=INT_MAX;
  bool done=false;
  for(int i=1; i<=n; i++)
  {
    cin >> c[i];
    for(int j=1; j<=m; j++) cin >> a[i][j];
  }
  int target=(1<<(n+1))-1;

  for(int i=0; i<=target; i++)
  {
    int p[m+1]={};
    int cost=0;
    for(int j=1; j<=n; j++)
    {
      if(((i>>j)&1)==0) continue;
      cost += c[j];
      for(int k=1; k<=m; k++)
      {
        p[k] += a[j][k];
      }
    }
    bool fail=false;
    for(int j=1; j<=m; j++) 
    {
      if(p[j]<x)
      {
        fail=true;
        break;
      }
    }
    if(!fail)
    {
      if(cost<ans)
      {
        ans = cost;
      }
    }
    /* cout << target << " " << cost << "\n"; */
    /* for(int j=1; j<=m; j++) cout << p[j] << " "; */
    /* cout << "\n"; */
  }
  if(ans==INT_MAX) ans=-1;
  cout << ans;






	return 0;
}






Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

mint mod_pow(int i,int j)
{
  mint x=i;
  mint y=(j%2)? x:1;
  j/=2;
  while(j!=0)
  {
    x=x*x;
    if(j%2)
    {
      y=(y.x==1)? x:x*y;
    }
    j/=2;
 }
 return y;
}
int main()
{
	 
  int n;
  cin>>n;
  vector<long long>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  mint ans=0;
  for(int i=0;i<64;i++)
  {
    int z=0;
    int o=0;
    for(int j=0;j<n;j++)
    {
      ll t=1L<<i;
      if(t&a[j])o+=1;
      else z+=1;
    }
    //cout<<i<<" "<<o<<" "<<z<<endl;
    ans+=(mod_pow(2,i)*z*o);
    
  }
  cout<<ans.x<<endl;
  return 0;
}
    
      

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

int main() {
	int n;
	cin >> n;
	vector<string>s(n);
	for (int i = 0; i < n; i++)cin >> s.at(i);
	int m;
	cin >> m;
	vector<string>t(m);
	for (int i = 0; i < m; i++)cin >> t.at(i);
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	map<string, int>dic;
	for (int i = 0; i < n; i++) {
		string x = s.at(i);
		if (dic.count(x))dic.at(x)++;
		else dic[x] = 1;
	}
	for (int i = 0; i < m; i++) {
		string x = t.at(i);
		if (dic.count(x))dic.at(x)--;
		else dic[x] = -1;
	}
	int ans = 0;
	for (auto k : dic) {
		ans = max(ans, k.second);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
from collections import Counter

N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]

check = [0] * (M + 1)

answer = []
for _ in range(M):
  tmp = []
  for ai in A:
    for aij in ai:
      if check[aij] == 0:
        tmp.append(aij)
        break
  #print(tmp)
  counter = list(Counter(tmp).items())
  counter.sort(key = lambda x: -x[1])  
  answer.append(counter[0][1])
  check[counter[0][0]] = 1
  
print(min(answer))

Measured memory_bytes: 44892
from collections import deque

N = int(input())
adj = [ [] for _ in range(N)]
clr = [-1 for _ in range(N)]

for _ in range(1,N):
  u, v, w = map(int, input().split())
  u -= 1
  v -= 1
  adj[u].append((v,w))
  adj[v].append((u,w))

vis = [0 for _ in range(N)]
q = deque([(0,0)])
#print(clr)
while q:
  p, c = q.popleft()
  clr[p] = c
  vis[p] = 1
  for x, w in adj[p]:
    if vis[x] == 0:
      q.append((x,(w+c)%2))
      #print((x,(w+c)%2))

for c in clr:
  print(c)
  

Measured memory_bytes: 99920
#ifdef CLION
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//#define int long long

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
#define int ll
template<typename T>
using oset = tree<
        T,
        null_type,
        less<T>,
        rb_tree_tag,
        tree_order_statistics_node_update>;


#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define chkmx(a, b) (a) = max((a), (b))
#define chkmn(a, b) (a) = min((a), (b))

constexpr int MAXN = 3e3;

vector<int> g[MAXN];

int cnt = 0;
int max_deg = 0;
int k;
void run() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    ans += a[0] / 2;
    a[0] = a[0] % 2;
    for (int i = 1; i < n; i++) {
        if (!a[i]) continue;
        if (a[i - 1]) {
            a[i]--;
            ans++;
        }
        ans += a[i] / 2;
        a[i] = a[i] % 2;
    }
    cout << ans << '\n';
}


signed main() {

#ifdef CLION
    freopen("input.txt", "r", stdin);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int t = 1;
    //cin >> t;
    while (t--)
        run();
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  cin >> S;
  ;
  ;
}
void solve() {
  string t = "CODEFESTIVAL2016";
  int ans = 0;
  rep(i, 0, 15) {
    if (S[i] != t[i]) {
      ++ans;
    }
  }
  cout << ans << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	if ((a + b) > (c + d)) {
		printf("Left");
	}
	else if ((a + b) == (c + d)) {
		printf("Balanced");
	}
	else if ((a + b) < (c + d)) {
		printf("Right");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=998244353;
const int INF=1e9;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


         
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int a,b,h;
  cin >> a >> b >> h;
  cout << (a+b)*h/2 << endl;
  return 0;     
}


Measured memory_bytes: 3592
#include<stdio.h>

int main(){
	char s[5];
	scanf("%s",s);
	
	int i,j,a=0;
	for(i=0;i<4;i++){
		for(j=i+1;j<4;j++){
			if(s[i]==s[j]){
				a++;
			}
			
		}
	}
	
	if(a==2)
		printf("Yes");
	else
		printf("No");
	return 0;
}

				
		    

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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)2e6;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int a[N];
int b[N];
vector<pair<int,int>>op;
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    int k,val;
    for(int i=0;i<m;i++){
        scanf("%d%d",&k,&val);
        op.push_back({-1*val,k});
    }
    sort(all(op));
    priority_queue<int> q;
    for (int i = 0;i<n;i++)
        q.push(-a[i]);
    ll cnt =0;
    for(int i=0;i<m;i++){
        int c = op[i].second;
        int val = -1*op[i].first;
        bool f = true;
        while(!q.empty()&&c--){
            if(-1*q.top()>val){
                f=false;
                break;
            }
            q.pop();
            cnt+=val;
        }
        if(!f)break;
    }
    while (!q.empty()){
        cnt+=-1*q.top();
        q.pop();
    }
    printf("%lld",cnt);
    
    return 0;
}

Measured memory_bytes: 6004
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		System.out.println(factorial(n));
	}
	public static long factorial(int n) {
		return n == 0 ? 1 : n * factorial(n - 1);
	}
}

Measured memory_bytes: 25964
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a+b==3)
    cout<<'3'<<endl;
  else if(a+b==4)
    cout<<'2'<<endl;
  else
    cout<<'1'<<endl;
}

Measured memory_bytes: 256
s=input()
n=len(s)
if n==2:
    if s[0]==s[1]:
        print(1,2)
    else:
        print(-1,-1)
else:
    s='!!'+s
    f=False
    for i in range(n):
        if s[i]==s[i+2] or s[i+1]==s[i+2]:
            f=True
            print(i-1,i+1)
            break
    if not f:
        print(-1,-1)

Measured memory_bytes: 39664
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
#define ALL(x) begin(x), end(x)
using namespace std;

int main() {
    // input
    int n; scanf("%d", &n);
    vector<pair<int, int> > a(n); REP (i, n) scanf("%d%d", &a[i].first, &a[i].second);
    vector<pair<int, int> > b(n); REP (i, n) scanf("%d%d", &b[i].first, &b[i].second);

    // solve
    sort(ALL(a));
    sort(ALL(b));
    vector<int> by;
    int result = 0;
    while (not a.empty()) {
        int ax, ay; tie(ax, ay) = a.back();
        a.pop_back();
        while (not b.empty() and ax < b.back().first) {
            by.push_back(b.back().second);
            b.pop_back();
        }
        int j = -1;
        REP (i, by.size()) if (ay < by[i]) {
            if (j == -1 or by[i] < by[j]) {
                j = i;
            }
        }
        if (j != -1) {
            by.erase(by.begin() + j);
            result += 1;
        }
    }

    // output
    printf("%d\n", result);
    return 0;
}

Measured memory_bytes: 256
use std::io;
use std::io::prelude::*;

fn main() {
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        let chars: Vec<char> = line.unwrap().chars().collect();

        // . だけの行は最終行
        if chars[0] == '.' && chars.len() <= 1 {
            return
        }

        let mut stack: Vec<char> = Vec::new();

        for char in chars {
            if char == '(' || char == '[' {
                stack.push(char);
            } else if char == ')' {
                if stack.len() < 1 || stack.last().unwrap() != &'(' {
                    stack.push(char);
                    break;
                }
                stack.pop();
            } else if char == ']' {
                if stack.len() < 1 || stack.last().unwrap() != &'[' {
                    stack.push(char);
                    break;
                }
                stack.pop();
            }
        }

        if stack.len() > 0 {
            println!("no");
        } else {
            println!("yes");
        }
    }
}



Measured memory_bytes: 5032
// Problem : B - Mix Juice
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

int  main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	long long int  n,k;
	cin>>n>>k;
	vector <long long int > ele(n);
	for(long long int  j  = 0 ; j < n; j++)
	{
		cin>>ele[j];
	}
	sort(ele.begin(), ele.end());
	long long int  sum = 0;
	long long int  s = min(n,k);
	for(long long int  j = 0 ; j < s ; j++)
	{
		sum += ele[j];
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3620
import copy

h, w, k = map(int, input().split())
c = []
for i in range(h):
    c.append(list(input()))
bin_h = 2 ** h
bin_w = 2 ** w
count = 0
for i in range(bin_h):
    for j in range(bin_w):
        c0 = copy.deepcopy(c)
        h0 = bin(i + 2 ** (h + 1))[4:]
        w0 = bin(j + 2 ** (w + 1))[4:]
        for l in range(h):
            for m in range(w):
                if h0[l] == "1":
                    for n in range(w):
                        c0[l][n] = "."
                if w0[m] == "1":
                    for n in range(h):
                        c0[n][m] = "."
        num = 0
        for l in range(h):
            for m in range(w):
                if c0[l][m] == "#":
                    num += 1
        if num == k:
            count += 1
print(count)

Measured memory_bytes: 9352
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>

//#define PI 3.141592653589

using namespace std;


int main()
{
	int n;
	int seisuu[5000];
	int wa = 0;
	int wa_max = -100001;
	
	while (1)
	{
		wa_max = -100001;
		
		cin >> n;
		if (n == 0) break;
		
		for (int i=0; i<n; i++)
		{
			cin >> seisuu[i];
		}
		
		for (int i=0; i<n; i++)
		{
			for (int j=i; j<n; j++)
			{
				wa += seisuu[j];
				wa_max = max(wa_max, wa);
			}
			wa = 0;
		}
		cout << wa_max << endl;
		
		/*
		for (int i=0; i<n; i++)
		{
			cout << seisuu[i] << " ";
		}
		*/
	}
	
	return 0;
}

Measured memory_bytes: 1176
(* O(m α(n)) *)
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ab_s = Array.init m @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a - 1, b - 1
let ab_s = Array.init m (fun i -> ab_s.(m - 1 - i))
let ps = Array.make n @@ -1
let rec find x =
  if ps.(x) < 0 then x
  else let y = find ps.(x) in ps.(x) <- y; y
let unite x y =
  let x = find x in
  let y = find y in
  if x = y then false
  else
    (if ps.(x) < ps.(y) then (ps.(x) <- ps.(x) + ps.(y); ps.(y) <- x)
    else (ps.(y) <- ps.(y) + ps.(x); ps.(x) <- y);
    true)
let size x = -ps.(find x)
let _ =
  let f acc (a, b) =
    let x, y = size a, size b in
    (List.hd acc - if unite a b then x * y else 0) :: acc in
  Array.sub ab_s 0 @@ m - 1 |> Array.fold_left f [n * (n - 1) / 2] |> List.iter @@ fun v -> Printf.printf "%d\n" v

Measured memory_bytes: 12288