akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
class Main {
    static long ans=0;
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());
        
        long ans=K;
        for(int i=1; i<N; i++)
            ans*=(K-1);

        System.out.println(ans);
    }
}


Measured memory_bytes: 21076
N=int(input())
abc=[list(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N)]
for i in range(3):
    dp[0][i]=abc[0][i]
for i in range(1,N):
    for j in range(3):
        for k in range(3):
            if(j!=k):
                dp[i][j]=max(dp[i][j],dp[i-1][k]+abc[i][j])
print(max(dp[-1][2],max(dp[-1][0],dp[-1][1])))

Measured memory_bytes: 50000
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 998244353


ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

ll dp[3005][3005];

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    
    rep(i,3005)rep(j,3005){
        dp[i][j]=0;
    }
    
    dp[a][b]=1;
    
    for(ll i=a+1;i<=c;i++){
        dp[i][b]=(dp[i-1][b]*b)%mod;
    }
    
    for(ll i=b+1;i<=d;i++){
        dp[a][i]=(dp[a][i-1]*a)%mod;
    }
    
    //cout << dp[2][1] << endl;
    
    for(ll i=a+1;i<=c;i++){
        for(ll j=b+1;j<=d;j++){
            dp[i][j]+=(dp[i][j-1]*i)%mod;
            //cout << dp[i][j] << endl;
            dp[i][j]=dp[i][j]%mod;
            dp[i][j]+=(dp[i-1][j]*j)%mod;
            dp[i][j]+=mod;
            dp[i][j]-=(((dp[i-1][j-1]*(i-1))%mod)*(j-1))%mod;
            dp[i][j]=dp[i][j]%mod;
        }
    }
    
    cout << dp[c][d] << endl;

    return 0;
}











Measured memory_bytes: 74176
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int N, ans;

int main()
{
	in >> N;
	std::vector<std::string>S(N);
	rep(i, N) in >> S[i];
	rep(A, N)
	{
		bool flag = true;
		rep(i, N)
		{
			rep(j, N)
			{
				if (S[(i + A) % N][j] != S[(j + A) % N][i])
				{
					flag = false;
					break;
				}
			}
			if (!flag) break;
		}
		if (flag) ans += N;
	}
	out << ans << std::endl;
	return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(sa[i]);
		}
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		TreeMap<Integer, Long> map = new TreeMap<>();
		map.put(0, 0L);
		map.put(Integer.MAX_VALUE, Long.MAX_VALUE);
		for (int i = 0; i < n; i++) {
			Integer key = map.lowerKey(h[i]);
			long val = map.get(key) + a[i];
			while (true) {
				Integer key2 = map.higherKey(h[i]);
				if (map.get(key2) < val) {
					map.remove(key2);
				} else {
					break;
				}
			}
			map.put(h[i], val);
		}
		map.remove(map.lastKey());
		System.out.println(map.lastEntry().getValue());
	}
}


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

def main():
	n = int(input().strip())
	v = list(map(int, input().strip().split()))
	v2 = sorted(v)
	if v == v2:
		print('YES')
		return
	for i in range(n-1):
		for j in range(i+1, n):
			w = v[:]
			w[i], w[j] = w[j], w[i]
			if w == v2:
				print('YES')
				return
	print('NO')

if __name__ == '__main__':
	main()


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

int main()
{
  int N;
  const int devide = 1000000007;
  long long int power;

  cin >> N;

  power = 1;
  for (int i = 1; i <= N; i++)
    power = (power * i) % devide;
  cout << power << endl;

  return 0;
}


Measured memory_bytes: 3608
#include <cstdio>
#include <string.h>
using namespace std;

int main(){
	const int size = 16 + 1;
	int a, b, n, x, y;
	int dp[size][size];
	bool fab[size][size];
	
	while(true){
		scanf("%d%d", &a, &b);
		if(a == 0 && b == 0) break;
		scanf("%d", &n);
		memset(fab, false, sizeof(fab));
		for(int i = 0; i < n; i++){
			scanf("%d%d", &x, &y);
			fab[y][x] = true;
		}
		
		memset(dp, 0, sizeof(dp));
		dp[1][1] = 1;
		for(int i = 1; i <= b; i++){
			for(int j = 1; j <= a; j++){
				if(i == 1 && j == 1) continue;
				if(fab[i][j]) dp[i][j] = 0;
				else{
					dp[i][j] = ((i > 1)? dp[i - 1][j] : 0) + ((j > 1)? dp[i][j - 1] : 0);
				}
			}
		}
		
		printf("%d\n", dp[b][a]);
	}
	
	return 0;
}

Measured memory_bytes: 1028
n, k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

if k >= n - 1
  puts (a[-1] - a[0]).abs
  exit
end

dp = [0xffffffff] * n
dp[0] = 0
(1...n).to_a.each do |i|
  (i - 1).downto([i - k, 0].max) do |j|
    v = dp[j] + (a[i] - a[j]).abs

    dp[i] = v if v < dp[i]
  end
end

puts dp[-1]

Measured memory_bytes: 14468
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#pragma comment(linker, "/STACK:336777216")  

using namespace std;

const int MAXN = 1000 + 10;
const int MAXX = 5000 + 10;
const long long INF = 10000000000000000LL;

