akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#include<queue>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 1123456789012345
using namespace std;

int main(){
	ll a, b, c, d; cin >> a >> b >> c >> d;
	bool flag_a = false;
	bool flag_b = false;
	ll count = 0;
	rep(i, max(b,d)+1){
		if (flag_a && flag_b) count++;
		if (i == a) flag_a = true;
		if (i == b) flag_a = false;
		if (i == c) flag_b = true;
		if (i == d) flag_b = false;
	}
	if(count>=0) cout << count << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

class UnionFindTree {
private:
    vector<int> parent;
    vector<int> count;
public:
    UnionFindTree(int n) : parent(n), count(n, 1) {
        // 最初は全てを根として初期化
        for(int i = 0; i < n; i++) parent[i] = i;
    }

    int get_root(const int x) {
        // データxが属する木の根を取得する
        if (parent[x] == x) return x;
        // 取得したものは直接木の根をつなぐ(経路圧縮)
        return parent[x] = get_root(parent[x]);
    }

    void unite(const int x, const int y) {
        // xとyの木を併合する
        int rx = get_root(x);
        int ry = get_root(y);
        // 元から同じ木に属している場合は何もしない
        if (rx == ry) return;
        // xの属する木をyの属する木につける
        parent[rx] = ry;
        count[ry] += count[rx];
        count[rx] = 0;
    }

    bool is_same_root(const int x, const int y) {
        return get_root(x) == get_root(y);
    }

    int get_size(const int x) {
        return count[get_root(x)];
    }

    void print() {
        for(auto elm : parent) cout << elm << " ";
        cout << endl;
        for(auto elm : count) cout << elm << " ";
        cout << endl;
    }
};

struct cell {
    double x;
    double y;
    double z;
    double r;
};

int main() {

    while (true) {
        int n;
        cin >> n;
        if(n == 0) break;

        vector<cell> c(n);
        for (auto i = 0; i < n; i++) {
            double x, y, z, r;
            cin >> x >> y >> z >> r;
            c[i] = {x, y, z, r};
        }

        UnionFindTree tree(n);
        map<double, vector<pair<int, int>>> g;
        for (auto i = 0; i < n; i++) {
            for (auto j = i + 1; j < n; j++) {
                double nx = (c[i].x - c[j].x) * (c[i].x - c[j].x);
                double ny = (c[i].y - c[j].y) * (c[i].y - c[j].y);
                double nz = (c[i].z - c[j].z) * (c[i].z - c[j].z);
                double nr = (c[i].r + c[j].r) * (c[i].r + c[j].r);
                // cout << i << " " << j << endl;
                // cout << nx << " " << ny << " " << nz << " " << nr << endl;
                if (nx + ny + nz > nr)
                    g[sqrt(nx + ny + nz) - sqrt(nr)].emplace_back(i, j);
                else
                    g[0].emplace_back(i, j);
            }
        }

        double ans = 0;
        for (auto &a : g) {
            // cout << "a:" << a.first << endl;
            for (auto &b : a.second) {
                // cout << "b:" << b.first << " " << b.second << endl;
                if (not tree.is_same_root(b.first, b.second)) {
                    tree.unite(b.first, b.second);
                    ans += a.first;
                }
            }
        }

        cout << fixed << setprecision(3) << ans << endl;
    }
    return 0;
}


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


void solve(long long P, long long Q, long long R){
  vector<int> pqr;
  pqr.push_back(P);
  pqr.push_back(Q);
  pqr.push_back(R);
  vector<int> v;
  int ans;
  for (int i = 0; i < 3; i++) {
     for (int j = 0; j < 3; j++) {
     
       if (i != j) {
         auto num = pqr[i] + pqr[j];
         v.push_back(num);
       }
     }
  }
  ans = *std::min_element(v.begin(), v.end());
  cout << ans << endl;


}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long P;
    scanf("%lld",&P);
    long long Q;
    scanf("%lld",&Q);
    long long R;
    scanf("%lld",&R);
    solve(P, Q, R);
    return 0;
}


Measured memory_bytes: 256
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}
}
use input::*;

fn main() {
    let (x, y): (isize, isize);
    input!(x, y);
    if (x - y).abs() <= 1 {
        p("Brown");
    } else {
        p("Alice");
    }
}


Measured memory_bytes: 4352
A, B = map(int, input().split())

x_min_tmp = A * 12.5
if x_min_tmp.is_integer:
  x_min = int(x_min_tmp)
else:
  x_min = int(x_min_tmp) + 1

x_max_tmp = (A + 1) * 12.5
x_max = int(x_max_tmp) + 1

ans = -1
for n in range(x_min, x_max + 1):
  if int(n * 0.08) == A and int(n * 0.1) == B:
    ans = n
    break

