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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) {
    if ( l >= r ) return;
    int root = pre[pos++];
    int m = distance(in.begin(), find(in.begin(), in.end(), root));
    rec(l, m);
    rec(m + 1, r);
    post.push_back(root);
}

void solve() {
    pos = 0;
    rec(0, pre.size());
    for (int i = 0;i < n; i++) {
        if (i) cout << " ";
        cout << post[i];
    }
    cout << endl;
}

int main() {
    int k;
    cin >> n;
    
    for (int i = 0; i <n; i++) {
        cin >> k;
        pre.push_back(k);
    }
    
    for (int i = 0; i < n; i++) {
        cin >> k;
        in.push_back(k);
    }
    
    solve();
    
    return 0;
}


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

#define int long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define lb lower_bound
#define ub upper_bound
#define srt(a) sort(a.begin(),a.end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
#define mxe(a) *max_element(a.begin(),a.end())
#define mne(a) *min_element(a.begin(),a.end())
#define endl '\n'
#define mod 1000000007
#define INF64 1e18

int32_t main(){
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int n,k;cin>>n>>k;
  vi a(n);
  for(int i=0;i<n;i++)
    cin>>a[i];
  vi dp(n);
  for(int i=1;i<n;i++){
    int mn=INF64;
    for(int j=i-1;j+k>=i&&j>=0;j--)
      mn=min(mn,dp[j]+abs(a[i]-a[j]));
    dp[i]=mn;
  }
  cout<<dp[n-1];
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int a, b, c, d;
  cin >> a >> b >> c >> d;
  long long int res = a*c;
  res = max(res, max(b*c, max(d*a, b*d)));
  cout << res;
  return 0;
}


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

string name[1001];
int eby[1001], wy[1001];

int main(){
	name[0] = "Unknown";
	int n, q;
	while(cin >> n >> q, n){
		for(int i = 0; i < n; ++i){
			cin >> name[i] >> eby[i] >> wy[i];
		}
		for(int i = 0; i < q; ++i){
			int ans = -1, x;
			cin >> x;
			for(int j = 0; j < n; ++j){
				if(x <= wy[j] && x > wy[j] - eby[j]){
					ans = j;
					break;
				}
			}
			if(ans == -1){
				cout << "Unknown\n";
			}
			else{
				cout << name[ans] << ' ' << x - wy[ans] + eby[ans] << '\n';
			}
		}
	}
}

Measured memory_bytes: 1304
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct Circle
{
	long long x,y,r;
	double calc(const Circle &c)const
	{
		return max(sqrt((x-c.x)*(x-c.x)+(y-c.y)*(y-c.y))-r-c.r,0.0);
	}
}c[1010];
double dis[1010];
bool vis[1010];
int main()
{
	int n,mi;
	scanf("%lld%lld%lld%lld",&c[0].x,&c[0].y,&c[1].x,&c[1].y);
	c[0].r=0;
	c[1].r=0;
	scanf("%d",&n);
	n++;
	for(int i=2;i<=n;i++)
		scanf("%lld%lld%lld",&c[i].x,&c[i].y,&c[i].r);
	for(int i=1;i<=n;i++)
		dis[i]=1e100;
	dis[0]=0;
	memset(vis,0,sizeof(vis));
	while(!vis[1])
	{
		mi=-1;
		for(int i=0;i<=n;i++)
			if(!vis[i]&&(mi==-1||dis[i]<dis[mi]))
				mi=i;
		vis[mi]=true;
		for(int i=0;i<=n;i++)
			dis[i]=min(dis[i],dis[mi]+c[mi].calc(c[i]));
	}
	printf("%.10lf",dis[1]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int         int64_t
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll          vector<int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mi        map<int,int>
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
int n,i,j,k,l,sum=0,flag=0,t,a[200005],ans=0;
void solve(){
    priority_queue<int> pq;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>j;
        pq.push(j);
    }
    while(!pq.empty() && k){
        int num = pq.top();
        pq.pop();
        k--;
        num/=2;
        if(num) pq.push(num);
    }
    while(!pq.empty()){
        ans+=pq.top();
        pq.pop();
    }
    cout<<ans<<endl;
}
signed main()
{
    ios
    int test=1;
    //cin>>test;
    while(test--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1400
using System;
using System.Collections.Generic;

namespace binarySearch
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var S = new HashSet<int>();
            foreach (var s in Console.ReadLine().Split(' '))
            {
                S.Add(int.Parse(s));
            }
            Console.ReadLine();
            var T = new HashSet<int>();
            foreach (var t in Console.ReadLine().Split(' '))
            {
                T.Add(int.Parse(t));
            }

            S.IntersectWith(T);
            var arr = new int[S.Count];
            Console.WriteLine(arr.Length);
        }
    }
}

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

