akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            int C = sc.nextInt();
            int D = sc.nextInt();

            for (;;) {
                C -= B;
                if (C <= 0) {
                    System.out.println("Yes");
                    return;
                }
                A -= D;
                if (A <= 0) {
                    System.out.println("No");
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 27048
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
a_hash = [[False, False, False] for _ in range(3)]
 
for i in b:
    for ind, j in enumerate(a):
        if i in j:
            a_hash[ind][j.index(i)] = True
 
for i in a_hash:
    if all(i):
        print("Yes")
        exit()
 
if a_hash[0][0] and a_hash[1][1] and a_hash[2][2]:
    print("Yes")
    exit()
elif a_hash[0][2] and a_hash[1][1] and a_hash[2][0]:
    print("Yes")
    exit()
 
for num in range(3):
    if a_hash[0][num] and a_hash[1][num] and a_hash[2][num]:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
string s;
vector<int> bucket[200];
int main()
{
	cin >> s;
	int n = s.size();
	for(int i = 0; i < n; i ++)
		bucket[s[i]].push_back(i + 1);
	int ans = 11111111;
	for(int i = 'a'; i <= 'z'; i ++)
		if(bucket[i].size())
		{
			bucket[i].push_back(0);
			bucket[i].push_back(n + 1);
			sort(bucket[i].begin(), bucket[i].end());
			int now = 0;
			for(int j = 1; j < bucket[i].size(); j ++)
				now = max(bucket[i][j] - bucket[i][j - 1] - 1, now);
			ans = min(ans, now);
		}
    cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
#define fs first
#define sc second

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

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

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


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

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

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

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

vector<pair<long long, long long> > prime_factorize(long long n) { //素因数分解、pairのfirstに底、secondに底の何乗
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> is(26);
    rep(i, n) is[s[i] - 'a'].insert(i);
    rep(qi, q){
        int ty;
        cin >> ty;
        if (ty == 1){
            int i; char c;
            cin >> i >> c;
            --i;
            is[s[i] - 'a'].erase(i);
            s[i] = c;
            is[s[i] - 'a'].insert(i);
        } else {
            int l, r;
            cin >> l >> r;
            --l;
            int ans = 0;
            rep(i, 26){
                auto it = is[i].lower_bound(l);
                if(it != is[i].end() && *it < r) ++ans;
            }
            print(ans);
        }
    } 


}



Measured memory_bytes: 24220
using System;

class MainClass
{
    public static void Main(string[] args)
    {
        
        //string[] s1 = Console.ReadLine().Split(' ');

        //long N = long.Parse(s1[0]);
        //long K = long.Parse(s1[1]);

        long N = long.Parse(Console.ReadLine());
        string[] s1 = Console.ReadLine().Split(' ');
        string[] s2 = Console.ReadLine().Split(' ');


        //long K = long.Parse(Console.ReadLine());
        long[,] a = new long[2,N];
        //long[] b = new long[N];

        for (int i = 0; i < N;i++)
        {
            //string[] s2 = Console.ReadLine().Split(' ');
            a[0,i] = long.Parse(s1[i]);
            a[1, i] = long.Parse(s2[i]);
            //b[i] = long.Parse(s1[1]);
        }

        long[] sum = new long[N];

        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j <= i;j++)
            {
                sum[i] += a[0, j];
            }

            for (int j = i; j < N; j++)
            {
                sum[i] += a[1, j];
            }
                
        }

        Array.Sort(sum);
        Array.Reverse(sum);

        Console.WriteLine(sum[0]);

    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    vector< vector<int> > V;
    string s;
    while(getline(cin,s))
    {
        string val;
        stringstream ss(s);
        vector<int> x;
        while(getline(ss,val,','))
        {
            x.push_back(atoi(val.c_str()));
        }
        V.push_back(x);
    }
     
    for(int i=1;i<V.size()/2+1;i++)
    {
        for(int l=0;l<V[i].size();l++)
        {
            int a=0,b=0;
            if(l)a=V[i-1][l-1];
            if(l!=V[i].size()-1)b=V[i-1][l];
            V[i][l]+=max(a,b);
        }
    }
    for(int i=V.size()/2+1;i<V.size();i++)
    {
        for(int l=0;l<V[i].size();l++)
        {
            V[i][l]+=max(V[i-1][l],V[i-1][l+1]);
        }
    }
    for(int i=0;i<V.size();i++)
    {
        for(int l=0;l<V[i].size();l++)
        {
            //printf("%3d",V[i][l]);
        }
        //cout<<endl;
         
    }
     
     
     
    cout<<V.back().back()<<endl;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
double  p[3005], dp[3005], ans;
ll n;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	for (ll i = 1; i<= n; i++)cin >> p[i];
	dp[0] = 1;
	for (ll i= 1; i <= n; i++){
		for (ll j = i; j >= 0; j--){
			//going for all values that can be modified
			//~ if (j == 0)dp[j] = dp[j]*((double)1-p[i]);
			dp[j] = dp[j]*((double)1-p[i]) + (j == 0 ? 0:dp[j-1]*p[i]);
			
		}
	}//dp[i] stores the probability of having i heads up till this point
	for (ll i = 0; i <= n; i++){
		ll tails = n-i;
		if (i > tails)ans += dp[i];
	}
	cout << setprecision(20) << ans;
	//~ for (ll i= 0; i <= n; i++)cout << dp[i] << ' ';
	//~ cout << dp[n/2+1];
}


Measured memory_bytes: 256
N = int(input())
a = []
b = []
w = {}
for _ in range(N):
    A,B = list(map(int,input().split()))
    a.append(A)
    b.append(B)
for i,c in enumerate(b):
    if not c in w.keys():
        w[c] =  [i]
    else:
        w[c].append(i)
#print(a)
#print(w)
wt = 0
for t in sorted(w.keys()):
    #print('clock:',t)
    #print(w[t])
    for k in w[t]:
        wt += a[k]
    else:
        pass
        #print(k,wt)
    if t >= wt:
        pass
    else:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 57932
list = input().split(" ")
a, b, c, d = int(list[0]), int(list[1]), int(list[2]), int(list[3])
ans1 = a * c
ans2 = a * d
ans3 = b * c
ans4 = b * d
ans_list = [ans1, ans2, ans3, ans4]
ans_list.sort()
print(ans_list[3])
              

Measured memory_bytes: 9188
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <numeric>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


//複数のソート
void sort2vectors(vector<int> &av, vector<int> &bv)
{
        int n = av.size();
        vector<int> p(n), av2(n), bv2(n);
        iota(p.begin(), p.end(), 0);
        sort(p.begin(), p.end(), [&](int a, int b) { return av[a] < av[b]; });
        for (int i = 0; i < n; i++) {
                av2[i] = av[p[i]];
                bv2[i] = bv[p[i]];
        }
        av = av2;
        bv = bv2;
}

//最大公約数
int gcd(int a, int b)
{
    int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

//最小公倍数
int lcm(int x, int y)
{
    return (x * y / gcd(x, y));
}

int isPrime(int x){
  int i;
  if(x < 2) return 0;
  else if(x == 2) return 1;
  if( x%2 == 0) return 0;
  for(i = 3; i*i <= 2; i += 2){
    if(x%i == 0) return 0;
  }
  return 1;
}


const int pmax = 10000000;
bool isPrime_table[pmax];
//constがないと配列宣言できない

void eratos(void){
  int i, j;
  double sqrtmax=sqrt(pmax);

  REP(k, pmax) isPrime_table[k] = true; /* Initialization */

  /* Sieve process  */
  isPrime_table[0] = false;
  isPrime_table[1] = false;
          /* 0 and 1 are not prime. */
  for (i=2; i <= sqrtmax; i++){
    if (isPrime_table[i]==true){   /* i is prime. */
      for (j=i; i*j<pmax; j++){
        isPrime_table[i*j] = false; /* multiples of i are not prime. */
      }
    }
  }
}

//漸化式敵に記述も可能
//abs(dx[i]+dy[j])==1で四方
int dx[3]={-1, 0, 1};
int dy[3]={-1, 0, 1};
int W0, H0;
int  masu0[100][100]={0};
int cnt0;

int dfs(int a, int b){
  masu0[a][b] = 2;
  REP(i, 3)REP(j, 3){
    a = a+dx[i];
    b = b+dy[j];
    if(masu0[a][b]== 1 && a >= 0 && a < W0 && b >= 0 && b < H0){
    dfs(a, b);
  }
  }
  return 1;
}

//文字列取り出し　str.substr(i, 5)
//文字数字変換 stoi, stod とto_string
//初期化memset
//複数配列のソート
//dp
//mapとsetのサイズ
//str.find std::npos
//autoの後の&の数
//大文字小文字変換　tolower touuper
//文字列の反転
const string abet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");

static const long long int MOD = 1000000007;

static const double PI=3.1415926535897932;

char s[11];
ll res = 0;
int p[11], sz = 0;

void solve(int a, ll b, ll c){
  if(!s[a]){
    res += b+c;
    return;
  }
  solve(a+1, b+c, s[a]-'0');
  solve(a+1, b, (s[a]-'0')+c*10);
}


int main(void){

  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s;

  solve(0, 0, 0);

  cout << res/2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
const int MAX = 100005;

int main() {
	int N;
	cin >> N;
	vector<int> A(MAX);
	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;
		A[x]++;
	}

	int Q;
	cin >> Q;
	long long ans = 0;
	for (int i = 0; i < MAX; i++) {
		ans += i * A[i];
	}

	for (int i = 0; i < Q; i++) {
		int B, C;
		cin >> B >> C;
		ans += (C - B) * A[B];
		A[C] += A[B];
		A[B] = 0;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(c) (c).begin(), (c).end()
#define REVERSE(c) reverse(ALL(c))
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort(ALL(c))
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


inline bool check(LL x, LL y, VS& A, VS& B) {
    REP(i, SZ(B)) {
        REP(j, SZ(B)) {
            if (A[x + i][y + j] != B[i][j]) {
                return false;
            }
        }
    }
    return true;
}


int main() {
    LL N, M;
    cin >> N >> M;
    VS A(N), B(M);
    REP(i, N) {
        cin >> A[i];
    }
    REP(i, M) {
        cin >> B[i];
    }
    REP(i, N - M + 1) {
        REP(j, N - M + 1) {
            if (check(i, j, A, B)) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
	cout << "No" << endl;
    return 0;
}


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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

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

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	int a, b, c, d;
	sf("%d %d %d %d", &a, &b, &c, &d);
	int x = (int) ceil((float)c / b);
	int y = (int) ceil((float)a / d);
	puts(x <= y ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 3696
while 1:
	x=input()
	if x=="0":
		break
	a=0
	b=0
	for i in range(1,len(x)):
		if x[i]=="A":
			a+=1
		else:
			b+=1
	if a>b:
		a+=1
	else:
		b+=1
	print(a,b)


Measured memory_bytes: 5552
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0

for i in range(0, a+1):
    for j in range(0, b+1):
        for k in range(0, c+1):
            if 500*i + 100*j + k*50 == x:
                count += 1

print(count)

Measured memory_bytes: 9192
#include<iostream>
using namespace std;
int main(){
	char a[100001];
	int ans=0;
	cin>>a;
	if(a[0]!='C') ans++;
	if(a[1]!='O') ans++;
	if(a[2]!='D') ans++;
	if(a[3]!='E') ans++;
	if(a[4]!='F') ans++;
	if(a[5]!='E') ans++;
	if(a[6]!='S') ans++;
	if(a[7]!='T') ans++;
	if(a[8]!='I') ans++;
	if(a[9]!='V') ans++;
	if(a[10]!='A') ans++;
	if(a[11]!='L') ans++;
	if(a[12]!='2') ans++;
	if(a[13]!='0') ans++;
	if(a[14]!='1') ans++;
	if(a[15]!='6') ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  string a,b;
  cin >> a >> b;
  if(a<b) {
    cout << "<" << endl;
  }
  else if(a>b) {
    cout << ">" << endl;
  }
  else {
    cout << "=" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef vector <int> vi;
typedef pair<double,double> pd;
typedef vector <pd > vp;
vp D;
vi A;

int side(pd p1, pd p2){
	double dy=p2.first-p1.first,dx=p2.second-p1.second;
	for(int i=0;i<(int)D.size();i++){
		pd p3=D[i];
		if (p1==p3||p2==p3)continue;
		if ((p3.second-p1.second)*dy-dx*(p3.first-p1.first)<0) return 0;
	}
    return 1;
}

int main(){
	while (1){
		int n,i,s;
		pd p,p1,p2;
		char c;
		cin>>n;
		if (n==0) break;
		for (i=0;i<n;i++){
			cin>>p.first>>c>>p.second;
			D.push_back(p);
			A.push_back(0);
		}
		sort(D.begin(),D.end());
		p=D[0];
		p1=p;
		s=0;
		while (1){
			for (i=0;i<n;i++){
				p2=D[i];
				if (A[i]==0 && p1!=p2 && side(p1,p2)) break;
			}
			p1=p2;
			A[i]=1;
			s++;
			if (p2==p) break;
		}
		cout<<D.size()-s<<"\n";
		D.clear();
		A.clear();
	}
}

Measured memory_bytes: 1260
#include <iostream>
#define MAXINT 0x3F3F3F3F

using namespace std;

int n;
int a[101];
int mn;

int main() {
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	mn = MAXINT;
	for(int i = -100; i <= 100; i++) {
		int res = 0;
		for(int j = 0; j < n; j++) {
			res += (a[j] - i) * (a[j] - i);
		}
		mn = min(mn, res);
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0]*(W+1) for _ in range(2)]

for i in range(N):
    wi, vi = wv[i]
    
    for j in range(W+1):
        if j-wi>=0:
            dp[(i+1)&1][j] = max(dp[i&1][j], dp[i&1][j-wi]+vi)
        else:
            dp[(i+1)&1][j] = dp[i&1][j]

print(dp[N&1][W])

Measured memory_bytes: 43500
void main(){
	string s = readln().chomp().dup().reverse();
	string[] chk = ["remaerd", "maerd", "resare", "esare"];
	bool is_continue = true;
	while(is_continue){
		foreach(i,elm; chk){
			if(s.indexOf(elm)==0){
				s = s[elm.length..$];
				break;
			}
			// 最後まで見つからなければ終わり
			else if(i==3)is_continue = false;
		}
	}
	writefln("%s", s.length==0? "YES":"NO");
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


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

int main() {
	
	int h,w;
	cin>>h>>w;
	
	char a[h][w];
	char x;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			cin>>a[i][j];
		
	int dp[h][w] {0};	
	if(a[0][0]=='#')
		dp[0][0]=1;
		
	for(int j=1;j<w;j++)
	{
		if(a[0][j]=='#' && a[0][j-1]=='.')
			dp[0][j]=dp[0][j-1]+1;
		else
			dp[0][j]=dp[0][j-1];
	}
	for(int i=1;i<h;i++)
	{
		if(a[i][0]=='#' && a[i-1][0]=='.')
			dp[i][0]=dp[i-1][0]+1;
		else
			dp[i][0]=dp[i-1][0];
	}
	
	for(int i=1;i<h;i++)
		for(int j=1;j<w;j++)
			{
				dp[i][j]=min((a[i][j]=='#' && a[i-1][j]=='.')?dp[i-1][j]+1:dp[i-1][j], (a[i][j]=='#' && a[i][j-1]=='.')?dp[i][j-1]+1:dp[i][j-1]);
			}
			
	cout<<(dp[h-1][w-1])<<endl;
	/*for(int i=0;i<h;i++)
	{for(int j=0;j<w;j++)
	cout<<dp[i][j];
	cout<<endl;}*/
	
	// your code goes here
	return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    n = int(input())
    a = list(map(int, input().split()))

    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i, ae in enumerate(a):
        d1[i + ae +1] += 1
        d2[i - ae +1] += 1
    r = 0
    for d1e in d1.keys():
        rt = d1[d1e] * d2[d1e]
        r += rt
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 73732
def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    s = input().rstrip()

    pattern1 = 0
    pattern2 = 0

    for i, c in enumerate(s):
        if i % 2 == 0:
            if c == "0":
                pattern1 += 1
            else:
                pattern2 += 1
        else:
            if c == "0":
                pattern2 += 1
            else:
                pattern1 += 1

    print(min(pattern1, pattern2))

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 73328
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int a,b;
  while(cin>>a>>b,a||b){
    int co=0;
    loop(i,1,a+1)
      loop(j,1,a+1)
      loop(k,1,a+1)if(i!=j&&j!=k&&k!=i&&i+j+k==b)co++;//cout<<i<<" "<<j<<" "<<k<<endl;
    cout<<co/6<<endl;
  }
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> Pair;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll n, m;
VL c;
vector<VL> dp;

int main() {
    cin >> n >> m;
    REP(i, m) c.emplace_back(IN());
    dp.assign(m + 1, VL(n + 1, LINF));
    dp[0][0] = 0;
    REP(i, m) REP(j, n + 1) {
        if(j < c[i])
            dp[i + 1][j] = dp[i][j];
        else
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - c[i]] + 1);
    }
    cout << dp[m][n] << "\n";
}



Measured memory_bytes: 11620
// https://atcoder.jp/contests/abc116/tasks/abc116_a
// +build ignore

package main

import (
	"fmt"
	"sort"
)

func main() {
	var area int
	sides := make([]int, 3)
	for i := 0; i < 3; i++ {
		fmt.Scan(&sides[i])
	}
	sort.Sort(sort.IntSlice(sides))
	area = (sides[0] * sides[1]) / 2
	fmt.Println(area)
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 400010;
struct node{
	int pre, to;
}edge[N];
int head[N], tot;
int n;
int out[N];
void add(int u, int v) {
	edge[++tot] = node{head[u], v};
	head[u] = tot;
}
int main() {
	cin >> n;
	for (int i = 2; i <= n; i++) {
		int a;
		cin >> a;
		add(a, i);
		out[a]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << out[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 6756
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 

int main(){
	int N, Q;
	string S;
	cin >> N >> S >> Q;
	//a~zについてそれぞれの文字がSで位置するindexの数列が昇順に入る
	vector<set<int>> st(26);

	for(int i=0; i<N; i++){
		int mozi = S[i] - 'a';
		st[mozi].insert(i);
	}

	for(int i=0; i<Q; i++){
		int num;
		cin >> num;
		if(num==1){
			int index;
			char c;
			cin >> index >> c;
			index--;
			int del_mozi = S[index] - 'a';
			st[del_mozi].erase(index);
			S[index] = c;
			int insert_mozi = c - 'a';
			st[insert_mozi].insert(index);
			continue;
		}
		//以下num==2の場合
		int l, r;
		cin >> l >> r;
		l--; r--;
		int ans = 0;
		for(int mozi=0; mozi<26; mozi++){
			auto iter = st[mozi].lower_bound(l);
			if(iter == st[mozi].end()) continue;
			int place = *iter;
			//cout << " *iter: " << *iter << endl;
			if(l <= place && place<=r) ans++;
		}
		cout << ans << endl;

	}

}


Measured memory_bytes: 27172
#include <bits/stdc++.h>
#define MOD 1000000007
// #define MOD 998244353
#define pb push_back
#define ll long long
#define ld long double
#define ft first
#define sd second
using namespace std;

const int N = 5000 + 9;
pair<ll, ll> a[N];
ll dp[N][N];

signed main() {

    // freopen("out.txt","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i].ft >> a[i].sd;
    }
    sort(a + 1, a + n + 1, [&](auto l, auto r) {
        return l.ft + l.sd < r.ft + r.sd;
    });
    dp[1][1] = a[1].sd;
    for(int i = 2; i <= n; i++) {
        dp[i][1] = min(dp[i-1][1], a[i].sd);
        for(int j = 2; j <= i; j++) {
            dp[i][j] = dp[i-1][j] > 0 ? dp[i-1][j] : (ll)1e14;
            if(dp[i-1][j-1] <= a[i].ft) {
                dp[i][j] = min(dp[i][j], dp[i-1][j-1] + a[i].sd);
            }
        }

    }
    // cout << dp[2][2] << endl;
    for(int j = n; j > 0; j--) {
        if(dp[n][j] != 0 && dp[n][j] < 1e11) {
            cout << j << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 194176
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const long long MOD = 1e9 + 7;

class Combination {
    //a^p%mod
    ll powmod(ll a, ll p) {
        ll ans = 1LL;
        ll mul = a;
        // p >>=1 <-> p=(p >> 1)
        for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
            if ((p & 1) == 1) ans = (ans * mul) % mod;
        }

        return ans;
    }
public:
    int N;
    ll mod;
    vector<ll> fact;
    vector<ll> revFact;

    Combination(int n, ll m) : N(n), mod(m), fact(n+1), revFact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= N; i++) {
            fact[i] = fact[i-1] * i;
            fact[i] %= mod;
        }

        // Fermat's little theorem
        revFact[N] = powmod(fact[N], mod - 2);

        for (int i = N-1; i >= 0; i--) {
            revFact[i] = revFact[i+1] * (i+1);
            revFact[i] %= mod;
        }
    }

    ll get(int a, int b) {
        if (a < 0 || b < 0) return 0;
        if (b > a) return 0;
        return (((fact[a] * revFact[b]) % mod) * revFact[a-b]) % mod;
    }
};

int main(){
  int N;
  cin >> N;
  int a[N + 1];
  for(int i = 0; i < N + 1; i++) cin >> a[i];

  int cnt[N];
  fill(cnt, cnt + N, 0);
  for(int i = 0; i < N + 1; i++) cnt[a[i] - 1]++;

  int num;
  for(int i = 0; i < N; i++){
    if(cnt[i] == 2){
      num = i + 1;
      break;
    }
  }

  vector<int> pos;
  for(int i = 0; i < N + 1; i++){
    if(a[i] == num) pos.push_back(i);
  }

  int c = pos[0] + (N - pos[1]);

  Combination cm = Combination(N + 5, MOD);

  for(int k = 1; k <= N + 1; k++){
    ll ans = cm.get(N + 1, k);
    ans -= cm.get(c, k - 1);
    if(ans < 0) ans += MOD;

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3584
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static int A, B, C, N;
    static int[] L;
    static List<Integer> listA = new ArrayList<>(), listB = new ArrayList<>(), listC = new ArrayList<>();
    static int min = Integer.MAX_VALUE;

    static void solve(Scanner scanner) {
        N = Integer.parseInt(scanner.next());
        A = Integer.parseInt(scanner.next());
        B = Integer.parseInt(scanner.next());
        C = Integer.parseInt(scanner.next());
        L = new int[N];
        for (int i = 0; i < N; i++) {
            L[i] = Integer.parseInt(scanner.next());
        }

        dfs(0);
        System.out.println(min);
    }

    private static void dfs(int i) {
        if (i == N) {
            // calc
            if (listA.isEmpty() || listB.isEmpty() || listC.isEmpty()) {
                return;
            }
            int cost = 0;
            cost += 10 * (listA.size() - 1 + listB.size() - 1 + listC.size() - 1);
            {
                int sum = 0;
                for(int n: listA) {
                    sum += n;
                }
                cost += Math.abs(A - sum);
            }
            {
                int sum = 0;
                for(int n: listB) {
                    sum += n;
                }
                cost += Math.abs(B - sum);
            }
            {
                int sum = 0;
                for(int n: listC) {
                    sum += n;
                }
                cost += Math.abs(C - sum);
            }
            min = Math.min(min, cost);
            return;
        }

        listA.add(L[i]);
        dfs(i + 1);
        listA.remove(listA.size() - 1);

        listB.add(L[i]);
        dfs(i + 1);
        listB.remove(listB.size() - 1);

        listC.add(L[i]);
        dfs(i + 1);
        listC.remove(listC.size() - 1);

        dfs(i + 1);
    }

}



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

using namespace std;

using Weight = int;

struct Edge {
    int src, dst, rev;
    Weight weight;
    Edge(int f, int t, Weight c, int rev = 0) :
        src(f), dst(t), rev(rev), weight(c) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

class Dinic {
public:
    Dinic(const int n) : n(n), g(n) {}
    void add_edge(const int src, const int dst, const Weight cap) {
        g[src].emplace_back(Edge(src, dst, cap, g[dst].size()));
        g[dst].emplace_back(Edge(dst, src, 0, g[src].size() - 1));
    }

    Weight MaximumFlow(const int s, const int t) {
        Weight flow = 0;

        while(true) {
            vector<int> level(n, -1), iter(n);
            Bfs(level, s);

            if(level[t] < 0) break;
            Weight f = 0;
            while((f = Dfs(level, iter, s, t, INF)) > 0)
                flow += f;
        }

        return flow;
    }

private:
    const Weight INF = 1e8;
    int n;
    Graph g;

    void Bfs(vector<int> &level, const int s){
        level[s] = 0;
        queue<int> que;
        que.push(s);
        while(!que.empty()){
            const int v = que.front();
            que.pop();
            for (auto &e : g[v]) {
                if(e.weight > 0 && level[e.dst] < 0){
                    level[e.dst] = level[v] + 1;
                    que.push(e.dst);
                }
            }
        }
    }

    Weight Dfs(vector<int> &level, vector<int> &iter, int v, int t, Weight flow) {
        if(v == t) return flow;
        for (int &i = iter[v], N = g[v].size(); i < N; ++i) {
            Edge &e = g[v][i];

            if(e.weight > 0 && level[v] < level[e.dst]){
                Weight d = Dfs(level, iter, e.dst, t, min(flow, e.weight));
                if(d > 0){
                    e.weight -= d;
                    g[e.dst][e.rev].weight += d;
                    return d;
                }
            }
        }
        return 0;
    }
};

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

    int n, m, u, v, c;

    cin >> n >> m;
    Dinic flow(n);
    for (int i = 0; i < m; ++i) {
        cin >> u >> v >> c;
        flow.add_edge(u, v, c);
    }

    cout << flow.MaximumFlow(0, n - 1) << endl;

    return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  int N, M;
  cin >> N >> M;
  int result = N * (N - 1) / 2 + M * (M - 1) / 2;
  cout << result << endl;
}

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

using namespace std;

int sum[maxn << 2];

#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)

inline void up(int x){
	sum[x] = max(sum[ls(x)], sum[rs(x)]);
}

void modify(int x, int l, int r, int pos, int d){
	if(l == r){
		sum[x] += d;
		return;
	}
	int mid = l + r >> 1;
	if(mid >= pos) modify(ls(x), l, mid, pos, d);
	else modify(rs(x), mid + 1, r, pos, d);
	up(x);
}


int n, m, t;
int x, y;
vector<int> v[maxn];
int ans;

int main(){
	scanf("%d%d%d", &n, &m, &t);
	while(t--){
		scanf("%d%d", &x, &y);
		v[x].push_back(y);
		modify(1, 1, m, y, 1);
	}
	for(int i = 1;i <= n;i++){
		for(int j = 0;j < v[i].size();j++){
			modify(1, 1, m, v[i][j], -1);
		}
		ans = max(ans, (int)v[i].size() + sum[1]);
		for(int j = 0;j < v[i].size();j++){
			modify(1, 1, m, v[i][j], 1);
		}
	}
	printf("%d", ans);
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;

ll l[MAX_N];
ll r[MAX_N];

inline bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
  return a.first < b.first || (a.first == b.first && a.second > b.second);
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    scanf("%lld %lld", &(l[i]), &(r[i]));
  }

  if (n == 2) {
    ll ans = (r[0] - l[0] + 1L) + (r[1] - l[1] + 1L);
    printf("%lld\n", ans);
    return 0;
  }

  int max_l_ind = 0;
  int min_r_ind = 0;

  for (int i = 1; i < n; ++i) {
    if (l[i] > l[max_l_ind]) max_l_ind = i;
    if (r[i] < r[min_r_ind]) min_r_ind = i;
  }

  ll ans = 0L;

  // for case that a part of group is singleton
  for (int i = 0; i < n; ++i) {
    if (i == min_r_ind || i == max_l_ind) continue;

    ans = max(ans, max(r[min_r_ind] - l[max_l_ind] + 1, 0LL) + r[i] - l[i] + 1L);
  }

  vector<pair<ll, ll>> p;

  for (int i = 0; i < n; ++i) {
    if (i == min_r_ind || i == max_l_ind) continue;

    pair<ll, ll> tmp;

    tmp.first = max(r[min_r_ind] - l[i] + 1L, 0LL);   // first: fixed right
    tmp.second = max(r[i] - l[max_l_ind] + 1L, 0LL);  // second: fixed left

    p.push_back(tmp);
  }

  ll singleton_fixed_right = r[min_r_ind] - l[min_r_ind] + 1L;
  ll singleton_fixed_left = r[max_l_ind] - l[max_l_ind] + 1L;

  sort(p.begin(), p.end(), cmp);

  ans = max(ans, singleton_fixed_left + p[0].first);  // all fixed right to T, except a fixed left which belongs to S

  for (int i = 0; i < p.size(); ++i) {
    ans = max(ans, p[i].second);
  }

  ll part = p[0].second;
  for (int i = 1; i < p.size(); ++i) {
    ans = max(ans, part + p[i].first);
    part = min(part, p[i].second);
  }

  ans = max(ans, singleton_fixed_right + part);  // all fixed left to T, except a fixed right which belongs to S

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 3956
from collections import Counter

n = int(input())
l = [int(i) for i in input().split()]

S = Counter(l)

ans = 0
for i in S.values():
    ans += int(i * (i - 1) / 2)

for i in range(n):
    val = S[l[i]]
    print(ans - val + 1)


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

long long n;
long long a[200006] = {0};

long long solve();

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
    if(i != 0) a[i] += a[i - 1];
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 100000000000000000;
  for(int i = 0; i < n - 1; ++i) {
    long long l, r;
    l = a[i];
    r = a[n - 1] - l;
    ans = min(max(l - r, r - l), ans);
  }
  return ans;
}

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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

const ll inf = 0x3f3f3f3f3f3f3f3fll;

int n;
ll x[15], y[15], p[15];

ll _rev_x[20010], _rev_y[20010];
ll dp_x[1 << 15][15], dp_y[1 << 15][15];
ll ans[16];
int opt[15];

void dfs(int d) {
  if (d == n) {
    int cnt = 0, mask_x = 0, mask_y = 0;
    rep(i, 0, n) {
      if (opt[i]) cnt++;
      if (opt[i] == 1) mask_x |= 1 << i;
      if (opt[i] == 2) mask_y |= 1 << i;
    }
    ll val = 0;
    rep(i, 0, n) val += p[i] * min(dp_x[mask_x][i], dp_y[mask_y][i]);
    chmin(ans[cnt], val);
    return;
  }

  rep(i, 0, 3) {
    opt[d] = i;
    dfs(d + 1);
  }
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  read(n);
  rep(i, 0, n + 1) ans[i] = inf;
  rep(i, 0, n) read(x[i], y[i], p[i]);

  rep(i, 0, 1 << n) {
    vector<int> vx;
    vx.push_back(0);
    rep(j, 0, n) if (i >> j & 1) {
      vx.push_back(x[j]);
    }
    sort(all(vx));

    int p = 0;
    rep(j, 0, n) {
      dp_x[i][j] = inf;
      auto it = lower_bound(all(vx), x[j]);
      if (it != vx.end()) chmin(dp_x[i][j], *it - x[j]);
      if (it != vx.begin()) { --it; chmin(dp_x[i][j], x[j] - *it); }
    }
  }

  rep(i, 0, 1 << n) {
    vector<int> vy;
    vy.push_back(0);
    rep(j, 0, n) if (i >> j & 1) {
      vy.push_back(y[j]);
    }
    sort(all(vy));

    int p = 0;
    rep(j, 0, n) {
      dp_y[i][j] = inf;
      auto it = lower_bound(all(vy), y[j]);
      if (it != vy.end()) chmin(dp_y[i][j], *it - y[j]);
      if (it != vy.begin()) { --it; chmin(dp_y[i][j], y[j] - *it); }
    }
  }

  dfs(0);

  rep(i, 0, n + 1)
    write(ans[i]);
}


Measured memory_bytes: 11240
def resolve():
    n = int(input())
    h = list(map(int, input().split()))

    # i 番目の足場にたどり着くまでの最小コスト
    dp = [float('inf')] * n
    dp[0] = 0

    for i in range(1, n):
        dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
        if i > 1:
            dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))

    print(dp[n - 1])
    
resolve()

Measured memory_bytes: 13928
<?php

fscanf(STDIN, '%d', $n);

for ($i = 0; $i < $n; $i++) {
    $a = $b = array();
    fscanf(STDIN, '%f %f %f %f %f %f', $a[], $a[], $a[], $b[], $b[], $b[]);
    $ab = TRUE;
    if ($a[2] < $b[2]) {
        $ab = FALSE;
        $tmp = $a;
        $a = $b;
        $b = $tmp;
    }
    $d = sqrt(($a[0] - $b[0]) * ($a[0] - $b[0]) + ($a[1] - $b[1]) * ($a[1] - $b[1]));
    if ($a[2] + $b[2] < $d) {
        echo 0;
    } elseif ($d + $b[2] >= $a[2]) {
        echo 1;
    } else {
        echo $ab ? 2 : -2;
    }
    echo PHP_EOL;
}

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

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

    int a = n%10;

    if (a == 3) {
        cout << "bon" << endl;
        return 0;
    }
    if (a == 0 || a == 1 || a == 6 || a == 8) {
        cout << "pon" << endl;
        return 0;
    }
    cout << "hon" << endl;
    return 0;
}

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

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

  int count = 1;
  for(int i=0; i<n; i++){
    if(a[i]==count){
      flag=1;
      count++;
    }else{
      ans++;
    }
  }

  if(flag) cout << ans << endl;
  else cout << "-1" << endl;

  return 0;
}


Measured memory_bytes: 1024
//
// Created by ss250251 on 2/16/2020.
//

#include<bits/stdc++.h>
using namespace std;
#define INF 1e18L + 7
#define MOD 1e9+7
template <typename T>
void max_self(T&a,T b){
    a = max(a,b);
}
template <typename T>
void min_self(T&a,T b){
    a = min(a,b);
}

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<vector<long long>>dp(n,vector<long long>(n,0));
    for(int i=0;i<n;i++){
        for(int j=i;j>=0;j--){
            if(i==j)dp[j][i]=a[i];
            else{
                dp[i][j] = max(a[j]-dp[i][j+1], a[i] - dp[i-1][j]);
            }
        }
    }
    cout<<dp[n-1][0];
}

Measured memory_bytes: 70656
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <iomanip>

using namespace std;

int main(){

    
    double a;
    while(cin>>a){
        double out=0;
        for(int i=1; i<=10; i++){
            out+=a;
            if(i%2==0){
                a/=3;
            }else{
                a*=2;
            }
        }
        cout<<fixed<<setprecision(8)<<out<<endl;
    }
}

Measured memory_bytes: 1276
#include<stdio.h>
#define MAX 1000000
 int main(){    char prime[MAX];    int num, i, j, ans;     for(i = 0; i < MAX; i++)    {        prime[i] = 1;    }    prime[0] = prime[1] = 0;    for(i = 2; i < (MAX/2); i++)    {        if(prime[i])        {            for(j = 2*i; j < MAX; j += i)            {                prime[j] = 0;            }        }    }         while(scanf("%d", &num) != EOF)    {        ans = 0;                 for(i = 2; i <= num; i++)        {            ans += prime[i];        }                 printf("%d\n", ans);    }     return 0;}

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

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> ps(m);
	vector<string> ss(m);
	for (int i = 0; i < m; i++)
	{
		cin >> ps[i] >> ss[i];
		ps[i]--;
	}

	vector<bool> done(n, false);
	vector<int> sub(n, 0);

	int ac = 0, pe = 0;

	for (int i = 0; i < m; i++)
	{
		if (done[ps[i]])
		{
			continue;
		}

		if (ss[i] == "AC")
		{
			ac++;
			done[ps[i]] = true;
		}
		else
		{
			sub[ps[i]]++;
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (done[i])
		{
			pe += sub[i];
		}
	}

	cout << ac << ' ' << pe << endl;

	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
const lint MOD = pow(10, 9) + 7;

int main() {
	lint N;
	cin >> N;
	vector<lint>A(N);
	vector<lint>B(N);
	rep(i, N) {
		cin >> A[i];
	}
	rep(i, N) {
		cin >> B[i];
	}
	lint sumA = 0, sumB = 0;
	rep(i, N) {
		sumA += A[i];
	}
	rep(i, N) {
		sumB += B[i];
	}
	if (sumA < sumB) {
		cout << -1 << endl;
	}
	else {
		lint x = 0, y = 0;
		lint xx = 0;//足りてない量
		rep(i, N) {
			if (A[i] < B[i]) {
				x++;//足りてない数
				xx += B[i] - A[i];
			}
		}
		vector<int>Y;
		rep(i, N) {
			if (A[i] > B[i]) {
				Y.push_back(A[i] - B[i]);
			}
		}
		sort(Y);
		reverse(Y);
		int Z = Y.size();
		vector<lint>SUM(Z);
		SUM[0] = Y[0];
		for (int i = 1; i < Z; i++) {
			SUM[i] = SUM[i - 1] + Y[i];
		}
		rep(i, N) {
			if (SUM[i] >= xx) {
				y = i;
				break;
			}
		}
		if (x == 0)cout << 0 << endl;
		
		else cout << x + y+1 << endl;
	}
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main() {
    ll n;
    cin >> n;
    ll sqn = sqrt(n) + 1;
    ll ans = LLONG_MAX;
    FOR(i, 1, sqn) {
        if(n % i == 0) ans = min(ans, i - 1 + (n / i) - 1);
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
/*input
5 5
1 2
2 3
3 1
5 4
5 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

vector<int> child[maxn];

int tg[maxn];
bool vis[maxn];
void dfs(int u){
	vis[u]=1;
	for(int v:child[u]) if(!vis[v]){
		tg[v]=!tg[u];
		dfs(v);
	}
}

int main()
{
	//IOS;
	int n,m;
	cin>>n>>m;
	REP(i,m){
		int u,v;
		cin>>u>>v;
		u--;v--;
		child[u].pb(v);
		child[v].pb(u);
	}
	dfs(0);

	bool f=1;
	for(int i=0;i<n;i++) for(int j:child[i]){
		if(tg[i]==tg[j]) f=0;
	}
	if(f){
		int cnt=0;
		REP(i,n) cnt+=tg[i];
		cout<<(ll)cnt*(n-cnt)-m<<'\n';
	}
	else cout<<(ll)n*(n-1)/2-m<<'\n';

	return 0;
}


Measured memory_bytes: 11776
#include <stdio.h>

int main(){

  int x, y, tmp;

  for(int i = 1; ; i++) {
    scanf("%d %d", &x, &y);

    if(x == 0 && y == 0) break;

    if(x > y) {
      tmp = x;
      x = y;
      y = tmp;
    }
    printf("%d %d\n", x, y);
  }
}


Measured memory_bytes: 2096