akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);

    long ans;

    for (int l, r, xs; l < n; l++) {
        for (; r < n + 1; r++) {
            if (r < n && (xs & a[r]) == 0) {
                xs += a[r];
            }
            else {
                break;
            }
        }

        xs -= a[l];
        ans += r - l;
    }

    writeln(ans);
}













































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 10664
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,S[100];

void push(int a){
  S[++top] = a;
}

int pop(){
  int ans;
  top--;
  ans = S[top+1];
  return ans;
  
}

int main(){
  
  int s, t, u;
  top = 0;
  char array[1000000];
  
  while(1)
    {
      if( scanf("%s", &array[0]) == EOF ) break;
      
      if ( array[0] == '+' ){
	s = pop();
	t = pop();
	push(s + t);
      } 
      else if ( array[0] == '-' ){
	t = pop();
	s = pop();
	push(s - t);
      }
      else if ( array[0] == '*' ){
	s = pop();
	t = pop();
	push(s * t);
      }
      else {
	u = atoi(array);
	push(u);
      }
    }
  
  printf("%d\n", pop());
  
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  string prev, curr;
  set<string> hist;
  cin >> prev;
  hist.insert(prev);
  rep(i, N - 1) {
    cin >> curr;
    if (prev[prev.size() - 1] != curr[0] || hist.count(curr) > 0) {
      cout << "No" << endl;
      return 0;
    }
    hist.insert(curr);
    prev = curr;
  }
  cout << "Yes" << endl;
}

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

using namespace std;

int n;
int a[100001];

int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)
        scanf("%d",&a[i]);
    sort(a + 1,a + 1 + n);
    int cou = n / 2;
    if(a[cou] == a[cou + 1])
        printf("0\n");
    else
    {
        int ans = a[cou + 1] - a[cou];
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
//#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


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

	for (i = k; i < n; i++)
	{
		if ((a.at(i - k)) >= a.at(i))
		{
			cout << "No" << endl;
		}
		else
		{
			cout << "Yes" << endl;
		}
	}
}


	
	

	
	
/**/
/*#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define PI 3.141592653589793

int main(void) {
	return 0;
}
*/

Measured memory_bytes: 4048
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	ll l = 0; //left pointer
	ll ans = 1;
	vi cnt(22, 0);
	rep(j, 22) if(a[0] & (1 << j)) cnt[j]++;
	repn(i, 1, n){
		//keep deleting from the back?
		rep(j, 22) if(a[i] & (1 << j)){
			if(cnt[j]){
				int f = 1;
				while(f){
					rep(k, 22){
						if(a[l] & (1 << k)) cnt[k]--;
					}		
					if(!cnt[j]) f = 0;
					l++;
				}
			}
			cnt[j]++;
		}
		ans += (ll)(i - l + 1);
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1024
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) { 
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            StringBuilder in = new StringBuilder(sc.nextLine());
            for(; ; ){
                if(in.indexOf("the") >= 0 || in.indexOf("this") >= 0 || in.indexOf("that") >= 0){
                    System.out.println(in);
                    break;
                }
                for(int i = 0; i < in.length(); i++){
                    char c = in.charAt(i);
                    if(Character.isLetter(c))
                        in.setCharAt(i, c == 'z' ? 'a' : (char)(c+1));
                }
            }
        }
    }
}

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

int main(){
	int N;
	cin>>N;
	vector<int>a(N);
	rep(i,N){
		cin>>a.at(i);
	}
	int ans=0;
	rep(i,N){
		if(a.at(a.at(i)-1)==i+1){
			ans++;
		}
	}
	cout<<ans/2;
return 0;}

/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 640
import math