int main() {
  int H, W;
  string s;
  cin >> H >> W;
 for (int i = 0; i <= W + 1; i++)
 //for (int i = 1; i <= W + 2; i++) 
   cout << "#";
  cout << endl;
 for (int i = 0; i < H; i++) {
   cout << "#";
   cin >> s;
   cout << s;
   cout << "#" << endl;
 }
  for (int i = 0; i <= W + 1; i++)
    cout << "#";
  cout << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;


public class Main {


    private void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int x = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        Arrays.sort(arr);
        int count = 0;
        int index = 0;
        while (index < n && x - arr[index] >= 0) {
            x -= arr[index];
            index++;
            count++;
        }
        if (x > 0 && index == n) {
            out.println(count - 1);
            return;
        }
        out.println(count);

    }


    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        try (
                InputReader in = new InputReader(System.in);
                PrintWriter out = new PrintWriter(System.out)) {
            solve(in, out);
        }
    }


    static class InputReader implements AutoCloseable {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }


        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        @Override
        public void close() {

        }
    }

}


Measured memory_bytes: 21460
d, g = list(map(int, input().split()))
p, c = [], []
for i in range(d):
    pi, ci = list(map(int, input().split()))
    p.append(pi)
    c.append(ci)
bit_li = []
for i in range(2 ** d):
    bit = [0] * d
    for j in range(d):
        if (i >> j) & 1:
            bit[j] = 1
    bit_li.append(bit)
# bit_liは[0,0,1,1,0,...]みたいなのが要素であるリスト
ans = []
for li in bit_li:
    point = 0
    n = 0
    # 全部解くやつを加算
    for i in range(d):
        if li[i] == 1:
            point += (i + 1) * 100 * p[i] + c[i]
            n += p[i]
    flag = True
    if point >= g:  # 全部解くだけで条件満たしてたらappend
        ans.append(n)
        flag = False
    basepoint = point
    base_n = n
    # 中途半端にとくやつを加算
    for i in range(d):
        if li[i] == 0 and flag:
            for j in range(p[i] - 1):
                n += 1
                point += (i + 1) * 100
                if point >= g:
                    ans.append(n)
            point = basepoint
            n = base_n


print(min(ans))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int n;
  cin >> n;
  int ans;
  for (int x = 1; x <= n; ++x) {
    //if (n <= (double)x*1.08 && (double)x*1.08 < n) 
    if (floor(x*1.08) == n) {
      cout << x << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <algorithm>

const int MAXN = 100005;

int h[MAXN], f[MAXN];

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &h[i]);

    f[0] = 0;
    for (int i = 1; i < n; i++) {
        f[i] = INT_MAX;
        for (int j = 1; j <= k && i - j >= 0; j++)
            f[i] = std::min(f[i], f[i - j] + std::abs(h[i] - h[i - j]));
    }

    printf("%d\n", f[n - 1]);
    
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    int ans = min(n*a, b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = long long;
using P = pair<int,int>;

const string byleft = "yhnujmikolp";
bool f(char c) {
    for(const char& l : byleft) {
        if(l == c) return true; 
    }
    return false;
}


int main(){
    string S;
    while(cin >> S, S != "#"){
        bool now = f(S[0]);
        int ans = 0;
        for(char& c : S){
            bool isLeft = false;
            for(const char& l : byleft){
                if(c == l) isLeft = true;
            }
            if(now != isLeft) ans++;
            now = isLeft;
        }

        cout << ans << endl;
    }
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maks = 3e3 + 5;
ll mod = 1e9 +7;
long long dp[maks][maks];
int n,h;
void input() {
    cin >> h >> n;
    dp[1][1] = 1;
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= n; j++) {
            char z; cin >> z;
            if(z=='.') {
                dp[i][j] += (dp[i-1][j]+dp[i][j-1]);
                dp[i][j] %= mod;
            }
        }
    }

}
int main() {
    input();
    cout << dp[h][n];
}

Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
int visit[100001];
int main(void){
	int N;
	cin >> N;
	vector<vector<int>> to(N),cost(N);
	for(int i=0;i<N-1;i++){
		int a,b,w;
		cin >> a >> b >> w;
		a--;
		b--;
		to[a].push_back(b);
		cost[a].push_back(w);
		to[b].push_back(a);
		cost[b].push_back(w);
	}
	vector<int> ans(N);
	queue<int> q;
	ans[0]=0;
	q.push(0);
	while(!q.empty()){
		int v = q.front();
		q.pop();
		for(int i=0;i<to[v].size();i++){
			int u = to[v][i];
			int w = cost[v][i];
			if(visit[u]!=0)continue;
			ans[u]=(ans[v]+w)%2;
			visit[u]=1;
			q.push(u);
		}
	}
	for(int i=0;i<N;i++)cout << ans[i] << endl; 
}

Measured memory_bytes: 14208
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}
const int mod = 1000000007;

