akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<ll> a(N), b(N);
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
    if (a == b) {
        cout << 0 << '\n';
        return 0;
    }
    ll ans = 0;
    ll mi = LINF;
    for (int i = 0; i < N; i++) {
        ans += a[i];
        if (a[i] > b[i]) {
            mi = min(mi, b[i]);
        }
    }
    cout << ans - mi << '\n';

}


Measured memory_bytes: 3628
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int d=in.nextInt(),l=in.nextInt();
		int cnt=0;
		while(d>0) {
			if(l>d)d--;
			else d-=l;
			cnt++;
		}
		System.out.println(cnt);
	}

}



Measured memory_bytes: 26244
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<map>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 110000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<pair<ll,ll>,ll> p;
typedef pair< pair<ll,ll>, ll> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
ll par[110000]; //親

// n要素を初期化
void init(ll n){
  for(ll i=0;i<n;i++){
    par[i]=-1;
  }
}

//木の根を求める
ll find(ll x){
  if(par[x]<0){
    return x;
  }else{
    return par[x]=find(par[x]);
  }
}

ll usize(ll x){
  return -par[find(x)];
}


//xとyの属する集合を併合
void unite(ll x,ll y){
  x=find(x);
  y=find(y);
  if(x==y) return;

  if(usize(x)<usize(y)) swap(x,y);
  par[x]+=par[y];
  par[y]=x;
}


//xとyが同じ集合に属するか否か
bool same(ll x,ll y){
  return find(x)==find(y);
}


int main(){
    ll N,M,A[110000],B[110000];
    cin>>N>>M;
    vector<ll> ans;
    for(ll i=0;i<M;i++){
        cin>>A[i]>>B[i];
        A[i]--; B[i]--;
    } 
    init(N);
    ans.push_back((ll)N*(N-1)/2);
    ll now=N*(N-1)/2;
    for(ll i=M-1;i>=0;i--){
        ll a=A[i],b=B[i];
        if(same(a,b)){
            ans.push_back(now);
        }else{
            ll plus=(ll)usize(a)*usize(b);
            unite(a,b);
            now-=plus;
            ans.push_back(now);
        }
    }
    for(ll i=M-1;i>=0;i--){
        cout<<ans[i]<<endl;
    }
}



Measured memory_bytes: 4596
#include<bits/stdc++.h>
#define M 200005
#define LL long long
using namespace std;
int n,q;
struct edge{
	int to,fr;
}E[M<<1];
int lst[M],tote;
void addedge(int a,int b){
	E[++tote]=(edge){b,lst[a]};
	lst[a]=tote;
}
void addedges(int a,int b){
	addedge(a,b);addedge(b,a);
}
struct node{
	int id,d;
};
vector<node>P[M];
int D[M];
int sz[M],dep[M],son[M],fa[M],top[M],ID[M];
int L[M],R[M],TT;
struct Tree{
	int L,R;
	LL sum;
	int cnt;
	Tree operator +(Tree x){
		return (Tree){L,x.R,sum+x.sum,cnt+x.cnt};
	}
};
struct Seg{
	Tree T[M<<2];
	void Up(int p){
		T[p]=T[p<<1]+T[p<<1|1];
	}
	void Build(int l,int r,int p){
		T[p].L=l,T[p].R=r;
		if(l==r){
			T[p].sum=D[ID[l]];
			return;
		}
		int mid=(l+r)>>1;
		Build(l,mid,p<<1);
		Build(mid+1,r,p<<1|1);
		Up(p);
	}
	Tree Sum(int l,int r,int p){
		if(T[p].L==l&&r==T[p].R)return T[p];
		int mid=(T[p].L+T[p].R)>>1;
		if(mid>=r)return Sum(l,r,p<<1);
		else if(mid<l)return Sum(l,r,p<<1|1);
		else return Sum(l,mid,p<<1)+Sum(mid+1,r,p<<1|1);
	}
	void Add(int x,int c,int cc,int p){
		if(T[p].L==T[p].R){
			T[p].sum=c;
			T[p].cnt=cc;
			return;
		}
		int mid=(T[p].L+T[p].R)>>1;
		if(mid>=x)Add(x,c,cc,p<<1);
		else Add(x,c,cc,p<<1|1);
		Up(p);
	}
}Tr;

