akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#define NPANEL 9

class State {
public:
  int panels[9];
  int empty;
  State(int p[]) {
    for (int i = 0; i < NPANEL; i++) {
      panels[i] = p[i];
      if (p[i] == 0)
        empty = i;
    }
  }
  void print() {
    for (int i = 0; i < NPANEL; i++) {
      if (i != 0 && i % 3 == 0)
        printf("\n");
      printf("%d ", panels[i]);
    }
  }
  bool is_completed() {
    for (int i = 1; i < NPANEL; i++)
      if (panels[i - 1] != i)
        return false;
    return true;
  }
  State left() { return slide(empty, empty - 1); }
  State above() { return slide(empty, empty - 3); }
  State right() { return slide(empty, empty + 1); }
  State bottom() { return slide(empty, empty + 3); }
  State slide(int x, int y) {
    auto s = State(panels);
    swap(s.panels[x], s.panels[y]);
    s.empty = y;
    return s;
  }

  vector<State> nexts() {
    vector<State> v;
    if (empty % 3 != 0)
      v.push_back(left());
    if (empty >= 3)
      v.push_back(above());
    if (empty % 3 != 2)
      v.push_back(right());
    if (empty <= 5)
      v.push_back(bottom());
    return v;
  }
};

bool store(State st) {
  static set<int> pool;
  int hash = 0;
  for (int i = 0; i < NPANEL; i++) {
    hash *= 10;
    hash += st.panels[i];
  }
  bool exists = (pool.find(hash) != pool.end());
  if (!exists)
    pool.insert(hash);
  return !exists;
}

struct Node {
  State state;
  int depth;
};

int solve(State init) {
  if (init.is_completed())
    return 0;
  queue<Node> que;
  que.push(Node{init, 0});

  while (!que.empty()) {
    Node node = que.front();
    for (auto s : node.state.nexts()) {
      if (s.is_completed()) {
        return node.depth + 1;
      }
      if (store(s)) {
        que.push(Node{s, node.depth + 1});
      }
    }
    que.pop();
  }
}

int main() {
  int data[NPANEL];
  for (int i = 0; i < NPANEL; i++)
    cin >> data[i];

  auto s = State(data);
  cout << solve(s) << endl;
}

Measured memory_bytes: 12800
#!/usr/bin/env python3

import math

numbers = input().split(" ")
a = int(numbers[0])
b = int(numbers[1])
c = int(numbers[2])

k = int(input())



for i in range(k):
    if a < b:
        break
    b *= 2
    k -= 1

c = c * (2 ** k)

if (a < b) and (b < c):
    print("Yes")
else:
    print("No")





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

int main(){
    string o, e;
    cin >> o >> e;
    string s = "";
    for (int i = 0; i < e.size(); i++)
    {
        cout << o[i] << e[i];
    }
    if (o[e.size()])
    {
        cout << o.back() << "\n";
    }
    
    cout << "\n";
}

Measured memory_bytes: 256
import Data.List( subsequences)
main = do
    s <- getLine
    let powSet = subsequences [1..lngth]
	lngth = length s
	splits (list,[]) _ = map (read::String->Integer) list
	splits (list,_) [] = map (read::String->Integer) list
	splits (list,rem) (pos:ps) =
	  let
	    (l,r) = splitAt pos rem
	  in
	    splits (l:list, r) $ map ((negate pos)+) ps
    print . sum . map sum $ take (2^(lngth-1)) $ reverse $ map (splits ([],s)) powSet

