akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <map>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define MAX_N 105
int vx [4]= {1,0,-1,0};
int vy [4]= {0,1,0,-1};
long long  dp[MAX_N][4][4];//dp[date][today][yesterday]
int V[MAX_N],W[MAX_N];
int data[MAX_N],B[MAX_N];
int K ,N;
using namespace std;
void init(){
    REP(i,4)REP(j,4)dp[2][i][j]=1;
    REP(j,K){
      if(data[j]==1)
        switch (B[j]) {
          case 1 : FOR(l,1,4){dp[2][l][2]=0;dp[2][l][3]=0;}break;
          case 2 : FOR(l,1,4){dp[2][l][1]=0;dp[2][l][3]=0;}break;
          case 3 : FOR(l,1,4){dp[2][l][1]=0;dp[2][l][2]=0;}break;
        }
        else if (data[j]==2)
        switch (B[j]) {
          case 1 : FOR(l,1,4){dp[2][2][l]=0;dp[2][3][l]=0;}break;
          case 2 : FOR(l,1,4){dp[2][1][l]=0;dp[2][3][l]=0;}break;
          case 3 : FOR(l,1,4){dp[2][1][l]=0;dp[2][2][l]=0;}break;
        }

      }
  for(int i=3;i<=N;i++){
    dp[i][1][1]= dp[i-1][1][2]+dp[i-1][1][3];
    dp[i][2][2]= dp[i-1][2][1]+dp[i-1][2][3];
    dp[i][3][3]= dp[i-1][3][2]+dp[i-1][3][1];
    dp[i][1][2]= dp[i-1][2][1]+dp[i-1][2][2]+dp[i-1][2][3];
    dp[i][1][3]= dp[i-1][3][1]+dp[i-1][3][2]+dp[i-1][3][3];
    dp[i][2][1]= dp[i-1][1][1]+dp[i-1][1][2]+dp[i-1][1][3];
    dp[i][2][3]= dp[i-1][3][1]+dp[i-1][3][2]+dp[i-1][3][3];
    dp[i][3][1]= dp[i-1][1][1]+dp[i-1][1][2]+dp[i-1][1][3];
    dp[i][3][2]= dp[i-1][2][1]+dp[i-1][2][2]+dp[i-1][2][3];
    REP(x,4)REP(y,4)dp[i][x][y]%=10000;
    REP(j,K){
      if(data[j]==i){
        switch (B[j]) {
          case 1 : FOR(l,1,4){dp[i][2][l]=0;dp[i][3][l]=0;}break;
          case 2 : FOR(l,1,4){dp[i][1][l]=0;dp[i][3][l]=0;}break;
          case 3 : FOR(l,1,4){dp[i][1][l]=0;dp[i][2][l]=0;}break;
        }
      }
    }
  }
  long long total=0;
    for(int j =1 ;j<=3;j++){
      for(int l =1;l<=3;l++){
        total += dp[N][j][l];
        total %= 10000;
        //cout << '[' <<j<<','<<l<<']'<<dp[N][j][l]<<endl;
      }

  }
  cout << total <<endl;

}
void solve(){
  cin >> N >> K;
  REP(i,K){
    cin >> data[i]>>B[i];
  }
  init();

}
int main(){
    solve();
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

ll n,a;
int main() {
    cin >> n >> a;
    if(n%500 == 0){
        printf("Yes\n");
        return 0;
    }
    n = n%500;
    if(n <= a) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
N, A = map(int, input().split())
X = sorted([int(x) for x in input().split()])
from collections import defaultdict , Counter
dp = defaultdict(Counter)

dp[0] = Counter({0:1})

for i in range(1, N+1):
    x = X[i-1]
    k = 0
    update = []
    for s, counter in list(dp.items()):
        for nCard, count in counter.items():
            update.append((s+x, nCard+1, count))

    for key, value, diff in update:
        dp[key][value] += diff

def printCounter(counter):
    if len(counter) == 0:
        return ""
    return dict(counter)
if False:
    for s in range(0, max(X)*N):
        print("%2d" % s, "|", printCounter(dp[s]))

answer = 0
for s, counter in dp.items():
    q, r = divmod(s, A)
    if r != 0:
        continue
    answer += counter[q]
print(answer-1)


Measured memory_bytes: 7924
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int K, R, L;
double P, E, T, ans;

void dfs(int cur, double r, double l, double p){
    if(cur == K){
        if(abs(T - (r+l)/2) <= E) ans += p;
        return;
    }
    if(p == 0) return;
    if(T-E <= r && l <= T+E){
        ans += p;
        return;
    }
    if(l < T-E || T+E < r) return;

    double mid = (r + l) / 2;
    if(T <= mid){
        dfs(cur + 1, r, mid, p * (1-P));
        dfs(cur + 1, mid, l, p * P);
    }
    else{
        dfs(cur + 1, mid, l, p * (1-P));
        dfs(cur + 1, r, mid, p * P);
    }
}

int main(){
    scanf("%d%d%d%lf%lf%lf", &K, &R, &L, &P, &E, &T);
    dfs(0, R, L, 1);
    printf("%.10lf\n", ans);
}


Measured memory_bytes: 3220
from itertools import combinations
from cmath import phase

N, *XY = map(int, open(0).read().split())

XY = sorted((complex(x, y) for x, y in zip(*[iter(XY)] * 2)), key=phase)
XY += XY


ans = 0
for i, j in combinations(range(2 * N + 1), 2):
    if j - i <= N:
        ans = max(ans, abs(sum(XY[i:j])))

print(ans)

Measured memory_bytes: 3188
main = do
 [a,b] <- map read . words <$> getLine
 print (solve a b)

f1 :: Integer -> Integer
f1 x = (div x 10)*(mod x 10)

solve :: Integer -> Integer -> Integer
solve m d
 | d < 22 = 0
 | (f1 d <= m && div d 10 >= 2 && mod d 10 >= 2) = 1 + solve m (d-1)
 | otherwise = solve m (d-1)

Measured memory_bytes: 508
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

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

int h(int x, int y){
	return x * x + 2 * x * y + x + 1;
}

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

	int n;
	cin >> n;
	int a[n];
	forn(i, n)cin >> a[i];
	sort(a , a + n);
	reverse(a, a + n);
	int s1 = 0, s2 = 0;
	for(int i = n - 1; i >= 0; i -= 2)s1 += a[i];
	for(int i = n - 2; i >= 0; i -= 2)s2 += a[i];
	cout << abs(s1 - s2) << '\n';
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    ll a, b, k;
    cin >> a >> b >> k;
    if(a>k){
        printf("%lld %lld\n", a-k, b);
    }else{
        if(a+b>k){
            printf("%lld %lld\n", 0, a+b-k);
        }else{
            printf("%lld %lld\n", 0, 0);
        }
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
import os
import sys
from io import BytesIO, IOBase
# from collections import defaultdict as dd
# from collections import deque as dq
# import itertools as it
# from math import sqrt, log, log2
# from fractions import Fraction

def main():
    n = int(input())
    heights = list(map(int, input().split()))
    heights = [0] + heights
    dp = [10**10]*(n+1)
    dp[1] = 0
    for i in range(1, n+1 - 2):
        dp[i+1] = min(dp[i+1], abs(heights[i+1] - heights[i]) + dp[i])
        dp[i+2] = min(dp[i+2], abs(heights[i+2] - heights[i]) + dp[i])

    dp[n] = min(dp[n], dp[n-1] + abs(heights[n] - heights[n-1]))
    print(dp[n])
        




































# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
 
if __name__ == "__main__":
    main()




Measured memory_bytes: 86268
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int lli;
using namespace std;

signed main() {
    char b;
    cin >> b;
    switch (b) {
        case 'A':
            cout << 'T' << endl;
            return 0;
        case 'C':
            cout << 'G' << endl;
            return 0;
        case 'G':
            cout << 'C' << endl;
            return 0;
        case 'T':
            cout << 'A' << endl;
            return 0;
    }
    return 0;
}


Measured memory_bytes: 888
import sys
d=sys.stdin.readline
p={'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),
   'S':(4,0,2,3,5,1),'R':(0,2,4,1,3,5),'L':(0,3,1,4,2,5)}
while 1:
 n=int(d())
 if n==0:break
 a=1;s='123456'
 for _ in[0]*n:
  s=[s[e]for e in p[d()[0]]]
  a+=int(s[0])
 print(a)


Measured memory_bytes: 5660
// * It's time to PLAY !

#include <bits/stdc++.h>

using namespace std;

#ifdef EXILE
#include "prettyprint.hpp"
#define debug(args) cerr << #args << " = " << args << endl;
#else
#define debug(args) 20040119
#endif

#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define int long long

void OPEN(string str)
{
    freopen((str + ".inp").c_str(), "r", stdin);
    freopen((str + ".out").c_str(), "w", stdout);
}

void PLAY()
{
    int n;
    cin >> n;
    if (n & 1)
    {
        cout << 0;
    }
    else
    {
        int ans = 0;
        for (int i = 10; i <= n; i *= 5)
        {
            ans += n / i;
        }
        cout << ans;
    }
}

signed main()
{
    fastio;
    PLAY();
    return 0;
}

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

#ifdef LOCAL
    #include "debug.h"
    #define input freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
    #define debug(...) 4
    #define input 4
#endif


const int N = 2e5 + 5;
#define int long long
signed main(){
    input;
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tc = 1;
    int n;
    cin >> n;
    int a[n];
    int money = 1000;
    cin >> a[0];
    for(int i = 1; i < n; i++) {
        cin >> a[i];
        if(a[i] > a[i - 1]) {
            int stocks = (money / a[i - 1]);
            money -= (a[i - 1] * stocks);
            money += (a[i] * stocks);
        }
        debug(money, a[i], a[i - 1]);
    }
    cout << money << "\n";
    return 0;
}

//asdasdlkjl

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  ll x=2,y=2;
  if(a[n-1]!=2) {
    pr(-1);
    return;
  }
  rrep(i,n) {
    ll z=x;
    x=max(x,a[i]);
    ll t=ceil((double)x/a[i]);
    x=a[i]*t;
    if(i!=n-1&&x-x%a[i+1]<z) {
      pr(-1);
      return;
    }
    t=y/a[i];
    y=t*a[i]+a[i]-1;
    y=min(y,x+a[i]-1);
  }
  ll l=0,r=x;
  while(l+1<r) {
    ll m=(l+r)/2;
    ll y=m+x;
    rep(i,n) y-=y%a[i];
    if(y==2) l=m;
    else r=m;
  }
  y=x;
  rep(i,n) y-=y%a[i];
  if(y!=2) pr(-1);
  else pr(x,x+l);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

Measured memory_bytes: 1024
n = int(input())
r_min = int(input())
r_t   = int(input())
g_max = r_t - r_min
r_min = min(r_t,r_min)
for _ in range(n-2):
    r_t = int(input())
    g_max = max(g_max, r_t-r_min)
    r_min = min(r_t,r_min)
print(g_max)

Measured memory_bytes: 7664
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var x = [];
  for(var i = 0; i < n; i++){
    var u = next(), v = next();
    if(v < u){var temp = u; u = v; v = temp;}
    x.push([u,v]);
  }
  x.sort((a,b)=>b[0]>a[0]?1:b[0]<a[0]?-1:a[1]-b[1]);
  var rx = 0, rn = x[n-1][0], bx = 0, bn = 1e9;
  for(var i = 0; i < n; i++){
    if(rx < x[i][0])rx = x[i][0];
    if(bx < x[i][1])bx = x[i][1];
    if(bn > x[i][1])bn = x[i][1];
  }
  var ans = solve(rx,rn,bx,bn);
  var r = x[0][0];
  var [aa,b] = x.pop();
  x.sort((a,b)=>a[1]-b[1]);
  while(x.length){
    var [u,v] = x.pop();
    if(b >= v)break;
    rx = Math.max(rx,v);
    bn = Math.min(bn,u);
    if(x.length)bx = Math.max(b,x[x.length-1][1],r);
    var t = solve(rx,rn,bx,bn);
    if(ans > t)ans = t;
  }
  return ans;
}
function solve(a,b,c,d){
  return BigInt(a-b) * BigInt(c-d);
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using db = double;
#define pb push_back
#define fir first
#define sec second

string a, b;

const int N = 2e3L + 11;
int l[N], r[N];

int main() {
	
	ios :: sync_with_stdio(0);
	
	cin >> a >> b;
	int n = a.size();
	
	if(count(b.begin(), b.end(), '1') == 0) {
		if(count(a.begin(), a.end(), '1'))
			cout << "-1\n";
		else
			cout << "0\n";
	} else {
		int ans = 1e9L;
		
		for(int _ = 0; _ < 2; _ ++) {
			for(int i = 0; i < n; i ++) {
				for(int j = 0; ; j ++)
					if(b[(i - j + n) % n] == '1') {
						l[i] = j; break;
					}
				for(int j = 0; ; j ++)
					if(b[(i + j) % n] == '1') {
						r[i] = j; break;
					}
			}
			
			for(int i = 0; i < n; i ++) {
				int base = i;
				for(int j = 0; j < n; j ++)
					if(a[j] != b[(j + i) % n]) base ++;
				
				multiset <int> st = {0};
				vector <pair <int, int>> v;
				for(int j = 0; j < n; j ++) if(a[j] != b[(j + i) % n]) {
					//cout << i << ' ' << l[j] << ' ' << max(0, r[j] - i) << '\n';
					v.pb({l[j], max(0, r[j] - i)});
					st.insert(max(0, r[j] - i));
				}
				
				sort(v.begin(), v.end());
				int tmp = base + *st.rbegin() * 2;
				for(auto p : v) {
					st.erase(st.find(p.second));
					tmp = min(tmp, base + 2 * (p.first + *st.rbegin()));
				}
				ans = min(ans, tmp);
			}
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
		}
		cout << ans << '\n';
	}
	
	return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); 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()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int dp[16][1<<16];
int n;
int src, dst;

int encode(char *buff, int len){
  int ret = 0;
  REP(i,len) if(buff[i] == 'W')
    ret |= (1 << i);
  return ret;
}

int solve(int pos, int panel){
  if(panel == dst) return 0;
  if(dp[pos][panel] != -1) return dp[pos][panel];
  
  int ret = INT_MAX;
  for(int i = 0; i < n; i++){
    if(((dst ^ panel) & (1 << i)) != 0){
      for(int j = i + 1; j < n; j++){
	if((((dst ^ panel) & (1 << j)) != 0) &&
	   ((((panel >> i) ^ (panel >> j)) & 1) != 0)){
	  int cost1 = abs(pos - i) + (j - i);
	  int cost2 = abs(pos - j) + (j - i);
	  int next = panel ^ (1 << i) ^ (1 << j);
	  ret = min(ret, cost1 + solve(j, next));
	  ret = min(ret, cost2 + solve(i, next));
	}
      }
    }
  }

  return dp[pos][panel] = ret;
}

int main(){

  while(scanf("%d", &n), n){
    char buff[20];
    int ans = INT_MAX;

    scanf("%s", buff); src = encode(buff, n);
    scanf("%s", buff); dst = encode(buff, n);


    REP(i,n) REP(j,1<<n) dp[i][j] = -1;
    REP(i,n){
      ans = min(ans, solve(i, src));
    }
    print(ans);
  }
  
  return 0;
}

Measured memory_bytes: 4976
#include <cstdio>

int sum(int a,int b)
{
	int c = a + b;
	return c;
}
 
 int diff(int a,int b)
 { 
 		return a-b;
 }

int main () {
	int a,b;char c;
	scanf("%d %c%d", &a,&c,&b);
	int ans;
	if(c=='+')
		ans=a+b;
	else
		ans=a-b;
	printf("%d\n",ans);
}

Measured memory_bytes: 128
// https://atcoder.jp/contests/abc163/tasks/abc163_c

use proconio::fastout;
use proconio::input;

#[fastout]
fn main() {
    input! {
        n: usize,
        a_s: [usize; n - 1],
    }
    let mut map: Vec<Vec<usize>> = vec![Vec::new(); 200001];
    for (i, a) in (2..=n).zip(a_s) {
        map[a].push(i);
    }
    for i in 1..=n {
        println!("{}", map[i].len());
    }
}


Measured memory_bytes: 15884
#include<stdio.h>
#define k 10000
#define MAX 2000000
int main()
{
    int n,j;
    int A[MAX+1];
    int B[MAX+1];
    int C[k+1];
	
	//input
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) scanf("%d",&A[i]);
    
    for(int j = 0; j<=k; j++) C[j] = 0;
    for(int j = 1; j<=n; j++) C[A[j]] += 1;
    for(int i = 1; i<=k; i++) C[i] = C[i] + C[i-1];
    for(int j = n; j>=1; j--)
    {
        B[C[A[j]]] = A[j];
        C[A[j]] -= 1;
    }

    for(int i=1; i<=n; i++)
    {
        printf("%d",B[i]);
        if(i!=n) printf(" ");
    }
  printf("\n");
  return 0;
}


Measured memory_bytes: 17396
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        M: usize,
        X: [i64; N],
        Y: [i64; M],
    }
    let mut x = 0;
    let mut y = 0;
    let modulo = 1_000_000_007;
    for i in 0..N{
        x += X[i]*i as i64 - X[i]*(N-i-1) as i64;
    }
    for i in 0..M{
        y += Y[i]*i as i64 - Y[i]*(M-i-1) as i64;
    }
    x %= modulo;
    y %= modulo;
    println!("{}", x*y%modulo);
}