int N;
int P[MAXN];
int X[MAXN];
int TotW[MAXN];
int Deg[MAXN], Q[MAXN];

vector <int> Sons[MAXN];
long long H[MAXN];
long long DP[2][MAXX];

inline void UpMin(long long& a, long long b)
{
	if (a > b)
		a = b;
}
inline void UpMax(long long& a, long long b)
{
	if (a < b)
		a = b;
}

void Work()
{
	scanf("%d", &N);
	for (int i = 2; i <= N; i ++)
	{
		scanf("%d", &P[i]);
		Deg[P[i]] ++;
		Sons[P[i]].push_back(i);
	}
	for (int i = 1; i <= N; i ++)
		scanf("%d", &X[i]);

	memset(DP, 1, sizeof(DP));
	long long INF = DP[0][0];

	int nQ = 0;
	for (int i = 1; i <= N; i ++)
		if (Deg[i] == 0)
			Q[nQ ++] = i;
	for (int h = 0; h < nQ; h ++)
	{
		int i = Q[h];
		if (Sons[i].empty())
			H[i] = 0;
		else
		{
			memset(DP, 1, sizeof(DP));
			DP[0][0] = 0;
			int cur = 0, next = 1;
			for (auto j: Sons[i])
			{
				memset(DP[next], 1, sizeof(DP[next]));
				for (int p = MAXX - 1; p >= 0; p --)
				{
					if (p + X[j] < MAXX)
						UpMin(DP[next][p + X[j]], DP[cur][p] + H[j]);
					if (p + H[j] < MAXX)
						UpMin(DP[next][p + H[j]], DP[cur][p] + X[j]);
				}
				swap(cur, next);
			}
			H[i] = INF;
			for (int p = 0; p <= X[i]; p ++)
				UpMin(H[i], DP[cur][p]);
			if (H[i] == INF)
			{
				printf("IMPOSSIBLE\n");
				return;
			}
		}
		Deg[P[i]] --;
		if (Deg[P[i]] == 0)
			Q[nQ ++] = P[i];
	}

	printf("POSSIBLE\n");
}

int main()
{
	Work();
	return 0;
}

Measured memory_bytes: 384
l=lambda:map(int, input().split())
n,m=l()
p=[-1]*n
def root(x):
  if p[x]<0:return x
  p[x]=root(p[x]);return p[x]
def union(x,y):
  x,y=root(x),root(y)
  if x==y: return
  p[x]+=p[y]
  p[y]=x
def same(x,y):
  return root(x)==root(y)
def size(x):
  return -p[r(x)]
for _ in range(m):
  a,b=l()
  union(a-1,b-1)
print(-min(p))


Measured memory_bytes: 13276
#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, a[20], t; double dp[20][200000]; vector<int> s[200000];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]), t = max(t, a[i]);
	for (int i = 1; i < 2 * t; i++) {
		for (int j = i; j < 2 * t; j += i) {
			s[j].push_back(i);
		}
	}
	for (int i = 1; i < 2 * t; i++) dp[0][i] = 1.0 * abs(a[0] - i) / a[0];
	for (int i = 1; i < n; i++) {
		for (int j = 1; j < 2 * t; j++) {
			dp[i][j] = 1.0;
			for (int k = 0; k < s[j].size(); k++) {
				dp[i][j] = min(dp[i][j], max(dp[i - 1][s[j][k]], 1.0 * abs(a[i] - j) / a[i]));
			}
		}
	}
	double ret = 1.0;
	for (int i = 1; i < 2 * t; i++) {
		ret = min(ret, dp[n - 1][i]);
	}
	printf("%.9f\n", ret);
	return 0;
}

Measured memory_bytes: 54004
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> a(n), b(n);
    rep(i,0,n) {
        cin >> a[i];
        --a[i];
        b[a[i]] = i;
    }
    vector<int> next(n+1,n), prev(n+1,n);
    next[n] = 0;
    prev[n] = 0;
    set<int> last{a[0]};
    rep(i,1,n) {
        if(i-k>=0) last.erase(a[i-k]);
        auto it = last.lower_bound(a[i]);
        int j = n;
        if(it!=last.end()) {
            j = b[*it];
        }
        next[i] = j;
        prev[i] = prev[j];
        next[prev[j]] = i;
        prev[j] = i;
        last.insert(a[i]);
    }
    vector<int> ans(n);
    int j = n;
    rep(i,0,n) {
        j = next[j];
        ans[j] = i;
    }
    rep(i,0,n) cout << ans[i]+1<<"\n";
}


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

signed main(void){
 
  string s; cin>> s;
  if( s[2] == s[3] && s[4] == s[5] ){ 
    
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        String in=sc.next();
        String []s=in.split("",0);
        String ss="";
        int count=0;
        for(int i=0;i<n;i++){
            if(!s[i].equals("#")){
                count++;
            }
        }
        int countmin=count;
        for(int i=0;i<n;i++){
            if(!s[i].equals("#"))
                count--;
            else count++;
            countmin=Math.min(count,countmin);
        }
        System.out.println(countmin);
    }
    
    
 
}class Po{
    int a,b;
    public Po(int a,int b){
        this.a=a;
        this.b=b;
    }
    public String toString(){
        return a+" "+b;
    }
}