void dfsinit(int v,int f){
	sz[v]=1;
	for(int i=lst[v];i;i=E[i].fr){
		int u=E[i].to;
		if(u==f)continue;
		dep[u]=dep[v]+1;
		fa[u]=v;
		dfsinit(u,v);
		sz[v]+=sz[u];
		if(sz[u]>sz[son[v]])son[v]=u;
	}
}
void Redfs(int v,int tp){
	L[v]=++TT;ID[TT]=v;
	top[v]=tp;
	if(son[v])Redfs(son[v],tp);
	for(int i=lst[v];i;i=E[i].fr){
		int u=E[i].to;
		if(u==fa[v]||u==son[v])continue;
		Redfs(u,u);
	}
	R[v]=TT;
}
void init(){
	dfsinit(1,0);
	Redfs(1,1);
	Tr.Build(1,TT,1);
	for(int i=1;i<n;i++)
		for(int j=0,sz=P[i].size();j<sz;j++)
			Tr.Add(L[P[i][j].id],P[i][j].d,0,1);
}
struct QAQ{
	int id,td,a,b;
};
vector<QAQ>Q[M];
LL ans[M];
int main(){
	scanf("%d%d",&n,&q);
	for(int i=1,a,b,c,d;i<n;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		P[c].push_back((node){i+n,d});
		D[i+n]=d;
		addedges(a,i+n);
		addedges(b,i+n);
	}
	init();
	for(int i=1,a,b,c,d;i<=q;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		Q[a].push_back((QAQ){i,b,c,d});
	}
	for(int i=1;i<n;i++){
		if(Q[i].empty())continue;
		for(int j=0,sz=P[i].size();j<sz;j++)
			Tr.Add(L[P[i][j].id],0,1,1);
		for(int j=0,sz=Q[i].size();j<sz;j++){
			int a=Q[i][j].a,b=Q[i][j].b,c=0;
			LL d=Q[i][j].td;
			LL dis=0;
			while(top[a]!=top[b]){
				if(dep[top[a]]<dep[top[b]])swap(a,b);
				Tree tt=Tr.Sum(L[top[a]],L[a],1);
				c+=tt.cnt;dis+=tt.sum;
				a=fa[top[a]];
			}
			if(dep[a]<dep[b])swap(a,b);
			Tree tt=Tr.Sum(L[b],L[a],1);
			c+=tt.cnt;
			dis+=tt.sum;
			dis+=d*c;
			ans[Q[i][j].id]=dis;
		}
		for(int j=0,sz=P[i].size();j<sz;j++)
			Tr.Add(L[P[i][j].id],P[i][j].d,0,1);
	}
	for(int i=1;i<=q;i++)printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 49396
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define mod 1000000007
#define dbl double
#define pb push_back
#define vec vector<ll>
#define vecp vector<pair<ll,ll> >
using namespace std;
void fio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
}

int main()
{
	char c;
	cin>>c;
	//cout<<(int)c;
	if((int)c>=97)
	cout<<"a"<<endl;
	else
	cout<<"A"<<endl;
	
	return 0;
}