int main() {
    string s;
    cin >> s;
    string t = s;
    reverse(t.begin(),t.end());
    int ans = 0;
    rep(i,s.size()/2) {
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
n = int(input())
if n == 1:
    print(1)
else:
    Li = 2
    Lj = 1
    cnt = 2
    while True:
        Lk = Li + Lj
        if cnt == n:
            print(Lk)
            break
        cnt += 1
        Li = Lj
        Lj = Lk

Measured memory_bytes: 2940
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int S=stdIn.nextInt();
		int W=stdIn.nextInt();
		if(S>W)
			System.out.println("safe");
		else
			System.out.println("unsafe");

	}

}


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

ll n, a[1000][1000], ans = 0;

int main(){
    cin >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) cin >> a[i][j];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= i; j++){
            bool sum = 0;
            for (int k = 1; k <= n; k++){
                if (k == i || k == j) continue;
                else if (a[i][j] == a[i][k] + a[k][j]) sum = 1;
                else if (a[i][j] > a[i][k] + a[k][j]){
                    cout << -1;
                    return 0;
                }
            }
            if (!sum) ans += a[i][j];
        }
    cout << ans;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

string s;
int sum=0;

int main()
{
	cin>>s;
	rep(i,s.size()) sum+=s[i]-'0';
	if(sum%9==0) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3720
from fractions import gcd

A, B, C, D = map(int, input().split())

c_div = B//C - (A-1)//C
d_div = B//D - (A-1)//D
g = C*D // gcd(C, D)
cd_div = B//g - (A-1)//g
tot = B - A + 1
print(tot - c_div - d_div + cd_div)

Measured memory_bytes: 67052
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}

int s;
int mod=1e9+7;
int dp[5000];

int f(int temp)
{
	if(temp>s)
	return 0;
	if(temp==s)
	return 1;
	
	if(dp[temp]!=-1)
	return dp[temp];
	
	int ans=0;
	for(int i=3;i<=s;i++)
	{
		ans+=f(temp+i);
		ans%=mod;
	}
	return dp[temp]=ans;
}

int32_t main()
{
	memset(dp,-1,sizeof(dp));
	cin >> s;
	cout << f(0);	
}



Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  while(true){
  cin>>n;
  if(!n)break;
  int table[n+1][n+1];
  for(int y=0;y<n;y++){
    int s = 0;
    for(int x=0;x<n;x++){
      cin>>table[x][y];
      s+=table[x][y];
    }
    table[n][y] = s;
  }
  for(int x=0;x<n+1;x++){
    int s = 0;
    for(int y=0;y<n;y++){
      s+=table[x][y];
    }
    table[x][n] = s;
  }
  for(int y=0;y<n+1;y++){
    for(int x=0;x<n+1;x++){
      printf("%5d",table[x][y]);
    }
    printf("\n");
  }
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<algorithm>
using namespace std; 
struct qj{
    int l,r;
}game[1000005];;
bool cmp(qj a,qj b) {
    if(a.r!=b.r)return a.r<b.r;
    return a.l<b.l;
}
int f[1000005];
int i,n,temp,x,l;
int main(){
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d%d",&x,&l),game[i].l=x-l,game[i].r=x+l; 
        // scanf("%d%d",&game[i].l,&game[i].r);  
    sort(game+1,game+1+n,cmp);
    f[0]=0;
    temp=0;
    for(i=1;i<=n;i++){
        while(game[temp+1].r<=game[i].l)temp++;
        f[i]=max(f[i-1],f[temp]+1);
    }
    printf("%d\n",f[n]);
    return 0;
}

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

using namespace std;

#define tie() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define ff first
#define ss second

void solve()
{
    int n , v;cin>>n;
    int a[n] , b[n] , c[n-1];

    for(int i = 0 ; i < n ; i++) cin>>v , a[i] = v-1;

    for(int i  =0 ; i  < n ; i++) cin>>b[i];

    for(int i = 0 ;i  < n-1 ; i++) cin>>c[i];

    int s = 0;
    for(int i = 0 ; i < n ; i++)
    {
        s+=b[a[i]];
        if(i!=0 && a[i]!=0)
        {
            if(a[i-1] == a[i] - 1)
                s+=c[a[i] - 1];
        }
    }
    cout<<s<<endl;
    return;
}


int32_t main()
{
    tie();
    int t = 1;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	vars := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&vars[i])
	}
	fmt.Println(minOf(vars), maxOf(vars), sum(vars))
}