D,G = map(int,input().split(" "))
G //= 100
p = []
c = []
for x in range(D):
    a,b = map(int,input().split(" "))
    p.append(a)
    c.append(b//100)

h = [sum(p)]

for x in range(2**D):
    o = [(x//(2**y))%2 for y in range(D)]
    if not(0 in o):
        continue
    g = sum([p[y]*(y+1)+c[y] for y in range(D) if o[y]])
    if g >= G:
        h.append(sum([p[y] for y in range(D) if o[y]]))
        continue
    s = max([y for y in range(D) if not(o[y])])
    if g + (s+1)*(p[s]-1) >= G:
        h.append(sum([p[y] for y in range(D) if o[y]])+math.ceil((G-g)/(s+1)))

print(min(h))


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

int main() {
  int N;
  cin>>N;
  vector<int> S(N-1,0);
  vector<int> T(N,0);
  for(int i=0; i<N-1; i++){
    cin>>S.at(i);
    T.at(S.at(i)-1)++;
  }
 
  for(int i=0; i<N; i++){
    cout<< T.at(i)<<endl;
  }
}



Measured memory_bytes: 4756
#include<stdio.h>
#include<math.h>
int main(){
 
  int i,n,score[1001],sum;
  double ave,sig,v;
 
   
  while(1){
 
    scanf("%d", &n );
    if ( n == 0 ) break;
     
    for ( i  = 0 ; i < n ; i++ ){
      scanf("%d", &score[i] );
    }
 
    sum = 0;
     
    for ( i = 0 ; i < n ; i++ ){
      sum = sum + score[i];
    }
     
    ave = 1.0 * sum / n;
 
    sig = 0;
     
    for ( i = 0 ; i < n ; i++ ){
      sig +=( score[i] - ave ) * ( score[i] - ave );
    }
 
    v = sqrt( sig / n );
 
    printf("%.8lf\n", v );
 
  }
   
  return 0;
     
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	ll ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A, B, K;
  cin >> A >> B >> K;
  int count = 0;
  int ans = 0;
  
  for(int i=100; i>0; i--){
    if(A %i == 0 && B %i == 0){
      count++;
    }
    if(count == K){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

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

int main(){
	int N,M;
	cin >> N >> M;
	if(N==1){
		int ans=-1;
		for(int i=0;i<M;i++){
			int s,c;
			cin >> s >> c;
			if(ans==-1)ans=c;
			if(ans!=c){
			cout << "-1" << endl;
			return 0;
			}
		}
		if(ans==-1)cout << "0" << endl;
		else cout << ans << endl;
		return 0;
	}
	vector<int> A(N,-1);
	for(int i=0;i<M;i++){
		int s,c;
		cin >> s >> c;
		s--;
		if(s==0 && c==0){
			cout << "-1" << endl;
			return 0;
		}
		if(A[s]==-1)A[s]=c;
		else if(A[s]!=c){
			cout << "-1" << endl;
			return 0;
		}
	}
	for(int i=0;i<N;i++){
		if(A[i]==-1){
			if(i==0)cout << "1";
			else cout << "0";
		}
		else cout << A[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

n,m = map(lambda x: int(x), input().split())
x = [0 for i in range(100005)]
tot=0
ac=0
for i in range(m):
	p, s = input().split()
	p=int(p)
	if x[p] == -1:
		continue
	if s == 'AC':
		ac +=1
		tot+=x[p]
		x[p]=-1
	elif s == 'WA':
		x[p] += 1
print(ac, tot)

Measured memory_bytes: 4224
#include <iostream>
#include <string>

int main(){
  std::string N;
  std::cin >> N;
  if(N[0] == '7' or N[1] == '7' or N[2] == '7'){
    std::cout << "Yes" << std::endl;
  }
  else{
    std::cout << "No" << std::endl;
  }
  return 0;
}

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

int main(){

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

	int A; cin >> A;
	int B; cin >> B;

	int money = 0;
	money += max(A,B);

	if(max(A,B)==A) money += max(A-1,B);
	else money += max(A,B-1);

	cout << money;

	return 0;
}


Measured memory_bytes: 256
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
S, W = readints()
if S <= W:
    print('unsafe')
else:
    print('safe')


Measured memory_bytes: 68640
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define maxn 100005
#define mo 1000000007
#define ll long long 
using namespace std;

int n,m,i,j,k,x[maxn],y[maxn],tot,id[maxn],cnt;
struct arr{int x,y,i;} a[maxn];
int cmp(arr a,arr b){return a.x<b.x||a.x==b.x&&a.y<b.y;}
int cmp2(int i,int j){return a[i].y<a[j].y;}

struct Treearray{
	ll s[maxn];
	void add(int x,ll d){for(;x<=cnt;x+=x&-x) (s[x]+=d)%=mo;}
	ll sum(int x,ll S=0){for(;x;x-=x&-x) (S+=s[x])%=mo; return S;}
} t;

int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++) scanf("%d",&x[i]);
	for(i=1;i<=m;i++) scanf("%d",&y[i]);
	k=0;
	for(i=1;i<=n;i++) {
		while (k<m&&x[i]>y[k]) k++;
		if (x[i]>=y[k]||k==1) continue;
		tot++,a[tot].x=x[i]-y[k-1],a[tot].y=y[k]-x[i];
	}
	sort(a+1,a+1+tot,cmp);
	for(i=1;i<=tot;i++) id[i]=i;
	sort(id+1,id+1+tot,cmp2);
	cnt=1;
	for(i=1;i<=tot;i++) {
		cnt+=(i==1||a[id[i]].y!=a[id[i-1]].y);
		a[id[i]].i=cnt;
	}
	t.add(1,1);
	for(i=1;i<=tot;i=j) {
		for(j=i;j<=tot&&a[j].x==a[i].x;j++);
		for(k=j-1;k>=i;k--) if (k==j-1||a[k].y<a[k+1].y)
			t.add(a[k].i,t.sum(a[k].i-1));
	}
	printf("%lld",t.sum(cnt));
}

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

int main (){
  int N,M;
  long long ans=0;
  cin>>N>>M;
  vector<pair<long long,long long>>energy(N);
  rep(i,N){
    long long a,b;
    cin>>a>>b;
    energy[i]=make_pair(a,b);
  }
  sort(energy.begin(),energy.end());
  for(int i=0;i<N;i++){
    if(energy[i].second>=M){
      ans+=energy[i].first*M;
      cout<<ans;
      return 0;
    }
    else{
      M-=energy[i].second;
      ans+=energy[i].first*energy[i].second;
    }
  }
}


Measured memory_bytes: 1792
object Main {
  def main(args:Array[String]) {
    var count = 0
    var max_time = 0
    var min_cost = 1001
    for(line <- io.Source.stdin.getLines()) {
	  val factors = line.split(" ").map{_.toInt}
	  if(count == 0) {
	    max_time = factors(1)
	  }
	  else {
  	    if(factors(1) <= max_time) {
	      if(factors(0) < min_cost) {
		    min_cost = factors(0)
		  }
	    }
	  }
      count += 1
	}
	if(min_cost == 1001) {
	  println("TLE")
	}
	else {
	  println(min_cost)
	}
  }
}

Measured memory_bytes: 27064
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int N;
    io.read(N);
    string s = to_string(N);
    int dsum = 0;
    for(int i = 0; i < s.size(); i++){
        dsum += s[i] - '0';
    }
    if(N % dsum == 0) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int H,W,i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0&&W==0)break;
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if((i+j)%2==0)printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include<stdio.h>
int main()
{
	int n;
	while (scanf("%d",&n)!=EOF)
	{
		int a,b,c,k;
		if (n>=100&&n<1000)
		{
             a=n%10;
			 b=(n%100-a)/10;
			 c=(n-a-b*10)/100;
			 k=a*100+b*10+c;
			 if (k==n)
				 printf("Yes\n");
			 else printf("No\n");

		}
		else printf("No\n");
	
	}
	return 0;

}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

const int MAXN = 100005;
int n, c, k;
int a[MAXN];

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

    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }

    sort(a, a + n);

    int bus_time = 0;
    int cap_left = 0;
    int buses = 0;

    for (int i = 0; i < n; ++i) {
        if (cap_left == 0 or a[i] > bus_time or a[i] + k < bus_time) {
            ++buses;
            cap_left = c - 1;
            bus_time = a[i] + k;
        } else {
            cap_left -= 1;
        }
    }

    printf("%d\n", buses);

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
 
 
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
 
    string S;
    cin >> S;
    int N = S.size();
    int M = 2019;
 
  int A[M]{}, B[M]{};
  int ans = 0;
  rep(i,N){
    int a = S[i] - '0';
    if(i % 2 == 0){
      rep(j,M){
        B[j] = 0;
      }
      int d = a % M;
      B[d] = 1;
      rep(j,M){
        int z = (j*10+a) % M;
        B[z] += A[j];
      }
      ans += B[0];
    }
    else{
      rep(j,M){
        A[j] = 0;
      }
      int d = a % M;
      A[d] = 1;
      rep(j,M){
        int z = (j*10+a) % M;
        A[z] += B[j];
      }
      ans += A[0];
    }
  }
  cout << ans << endl;
}

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

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

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> val(1e+5 + 10, 0);

    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        val[a] += b;
    }

    ll ans;
    for (int i = 1; i <= 1e+5+10; i++) {
        k -= val[i];
        if (k <= 0) {
            ans = i;
            break;
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4044
def main():
    import sys
    input = sys.stdin.readline
    s = list(input().strip())
    K = int(input())
    for i, c in enumerate(s):
        if c == 'a':
            continue
        z = 123 - ord(c)
        if K >= z:
            s[i] = 'a'
            K -= z
        if K == 0:
            break
    
    s[-1] = chr(((ord(s[-1])-97+K))%26+97)

    print(''.join(s))

if __name__ == '__main__':
     main()

Measured memory_bytes: 4156
import math
import itertools

#math.sqrt(4).is_integer()

#整数になるものの数
ans = 0

cal = []

N,D = map(int,input().split())

#N行D列の配列
G = []
for i in range(N):
    li = list(map(int,input().split()))
    G.append(li)

#点の数
counter = [i for i in range(N)]
#２点の組み合わせの列挙
comb = itertools.combinations(counter, 2)
#列挙したものをリストにする
li_comb = []
for i in comb:
    li_comb.append(i)


for i in range(len(li_comb)):
    for j in range(D):
        cal.append(pow(G[li_comb[i][0]][j]-G[li_comb[i][1]][j],2))
    if math.sqrt(sum(cal)).is_integer() :
        ans += 1
    cal = []

print(ans)


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

using namespace std;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(NULL);
    
    string a="",b="";
    cin >> a >> b;int i,j;
    int al = a.length();int bl = b.length();
    int dp[bl+1][al+1];
    for(i=0;i<=al;i++){
        dp[0][i]=0;
    }
    for(i=1;i<=bl;i++){
        dp[i][0]=0;
        for(j=1;j<=al;j++){
            if(b[i-1] == a[j-1])
            dp[i][j]= dp[i-1][j-1] + 1;
            else
            dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
   /* for(i=0;i<=bl;i++){
        for(j=0;j<=al;j++){
            cout << dp[i][j] << " ";
        }
        cout << "\n";
    }*/
    string s="";i=bl;j=al;
    while(dp[i][j] > 0){

            if(a[j-1]==b[i-1]){
                s = s+b[i-1];
                i--;
                j--;
            }
            else if(dp[i-1][j] > dp[i][j-1]){
            i--;
            }
            else
            j--;
    }
    reverse(s.begin(),s.end());
    cout << s;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  long long ans=0;
  for (int i=K+1;i<N+1;i++){
    int x=N/i;
    int y=N%i;
    ans+=(long long)x*(i-K)+max(0,y-K+1);
    if (K==0){
      ans--;
    }
  }
  cout << ans << endl;
}

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

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

void solve()
{
    ll n;
    cin >> n;
    vll a(n);
    for(ll i=0;i<n;i++) {
    	cin >> a[i];
    }
    ll cnt = 1, ans = 0;
    for(ll i=0;i<n;i++) {
    	if(a[i] == cnt) {
    		cnt++;
    		ans++;
    	}
    }
    if(ans == 0) {
    	cout << "-1\n";
    } else {
    	cout << n - ans << "\n";
    }
}

int main()
{
    FAST_IO;
    #ifndef ONLINE_JUDGE 
      // OC;
    #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>

#define PI 3.14159265359

#define INF 99999999;

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

typedef long long ll;

using namespace std;



/*
class LightSwitchingPuzzle
{
public:
	int minFlips(string s)
	{

	}
}
*/


int main()
{
	for (int n; cin>>n,n;)
	{
		vector<int> is(n), ps(n), qs(n), rs(n);
		for (int i=0; i<n; i++)
		{
			cin >> is[i] >> ps[i] >> qs[i] >> rs[i];
		}
		int P, Q, R, C;
		cin >> P >> Q >> R >> C;
		
		vector<int> res;
		for (int i=0; i<n; i++)
		{
			if (ps[i]<=P && qs[i]<=Q && rs[i]<=R && ps[i]*4+qs[i]*9+rs[i]*4<=C)
			{
				res.push_back(is[i]);
			}
		}
		
		if (res.empty())
		{
			cout << "NA" << endl;
		} else {
			for (int i=0; i<res.size(); i++)
			{
				cout << res[i] << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1240
//
// author  : Abhishek
//
#include <bits/stdc++.h>

#define ll long long
#define db double
#define deb(x) cout<<#x<<": "<<x<<"\n"
#define all(x) x.begin(),x.end()
#define fo(i, n) for(i=0 ; i<n ; i++)
#define Fo(i, k, n) for(i=k ; i<n ; i++)

using namespace std;

const ll mod = 1000000007;
const ll N = 300005;  // array size
const ll inf = 10000000000000000;


void print(vector<ll> v) {
    ll i;
    fo(i, v.size())cout << v[i] << " ";
    cout << "\n";
}

vector<ll> read(ll n) {
    ll i;
    vector<ll> arr(n, 0);
    fo(i, n)cin >> arr[i];
    return arr;
}

vector<ll> read(ll n, ll k) {
    ll i;
    vector<ll> arr(n + k, 0);
    Fo(i, k, n + k)cin >> arr[i];
    return arr;
}

bool isEven(ll n) {
    return n % 2 == 0;
}

bool isOdd(ll n) {
    return n % 2 != 0;
}


void solve() {
    ll t;
    cin >> (t);
    while (t--) {

        ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    }
}

int main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

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

    ll i, j, k, n, m, p, q, x, y, a, b, l, r;

    cin >> n;
    vector<ll> arr(n);
    arr = read(n);
    sort(all(arr));

//    print(arr);

    ll ans = 0;
    fo(i, n - 2) {
        Fo(j, i + 1, n - 1) {
            ll pos = lower_bound(arr.begin(), arr.end(), arr[i] + arr[j]) - arr.begin();
            pos--;

//            cout << i << " i: " << arr[i] << " j: " << arr[j] << " sum:" << arr[i] + arr[j] << " " << pos << "\n";
//            deb(pos - j);
//
            if (pos > j)
                ans += (pos - (j));
        }
    }

    cout << ans << "\n";

    return 0;
}




Measured memory_bytes: 3644
n = int(input())

c = n // 4

ans = 0

for i in range(c+1):
    d = (n - i*4) // 7
    for v in range(d+1):
        buy = i*4 + v*7
        check = buy - n
        
        if check == 0:
            ans = "Yes"

if ans == "Yes":
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
from bisect import bisect_left
 
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
c = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    c += bisect_left(l, l[i]+l[j]) - j - 1
 
print(c)


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

int main() {
    int n;
    cin >> n;
    int v[n];
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v, v + n);

    double ans = v[0];
    for (int i = 1; i < n; i++) {
        ans = (ans + v[i]) / 2;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

bool f(ll n, ll k) {
  if (k == 1) return false;
  while (n > 1) {
    if (n % k == 0) n /= k;
    else if (n / k > 0) n %= k;
    else n -= k;
  }
  return n == 1;
}

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

  ll n;
  cin >> n;

  ll ans = 0;
  bool nminus1 = false;
  for (ll i = 1; i * i <= n; i++) {
    if (f(n, i)) ans++;
    if (i != n/i && f(n, n/i)) ans++;
    if (i == n-1 || n/i == n-1) nminus1 = true;
  }
  if (!nminus1) ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <algorithm>

using namespace std;
using ll = long long int;

int main()
{
    int n;
    cin >> n;
    map<string, ll> mp;
    for (size_t i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        sort(s.begin(), s.end(), [](const char lhs, const char rhs) {
            return lhs < rhs;
        });
        mp[s]++;
    }

    ll ans = 0;
    for (auto &&e : mp)
    {
        if (e.second > 1)
        {
            ans += (e.second) * (e.second - 1) / 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
#include <stdio.h>
int main(){
	int a,b,d,r;
	double f;
	do{
		printf("");
		scanf("%d %d",&a,&b);	
	}while(!(a>=1 && a<=1000000000 && b>=1 && b<=1000000000));
	d=a/b;
	r=a%b;
	f=1.00000*a/b;
	printf("%d %d %.5lf\n",d,r,f);
	return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pll > 
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
//#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
set <pll> adj[200002];
set <lli> adj2[200002];
lli mod=1000000007;
int main() {
	ios::sync_with_stdio(0);
    cin.tie(0);
        lli a,b;
        cin>>a>>b;
        lli c=(a+b)/2;
        a=abs(a-c),b=abs(b-c);
        if(a==b)cout<<c;
        else cout<<"IMPOSSIBLE";


        return 0;
}

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

int solve(int n, int a, int b, int c, int x, vector<int> &y, vector<int> &z) {
  int head = 0;
  rep (t, 10000+1) {
    if (y[head] == z[t]) head++;
    if (head == n) return t;
  }
  return -1;
}

int main() {
  int n, a, b, c, x;
  vector<int> z;
  vector<int> y;

  while(cin >> n >> a >> b >> c >> x, n) {
    y.resize(n);
    z.resize(10000+1);

    rep (i, n) cin >> y[i];

    z[0] = x;
    for (int i=1; i<=10000+1; i++) z[i] = (a*z[i-1] + b) % c;

    cout << solve(n, a, b, c, x, y, z) << endl;
  }
  return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

string s;

void solve(){
 cin >> s;
 ll n=s.length();
 reverse(all(s));
  vll sum(n+1,0);
  ll pow=1;
 rep(i,0,n){  
  sum[i+1]=sum[i]+pow*(s[i]-'0');
  sum[i+1]%=2019; 
  pow*=10;
  pow%=2019; 
 }
  map<ll,ll> mp;
 for(auto a:sum) mp[a]++;  
  ll res=0;
 for(auto p:mp) res+=p.se*(p.se-1)/2; 
 cout << res << endl;
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  


Measured memory_bytes: 5140
from collections import deque


def bfs(p):
    q = deque()
    q.append((p[0], p[1], 0))
    dis = 0
    path[p[0]][p[1]] = 0
    while len(q):
        x, y, s = q.popleft()
        dis = max(dis, s)  
        for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            nx = x + dx
            ny = y + dy
            if 0 <= nx < H and 0 <= ny < W and path[nx][ny] > s + 1 and maze[nx][ny] == '.':
                path[nx][ny] = s + 1
                q.append((nx, ny, s + 1))

    return dis

H, W = map(int, input().split())
maze = [input() for _ in range(H)]

ans = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == '.':
            path = [[1000] * W for _ in range(H)]
            ans = max(ans, bfs((i, j)))

print(ans)


Measured memory_bytes: 44912
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  long long n, k;
  cin >> n >> k;
  n %= k;
  cout << min(n, k - n) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const int H_MAX = 50000;
typedef pair<int, int> P;
int main()
{
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);

    rep(i, N) cin >> A[i] >> B[i];

    vector<vector<ll>> dp(N + 1, vector<ll>(H_MAX, INF));

    rep(i, N + 1) dp[i][0] = 0;

    rep(i, N) {
        rep(j, H_MAX) {
            if (j < A[i]) {
                dp[i + 1][j] = dp[i][j];
            }
            else {
                dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - A[i]] + B[i]);
            }
        }
        ll m = INF;
        for (int j = H_MAX - 1; j >= 0; j--) {
            chmin(m, dp[i + 1][j]);
            chmin(dp[i + 1][j], m);
        }
    }

    ll ans = INF;
    repd(i, H, H_MAX) {
        chmin(ans, dp[N][i]);
    }

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

Measured memory_bytes: 396068
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,maxx;
	cin>>a>>b;
	int x,y,z;
	x=a+b;
	y=a-b;
	z=a*b;
	maxx=max(x,y);
	maxx=max(maxx,z);
	cout<<maxx<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 1000010
#define test(a,n) REP(i,n) cout << a[i] << " ";
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  REP(i,n) cin >> x[i];
  int ans = 100000000000000;
  int sum = 0;
  
  REP(P,110){
    sum = 0;
    REP(i,n){
      sum += abs(P-x[i])*abs(P-x[i]);
    }
    ans = min(ans,sum);
  }
  
  cout << ans;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> num(N);
  for (int i=0; i<N; i++) {
  cin >> num.at(i);
  }
  
  vector<int> ni(N);
  for (int i=0; i<N; i++) {
    for (int j=0; j<30; j++) {
      if (num.at(i) % 2 == 0) {
      ni.at(i)++;
      num.at(i) = num.at(i) / 2;
      }
      else break;
    }
  }
  
  sort(ni.begin(), ni.end());
  
  cout << ni.at(0) << endl;
}

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

template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;
    const F f;
    const Monoid M1;
    int sz;
    vector<Monoid> dat;
    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
        sz = 1;
        while (sz < n) sz <<= 1;
        dat.assign(sz * 2, M1);
    }
    void set(int k, const Monoid &x) { dat[k + sz] = x; }
    void build() {
        for (int k = sz - 1; k > 0; k--) {
            dat[k] = f(dat[2 * k], dat[2 * k + 1]);
        }
    }
    void update(int k, const Monoid &x) {
        dat[k += sz] = x;
        while (k >>= 1) dat[k] = f(dat[2 * k], dat[2 * k + 1]);
    }
    Monoid get(int a, int b) {  // [a, b)
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = f(L, dat[a++]);
            if (b & 1) R = f(dat[--b], R);
        }
        return f(L, R);
    }
    Monoid operator[](const int &k) const { return dat[k + sz]; }
};

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

int main() {
    int n; cin >> n;
    SegmentTree<int> seg(n, [](int a, int b){ return gcd(a, b); }, 0);
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        seg.set(i, a);
    }
    seg.build();
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int left = seg.get(0, i);
        int right = seg.get(i + 1, n);
        ans = max(ans, gcd(left, right));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC110A
int main(void) {
  int a, b, c, n, k, i, cou=0, tmp;
  scanf(" %d %d %d", &a, &b, &c);
  if(a>=b&&a>=c) printf("%d", 10*a+b+c);
  else if(b>=a&&b>=c) printf("%d", 10*b+a+c);
  else printf("%d", 10*c+a+b);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const int A = 26;
    int D; cin >> D;
    vector<int> c(D);
    REP(i,D) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(A));
    REP(i,D) REP(j,A) cin >> s[i][j];

    REP(i,D) {
        auto it = max_element(ALL(s[i]));
        int d = distance(s[i].begin(),it) + 1;
        OUT(d)
    }

    return 0;
}

Measured memory_bytes: 3708
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let (n, d): (usize, isize) = parse_line().unwrap();

    let mut ret = 0;
    for _ in 0..n {
        let (x, y): (isize, isize) = parse_line().unwrap();

        if x * x + y * y <= d * d {
            ret += 1;
        }
    }
    println!("{}", ret);
}


Measured memory_bytes: 2176
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef long long int64;

template<typename CostType>
/// \brief 辺の情報
struct Edge{
  int      to;
  CostType cost;

  Edge(int t, CostType c): to(t), cost(c){
  }
};

template<typename CostType>
class Graph{

private:

  /// \brief adjacent_list_[n]=ノードnの隣接リストを表すvector<Edge>
  std::vector<std::vector<Edge<CostType>>> adjacent_list_;

public:

  /// \brief 頂点数
  const int NODE_SIZE_;

  /// \brief コンストラクタ
  /// \param node_size 頂点数
  explicit Graph(const int node_size): NODE_SIZE_(node_size),
                                       adjacent_list_(node_size){
  }

  /// \brief 有向グラフの辺を生やす
  /// \param from 辺の根本の頂点の番号
  /// \param to 辺の先の頂点の番号
  /// \param cost 辺のコスト
  void SetDirectedEdge(const int from, const int to, const CostType cost){
    adjacent_list_[from].push_back(Edge<CostType>(to, cost));
  }

  /// \brief 無向グラフの辺を生やす
  /// \param node_a 一方の頂点の番号
  /// \param node_b もう一方の頂点の番号
  /// \param cost 辺のコスト
  void
  SetUndirectedEdge(const int node_a, const int node_b, const CostType cost){
    SetDirectedEdge(node_a, node_b, cost);
    SetDirectedEdge(node_b, node_a, cost);
  }

  /// \brief ある頂点の隣接リストを取得
  /// \param node_num 頂点の番号
  /// \return 隣接リスト
  std::vector<Edge<CostType>> GetAdjacentList(int node_num) const{
    return adjacent_list_[node_num];
  }
};

struct State{
  int depth;
  int pos;
  State(int d,int p):depth(d),pos(p){}
};

vector<int> CalcDist(Graph<int>& graph, int start_pos){
  vector<int> dist(graph.NODE_SIZE_+1,-1);
  queue<State> q;
  q.push(State(0,start_pos));
  dist[start_pos]=0;

  while(!q.empty()){

    State curr=q.front();
    q.pop();
    for(auto e:graph.GetAdjacentList(curr.pos)){
      if(dist[e.to]==-1){
        dist[e.to]=curr.depth+1;
        q.push(State(curr.depth+1,e.to));
      }
    }

  }

  return dist;
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n,u,v;
  cin>>n>>u>>v;

  Graph<int> graph(n+1);
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    graph.SetUndirectedEdge(a,b,1);
  }

  vector<int> tak_dist=CalcDist(graph, u), aok_list=CalcDist(graph,v);

  int result=0;
  for(int i=1;i<=n;i++){
    if(tak_dist[i]>aok_list[i]) continue;
    if(tak_dist[i]==aok_list[i]){
      bool all_same=true;
      for(auto e:graph.GetAdjacentList(i)){
        if(tak_dist[e.to]!=aok_list[e.to]){
          all_same=false;
        }
      }
      if(all_same) continue;
    }
    int tmp_res=tak_dist[i];
    int bet=aok_list[i]-tak_dist[i];
    if(bet>=2){
      tmp_res+=bet-1;
    }
    result=max(result,tmp_res);
  }
  cout<<result<<endl;







  return 0;
}

Measured memory_bytes: 7296
s = [_ for _ in input()]

def are_different(a, b):
    if (a == "0" and b == "1") or (a == "1" and b == "0"):
        return True
    else:
        return False

len_ori = len(s)
res = []
while len(s) > 0:
    # print("1")
    # print(res, s)
    while len(s) >= 2 and s[0] != s[1]:
            s.pop(0)
            s.pop(0)
    # print("2")
    # print(res, s)
    while len(s) >= 1 and len(res) >= 1 and res[-1] != s[0]:
        res.pop(-1)
        s.pop(0)
    if len(s) >= 1:
        res.append(s[0])
        s.pop(0)

    # print("3")
    # print(res, s)

print(len_ori - len(res))
# print("1")
# print(res, s)
# # if s[0] != s[1]:
# while len(s) >= 2 and s[0] != s[1]:
#         s.pop(0)
#         s.pop(0)
# res.append(s[0])
# s.pop(0)
# print("2")
# print(res, s)
# while len(s) >= 1 and len(res) >= 1 and res[-1] != s[0]:
#     res.pop(-1)
#     s.pop(0)

# print("3")
# print(res, s)


Measured memory_bytes: 4252
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();   //スタック要素数
        int q = sc.nextInt();   //命令数

        ArrayList<Deque<Integer>> stack = new ArrayList<>();
        for(int i = 0;i < n;i++){
            stack.add(new ArrayDeque<>());
        }

        for(int i = 0;i < q;i++){
            int num = sc.nextInt(); //命令番号
            int t = sc.nextInt();   //指定スタック番号
            switch(num){
                case 0: //push
                    int x = sc.nextInt();
                    stack.get(t).add(x);
                    break;
                case 1: //top
                    if(stack.get(t).size() > 0)
                        System.out.println(stack.get(t).getLast());
                    break;
                case 2: //pop
                    if(stack.get(t).size() > 0)
                        stack.get(t).removeLast();
                    break;
            }
        }
    }
}




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

int main() {
  int chkKin;
  int iKin,iKinNext;
  double d;
  int pay;
  
  cin >> pay;
  
  chkKin = pay / 1.08;
  iKin = chkKin * 1.08;
  d = (chkKin + 1) * 1.08;
  iKinNext = d;
  
  if(pay == iKin) cout << chkKin;
  else if(pay == iKinNext) cout << chkKin + 1;
  else cout << ":(";    
}


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

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

int main()
{	
	ll a, b, c, d;
	cin >> a >> b >> c >> d;



	//cでもdでも割り切れない = 全体 - （cまたはdで割り切れる）
	//cまたはdで割り切れる   = cで割り切れる + dで割り切れる - （cとd両方で割り切れる）
	//cとd両方で割り切れる   = cとdの最小公倍数で割り切れる


	//cで割り切れる数の個数の計算
	ll dc = (b / c) - ((a - 1) / c);

	//cで割り切れる数の個数の計算
	ll dd = (b / d) - ((a - 1) / d);

	//cとd両方で割り切れる数の個数の計算

	//最小公倍数の計算
	//最大公約数の計算
	ll gcd = 0;

	{
		ll x = c;
		ll y = d;
		ll tmp = 0;

		do
		{ 
			tmp = y;
			y = x % y;
			x = tmp;

		} while (y != 0);

		gcd = tmp;
	}

	ll lcm = c * d / gcd;
	ll dcd = (b / lcm) - ((a - 1) / lcm);


	cout << (b - a + 1) - (dc + dd - dcd) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	char op1[20],op2[20];
	int i;
	for(i=0;i<a;i++)
		op1[i]=b+48;
		op1[i]='\0';
	for(i=0;i<b;i++)
		op2[i]=a+48;
		op2[i]='\0';
	int judge=strcmp(op1,op2); 
	if(judge<=0)
	printf("%s",op1);
	else printf("%s",op2);
	return 0;
} 

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    int n;cin>>n;
    vector<long long> a(n),b(n+1);
    map<long long, long long> cnt;
    for(int i=0;i<n;++i)cin>>a[i];
    b[0]=0;
    for(int i=0;i<n;++i)b[i+1] = b[i]+a[i];
    for(int i=0;i<=n;++i)cnt[b[i]]++;
    long long res = 0;
    for(auto itr=cnt.begin();itr!=cnt.end();itr++){
        res += itr->second*(itr->second-1)/2;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
///                    BISMILLAHIR RAHMANIR RAHIM
#define max 100006
int siv[max];
int sieve(int n)
{
    siv[0]=1;
    siv[1]=1;
    for(int i=4;i<max;i+=2)
        siv[i]=1;
        int sq=sqrt(max);
        for(int i=3;i<=sq;i+=2){
            if(siv[i]==0){
                for(int j=i*i;j<=max;j+=i){
                    siv[j]=1;
                }
            }
        }
        for(int i=n;i<=max;i++){
            if(siv[i]==0){
                return i;
            }
        }
}
int main()
{
 int x;
 cin>>x;
  int ans=sieve(x);
 cout<<ans<<endl;

}

/// A L H A M D U L I L L A H


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

void solve() 
{
    string s,t;cin>>s>>t;
    t.pop_back();
    cout<<(s==t?"Yes":"No")<<endl;
}

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

Measured memory_bytes: 3656
#include <stdio.h>
#include <string.h>
int main(void){
    int a,b;
    int n,i,N=0;
    int ans;
    scanf("%d %d",&a ,&b);
    n=b-a;
    for(i=1;i<n;i++){
        N=N+i;
    }
    ans=N-a;
    printf("%d\n",ans);

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);

  int max=-1;
  for(int i=0; i<d.size(); i++) {
    cin >> d.at(i);
    if(max < d.at(i)) max=d.at(i);
  }

  int X=0;
  int pastmax;
  do {
    X++;
    pastmax = max;
    max=-1;
    for(int i=0; i<d.size(); i++) {
      if(max<d.at(i) && d.at(i)<pastmax) max=d.at(i);
    }
  } while(max!=-1);
  cout << X << endl;
}


Measured memory_bytes: 256
n = list(map(int, list(input())))[::-1] + [0]
sum1 = sum(n)
for i in range(len(n)-1):
    if n[i] > 5 or (n[i]==5 and n[i+1]>4):
        n[i] = 10-n[i]
        n[i+1] += 1
print(min(sum1, sum(n)))


Measured memory_bytes: 141884
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,top,dis[N],ans[N],head[N];
struct node{
	int too,next,zh;
}edge[N*2];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
void add(int a,int b,int c)
{
	edge[++top].too=b;edge[top].zh=c;
	edge[top].next=head[a];head[a]=top;	
}
void dfs(int u,int fa)
{
	if((dis[u]-dis[1])%2==0)ans[u]=0;
	else ans[u]=1;
	for(int i=head[u];i;i=edge[i].next)
	{
		int v=edge[i].too;
		if(v==fa)continue;
		dis[v]=dis[u]+edge[i].zh;
		dfs(v,u);
	}
}
int main()
{
	n=read();
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read(),z=read();
		add(x,y,z);
		add(y,x,z);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
	return 0;
}

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

int main(){
	int n,i,a,point;
	while(cin >> n && n){
		point = 0;
		for(i = 0;i < n / 4;i++){
			cin >> a;
			point += a;
		}
		cout << point << endl;
	}
	return 0;
}

Measured memory_bytes: 0