Measured memory_bytes: 1148
import java.util.Scanner;
public class Main {
	public static int str(String a,String b) {
		if(a.equals(b)) {
			return 0;
		}
		return 1;
	}
    public static void main(String[] args) {
    	Scanner scan=new Scanner(System.in);
    	String str=scan.next();
    	int a=0;
    	a+=str(String.valueOf(str.charAt(0)),"C");
    	a+=str(String.valueOf(str.charAt(1)),"O");
    	a+=str(String.valueOf(str.charAt(2)),"D");
    	a+=str(String.valueOf(str.charAt(3)),"E");
    	a+=str(String.valueOf(str.charAt(4)),"F");
    	a+=str(String.valueOf(str.charAt(5)),"E");
    	a+=str(String.valueOf(str.charAt(6)),"S");
    	a+=str(String.valueOf(str.charAt(7)),"T");
    	a+=str(String.valueOf(str.charAt(8)),"I");
    	a+=str(String.valueOf(str.charAt(9)),"V");
    	a+=str(String.valueOf(str.charAt(10)),"A");
    	a+=str(String.valueOf(str.charAt(11)),"L");
    	a+=str(String.valueOf(str.charAt(12)),"2");
    	a+=str(String.valueOf(str.charAt(13)),"0");
    	a+=str(String.valueOf(str.charAt(14)),"1");
    	a+=str(String.valueOf(str.charAt(15)),"6");
System.out.println(a);
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int A,B,C,D,E,F;
	cin >> A >> B >> C >> D >> E >> F;
	vector<int> nAB(F+1,0), nCD(F+1,0);
	nAB[0] =nCD[0] =1;
	for(int i =0; i <= F; i++) if(nAB[i]) {
		if(i+A <= F) nAB[i+A] =1;
		if(i+B <= F) nAB[i+B] =1;}
	for(int i =0; i <= F; i++) if(nCD[i]) {
		if(i+C <= F) nCD[i+C] =1;
		if(i+D <= F) nCD[i+D] =1;}
	int ansW =A, ansS =0;
	for(int i =1; i <= F/100; i++) if(nAB[i])
		for(int j =0; j <= i*E; j++) if(nCD[j])
			if(ansS*(i*100+j) < j*(ansW*100+ansS) && i*100+j <= F)
				ansS =j, ansW =i;
	cout << ansW*100+ansS << " " << ansS << "\n";
	return 0;}

// look at my code
// my code is amazing

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

using namespace std;

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

	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3464
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		Scanner sc = new Scanner(br.readLine());
		int w=sc.nextInt();
		int h=sc.nextInt();
		int x=sc.nextInt();
		int y=sc.nextInt();
		int r=sc.nextInt();
		if(x<0||y<0||w<x||h<y){System.out.println("No");}
		else if((x+r<=w&&y+r<=h)&&(x-r>=0&&y-r>=0)){System.out.println("Yes");}
		else{System.out.println("No");}
		}
}

Measured memory_bytes: 17376
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def primeFactors(n):
    facs = defaultdict(int)
    # Print the number of two's that divide n
    while n % 2 == 0:
        facs[2]+=1
        n = n / 2

    # n must be odd at this point
    # so a skip of 2 ( i = i + 2) can be used
    for i in range(3, int(sqrt(n)) + 1, 2):

        # while i divides n , print i ad divide n
        while n % i == 0:
            facs[i]+=1
            n = n / i

            # Condition if n is a prime
    # number greater than 2
    if n > 2:
        facs[n]+=1

    return facs

n = INT()

factors = primeFactors(n)

canBe = []

for el in factors:
    for po in range(1, 60):
        if(factors[el]<=0):
            break
        canBe.append(int(el**po))
        factors[el]-=1


canBe.sort()
i = 0
ans = 0