func maxOf(vars []int) int {
	sort.Ints(vars)
	return vars[len(vars)-1]
}

func minOf(vars []int) int {
	sort.Ints(vars)
	return vars[0]
}

func sum(vars []int) int {
	var sum int
	for _, num := range vars {
		sum += num
	}
	return sum
}



Measured memory_bytes: 1772
H,W=map(int,input().split())
list = []
def isAllWhite(raw):
    for char in raw:
        if char != ".":
            return(False)
    return(True)

for i in range(H):
    raw = input()
    if isAllWhite(raw):
        continue
    else:
        list.append(raw)

def isColWhite(list,col):
    L = len(list)
    for i in range(L):
        if list[i][col] != ".":
            return(False)
    return(True)

ans = [[] for _ in range(len(list))]
for j in range(len(list[0])):
    if isColWhite(list,j):
        continue
    else:
        for i in range(len(ans)):
            ans[i].append(list[i][j])
for raw in ans:
    print("".join(raw))

Measured memory_bytes: 3188
#!/usr/bin/env python3
import sys

A,B,M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
minSum = min(a) + min(b)

for i in range(M):
    x = list(map(int, input().split()))
    p = a[x[0]-1] + b[x[1]-1] - x[2]
    if p < minSum:
        minSum = p

print(minSum)


Measured memory_bytes: 18612
#include<iostream>
struct D{int a,b,c;};
main(){
  int a,b,c,N,i,w,x,y,z,m[303];
  D t[1001];
  for(;std::cin>>a>>b>>c>>N,a;){
    for(i=301;i-->0;)m[i]=2;
    for(i=0;N-->0;){
      std::cin>>w>>x>>y>>z;
      D d={w,x,y};
      if(z)m[w]=m[x]=m[y]=1;
      else t[i++]=d;
    }
    for(;i-->0;){
      if((m[t[i].a]&1)+(m[t[i].b]&1)+(m[t[i].c]&1)==2){
	m[t[i].a]&=1;
	m[t[i].b]&=1;
	m[t[i].c]&=1;
      }
    }
    for(i++;i++<a+b+c;)printf("%d\n",m[i]);
  }
}

Measured memory_bytes: 0
import copy
H,W,K=map(int,input().split())

MasuMoji=[input() for i in range(H)]  

###
def countAllmasu(masu,H,W):
  total=0
  for h in range(H):
    for w in range(W):
      total+=masu[h][w]
  return(total)
###

masu=[]
for h in range(H):
  masu.append([])
  for w in range(W):
    if MasuMoji[h][w]==".":
    	masu[h].append(0)
    else:
        masu[h].append(1)
  

H_OI=[]
for i in range(2 ** H):
    OI=[]
    #print("pattern {}: ".format(i), end="")
    for j in range(H):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            OI.append(1)  # フラグが立っていたら bag に果物を詰める
        else:
            OI.append(0)
            
    H_OI.append(OI)

  
W_OI=[]
for i in range(2 ** W):
    OI=[]
    #print("pattern {}: ".format(i), end="")
    for j in range(W):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            OI.append(1)  # フラグが立っていたら bag に果物を詰める
        else:
            OI.append(0)
            
    W_OI.append(OI)

patterns=0


for h in H_OI:
  for w in W_OI:
      
    tempmasu= copy.deepcopy(masu)

    for h2 in range(H):
      for w2 in range(W):
        if h[h2]==1 or w[w2]==1:
          tempmasu[h2][w2]=0


    #print(countAllmasu(tempmasu,H,W))
    if countAllmasu(tempmasu,H,W)==K:
      patterns+=1
      
print(patterns)

Measured memory_bytes: 72624
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
#define N 5001

