akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define Endl '\n'
typedef long long int lli;
void solve();
signed main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  solve();
}
void solve(){
  lli A, B, N;
  cin>>N>>A>>B;
  for(int i=A;i<=B;i++){
    if(i%N == 0){
      cout<<"OK"<<Endl;
      return;
    }
  }
  cout<<"NG"<<Endl;
}


Measured memory_bytes: 3608
#include <cstdio>
#include <iostream>
#include <vector>
#include <ctype.h>
#include <algorithm>
#define mp make_pair
#define fir first
#define sec second

using namespace std;

typedef long long LL;
typedef pair<LL, LL> pll;

const int MAXN = 2e5 + 7;
const int MOD = 1000000007 ; 

inline int read() {
	int res = 0, flag = 1; char in = getchar();
	while(!isdigit(in)) { if(in == '-') flag = -1; in = getchar(); }
	while(isdigit(in)) { res = (res << 1) + (res << 3) + in - '0'; in = getchar(); }
	return res * flag;
}

inline void chkmax(int &a, int b) { if(a < b) a = b; }
inline void chkmin(int &a, int b) { if(a > b) a = b; }

inline LL fpm(int x, int y) {
	LL res = 1;
	while(y) {
		if(y & 1) res = 1ll * res * x % MOD;
		x = 1ll * x * x % MOD;
		y >>= 1;
	}
	return res;
}

vector<int> G[MAXN];
vector<pll> dp[MAXN];

int n, fa[MAXN];
int lc[MAXN], id[MAXN], tot;
int dep[MAXN], cnt[MAXN];
LL zro[MAXN], all[MAXN], one[MAXN];
LL ans;

void dfs(int u) {
	int son = n + 1;
	int len = G[u].size();
	for(int i = 0; i < len; ++i) {
		int v = G[u][i];
		dfs(v);
		if(lc[v] > lc[son]) son = v;
	}
	if(son != n + 1) id[u] = id[son], lc[u] = lc[son] + 1;
	else id[u] = ++tot;

	dp[id[u]].push_back(mp(1ll, 1ll));
	if(G[u].size() == 1) return ;

	for(int i = 0; i <= lc[u]; ++i)
		all[i] = zro[i] = 1, one[i] = 0;
	
	for(int t = 0; t < len; ++t) {
		int v = G[u][t];
		for(int i = 0; i <= lc[v]; ++i) {
			int cur = lc[son] - lc[v] + i;
			pll st = dp[id[v]][i];
			(all[cur] *= (st.fir + st.sec) % MOD) %= MOD;
			(zro[cur] *= st.fir) %= MOD;
		}
	}

	for(int t = 0; t < len; ++t) {
		int v = G[u][t];
		for(int i = 0; i <= lc[v]; ++i) {
			int cur = lc[son] - lc[v] + i;
			pll st = dp[id[v]][i];
			(one[cur] += zro[cur] * fpm(st.fir, MOD - 2) % MOD 
				* st.sec % MOD) %= MOD;
		}
	}
	for(int i = 0; i < lc[u]; ++i) {
		dp[id[u]][i].fir = (all[i] - one[i] + MOD) % MOD;
		dp[id[u]][i].sec = one[i];
	}
}

inline void solve() {
	n = read();
	for(int i = 1; i <= n; ++i) {
		G[fa[i] = read()].push_back(i);
		dep[i] = dep[fa[i]] + 1;
		++cnt[dep[i]];
	}
	lc[n + 1] = -MAXN;
	++cnt[0];
	dfs(0);
	for(int i = 0; i <= lc[0]; ++i) {
		pll st = dp[id[0]][i];
		(ans += st.sec * fpm(2, n + 1 - cnt[lc[0] - i]) % MOD) %= MOD;
	}
	cout << ans << endl;
}

int main() {

	solve();
	return 0;
}


Measured memory_bytes: 52852
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a, b, c, d;
  cin >> n;
  a = n / 1000;
  b = n / 100 % 10;
  c = n / 10 % 10;
  d = n % 10;
  
  string result;
  
  if (a == b && a == c ){
    result = "Yes";  
  }
  else if(b == c && b == d){
    result = "Yes";
  }
  else{
    result = "No";
  }
      
  cout << result << endl;
}

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