while (True):
    if (i >= len(canBe) or canBe[i] > n):
        break
    if(n/canBe[i]==n//canBe[i]):
        n /= canBe[i]
        ans += 1
    i += 1
    # print(n)
print(ans)

Measured memory_bytes: 68912
#include<bits/stdc++.h>
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<int,Pil>Piil;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
int a[21];
int f[2001]={};

int main() {

	int n,q;
	cin>>n;
	rep(i,n)cin>>a[i];

	rep(i,(1<<n)){
		int t=0;
		rep(j,n){
			if(i&(1<<j))t+=a[j];
		}
		f[t]=1;
	}
	cin>>q;
	rep(i,q){
		int m;
		cin>>m;
		if(f[m])cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}

	return 0;
}



Measured memory_bytes: 3112
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    cout << min( A, B ) << " " << max( ( A + B ) - N, 0 ) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, 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 (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,m,x;
    cin >> n >> m >> x;
    vector<ll> c(n);
    auto a = make_v<ll>(n, m);
    rep(i, n){
        cin >> c[i];
        rep(j, m){
            cin >> a[i][j];
        }
    }
    ll ans = LLINF;
    rep(bit, 1 << n){
        vector<ll> sum(m);
        bool flag = true;
        ll money = 0;
        rep(i, n){
            if(bit >> i & 1){
                money += c[i];
                rep(j, m) sum[j] += a[i][j];
            }
        }
        rep(i, m){
            if(sum[i] < x) {
                flag = false;
                break;
            }
        }
        if(flag) chmin(ans, money);
    }
    if(ans == LLINF) print(-1);
    else print(ans);

}



Measured memory_bytes: 3668
"""
bitDPというらしい
dp[i][j] = i番目の入力に対して、状態jを実現する最小値
j : 2^12通り。それぞれの宝箱をbitと見立てる
"""

N, M = map(int, input().split())
INF = 10**5+1


dp = [INF for i in range(2**N+1)]
dp[0] = 0

for i in range(M):
    cost,b = map(int, input().split())
    boxes = list(map(int, input().split()))
    status = 0
    for box in boxes:
        status += 2**(box-1)
    for j in range(2**N):
        if dp[j] != INF:
            nxt = status | j
            dp[nxt] = min(dp[j] + cost, dp[nxt])

ans = dp[2**N-1]
if ans == INF:
    print(-1)
else:
    print(ans)

# for i in range(M):
#     print(dp[i])

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

int main() {
 string s;
 int count = 0;
 cin >> s;
 
 for (int i = 0; i < s.length(); ++i){
   if (s[i] != s[s.length()-1-i]) count++;	
   
 }
  
  
  cout << count/2 << endl;
 
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (A, B, C) = readLine()!!.split(" ").map(String::toLong)
    val AC = Math.max(A - C, 0)
    val BC = if (A < C) {
        Math.max(B - (C - A), 0)
    } else {
        B
    }
    println("$AC $BC")
}



Measured memory_bytes: 37948
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  for(int a=1;a<=9;a++)for(int b=1;b<=9;b++){
      if(a*b==n){
        printf("Yes");
        return 0;
      }
  }
  printf("No");
  return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    p = list(map(int, input().split()))
    is_same = [False for _ in range(n)]
    ans = 0

    for index, pi in enumerate(p, 1):
        diff = pi - index

        if diff == 0:
            is_same[index - 1] = True

    i = 0

    while i < n:
        if i == n - 1 and is_same[i]:
            ans += 1
            break

        if is_same[i] and is_same[i + 1]:
            i += 2
            ans += 1
        elif is_same[i] and not is_same[i + 1]:
            i += 2
            ans += 1
        else:
            i += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14008
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] c = new int[3][3];
		String ans = "No";
		
		for(int i=0; i<3; i++){
		    for(int j=0; j<3; j++){
		        c[i][j] = sc.nextInt();
		    }
		}
		
		if(c[0][2]-c[0][1] == c[1][2]-c[1][1] && c[1][2]-c[1][1] == c[2][2]-c[2][1]){
		    if(c[0][1]-c[0][0] == c[1][1]-c[1][0] && c[1][1]-c[1][0] == c[2][1]-c[2][0]){
		        if(c[2][0]-c[1][0] == c[2][1]-c[1][1] && c[2][1]-c[1][1] == c[2][2]-c[1][2]){
		            if(c[1][0]-c[0][0] == c[1][1]-c[0][1] && c[1][1]-c[0][1] == c[1][2]-c[0][2]){
		                ans = "Yes";
		            }
		        }
		    }
		}
      	System.out.println(ans);
    }
}

Measured memory_bytes: 35492
#include<bits/stdc++.h>
using namespace std;
int main(){
    int l,r;
    cin>>l>>r;
    if(r-l>2017)cout<<"0"<<endl;
    else{
        int m=2018;
        for(int i=l;i<r;i++){
            for(int j=i+1;j<=r;j++)m=min(m,(i%2019)*(j%2019)%2019);
        }
        cout<<m<<endl;
    }
    return 0;
}

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

using namespace std;
 
//#define int long long
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=0;i<=n;i++)

ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
 
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

struct UnionFind{
    vector<ll> par;
    vector<ll> siz;

    UnionFind(ll N):par(N),siz(N,1){
        for(int i = 0;i<N;i++){
            par[i] = i;
        }
    }

    ll root(ll x){
        if(par[x]==x)
        return x;
        return par[x]=root(par[x]);
    }

    void unite(ll x, ll y){ //xとyを結合
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(siz[x]<siz[y])swap(x,y);
        siz[x]+=siz[y];
        par[y]=x;
    }

    ll size(ll x){
        return siz[root(x)];
    }