Measured memory_bytes: 54724
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  int T; cin >>T;
  REP(t, T){
    string s; cin >>s;
    int h = atoi(s.substr(0, 2).c_str());
    int m = atoi(s.substr(3).c_str());
    double d = fabs((h * 30.0 + m * 0.5) - m * 6.0);
    d = min(d, 360.0 - d);
    cout <<(d >= 0.0 && d < 30.0 ? "alert" : (d >= 90.0 && d <= 180.0 ? "safe" : "warning")) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
N, K = map(int, input().split())
A = list(map(int, input().split()))

position = A.index(1)
counter = 0
# 左にposition個, 右に(N - position - 1)個の要素がある。
# 左
counter += position // (K - 1)
# 右
counter += (N - position - 1) // (K - 1)

amari = position % (K - 1) + (N - position - 1) % (K - 1)
if amari > 0: amari += 1
# print(amari)

counter += amari // K
if amari % K > 0: counter += 1

print(counter)

Measured memory_bytes: 13880
from sys import stdin
import math
def isPrime(x):
    if x == 2 or x == 3: return True
    elif (x < 2 or x % 2 == 0 or x % 3 == 0): return False
    s = int(math.sqrt(x) + 1)
    for i in range(5, s + 1, 2):
        if x % i == 0: return False
    return True
n = int(stdin.readline())
cnt = 0
for i in range(0, n):
    if isPrime(int(stdin.readline())): cnt += 1
print(cnt)

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

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

int main() {
  string s;
  ll k;
  cin >> s >> k;
  rep(i, min((ll)s.size(), k)) {
    if(s[i] >= '2') {
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << '1' << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 26 23:53:42 2019

@author: yuta
"""

def maxdif(n,a):
    b = sorted(list(map(int,a)))
    c = b[n-1] - b[0]
    print(c)

x = int(input())
y = input().split()

maxdif(x,y)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  int cnt = 0;
  REP(i,N){
    if(i%2==0&&A[i]%2==1){
      cnt++;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String[] S = new String[H];
		for(int i = 0;i < H;++i)
			S[i] = sc.next();
		sc.close();
		
		int[][] mine = new int[W][H];
		for(int y = 0;y < H;++y) {
			for(int x = 0;x < W;++x) {
				if(S[y].charAt(x) == '#') {
					int ypro = y > 0 ? y-1 : y;
					int yter = y == H-1 ? y : y+1;
					int xpro = x > 0 ? x-1 : x;
					int xter = x == W-1 ? x : x+1;
					for(int yi = ypro;yi <= yter;++yi)
						for(int xi = xpro;xi <= xter;++xi)
							mine[xi][yi]++;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int y = 0;y < H;++y) {
			for(int x = 0;x < W;++x) {
				if(S[y].charAt(x) == '#')
					sb.append('#');
				else
					sb.append(mine[x][y]);
			}
			sb.append('\n');
		}
		System.out.println(sb.toString());
	}
}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define IMP cout << "IMPOSSIBLE" << endl
#define Imp cout << "Impossible" << endl
#define imp cout << "impossible" << endl
#define M1 cout << "-1" << endl
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

ll dp[55][5005];

void Main()
{
    arrayFill(dp, 0);
    int n = in(), a = in();
    vint x = in(n);
    rep(i, n) x[i] -= a;

    dp[0][2500] = 1;

    rep(i, n) rep(j, 5000)
    {
        dp[i + 1][j] += dp[i][j];
        dp[i + 1][j + x[i]] += dp[i][j];
    }

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

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


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


class contest
{
		static void Main(string[] args)
		{
			var num = int.Parse(Console.ReadLine());
            long count = 0;
            int rest = 0;
            var input = new List<int>();

            for (int i = 0; i < num; i++) input.Add(int.Parse(Console.ReadLine()));

            for (int i = 0; i < num; i++)
            {
                int digit = (input[i] == 0) ? 0 : input[i] + rest;
                count += digit / 2;
                rest = digit % 2;

            }

            Console.WriteLine(count);      
		}
}

Measured memory_bytes: 7768
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

struct Node {
    int id;
    int left;
    int right;
};

int n;
Node nodes[25];
int root;
bool hasparent[25];

inline void walk_preorder(int id) {
    if (id == -1) { return; }
    Node& node = nodes[id];
    printf(" %d", node.id);
    walk_preorder(node.left);
    walk_preorder(node.right);
}

inline void walk_inorder(int id) {
    if (id == -1) { return; }
    Node& node = nodes[id];
    walk_inorder(node.left);
    printf(" %d", node.id);
    walk_inorder(node.right);
}

inline void walk_postorder(int id) {
    if (id == -1) { return; }
    Node& node = nodes[id];
    walk_postorder(node.left);
    walk_postorder(node.right);
    printf(" %d", node.id);
}

int main(void) {

    scanf("%d", &n);

    for (int i = 0, id; i < n; ++i) {
        scanf("%d", &id);
        Node& pnode = nodes[id];
        pnode.id = id;
        scanf("%d %d", &pnode.left, &pnode.right);
        if (pnode.left != -1)  hasparent[pnode.left]  = true;
        if (pnode.right != -1) hasparent[pnode.right] = true;
    }

    for (int i = 0; i < n; ++i) {
        if (!hasparent[i]) {
            root = i;
            break;
        }
    }

    printf("Preorder\n");
    walk_preorder(root);
    printf("\n");

    printf("Inorder\n");
    walk_inorder(root);
    printf("\n");

    printf("Postorder\n");
    walk_postorder(root);
    printf("\n");

    return 0;
}

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

using namespace std;

int main() {
  int R;
  
  cin >> R;
  
  if (R < 1200) {
    cout << "ABC";
  } else if (R < 2800) {
    cout << "ARC";
  } else {
    cout << "AGC";
  }
  
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int itchi(unsigned int mask, int x) {
    int t = 0;
    for(int i=0; i< (x-1); i++) {
        t += (mask & 0x1);
        mask >>= 1;
    }
    return t+1;
}
int kai(int x) {
   int total = 1;
   for(int i=1; i<=x; i++) {
      total = total*i;
   }
   return total;
}

int main(){
  int N; 
  scanf("%d\n", &N);
  int A[8];
  int B[8];
  unsigned int mask_a;
  unsigned int mask_b;

  mask_a = (0x1<<N) - 1;
  int t1=1;
  for(int i=0; i<N; i++) {
     scanf("%d\n", &A[i]);
     t1 += (itchi(mask_a, A[i]) -1) * kai(N-i-1) ;
     mask_a &= ~(0x1 << (A[i]-1));
  }
  int t2=1;
  mask_b = (0x1<<N) - 1;
  for(int i=0; i<N; i++) {
     scanf("%d\n", &B[i]);
     t2 += (itchi(mask_b, B[i]) -1) * kai(N-i-1);
     mask_b &= ~(0x1 << (B[i]-1));
  }
  printf("%d\n", t1 - t2 > 0 ? t1-t2: (t1  -t2)*-1);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ft first
#define sc second
#define ppb pop_back
#define sz size
#define forn(i,a,n) for(i=a;i<n;i++)
#define M 1000000007
#define inf 2e18


int main() {

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
    
      
 ll n;
 cin>>n;
 vector<ll> v(n);
 ll val=0;
 for(ll i=0;i<n;i++){
    cin>>v[i];
    if(val+1==v[i])val++;
 }
 if(val==0)
    cout<<-1<<"\n";
else{
    cout<<n - (val)<<"\n";
}
 
return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#define ll long long
#define dd double
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	ll t1, t2;
	ll maxx = -1;
	ll minn = 0xffffffff;
	for (ll i = 0; i < m; i++) {
		cin >> t1 >> t2;
		if (t1 > maxx) {
			maxx = t1;
		}
		if (t2 < minn) {
			minn = t2;
		}
	}
	ll t3 = minn + 1 - maxx;
	if (t3 < 1) {
		cout << "0" << endl;
	}
	else {
		cout << t3 << endl;
	}
}

Measured memory_bytes: 256
grid = [[None for j in range(55)] for i in range(55)]
h, w = [int(i) for i in input().split()]
for i in range(h):
  a=list(input())
  for j in range(w):
    grid[i+1][j+1]=a[j]
for x in range(h):
  for y in range(w):
    if grid[x][y]=="#":
      if grid[x+1][y]=="#" or grid[x-1][y]=="#" or grid[x][y+1]=="#" or grid[x][y-1]=="#":
        continue
      else:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
from decimal import Decimal
w,h,x,y = map(int, input().split())
if x==w/2 and y==h/2:
    print(Decimal(w*h/2).quantize(Decimal('0.000000')),1)
else:
    print(Decimal(w*h/2).quantize(Decimal('0.000000')),0)

Measured memory_bytes: 5076
input = input().split()
N = int(input[0])
A = int(input[1])
B = int(input[2])

ans = 0

for i in range(1, N + 1):
    digits = list(map(int, str(i)))
    s = sum(digits)

    if A <= s and s <= B:
        ans += i

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll n,a,b,rem,ans=0;
	cin>>n>>a>>b;
	ans+=(n/(a+b))*a;
	ans+=min(a,n%(a+b));
	cout<<ans<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    System.out.print(Logic.run(x));
  }
}
class Logic{
  public static int run(int x){
    int joy = 0;
    joy += (x / 500) * 1000;
    x = x % 500;
    joy += (x / 5) * 5;
    return joy;
  }
}

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


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if ((a * 100 + b * 10 + c) % 4 == 0) {
		cout << "YES" << endl;
	}
	else
		cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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 const INF = 1001001001;


int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int n,i; cin >> n >> i;
cout << n+1-i << endl;
return 0;
}

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

const long N=1000000;

int main(){
	long ham[550];
	long now=0;
	
	for(int i=0; i<20; ++i){
		for(int j=0; j<13; ++j){
			for(int k=0; k<9; ++k){
				long t=pow(2,i)*pow(3,j)*pow(5,k);
				if(t>N) break;
				ham[now++]=t;			
			}
		}
	}
	
	sort(ham, ham+now);
		
	while(1){
		long a, b, ans=0;
		scanf(" %ld", &a);
		if(a==0) break;
		scanf(" %ld", &b);
		
		for(long i=0; i<N; ++i){
			if(ham[i]>=a){
				now=i;
				break;
			}
		}
		
		for(long i=a; i<=b; ++i){
			if(ham[now]==i){
				++ans;
				++now;
			}
		}
	
		printf("%ld\n", ans);
	}

	return 0;
}

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

using namespace std;

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

int h[1501], w[1501];
int H[2000000], W[2000000];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
	while(cin >> N >> M, N*M) {
	    memset(H, 0, 2000000);
	    memset(W, 0, 2000000);
	    rep(i, N) cin >> h[i];
	    rep(i, M) cin >> w[i];
	    rep(i, N) {
	        int l = 0;
	        REP(j, i, N) {
	            l += h[j];
	            H[l]++;
	        }
	    }
	    rep(i, M) {
	        int l = 0;
	        REP(j, i, M){
	            l += w[j];
	            W[l]++;
	        }
	    }
	    int ans = 0;
	    rep(i, 2000000) ans += H[i]*W[i];
	    cout << ans << endl;
	}
}



Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, W;
    cin >> N >> W;    
    vector<pair<int, int>> wv(N);
    rep(i, N) cin >> wv[i].first >> wv[i].second;
    int wmin = wv[0].first;
    vector<vector<vector<int>>> dp(N);
    int ans = 0;
    
    rep(i, N) {
        wv[i].first -= wmin;
    }
    
    rep(i, N) {
        dp[i].resize(N + 1);
        
        rep(ii, N + 1) {
            dp[i][ii].resize(N * 3, 0);
        }
    }
    
    rep(i, N) {
        if (i == 0) {
            dp[i][1][wv[i].first] = wv[i].second;
            continue;
        }
        
        reps(ii, 1, N + 1) {
            if (ii == 1) {
                rep(iii, N * 3) {
                    if (iii == wv[i].first) {
                        dp[i][ii][iii] = max(dp[i - 1][ii][iii], wv[i].second);
                    }
                    else {
                        dp[i][ii][iii] = dp[i - 1][ii][iii];
                    }
                }
                
                continue;
            }
            
            rep(iii, N * 3) {
                dp[i][ii][iii] = max(dp[i][ii][iii], dp[i - 1][ii][iii]);
                
                if (iii < wv[i].first) {
                    continue;
                }
                
                if (dp[i - 1][ii - 1][iii - wv[i].first] == 0) {
                    continue;
                }
                
                dp[i][ii][iii] = max(dp[i - 1][ii][iii], dp[i - 1][ii - 1][iii - wv[i].first] + wv[i].second);
            }
        }
    }
    
    reps(i, 1, N + 1) {
        rep(ii, N * 3) {
            if (((ll)i * wmin + ii) > (ll)W) {
                continue;
            }
            
            ans = max(ans, dp[N - 1][i][ii]);
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12544
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<set>
#include<random>
#include<ctime>
#include<chrono>
using namespace std;
using ll = long long int;

const int C_NUM = 26;
const int D_MAX = 366;
int D;
int c[C_NUM+5];
int s[D_MAX][C_NUM+5];

int t[D_MAX];
set<int> last[C_NUM+5];


int main(){
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
    cin >> D;
    for(int i = 1; i <= C_NUM; i++)cin >> c[i];
    for(int i = 1; i <= D; i++){
        for(int j = 1; j <= C_NUM; j++){
            cin >> s[i][j];
        }
    }
    ll v = 0;
    for(int j = 1; j <= C_NUM; j++)last[j].insert(0);
    for(int i = 1; i <= D; i++){
        ll merit = 0;
        int choice = 0;
        for(int j = 1; j <= C_NUM; j++){
            ll nowm = s[i][j];
            nowm += c[j] * (i - *last[j].rbegin());
            if (nowm > merit){
                merit = nowm;
                choice = j;
            }
        }
        v += merit;
        last[choice].insert(i);
        t[i] = choice;
    }

    for(int j = 1; j <= C_NUM; j++)last[j].insert(D+1);
    random_device rnd;
    int count = 0;
    end = chrono::system_clock::now();
    double ttime = static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0);
    while(count < 100000){
        int sub = 0;
        int day = (rnd() % D) + 1;
        int o = t[day];
        int nowmax = 0;
        int choice = o;
        for(int n = 1; n <= C_NUM; n++){
            if (n == o)continue;
            sub = s[day][n] - s[day][o];
            int bo = *(--last[o].find(day));
            int ao = *(++last[o].find(day));
            sub -= c[o] * (day - bo) * (ao - day);
            last[n].insert(day);
            int bn = *(--last[n].find(day));
            int an = *(++last[n].find(day));
            sub += c[n] * (day - bn) * (an - day);
            if (nowmax < sub){
                nowmax = sub;
                choice = n;
            }
            last[n].erase(day);
        }
        v += nowmax;
        t[day] = choice;
        last[o].erase(day);
        last[choice].insert(day);
        end = chrono::system_clock::now();
        double ttime = static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0);
        count++;
    }
    for(int i = 1; i <= D; i++)cout << t[i] << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>

using lint = long long;
using Graph = std::vector<std::vector<int>>;

using namespace std;

struct StronglyConnectedComponents {
    Graph graph, rgraph;
    vector<bool> visited;
    vector<int> order;

    // id[v] = 頂点vはgroups[id[v]]に属する
    vector<int> id;
    vector<vector<int>> groups;

    void revinit() {
        rgraph = Graph(graph.size());
        for (int v = 0; v < graph.size(); ++v) {
            for (int sv : graph[v]) {
                rgraph[sv].push_back(v);
            }
        }
    }

    void dfs(int v) {
        if (visited[v]) return;
        visited[v] = true;
        for (int sv : graph[v]) dfs(sv);
        order.push_back(v);
    }

    void rdfs(int v) {
        if (id[v] >= 0) return;
        id[v] = groups.size() - 1;
        groups.back().push_back(v);
        for (int sv : rgraph[v]) rdfs(sv);
    }

    explicit StronglyConnectedComponents(const Graph& g)
        : graph(g), visited(graph.size(), false), id(graph.size(), -1) {
        revinit();

        for (int v = 0; v < graph.size(); ++v) dfs(v);
        reverse(order.begin(), order.end());

        for (int v : order) {
            if (id[v] < 0) {
                groups.push_back(vector<int>());
                rdfs(v);
            }
        }
    }
};


const lint MOD = 1e9 + 7;

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

    Graph graph(N);
    for (int i = 0; i < M; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        graph[v].push_back(u);
        // 後でDFSしやすいように逆向きに辺を張る
    }

    StronglyConnectedComponents scc(graph);
    int V = scc.groups.size();

    // 縮約したグラフ(根付き森)を作成
    vector<int> in(V, 0);  // 入次数(根の判定に使う)
    Graph ngraph(V);
    for (int v = 0; v < N; ++v) {
        for (int sv : graph[v]) {
            if (scc.id[v] == scc.id[sv]) continue;
            ngraph[scc.id[v]].push_back(scc.id[sv]);
            ++in[scc.id[sv]];
        }
    }

    function<lint(int, int)> dfs = [&](int v, int r) {
        lint ret = 1;  // vを黒く塗る場合
        for (int sv : ngraph[v]) {
            if (sv == r) continue;
            (ret *= dfs(sv, v)) %= MOD;
        }

        // vを白く塗る場合を追加
        return (ret + 1) % MOD;
    };

    lint ans = 1;
    for (int v = 0; v < V; ++v) {
        if (in[v] == 0) (ans *= dfs(v, -1)) %= MOD;
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3412
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    
    int res = 0;
    
    for (int i = 0; i < N; ++i) {
        
        while (i + 1 < N && A[i] == A[i+1]) ++i;
        
        if(i + 1 < N && A[i] < A[i + 1]) {
            while (i + 1 < N && A[i] <= A[i + 1]) ++i; 
        }
        
        else if (i + 1 < N && A[i] > A[i + 1]) {
            while (i + 1 < N && A[i] >= A[i +1]) ++i;
        }
        ++res;
        
    }
    cout << res << endl;
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef pair<l_l,ll> lll;
typedef vector<string> vs;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
ll n;
ld dp[330][330][330];
ld rec(ll a,ll b,ll c){
    if(dp[a][b][c]>=0)return dp[a][b][c];
    if(a==0&&b==0&&c==0)return dp[0][0][0]=0.0;
    ld res=n;
    if(a-1>=0)res+=rec(a-1,b,c)*a;
    if(b-1>=0)res+=rec(a+1,b-1,c)*b;
    if(c-1>=0)res+=rec(a,b+1,c-1)*c;
    res/=a+b+c;
    return dp[a][b][c]=res;
}
int main(){
    cin>>n;
    ll a=0,b=0,c=0;
    memset(dp,-1,sizeof(dp));
    rep(i,n){
        ll x;cin>>x;
        if(x==1)a++;
        else if(x==2)b++;
        else c++;
    }
    ld ans=rec(a,b,c);
    cout.precision(20);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 565364
_ = input()
T, A = map(int, input().split())
H = map(int, input().split())

min_value = 10 ** 9
location = -1

for i, h in enumerate(H):
    tmp = abs((T - h * 0.006) - A)
    if tmp < min_value:
        min_value = tmp
        location = i

print(location + 1)

Measured memory_bytes: 3060
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

template<int um> class UF{
    public:
    vector<int> par,rank;
    UF(){rank=vector<int>(um,0);rep(i,um)par.push_back(i);}
    int operator[](int x){return (par[x]==x)?(x):(par[x]=operator[](par[x]));}
    int operator()(int x,int y){
        if((x=operator[](x))==(y=operator[](y))) return x;
        if(rank[x]>rank[y]) return par[x]=y;
        rank[x]+=rank[x]==rank[y];return par[y]=x;
    }
};

UF<500000> uf;
int N, M;
int U[2009], V[2009], W[2009], T[2009], D[1009][1009];
vector<pii> E[2009];
ll X, p2[2009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    p2[0]=1;
    rep(i,2008) p2[i+1]=p2[i]*2%MOD;
    
    cin>>N>>M>>X;
    priority_queue<pii> PQ;
    rep(i,M){
        cin>>U[i]>>V[i]>>W[i];
        U[i]--, V[i]--;
        E[U[i]].push_back({V[i],i});
        E[V[i]].push_back({U[i],i});
        PQ.push({-W[i],i});
    }
    
    ll S=0;
    while(PQ.size()){
        int x = PQ.top().second; PQ.pop();
        if(uf[U[x]]!=uf[V[x]]){
            S+=W[x];
            uf(U[x],V[x]);
            T[x]=1;
        }
    }
    
    rep(i,N){
        rep(x,N) D[i][x]=1<<30;
        D[i][i]=0;
        priority_queue<pii> Q;
        Q.push({0,i});
        while(Q.size()){
            int co=-Q.top().first;
            int cur=Q.top().second;
            Q.pop();
            if(D[i][cur]!=co) continue;
            for(auto& e:E[cur]){
                if(D[i][e.first]>max(co,W[e.second])){
                    D[i][e.first]=max(co,W[e.second]);
                    Q.push({-D[i][e.first],e.first});
                }
            }
        }
    }
    
    ll DD=X-S;
    int eq=0, up=0;
    rep(i,M) if(T[i]==0){
        if(W[i]-D[U[i]][V[i]]==DD) eq++;
        if(W[i]-D[U[i]][V[i]]>DD) up++;
    }
    ll ret=0;
    if(DD>0){
        ret=2*(p2[eq]+MOD-1)*p2[up]%MOD;
    }else if(DD==0){
        ret=2*(p2[eq]+MOD-1)*p2[up]%MOD;
        ret+=(p2[N-1]+MOD-2)*p2[M-N+1]%MOD;
    }
    cout1(ret%MOD);
}

Measured memory_bytes: 8432
import itertools
N, M, X = map(int, input().split())
book_lists = [list(map(int, input().split())) for i in range(N)]
no_skill_flg = True
for i in range(1, N+1):
    for j in itertools.combinations(book_lists,i):
        sum_list = [0 for _ in range(M+1)]
        for book_date in j:
            for k, l in enumerate(book_date):
                sum_list[k] += l
        if all([s >= X for s in sum_list[1:]]):
            no_skill_flg = False
            if 'ans' in globals():
                ans = min(ans, sum_list[0])
            else:
                ans = sum_list[0]
print(ans if not no_skill_flg else -1)

Measured memory_bytes: 9228
n = int(input())
a = list(map(int, input().split()))

counter = 1
smash = 0
bl = True

for i in range(n):
    if a[i] != counter:
        smash += 1
    else:
        counter += 1

if smash == n:
    bl = False
# print(counter)

print(smash if bl else "-1")



Measured memory_bytes: 24744
import fractions
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
l=[0]*n
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
    left[i + 1] = (fractions.gcd(left[i],a[i]))
    right[n - i - 1] = (fractions.gcd(right[n - i],a[n - 1 - i]))

ans = 0
for i in range(n):
    ans = max(ans,fractions.gcd(left[i],right[i + 1]))
print(ans)

Measured memory_bytes: 16136
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int INF=500;
int main() {
  int n;cin>>n; int a[2][n], b[2*n];
  for(int i=0;i<n;i++) cin>>a[0][i];
  for(int i=0;i<n;i++) cin>>a[1][i];
  for(int i=0;i<n;i++) {b[2*i]=a[0][i], b[2*i+1]=a[1][i];}
  sort(b,b+2*n); int mb = 0; 
  for(int i=0;i<2*n;i++) {
    if (i==0 || b[i]!=b[i-1]) mb++;
    else continue;
    for(int j=0;j<n;j++) {
      if (a[0][j]==b[i]) a[0][j]=mb;
      if (a[1][j]==b[i]) a[1][j]=mb;
    }
  }
  mb++;/*
  for(int j=0;j<2;j++){
  for(int i=0;i<n;i++) {
    cout<<a[j][i]<<" ";
  }cout<<endl;}*/

  int dp[mb+1][1<<n];
  fill(dp[0], dp[mb+1], (int)INF);
  dp[0][0] = 0;

  for(int i=0;i<n;i++) {
    for(int j=0;j<mb;j++) {
      for(int k=0;k<(1<<n);k++) {
        if (dp[j][k] == INF) continue;
        int pp = 0;
        for(int x=0;x<n;x++) {
          if (k&(1<<x)) pp++;
        }
        if (pp!=i) continue;
        //cout<<i<<" "<<j<<" "<<k<<endl;
        int p[n], nw=i;

        for(int x=0;x<n;x++) {
          if (k&(1<<x)) continue;
          p[nw] = x; nw++;
        }
        //cout<<"p: ";
        //for(int x=i;x<n;x++) cout<<p[x]<<" ";cout<<endl;

        for(int x=i;x<n;x++) {
          int aorb = (20+i-p[x])%2;
          int cs = a[aorb][p[x]];
          if (j<=cs) {
            dp[cs][k+(1<<p[x])] =
            min(dp[cs][k+(1<<p[x])], dp[j][k]+(x-i));
          }
          //cout<<(j<=cs)<<" ("<<i<<" "<<j<<" "<<k<<") "<<x<<" "<<p[x]<<" "<<aorb<<" "<<cs<<endl;
        }
      }
    }
  }
  /*
  for(int i=0;i<=n;i++) {
    for(int j=0;j<=mb;j++) {
      for(int k=0;k<(1<<n);k++) {
        cout<<dp[j][k]<<" ";
      } cout<<endl;
    } cout<<endl;
  }*/

  int mn=INF;
  for(int i=0;i<mb;i++) {
    mn = min(mn, dp[i][(1<<n)-1]);
  }
  if (mn == INF) cout<<"-1"<<endl;
  else cout<<mn<<endl;
}

Measured memory_bytes: 30976
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;


int main(){
    int n;
    cin>>n;
    float x = n / 1.08;
    if(floor(ceil(x)*1.08)==n) cout<<ceil(x)<<endl;
    else cout<<":("<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define LIMIT 128

int main() {
    char s[LIMIT*2];
    char p[LIMIT];

    for (int i=0; i<LIMIT; ++i) {
        s[i] = '\0';
    }
    fgets(s, LIMIT, stdin);
    char *ln = strchr(s, '\n');
    if (ln != NULL) {
        *ln = '\0';
    }
    for (int i=0; i<LIMIT; ++i) {
        p[i] = '\0';
    }
    fgets(p, LIMIT, stdin);
    ln = strchr(p, '\n');
    if (ln != NULL) {
        *ln = '\0';
    }

    int slen = strlen(s);
    int plen = strlen(p);

    for (int i=0; i<slen; ++i) {
        s[slen+i] = s[i];
    }

    if (strstr(s, p) != NULL) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}



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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var dts = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var (d, t, s) = (dts[0], dts[1], dts[2]);

        Console.WriteLine(d <= t * s ? "Yes" : "No");
    }
}


Measured memory_bytes: 28280
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  map<int, int> amap;
  int tmp;
  for(int i=0;i<N-1;++i) {
    cin>>tmp;
    amap[tmp]++;
  }
  for(int i=1;i<=N;++i) cout<<amap[i]<<endl;
}



Measured memory_bytes: 12988
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> num(n);
	REP(i, n)
		cin >> num[i];
	ll cnt = 0;
	REP(i,n/2+1) {
		while (num[i] + num[i+1] > x) {
			if (num[i+1] > 0) {
				int sub=min(num[i+1],(num[i] + num[i+1])-x);
				num[i+1]-=sub;
				cnt+=sub;
			}
			else {
				int sub = num[i] - x;
				num[i]-=sub;
				cnt+=sub;
			}
		}
		while (num[n-1-i] + num[n-2-i] > x) {
			if (num[n-2-i] > 0) {
				int sub = min(num[n-2-i], (num[n-1-i] + num[n-2-i]) - x);
				num[n-2-i] -= sub;
				cnt += sub;
			}
			else {
				int sub = num[n-1-i] - x;
				num[n-1-i] -= sub;
				cnt += sub;
			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  LL x, y;
  cin>>x>>y;
  int ans=0;
  while(x<=y){
    x*=2;
    ++ans;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import statistics
n = int(input())
a = list(map(int,input().split()))
A = [0]*n
sad = 0
for i in range(1,n+1):
    A[i-1] = a[i-1]-i

A.sort()
b = int(statistics.median(A))
sad = sum(abs(A[i-1]-b) for i in range(1,n+1))
print(sad)

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

int main()
{
    int H, W;
    bool first = true;

    while (cin >> H >> W && H && W) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++)
                cout << "#";
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3100
#include<iostream>
#include<cstring>
using namespace std;
int cnt[27];
int main()
{
	char a,b,c,d;
	cin>>a>>b>>c>>d;
	cnt[a-'A'+1]++;
	cnt[b-'A'+1]++;
	cnt[c-'A'+1]++;
	cnt[d-'A'+1]++;
	for(int i=1;i<=26;i++)
	{
		if(cnt[i]!=0 && cnt[i]!=2)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

int exp(int a, int b);

int main(){

    int x;
    cin >> x;

    int ans = 0, buf = 0;
    int a, b = 2;
    int temp;

    for (a=2; a<x; a++){
        temp = exp(a, b);

        while (temp <= x){
            buf = temp;
            b++;
            temp = exp(a, b);
//            cout << buf << endl;  // debug
        }
        b = 2;
        ans = max(buf, ans);
    }

    if (ans != 0) cout << ans << endl;
    else cout << 1 << endl;
    return 0;
}

int exp(int a, int b){

    if (b == 0) return 1;

    return a*exp(a, b-1);
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
typedef long long ll;
# define INF 1e15
using namespace std;

int main()
{
  int n;
  cin >> n;
  ll sum=0;
  int a[n];ll cf[n];
  for(int i=0;i<n;i++)
  {
    cin >> a[i];
    sum+=a[i];
    cf[i]=sum;
  }
  ll sum_a;ll sum_b;
  ll ans=INF;
  for(int i=0;i<n-1;i++)
  {
    sum_a=cf[i];
    sum_b=sum-sum_a;
    ans=min(ans,abs(sum_a-sum_b));
  }
  cout << ans;
  return 0;
}


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

int N, M;
int WA[105000];
bool AC[105000];

void solve() {
    cin >> N >> M;
    int WAnum = 0;
    int ACnum = 0;
    for(int i = 1; i <= N; i++) {
        WA[i] = 0;
        AC[i] = false;
    }
    while(M--) {
        int p;
        string S;
        cin >> p >> S;
        if(AC[p]) continue;
        if(S == "AC") {
            AC[p] = true;
            ACnum++;
            WAnum += WA[p];
        } else if(S == "WA") {
            WA[p]++;
        }
    }
    cout << ACnum << " " << WAnum << endl;
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 4096