Measured memory_bytes: 3592
// ConsoleApplication7.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char* argv[])
{
	int i, j, k;
	int n;
	int b, f, r, v;
	int building[4][3][10];

	cin >> n;
	memset(building, 0, sizeof(building));

	for (i = 0; i < n; i++) {
		cin >> b;
		cin >> f;
		cin >> r;
		cin >> v;
		building[b - 1][f - 1][r - 1] += v;
	}

	for (i = 0; i < 4; i++) {
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 10; k++) {
				cout << " " << building[i][j][k];
			}
			cout << endl;
		}
		if (i < 3) {
			cout << "####################" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3052
#include <stdio.h>
int main(){
    int i,n;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    int j;
    
    
    printf("%d",a[n-1]);
    
    for(j=2;j<=n;j++)
        printf(" %d",a[n-j]);

printf("\n");
}



Measured memory_bytes: 2084
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

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

    ll tmp = (c-a-b)*(c-a-b);
    if(c-a-b<=0){
        cout << "No" << endl;
        return 0;
    }

    if(tmp>4LL*a*b){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
int MOD=1000000007;
bool compare(string const& a,string const& b,int push){
    bool res=true;
    if(a=="inf"){
        res=false;
        goto FINE;
    }
    if(b=="inf")goto FINE;
    if((int)a.length()+1==b.length()){
        int n=(int)b.length();
        int i=0;
        while(a[i]==b[i]&&i<n)i++;
        if(a[i]<b[i]&&i<n)res=false;
        else if(i==n){
            if(push+'0'<b[i])res=false;
        }
    }
    else if((int)a.length()+1<(int)b.length())res=false;
    else res=true;
    FINE:
    return res;
}
signed main(){
    int n,m;cin>>n>>m;
    vector<int> num={0,2,5,5,4,5,6,3,7,6};
    vector<int> a(m);
    rep(i,m)cin>>a[i];
    vector<pair<int,int>> use;
    rep(i,m){
        use.push_back(make_pair(a[i],num[a[i]]));
    }
    sort(use.begin(),use.end());
    reverse(use.begin(),use.end());
    vector<string> dp(10001,"inf");
    dp[0]='0';
    rep(i,m){
        rep(j,n+1){
            if(j>=use[i].second){
                if(compare(dp[j-use[i].second],dp[j],use[i].first)){
                    dp[j]=dp[j-use[i].second];
                    dp[j]+=use[i].first+'0';
                }
            }
        }
    }
    rep(i,n+1){
        //cout<<dp[i]<<" ";
    }
    //cout<<endl;
    int numm=(int)dp[n].size();
    for(int i=1;i<numm;i++)cout<<dp[n][i];
    cout<<endl;
    //cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 43136
# 約数の列挙
#############################################################
def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
#############################################################

N = int(input())
div1 = make_divisors(N)
div2 = make_divisors(N - 1)
div_set = set(div1 + div2)
div_set.remove(1)
# print(div_set)
ans = 0
for div in div_set:
    tmp = N
    while tmp % div == 0:
        tmp = tmp // div

    if tmp % div == 1:
        ans += 1
print(ans)


Measured memory_bytes: 66704
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.cpp
 * Author: Allen
 *
 * Created on January 12, 2019, 5:45 PM
 */

#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
int dp[100000];
    vector<int> matrix[100000];
int go(int a){
    if(dp[a]!=-1){
        return dp[a];
    }
    int an=0;
    for(int b:matrix[a]){
        an=max(an,go(b)+1);
    }
    return dp[a]=an;
}

/*
 * 
 */
int main(int argc, char** argv) {
    int n,m;
    cin>>n>>m;
    bool start[n];
    for(int i=0;i<n;i++){
        start[i]=true;
        dp[i]=-1;
    }
    int a,b;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        a-=1;
        b-=1;
        matrix[a].push_back(b);
        start[b]=false;
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(start[i]){
        ans=max(ans,go(i));
        }
    }
    printf("%d",ans);
    return 0;
}



Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

int N;
Graph<int> G;
vector<int> dp;
vector<int> modpow;
int rec(int v, int p = -1) {
    int res = 0;
    int tmp = modpow[N - 1] - 1;
    dp[v] = 1;
    for (auto nv : G[v]) {
        if (nv == p)
            continue;
        (res += rec(nv, v)) %= MOD;
        (tmp -= modpow[dp[nv]] - 1) %= MOD;
        dp[v] += dp[nv];
    }
    (tmp -= modpow[N - dp[v]] - 1) %= MOD;
    (res += tmp) %= MOD;
    return res;
}

void extGCD(ll a, ll b, ll &p, ll &q) {
    if (b == 0) {
        p = 1, q = 0;
        return;
    }
    extGCD(b, a % b, q, p);
    q -= a / b * p;
}

int modinv(ll a, ll m) {
    ll p, q;
    extGCD(a, m, p, q);
    p %= m;
    if (p < 0)
        p += m;
    return p;
}

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

    cin >> N;
    G.resize(N);
    for (int i = 1; i < N; ++i) {
        int A, B;
        cin >> A >> B;
        A--, B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    modpow.resize(N + 1);
    modpow[0] = 1;
    for (int i = 1; i <= N; ++i)
        modpow[i] = (modpow[i - 1] * 2) % MOD;

    dp.resize(N);
    ll res = rec(0);
    if (res < 0)
        res += MOD;
    (res *= modinv(modpow[N], MOD)) %= MOD;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 23936
#include <iostream>

using namespace std;
#include <string>
typedef long long int ll;

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

  string S;
  cin >> S;

  int count = 0;
  for (size_t i = 0; i < 1000; i++) {
    string s_ = to_string(i);
    while(s_.length()<3){
      s_ = "0"+s_;
    }
    int keta=0;
    int num = 0;
    for(int n=0;n<N;n++){
      //string s = S[n];
      if(S[n]==s_[keta]){
        keta += 1;
        if(keta==3){
          count += 1;
          break;
        }
      }
    }
  }

  cout << count;

  return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll              long long
#define pi              pair<int,int>
#define pll             pair<ll,ll>
#define pb              push_back
#define F               first
#define S               second
#define vi              vector<int>
#define vll             vector<ll>
#define endl            '\n'
#define all(v)          (v).begin(),(v).end()
#define FOR(i,a,b)      for(int i=a;i<b;i++)
#define MP(a,b)         make_pair(a,b)
#define debug(x)        cerr<< #x << " : " << x << endl;
#define debugp(p)       cerr<< #p << " : " << "(" << (p).first << "," << (p).second << ")\n";
#define debugv(v)       cerr<< #v << " : " << "["; for(int i = 0; i < (v).size(); i++) cerr << v[i] << " "; cerr<<"]\n";
#define debugs(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<*itr << " "; cerr << "]\n";
#define debugm(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<"(" << itr->first << "," << itr->second << ") "; cerr << "]\n";

/* ordered set: 
tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
member functions :
1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/

inline ll modexp(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}

const int inf = 1e9 + 7;

void solve(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll cmax = a[0];
    ll ans = 0;
    for (int i = 1; i < n; i++){
        if (a[i] >= cmax){
            cmax = max (cmax , a[i]);
        } else{
            ans += cmax - a[i];
        }
    }
    cout << ans << endl;
}
int main(){
    ios :: sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
    
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    #ifdef LOCAL
    cerr << "Time elapsed\t: " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";       
    #endif
}



Measured memory_bytes: 4764
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef int64_t i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
    i64 from, to, cost;
    edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

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

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}
//

#pragma endregion

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

int main() {
    i64 n, k;
    cin >> n >> k;
    vector<P> v;
    for (int i = 0; i < n; ++i) {
        i64 a, b;
        cin >> a >> b;
        v.push_back(P(a, b));
    }
    sort(v.begin(), v.end());
    i64 sum = 0;
    for (int i = 0; i < n; ++i) {
        sum += v[i].second;
        if (sum >= k) {
            cout << v[i].first << endl;
            break;
        }
    }
}


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

int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if (L > R){
    cout << "Left" << endl;
  }
  else if (L < R){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
  
}

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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
    a[i]--;
  }
  queue<int> btn;
  btn.push(a[0]);
  int cnt=0;
  bool flag=0;
  rep(i,n){
    cnt++;
    if(btn.front()==1){
      flag=1;
      break;
    }
    btn.push(a[btn.front()]);
    btn.pop();
  }
  if(flag) cout<<cnt<<endl;
  else cout<<-1<<endl;
}

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

int main() {
    string s;
    cin >> s;
    char c = s[0];
    int ans = 0;
    for (int i = 1; i < s.size(); i++) {
        if (c != s[i]) {
            ans++;
            c = s[i];
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ele int
using namespace std;
#define maxn 100010
#define maxk 2010
ele n,k,x[maxn],y[maxn],c[maxn],a[maxk][maxk];
char s[100];
inline ele qry(ele i,ele j){
	if (i<0 || j<0) return 0;
	return a[i][j];
}
inline ele qry(ele i1,ele j1,ele i2,ele j2){
	if (i1>=k*2 || j1>=k*2) return 0;
	if (i2<0 || j2<0) return 0;
	i1=max(0,i1); j1=max(0,j1);
	i2=min(i2,k*2-1); j2=min(j2,k*2-1);
	return qry(i2,j2)-qry(i1-1,j2)-qry(i2,j1-1)+qry(i1-1,j1-1);
}
int main(){
	scanf("%d%d",&n,&k);
	ele cnt=0;
	memset(a,0,sizeof(a));
	for (int i=0; i<n; ++i){
		scanf("%d%d%s",x+i,y+i,s);
		x[i]%=k*2; y[i]%=k*2;
		if (s[0]=='B') c[i]=0,--a[x[i]][y[i]],++cnt;
		else c[i]=1,++a[x[i]][y[i]];
	}
	for (int i=0; i<(k<<1); ++i){
		for (int j=1; j<(k<<1); ++j) a[i][j]+=a[i][j-1];
		if (i) for (int j=0; j<(k<<1); ++j) a[i][j]+=a[i-1][j];
	}
	ele ans=0;
	for (int i=0; i<(k<<1); ++i)
		for (int j=0; j<(k<<1); ++j){
			ele tmp=0;
			for (int di=-2; di<3; ++di)
				for (int dj=-2; dj<3; ++dj){
					if ((di+dj)&1) continue;
					ele ni=i+k*di,nj=j+k*dj;
					tmp+=qry(ni,nj,ni+k-1,nj+k-1);
				}
			ans=max(ans,cnt+tmp);
		}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
	// n := 人数
	int n;
	while( cin >> n , n ){
		// s[i][j] := i が j さんの個人情報を知っているかどうか.
		int s[101][101] = {0};
		
		for(int i=0 ; i < n ; i++ ){
			int m;
			cin >> m;
			for(int j=0 ; j < m ; j++ ){
				int p;
				cin >> p;
				p--;
				// i さんは p さんの個人情報を知っている.
				s[i][p] = 1;
			}
		}
		// k := 個人情報が漏洩した人数.
		int k;
		cin >> k;
		// L := 個人情報が漏洩した人の番号を保持する配列.
		vector<int> L(k);
		for(int i=0 ; i < k ; i++ ){
			cin >> L[i];
			L[i]--;
		}
		
		// ans := 個人情報を漏らした可能性のある人の番号を保持する配列.
		vector<int> ans;
		
		for(int y=0 ; y < n ; y++ ){
			bool flag = true;
			// foo := y さんが知っている人の番号を保持する配列
			vector<int> foo;
			for(int x=0 ; x < n ; x++ ){
				if( s[y][x] ) foo.push_back( x );
			}
			for(int i=0 ; i < L.size() ; i++ ){
				// x さんは L[i] さんの情報を漏らした可能性がなければ flag を false にしておく.
				if( count(foo.begin(), foo.end(), L[i] ) == 0 ){
					flag = false;
				}
			}
			// x さん が個人情報を漏らした可能性のある人なら ans に追加.
			if( flag ) ans.push_back( y );
		}
		
		// 個人情報を漏らした可能性のある人物が一人だけならその番号を出力, そうでなければ -1 を出力.
		if( ans.size() == 1 ){
			cout << (ans[0]+1) << endl;
		}else{
			cout << -1 << endl;
		}
	}
}

Measured memory_bytes: 948
program main
implicit none
integer i,m,n,p,sumwa
integer,allocatable :: ac(:),wa(:)
character(2) s
read(*,*) n,m

allocate(ac(n))
allocate(wa(n))
ac(:)=0;wa(:)=0
sumwa=0

do i=1,m
   read(*,*) p,s
   if(ac(p)==0) then
      if(s=='AC') then
         ac(p)=1
         sumwa =sumwa + wa(p)
      else if(s=='WA') then
         wa(p)=wa(p) + 1
      end if
   endif
end do
      
write(*,'(i0,a,i0)') sum(ac),' ',sumwa
end program main



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

const string YES = "Yes";
const string NO = "No";

int solve(long long H, long long N, std::vector<long long> A)
{
    for (int i = 0; i < N; i++)
    {
        H -= A[i];

        if (H <= 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

// Generated by 1.1.6 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 H;
    scanf("%lld", &H);
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(H, N, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        A, B, C, X = [int(input()) for _ in range(4)]
        ans = 0
        for a in range(A + 1):
            for b in range(B + 1):
                for c in range(C + 1):
                    if 500 * a + 100 * b + 50 * c == X:
                        ans += 1
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 38896
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	ll k; cin >> k;
	ll ans = 0;
	for( ll a = 1; a <= k; ++a ){
		for( ll b = 1; b <= k; ++b ){
			for( ll c = 1; c <= k; ++c ){
				ans += __gcd(__gcd(a, b), c);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    cout << (n >= 1000 ? "ABD" : "ABC") << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int K ;
    string S ;
    
    cin >> K >> S ;
    if( K >= S.size() )
    {
        cout << S << endl ;
    }
    else
    {
        for( int i = 0 ; i < K ; ++i )
        {
            cout << S.at(i) ;
        }
        cout << "..." << endl ;
    }

}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	string S;
	cin >> S;
	ll N = S.size();
	vector<ll> red(N+1, 0), blue(N+1, 0);
	REP(i, N){
		if(S[i]=='0'){
			red[i+1] = red[i] + 2;
			blue[i+1] = blue[i];
		}else if(S[i]=='1'){
			red[i+1] = red[i] + 1;
			blue[i+1] = blue[i] + 1;
		}else{
			red[i+1] = red[i];
			blue[i+1] = blue[i] + 2;
		}
	}
	ll ma = 4040;
	ll dp[ma][ma];
	REP(i, ma)REP(j, ma) dp[i][j] = 0;
	dp[0][0] = 1;
	REP(i, 2*N){
		ll ikeru = min((ll)i, N-1);
		ll ikered = red[ikeru+1];
		ll ikeblue = blue[ikeru+1];
		REP(j, 2*N){
			if(ikered>j){
				dp[i+1][j+1] += dp[i][j];
				dp[i+1][j+1] %= mod;
			}
			if(ikeblue>i-j){
				dp[i+1][j] += dp[i][j];
				dp[i+1][j] %= mod;
			}
		}
	}
	cout << dp[2*N][red[N]] << endl;
    return 0;
}

Measured memory_bytes: 127744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
const int INF=1001001001;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数
const ll MAXN = 1001024; // b-a < MAXN, sqrt(b) < MAXN


int main(){
    int n;
    cin >> n;
    int x[n], y[n];
    double cnt = 0;
    rep(i, n)
    {
        cin >> x[i] >> y[i];
    }
    rep(j,n-1){
        rep2(i,j+1,n){
            cnt += (double)pow((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]), 0.5);
        }
    }
    cout <<fixed<<setprecision(10)<<cnt*2/n << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
int main (){
	int N, A,B;
	scanf("%d %d %d",&N,&A,&B);
	int sum=0;
	for (int i=0 ; i<=N ;i++){
		int digit=0;
		int temp=i;
		while (temp!=0){
			digit+=temp%10;
			temp/=10;
		}
		if (digit>=A&&digit<=B){
			sum+=i;
		}
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 1732
#include <cstring>
#include <cstdio>
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

int dp[2][2][2][2][2][10][512];

char a[512];
char b[512];
int m;
int aa[512];
int bb[512];

int main(){
  scanf("%s", a);
  scanf("%s", b);
  scanf("%d", &m);

  int nb = strlen(b);
  int na = strlen(a);

  REP(i,na) aa[i] = a[na - i - 1] - '0';
  REP(i,nb) bb[i] = b[nb - i - 1] - '0';

  reverse(aa, aa + nb);
  reverse(bb, bb + nb);

  for(int i = aa[0]; i <= bb[0]; i++){
    int fa = 0;
    int fb = 0;
    int nz = 0;
    if(i > aa[0]) fa = 1;
    if(i < bb[0]) fb = 1;
    if(i != 0) nz = 1;
    dp[0][fa][fb][nz][0][i][i % m] = 1;
    if(nz == 1 && nb != 1)
      dp[0][fa][fb][nz][1][i][i % m] = 1;
  }

  REP(i,nb - 1){
    REP(fa,2) REP(fb,2) REP(nz,2) REP(ud,2) REP(p, 10) REP(am, m)
      dp[(i + 1) % 2][fa][fb][nz][ud][p][am] = 0;

    REP(fa,2) REP(fb,2) REP(nz,2) REP(ud,2)
      REP(p,10) REP(am, m) if(dp[i % 2][fa][fb][nz][ud][p][am]){
      int low  = 0;
      int high = 9;

      // printf("%d: %d %d %d %d %d %d: %d\n", i, fa, fb, nz, ud, p, am, dp[i % 2][fa][fb][nz][ud][p][am]);

      if(fa == 0) low  = aa[i + 1];
      if(fb == 0) high = bb[i + 1];

      if(nz == 1){
        if(ud == 0) low  = max(low, p + 1);
        else        high = min(high, p - 1);
      }

      for(int next = low; next <= high; next++){
        int ffa = fa;
        int ffb = fb;
        int nnz = nz;
        if(next > aa[i + 1]) ffa = 1;
        if(next < bb[i + 1]) ffb = 1;
        if(next > 0) nnz = 1;
        if(nz == 0 && nnz == 1 && i != nb - 2){
          dp[(i + 1) % 2][ffa][ffb][nnz][0][next][(am * 10 + next) % m]
            = (dp[i % 2][fa][fb][nz][ud][p][am] + dp[(i + 1) % 2][ffa][ffb][nnz][0][next][(am * 10 + next) % m]) % 10000;
          dp[(i + 1) % 2][ffa][ffb][nnz][1][next][(am * 10 + next) % m]
            = (dp[i % 2][fa][fb][nz][ud][p][am] + dp[(i + 1) % 2][ffa][ffb][nnz][1][next][(am * 10 + next) % m]) % 10000;
        }else{
          dp[(i + 1) % 2][ffa][ffb][nnz][!ud][next][(am * 10 + next) % m]
            = (dp[i % 2][fa][fb][nz][ud][p][am] + dp[(i + 1) % 2][ffa][ffb][nnz][!ud][next][(am * 10 + next) % m]) % 10000;
        }
      }
    }
  }

  int ans = 0;

  REP(fa,2) REP(fb,2) REP(ud,2) REP(p,10)
    ans = (ans + dp[(nb - 1) % 2][fa][fb][1][ud][p][0]) % 10000;

  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1368
#include <stdio.h>
int main(){
  int A,B,C,K;
  scanf("%d %d %d %d",&A,&B,&C,&K);
  if(K<A){printf("%d",K);}
  else if(K>A+B){printf("%d",A-(K-(A+B)));}
  else{printf("%d",A);}
  return 0;
}

Measured memory_bytes: 1732
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
  read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
  match n {
    0 => a,
    _ => {
      a.push(read::<T>());
      read_n_logic(n - 1, a)
    }
  }
}

use std::cmp::{max, min};

fn main() {

  let a: i64 = read();
  let b: i64 = read();
  if b == 1 {
      println!("{}", 0);
  } else {
      println!("{}", (b - 1) /(a - 1) + if (b - 1) % (a - 1) == 0 { 0} else { 1});
  }
  
}


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

public class Main {
    void run() {
        while (true) {
            int W = readInt();
            int Q = readInt();
            if (W == 0 && Q == 0) break;
            int[] used = new int[W];
            Arrays.fill(used, -1);
            for (int q = 0; q < Q; q++) {
                char c = read().charAt(0);
                if (c == 's') {
                    int id = readInt();
                    int w = readInt();
                    int p = -1;
                    for (int i = 0; i + w <= W; i++) {
                        boolean ok = true;
                        for (int j = 0; j < w; j++) {
                            if (used[i + j] != -1) ok = false;
                        }
                        if (ok) {
                            p = i;
                            break;
                        }
                    }
                    if (p != -1) {
                        for (int i = 0; i < w; i++) {
                            used[p + i] = id;
                        }
                        sysout.println(p);
                    } else {
                        sysout.println("impossible");
                    }
                } else {
                    int id = readInt();
                    for (int i = 0; i < W; i++) {
                        if (used[i] == id) used[i] = -1;
                    }
                }
            }
            sysout.println("END");
        }
    }

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

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = null;

    String read() {
        if (buffer == null || !buffer.hasMoreTokens()) {
            try {
                buffer = new StringTokenizer(in.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }

    String readLine() {
        buffer = null;
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Measured memory_bytes: 16936
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;
ll const MOD = 1000000007;


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

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

int ans = max(2*A-1,max(2*B-1,A+B));
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef pair<ll,ll> PLL;

#define REP(x,l,u) for(ll x = l; x < u; x++)
#define RREP(x,l,u) for(ll x = l; x >= u; x--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mst(x,v) memset(x, v, sizeof(x))
#define sz(x) (ll)x.size()

string to_string(string s) {return s;}
string to_string(char c) {string s = string(1, c);return s;}
template <typename A, typename B> string to_string(pair<A,B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(vector<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }
template <typename A> string to_string(set<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }

void debug_out() {cerr << endl;}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

void in() {}
template <typename A> void in(A & x) { cin >> x; }
template <typename A, typename B> void in(pair<A,B> & x) { in(x.first); in(x.second); }
template <typename A> void in(vector<A> & x) { REP(i,0,(ll)x.size()) in(x[i]); }
template <typename Head, typename... Tail> void in(Head & H, Tail & ... T) {in(H); in(T...); }

#ifndef ONLINE_JUDGE
#define debug(...) do { cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); } while (false)
#else
#define debug(...) do { } while (false)
#endif

const ll inf = (ll)1e18 + 5;
const ll mod = 1e9+7;

ll nax = 1005;
VLL p(nax*nax, 1);
VLL P;

void init() {
	p[0] = 0;
	p[1] = 0;

	for (ll x = 2; x < nax*nax; x++) {
		if (p[x] == 0) {
			continue;
		}

		P.push_back(x);
		
		for (ll f = x; x * f < nax * nax; f++) {
			p[x*f] = 0;
		}
	}
}

map<ll,ll> pf(ll x) {
    map<ll,ll> f;
    REP(i,0,sz(P)) {
        if (P[i] * P[i] > x) break;
        while (x % P[i] == 0) {
            f[P[i]]++;
            x /= P[i];
        }
    }
    if (x > 1) f[x]++;
    return f;
}

VLL F(100500, -1);
VLL INVF(100500, -1);

ll pow(ll a, ll b) {
	if (b == 0) return 1;
	ll h = pow(a, b/2);
	ll ans = b % 2 ? h * h % mod * a : h * h;
	ans %= mod;
	return ans;
}

ll f(ll x) {
	if (F[x] != -1) return F[x];
	if (x == 0) return 1;
	F[x] = f(x-1) * x % mod;
	return F[x];
}

ll invf(ll x) {
	if (INVF[x] != -1) return INVF[x];
	INVF[x] = pow(f(x), mod-2);
	return INVF[x];
}

ll ncr(ll n, ll r) {
	// n! / r! / (n-r)!
	ll ans = f(n);
	ans *= invf(r);
	ans %= mod;
	ans *= invf(n-r);
	ans %= mod;
	return ans;
}


void solve() {
	ll n, m;
	in(n, m);

	map<ll,ll> factors = pf(m);

	REP(i,0,n) f(i); // ease on the recursion

	ll ans = 1;
	for (PLL a : factors) {
		ans *= ncr(a.second + n - 1, a.second) % mod;
		ans %= mod;
	}
	cout << ans << endl;


}

signed main() {
	init();
	ll t = 1;
	REP(i,0,t) solve();
	return 0;
}

Measured memory_bytes: 11000
using System;

namespace ALDS1
{
    class Program
    {
        private static int Prime(int a)
        {
            for(int i = 2; i <= Math.Sqrt(a); i++)
                if (a % i == 0) return 0;
            return 1;
        }

        static void Main()
        {
            int c = 0;
            int l = int.Parse(Console.ReadLine());
            while ( l-- > 0)
                c += Prime(int.Parse(Console.ReadLine()));
            Console.WriteLine(c);
        }
    }
}

Measured memory_bytes: 9276
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
       
    int n = scan.nextInt();
    int[] p = new int[n];
    
    for (int i = 0; i < n; i++) {
      p[i] = scan.nextInt();
    }
    
    for (int k = 0; k < n - 1; k++) {
    	if (p[k] > p[k+1]) {
    		break;
    	} else if (k == (n - 2)) {
    		System.out.print("YES");
    		return;
    	}
    }
    
    int[] q = new int[n];
    
    for (int i = 0; i < n - 1; i++) {    
      for (int j = i + 1; j < n; j++) {
    	for (int k = 0; k < n; k++) {
			 q[k] = p[k];
		}
		q[i] = p[j];
		q[j] = p[i];
		
		for (int k = 0; k < n - 1; k++) {
			if (q[k] > q[k+1]) {
				break;
			} else if (k == (n - 2)) {
				System.out.print("YES");
				return;
			}
		}
      }
    }
    
    System.out.print("NO");
    return;
  }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int H,W; cin>>H>>W;
  int ans=W*(H/2);
  if(H%2==1) ans+=(W+1)/2;
  if(H==1||W==1) ans=1;
  cout<<ans<<endl;
  }



Measured memory_bytes: 256
using System;
public class prog{
    public static void Main(){
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Trim().Split(' ');
        var i = 1;
        var count = 0;
        for(var k=0;k<n;k++){
            var ak = int.Parse(a[k]);
            if(ak != i){
                count++;
            }
            else{
                i++;
            }
        }
        if(i==1) count=-1;
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 30172
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int result = -1;
			int n = sc.nextInt();
			int m = sc.nextInt();
			if (n == 0 && m == 0)
				break;
			int[] ns = new int[n];
			int[] ms = new int[m];
			for (int i = 0; i < n; i++)
				ns[i] = sc.nextInt();
			for (int i = 0; i < m; i++)
				ms[i] = sc.nextInt();
			Arrays.sort(ns);
			Arrays.sort(ms);
			int nsum = 0, msum = 0;
			for (int i = 0; i < n; i++)
				nsum += ns[i];
			for (int i = 0; i < m; i++)
				msum += ms[i];
			out: for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++) {
					if (nsum - ns[i] + ms[j] == msum - ms[j] + ns[i]) {
						System.out.println(ns[i] + " " + ms[j]);
						result = 1;
						break out;
					}
				}
			if (result == -1)
				System.out.println(result);
		}
		sc.close();
	}
}

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

int main() {
int N, M;
cin >> N >> M;
vector<int> vec(2*M);

for(int i=0;i<2*M;i++){
  cin >> vec.at(i);
}
for(int k=0;k<N;k++){
  int a = 0;
  for(int i=0;i<2*M;i++){
    if(1+k==vec.at(i)){
      a++;

    }
  }
  cout << a <<endl;

}

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long intS
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    int a1, a2, a3;
    
    cin >> a1 >> a2 >> a3;
    
    
    if(a1 >= a2 && a1 >= a3 && a2 >= a3){
    
    cout << a2-a3 + a1-a2 << endl;
    
    }else if(a1 >= a2 && a1 >= a3 && a3 >= a2){
    
    cout << a3-a2 + a1-a3 << endl;
    
    }else if(a2 >= a3 && a2 >= a1 && a1 >= a3){
    
    cout << a1-a3 + a2-a1 << endl;
    
    }else if(a2 >= a3 && a2 >= a1 && a3 >= a1){
    
    cout << a3-a1 + a2-a3 << endl;
    
    }else if(a3 >= a2 && a3 >= a1 && a1 >= a2){
    
    cout << a1-a2 + a3-a1<< endl;
    
    }else {
    
    cout << a2-a1 + a3-a2 << endl;
    
    }
    
    
    
//////////////////////////////////////////////////////
return 0;}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 100010
#define inf 1e9

int main()
{

    ll n;
    vector<pll> v;
    cin >> n;
    for(ll i = 1; i <= n; i++)
    {

        ll x;
        cin >> x;
        v.pb(mp(x, i));
    }
    sort(v.begin(),v.end());
    for(ll i = 0; i < v.size(); i++) cout << v[i].ss << " ";
}


Measured memory_bytes: 2544
N = int(input())
H = list(map(int, input().split()))
answer = 0
temp = 0
for i in range(N - 1):
    if H[i] < H[i + 1]:
        answer = max(answer, temp)
        temp = 0
    else:
        temp += 1
        answer = max(answer, temp)
print(answer)


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

int main(){
  int x[2][3000];
  int i,temp;
 
  for(i = 0;;i++){
      cin >> x[0][i] >> x[1][i];
      if(x[0][i] == 0 && x[1][i] == 0)break;
      if(x[0][i] > x[1][i]){
        temp = x[0][i];
        x[0][i] = x[1][i];
        x[1][i] = temp;
      }
  }
  
  for(int j = 0;j < i;j++){
      cout << x[0][j] <<" "<< x[1][j] << endl;
  }
  return 0;
}


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

/// Typedef
typedef long long           ll;
typedef unsigned long       ul;
typedef unsigned long long  ull;
typedef vector<int>         vi;
typedef vector<vi>          vvi;
typedef vector<ll>          vll;
typedef pair<int,int>       pii;
typedef pair<ll,ll>         pll;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define loop(i, y)          for(int i=0; i<int(y); i++)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x); i>=int(y); i--)
#define all(c)              c.begin(), c.end()
#define sz(c)               int(c.size())
#define clr(x, y)           memset(x, y, sizeof(x))
#define si(x)               scanf("%d", &x)
#define sii(x, y)           scanf("%d %d", &x, &y)
#define siii(x, y, z)       scanf("%d %d %d", &x, &y, &z)
#define sl(x)               scanf("%lld", &x)
#define sll(x, y)           scanf("%lld %lld", &x, &y)

///START
/// Constants
#define MAX     200005
#define MOD     1000000007
#define base    1000000007
#define eps     1e-9
#define INF     1llu<<61    // 2,305,843,009,213,693,952
#define inf     1<<29       // 536,870,912
#define PI      acos(-1.0)  // 3.1415926535897932
// #define      INF 0x3f3f3f3f3f3f3f3f
// #define      inf 0x3f3f3f3f

int main(){
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n,k;
    sii(n,k);
    string str;
    cin>>str;
    FOR(i,0,sz(str)){
        if(i==k-1){
                str[i]=tolower(str[i]);
        }
    }
    cout<<str<<endl;
    #ifdef VAMP
        printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=list(input())
from collections import Counter
myc= Counter(s)
val=list(myc.values())
if len(val)!=3:
    print(0)
else:
    ans=val[0]*val[1]*val[2]
    for i in range(n-2):
        for j in range(i+1,n-1):
            if 2*j-i < n:
                if len(set(list((s[i],s[j],s[2*j-i]))))==3:
                    ans-=1
    print(ans)

Measured memory_bytes: 74604
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l;
    cin>>n>>l;
    long ans=0;
    if(l%2!=0){
        long count=0;
        for(int i=1;i<=n;i++){
            if(i%l==0)count++;
        }
        ans=count*count*count;
    }
    else{
        long count1=0,count2=0;
        for(int i=1;i<=n;i++){
            if(i%l==0)count1++;
            if(i%l==l/2)count2++;
        }
        ans=count1*count1*count1+count2*count2*count2;;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    string a;
    cin >> a;
    if(a == "SUN") {
        cout << "7" << endl;
    }
    else if(a == "MON"){
        cout << "6" <<endl;
    }
    else if(a == "TUE"){
        cout << "5" <<endl;
    }
    else if(a == "WED"){
        cout << "4" <<endl;
    }
    else if(a == "THU"){
        cout << "3" <<endl;
    }else if(a == "FRI"){
        cout << "2" <<endl;
    }
    else if(a == "SAT"){
        cout << "1" <<endl;
    }


    return 0;
}

Measured memory_bytes: 256
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0
using namespace std;
using ll = long long;

void testcase() {
    string s; cin >> s;

    int sum = 0;

    for (char ch : s) {
        sum = (sum + (ch-'0')) % 9;
    }
    if (sum==0) cout << "Yes";
    else cout << "No";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 3732