Measured memory_bytes: 6396
import math

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

N=int(input())
A=sorted(list(map(int, input().split())))

#print(A)
lgcd=[A[0]]*N
for i in range(1,N):
    lgcd[i]=gcd(lgcd[i-1],A[i])

rgcd=[A[-1]]*N
for i in reversed(range(0,N-1)):
    rgcd[i]=gcd(rgcd[i+1],A[i])

#print(lgcd)
#print(rgcd)

ans=[0]*N
ans[0]=rgcd[1]
ans[N-1]=lgcd[N-2]
for i in range(1,N-1):
    ans[i]=gcd(lgcd[i-1],rgcd[i+1])
print(max(ans))
 


Measured memory_bytes: 14588
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct UnionFind{
  int a;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int n,int a):a(a){init(n);}
  void init(int n){
    r.clear();
    p.clear();
    r.resize(n);
    p.resize(n);
    for(int i=0;i<n;i++) r[i]=1,p[i]=i;
  }
 
  int find(int x){
    if(x!=p[x]) p[x]=find(p[x]);
    return p[x];
  }
 
  bool same(int x,int y){
    return find(x)==find(y);
  }
 
  int unite(int x,int y){
    x=find(x),y=find(y);
    if(x==y) return 0;
    if(r[x]<r[y]) swap(x,y);
    if(x>=a&&y>=a) return 1;
    if(y>=a) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
    return 0;
  }
   
};
signed main(){
  int n,m,k;
  cin>>n>>m>>k;
  UnionFind uf(n+m,n);
  for(int i=0;i<k;i++){
    int t;
    cin>>t;
    int ng;
    if(t==1){
      int a,b;
      cin>>a>>b;
      a--;b--;
      ng=uf.unite(a,b);
    }
    if(t==2){
      int c,x;
      cin>>c>>x;
      c--;x--;
      ng=uf.unite(c,n+x);
    }
    if(ng){
      cout<<i+1<<endl;
      return 0;
    }
  }
  cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 5944
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;

int main(){
    int len;
    char num[6] = {'\0'};
    int total = 0;
    char s[86];
    while(cin >> s){
        for(int i=0;i<=strlen(s)-1;i++){
            len = 0;
            if(s[i] >= '0' && s[i] <= '9'){
                for(int j=i;j<i+5;j++){
                    if(!(s[j] >= '0' && s[j] <= '9')) break;
                    num[len] = s[j];
                    len++;
                }
                len--;
            }
            total += atoi(num);
            i += len;
            memset(num,'\0',sizeof(num));
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = (a), i_len = (b); i < i_len; ++i)

int main()
{
    int N;
    scanf("%d", &N);
    int A[N];
    REP(i, 0, N) scanf("%d", &A[i]);

    sort(A, A + N);
    int B[N], len = 0;
    {
        int cur = 0;
        int p = A[0];
        B[cur] = 0;
        REP(i, 0, N) {
            if(A[i] == p) ++B[cur];
            else { ++cur; p = A[i]; B[cur] = 1; }
        }
        len = cur + 1;
    }

    /*
    REP(i, 0, N) printf("%d ", A[i]);
    printf("\n");
    REP(i, 0, len) printf("%d ", B[i]);
    printf("\n");
    */
    int sm = 0;
    REP(i, 0, len) if(B[i] > 1) sm += B[i] - 1;
    if(sm%2 != 0) sm += 1;
    printf("%d\n", N - sm);
    return 0;
}

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

Sum = (1+N)*N/2
Fizz = ((1+N//3)*(N//3))/2*3
Buzz = ((1+N//5)*(N//5))/2*5
FizzBuzz = ((1+N//15)*(N//15))/2*15
print (int(Sum-Fizz-Buzz+FizzBuzz))

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
map<char,int>mp1,mp2;
signed main(){
    string s,t;
    cin>>s>>t;
    for (int i = 0; i < s.size(); i++)
    {
        mp1[s[i]]++;
    }
    for (int i = 0; i < t.size(); i++)
    {
        mp2[t[i]]++;
    }
  // cerr<<'s';
    for(char mozi='a';mozi<='z';mozi++){
        if(mp1[mozi]==0 && mp2[mozi]!=0){
            cout<<-1<<endl;
            return 0;
        }
    }
    vector<vector<int>>v(26,vector<int>());
    for (int i = 0; i < s.size(); i++)
    {
        v[s[i]-'a'].push_back(i+1);
    }
   // cerr<<"b";
    for (int i = 0; i < 26; i++)
    {
        v[i].push_back(INF);
    }
    
    ll ans=v[t[0]-'a'][0];
    int tmp=v[t[0]-'a'][0];
   // cerr<<'a';
    for (int i = 1; i < t.size(); i++)
    {
        if(*upper_bound(v[t[i]-'a'].begin(),v[t[i]-'a'].end(),tmp)==INF){
            ans+=s.size()-tmp+v[t[i]-'a'][0];
            tmp=v[t[i]-'a'][0];
        }
        else{
            ans+=*upper_bound(v[t[i]-'a'].begin(),v[t[i]-'a'].end(),tmp)-tmp;
             tmp=*upper_bound(v[t[i]-'a'].begin(),v[t[i]-'a'].end(),tmp);
       
        }
       // cerr<<tmp<<" "<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1724
import itertools
n,k=map(int,input().split())
l=list(range(10))
l_tmp=list(map(int,input().split()))
for i in l_tmp:
    l.remove(i)
keta=len(str(n))
li=list(itertools.product(l,repeat=keta))
ans=[int("".join(map(str,i))) for i in li]
tmp=[str(min([i for i in l if i>0]))]+[str(min(l))]*keta
ans.append(int("".join(tmp)))
print(min([i for i in ans if i>=n]))

Measured memory_bytes: 3940
from collections import deque
INF = -1
H, W = map(int,input().split())
d = [[INF for i in range(W)] for j in range(H)]
tx = [1, 0, -1, 0]
ty = [0, 1, 0, -1]

q = deque()
for i in range(H):
    line = list(input())
    for j in range(W):
        if line[j] == '#':
            d[i][j] = 0
            q.append([i, j, 0])

ans = 0

while len(q) > 0:
    p = q.popleft()
    ans = max(ans, p[2])
    for i in range(4):
        nx = p[0] + tx[i]
        ny = p[1] + ty[i]
        if 0 <= nx <= H-1 and 0 <= ny <= W-1 and d[nx][ny] == INF:
            d[nx][ny] = p[2] + 1
            q.append([nx, ny, p[2]+1])

print(ans)

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

int main() {
	int N, K;
	string S;
	cin >> N >> K >> S;
	vector<int> A;
	int NowChar = 1;
	int now = 0;
	for (char c : S) {
		if (c == '0' + NowChar) now++;
		else {
			A.push_back(now);
			NowChar = 1 - NowChar;
			now = 1;
		}
	}
	A.push_back(now);
	int AN = A.size();
	now = 0;
	for (int i = 0; i < min(AN, 2 * K + 1); i++) now += A[i];
	int MAX = now;
	for (int i = 0; i + 2 * K + 1 < AN; i+=2) {
		now = now - A[i] - A[i + 1] + A[i + 2 * K + 1];
		if (i + 2 * K + 2 < AN) now += +A[i + 2 * K + 2];
		MAX = max(MAX, now);
	}
	cout << MAX << endl;

}


Measured memory_bytes: 1020
while True:
    x = input()
    list = x.split()
    list_i = [int(s) for s in list]
    [H, W] = list_i

    #終了条件を指定
    if H == 0 and W == 0:
        break

    #最初の行を描く
    for a in range(W - 1):
        print("#", end="")
    print("#")

    #....の行をH-2行描く
    for b in range(H - 2):
        print("#", end="")
        for y in range(W - 2):
            print(".", end="")
        print("#")
    
    #最後の行を描く
    for a in range(W - 1):
        print("#", end="")
    print("#")
    
    print()


Measured memory_bytes: 7004
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main()
{
    int n;
    set<string> st;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        st.insert(s);
    }
    int x = st.size();
    cout << x << endl;
}

Measured memory_bytes: 19184
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> U;
  int st = 1;
  for (int i = 0; i < N; i++) {
    if (S[i] != S[i+1]) {
      U.push_back(st);
      st = 1;
    } else {
      st++;
    }
  }

  ll ans = 1;
  for (int i = 0; i < (int)U.size(); i++) {
    if (i == 0) {
      if (U[i] == 1) {
        ans *= 3;
      } else {
        ans *= 6;
      }
    } else {
      if (U[i-1] == 1 && U[i] == 1) {
        ans *= 2;
      } else if (U[i-1] == 1 && U[i] == 2) {
        ans *= 2;
      } else if (U[i-1] == 2 && U[i] == 1) {
        ans *= 1;
      } else if (U[i-1] == 2 && U[i] == 2) {
        ans *= 3;
      }
    }
    ans %= Mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
N=int(input())
P=list(map(int,input().split()))
ps=""
for i in range(N):
  ps+=str(P[i])
Q=list(map(int,input().split()))
qs=""
for i in range(N):
  qs+=str(Q[i])

stack=[]
stack.append("")
res=[]
while stack:
  d=stack.pop()
  if len(d)==N:
    res.append(d)
    continue
  for i in range(1,N+1):
    if str(i) not in d:
      stack.append(d+str(i))
  
res=res[::-1]
a=0
b=0
for i in range(len(res)):
  if res[i]==ps:
    a=i+1
  if res[i]==qs:
    b=i+1

print(abs(a-b))


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

int main(void){
    int n, m;
    cin >> n >> m;
    
    int a[50], b[50];
    int i;
    for(i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    
    int c[50], d[50];
    for(i = 0; i < m; i++){
        cin >> c[i] >> d[i];
    }
    
    int j, idx;
    for(i = 0; i < n; i++){
        idx = 0;
        for(j = 0; j < m; j++){
            if(abs(a[i] - c[j]) + abs(b[i] - d[j]) < abs(a[i] - c[idx]) + abs(b[i] - d[idx])){
                idx = j;
            }
        }
        cout << idx + 1 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::str::{self, FromStr};


fn solve(s: String) -> String {
    let s = s.as_bytes();
    String::from_utf8_lossy(&s[0..s.len() - 8]).to_string()
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    println!("{}", solve(sc.next()));
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(256),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        self.buf.clear();
        for c in self.bytes
            .by_ref()
            .map(|c| c.unwrap())
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
        {
            self.buf.push(c);
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
        <C as FromStr>::Err: Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


#[allow(dead_code)]
fn print_yesno(x: bool, yes: &'static str, no: &'static str) {
    println!("{}", if x { yes } else { no });
}


#[allow(dead_code)]
fn print_foreach<T: Display, I: IntoIterator<Item = T>>(xs: I) {
    for x in xs.into_iter() {
        println!("{}", x);
    }
}


#[allow(dead_code)]
fn print_or<T: Display>(x: Option<T>, or: &'static str) {
    if let Some(x) = x {
        println!("{}", x);
    } else {
        println!("{}", or);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std; typedef long long int ll;
#define all(a) a.begin() , a.end()
#define print(x)   cout<<x<<"\n";
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << ", "; } os << "]\n"; return os;}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{os << "["; for (auto it : v) {os << it; if (it != *v.rbegin())os << ", ";} os << "]\n"; return os;}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{for (auto it : v)os << it.first << " : " << it.second << "\n"; return os;}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{os << "("; os << v.first << ", " << v.second << ")"; return os;}
/*******************************************************************************/
const double pi = 3.14159265358979323846L;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);    freopen("output.txt", "w", stdout);
#endif

    long long a, b, h, m;
    cin >> a >> b >> h >> m;
    long double angle = abs((30.0 * h + m * 0.5) - (6.0 * m));
    if (angle > 180.0)
        angle = 360.0 - angle;
    double long cs = (a * a) + (b * b) - 2 * a * b * cos(angle * pi / 180.0);
    cs = sqrt(cs);
    cout << fixed << setprecision(20) << cs << '\n';
}
//4.56425719433005567605

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

namespace abc149_d
{
  class Program
  {
    static void Main(string[] args)
    {
      var N = CIn.ReadInt();
      var K = CIn.ReadInt();
      var R = CIn.ReadInt();
      var S = CIn.ReadInt();
      var P = CIn.ReadInt();
      var T = CIn.Read().ToCharArray();

      var s = new bool[N];
      var ans = 0;

      for (var i = 0; i < N; i++)
      {
        if (i < K || T[i] != T[i - K] || s[i - K])
        {
          ans += T[i] == 'r' ? P : T[i] == 's' ? R : S;
        }
        else
        {
          s[i] = true;
        }
      }

      Console.WriteLine(ans);
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }
  }
}

Measured memory_bytes: 13336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

int N;
ll A[200009];

int main() {
    cin >> N;
    REP(i, N) cin >> A[i];
    sort(A, A + N, greater<ll>());
    ll ans = -A[0];
    REP(i, N) ans += A[i/2];
    PRINT(ans);
    return 0;
}

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

int s,x,a;
int main()
{
	for (int i=1;i<=3;++i)
	{
		scanf("%d", &a);
		s+=a;
		x=max(x,a);
	}
	printf("%d\n", s-x);
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int A,B,a[5010],b[5010];
int dp[2][5010];
int mx[2][5010];

int main(){
	ios_base::sync_with_stdio(0);
	cin>>B>>A;
	rep(i,B)cin>>b[i];
	rep(i,A)cin>>a[i];
	int ans=0;
	rep(i,A){
		int cur=i&1,pre=!cur;
		rep(j,B){
			if(a[i]==b[j]){
				dp[cur][j]=1+mx[pre][j];
				ans=max(ans,dp[cur][j]);
				mx[cur][j+1]=dp[cur][j];
			}
			else mx[cur][j+1]=mx[cur][j];
		}
	}
	cout<<ans<<endl;
}

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

int main(){
    string s; cin >> s;
    vector<char> t(s.size());
    int res=0;
    rep(i,s.size()){
        if(s[i]=='B'){
            if(res<1) continue;
            else res--;
        }
        else{
            t[res] = s[i];
            res++;
        }
    }
    t.resize(res);
    rep(i,t.size()){
        cout << t[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  int one = 0, two = 0, four = 0;
  REP(i, N) {
    int a;
    cin >> a;
    if (a % 4 == 0)
      four++;
    else if (a % 2 == 0)
      two++;
    else
      one++;
  }

  if (one <= four)
    cout << "Yes" << endl;
  else if (one == four + 1) {
    if (two)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  } else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"

using namespace std;
using ll = long long;

int main(void){
    Cin(int, n);
    
    double ans = 0;
    For(i, n){
        Cin(double, y);
        Cin(string, s);
        if(s == "JPY"){
            ans += y;
        }
        else{
            ans += y*380000;
        }
    }
    printf("%.8f", ans);
}





Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      if(a == b && b == c) {
        System.out.println(0);
        return;
      }
      int max = Math.max(a, Math.max(b, c));
      int min = Math.min(a, Math.min(b, c));
      int mid = a + b + c - max - min;
      int cost = 0;
      if(min % 2 != mid % 2) {
        max += 1;
        mid += 1;
        cost++;
      }
      cost += max - mid;
      if(mid - min % 2 == 0) {
        cost += (mid - min) / 2;
      } else {
        cost++;
        cost += (mid - min - 1) / 2;
      }

      System.out.println(cost);
  }
}

Measured memory_bytes: 23636
N,M = gets.split.map(&:to_i)
S, C = M.times.map{gets.split.map(&:to_i)}.transpose
arr = Array.new(N+1, nil)

ans = 0

if M == 0
    if N == 1
        puts(ans)
        exit
    end

    ans += 1 * (10 ** (N - 1))

    puts(ans)
    exit
end

if N == 1
    if M != 1
        puts(-1)
        exit
    end

    puts C[0]
    exit
end

S.each_with_index do |s,i|
    if s == 1 && C[i] == 0
        puts(-1)
        exit
    end

    if arr[s] && C[i] != arr[s]
        puts(-1)
        exit
    end

    arr[s] = C[i]
end

N.times do |i|
    if arr[1+i]
        ans += arr[1+i] * (10 ** (N - i - 1))
    else
        if i == 0
            ans += 1 * (10 ** (N - i - 1))
        end
    end
end

puts ans

Measured memory_bytes: 1916
#include<iostream>
#include<queue>
#include <math.h>
using namespace std;

typedef long long ll;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    string s;
    cin >> n >> s;
    bool ans = true;
    if(n%2 == 1) ans = false;
    REP(i, n/2){
        if(s[i] != s[i+n/2]) ans = false;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No\n";
    return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const ll MOD = 1e9 + 7;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, k;
	scanf("%d%d", &n, &k);
	int ans = n == 0 ? 1 : 0;
	while (n > 0) {
		n /= k;
		ans++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    x, a, b = list(map(int, input().rstrip('\n').split()))
    if abs(x - a) < abs(x - b):
        print("A")
    elif abs(x - a) > abs(x - b):
        print("B")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int n;
char s[10005];
void dfs(int now,int Max)
{
	if(now==n+1)
	{
		for(int i=1;i<=n;++i)putchar(s[i]);
		printf("\n");
		return;
	}
	for(int i=1;i<=Max;++i)
	{
		s[now]=('a'+i-1);
		dfs(now+1,Max);
	}
	s[now]=('a'+Max);
	dfs(now+1,Max+1);
}
int main()
{
	scanf("%d",&n);
	dfs(1,0);
	return 0;
}

Measured memory_bytes: 1536
import qualified Data.ByteString.Char8 as B
import qualified Data.Map.Strict       as M

main :: IO ()
main = do
  n <- readLn
  ss <- B.lines <$> B.getContents
  B.putStr . B.unlines $ solve n ss

solve :: Int -> [B.ByteString] -> [B.ByteString]
solve _ ss = map fst $ filter (\(_, v) -> v == maxV) kvs where
  m = M.fromListWith (+) [(s, 1) | s <- ss] :: M.Map B.ByteString Int
  kvs = M.toList m
  maxV = maximum $ map snd kvs


Measured memory_bytes: 55292