int a[N];
bool dp[N][N];
bool suf[N];
int minValue[N][N];
void solve() {
	int n, k; scanf("%d %d", &n, &k);
	long long sum = 0;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]); sum += a[i];
		if (a[i] >= k) {
			a[i] = k;
		}
	}
	if (sum < k) {
		printf("%d\n", n);
		return;
	}
	dp[0][0] = true;
	for (int i = 1; i <= n; ++i) {
		for (int j = k; j >=0; --j) {
			dp[i][j] |= dp[i - 1][j];
			if (dp[i - 1][j]) {
				int go = min(k, j + a[i]);
				dp[i][go] = true;
			}
		}
	}
	for (int i = n; i >= 0; --i) {
		for (int j = k; j >= 0; --j) {
			minValue[i][j] = -1;
			if (j + 1 <= k) {
				minValue[i][j] = minValue[i][j + 1];
			}
			if (dp[i][j]) {
				minValue[i][j] = j;
			}
		}
	}

	suf[0] = true;
	int ret = 0;
	for (int i = n; i; --i) {
		int v = a[i];
		int lim = k - v;
		bool isGood = true;
		int mini = k;
		for (int j = 0; j <= k; ++j) {
			if (suf[j]) {
				int x = max(k - v - j, 0);
				if (minValue[i - 1][x] != -1) {
					int tt = minValue[i - 1][x] + j;
					mini = min(mini, tt);
				}
			}
		}
		if (mini >= k) {
			++ret;
		}
		
		for (int j = k; j >=0; --j) {
			if (suf[j]) {
				int go = min(k, j + a[i]);
				suf[go] = true;
			}
		}
	}
	printf("%d\n", ret);
}

int main()
{
	//freopen("input.txt", "r", stdin);
	solve();
	return 0;
}


Measured memory_bytes: 122368
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int ans = 1;
  int num;
  cin >> num;
  vector <int> mochis(num);
  for(int i = 0; i < num; i++)
    cin >> mochis.at(i);
  sort(mochis.begin(), mochis.end());
  //reverse(mochis.begin(), mochis.end());
  for(int i = 1; i < num; i++){
    if(mochis.at(i - 1) != mochis.at(i))
      ans++;
  }
  cout << ans << endl;
  
  
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

    vector<ll> B(N - 1, 0LL);
    for_each(B.begin(), B.end(), [](auto &b) { cin >> b; });

    vector<pair<ll, ll>> candidates;
    candidates.push_back(pair<ll, ll>(1000000, B[0]));
    for (int i = 0; i < N - 2; i++)
    {
        candidates.push_back(pair<ll, ll>(B[i], B[i + 1]));
    }
    candidates.push_back(pair<ll, ll>(B[N - 2], 1000000));

    ll res = 0;
    for (int i = 0; i < candidates.size(); i++)
    {
        pair<ll, ll> p = candidates[i];
        res += min(p.first, p.second);
    }

    cout << res << endl;

    return 0;
}

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

int main(){

  int N;
  int A[2][101];
  int ans,tmp;

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

  ans = 0;
  for(int i = 0; i<N; i++){
    tmp = 0;
    for(int j = 0; j<N; j++){
      if(j < i){
        tmp += A[0][j];
      }
      else if(j == i){
        tmp += A[0][j] + A[1][j];
      }
      else{
        tmp += A[1][j];
      }
    }
    //cout << tmp << endl;

    if(tmp > ans){
      ans = tmp;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
package main

import (
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		neg := false
		for ; '0' > b; b = rc() {
			if b == '-' {
				neg = true
			}
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		if neg {
			return -x
		}
		return
	}
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}
	gcd := func(a, b int) int {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}
	const mod int = 1e9 + 7
	pow := func(n int) int {
		res, x := 1, 2
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}

	type pair struct{ x, y int }
	cntO := 0
	cnt := map[pair]int{}
	cnt2 := map[pair]int{}
	n := r()
	for i := 0; i < n; i++ {
		x, y := r(), r()
		if x == 0 && y == 0 {
			cntO++
			continue
		}
		if y < 0 {
			x = -x
			y = -y
		} else if y == 0 {
			x = abs(x)
		}
		g := gcd(abs(x), y)
		x /= g
		y /= g
		if x > 0 {
			cnt[pair{x, y}]++
		} else {
			cnt2[pair{y, -x}]++
		}
	}

	ans := 1
	for p, c := range cnt {
		ans = ans * (pow(c) + pow(cnt2[p]) - 1) % mod
		delete(cnt2, p)
	}
	for _, c := range cnt2 {
		ans = ans * (pow(c)) % mod
	}
	Fprint(_w, (ans+cntO-1+mod)%mod)
}

func main() { run(os.Stdin, os.Stdout) }


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

const int INF = 100000000;

int main(){
  int n, ma, mb;
  cin >> n >> ma >> mb;
  vector<int> a(n), b(n), c(n);
  int maxa = 0, maxb = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i] >> b[i] >> c[i];
    if(a[i]>maxa) maxa = a[i];
    if(b[i]>maxb) maxb = b[i];
  }

  vector<vector<vector<int> > > dp(n+1, vector<vector<int> >(maxa*(n+1), vector<int>(maxb*(n+1), INF)));
  dp[0][0][0] = 0;
  int min = INF;
  for(int i = 0; i < n; i++){
    for(int ca = 0; ca < maxa*n; ca++){
      for(int cb = 0; cb < maxb*n; cb++){
        if(dp[i+1][ca][cb] > dp[i][ca][cb])
          dp[i+1][ca][cb] = dp[i][ca][cb];
        if(dp[i+1][ca+a[i]][cb+b[i]] > dp[i][ca][cb]+c[i])
          dp[i+1][ca+a[i]][cb+b[i]] = dp[i][ca][cb]+c[i];
      }
    }
  }
  for(int i = 1; ma*i < maxa*n && mb*i < maxb*n; i++){
    if(dp[n][ma*i][mb*i] < min) min = dp[n][ma*i][mb*i];
  }
  if(min == INF) cout << -1 << endl;
  else cout << min << endl;
}