print(ans)

Measured memory_bytes: 3064
import java.util.*;


class Main{

    int n=0,m=1;
    
    Main(){
        Scanner sc = new Scanner(System.in);
        
        for(int i=0;i<6;i++){
            int a=sc.nextInt();
            n=n+a*m;
            
            if(i%2==0)m*=5;
            else m*=2;
        }

        if(n>=1000)n=1;
        else n=0;
        System.out.println(n);
    }

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

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

int main(){
  string S;
  cin >> S;
  int A=S.size(),flag=1;
  for(int i=0;i<A;i++){
    if(i%2==0){
      if(S[i]=='L')
        flag=0;
    }
    else{
      if(S[i]=='R')
        flag=0;
    }
  }
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	nextReader = newScanner()

	X := nextInt()
	A := nextInt()

	if X < A {
		fmt.Println(0)
	} else {
		fmt.Println(10)
	}
}

var nextReader func() string

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
using namespace std;


int main(void) {

  string s; cin >> s;
  int a, b, c, d;
  a = s[0]-'0';
  b = s[1]-'0';
  c = s[2]-'0';
  d = s[3]-'0';

  string op = "+-";
  for(int i=0; i<2; i++){
    for(int j=0; j<2; j++){
      for(int k=0; k<2; k++){
        int tmp = a;
        if( i == 0 ) tmp += b;
        else tmp -= b;
        if( j == 0 ) tmp += c;
        else tmp -= c;
        if( k == 0 ) tmp += d;
        else tmp -= d;

        if( tmp == 7 ){
          cout << a << op[i] << b << op[j] << c << op[k] << d << "=7" << endl;
          return 0;
        }
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
point = 0

for i in range(k):
  part = t[i::k]
  R = part.count("r") - part.count("rr")
  S = part.count("s") - part.count("ss")
  P = part.count("p") - part.count("pp")
  point += R*p + S*r + P*s

print(point)
  

Measured memory_bytes: 3316
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

long a[200010];

bool chk(int l, int r){
  int rp=0;
  FOR (i,l,r){
    if (rp&a[i]) return false;
    rp+=a[i];
  }
  return true;
}

int main(){
  int n,l;
  vector<string> s;
  string t;
  cin >> n >> l;
  REP(i,n){
    cin >> t;
    s.push_back(t);
  }
  SORT(s);
  REP(i,n){
    cout << s[i];
  }
  return 0;
}


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

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

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

  vector<int> a(n);
  rep(i,n) cin >> a.at(i);

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

  vector<int> yakusuu(1000005,0);
  rep(i,n){
    int x = a.at(i);
    if(yakusuu.at(x)!=0){yakusuu.at(x)=2; continue;}
    for(int j=x; j<1000005; j+=x){
      yakusuu.at(j)++;
    }
  }

  int ans = 0;
  rep(i,n){
    int x = a.at(i);
    if(yakusuu.at(x)==1)ans++;
  }

  cout << ans;
  
}

Measured memory_bytes: 8020
#include<stdio.h>


#define MAX 100000
#define N -1


typedef struct{
  int p,l,r;
}Node;


Node T[MAX];
int a;


void pre(int);
void in(int);
void post(int);


int main()
{
  int i,b,c,left,right;
  
  scanf("%d",&a);
  
  for(i=0;i<a;i++)T[i].p=T[i].l=T[i].r=N;
  
  for(i=0;i<a;i++){
    
    scanf("%d %d %d",&c,&left,&right);
    
    T[c].l=left;
    T[c].r=right;
    
    if(left!=N)T[left].p=c;
    if(right!=N)T[right].p=c;
  }
  
  for(i=0;i<a;i++)if(T[i].p==N)b=i;
  
  printf("Preorder\n");
  pre(b);
  printf("\n");
  
  printf("Inorder\n");
  in(b);
  printf("\n");
  
  printf("Postorder\n");
  post(b);
  printf("\n");
  
  return 0;
}


void pre(int s)
{
  if(s==N)return;
  
  printf(" %d",s);
  pre(T[s].l);
  pre(T[s].r);
}


void in(int t)
{
  if(t==N)return;
  
  in(T[t].l);
  printf(" %d",t);
  in(T[t].r);
}


void post(int u)
{
  if(u==N)return;
  
  post(T[u].l);
  post(T[u].r);
  printf(" %d",u);
}



Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define ll long long
typedef pair<int, int> P;

int main(){
  ll n, p, res = 1, now = 0;
  cin >> n >> p;
  if (n == 1 || p == 1) {
    cout << p << endl;
    exit(0);
  }
  bool flag = true;
  for (ll i = sqrt(p); i > 1; i--) {
    now = p;
    flag = true;
    rep(j, n) {
      if (now % i != 0) {
        flag = false;
        break;
      }else{
        now /= i;
      }
    }
    if (flag) {
      res = i;
      break;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int N, A; cin >> N >> A;
	cout << (N%500-A<=0?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n, k = map(int, input().split())
    s = input()

    happy = 0
    for i in range(1, n):
        if s[i-1] == s[i]:
            happy += 1
    print(min(happy + k * 2, n - 1))

if __name__ == '__main__':
    main()


Measured memory_bytes: 39280
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
  string s;
  cin >> s;
  int sl = s.length();
  reverse(all(s));

  int ans = 0;
  for (int i = 0; i < sl; ++i) {
    ans += s[i]-'0';
  }

  for (int i = 0; i+1 < sl; ++i) {
    s[i] = '9';
    if (s[i+1] != '0') {
      s[i+1]--;
      int tmp = 0;
      for (int j = 0; j < sl; ++j) {
        tmp += s[j]-'0';
      }
      ans = max(ans, tmp);
    }
  }

  cout << ans << endl;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    for (int i=0; i<N; i++){
        cin >> P[i];
    }
    sort(P.begin(), P.end());
    int ans = 0;
    for (int i=0; i<K; i++){
        ans += P[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	// your code goes here
	int n; cin>>n; long long a[n], sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n, greater<long long>());
	if(n%2==0){
		for(int i=0;i<n/2;i++){
			if(i==0)sum+=a[i];
			else sum+=(a[i]*2);
		}
	}
	else{
		int i;
		for(i=0;i<n/2;i++){
			if(i==0)sum+=a[i];
			else sum+=(a[i]*2);
		}
		sum+=a[i];
	}
	cout<<sum;
	
	return 0;
}

Measured memory_bytes: 5200
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

let main() =
    let [| x1; y1; x2; y2 |] = reada int
    let a, b = x2 - x1, y2 - y1
    let x3, y3 = x2 - b, y2 + a
    let x4, y4 = x1 - b, y1 + a
    sprintf "%d %d %d %d" x3 y3 x4 y4 |> puts
    ()

main()
writer.Close()


Measured memory_bytes: 12112
#include <stdio.h>

int main(void)
{
  unsigned int x1, x2, sum, digits;
  while(fscanf(stdin, "%d %d", &x1, &x2) != EOF)
    {
      sum = x1 + x2;
      digits = 0;
      while(sum > 0)
        {
          sum /= 10;
          digits++;
        }

      printf("%d\n", digits);
    }

  return 0;
}

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

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

    vector<int> h(n);
    // int64_t maxs[k];

    int64_t res = 0;

    for (size_t i = 0; i < n; i++)
    {
        cin>>h.at(i);
    }
    
    sort(h.begin(),h.end());


    if (n > k)
    {
     
    
    
        for (size_t i = 0; i < n-k; i++)
        {
            res += h.at(i);
        }

    } else {
        res = 0;
    }
    cout << res;

}

Measured memory_bytes: 1024
L,R=gets.chomp.split(" ").map(&:to_i);
qL=L/2019
qR=R/2019
if(qL<qR)
 print(0)
else
modL=L.modulo(2019)
modR=R.modulo(2019)
x=2019*2019 
for j in modL+1..modR
for i in modL..j-1
 x=[(i*j).modulo(2019),x].min
end
end
print(x)
end

Measured memory_bytes: 1788
#include <cstdio>

#include <algorithm>
#include <numeric>

using namespace std;

typedef long long ll;

const int N = 100010;

int n;
int a[N], b[N];
int arr[N * 2];
ll sum[N * 2];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d%d", &a[i], &b[i]);
	ll ans = min(accumulate(a + 1, a + n + 1, 0LL), accumulate(b + 1, b + n + 1, 0LL));
	copy(a + 1, a + n + 1, arr + 1);
	copy(b + 1, b + n + 1, arr + n + 1);
	sort(arr + 1, arr + n * 2 + 1);
	for (int i = 1; i <= n * 2; ++i)
		sum[i] = sum[i - 1] + arr[i];
	for (int i = 1; i <= n; ++i) {
		int x = lower_bound(arr + 1, arr + n * 2 + 1, a[i]) - arr,
		    y = lower_bound(arr + 1, arr + n * 2 + 1, b[i]) - arr;
		if (x == y)
			++y;
		for (int j = n; j >= n - 2; --j)
			if ((j + (x > j) + (y > j)) == n)
				ans = min(ans, sum[j] + (x > j) * arr[x] + (y > j) * arr[y]);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  string S;
  cin>>S;
  int N=S.size();
  if(N<4||(S[0]!='Y'||S[1]!='A'||S[2]!='K'||S[3]!='I')) cout<<"No";
  else cout<<"Yes";
return 0;}

Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    int p[m], y[m];
    vector<set<pii>> s(n+1);
    rep(i, m) {
        cin >> p[i] >> y[i];
        s[p[i]].insert({y[i], i});
    }
    vector<string> ans(m);
    rep(i, n+1) {
        if (i > 0) {
            int cnt = 0;
            for (pii x : s[i]) {
                string t1 = to_string(i);
                while ((int)t1.size() < 6) {
                    t1 = '0' + t1;
                }
                string t2 = to_string(++cnt);
                while ((int)t2.size() < 6) {
                    t2 = '0' + t2;
                }
                ans[x.second] = t1 + t2;
            }
        }
    }
    rep(i, m) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 16404
#include<cstdio>
#include<algorithm>
using namespace std;

struct Node{
	int l,r;
	bool operator<(const Node& o)const {
		return r < o.r;
	}
};

const int N = 1e5+5;

int n;
Node a[N];

int main(){
	//freopen("IN","r",stdin);
	scanf("%d",&n);
	for(int i = 0;i < n;i++){
		int m,l;
		scanf("%d%d",&m,&l);
		a[i].l = m-l, a[i].r = m+l;		
	}
	sort(a,a+n);
	int res = 1,pre = a[0].r;
	for(int i = 1;i < n;i++){
		if(a[i].l >= pre) {
			res++,pre = a[i].r;
		}
	}
	printf("%d\n", res);
}

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

using namespace std;

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

    int n;
    cin >> n;
    long long arr[n] = {0};
    long long sum = 0;
    for(int x=0;x<n;x++){
        cin >> arr[x];
        sum = (sum + arr[x])%1000000007;
    }
    
    //cout << sum << endl;

    long long ans = 0;
    for(int x=0;x<n;x++){
        sum = sum - arr[x];

        if (sum < 0) sum += 1000000007;

        ans = (ans + arr[x]*sum)%1000000007;
    }

    cout << ans << '\n';
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}

template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}

template <typename T> void print(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void print(const T &value, const Args&... args){std::cout << value << " ";print(args...);}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int N;

  while(cin >> N){
    vector<int> A(N+1); cin >> A;

    bool ok = true;
    i64 ans = 0;


    vector<i64> MAX(N+1);

    i64 x = 1;
    FORE(i,0,N){
      if(x < A[i]){
        ok = false;
        break;
      }
      
      MAX[i] = x;

      x -= A[i];
      if(x <= 1e15) x *= 2;
    }

    dump(MAX);
    
    i64 t = 0;
    REV(i,N,0){
      i64 a = (t + 1) / 2;
      i64 b = min(t, MAX[i]);

      //dump(make_tuple(t, a, b, A[i], MAX[i]));

      if(MAX[i] - A[i] < a){
        ok = false;
        break;
      }
      
      ans += t;

      t = min(MAX[i], b + A[i]);
    }

    ans += 1;

    

    if(ok){
      print(ans);
    }else{
      print(-1);      
    }
  }
  

  return 0;
}


Measured memory_bytes: 4504
N = gets.to_i
a = N / 3
b = N / 5
c = N / 15

d = N * (1 + N) / 2
e = a * (3 + a * 3) / 2
f = b * (5 + b * 5) / 2
g = c * (15 + c * 15 ) / 2
puts d - e - f + g

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

int gcd(int a, int b) {
  if(a < b) return gcd(b, a);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main() {
  int N; cin >> N;
  vector<int> mon(N);
  for(int i=0;i<N;i++){
    cin >> mon.at(i);
  }
  int ans=mon.at(0);
  for(int i=1;i<N;i++){
    ans=gcd(ans, mon.at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;
int main()
{
      int a,b,i;
      cin >> a >> b ;
      if(a==b)
      {
          for(i=0;i<a;i++)
        {
          cout << a ;
        }
        cout << endl;
      }


      else if(a>b)
        {
              for(i=0;i<a;i++)
           {
              cout << b ;
           }
             cout << endl;
        }

    else
    {
           for(i=0;i<b;i++)
           {
              cout << a ;
           }
             cout << endl;
    }



      return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const int MAX_N=10000;

pair<int,int> p[MAX_N+1];

int main(){ _;
  int n,a=0,b=0,c=0,d=0,e=0,f=0;
  while(scanf("%d",&n),n!=0){
    REP(i,n){
      scanf("%02d:%02d:%02d %02d:%02d:%02d",&a,&b,&c,&d,&e,&f);
      p[i]=make_pair(a*3600+b*60+c,d*3600+e*60+f);
    }
    priority_queue<int,vector<int>,greater<int> > que;
    int maxTrain=0;
    sort(p,p+n);
    REP(i,n){
      while(!que.empty()&&que.top()<=p[i].first)
	que.pop();
      que.push(p[i].second);
      maxTrain=max(maxTrain,(int)que.size());
    }
    cout<<maxTrain<<endl;
  }
}

Measured memory_bytes: 1384
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main()
{
	int n, m, k;
	cin >> n >> m >> k;

	vector<vector<int>> fr(n+1);
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		fr[a].push_back(b);
		fr[b].push_back(a);
	}

	vector<vector<int>> br(n + 1);
	for (int i = 0; i < k; ++i) {
		int c, d;
		cin >> c >> d;
		br[c].push_back(d);
		br[d].push_back(c);
	}

	vector<int> ret(n+1, -1);
	vector<int> cnums(n + 1, 0);
	queue<int> q;
	q.push(1);
	int count = 0;
	ret[1] = count;
	++cnums[count];
	int checked = 2;
	while (!q.empty()) {
		int ft = q.front();
		for (auto& i : fr[ft]) {
			if (ret[i] == -1) {
				q.push(i);
				ret[i] = count;
				++cnums[count];
			}
		}

		q.pop();
		if (q.empty()) {
			for (int i = checked; i <= n; ++i) {
				if (ret[i] == -1) {
					q.push(i);
					++count;
					ret[i] = count;
					++cnums[count];
					checked = i + 1;
					break;
				}
			}
		}
	}

	for (int i = 1; i <= n; ++i) {
		int r = cnums[ret[i]] - 1;
		r -= static_cast<int>(fr[i].size());
		for (auto& b : br[i]) {
			if (ret[i] == ret[b]) {
				--r;
			}
		}
		cout << r << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 13048
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> Pi;
int D,N;

int f(vector<vector<int> >& list,vector<vector<int> >& used)
{
  
  int mex = 0;
  queue<Pi> que;// Pi(P(value,day),pre_index)
  for(int i=0;i<list[0].size();i++)
    {
      que.push(Pi(P(0,1),i));
      used[0][i] = 0;
    }
  
  while(!que.empty())
    {
      Pi p = que.front(); que.pop();
      int total,day,pre_index;
      total = p.F.F, day = p.F.S, pre_index = p.S;

      if(day >= D)
	{
	  mex = max(mex,total);
	  continue;
	}

      for(int i=0;i<list[day].size();i++)
	{
	  int sum = total + abs(list[day-1][pre_index]-list[day][i]);
	  if(used[day][i] >= sum)
	    continue;

	  used[day][i] = sum;
	  que.push(Pi(P(sum,day+1),i));
	}

    }

  return mex;
}


int main()
{

  cin >> D >> N;
  vector<int> T;
  vector<vector<int> > list,used;
  list.resize(D),used.resize(D);


  for(int i=0;i<D;i++)
    {
      int in; cin >> in;
      T.push_back(in);
    }

  for(int j=0;j<N;j++)
    {
      int A,B,C;
      cin >> A >> B >> C;
      for(int k=0;k<D;k++)
	{
	  if(A <= T[k] && T[k] <= B)
	    {
	      list[k].push_back(C),used[k].push_back(-1);
	    }
	}
    }
  cout << f(list,used) << endl;


  return 0;
}

Measured memory_bytes: 10088
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int N;
int a[100010];
int b[100010];
/**********************************/


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) cin >> a[i];
    sort(a, a+N);

    int k=0;
    int x = 1;
    if(N%2==1) {
        b[0] = 0;
        x = 2;
        k = 1;
    }
    for(; x<N; x+=2) {
        b[k] = b[k+1] = x;
        k += 2;
    }

    REP(i, N) {
        if(a[i] != b[i]) {
            cout << 0 << endl;
            return 0;
        }
    }

    int ans = 1;
    UP(i, 1, N/2) {
        ans *= 2;
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
N = int(input())

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

ans = 0

for i in range(0,N):
    r1 = a[0][:i+1]
    r2 = a[1][i:]

    ans = max(ans, sum(r1) + sum(r2))

print(ans)

Measured memory_bytes: 3064
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    
    print(sRaw().replace("?","D"))

main()


Measured memory_bytes: 68436
#include<stdio.h>

int main(void){
    //long n=0 , m=0, k=0;
    int n=0 , m=0, k=0;

    int ans = 0;
    //scanf("%ld %ld %ld", &n, &m, &k);
    scanf("%d %d %d", &n, &m, &k);

    for(int a = 0; a <= n && ans == 0; a++){
        for(int b = 0; b <= m && ans == 0; b++){
            if( (a*m - 2*a*b + b*n) == k ){
                ans = 1;
                break;
            }
        }
    }
    if(ans) printf("Yes\n");
    else printf("No\n");
}


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

int main() {
    
    vector<int> vec(3);
    for (int i = 0; i < 3; i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());

    if (vec.at(0) == vec.at(1)) cout << vec.at(2) << endl;
    else cout << vec.at(0) << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = [0] * N
for i in range(N):
    S[i] = str(input())
S.sort()
#print(S)
cnt_max = 1
cnt = 1
ans = [0] * N
ans[0] = S[0]
flag = 0
for i in range(1, N):
    if S[i-1] == S[i]:
        cnt += 1
        if i == N-1:
            if cnt > cnt_max:
                print(S[i])
                exit()
            elif cnt == cnt_max:
                ans[flag] = S[i]
    else:
        if cnt > cnt_max:
            ans = [0] * N
            ans[0] = S[i-1]
            flag = 1
            cnt_max = cnt
        elif cnt == cnt_max:
            ans[flag] = S[i-1]
            flag += 1
        cnt = 1
        if cnt == cnt_max and i == N-1:
            ans = S
    #print(cnt)

#print(ans)
i = 0
while ans[i] != 0:
    i += 1
    if i == N:
      break
ans = ans[:i]
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 20252
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    getLine
    bs <- getIntList
    print $ (head bs) + (solve bs)

solve [] = 0
solve [b] = b
solve (b1 : b2 : bs) = (min b1 b2) + (solve (b2 : bs))

Measured memory_bytes: 508
#include <stdio.h>

int dp[45];

int main(void) {
  int i;
  dp[0] = dp[1] = 1;
  for ( i = 2; i <= 44; i++ ) dp[i] = dp[i-1] + dp[i-2];
  scanf("%d", &i);
  printf("%d\n", dp[i]);
  return 0;
}



Measured memory_bytes: 2104
N = int(input())
S = input()

sm = 0
L = 0
s_list = list(S)

for s in s_list:
    if s == "(":
        sm += 1
    else:
        sm -= 1
        if sm < 0:
            L += 1
            sm = 0
            
S = L*"(" + S

r_num = S.count(")")
l_num = S.count("(")

L = max(0, r_num-l_num)
R = max(0, l_num-r_num)


S = L*"(" + S + R*")"
print(S)

Measured memory_bytes: 3060
fun main(args: Array<String>) {
    var n = readInputLine().toInt()
    
    var ans = 0
    
    for (i in 1..n) {
        if (i.toString().length % 2 == 1) {
            ans++
        }
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 34596
#include <stdio.h>
#include <algorithm>
int main() {
	int H, W;
	scanf("%d %d", &H, &W);
	char a[200][200];
	for (int i = 0; i < H; i++) {
		scanf("%s", a[i + 1] + 1);
		a[i + 1][0] = '#';
		a[i + 1][W + 1] = '#';
		a[i + 1][W + 2] = '\0';
	}
	for (int i = 0; i < W + 2; i++) {
		a[0][i] = '#';
		a[H + 1][i] = '#';
	}
	a[0][W + 2] = '\0';
	a[H + 1][W + 2] = '\0';
	for (int i = 0; i < H + 2; i++)
		printf("%s\n", a[i]);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  string str;
  cin >> str;
  int a,b,c,d;
  a = str[0] - '0';
  b = str[1] - '0';
  c = str[2] - '0';
  d = str[3] - '0';
  if(a+b+c+d==7)cout<<a<<"+"<<b<<"+"<<c<<"+"<<d;
  else if(a+b+c-d==7)cout<<a<<"+"<<b<<"+"<<c<<"-"<<d;
  else if(a+b-c+d==7)cout<<a<<"+"<<b<<"-"<<c<<"+"<<d;
  else if(a-b+c+d==7)cout<<a<<"-"<<b<<"+"<<c<<"+"<<d;
  else if(a+b-c-d==7)cout<<a<<"+"<<b<<"-"<<c<<"-"<<d;
  else if(a-b+c-d==7)cout<<a<<"-"<<b<<"+"<<c<<"-"<<d;
  else if(a-b-c+d==7)cout<<a<<"-"<<b<<"-"<<c<<"+"<<d;
  else if(a-b-c-d==7)cout<<a<<"-"<<b<<"-"<<c<<"-"<<d;
  cout<<"=7"<<endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
    "fmt"
    "sort"
)

func main() {
    var n int
    fmt.Scan(&n)

    list := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&list[i])
    }

    oldList := make([]int, n)
    copy(oldList, list)

    // sort.Sort(sort.IntSlice(list))  下と同じ
    sort.IntSlice(list).Sort()

    count := 0
    for i := 0; i < len(oldList); i++ {
        if oldList[i] != list[i] {
            count += 1
        }
    }
    // 昇順リストと差分が2か所または0か所の場合OKとする
    if count == 2 || count == 0{
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }

}


Measured memory_bytes: 512
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
 
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N;
ll a[20][20];
ll score[(1<<16) + 5]={0};
ll dp[(1<<16) + 5] = {0};
ll calc(int i, int bcnt){
	ll ret = 0;
	if(i==0)return 0;
	else{
		rep(k,N){
			if(i&(1<<k)){
				ret+=a[bcnt][k];
			}
		}
		return ret;
	}
}
int main(){
	cin>>N;
	rep(i,N)rep(j,N)cin>>a[i][j];
	int now=1;
	int bcnt=0;
	score[0]=0;
	rep(i,(1<<N)){
		if(now*2<=i)now*=2,bcnt++;
		score[i]=score[i-now]+calc(i, bcnt);
		//cout<<score[i]<<endl;
	}
	rep(S,(1<<N)){
		dp[S]=max(score[S],(ll)0);
		//cout<<S<<endl;
		for(int T=S;;T=(T-1)&S){
			maxs(dp[S],dp[S-T]+dp[T]);
			if (T<= 0)break;
			//cout<<" "<<T<<endl;
		}
	}
	cout<<dp[(1<<N)-1]<<endl;
}

Measured memory_bytes: 1280
#include<stdio.h>

int main(){

int N;
scanf("%d",&N);

int a[N];
for (int i = 0; i < N; i++){
    scanf("%d",&a[i]);
}

int br=0,num=1;
for (int i = 0; i < N; i++){
  a[i]==num ? num++ : br++;
}
br==N ? puts("-1") : printf("%d",br);

return 0;

}

Measured memory_bytes: 2456
n = int(input())
alst = list(map(int, input().split()))
dp = [[1000, [0, 0]]]

for a in alst:
    tmp1 = max(dp[-1][0], dp[-1][1][0] * a + dp[-1][1][1])
    tmp2 = tmp1 // a
    tmp3 = tmp1 % a
    dp.append([tmp1, [tmp2, tmp3]])
print(dp[-1][0])

Measured memory_bytes: 9192
import sys
N = int(input())
S = sorted(list(map(int, input().split())))
parent = [S[-1]]
rest = S[:-1]
for i in range(N):
    next_generation = []
    next_rest = []
    for p in parent[::-1]:
        while True:
            if len(rest) == 0:
                print('No')
                sys.exit()
            q = rest.pop()
            if p>q:
                next_generation.append(q)
                break
            else:
                next_rest.append(q)
    parent+=next_generation
    parent.sort()
    rest += next_rest
    rest.sort()
print('Yes')        

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

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> vll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll L, N;
  cin >> L >> N;
  ll X[N+2] = {}, xsum[N+2] = {};
  rep(i, N) cin >> X[i+1];
  X[N+1] = L;
  repi(i, 1, N+2) xsum[i] = xsum[i-1] + X[i];

  ll ans = 0;
  repi(last, 1, N+1){
    ll n = min(last - 1, N - last);
    ll tmp = (xsum[last-1] - xsum[last-1-n]) * 2;
    tmp += (L * n - (xsum[last+n] - xsum[last])) * 2;
    tmp += max(X[last], L - X[last]);
    ans = max(ans, tmp);
    if(last - 1 < N - last){
      ans = max(ans, tmp - max(X[last], L-X[last]) + X[last] + 2*(L-X[last+n+1]));
    }
    if(last - 1 > N - last){
      ans = max(ans, tmp - max(X[last], L-X[last]) + (L-X[last]) + 2*X[last-1-n]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include<cstdio>

int main()
{
	int m,d;
	scanf("%d%d",&m,&d);
	int ans=0;
	for(int i=1;i<=m;++i)
	{
		for(int j=22;j<=d;++j)
		{
			if((j%10)*(j/10)==i&&(j%10>=2))
			{
				++ans;
			}
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
using System;
using System.Text.RegularExpressions;
namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            Regex snakeA = new Regex(@"^>'(=+)#\1~$");
            Regex snakeB = new Regex(@"^>\^(?:Q=)+~~$");
            int count = int.Parse(Console.ReadLine());
            string input;
            for(int i=0; (i < count) && (input = Console.ReadLine()) != null; ++i) {
                Console.WriteLine(snakeA.IsMatch(input) ? "A" : snakeB.IsMatch(input) ? "B" : "NA");
            }
        }
    }
}

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

int main() {
  string str;
  cin >> str;
  
  if(str.at(2)==str.at(3) && str.at(4)==str.at(5)){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

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

using ll=long long;

ll rec(ll a,ll b){
	if(b==0) return -a;
	ll ret=2LL*(a/b)*b;
	ret+=rec(b,a%b);
	return ret;
}

int main(void){
	ll n,x;
	cin >> n >> x;
	cout << n+rec(x,n-x) << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
As = list(map(int,input().split()))
min = 0
for i, a in enumerate(As):
    cnt = 0
    if i == 0:
        while a % 2 == 0:  
            a /= 2
            cnt += 1
        min = cnt
    else:
        while a % 2 == 0 and cnt < min:  
            a /= 2
            cnt += 1
        min = cnt
print(min)

Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 100005
int head,tail;
struct inf{
	char name[11];
	int time;
};
struct inf queue[MAX],what;
struct inf dequeue(){
	struct inf x;
	x=queue[head];
	head=(head+1)%MAX;
	return x;
}//取 
void enqueue(struct inf mid){
	queue[tail]=mid;
	tail=(tail+1)%MAX;
}//送 
int main(){
	int n,q,i,t=0;
	scanf("%d%d",&n,&q);
	head=1;
	tail=n+1;
	for(i=1;i<n+1;i++){
		scanf("%s%d",queue[i].name,&queue[i].time);
	}
	while(head!=tail){
		what=dequeue();
		if(what.time>q){
			what.time=what.time-q;
			enqueue(what);
			t=t+q;
		}
		else{
			t=t+what.time;
			printf("%s %d\n",what.name,t);
		}
	}//模拟 
	return 0;
} 


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



int main()
{
  int a1,a2,a3;
  int d1,d2,d3;
  cin >> a1 >> a2 >> a3;
  //do a1 first
  d1=min(abs(a2-a1)+abs(a3-a2),abs(a3-a1)+abs(a3-a2));
  d2=min(abs(a2-a1)+abs(a3-a1),abs(a3-a2)+abs(a1-a2));
  d3=min(abs(a3-a2)+abs(a1-a2),abs(a3-a1)+abs(a1-a2));
//  debug3(d1,d2,d3);
  cout << min (d1,min(d2,d3)) << endl;

  return 0;
}



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

using namespace std;

int main () {
	
	string s;
	cin >> s;
	if (s.size() > 3 and s.substr(0, 4) == "YAKI") {
		cout << "Yes" << endl;
	}
	else 
		cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
# http://kmjp.hatenablog.jp/entry/2019/01/13/0930
import sys
input = sys.stdin.readline

from bisect import bisect_left

n, q = map(int, input().split())
a = list(map(int, input().split()))
xs = [int(input()) for i in range(q)]

s = [0]*(n+1)
se = [0]*(n+1)
for i in range(n):
    s[i+1] = s[i] + a[i]
    if i :
        se[i+1] = se[i-1]
    se[i+1] += a[i]

def check(x, k):
    if k > n:
        return False

    Tk = (k+1)//2
    i = bisect_left(a, x- (a[n-Tk]-x))
    return i+k <= n

for x in xs:
    left = 0
    right = n+1
    while right-left > 1:
        mid = (left+right)//2
        if check(x, mid):
            left = mid
        else:
            right = mid
    top = (left+1)//2
    ans = 0
    ans += s[n] - s[n-top]
    if left%2:
        left += 1
    ans += se[n-left] if n-left>=0 else 0
    print(ans)

Measured memory_bytes: 74092
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
 
using namespace std;
typedef long long ll;

ll ans,mx,mn,sum;
int main(){
	int n,l;
	cin>>n>>l;
	string s[n];
	for(int i=0; i<n; i++){
		cin>>s[i];
	}
	sort(s,s+n);
	for(int i=0; i<n; i++)
		cout<<s[i];
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

vector<P> b(90000);

ll h, w, d, a[300][300], q, l[100000], r[100000];

int main(){
	
	
	cin >> h >> w >> d;
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			ll t;
			cin >> t;
			a[i][j] = t;
			b[t] = { i,j };
		}
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> l[i] >> r[i];
	}
	vector<vector<int> > cost(d+1);
	for (ll i = 0; i < d; i++) {
		cost[i].push_back(0);
		for (ll j = i + d; j <= h * w; j += d) {
			ll t;
			t = abs(b[j].first - b[j - d].first) + abs(b[j].second - b[j - d].second);
			cost[i].push_back(cost[i][j / d - 1] + t);
		}
	}

	for (int i = 0; i < q; i++) {
		ll x = l[i] % d, y = r[i] / d, z = l[i] / d;
		cout << cost[x][y] - cost[x][z] << endl;
	}
 	return 0;
}



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

// don't include x itself
template<class T> int former(const vector<T> &v, T x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin() - 1;
}


int main() {
  int N; cin >> N;
  vector<int> L(N);
  rep(i, N) cin >> L[i];
  sort(all(L));

  int ans = 0;
  for (int i = 0; i < N-2; i++) {
    for (int j = i+1; j < N-1; j++) {
      int k = former(L, L[i]+L[j]);
      ans += max(0, k-j);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256