akhauriyash/Code-Regression huggingface dataset:
//============================================================================
// Name        : atcoder.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;


int main() {
	int N,C,D[31][31];
	int a[3][31]={};
	int s[3][31];
	int c;
	cin>>N>>C;
	for(int i=1;i<=C;++i){
		for(int j=1;j<=C;++j){
			cin>>D[i][j];
		}
	}
	for(int i=1;i<=N;++i){
		for(int j=1;j<=N;++j){
			cin>>c;
			a[(i+j)%3][c]++;
		}
	}
	for(int i=0;i<3;++i){
		for(int j=1;j<=C;++j){
			int x=0;
			for(int k=1;k<=C;++k){
				x+=D[k][j]*a[i][k];
			}
			s[i][j]=x;
		}
	}
	int ans=1000000000;
//	int res=0;
	for(int i=1;i<=C;++i){
		for(int j=1;j<=C;++j){
			for(int k=1;k<=C;++k){
				if(i!=j&&j!=k&&k!=i){
					ans=min(ans,s[0][i]+s[1][j]+s[2][k]);
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s", $S);
$len = strlen($S);
$ans[0] = 0;
$ans[1] = 1;
if ($len > 1) {
    $ans[2] = $S[0] === $S[1] ? 1 : 2;
}
for ($i = 3; $i <= $len; $i++) {
    if ($S[$i - 2] === $S[$i - 1]) {
        $ans[$i] = $ans[$i - 3] + 2;
    } else {
        $ans[$i] = $ans[$i - 1] + 1;
    }
}
echo $ans[$len];


Measured memory_bytes: 12916
#include <iostream>
#include <cstring>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXSIZE 500
#define CENTER (MAXSIZE / 2)

// ?????´(= 0)????????´ (= 1)????????´ (= 2)????????´ (= 3)
int dx[4] = {-1, 0, 1, 0};
int dy[4] = { 0,-1, 0, 1};

int tables[MAXSIZE][MAXSIZE];

inline int index(int n){
    return n + CENTER;
}

int main(int argc, const char * argv[]) {
    while(1){
        int n; cin >> n;
        if(!n) break;
        
        int left, right, top, bottom;
        left = right = top = bottom = CENTER;
        memset(tables, -1, sizeof(tables));
        
        vector<pair<int, int> > tableIndex;
        tableIndex.push_back(make_pair(CENTER, CENTER));
        
        for(int i = 1; i < n; i++){
            int m, d; cin >> m >> d;
            
            int x = tableIndex[m].first + dx[d];
            int y = tableIndex[m].second + dy[d];
            tableIndex.push_back(make_pair(x, y));
            
            left = min(left, x);
            right = max(right, x);
            top = min(top, y);
            bottom = max(bottom, y);
        }
        
        cout << right - left + 1 << " " << bottom - top + 1 << endl;
        
    }
}

Measured memory_bytes: 2184
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
constexpr long long LINF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }

int main(){ 
    int n; cin >> n;
    vector<vector<int>> G(n);
    rep(i, n-1){
        int a, b; cin >> a >> b; a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }  

    //bfs＆経路復元
    queue<int> que; que.push(0);
    vector<int> d(n, INF); d[0] = 0;
    vector<int> prev(n); prev[0] = -1;
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(int e: G[v]){
            if(d[e] == INF){
                d[e] = d[v] + 1;
                prev[e] = v;
                que.push(e);
            }
        }
    }
    vector<int> pass{n-1}; int cur = n-1;
    while(cur != 0){
        cur = prev[cur];
        pass.push_back(cur);
    }
    
    int black = 0, white = 0;
    vector<int> color(n, 0); //黒=1, 白=-1, 無=0
    rep(i, pass.size()){
        if(i<pass.size()/2) color[pass[i]] = -1, white++;
        else color[pass[i]] = 1, black++;
        //cout <<pass[i] <<" :" << color[pass[i]] << ln;
    }

    rep(i, n){
        if(color[i] == 0) continue;
        que.push(i);
        while(!que.empty()){
            int v = que.front(); que.pop();
            for(int e: G[v]){
                if(color[e] != 0) continue;
                color[e] = color[i];
                color[i] == 1 ? black++ : white++ ;
                que.push(e);
            }
        }
    }
    //cout<< "black:" << black << " white:" << white << ln;
    cout << (black > white ? "Fennec" : "Snuke") << ln;
}

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

int main(){
    string str;
    cin >> str;
    while(str[0]!='0'){
        int sum=0;
        for(int i=0; i<str.size(); i++){
            sum+=str[i]-'0';
        }
        cout << sum << endl;
        cin >> str;
    }
    return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  ll a,b,v,w,t;
  cin >> a >> v >> b >> w >> t;
  ll A,V;
  A=max(a,b)-min(a,b);
  V=max(v,w)-min(v,w);
  if(w-v>=0)cout << "NO";
  else if(V*t>=A)cout << "YES";
  else cout << "NO";
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();

        long ans = solve(n, m);
        System.out.println(ans);
    }

    static long solve(long n, long m) {
        // 数列が作れないパターン
        if (Math.abs(n - m) > 1) {
            return 0;
        }

        long ans = 0;
        if (n == m) {
            // 犬猿同値
            ans = factorize(n) * factorize(m) * 2;
        } else {
            ans = factorize(n) * factorize(m);
        }
        return ans % 1000000007;
    }

    static long factorize(long n) {
        long ret = 1;
        for (int i = 1; i <= n; i++) {
            ret *= i;
            ret %= 1000000007;
        }
        return ret;
    }
}


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

#define ll long long

using namespace std;

const int MAXN = 100010;
const int MAXM = 100010;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int n, m, k;
int tot, cnt, ans;

int read() {
	int f = 1, s = 0;
	char ch = getchar();
	while ('0' > ch || ch > '9') {if (ch == '-') f = -1; ch = getchar();}
	while ('0' <= ch && ch <= '9') {s = (s << 1) + (s << 3) + ((int)ch ^ 48); ch = getchar();}
	return s * f;
}

int a[MAXN], b[MAXN];

string s;

int main() {
	int T;
	scanf("%d%d%d", &n, &m, &k);
	for (int i = n; i <= m; i++) {
		if (i % k == 0) ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3828
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;

int main(){
  int N;
  cin>>N;

  int A[2][200]={0};

  for(int i=0;i<2;i++){
    for(int j=0;j<N;j++){
      cin>>A[i][j];
    }
  }

  ll sum=0,ans=0;

  for(int h=0;h<=N;h++,sum=0){
    for(int i=0;i<N;i++){
      if(i==h) sum+=A[1][i]+A[0][i];
      else if(i<h) sum+=A[0][i];
      else sum+=A[1][i];
    }
    ans=max(ans,sum);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void YesNo(bool);
void YESNO(bool);


int main(){
    vector<int>s(3);
    for (int i = 0; i < 3; i++) {
        cin >> s.at(i);
    }
    sort(s.begin(), s.end());
    cout << s.at(2) * 10 + s.at(1) + s.at(0) << endl;
    
}


void YesNo(bool x){
    if (x) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

void YESNO(bool x){
    if (x) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
}


Measured memory_bytes: 256
var lines = []; var result = 0;
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 S = lines[0].split("");
    var K = Number(lines[1]);

    var str = Array(S.length).fill("").map(value => value = Array(S.length).fill(""));
    str[0][0] = ""

    var dictionary = [];

    for (var i = 0; i < S.length; i++) {
        for (var j = i; j < S.length; j++) {
            if (K <= str[i][j].length) { break; }

            str[i][j + 1] = str[i][j] + S[j];
            dictionary.push(str[i][j + 1])
        }
    }

    dictionary = dictionary.filter((value, index, array) => {
        return (array.indexOf(value) === index);
    });

    dictionary.sort()
    console.log(dictionary[K - 1]);
});


Measured memory_bytes: 230380
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from collections import deque

N,K = II()
t,d = Line(N)

x = []
for i in range(N):
    x.append([t[i],d[i]])

x.sort(key=lambda x: -x[1])

used = []
for i in range(K):
    used.append(x[i])

a = defaultdict(list)
for u in used:
    a[u[0]].append(u[1])

num = len(a.keys())

rem = []
for k in a.keys():
    if len(a[k])>=2:
        a[k].sort(reverse=True)
        for i in range(1,len(a[k])):
            rem.append(a[k][i])
rem.sort()
rem = deque(rem)

b = defaultdict(list)
for i in range(N):
    if a[t[i]]==[]:
        b[t[i]].append(d[i])

app = []
for k in b.keys():
    app.append(max(b[k]))
app.sort(reverse=True)
app = deque(app)

val = sum([used[i][1] for i in range(len(used))]) + num**2
temp = val
while (rem and app):
    re,ap = rem.popleft(), app.popleft()
    temp = temp-re+ap-num**2+(num+1)**2
    if val < temp:
        val = temp
    num += 1

print(val)

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	int n;
	cin >> n;
	vector<pair<int,int>> s;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		s.push_back(make_pair(a,i+1));
	}
	SORT_ASC(s);
	REP(i,n){
		if(i!=0){
			cout << " ";
		}
		cout << s[i].second;
	}
	cout << endl;


	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 1780
# coding: utf-8


def main():
    _ = int(input())
    A = list(map(int, input().split()))
    ans = 0

    for a in A:
        while a % 2 == 0 and a > 1:
            ans += 1
            a >>= 1

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 10120
/**********************************************
 *Author*        :coderdz
 *Created Time*  : 2018/6/7 22:36:37
 *Ended  Time*  : 2018/6/7 22:50:19
*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
#define IO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define rep(i,n) for(int i=1;i<=n;i++)
#define a first
#define b second
#define m(a,b) memset(a,b,sizeof(a))
typedef pair<int, int> PII;
typedef long long ll;
const int MAXN=2e5+10;

int a[MAXN];

inline void OPEN(string s){
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

pair<int,int> pa[MAXN];

int main(){
    //IO;
    int n;
    cin>>n;
    int a[105];
    int ans=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;){
    	int cnt=1;
    	int j;
    	for(j=i+1;j<=n;j++){
			if (a[i]==a[j])
				cnt++;
			else break;
		}
		i=j;
		ans+=(cnt/2);
	}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import io.{StdIn => in}

object Main extends App {
  val s = in.readLine
  val n = s.size
  val ptn = Array.ofDim[Boolean](n)

  def f():Long = {
    var res = 0L
  
    def dfs(idx:Int):Unit = {
      if(idx == n) evaluate
      else {
        ptn(idx) = false
        dfs(idx + 1)
        ptn(idx) = true
        dfs(idx + 1)
      }
    }

    def evaluate():Unit = {
      val sb = StringBuilder.newBuilder
      sb.append(s)
      var pos = 0
      for(i <- 1 until n) {
        if(ptn(i)) {
          sb.insert(i+pos," ")
          pos += 1
        }
      }
      // println(ptn.mkString(" "))
      // println(sb)
      res += sb.toString.split(" ").map(_.toLong).sum
    }

    dfs(1)
    res
  }

  val ans = f()
  println(ans)
}


Measured memory_bytes: 27332
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Contest
{
    class ABC
    {
        static void Main()
        {
            Solve();
        }
        private static void Solve()
        {
            long[] INPUT = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long a = INPUT[0];
            long b = INPUT[1];
            long gcd = Gcd(a, b);
            var res = Factorize(gcd);
            Console.WriteLine(res.Keys.Count + 1);
        }
        // ユークリッドの互除法 
        static long Gcd(long a, long b)
        {
            return b == 0 ? a : Gcd(b, a % b);
        }
        /// <summary>
        /// 素因数分解
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static Dictionary<long, int> Factorize(long n)
        {
            var ret = new Dictionary<long, int>();
            for (long i = 2; i * i <= n; i++)
            {
                if (n % i != 0)
                {
                    continue;
                }

                ret[i] = 0;
                while (n % i == 0)
                {
                    n /= i;
                    ret[i]++;
                }
            }

            if (n > 1)
            {
                if (ret.ContainsKey(n))
                {
                    ret[n]++;
                }
                else
                {
                    ret[n] = 1;
                }
            }

            return ret;
        }
    }
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
ll INF = 1LL << 60;
 
using vc = vector<char>;
using vi = vector<int>;

using comb = tuple<int, int, int>;

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

    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    vector<ll> XS (X);
    vector<ll> YS (Y);
    vector<ll> ZS (Z);
    
    F0R(i, X) {cin >> XS[i];}
    F0R(i, Y) {cin >> YS[i];}
    F0R(i, Z) {cin >> ZS[i];}

    sort(XS.begin(), XS.end());
    sort(YS.begin(), YS.end());
    sort(ZS.begin(), ZS.end());
    set<comb> considered;
    priority_queue<pair<ll, comb>> q;
    q.push({XS[X-1] + YS[Y-1] + ZS[Z-1], make_tuple(X-1, Y-1, Z-1)});
    considered.insert(make_tuple(X-1, Y-1, Z-1));

    vector<ll> ans (K);
    F0R(i, K) {
        
        comb other = q.top().second;
        int xind = get<0>(other);
        int yind = get<1>(other);
        int zind = get<2>(other);
        ans[i] = q.top().first;
        // cout << q.top().first << " " << q.size() << " " << xind << " " << yind << " " << zind << endl;

        q.pop();
        F0R(xp, 2) {
            F0R(yp, 2) {
                F0R(zp, 2) {
                    if (xp + yp + zp != 1) continue;
                    
                    int nx = xind - xp;
                    int ny = yind - yp;
                    int nz = zind - zp;

                    comb tup = make_tuple(nx, ny, nz);
                    if (0 <= nx && 0 <= ny && 0 <= nz && considered.find(tup) == considered.end()) {
                        q.push({(ll)XS[nx] + YS[ny] + ZS[nz], tup});
                        considered.insert(tup);
                    }
                }
            }
        }
    }
    for (auto it = ans.begin(); it != ans.end(); ++it) {
        cout << *it << endl;
    }
    
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int N;
vector<string> names;
vector<int> starts;
int P;
vector<string> favs;
map<string, int> to_id;
bool cross_impl(int s1, int s2) {
    if (s1 <= s2 && s2 < s1 + 30) return true;
    return false;
}
bool cross(int s1, int s2) { return cross_impl(s1, s2) || cross_impl(s2, s1); }
void solve() {
    rep(i, P) rep(j, P) if (i != j) {
        int a = to_id[favs[i]];
        int b = to_id[favs[j]];
        if (cross(starts[a], starts[b])) {
            // cout << "muri: " << favs[i] << ", " << favs[j] << endl;
            // cout << a << ", " << b << endl;
            // cout << starts[a] << ", " << starts[b] << endl;
            cout << "-1" << endl;
            return;
        }
    }
    vector<int> used;
    rep(i, P) {
        int a = to_id[favs[i]];
        used.push_back(starts[a]);
    }
    rep(_, N) {
        int mini = 1e8;
        for (auto s : starts) {
            bool ok = true;
            for (auto x : used) ok &= !cross(x, s);
            if (ok && mini > s) mini = s;
        }
        if (mini != 1e8) used.push_back(mini);
    }
    cout << used.size() << endl;
}
int main() {
    while (cin >> N, N) {
        rep(i, N) {
            string n;
            int w, s;
            cin >> n >> w >> s;
            s = s / 100 * 60 + s % 100;
            s += w * 86400;
            names.push_back(n);
            starts.push_back(s);
            // cout << i << ": " << s << endl;
            int t = to_id.size();
            to_id[n] = t;
        }
        cin >> P;
        rep(i, P) {
            string n;
            cin >> n;
            favs.push_back(n);
        }
        solve();
        favs.clear();
        starts.clear();
        to_id.clear();
        names.clear();
    }
    return 0;
}

Measured memory_bytes: 3292
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
	string s;
	int n,count=0;
	cin >> n >> s;
	for (int i = 0; i < n-1; i++)
	{
		if (s[i] == s[i + 1])
		{
			count++;
		}
	}
	cout << n-count << endl;
}

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

#define w cout
#define e '\n'
#define int long long
#define sz(x) (int)x.size()
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

const int N = 1e6;

signed main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s;cin >> s;
	int c = 0;
	for(char i : s) {
		if(i == 'A') c++;
	}
	if(c == 1 || c == 2) w << "Yes" ;
	else w << "No";
}


Measured memory_bytes: 256
while True:
    a,op,b = raw_input().split()
    if '?' == op:
        exit()
    a = int(a)
    b = int(b)
    if '+' == op:
        print a + b
    if '-' == op:
        print a - b
    if '*' == op:
        print a * b
    if '/' == op:
        print a / b

Measured memory_bytes: 6420
"use strict";
    
const main = arg => {
    const N  = arg.split("\n")[0];
    const lr = arg.split("\n").slice(1, N + 1);
    let answer = 0;
    
    for(let i=0; i<N; i++) {
        answer += lr[i].split(" ")[1] - lr[i].split(" ")[0] + 1;
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7612
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
    int a,b,c,d;
    long long n;
    cin>>a>>b>>c>>d;
    cin>>n;
    long long av=8*a,bv=b*4,cv=c*2,dv=d;
    long long s=0;
    if(n>=2)
    {
        s+=min(av,min(bv,min(cv,dv)))*(n/2);
        n=n%2;
    }
    if(n==1)
        s+=min(4*a,min(2*b, c));
    printf("%lld\n",s);
    return 0;
}

Measured memory_bytes: 256
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int a,b;
  cin >> a >> b;
  cout << max(a+b,max(a-b,a*b)) << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
int a[100010];
int main()
{
	int n;
	scanf("%d", &n);
	int dap = 0;
	for (int i = 0; i < n; i++)
	{
		int q;
		scanf("%d", &q);
		q++;
		a[q]++;
		a[q - 1]++;
		a[q + 1]++;
		dap = max(dap, a[q]);
		dap = max(dap, a[q + 1]);
		dap = max(dap, a[q - 1]);
	}
	printf("%d", dap);
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

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

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

vector<ll> costs(12,0);
vector<vector<ll>> points(12, vector<ll>(12,0));
int min_cost = INT_MAX;
ll N, M, X;

void dfs(int cur, vector<int> total, int cost){
    if( cur >= N ){
        REP(j,M){
            if(total[j] < X){
                return;
            }
        }
        min_cost = min(cost, min_cost);
        return;
    }

    // not pick
    dfs(cur+1, total, cost);

    // pick
    cost += costs[cur];
    REP(j,M){
        total[j] += points[cur][j];
    }
    dfs(cur+1, total, cost);
}

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    cin >> N >> M >> X;

    REP(i, N) {
        cin >> costs[i];
        REP(j, M){
            cin >> points[i][j];
        }
    }

    vector<int> total(12);
    dfs(0, total, 0);
    if( min_cost == INT_MAX ){
        cout << -1 << endl;
    }else {
        cout << min_cost << endl;
    }
}


Measured memory_bytes: 3636
import sys
import itertools

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()
dbg = lambda *args, **kwargs: print(*args, **kwargs, file=sys.stderr)

N = ni()
A = nl()
assert len(A) == (N + 1)


def solve():
    ar = list(itertools.accumulate(A[::-1]))
    ar.reverse()
    ar.append(0)
    assert len(ar) == (N + 2)
    if N == 0:
        return 1 if A[0] == 1 else -1
    if A[0] != 0:
        return -1
    inn = ans = 1
    for i in range(1, N + 1):
        b = 2 * inn - A[i]
        if b < 0:
            return -1
        inn = min(b, ar[i + 1])
        ans += inn + A[i]
    return ans


print(solve())


Measured memory_bytes: 85880
#include<bits/stdc++.h>
using namespace std;
#define PI acos(-1)
using ll = long long;
int main()
{
    ll k, n; cin >> k >> n;
    vector < ll > rm(n);
    for(ll i = 0; i < n; i++)
        cin >> rm[i];
    ll d = accumulate(rm.begin(), rm.end(),0);
    if(k > d)
    {
        cout << k - d;
    }
    if(k == d)
        cout << 0;
    if(k < d)
        cout << -1;
}




Measured memory_bytes: 3672
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int x = scan.nextInt();
		while(n != 0 || x != 0) {
			int count = 0;
			for(int i=1; i<=n; i++){
				for(int j=i+1; j<=n; j++){
					for(int k=j+1; k<=n; k++){
						if(i + j + k == x) {count = count + 1;}
					}
				}
			}
			System.out.println(count);
			n = scan.nextInt();
			x = scan.nextInt();
		}
	}
}

Measured memory_bytes: 26632
#include <iostream>
#include <algorithm>
using namespace std;
using int64 = long long;

int main() {
  int N; cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i]; A[i] -= (i+1);
  }
  sort(A,A+N);
  int b;
  if (N%2 == 1) {
    b = A[N/2];
  }
  else {
    b = (A[N/2-1]+A[N/2])/2;
  }
  long long answer = 0;
  for (int i = 0; i < N; i++) {
    answer += abs(A[i]-b);
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 1024
/* A - ∴ (Therefore) */

#include <stdio.h>

int main(void){
  int N;
  scanf("%d", &N);
  if(N % 10 == 2 || N % 10 == 4 || N % 10 == 5 || N % 10 == 7 || N % 10 == 9){
    printf("hon\n");
  }else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8){
    printf("pon\n");
  }else{
    printf("bon\n");
  }
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
#define pb push_back
#define ll long long
/*

to make a change to a sort do this : 

sort (a.begin(), a.end(), [&](int x , int y){
	return x<y;
})

*/
struct Q
{
	ll x, y;
	ll operator*(Q b)
	{
		// cout << x << " "<< y<<endl;
		// cout << b.y << " "<< b.x << endl;
		return (x * b.y - y * b.x);
	}
	void read()
	{
		cin >> x >> y;
	}
	Q operator-(Q b)
	{
		return {x - b.x, y - b.y};
	}
	double operator%(Q b)
	{
		return sqrt(pow(x - b.x, 2) + pow(y - b.y, 2));
	}
};
bool inters(Q a, Q b, Q c, Q d)
{
	for (int i = 0; i < 2; i++)
	{
		Q zg = (b - a), zg1 = (b - c), zg2 = (b - d);
		ll v1 = zg * zg1, v2 = zg * zg2;
		if (v1 * v2 > 0)
		{
			return false;
		}
		else if (v1 == 0 && v2 == 0)
		{
			if (max(a.x, b.x) < min(c.x, d.x) || max(a.y, b.y) < min(c.y, d.y))
			{
				return false;
			}
		}
		swap(a, c);
		swap(b, d);
	}
	return true;
}
bool inter(Q a, Q b, Q c, Q d)
{
	if ((b - a) * (c - a) == 0) // check if b a (c) is coliner
	{
		if (((c.x <= b.x && c.x >= a.x) || (c.x <= a.x && c.x >= b.x)) && ((c.y <= b.y && c.y >= a.y) || (c.y <= a.y && c.y >= b.y)))
			return true;
		else
			return false;
	}
	else if ((b - a) * (d - a) == 0) // check if b a (d) is coliner
	{
		if (((d.x <= b.x && d.x >= a.x) || (d.x <= a.x && d.x >= b.x)) && ((d.y <= b.y && d.y >= a.y) || (d.y <= a.y && d.y >= b.y)))
			return true;
		else
			return false;
	}
	else if ((d - c) * (a - c) == 0) // check if d c (a) is coliner
	{
		if (((a.x <= d.x && a.x >= c.x) || (a.x <= c.x && a.x >= d.x)) && ((a.y <= d.y && a.y >= c.y) || (a.y <= c.y && a.y >= d.y)))
			return true;
		else
			return false;
	}
	else if ((d - c) * (b - c) == 0) // check if d c (b) is coliner
	{
		if (((b.x <= d.x && b.x >= c.x) || (b.x <= c.x && b.x >= d.x)) && ((b.y <= d.y && b.y >= c.y) || (b.y <= c.y && b.y >= d.y)))
			return true;
		else
			return false;
	}
	else
	{

		bool a1 = true, a2 = true, a3 = true, a4 = true;
		if ((a - c) * (d - c) < 0)
		{
			a1 = false;
		}
		if ((b - c) * (d - c) < 0)
		{
			a2 = false;
		}
		if ((c - a) * (b - a) < 0)
		{
			a3 = false;
		}
		if ((d - a) * (b - a) < 0)
		{
			a4 = false;
		}
		if (a1 != a2 && a3 != a4)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}

int main()
{
	FAST_IO
	int n, m;
	cin >> n >> m;
	map<int, int> ma;
	set<int> see;
	int ans = 0, anss = 0;
	for (int i = 0; i < m; i++)
	{
		int b;
		cin >> b;
		string s;
		cin >> s;
		if (s == "AC")
		{
			if (!see.count(b))
			{
				ans++;
				anss += ma[b];
				see.insert(b);
			}
		}
		else
		{
			ma[b] += 1;
		}
	}
	cout << ans << " "<< anss <<endl;
}


Measured memory_bytes: 9600
# coding: utf-8
A,B = list(map(int, input().split()))

def lr(A, tax):
    if (100 * A) % tax == 0:
        x1_l = 100 * A // tax
    else:
        x1_l = 100 * A // tax + 1
    if (100 * A + 100) % tax == 0:
        x1_r = (100 * A + 100) // tax - 1
    else:
        x1_r = (100 * A + 100) // tax
    return list(range(x1_l, x1_r+1))

list8=lr(A,8)
list10=lr(B,10)
ret = []
for val in list8:
    if val in list10:
        ret.append(val)
if len(ret)==0:
    print(-1)
else:
    print(min(ret))



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,a,b;
int main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	if (a>b)
	{
		printf("0");
		return 0;
	}
	if (n==1)
	{
		if (a!=b) {
			printf("0");
		}
		if (a==b)
		{
			printf("1");
			return 0;
		}
		return 0;
	}
	ll minsum=(a+b)+(a*(n-2));
	ll maxsum=(a+b)+(b*(n-2));
	printf("%lld\n",(ll)maxsum-minsum+1);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int ,int> pii;
typedef pair<ll,ll> pll;
const int INF = 1000000000;
const int maxN = 100010;
const int MOD = 100003;
 
int a[maxN];
int F[maxN];
int b[maxN];
int father(int x)
{
	if(x != F[x])
		F[x] = father(F[x]);
	return F[x];
}
int main()
{
	
	ll ttt = clock();
	
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		F[i] = i;
	}
	for(int i=1;i<=n;i++)
	{
		int x = i,y = a[i];
		F[father(x)] = father(y);
	}
	if(father(1) != father(2))
	{
		printf("-1\n");
		return 0;
	}
	int ans = 0;
	int tmp = 1;
	while(1)
	{
		if (clock() - ttt >= 900000)
		{
			puts("-1");
			return 0;
		}
		if(tmp == 2)
			break;
		else 
		{
			tmp = a[tmp];
			ans++;
		}	
	}
	printf("%d\n",ans);
	return 0;
} 


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

int main() {
  int N,K,Sum;
  cin>>N>>K;
  Sum=1;
 rep(i, N){if(Sum<K){Sum*=2;}else{Sum+=K;}}
  cout<<Sum<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

static const int N = 100;

int main(){
  int n,i,j;
  int v;
  int count=0;
  int A[N];

  /*scanf data*/
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  /*bubbule sort*/
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(A[j-1]>A[j]){
	v=A[j];
	A[j]=A[j-1];
	A[j-1]=v;
	count++;
      }
    }
  }

  /*printf data*/
  printf("%d",A[0]);
  for(i=1;i<n;i++)printf(" %d",A[i]);
  printf("\n%d\n",count);
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define ll unsigned long long int
#define loop(i,a,b) for(int i=a;i<b;i++)

int main()
{
    int n,k;
    int h[100005];
    cin>>n>>k;
    loop(i,0,n)
    cin>>h[i];
    ll dp[100005];
    loop(i,0,100005)
    dp[i]=-1;

    dp[0]=0;
    int i,j;

    for(i=0;i<n;i++)
    {
       for(j=i+1;j<=i+k;j++)
       {
       	if(j<n)
       	dp[j] = min(dp[j], dp[i]+ abs(h[j]-h[i]));
       }
    }

    cout<<dp[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 5100
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
const double PI = acos(-1);

int main(){
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        ll a;
        cin>>a;
        if(a%2!=0){
            cout<<"first"<<endl;
            return 0;
        }
    }
    cout<<"second"<<endl;
}



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

using namespace std;
#define sz(a) int(a.size())
#define ll  long long
#define mod int(1e9+7)
#define endl '\n'
#define ENGZ ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);cin.tie(0) , cout.tie(0) ;
#define pi (acos(-1))
#define S second
#define F first
ll fp(ll n , ll p )
{
    if(p==0)
        return 1;
    if(p==1)
        return n ;
    ll res = fp(n,p/2) ;
    res=((res)*(res)) ;
    if(p%2)
        res=(res*n) ;
    return res ;
}

int main()
{
    ENGZ;
    int a,b,c ;
    cin>> a>> b >>c ;
    if(a == b && a!=c)cout<<"Yes" <<endl;
    else if(a == c && a!=b)cout<<"Yes" <<endl;
    else if(c == b && a!=b)cout<<"Yes" <<endl;
    else cout<<"No" <<endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3)
#pragma comment(linker,"/stack:96777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

struct min_segment_tree{
	int n,seg[1<<19-1];
	void init(int n_){
		n=1;
		while(n<n_)n*=2;
		rep(i,2*n-1)seg[i]=INF;
	}
	void upd(int k,int a){
		k+=n-1;
		seg[k]=a;
		while(k){
			k=(k-1)/2;
			seg[k]=min(seg[k*2+1],seg[k*2+2]);
		}
	}
	int que(int a,int b,int k,int l,int r){
		if(r<=a||b<=l)return INF;
		if(a<=l&&r<=b)return seg[k];
		else{
			int vl=que(a,b,k*2+1,l,(l+r)/2);
			int vr=que(a,b,k*2+2,(l+r)/2,r);
			return min(vl,vr);
		}
	}
};
struct max_segment_tree{
	int n,seg[1<<19-1];
	void init(int n_){
		n=1;
		while(n<n_)n*=2;
		rep(i,2*n-1)seg[i]=-INF;
	}
	void upd(int k,int a){
		k+=n-1;
		seg[k]=a;
		while(k){
			k=(k-1)/2;
			seg[k]=max(seg[k*2+1],seg[k*2+2]);
		}
	}
	int que(int a,int b,int k,int l,int r){
		if(r<=a||b<=l)return -INF;
		if(a<=l&&r<=b)return seg[k];
		else{
			int vl=que(a,b,k*2+1,l,(l+r)/2);
			int vr=que(a,b,k*2+2,(l+r)/2,r);
			return max(vl,vr);
		}
	}
};
int main(){
	string s;
	cin>>s;
	if(s=="ABC")cout<<"ARC";
	else cout<<"ABC";
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;

bool flag[50001];
int prime[50001];

int main(){
  int n = 0;
  int i, j;

  flag[0] = flag[1] = true;
  for (i = 2; i * i <= 50000; i++){
    if(flag[i] != true){
      for(j = i * i; j <= 50000; j += i){
        flag[j] = true;
      }
    }
  }
  j = 0;
  for (i = 0; i <= 50000; i++){
    if (!flag[i]){
      prime[j++] = i;
    }
  }
  while(cin >> n, n){
    int cnt = 0;
    for(i = 0; prime[i] <= n / 2; i++){
      if (flag[n - prime[i]] == false){
        cnt++;
      }
    }
    cout << cnt << endl;
  }

  return (0);
}

Measured memory_bytes: 1236
package main

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

func main() {
	scanner := makeScanner(8192)
	eGetInt(scanner)
	as := eGetInts(scanner)
	count := 0
	for {
		for i := 0; i < len(as); i++ {
			if as[i]%2 != 0 {
				goto end
			}
			as[i] = as[i] / 2
		}
		count++
	}
end:
	fmt.Println(count)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}

func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
 
int n, ans;
vector <int> l;
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ans = 0;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        int x; cin >> x;
        l.pb(x);
    }
    sort(all(l));
    for(int i = n-1; i >= 2; --i) {
        for(int j = i-1; j >= 1; --j) {
            auto a = upper_bound(all(l), l[i]-l[j]);
            auto b = l.begin() + j - 1;
            if (b - a >= 0) ans += (b - a + 1);
        }
    }
    cout << ans;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <utility>
#include <queue>

#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; i++)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; }

typedef long long ll;
using namespace std;

int main() {
    
    int n;
    cin >> n;
    vector<int> h(n, 0);
    REP (i, n) cin >> h[i];

    int ans = 0;
    while (true) {
        int l = -1, re = n;
        REP(i, n) {
            if (l < 0) {
                if (h[i] > 0) l = i;
            } else {
                if (h[i] <= 0) {
                    re = i;
                    break;
                }
            }
        }
        if (l == -1) break;
        for (int i = l; i < re; i++) {
            h[i]--;
        }
        ans++;
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
int main(void)
{
    int X;
    cin >> X;
    int num=X/100;
    int frac=X-(num*100);
    //cout << num << ' ' << frac << endl;
    if(frac>5*num) cout << 0 << endl;
    else cout << 1 << endl;
}

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

int a[22][2];
int main() {
    int n, m = 1e9;
    cin >> n;
    for(int i = 0; i < 2; i++)
        for(int j = 0; j < n; j++)
            cin >> a[j][i];
    for(int i = 0; i < 1 << n; i++) {
        int x[22], d[22], e[22] = {}, b = 0;
        for(int j = 0; j < n; j++)
            x[j] = a[j][!!(i & 1 << j)];
        sort(x, x + n);
        for(int j = 0; j < n; j++) {
            for(int k = 0; k < n; k++) {
                if(e[k])
                    continue;
                if(x[j] == a[k][!!(i & 1 << k)] &&
                   (j ^ k ^ !(i & 1 << k)) & 1) {
                    d[j] = k, e[k]++;
                    goto A;
                }
            }
            goto F;
        A:;
        }
        for(int k = 0; k < n; k++)
            for(int l = k + 1; l < n; l++)
                if(d[k] > d[l])
                    b++;
        m = min(m, b);
    F:;
    }
    cout << (m < 1e9 ? m : -1) << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace  std ;
using db  = double;
using ll  = long long;
using ull = unsigned long long; 
using pII = pair <int, int>;
using pLL = pair <ll, ll>;
#define s(x) ((int)(x).size())
#define deb(x) cout << x << endl
#define deb1(x) cout << #x <<" "<< x << endl
#define deb2(x,y) cout << #x <<" "<< x <<" "<< #y <<" "<< y << endl
int main()
{
	  ll a, b;
	  ll T;
	  cin >> T;
	  ll c = 0, k=0;
	  while(T--)
	  {
	  	cin >> a >> b;
	  	if(a==b) c++;
	  	 if(a!=b) c= 0;
	  	 if(c==3) 
	  	 {
	  	 	k = 1;
	  	 	break;
	  	 }
	  }
	  if(k==1) deb("Yes");
	  else deb("No");

				
}		




Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;


int main() {

    int N;
    cin >> N;
    ll sum = 0;
    for(int i=1;i<=N;i++){
        if(i%3!=0&&i%5!=0){
            sum += i;
        }
    }
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, X, D;
  cin >> N >> X >> D;
  if (D == 0) {
    cout << (X == 0 ? 1 : N + 1) << '\n';
    return 0;
  }
  if (D < 0) X = -X, D = -D;
  tuple<long long, long long, long long> dlr[N + 1];
  dlr[0] = make_tuple(0, 0, 0);
  long long suml = 0, sumr = N - 1;
  long long x = X > 0 ? X % D : (D - (-X) % D) % D;
  for (int k = 1; k <= N; k++) {
    dlr[k] = make_tuple(k * x % D, k * X + suml * D, k * X + sumr * D);
    suml += k;
    sumr += N - 1 - k;
  }
  sort(dlr, dlr + N + 1);
  long long ans = 0;
  long long curd = -1;
  long long last;
  for (int k = 0; k <= N; k++) {
    long long d, l, r;
    tie(d, l, r) = dlr[k];
    if (d != curd) {
      curd = d;
      last = r;
    } else {
      if (r < last) continue;
      if (l <= last) ans -= (last - l) / D + 1;
      last = r;
    }
    ans += (r - l) / D + 1;
  }
  cout << ans << '\n';
  return 0;
}


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

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

int main(void){

	int w, h;

	while (cin >> w >> h , w, h){
		bool x_wall[40][40] = { false }, y_wall[40][40] = { false };
		bool used[40][40];
		queue<pair <int, pair<int, int> > > que;

		for (int j = 0; j < h; j++){
			for (int i = 0; i < w; i++) used[j][i] = false;
		}

		for (int i = 0; i < w; i++) y_wall[0][i] = true;
		
		for (int j = 0; j < h - 1; j++){
			int buff;
			x_wall[j][0] = true;
			for (int i = 1; i < w; i++) cin >> x_wall[j][i];
			x_wall[j][w] = true;

			for (int i = 0; i < w; i++) cin >> y_wall[j + 1][i];
			
		}

		x_wall[h-1][0] = true;
		for (int i = 1; i < w; i++) cin >> x_wall[h-1][i];
		x_wall[h-1][w] = true;

		for (int i = 0; i < w; i++) y_wall[h][i] = true;

		que.push(make_pair(1, make_pair(0, 0)));

		/*
		for (int j = 0; j < h; j++){
			for (int i = 0; i < w; i++){
				cout << x_wall[j][i] << y_wall[j][i] << "\t";
			}
			cout << endl;
		}
		*/

		bool flag = false;

		while (!que.empty()){
			pair <int, pair<int, int> > nxy = que.front();
			que.pop();

			int x = nxy.second.first;
			int y = nxy.second.second;
			if (used[y][x] || x < 0 || w < x || y < 0 || h < y)continue;

			used[y][x] = true;

			if (x == w - 1 && y == h - 1){
				cout << nxy.first << endl;
				flag = true;
				while (!que.empty()) que.pop();
				break;
			}

			//cout << nxy.first << "\t" << x << "\t" << y << endl;

			if (!x_wall[y][x] && !used[y][x - 1]) que.push(make_pair(nxy.first + 1, make_pair(x - 1, y)));
			if (!y_wall[y][x] && !used[y - 1][x]) que.push(make_pair(nxy.first + 1, make_pair(x, y - 1)));
			if (!x_wall[y][x + 1] && !used[y][x + 1]) que.push(make_pair(nxy.first + 1, make_pair(x + 1, y)));
			if (!y_wall[y + 1][x] && !used[y + 1][x]) que.push(make_pair(nxy.first + 1, make_pair(x, y + 1)));

		}

		if (!flag) cout << 0 << endl;

	}

	return 0;
}

/*
for(i=0;i<N;i++){
cin >> X[i];
}


for(i=0;i<N;i++){
for(j=0;j<N;j++){
cin >> X[i][j];
}
}
*/

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

int frog(vector<int> v, int k){
  vector<int> a(v.size(), INT_MAX);
  a[0]=0;
  for(int i=1; i<v.size(); i++){
    for(int j=1; j<=k; j++){
      if((i-j)>=0) a[i] = min(abs(v[i]-v[i-j])+a[i-j], a[i]);
      else break;
    }
  }
  return a[v.size()-1];
}

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> v(n);
  for(int i=0; i<n; i++) cin>>v[i];
  cout<<frog(v,k);
  return 0;
}

Measured memory_bytes: 4304
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define ll long long
int main(){
  int n,count0=0,count1=0;
  char s[100001];
  scanf("%s",s);
  n = strlen(s);
  for(int i=0;i<n;i++){
    if(s[i]=='0'){
     count0 += 1;
    }
    else{
     count1 += 1;
    }
  }
  if(count0>=count1){
    printf("%d",2*count1);
  }
  else{
    printf("%d",2*count0);
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main() {
	long long n,a,b;
	string s = "Yes";
	cin >> n >> a>>b;
	long long base = a*(n / (a + b));
	long long hoge = n % (a + b) > a ? a : n % (a + b);
	cout << base + hoge << endl;
}


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


namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            if (n % 2 == 0)
            {
                Console.WriteLine(n / 2);
            }
            else
            {
                Console.WriteLine(n / 2 + 1);
            }

            



            //ここまで
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

int main() {
  i64 a, b;
  cin >> a >> b;
  i64 now = 1;
  i64 ans = 0;
  while(now < b) {
    now += a - 1;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[100005];
int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	int r=0,c=0;
	for(int i=0; i<n-1; i++){
		if(a[i]==a[i+1]){
			c=r;
			r=a[i];
			i++;
		}

	}
	printf("%lld\n",1ll*r*c);
	return 0;
}


Measured memory_bytes: 640