Measured memory_bytes: 28416
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int mod_pow(int x,int y){
	int res=1;
	while(y>0){
		if(y&1)res*=x;
		x*=x;
		res%=mod;x%=mod;
		y>>=1;
	}
	return res;
}
bool prime(int x){
	for(int i=2;i*i<=x;i++){
		if(x%i==0)return false;
	}
	return x!=1;
}
int h,w,d;
pair<int,int>po[200000];
int sum[200000];
void init(){
	for(int i=0;i<h*w;i++){
		sum[i+d]=sum[i]+abs(po[i].first-po[i+d].first)+abs(po[i].second-po[i+d].second);
	}
}
signed main(){
	cin>>h>>w>>d;
	rep(i,h)rep(j,w){
		int a;cin>>a;a--;
		po[a]={i,j};
	}
	init();
	int q;cin>>q;
	while(q--){
		int l,r;cin>>l>>r;l--;r--;
		cout<<sum[r]-sum[l]<<endl;
	}
}


Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
typedef long long ll;

int n,m;
int a[100001],b[100001],t;
int fa[100001];
int ff(int x){return fa[x]?fa[x]=ff(fa[x]):x;}
ll Sum;

int main(){
	int x,y;
	scanf("%d%d",&n,&m);
	if(m==n-1) return puts("0"),0;
	F(i,1,n) scanf("%d",a+i), Sum+=a[i];
	F(i,1,m){
		scanf("%d%d",&x,&y);
		x=ff(x+1); y=ff(y+1);
		Sum-=max(a[x],a[y]);
		b[++t]=max(a[x],a[y]);
		if(a[x]>a[y]) fa[x]=y;
		else fa[y]=x;
	}
	if(t<n-m-2) return puts("Impossible"),0;
	sort(b+1,b+t+1);
	F(i,1,n-m-2) Sum+=b[i];
	printf("%lld",Sum);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;
#define pi 3.14159265358979

int main()
{
	string s;
	int minDiff = 1000;	//753からの最小の差
	int xSize = 3;		//比較する文字列Xは3文字
	int number = 753;	//比較対象の数字
	cin >> s;			//入力を受け取る

	rep(i, s.length() - xSize + 1)
	{
		int diff = abs(stoi(s.substr(i, xSize)) - number);	//選んだ数字との差の絶対値を計算
		if (diff < minDiff) minDiff = diff;					//もし753との差が最小なら保存
	}
	cout << minDiff << endl;
	return 0;
}

Measured memory_bytes: 3628
N = int(input())
A = list(map(int, input().split()))
s = [0] * (10**5+5)
Q = int(input())
total = sum(A)

for i in A:
    s[i] += 1

for _ in range(Q):
    B, C = map(int, input().split())
    d = s[B]
    s[B] = 0
    s[C] += d
    total += (C-B) * d
    print(total)


Measured memory_bytes: 21028
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

const int mx = 100005;
int dp[6][mx];

int main(){
    int n;
    cin >> n;
    int v = static_cast<int>(n/1.08);
    
    if (v*1.08==n) {
        cout << v << endl;
    }
    else if ((v+1)*1.08>n && (v+1)*1.08<n+1){
        cout << v+1 << endl;
    }
    else {
        cout << ":(" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
  private static boolean solve(String a, String b) {
    int n = Integer.parseInt(a + b);
    for (int i = 1; i * i <= n; i++) {
      if (i * i == n) {
        return true;
      }
    }
    return false;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    String a = reader.next();
    String b = reader.next();
    out.println(solve(a, b) ? "Yes" : "No");
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


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

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>

using namespace std;

typedef pair<int,int> Paint;

bool Pairsecond(const Paint& pf,Paint&ps){//sortCompare
  return pf.second < ps.second;
}

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)
#define pb push_back
#define MAX 1000000000
#define MOD 1000000007


/*
確認ポイント
cout<< (char)数値 //数値にあった文字に置き換えられる
cout<< (double)int型/(2など)//小数になる
length(),size()に括弧をつけ忘れてないか;
sort()が使える型//vector,string...
YesNo大文字小文字間違えてないか
cout << fixed << 小数計算//正しい小数表記になる(基本6桁)(e記法回避にも使える)
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
sqrt(数値型)でrootが取れる
vector.unique()は隣接した同じ要素を削除するので先にソートをする
*/
int main() { 
  int n;cin>>n;
  int b[n-1];
  for(int i = 0; n-1 > i; i++){
    cin>>b[i];
  }
  vector<int> a;
  a.push_back(10000000);
  for(int i = 0; n-1 > i; i++){
    a[a.size()-1]=min(a[a.size()-1],b[i]);
    a.push_back(b[i]);
  }
  int sm = 0;
  for(int i = 0; n > i; i++){
    sm += a[i];
    //cout << a[i] << endl;
  }
  cout << sm << endl;
  return 0;
}




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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL x, y;

int main() {
	cin >> x >> y;
	
	cout << (x % y == 0 ? -1 : x) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define mod1 998244353
#define Mmax 1000005
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
bool comp(pair<li,pair<li,li>>a,pair<li,pair<li,li>>b)
{
  if(a.first<b.first)
  return 1;
  else if(a.first>b.first)
  return 0;
  else
  {
    return a.second.first<b.second.first;
  }
}
li mpow(li x,li y)
{
  li ans=1;
  while(y)
  {
    if(y%2!=0)
    ans=(ans%mod)*(x%mod)%mod;
    y/=2;
    x=((x%mod)*(x%mod))%mod;
  }
  return ans;
}
void bfs(vector<li>v[],li visit[],li s,li ans[])
{
  deque<li>q;
  q.push_back(s);
  visit[s]=1;
  while(!q.empty())
  {
    li x=q.front();
    q.pop_front();
    for(auto i=v[x].begin();i!=v[x].end();i++)
    {
      if(!visit[*i])
      {
        q.push_back(*i);
        visit[*i]=1;
      }
    }
  }
}
void dfs(vector<li>v[],li visit[],li s)
{
  visit[s]=1;
  cout<<s<<" ";
    for(auto i=v[s].begin();i!=v[s].end();i++)
    {
      if(!visit[*i])
      {
        dfs(v,visit,*i);
      }
    }
}
vector<li>factor(li n)
{
  vector<li>v;
  if(n%2==0)
  {
    while(n%2==0)
    n/=2;
    v.push_back(2);
  }
  for(li i=3;i<=sqrt(n);i+=2)
  {
    if(n%i==0)
    {
      while(n%i==0)
      n/=i;
      v.push_back(i);
    }
  }
  if(n>1)
  v.push_back(n);
  return v;
}
int main()
{
fast_io
li a,b,c,d,p=1;
cin>>a>>b>>c>>d;
while(a>0&&c>0)
{
  if(p)
  {
    c-=b;
    p=0;
  }
  else
  {
    a-=d;
    p=1;
  }
}
if(a>0)
cout<<"Yes";
else
cout<<"No";
return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

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

	int r = 0;
	fx(N) {
		if (S[x] == 'R')r++;
	}

	int ans = 0;
	fx(r) {
		if (S[x] == 'W')ans++;
	}
	ce(ans)
	
    return 0;
}



Measured memory_bytes: 3720
import Data.List

main = do
    n <- readLn
    as <- getInts
    print $ solve n as

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: Int -> [Int] -> Int
solve n as | odd (n-m) = m-1
           | otherwise = m
    where m = length $ group $ sort as


Measured memory_bytes: 33276
const main = (input) => {
  var inputs = input.trim().split("");
  var ansa = ansb = 0;  // ansa 010101,  ansb 101010
  for(var i=0;i<inputs.length;i++){
    var pt = inputs[i]-0;
    if(i%2==0){
      if(pt==1) ansa++;
      else ansb++;
    }else{
      if(pt==0) ansa++;
      else ansb++;
    }
  }
  console.log(Math.min(ansa,ansb));
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 8396
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 16:33:03 2020

@author: shinba
"""


n = int(input())
a = list(map(int,input().split()))
cnt = 0
st = 1
for i in range(n):
    if a[i] == st:
        st += 1
    else:
        cnt += 1

if 1 in a:
    print(cnt)
else:
    print(-1)
    
    

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

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

	sort(a.begin(), a.end());

	int ans = 0;
	for (int i = 0; i < k; i++) {
		ans += a[n - 1 - i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
using namespace std;
 
int main(void){
  int a[2],sw=0;
  a[0]= a[1] = 0;
  
  string S;
  cin >>S;
  int length = S.length();
  char before = S[0];
  a[0]++;
  for(int i=1;i<length;i++){
  	if(S[i] != before){
      a[sw]++;
    }else {
     sw = 1-sw;
      a[sw]++;
    }
    before = S[i];
  }
  if( a[0] > a[1])cout<<a[1];
  else cout<<a[0];
    return 0;
}

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

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

using namespace std;
using lint=long long;

const lint INF=1LL<<61;

int main(){
	int n; scanf("%d",&n);

	vector<int> cnt(n);
	rep(i,n){
		int a; scanf("%d",&a); a--;
		cnt[a]++;
	}

	sort(cnt.begin(),cnt.end());

	vector<int> next(n);
	next[n-1]=n;
	for(int i=n-2;i>=0;i--) next[i]=(cnt[i]<cnt[i+1]?i+1:next[i+1]);

	lint sum=0;
	rep(i,n) sum+=cnt[i];

	rep(i,n){
		lint ans=0,tmp=sum,last=0,d=1;
		int pos=n-i;
		while(pos<n && tmp>d*(cnt[pos]-last)){
			tmp-=d*(cnt[pos]-last);
			ans+=cnt[pos]-last;
			last=cnt[pos];
			d+=next[pos]-pos;
			pos=next[pos];
		}
		ans+=tmp/d;
		printf("%lld\n",ans);
		sum-=cnt[n-i-1];
	}

	return 0;
}


Measured memory_bytes: 3200
N = int(input())
streak = 0
max_streak = 0
for _ in range(N):
    D1, D2 = input().split()
    if D1==D2:
        streak += 1
        max_streak = max(max_streak, streak)
    else:
        streak = 0

print('Yes' if max_streak>=3 else 'No')


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

using namespace std;
typedef long long ll;

const int N = int(1e5) + 7;

void init() {

}

void solve() {
	int n; scanf("%d", &n);
	vector<int> v(1);
	scanf("%d", &v[0]);
	v[0] = -v[0];
	for (int i = 0; i < n - 1; i++) {
		int p; scanf("%d", &p);
		vector<int>::iterator it = upper_bound(v.begin(), v.end(), -p);
		if (it == v.end()) v.push_back(-p);
		else *it = -p;
	}
	printf("%d\n", v.size());

}

const bool mtc = false;

int main() {
	int t;
	if (mtc) {
		scanf("%d", &t);
		while (t--) solve();
	}
	else solve();
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
// For policy based data structure
/*#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
/*using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set;*/
 
#define MD 1000000007
#define X first
#define Y second
#define pb push_back
#define debug(val, ch) cout <<val <<ch
 
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<int, bool> pib;
typedef pair<bool, int> pbi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
/*********************************************************************/
void test(int r)
{
	int d,t,s;
	cin>>d>>t>>s;
	int a=0;
	a=d/s;
	if(d%s)
		a++;
	if(a>t)
		cout<<"No";
	else
		cout<<"Yes";
	

}
/***********************************************************************/
int main()
{
	fast();
    int t=1,r;
    // cin>>t;
    for(r=1;r<=t;r++)
        test(r);
    return 0;
}

Measured memory_bytes: 3636
#pragma GCC optimize("O3")

#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;

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    map<ll,ll> freq;
    ll tot=0;
    int n;
    cin >> n;
    F0R(i,n) {
        int e;
        cin >> e;
        freq[e]++;
        tot+=e;
    }
    int tt;
    cin >> tt;
    while(tt--) {
        ll b,c;
        cin >> b >> c;
        if(freq.find(b)==freq.end()) {
            cout << tot << "\n";
            continue;
        }
        tot-=freq[b]*b;
        tot+=freq[b]*c;
        freq[c]+=freq[b];
        freq.erase(b);
        cout << tot << "\n";
    }

    return 0;
}


Measured memory_bytes: 7512
import re
s=input()
n=len(s)
ans=0
for i in range(n):
  for j in range(n):
    S=s[i:j+1]
    #print(S)
    m=re.fullmatch(r'[ATCG]+',S)
    #print(m)
    if m!=None:
      ans=max(ans,len(S))
print(ans)

Measured memory_bytes: 9796
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#include <bits/stdc++.h>
using namespace std;

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    ppl                      pair <int , pii>               
#define    sp(x)                    setprecision(x)

int32_t main()
{
    speed upp
    int a,b;
    cin>>a>>b;
    cout<<6-a-b;
}

Measured memory_bytes: 256