    bool same(ll x,ll y){
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    ios_base::sync_with_stdio(false);
    ll N,M,ans=0;
    ll x,y;
    cin >> N >> M;

    UnionFind rel(N);

    for(ll i=0;i<M;i++){
        cin >> x >> y; 
        rel.unite(x-1,y-1);
    }

    for(ll i=0;i<N;i++){
        ans = max(ans,rel.size(i));
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

vector <int> d;

ll ans(ll x) {
	ll res = 0;
	for (int i = 0; i < int(d.size()); i++) {
		res += (x - d[i]) * (x - d[i]);
	}
	return res;
}

int main() {
	#ifdef HOME
		freopen("input.txt", "rt", stdin);
	#endif
	int n;
	cin >> n;
	d.resize(n);
	ll res = 2e18;
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	int x;
	for (int i = -1000; i <= 1000; i++) {
		ll val = ans(1ll * i);
		if (val <= res) {
			x = i;
			res = val;
		}
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;

 
long N;
long ans;

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

int main(void){
	int a, b, c,ai, bi, ci,d,tmp,K;
	long ans=0;
	cin >> K;
	for(ai=1;ai<=K;ai++){
		for(bi=1;bi<=K;bi++){
			for(ci=1;ci<=K;ci++){
			    a=ai;b=bi;c=ci;
				if(a<b){
					tmp = a;
					a = b;
					b = tmp;
				}
				d=gcd(a, b);
				if(c<d){
					tmp = c;
					c = d;
					d = tmp;
				}
				ans += gcd(c, d);
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3596
s = input()
odd = 0
even = 0
n = len(s)
# 奇数回目が1か偶数回目が1かで考える
for i in range(n):
    if s[i] == '1':
        if i%2 == 0:
            odd += 1
        else:
            even += 1
# sが偶数ならoddかevenの少ないほうをチェンジ
if n%2 == 0:
    n //= 2
    ans = n - max(odd,even) + min(odd,even)
    print(ans)
#　奇数だと一か所ずれる
else:
    n //= 2
    x = n+1 - odd + even
    y = n - even + odd
    ans = min(x,y)
    print(ans)

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;

	int k = 1;
	for (int i = 0, x; i < n; ++i)
	{
		cin >> x;
		if (x == k) ++k;
	}

	if (k == 1)
	{
		cout << "-1\n";
		return 0;
	}

	cout << n-k+1 << "\n";

	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int Y = sc.nextInt();
        int Z = sc.nextInt();        
        int ans = 0;
        
        //椅子幅N・人幅Y・心の距離Zは、常に以下の式が成り立つ。
        while((ans + 1) * (Y + Z) + Z  <= N){
            ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((abs(a - b) <= d && abs(b - c) <= d) | abs(a - c) <= d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;

void ansYes(bool flag){
    if (flag) cout << "Yes" << endl; else  cout << "No" << endl;
}

void ansYES(bool flag){
    if (flag) cout << "YES" << endl; else  cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

struct datas{
    Int max;
    Int size;
};


int main(void) {
    string s;
    cin >> s;
    int hi = 0;
    REP(s.size(),i){
        if (hi == 0) {
            if (s.at(i) != 'h') {
                ansYes(false);
                return 0;
            }else{
                hi = 1;
            }
        }else{
            if (s.at(i) != 'i') {
                ansYes(false);
                return 0;
            }else{
                hi = 0;
            }
        }
    }
    if (hi != 0) {
        ansYes(false);
        return 0;
    }
    ansYes(true);
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int result = Integer.parseInt(scanner.next()) + Integer.parseInt(scanner.next());
            int length = String.valueOf(result).length();
            System.out.println(length);
        }
    }
}

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

const int MAX = 2e5 + 111;

int n, m;

vector <vector <int> > v;

bool gg[MAX];

int main() {
#ifdef LOCAL
    freopen("xxx.in", "r", stdin);
    freopen("xxx.out", "w", stdout);    
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    v.resize(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        v[a].push_back(b);
        v[b].push_back(a);
        if (b == n - 1)
            gg[a] = true;
        if (a == n - 1)
            gg[b] = true;
    }
    for (int i = 0; i < (int)v[0].size(); ++i) {
        if (gg[v[0][i]]) {
            cout << "POSSIBLE";
            return 0;
        }
    }
    cout << "IMPOSSIBLE";
    return 0;
}

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

signed main(){
  int R,D,X;
  cin>>R>>D>>X;
  rep(i,10){
    X=R*X-D;
    cout<<X<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	int x, y;
	cin >> x >> y;
	while(x > 0 && y > 0)
	{
		if (x >= y)
		{
			x %= y;
		} else 
		{
			y %= x; 
		}
	}
	cout << max(x, y) << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
ll H,W;
string str[20];
ll s[20][20];
ll X;
ll dummy[2][1<<20][2];
ll pow3[401];
const ll m=100000;
int main()
{
	pow3[0]=1;
	for(ll i=1;i<=400;i++) pow3[i]=pow3[i-1]*3%m;
	cin>>H>>W;
	X=(1<<W)-1;
	for(ll i=0;i<H;i++){
		cin>>str[i];
	}
	for(ll i=0;i<H;i++){
		for(ll j=0;j<W;j++){
			if(str[i][j]=='J') s[i][j]=1;
			if(str[i][j]=='O') s[i][j]=2;
			if(str[i][j]=='I') s[i][j]=3;
		}
	}
	ll (*prev)[2]=dummy[0];
	ll (*next)[2]=dummy[1];
	ll x,y;
	prev[0][0]=1;
	for(ll i=0;i<H;i++){
		for(ll j=0;j<W;j++){
			fill(next[0],next[1<<20],0);
			if(i==H-1&&j==W-1) continue;
			for(ll k=0;k<2;k++){
				for(ll S=0;S<1<<W;S++){
					if(s[i][j]==0||s[i][j]==1){//J
						next[(S<<1)&X][1]=(next[(S<<1)&X][1]+prev[S][k])%m;
					}
					if(s[i][j]==0||s[i][j]==2){//O
						next[((S|k)<<1)&X][0]=(next[((S|k)<<1)&X][0]+prev[S][k])%m;
					}
					if(s[i][j]==0||s[i][j]==3){//I
						if(((S>>(W-1))&1)&&j!=W-1) goto e;
						next[(S<<1)&X][0]=(next[(S<<1)&X][0]+prev[S][k])%m;
					}
					e: ;
				}
			}
			swap(prev,next);
		}
	}
	ll ans=0;
	ll cnt=0;
	for(ll i=0;i<H;i++){
		for(ll j=0;j<W;j++){
			if(s[i][j]==0) cnt++;
		}
	}
	ll d=1;
	if(s[H-1][W-1]==0) d=3;
	ans=pow3[cnt];
	for(ll k=0;k<2;k++){
		for(ll S=0;S<(1<<W);S++){
			if(s[H-1][W-1]==0){
				ans=(ans-prev[S][k]*3)%m;
			}
			else{
				ans=(ans-prev[S][k])%m;
			}
		}
	}
	printf("%lld\n",(ans%m+m)%m);
}

Measured memory_bytes: 36008
length,mi,ma = map(int,input().split())
summ = 0
for i in range(1,length + 1):
  digits = len(str(i))
  digits_summary = 0
  
  for j in range(digits):
    digits_summary += int(str(i)[j])
  
  if mi<=digits_summary and digits_summary<=ma:
    summ += i
  else:
    pass
print(summ)

Measured memory_bytes: 3060
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

A = []
for i in range(N):
    A.append(list(map(int, input().split())))

cnt = 0

for i in range(N):
    s = 0
    for j in range(M):
        s += A[i][j] * B[j]
    s += C

    if s > 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn count(v: &[usize], i: usize, k: usize) -> usize {
  let c = v[i];
  if k >= v.len() - 1 {
    return c;
  }
  c - (v[k] - v[k + 1])
}

fn main() {
  input! {
    n: usize,
    s: Chars
  };

  let mut rc = vec![0; n + 1];
  let mut gc = vec![0; n + 1];
  let mut bc = vec![0; n + 1];

  for (i, &ch) in s.iter().rev().enumerate() {
    let i = n - i;
    rc[i - 1] = rc[i];
    gc[i - 1] = gc[i];
    bc[i - 1] = bc[i];
    match ch {
      'R' => rc[i - 1] += 1,
      'G' => gc[i - 1] += 1,
      'B' => bc[i - 1] += 1,
      _ => {}
    }
  }
  let mut res = 0;
  for i in 0..n {
    for j in (i + 1)..n {
      if j + 1 == n {
        continue;
      }
      let l = j + (j - i);
      let c = match (s[i], s[j]) {
        ('R', 'G') => count(&bc, j + 1, l),
        ('R', 'B') => count(&gc, j + 1, l),
        ('G', 'R') => count(&bc, j + 1, l),
        ('G', 'B') => count(&rc, j + 1, l),
        ('B', 'R') => count(&gc, j + 1, l),
        ('B', 'G') => count(&rc, j + 1, l),
        _ => 0,
      };
      res += c;
    }
  }
  println!("{}", res);
}


Measured memory_bytes: 2248
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define  st first
#define  nd second
#define int long long

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef cc_hash_table<int, int, hash<int > > ht;
#define TIMES_PER_SEC (CLOCKS_PER_SEC)


double get_absolute_time()
{
	return (double)clock()/TIMES_PER_SEC;
}
double starttime_acrush;
void starttime()
{
	starttime_acrush=get_absolute_time();
}
double gettime()
{
	return get_absolute_time()-starttime_acrush;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define M   1000000007
const int N = 200001;  // limit for array size
int dp[10][10] ;
int a[N] ;
int32_t main(){

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

  dp [1][1] = 1;
  a[1] = 1;
int   ans = 1;

  for ( int i = 2 ; i <N ; i++ ) {
    int k = i ;
    int last = k%10 ;
    while ( k/10 ){
        k/=10;
    }
    int first = k ;
    //dbg(first,last);



    if(first==last)
    ans += (dp[last][first]*2 + 1) ;
    else{
        ans += (dp[last][first]*2);
    }
    dp[first][last]+=1;
    //dbg(ans);
    a[i] = ans ;
  }

  int n ;
  cin >> n ;
  cout << a[n] ;

}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define N 200000
#define LL long long
int n, ai[N], l;
LL s;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++ i) cin >> ai[i];
    sort(ai + 1, ai + n + 1);
    for (int i = 1; i <= n; ++ i)
    {
        if (s * 2 < ai[i]) l = i;
        s += ai[i];
    }
    cout << n - l + 1;
}


Measured memory_bytes: 640
N = int(input())
s = []
for i in range(N):
    s.append(int(input()))

ssum = sum(s)
dp = [[-(10**5) for i in range(ssum+1)] for j in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    for j in range(ssum+1):
        if j-s[i-1] >= 0:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-s[i-1]]+s[i-1])
        else:
            dp[i][j] = dp[i-1][j]

maxa = 0
for j in range(N+1):
    for i in range(ssum+1):
        if (dp[j][i])%10 == 0:
            continue
        else:
            now = dp[j][i]
            maxa = max(maxa,now)

print(maxa)

Measured memory_bytes: 28516
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  int N,K; cin>>N>>K;
  
  vector<int> vec(N);
  rep(i,N)
  {
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  
  ll sum=0;
  rep(i,K)
  {
    sum+=vec.at(i);
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3688
def bomb(x,y):
    for bi in range(-3,4):
        if 0<=x+bi<=7 and field[x+bi][y]=="1":field[x+bi][y]="2"
        if 0<=y+bi<=7 and field[x][y+bi]=="1":field[x][y+bi]="2"
        field[x][y]="0"
n=int(input())
for i in range(n):
    x=input()
    field=[]
    for j in range(8):
        s=input()
        f_s=[]
        for k in s:
            f_s.append(k)
        field.append(f_s)
    x=int(input())
    y=int(input())
    bomb(y-1,x-1)
    while "2" in [flatten for inner in field for flatten in inner]:
        for y in range(8):
            for x in range(8):
                if field[y][x]=="2":bomb(y,x)
    for j in range(8):field[j]=''.join(field[j])
    print(f'Data {i+1}:')
    for j in field:print(j)


Measured memory_bytes: 5628
package main

import "fmt"

func solve() {
	var c1, c2 string
	fmt.Scan(&c1, &c2)
	for i := range c1 {
		if c1[i] != c2[2-i] {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}

func main() {
	solve()
}


Measured memory_bytes: 512
#include<stdio.h>
#include<algorithm>
using namespace std;
int dat[100];
int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	for(int i=0;i<a;i++){
		int e;
		scanf("%d",&e);
		dat[i]=-e;
	}
	std::sort(dat,dat+a);
	int ret=d/b;
	for(int i=0;i<a;i++){
		int sum=0;
		for(int j=0;j<=i;j++)sum-=dat[j];
		ret=max(ret,(sum+d)/(b+(i+1)*c));
	}
	printf("%d\n",ret);
}

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

#define ld long double
#define ll long long
 
int main(){
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        //freopen("test.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    #endif*/
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;

    int n;cin>>n;
    vector<ll> a(n + 1),h(n);
    for(int i=0;i<n+1;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        if(a[i] >= h[i]){
            ans += h[i];
        }
        else {
            h[i] -= a[i];
            ans += a[i] + min(h[i],a[i + 1]);
            a[i + 1] = max(0LL,a[i + 1] - h[i]);
        }
    }
    cout<<ans;

    /*#ifndef ONLINE_JUDGE
        cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif*/
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    map<int,int> m;
    ll sum=0;
    rep(i,n){
        ll a;
        cin>>a;
        sum+=a;
        m[a]++;
    }
    
    int q;
    cin>>q;
    vector<ll> ans(q);
    rep(i,q){
        int b,c;
        cin>>b>>c;
        if(m[b]==0){
            ans[i]=sum;
        }
        else{

            ll x=m[b];
            ll y=m[c];
            //cout<<x<<" "<<y<<endl;
            m[b]=0;
            m[c]=x+y;
            sum-=x*b;
            sum+=c*x;
            ans[i]=sum;
        }
    }

    rep(i,q) cout<<ans[i]<<endl;

}


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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

int cnt = 0;

void solve()
{
	int n; cin >> n;
	int sum = 0;
	forn(i, n) 
	{
		int x; cin >> x;
		sum += x;
	}
	cout << sum - n;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


Measured memory_bytes: 3596
#include<stdio.h>
int MIN(int a,int b){
  if(a==0||a>b)return b;
  return a;
}
int main(){
  int Y[]={-1,0,1,0};
  int X[]={0,1,0,-1};
  int w,h,i,j,k,l,ny,nx,ax[15],ay[15],x[900],y[900],r,t,rr,min;
  while(scanf("%d %d",&w,&h),w||h){
    char d[30][30]={0};
    int dp[10][1<<10]={0};
    int m[30][30]={0};
    int f[30][30]={0};
    int c[30][30]={0};
    r=0;
    for(i=rr=1;i<=h;i++){
      for(j=1;j<=w;j++){
	scanf(" %c",&d[i][j]);
	if(d[i][j]=='o')d[ay[0]=i][ax[0]=j]='.';
	if(d[i][j]=='*'){
	  d[ay[rr]=i][ax[rr]=j]='.';
	  rr++;
	}
      }
    }
    for(i=min=0;i<rr;i++){
      f[y[t=0]=ay[i]][x[t]=ax[i]]=i+1;
      c[y[t]][x[t]]=0;
      for(r=1;r-t;t++){
	for(j=0;j<4;j++){
	  ny=y[t]+Y[j];
	  nx=x[t]+X[j];
	  if(d[ny][nx]-'.'||f[ny][nx]==i+1)continue;
	  c[y[r]=ny][x[r]=nx]=c[y[t]][x[t]]+1;
	  f[ny][nx]=i+1;
	  r++;
	}
      }
      for(j=1;j<rr;j++)m[i][j]=c[ay[j]][ax[j]];
    }
    rr--;
    for(i=0;i<rr;i++){
      dp[i][1<<i]=m[0][i+1];
      if(m[0][i+1]==0)rr=0;
    }
    for(l=0;l<rr;l++){
      for(i=0;i<rr;i++){
	for(j=0;j<1<<rr;j++){
	  if(dp[i][j]==0)continue;
	  for(k=0;k<rr;k++){
	    if(j&1<<k)continue;
	    dp[k][j|1<<k]=MIN(dp[k][j|1<<k],dp[i][j]+m[i+1][k+1]);
	  }
	}
      }
    }
    for(i=min=0;i<rr;i++)min=MIN(min,dp[i][(1<<rr)-1]);
    if(min)printf("%d\n",min);
    else   printf("-1\n");
  }
  return 0;
}
    

Measured memory_bytes: 676
# -*- coding: utf-8 -*-
n = int(input())
a1 = [int(i) for i in input().split()]
a2 = [int(i) for i in input().split()]

ans = 0
for i in range(n):
    tmp = sum(a1[:i+1]) + sum(a2[i:])
    if tmp > ans:
        ans = tmp
print(ans)


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a,b,t;
    cin>>a>>b>>t;
    if(a<=t) {
      cout<<(b*(t/a))<<endl;
    }
    else
      cout<<"0"<<endl;
    return 0;
}


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

int main()
{
  int num1, num2;

  cin >> num1 >> num2;

  if(num1 > 9 || num2 > 9)
  {
    cout << -1 << endl;
  }
  else
  {
    cout << num1 * num2 << endl;
  }
}


Measured memory_bytes: 3552
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int W = scanner.nextInt();
        int H = scanner.nextInt();

        int x = scanner.nextInt();
        int y = scanner.nextInt();


        double area = (double)W*H/ 2.0;

        if(2*x==W && 2*y==H){
            System.out.println(area + " " + "1");
        }else{
            System.out.println(area + " " + "0");
        }
    }
}


Measured memory_bytes: 21716
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	var in []string
	for {
		word := nextString(sc)
		if word == "0" {
			break
		}
		in = append(in, word)
	}
	for idx, word := range in {
		fmt.Printf("Case %d: %v\n", idx+1, word)
	}
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}



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

int main(){
  int n;cin>>n;
  ll ans=1;
  vector<ll> a(n,0);
  REP(i,n){
    cin>>a.at(i);
    if(a.at(i)==0){
      cout<<"0";
      return 0;
    }
  }

  REP(i,n){
    long double x=log10(ans),y=log10(a.at(i));
    if(x+y>(long double)18){
      cout<<"-1";
      return 0;
    }
    ans*=a.at(i);
    if(ans>(ll)1000000000000000000){
      cout<<"-1";
      return 0;
    }
  }

  cout<<ans;
}


Measured memory_bytes: 4044
#include<iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n + 2];
    a[0] = 0;
    a[n + 1] = 0; //return
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 1; i <= n + 1; ++i) { //not go spot
        ans += abs(a[i] - a[i - 1]);
    }
    for (int i = 1; i <= n; ++i) {
        cout << ans + abs(a[i + 1] - a[i - 1]) - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) << endl;
    }
    return 0;
}



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

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            int A;int B;int K;
            Multi(out A, out B, out K);
            var array = Enumerable.Range(A, K).ToList();
            array.AddRange(Enumerable.Range(B - K + 1, K).ToList());
            array = array.Where(a => A <= a && a <= B).ToList();
            array = array.Distinct().OrderBy(a => a).ToList() ;
            foreach (var a in array)
            {
                Console.WriteLine(a);
            }

            //Console.WriteLine(ans);
        }


        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

Measured memory_bytes: 13536
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    int a;
    int b;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        System.out.println(a(1, 1));
    }
    
    private int a(int ps, int i) {
        if (b == 1) {
            return 0;
        }
        if (ps == 1) {
            ps = a;
        } else {
            ps += a - 1;
        }
        if (ps >= b)
            return i;
        else
            return a(ps, i+1);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n,m;cin>>n>>m;

  int ban[n+1];
  string s;cin>>s;

  reverse(s.begin(),s.end());

  int now = 0;
  vector<int> ans;
  int p = 0;

  while(p < 1000000){
    p++;
    int maxNext = now + m;
    maxNext = min(maxNext,n);
    int next = now;
    for(int i = maxNext;i>now;i--){
      if(s[i] == '0'){
        next = i;
        break;
      }
    }

    if(next == now){
      cout<<-1<<endl;
      return 0;
    }

    ans.pb(next - now);
    now = next;

    if(now == n){
      break;
    }
  }

  for(int i = ans.size() - 1;i>=0;i--){
    cout<<ans[i]<<" ";
  }
  cout<<endl;

 

  return 0;
}

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

int main() {
	unsigned long long sum = 0ull, minA = 1000000001ull;
	bool isMinusNumOdd = false;
	bool isZeroExists = false;
	int n;
	cin >> n;
	
	int temp;
	for (int i = 0; i < n; ++i) {
		cin >> temp;
		sum += abs(temp);
		minA = min(minA, (unsigned long long)abs(temp));
		if (temp < 0)isMinusNumOdd = !isMinusNumOdd;
		if (temp == 0)isZeroExists = true;
	}

	if (!isZeroExists && isMinusNumOdd)sum -= (minA * 2);

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

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

int main(){
  while(true){
    
    int n,m;
    cin>>n>>m;
    if(n==0&&m==0){
      break;
    }
    vector<int> a(n);
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    int max=0;
    sort(a.begin(),a.end());
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
	int price = a[i]+a[j];
	if(price>max && price<=m){
	  max=price;
	}
      }
      
    }
    if(max==0){
      cout<<"NONE"<<endl;
      continue;
    }
    cout<<max<<endl;
  }
}


Measured memory_bytes: 3112