int main() {
	string s,c;
    cin>>s;
    cin>>c;
    int len=c.length();
    char str=c[--len];
    c.erase(c.begin()+s.length(),c.end());
    if(c==s&&str>='a'&&str<='z') cout<<"Yes";
    else cout<<"No";
	return 0;
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

int gcd(ll a, ll b){
    if(a<b){
        int tmp = a;
        a = b;
        b = tmp;
    }

    ll r = a%b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

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

bool isin(int x, int y) {
    return 0<=x && x<w && 0<=y && y<h;
}

int main(){
    vector<int> a(3);
    REP(i, 3) cin >> a[i];
    int ans = 0;

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

    int b = a[2] - a[1];
    int c = a[2] - a[0];

    if(b % 2 == c % 2) {
        cout << (b+c) / 2 << endl;
    } else {
        ans = b + 1;
        ans += (c + 1 - b) / 2;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 100008*2
int n,k;
int pos[maxn];
main(){
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%lld",&pos[i]);
	}
	int ans=1e18;
	for(int l=1;l+k-1<=n;l++){
		int r=l+k-1;
		if(pos[r]<0){
			ans=min(ans,0-pos[l]);
		}else if(pos[r]>=0&&pos[l]<=0){
			ans=min(ans,min(pos[r]-0,0-pos[l])+pos[r]-pos[l]);
		}else{
			ans=min(ans,pos[r]-0);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef pair<long,int> P;
int main(void){
  int n,i,a,b,c,q,k;
  const long INF=1e18;
  vector<P> g[100010];
  cin >> n;
  for (i=0;i<n-1;i++){
    cin >> a >> b >> c;
    g[a].push_back(P(b,c));
    g[b].push_back(P(a,c));
  }
  cin >> q >> k;
  int kt,x,y;
  long pd,d[100010];
  priority_queue<P,vector<P>,greater<P>> pque;
  for (i=1;i<=n;i++) d[i]=INF;
  pque.push(P(0,k));
  d[k]=0;
  while (!pque.empty()){
    pd=pque.top().first;
    kt=pque.top().second;
    pque.pop();
    if (d[kt]<pd) continue;
    for (i=0;i<g[kt].size();i++){
      if (d[g[kt][i].first]>d[kt]+g[kt][i].second){
        d[g[kt][i].first]=d[kt]+g[kt][i].second;
        pque.push(P(d[g[kt][i].first],g[kt][i].first));
      }
    }
  }
  for (i=0;i<q;i++){
    cin >> x >> y;
    cout << d[x]+d[y] << endl;
  }
  return 0;
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main(){
    Sieve sieve(1e6);
    ll n;
    cin >> n;
    ll a[n];
    for(ll i=0;i<n;i++){
        cin >> a[i];
    }
    ll memo=0;
    for(ll i=0;i<n;i++){
        memo=__gcd(memo,a[i]);
    }
    map<ll,ll> mp;
    for(ll i=0;i<n;i++){
        const auto &res=sieve.factor(a[i]);
        for(auto p:res) mp[p.first]++;
    }
    bool flag=true;
    for(auto p:mp){
        if(p.second>1) flag=false;
    }
    if(flag){
        cout << "pairwise coprime" << endl;
    }
    else if(!flag&&memo==1){
        cout << "setwise coprime" << endl;
    }
    else{
        cout << "not coprime" << endl;
    }
    return 0;
}  


Measured memory_bytes: 20080
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n,m;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	cout<<(n)*(n-1)/2+(m)*(m-1)/2;
	re 0;
}

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

int main()
{
	string s;
	int ans = 0;

	cin >> s;

	const char* c = s.c_str();

	for (int i = 0; i < 4; i++)
	{
		if (*c == '+')
		{
			++ans;
		}
		else
		{
			--ans;
		}
		c++;
	}

	cout << ans << endl;

	return 0;
}


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

#define pb push_back
#define pp pop_back
#define mp make_pair
#define ld long double
#define f first
#define s second
#define ll long long

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;

    if(n == 1) {
          cout << 1;
          return 0;
    }else if(n < 4){
          cout << 2;
          return 0;
    }
    int i, x = 3;
    for(i = 3;x + i < n;i ++)
        x += i;
    cout << i << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    vector<int> A(1000001);
    vector<int> B(1000001);
    cin >> N ;
    for(int i=0;i<N;i++){
        cin >> A.at(i);
    }
    for(int i=0;i<N;i++){
        B.at(A.at(i)-1)=i+1;
    }
    for(int i=0;i<N;i++){
        if(i==N-1){
            cout <<B.at(i)<<endl;
            return 0;
        }
        cout<<B.at(i)<<" ";
    }
    return 0;
}


Measured memory_bytes: 8576
#include<iostream>
using namespace std;
using ll = long long;
int main(){
    int n;
    cin>>n;
    int a[n],b[n],c[n-1],mz,bonus;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n-1;i++){
        cin>>c[i];
    }
    for(int i=0;i<n;i++){
        if(a[i+1]-a[i]==1){
            bonus = c[a[i]-1];
            b[i]=b[i]+bonus;
        }
    }
    mz=0;
    for(int i=0;i<n;i++){
        mz+=b[i];
    }
    cout<<mz<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define MAX 2000001
#define MAX_SCORE 10001

typedef struct {
  int id;
  int score;
  int rank;
} Info;

int n; // number of students
int counter[MAX_SCORE+1], maxi;
Info list[MAX+1], sortedList[MAX+1];


void CountingSort() {
  memset(counter,0,sizeof counter);
  int i;
  for(i=0;i<n;++i) ++counter[list[i].score];
  for(i=1;i<=maxi;++i) counter[i] += counter[i-1];
  for(i=n-1;i>=0;--i) {
    sortedList[--counter[list[i].score]] = list[i];
  }
}

int main() {
  int i, id, score;
  while( scanf("%d",&n) != EOF ) {
    maxi = 0;
    for(i=0;i<n;++i) {
      scanf("%d",&score);
      list[i].score = score;
      if( maxi < score ) maxi = score;
    }
    CountingSort();
    for(i=0;i<n;++i) {
      if( i ) printf(" ");
      printf("%d",sortedList[i].score);
    } puts("");
  }
  return 0;
}




Measured memory_bytes: 48620
n = int(input())
v = []
for i in range(n):
    ai = int(input())
    vi = []
    for j in range(ai):
        vi.append(list(map(int, input().split())))
    v.append(vi)

m = 0
for bit in range(2**n - 1, -1, -1):
    is_break = False
    for i in range(n):
        if not (bit & (1 << i)):
            continue
        for xij, yij in v[i]:
            if not (not (bit & (1 << xij - 1))) != yij:
                is_break = True
                break
        if is_break:
            break
    else:
        m = max(bin(bit).count('1'), m)

print(m)

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  int mn = INT_MAX;
  for (int i = 0; i + k - 1 < n; i++) {
    int left = x[i], right = x[i + k - 1];
    mn = min(mn, min(abs(left), abs(right)) + right - left);
  }

  cout << mn << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

void cc(int *a, int n) {
	int k;
    for(k=0;k<n;k++) {
 		if (k != 0) {
 	    	printf(" ");
        }
    	printf("%d", a[k]);
    }
    printf("\n");
}


void Insertion_sort(int a[], int n) {
	int i,j,v,k;
	for (i=1;i<n;i++) {
		v = a[i];
		j = i-1;
		while (j>=0 && a[j] > v) {
			a[j+1] = a[j];
			j--;
			a[j+1]=v;
		}
		cc(a, n);
	}
}		

 
							  
int main(void) {
	int n,i;
	int a[1000] = {};

	scanf("%d", &n);

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

	

	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int n;
    cin>>n;
    int a[n];
    map<int,bool>mp;
    int num=0;
    int k=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(mp[a[i]]==true){
            num++;
        }else{
            mp[a[i]]=true;
            k++;
        }
    }
    if(num%2){
        cout<<k-1<<endl;
    }else{
        cout<<k<<endl;
    }
   return 0;
}

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

using namespace std;

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


int main()
{
  string s;
  int k;
  cin >> s >> k;
  vector<string> v;
  // int count = 0;
  for (int i = 1; i <= 5; i++){
    for (int j = 0; j < int(s.size()); j++){
      v.push_back(s.substr(j, i));
    }
  }
  set<string> tmp(v.begin(), v.end());
  vector<string> v2(tmp.begin(), tmp.end());
  sort(v2.begin(), v2.end());
  // for(string a : v2) cout << a << endl;
  cout << v2[k - 1] << endl;
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

int main() {
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=0;
    ll x[n];
    rep(i,n){
        cin>>x[i];
    }
    rep(i,n-1){
        if ((x[i+1]-x[i])*a>b){
            ans+=b;
        }
        else{
            ans+=(x[i+1]-x[i])*a;
        }
    }
    cout<<ans<<endl;
    

    return 0;
}

Measured memory_bytes: 1024
while True:
    H, W = map(int, input().split())
    if H == W == 0:
       break
    for i in range(H):
       if i % 2 == 0:
           print("#."*(W//2) + "#"*(W%2))
       else:
           print(".#"*(W//2) + "."*(W%2))
    print()


Measured memory_bytes: 5608
import std.stdio, std.string, std.conv;

void main() {
    string s = readln.chomp;
    int[] num = new int[s.length];
    int cnt;
    foreach (i, x; s) {
        if (x == 'R') {
            ++cnt;
        } else {
            num[i-1] += cnt / 2 + cnt % 2;
            num[i] += cnt / 2;
            cnt = 0;
        }
    }
    foreach_reverse (i, x; s) {
        if (x == 'L') {
            ++cnt;
        } else {
            num[i] += cnt / 2;
            num[i+1] += cnt / 2 + cnt % 2;
            cnt = 0;
        }
    }
    num.to!(string[]).join(" ").writeln;
}

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

int main() {
    int n,w;
    cin >> n >> w;
    long int dp[n+1][w+1];
    int value[n], weight[n];
    for(int i=0;i<n;i++){
        cin >> weight[i] >> value[i];
    }
    for(int i=0;i<n+1;i++) dp[i][0] = 0;
    for(int j=0;j<w+1;j++) dp[0][j] = 0;

    for(int i=1;i<n+1;i++){
        for(int j=1;j<w+1;j++){
            if(weight[i-1] > j) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j], value[i-1] + dp[i-1][j-weight[i-1]]);
            
        }
    }
    // for(int i=0;i<n+1;i++){
    //     for(int j=0;j<w+1;j++)
    //         cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    cout << dp[n][w];
	return 0;
}


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

using namespace std;

const int N = 1024, mod = 1e9 + 7, K = 22;

long long dp[K][N], C[N][N];
int a[N];

int main() {
  for (int i = 0; i < N; ++i) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod;
    }
  }
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; ++i) {
    scanf("%d", a+i);
  }
  dp[0][0] = 1;
  int tot = 0;
  for (int i = 0; i < k; ++i) {
    tot += a[i];
    tot = min(tot, n);
    for (int j = 0; j <= a[i]; ++j) {
      for (int cnt = 0; cnt + j <= tot; ++cnt) {
        int sisa = n - cnt;
        if (sisa < j) continue;
        long long cur = dp[i][cnt] * C[sisa][j] % mod;
        cur = cur * C[n - j][a[i] - j] % mod;
        dp[i+1][cnt+j] = (dp[i+1][cnt+j] + cur) % mod;
      }
    }
    // for (int j = 0; j <= tot; ++j)
    //   cerr << i+1 << " " << j << " " << dp[i+1][j] << endl;
  }
  long long ans = dp[k][n] % mod;
  if (ans < 0)
    ans += mod;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 7552
import math
#最初の入力
a=input().strip().split()
b=[int(x) for x in a]

count=0

for item in range(b[0]):
    c=input().strip().split()
    d=[int(x) for x in c]
    num = d[0]*d[0] +d[1]*d[1]
    kyori = math.sqrt(num)
    if kyori<=b[1]:
        count +=1
        
print(count)

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define pri(x) printf("%d\n", x)
#define mp make_pair
#define pb push_back
#define BUFF ios::sync_with_stdio(false);
#define imprime(v) for(int X=0;X<v.size();X++) printf("%d ", v[X]); printf("\n");
#define endl "\n"
const int INF= 0x3f3f3f3f;
const long double pi= acos(-1);
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
const int MOD=1e9+7;
const ll LINF=0x3f3f3f3f3f3f3f3f;
const int MAXN = 100005;
int k;
ll a[MAXN];

ll get(ll n) {
  for(int i = 0; i < k; i++) {
    n -= n % (a[i]);
  }
  return n;
}

ll bb1(ll b, ll e) {
  if(b == e) return b;
  ll mid = (b + e) / 2ll;
  ll left = get(mid);
  if(left < 2) return bb1(mid + 1ll, e);
  return bb1(b, mid);
}

ll bb2(ll b, ll e) {
  if(b == e) return b;
  ll mid = (b + e + 1ll) / 2ll;
  ll left = get(mid);
  if(left <= 2) return bb2(mid, e);
  return bb2(b, mid - 1ll);
}


int main() {
  BUFF;
  cin >> k;
  for(int i = 0; i < k; i++) cin >> a[i];
  ll n1 = bb1(2, 1000000000000000ll);
  if(get(n1) != 2) {
    cout << -1 << endl;
    return 0;
  }
  ll n2 = bb2(n1, 1000000000000000ll);
  cout << n1 << " " << n2 << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int now=1;
    int ans=0;
    for(int i=0;i<n;i++){
        if(a[i]==now){
            now++;
        }else{
            ans++;
        }
    }
    if(now==1){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
    return(0);
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))

C = {}
s = 0
for i in range(len(A), 0, -1):
    t = i - A[i-1]
    if not(t in C):
        C[t] = 0
    C[t] += 1

    k = i + A[i-1]
    if k in C:
        s += C[k]

print(s)


Measured memory_bytes: 40464
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot

#############
# Main Code #
#############

N, M = getNM()
dist = [set() for i in range(N)]
for i in range(M):
    a, b = getNM()
    dist[a - 1].add(b - 1)
    dist[b - 1].add(a - 1)

flag = False
for i in list(dist[0]):
    if N - 1 in dist[i]:
        flag = True
print('POSSIBLE' if flag else 'IMPOSSIBLE')

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

const ll MAX_N = 1e6;

ll dat[2*MAX_N],n;
ll h[MAX_N],a[MAX_N];

void init(ll N){
  
  n = 1LL;
  
  while( n < N ){ n *= 2;}
  
  for(ll i = 0; i < 2*n-1; i++){ dat[i] = 0;} // Range Maximum Query
  
}

void update(ll k, ll val){ // kノードをaにupdateする
  
   k += n-1;
   dat[k] = val;
  
  while( k > 0){
    k = (k-1)/2;
    dat[k] = max(dat[2*k+1],dat[2*k+2]);
  }
}


ll find(ll a, ll b, ll k, ll l, ll r){
  
  if( r <= a || b <= l){ return 0;}
  if( a <= l && r <= b){ return dat[k];}
  
  else{
    ll v1 = find(a,b,2*k+1,l,(l+r)/2);
    ll v2 = find(a,b,2*k+2,(l+r)/2,r);
    
    return max(v1,v2);
  }
}


signed main(void){ 
  
  ll N; cin >> N;
  init(N);
  for(ll i = 0; i < N; i++){ cin >> h[i];h[i]--;}
  for(ll i = 0; i < N; i++){ cin >> a[i];}
  
  ll ans = 0;
  
  for(ll i = 0; i < N; i++){ 
    
    ll base = h[i]; 
    // base未満の範囲での最大値をRMQで求める
    ll val = find(0,base,0,0,n) ; //ここ後で埋める
    val += a[i];
    ans = max(ans,val);
    update(base,val);
    
    
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 12032
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 1e5+10;
const int64 MO = 1e9+7;
const int64 IN = 1e9;

int h[maxn], dp[maxn];

int N;

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> h[i];
	//
	for (int i = 1; i < N; i++) {
		dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
		if (i - 1)
			dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	//
	cout << dp[N - 1] << "\n";
}



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

int main() {
	int x[3000], y[3000];
	int i = 0;

	while(1){
		cin >> x[i] >> y[i];
		if (x[i] == 0 && y[i] == 0) break;
		i++;
	}

	for(int j = 0; j < i; j++){
		if (x[j] > y[j]){
			cout << y[j] << " " << x[j] << endl;
		} else {
			cout << x[j] << " " << y[j] << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
int n,sz,ch[N][26],val[N],c[26],pos[N],fm[N],fa[N],ans;
char s[N];
int ins(char *s){
	int len=strlen(s),tmp=0;
	for(int i=0;i<len;++i){
		if(!ch[tmp][s[i]-'a']){
			ch[tmp][s[i]-'a']=++sz;
			fa[sz]=tmp;fm[sz]=s[i]-'a';
		}
		tmp=ch[tmp][s[i]-'a'];
	}
	val[tmp]=1;
	return tmp;
}
void query(int tmp){
	for(int i=0;i<26;++i)c[i]=0;
	do{
		c[fm[tmp]]=1;tmp=fa[tmp];
		for(int i=0;i<26;++i)if(c[i]&&val[ch[tmp][i]])ans++;
	}while(tmp);
}
int main(){
//	freopen("B.in","r",stdin);
//	freopen("B.out","w",stdout);
	scanf("%d",&n);
	for(int i=1,len;i<=n;++i){
		scanf("%s",s);
		len=strlen(s);
		reverse(s,s+len);
		pos[i]=ins(s);
	}
	for(int i=1;i<=n;++i)query(pos[i]);
	ans-=n;
	cout<<ans<<endl;
	return 0;
} 

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

const ll INF = 1LL << 58;

//xより以下の要素へのindex
template <class T> int former(const vector<T> &v, T x) {
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素へのindex
template <class T> int latter(const vector<T> &v, T x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    cout<<700+100*(count(s.begin(),s.end(),'o'))<<endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        x: i64,
        xs: [i64; n],
    }

    // let mut xs = xs;
    // xs.reverse();

    let mut acc = vec![0; n + 1];
    for i in 1..(n + 1) {
        acc[i] = acc[i - 1] + xs[i - 1];
    }

    let mut ans = std::i64::MAX;
    for len in 1..(n + 1) {
        let mut cur: i64 = 0;

        let mut w = 3;
        let mut r = n;
        let mut ok = true;
        while r > 0 {
            let l = if r < len { 0 } else { r - len };

            let ww = if w == 3 { 5 } else { w };
            if let Some(new_cur) = (acc[r] - acc[l])
                .checked_mul(ww)
                .and_then(|v: i64| cur.checked_add(v))
            {
                cur = new_cur;
            } else {
                ok = false;
                break;
            }

            w += 2;
            r = l;
        }

        if !ok {
            continue;
        }

        cur += x * (n + len) as i64;
        // println!("{}: {}", len, cur);

        ans = std::cmp::min(ans, cur);
    }

    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=400015;
#define M 1000000007
#define double long double
#define BINF 100000000000000
#define init(arr,val) memset(arr,val,sizeof(arr))
#define MAXN 15000001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;

map<int, int>lol;

#undef int
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0);

	

	int n;
	cin >> n;
	int ans = 0;
	while(n > 0){
		if(lol[n] == 0){
			ans++;
			lol[n / 2] += 2;
		}else{
			ans += lol[n];
			lol[n / 2] += 2 * lol[n];
		}
		 n /= 2;
	}
	cout << ans << endl;
	
 
return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

void swap(int *num1, int *num2) {
  int temp;

  temp = *num1;
  *num1 = *num2;
  *num2 = temp;
}

int main(void) {
  int inputs[5], i, j;

  scanf("%d %d %d %d %d", &inputs[0], &inputs[1], &inputs[2], &inputs[3], &inputs[4]);

  for (i = 0; i < 5; i++)
    for (j = i + 1; j < 5; j++)
      if (inputs[i] < inputs[j])
        swap(&inputs[i], &inputs[j]);

  printf("%d %d %d %d %d\n", inputs[0], inputs[1], inputs[2], inputs[3], inputs[4]);

  return 0;
}

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

vector<pair<long long, long long> > prime_factorize(long long N) {
  vector<pair<long long, long long> > res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    long long ex = 0;

    while (N % a == 0) {
      ++ex;
      N /= a;
    }
    res.push_back({a, ex});
  }

  if (N != 1) res.push_back({N, 1});
  return res;
}

int main() {
  long long N;
  cin >> N;
  const auto &res = prime_factorize(N);
  cout << N << ":";
  for (auto p : res) {
    for (int i = 0; i < p.second; ++i) cout << " " << p.first;
  }
  cout << endl;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main() {
    int n, d, a;
    cin >> n >> d >> a;
    vector<pii> mon(n);
    int x, h;
    for (int i = 0; i < n; ++i) {
        cin >> x >> h;
        mon[i] = pii(x, (h + a-1) / a);
    }
    sort(all(mon));

    ll res = 0;
    ll now = 0;
    int j = 0;
    vector<ll> v(n, 0);
    for (int i = 0; i < n; ++i) {
        now += v[i];
        if (now >= mon[i].second) continue;
        for (;j < n; ++j) {
            if (mon[j].first > mon[i].first + 2 * d){
                v[j] -= mon[i].second - now;
                break;
            }
        }
        res += mon[i].second - now;
        now = mon[i].second;
    }
    cout << res << endl;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a){cout<<((a)?"Yes":"No")<<endl;}
void YESNO(int a){cout<<((a)?"YES":"NO")<<endl;}
void AorB(int a,string b,string c){cout<<((a)?b:c)<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int n,k;
    cin>>n>>k;
    Vi a(n),b(n),c(n);
    REP(i,0,n){
        cin>>a[i];
    }
    b[0]=a[0];
    REP(i,1,n){
        b[i]=b[i-1]+a[i];
    }
    c[n-1]=a[n-1];
    REPR(i,n-2,-1){
        c[i]=c[i+1]+a[i];
    }
    if(k>=n){
        int ans=0;
        REP(i,0,n) if(a[i]>0) ans+=a[i];
        cout<<ans<<endl;
        return 0;
    }
    
    int ans=0;
    REP(i,1,k+1){
        REP(j,0,i+1){
            Vi v;
            REP(l,0,j){
                v.pb(a[l]);
            }
            REP(l,0,i-j){
                v.pb(a[n-l-1]);
            }
            SORT(v);
//            REP(l,0,v.size()) cout<<v[l]<<" ";
//            cout<<endl;
            REP(l,0,k-i){
                if(v[l]>=0) break;
                else v[l]=0;
            }
            int t=0;
            REP(l,0,v.size()) t+=v[l];
            chmax(ans,t);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    vi x(5);
    rep(i,5)cin>>x[i];
    rep(i,5){
        if(x[i]!=i+1){
            cout << i+1 << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;

struct xyz {
    int x;
    int y;
    int cnt;
};

int main() {
    int h, w;
    cin >> h >> w;
    
    vector<string> v(h);
    queue<xyz> que;
    for(int i = 0; i < h; i++) {
        cin >> v[i];
        for(int j = 0; j < w; j++) {
            if(v[i][j] == '#') {
                xyz tmp;
                tmp.x = i; tmp.y = j; tmp.cnt = 0;
                que.push(tmp);
            }
        }
    }
    
    int dx[] = {1, 0, -1, 0};
    int dy[] = {0, 1, 0, -1};
    int ans = 0;
    while(!que.empty()) {
        xyz now = que.front();
        que.pop();
        
        for(int i = 0; i < 4; i++) {
            int xx = now.x + dx[i];
            int yy = now.y + dy[i];
            
            if(xx < 0 || xx >= h || yy < 0 || yy >= w) {
                continue;
            }
            else if(v[xx][yy] == '.') {
                v[xx][yy] = '#';
                xyz tmp;
                tmp.x = xx; tmp.y = yy; tmp.cnt = now.cnt + 1;
                que.push(tmp);
            }
        }
        
        ans = max(ans, now.cnt);
    }
    
    cout << ans << endl;
}



Measured memory_bytes: 13456
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int goR[200005][20];
int goL[200005][20];
int a[200005];
int n,v;
int R(int x,int k,int v){
    if(x>=n)return n;
    if(goR[x][k]!=-1)return goR[x][k];
    if(a[x+1]-a[x]>(v>>k))return goR[x][k]=x;
    return goR[x][k]=R(x+1,k,v);
}
int L(int x,int k,int v){
    if(x<=1)return 1;
    if(goL[x][k]!=-1)return goL[x][k];
    if(a[x]-a[x-1]>(v>>k))return goL[x][k]=x;
    return goL[x][k]=L(x-1,k,v);
}
int dpR[1<<20];
int dpL[1<<20];
 
int DPR(int x){
    if(x==0)return 0;
    if(dpR[x]!=-1)return dpR[x];
    dpR[x]=0;
    for(int i = 0;i<20;i++){
        if(x&(1<<i)){
            dpR[x]=max(dpR[x],R(DPR(x-(1<<i))+1,i,v));
        }
    }
    return dpR[x];
}
int DPL(int x){
    if(x==0)return n+1;
    if(dpL[x]!=-1)return dpL[x];
    dpL[x]=1e9+1;
    for(int i = 0;i<20;i++){
        if(x&(1<<i)){
            dpL[x]=min(dpL[x],L(DPL(x-(1<<i))-1,i,v));
        }
    }
    return dpL[x];
}
int main(){ 
    MEMS(goR);MEMS(goL);MEMS(dpR);MEMS(dpL);
    scanf("%d %d",&n,&v);
    for(int i = 1;i<=n;i++)
        //a[i]=-1e9+2e5*i;
        scanf("%d",&a[i]);
    a[0]=-1e9-1e8;
    a[n+1]=1e9+1e8;
    int Max=1;
    for(int i = 1;;i++){
        Max=i+1;
        if(!(v>>i))break;
    }
 
    if(DPR((1<<Max)-1)<n){
        for(int i = 1;i<=n;i++){
            printf("Impossible\n");
        }
        return 0;
    }
    for(int i = 1;i<=n;){
        int l=i,r=R(i,0,v);
       // printf("%d %d\n",l,r);
        int ok=0;
        for(int j=0;j<(1<<Max);j++){
            int a=j,b=(1<<Max)-j-1;
            if(a&1)a--;
            if(b&1)b--;
            if(DPR(a)>=l-1&&DPL(b)<=r+1){
                ok=1;
                break;
            }
        }
        if(ok){
            for(int i=l;i<=r;i++)printf("Possible\n");
        }
        else{
            for(int i = l;i<=r;i++)printf("Impossible\n");
        }
        i=r+1;
    }
}
/*
2 2 1
3 2 3
4 2 4 4 7
 
*/

Measured memory_bytes: 48128
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << " >> " << #x << " "<<x<<endl;
void Solve_Case()
{
    int N;
    cin >> N;
    vector<int> v(N);
    for(auto &i : v)
        cin >> i;
    sort(v.begin(),v.end());
    int ans = 0;
    for(int i=0;i<N;i++)
    {
        int a = v[i];
        for(int j=i+1;j<N;j++)
        {
            int b = v[j];
            for(int k=j+1;k<N;k++)
            {
                int c = v[k];
                if(a < b+ c && b < a + c && c < a + b)
                    ans++;
            }

        }
    }
        cout << ans;


}
int main()
{
    int TestCases=1;
   // cin >> TestCases;
    while(TestCases--)
    {
        Solve_Case();
    }
	return 0;
}


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

int main(){
  int a,b;cin>>a;
  cin>>b;
  int c1,c2,c3;
  c1=a*b*1;
  c2=a*b*2;
  c3=a*b*3;

  if(c1%2!=0||c2%2!=0||c3%2!=0)cout<<"Yes";
  else cout<<"No";

  return 0;
}

Measured memory_bytes: 256
#include <set>
#include <cstdio>
using namespace std;
int main() {
	int n, x;
	set<int> s;
	scanf("%d", &n);
	while (n--) {
		scanf("%d", &x);
		if (s.count(x) == 0) {
			s.insert(x);
		} else {
			s.erase(x);
		}
	}
	printf("%d\n", (int)s.size());
	return 0;
}

Measured memory_bytes: 4864
from collections import deque, defaultdict

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

def check(x):
    used = [0]*n
    if x >= n:
        return True
    # NM
    b = [deque(a[i]) for i in range(n)]
    d = defaultdict(list)

    ng = set()
    while True:
        for i in range(n):
            if used[i]:
                continue
            while b[i] and b[i][0] in ng:
                b[i].popleft()
            if not b[i]:
                return False
            like = b[i].popleft()

            d[like].append(i)
            used[i] = 1
        # チェック
        flag = True
        for key, value in d.items():
            if len(value) > x:
                flag = False
                ng.add(key)
                for v in value:
                    used[v] = 0
                d[key] = []
        if flag:
            return True

left = 0
right = n+1
while right - left > 1:
    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)

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

int main(void) {
    long n, m;
    cin >> n >> m;

    map<long,long> cnt;
    for(long i=0; i<n; i++) {
        long x;
        cin >> x;
        cnt[x]++;
    }

    vector<queue<long>> vq(m);
    for(auto &t: cnt) {
        long x, c;
        tie(x, c) = t;
        if(c&1) vq[x%m].push(x);
    }

    for(auto &t: cnt) {
        long x, c;
        tie(x, c) = t;
        for(long i=0; i<c/2; i++)
            vq[x%m].push(x), vq[x%m].push(x);
    }

    long r = 0;
    for(long i=1; 2*i<m; i++) {
        while(!vq[i].empty() && !vq[m-i].empty()) {
            auto x = vq[i].front(); vq[i].pop();
            auto y = vq[m-i].front(); vq[m-i].pop();
            cnt[x]--, cnt[y]--;
            r++;
        }
    }
    if(~m&1) {
        long i = m/2;
        while(vq[i].size() >= 2) {
            auto x = vq[i].front(); vq[i].pop();
            auto y = vq[m-i].front(); vq[m-i].pop();
            cnt[x]--, cnt[y]--;
            r++;
        }
    }
    {
        long i = 0;
        while(vq[i].size() >= 2) {
            auto x = vq[i].front(); vq[i].pop();
            auto y = vq[i].front(); vq[i].pop();
            cnt[x]--, cnt[y]--;
            r++;
        }
    }

    for(auto t: cnt) {
        long x, c;
        tie(x, c) = t;
        r += c/2;
    }

    cout << r << endl;
}


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

using namespace std;

int main() {
	int maxi = 1;
	int n;
	int ni = 0;
	cin >> n;
	for(int i = 1 ; i <= n ; i++) {
		int res = 0;
		int j = i;
		while(j % 2 == 0){
			res++;
			j /= 2;
		}
		if(res > ni) {
			ni = res;
			maxi = i;
		}
	}
	cout << maxi << endl;
	return 0;
}

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

int main(){
	int a,b;double cnt=0;
	cin>>a>>b;
	for(int i=1;i<=a;i++){
		double tot=1.0/a;int now=i;
		while(now<b){
			now*=2;//翻倍 
			tot/=2;//几率减半 
		}
		cnt+=tot;
	}
	cout<<fixed<<setprecision(12)<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    int n,a,i;
    long long max,min,sum;
    cin>>n;
    max=-1000000;
    min=1000000;
    sum=0;
    for(i=0;i<n;i++){
        cin>>a;
        if (a>max) max=a;
        if (a<min) min=a;
        sum+=a;
    }
    printf ("%lld %lld %lld\n",min,max,sum);
    return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n;
	cin>>n;
	vector<long long int> A(n);
	for(int i=0;i<n;i++)
	cin>>A[i];
	long long int count =0;
for (int i = 0; i < n; i++) { 
        for (int j = i + 1; j < n; j++) { 
  
            // The innermost loop checks for 
            // the triangle property 
            for (int k = j + 1; k < n; k++) 
  if(A[i]!=A[j]&&A[i]!=A[k]&&A[k]!=A[j])
  {
                // Sum of two sides is greater 
                // than the third 
                if ( 
                    A[i] + A[j] > A[k] 
                    && A[i] + A[k] > A[j] 
                    && A[k] + A[j] > A[i]) 
                    count++; 
        } 
    } 
}
    cout<<count; 
	return 0;
}

Measured memory_bytes: 3632
#pragma GCC optimize(1)
#include<bits/stdc++.h>
using namespace std;
const int maxn=4;
char x[maxn];int n;
int main(){
	for(register int i=1;i<=n;i++);
	scanf("%s",x);
	n=strlen(x);
	if(n==2) printf("%s\n",x);
	else{
		putchar(x[2]);putchar(x[1]);putchar(x[0]);putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,i,t,m;
	while(~scanf("%d",&n)){
		m=0;
		for(i=1;i<=9;i++)
		if(n%i==0)
		{
			t=n/i;
			if(t<=9&&1<=9)
			{
				m=1;
				break;
			}
		}
		if(m==1)
		printf("Yes\n");
		else
		printf("No\n");
	}
	return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n = read();
  vi h(n);
  REP(i, n) { h[i] = read(); }
  for (int i = 0; i < n - 1; i++) {
    if (h[i] >= h[i + 1]) {
      h[i]--;
      if (h[i] > h[i + 1]) {
        std::cout << "No" << std::endl;
        return 0;
      } else if (h[i] == h[i + 1]) {
        h[i + 1]++;
      }
    }
  }
  std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std ;
bool su[100000];
int main (){
    for(int i=0;i<28;i++){
        int g;
        cin>>g;
        su[g]=1;
    }
    for(int i=1;i<31;i++){
        if(su[i]==0){
            cout<<i<<endl;
        }
    }

}

Measured memory_bytes: 3068
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
 	
  int c,n,i,j,k,l;
  while(cin>>n){
    c=0;
    for(i=0;i<=9;i++){
      for(j=0;j<=9;j++){
	for(k=0;k<=9;k++){
	  for(l=0;l<=9;l++){
	    if(n<i+j+k+l)break;
	    if(n==(i+j+k+l))c++; 
	   
	  }
	}
      }
    }
    
    cout<<c<<endl;
  } 
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=8e18;
const int32_t LOG=21;
const int MOD=MOD2;

int a[200005];
int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      {
            map<int,int> cnt;
            int n;
            cin>>n;
            rep(i,1,n+1)cin>>a[i];
            int ans=0;
            rep(i,1,n+1)
            {
                ans+=cnt[i-a[i]];
                cnt[i+a[i]]++;
            }
            cout<<ans<<endl;


      }
      

      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 27912
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000000000;
const int mod = 1000000007;
int test[12345678], res[12345678];
signed main() {
	vector<char> v; map<int, int> cost;
	int n, m, sum = 0, num = 0, cnt = 0, ans = 0; string s, t;
	cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> test[h]; int x = 0;
		if (h == 0) { cnt = max((int)1, test[h]); sum = max(1 - test[h], (int)0); continue; }
		if (cnt > 0 && cnt + test[h] >= 0) { sum += 1 + (cnt + test[h]); cnt = -1; x++; }
		else if (cnt < 0 && cnt + test[h] <= 0) { sum += 1 - (cnt + test[h]); cnt = 1; x++; }
		if (x == 0) { cnt += test[h]; }
	}
	cnt = 0;
	for (int h = 0; h < n; h++) {
		int x = 0;
		if (h == 0) { cnt = min(test[h], (int)0 - 1); num = max(1 + test[h], (int)0); continue; }
		if (cnt < 0 && cnt + test[h] <= 0) { num += 1 - (cnt + test[h]); cnt = 1; x++; }
		else if (cnt > 0 && cnt + test[h] >= 0) { num += 1 + (cnt + test[h]); cnt = -1; x++; }
		if (x == 0) { cnt += test[h]; }
	}
	//cout << sum << ' ' << num << endl;
	cout << min(sum, num) << endl;
	return 0;
}

Measured memory_bytes: 2304
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		while (true) {
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			
			if (x == 0 && y == 0) break;
			
			if (x > y) {
				int t = x;
				x = y;
				y = t;
			}
			
			System.out.println(x + " " + y);
		}
	}

}



Measured memory_bytes: 36328