akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int N;
    cin >> N;
    vector<int> v(N);
    REP (i, 0, N) cin >> v[i];
    int res = 1 << 30;
    REP (_, 0, 2) {
        bool isUp = false;
        bool isDown = false;
        int ans = 1;
        for (int i = 1; i < N; i++) {
            if (isUp && v[i - 1] > v[i]) {
                ans++;
                isUp = isDown = false;
                continue;
            } else if (isDown && v[i - 1] < v[i]) {
                ans++;
                isUp = isDown = false;
                continue;
            }
            if (v[i] != v[i - 1]) {
                isUp = v[i - 1] < v[i];
                isDown = v[i - 1] > v[i];
            }
        }
        res = min(res, ans);
        reverse(v.begin(), v.end());
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
from collections import deque

n, m = map(int, input().split())

graph = [[] for _ in range(n+1)]

for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

dist = [[-1,0] for _ in range(n+1)]
dist[0][0] = 0
dist[1][0] = 0

d = deque()
d.append(1)

while d:
    v = d.popleft()
    for i in graph[v]:
        if dist[i][0] != -1:
            continue
        dist[i][0] = dist[v][0] + 1
        dist[i][1] = v
        d.append(i)

ans = dist[2:]

print('Yes')
for j in range(n-1):
    print(ans[j][1])

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

int main( )
{
    int n, i, j, k;
    int d, fl = 1;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> d;
        if (d % 2 == 0) {
            if (!(d % 3 == 0 || d % 5 == 0)) {
                fl = 0;
            }
        }
    }
    if (fl) cout << "APPROVED\n";
    else    cout << "DENIED\n";
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A, B, C = [input() for _ in range(3)]
ans = 0
for i in range(N):
    if A[i] == B[i] != C[i] or B[i] == C[i] != A[i] or C[i] == A[i] != B[i]:
        ans += 1
    elif not A[i] == B[i] == C[i]:
        ans += 2
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod=1e9+7;



struct indiv{
    int end,start,x,l;
};

bool asc(const indiv& left,const indiv& right){
    return left.end < right.end;
};

int main(){
    int n;
    cin >> n;
    vector<indiv> robo(n);
    int ans = 0;

    for(int i = 0; i < n; i++){
        cin >> robo[i].x >> robo[i].l;
        robo[i].start = robo[i].x-robo[i].l;
        robo[i].end = robo[i].x+=robo[i].l;
    }

    sort(robo.begin(),robo.end(),asc);

    int now_end = robo[0].end;
    ans++;

    for(int i = 1; i < n; i++){
        if(robo[i].start >= now_end){
            now_end = robo[i].end;
            ans++;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

template<typename T>
ostream& operator<<(ostream& os, const vector<vector<T>> &v)
{
  N_TIMES(y, v.size()) {
    N_TIMES(x, v[y].size()) {
      os << v[y][x];
      if (x + 1 < v[y].size()) { os << ' '; }
    }
    if (y + 1 < v.size()) { os << endl; }
  }
  return os;
}

int main()
{
  uint64_t H, W, K;
  cin >> H >> W >> K;

  vector<string> S(H);
  N_TIMES(y, H) { cin >> S[y]; }

  vector<vector<uint64_t>> T(H, vector<uint64_t>(W, 0));

  set<uint64_t> ys;
  N_TIMES(y, H) {
    bool flag = false;
    N_TIMES(x, W) {
      if (S[y][x] == '#') { flag = true; }
    }
    if (flag) { ys.insert(y); }
  }

  uint64_t c = 1;
  N_TIMES(y, H) {
    if (ys.find(y) == ys.end()) {
      if (y > 0) {
        N_TIMES(x, W) {
          T[y][x] = T[y - 1][x];
        }
      }
    } else {
      bool flag = false;
      N_TIMES(x, W) {
        if (S[y][x] == '#') {
          if (flag) { ++c; }
          T[y][x] = c;
          flag = true;
        } else {
          T[y][x] = c;
        }
      }
      ++c;
    }
  }

  uint64_t M = *ys.begin();
  N_TIMES(y, M) {
    N_TIMES(x, W) {
      T[y][x] = T[M][x];
    }
  }

  cout << T << endl;

  return 0;
}

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

int main(){
  ll n, k, s, a, b;
  cin >> n >> k >> s;

  for ( int i = 0; i < k; i++){
    cout << s << " ";
  }
  for ( int i = 0; i < n - k; i++){
    if ( s == 1){
      cout << s+1 << " ";
    } else {
      cout << s-1 << " ";
    }

  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10;
int n;
queue<pair<int, int> > q;
int fa[N];
int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }
set<int> g[N];

pair<int, int> gid(int x, int y) {
	if(x > y) swap(x, y);
	return make_pair(x, y);
}
map<pair<int, int>, int> cnt;

void lk(int u, int v) {
	g[u].emplace(v);
	g[v].emplace(u);
	int cur = ++ cnt[gid(u, v)];
	if(cur == 2) {
		q.emplace(u, v);
	} else if(cur == 3) {
		puts("NO");
		exit(0);
	}
}

int main() {
	scanf("%d", &n);
	for(int i = 1, u, v ; i <= 2 * (n - 1) ; ++ i) {
		scanf("%d%d", &u, &v);
		lk(u, v);
	}
	for(int i = 1 ; i <= n ; ++ i) {
		fa[i] = i;
	}
	for(int i = 1 ; i < n ; ++ i) {
		if(q.empty()) return puts("NO"), 0;
		int x = get(q.front().first), y = get(q.front().second);
		q.pop();
		if(g[x].size() > g[y].size()) {
			swap(x, y);
		}
		fa[x] = y;
		cnt.erase(gid(x, y));
		g[y].erase(x);
		g[x].erase(y);
		for(auto z: g[x]) {
			z = get(z);
			if(z == y) continue;
			cnt.erase(gid(x, z));
			lk(z, y);
			g[z].erase(x);
			g[x].erase(z);
		}
	}
	puts("YES");
}


Measured memory_bytes: 56064
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e14;
using Graph = vector<vector<int>>;

signed main(){
  int K;
  cin >> K;
  if( K%2 == 0 || K%5 == 0 ){
    cout << -1 << endl;
    return 0;
  }

  int L = K*9;
  if( K%7 == 0 ) L /= 7;

  int now = 10;
  for( int i = 1; i <= L; i++ ){
    if( now%L == 1 ){
      cout << i << endl;
      return 0;
    }
    now %= L;
    now *= 10;
  }
  cout << -1 << endl;
}


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

int main()
{
    string s;
    cin >> s;
    int c0 = 0;
    int c1 = 0;

    for(int i = 0; i < s.length(); i++)
    {
        if(s[i] == '0') c0++;
        else if(s[i] == '1') c1++;
    }

    int res = min(c0, c1);
    cout << res*2 << endl;

    return 0;
}

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

int64_t divceil(int64_t numer, int64_t denom) {
    if (numer % denom == 0) {
        return numer / denom;
    } else {
        return 1L + numer / denom;
    }
}
int main() {
    int64_t N, K;
    cin >> N;
    cin >> K;
    int64_t max_a = -1;
    vector<int64_t> A(N);
    for (uint64_t i = 0; i < N; i++) {
        cin >> A[i];
        max_a = max(max_a, A[i]);
    }

    int64_t result = max_a + 1;
    int64_t left = 1;
    int64_t right = max_a;
    while (true) {
        int64_t mid = (left + right) / 2;

        int64_t total_split = 0;
        for (uint64_t i = 0; i < N; i++) {
            int64_t split_num = divceil(A[i], mid) - 1L;
            total_split += split_num;
        }

        if (total_split <= K) {
            result = min(mid, result);
        }

        if (right - left <= 0) {
            break;
        }
        if (total_split <= K) {
            right = mid;
        } else if (left == mid) {
            left = right;

        } else {
            left = mid;
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 4796
n, a, b, c = map(int, input().split())
A = [a, b, c]
D = {'AB': 0, 'BC': 1, 'AC': 2}
S = [input() for i in range(n)]
S.append('AB')
X = []
for i in range(n):
    x, y = D[S[i]], (D[S[i]] + 1) % 3
    if A[x] == 0 and A[y] == 0:
        print('No')
        exit()
    if A[x] < A[y]:
        A[x], A[y] = A[x] + 1, A[y] - 1
        X.append('ABC'[x])
    elif A[x] > A[y]:
        A[x], A[y] = A[x] - 1, A[y] + 1
        X.append('ABC'[y])
    else:
        x1, y1 = D[S[i + 1]], (D[S[i + 1]] + 1) % 3
        if x == y1:
            A[x], A[y] = A[x] + 1, A[y] - 1
            X.append('ABC'[x])
        else:
            A[x], A[y] = A[x] - 1, A[y] + 1
            X.append('ABC'[y])
print('Yes')
print(*X, sep='\n')


Measured memory_bytes: 18484
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)


int main() {
    ll s, w;
    cin >> s >> w;
    string ans = "safe";
    if (s <= w) ans = "unsafe";
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
using namespace std;
using pii = pair<int,int>;
using ll = long long;
vector<int> G;

ll insertion(int a[], int n, int g)
{
    ll cnt = 0;
    for (int i=g; i < n; ++i) {
        int j = i-g;
        int tmp = a[i];

        while (j >= 0 && a[j] > tmp) {
            a[j+g] = a[j];
            j -= g;
            ++cnt;
        }
        a[j+g] = tmp;
    }
    return (cnt);
}

ll shell(int a[], int n)
{
    int h = 1;
    ll cnt = 0;
     while (h <= n) {
         G.push_back(h);
         h = 3*h + 1;
     }

     for (int i=G.size()-1 ; i >= 0; --i) {
         cnt += insertion(a, n, G[i]);
     }

     return cnt;
}

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

   int n;
   int a[1000123];

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

   ll cnt = shell(a, n);

   outl(G.size());
   for (int i=G.size()-1; i >= 0; --i) {
       cout << G[i] << (i-1 >= 0 ? ' ' : '\n');
   }
   outl(cnt);

   rep(i, n) {
       outl(a[i]);
   }
}




Measured memory_bytes: 6972
#include <bits/stdc++.h>
#define MOD 1000000007
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define RREP(i,a,b) for(ll i=(a); i>=(b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

ll n,k;
vvl a(100005);
vl c(100005,0);
vl p(100005,0);
vl pp(100005,0);
vector<bool> visit(100005,false);

void bfs(ll s){
    queue<ll> q;
    q.push(s);
    ll u;
    while(!q.empty()){
        u = q.front(); q.pop();
        visit[u] = true;
        for(auto v:a[u]){
            if(!visit[v]){
                p[v]++;
                pp[v] += p[u] + c[u];
                c[u]++;
                q.push(v);
            }
        }
    }
}
int main(){
    cin >> n >> k;
    ll A,B;
    rep(i,n-1){
        cin >> A >> B;
        A--; B--;
        a[A].push_back(B);
        a[B].push_back(A);
    }
    bfs(0);
    ll ans = 1;
    rep(i,n){
        //cout << p[i] << " " << pp[i] << " " << c[i] << "\n";
        ans = ((ans % MOD) * (k - p[i] - pp[i])) % MOD;
    }
    cout << ans << "\n";

}


Measured memory_bytes: 9716
#include<stdio.h>
int main(){
  int x,y,tmp,r;

  scanf("%d%d",&x,&y);

  if(x<y){
    tmp = x;
    x = y;
    y = tmp;
  }

  r = x % y;
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }

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

  return 0;
}
  



Measured memory_bytes: 2064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll n;
    cin >> n;
    ll a[n+1];
    rep(i,n+1)cin >> a[i];

    ll INF = 1001001001001001;

    ll y[n+1] = {};

    if(n == 0){
        if(a[0] == 1){
            cout << 1 << endl;
        }else{
            cout << -1 << endl;
        }
        return 0;
    }

    if(a[0] != 0){
        cout << -1 << endl;
        return 0;
    }

    y[0] = 1;

    srep(i,1,n+1){
        y[i] = min(y[i-1]*2, INF);
        if(a[i] > y[i]){
            cout << -1 << endl;
            return 0;
        }
        y[i] -= a[i];
    }

    ll ans = 0;



    ll now = 0;

    drep(i,n+1){
        if(i == n){
            ans += a[i];
            now = a[i];
        }else{
            ans += a[i];
            if(y[i] >= now){
                ans += now;
                now = now + a[i];
            }else{
                ans += y[i];
                now = y[i] + a[i];
            }
        }
    }

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




Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;
 
const int N = 5e5 + 5;
 
int n;
char s[N];
int L[N], R[N];
 
int main() {
    scanf("%s", s + 1);
    n = strlen(s + 1) + 1;
    for (int i = 1; i <= n; i++)
        L[i] = (s[i - 1] == '<') * (L[i - 1] + 1);
    for (int i = n; i; i--)
        R[i] = (s[i] == '>') * (R[i + 1] + 1);
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += max(L[i], R[i]);
//      cerr << max(L[i], R[i]) << ' ';
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 8184
n = int(input())
p = [int(i) for i in input().split()]
ans = 0
for i in range(1,n-1):
  if min(p[i-1], p[i], p[i+1]) != p[i] and max(p[i-1], p[i], p[i+1]) != p[i]:
    ans += 1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>

using namespace std;

typedef pair<int, int> pi;
int main(){
	vector<vector<pi> > A(3, vector<pi>(3));
	for(int i = 0; i < 3; ++i){
		for(int j = 0; j < 3; ++j){
			cin >> A[i][j].first;
			A[i][j].second = 0;
		}
	}
	int N; cin >> N;
	vector<int> b(N);
	for(int i = 0; i < N; ++i) cin >> b[i];

	for(int k = 0; k < N; ++k){
		for(int i = 0; i < 3; ++i){
			for(int j = 0; j < 3; ++j){
				if(A[i][j].first == b[k]){
					A[i][j].second = 1;
				}
			}
		}
		for(int i = 0; i < 3; ++i){
			bool tf = true;
			for(int j = 0; j < 3; ++j){
				if(A[i][j].second == 0) tf = false;
			}
			if(tf) { cout << "Yes" << endl; return 0; }
		}
		for(int i = 0; i < 3; ++i){
			bool tf = true;
			for(int j = 0; j < 3; ++j){
				if(A[j][i].second == 0) tf = false;
			}
			if(tf) { cout << "Yes" << endl; return 0; }
		}
		if(A[0][0].second == A[1][1].second && A[1][1].second && A[2][2].second) { cout << "Yes" << endl; return 0; }
		if(A[0][2].second == A[1][1].second && A[1][1].second && A[2][0].second) { cout << "Yes" << endl; return 0; }
	}

	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  zero
//
//  Created by 叶金炜 on 2019/4/2.
//  Copyright © 2019 okstal. All rights reserved.
//

#include <iostream>
using namespace std;
int main() {
    int a;
    cin>>a;
    int b=a*a*a;
    cout<<b<<endl;
}



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

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

  int n;
  cin >> n;
  int nxt = 1, cnt = 0;
  for (int i = 1; i <= n; i++) {
    int t;
    cin >> t;
    if (t == nxt) {
      nxt++;
    } else {
      cnt++;
    }
  }
  if (cnt == n) {
    cout << -1 << endl;
  } else {
    cout << cnt << endl;
  }
}

Measured memory_bytes: 256
/* ****_hela**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  4005
int lr[N][N],lb[N][N],lg[N][N],rr[N][N],rb[N][N],rg[N][N];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		int n;
		cin>>n;
		string s;
		cin>>s;

		for(int i=1;i<n;i++)
		{
			if(s[i-1]=='R')
				for(int k=i;k<n;k++)lr[k][i-1]=1,lr[k][n]++;
			else if(s[i-1]=='B')
				for(int k=i;k<n;k++)lb[k][i-1]=1,lb[k][n]++;
			else
				for(int k=i;k<n;k++)lg[k][i-1]=1,lg[k][n]++;
		}		
		for(int i=n-2;i>=0;i--)
		{
			if(s[i+1]=='R')
				for(int k=i;k>=0;k--)rr[k][i+1]=1,rr[k][n]++;
			else if(s[i+1]=='B')
				for(int k=i;k>=0;k--)rb[k][i+1]=1,rb[k][n]++;
			else
				for(int k=i;k>=0;k--)rg[k][i+1]=1,rg[k][n]++;
		}
		ll int sum=0;
		for(int i=0;i<n;i++)
		{
			if(s[i]=='R')
			{	
				//left blue
				for(int j=0;j<n;j++)
				{	
					if(lb[i][j]==1 && (2*i-j)<n && rg[i][2*i-j]==1)sum+=rg[i][n]-1;
					else if(lb[i][j]==1)sum+=rg[i][n];
				}
				//left green
				for(int j=0;j<n;j++)
				{
					if(lg[i][j]==1 && (2*i-j)<n && rb[i][2*i-j]==1)sum+=rb[i][n]-1;
					else if(lg[i][j]==1)sum+=rb[i][n];
				}
			}
			else if(s[i]=='G')
			{
				//left blue
				for(int j=0;j<n;j++)
				{	
					if(lb[i][j]==1 && (2*i-j)<n && rr[i][2*i-j]==1)sum+=rr[i][n]-1;
					else if(lb[i][j]==1)sum+=rr[i][n];
				}
				//left red
				for(int j=0;j<n;j++)
				{
					if(lr[i][j]==1 && (2*i-j)<n && rb[i][2*i-j]==1)sum+=rb[i][n]-1;
					else if(lr[i][j]==1)sum+=rb[i][n];
				}

			}
			else
			{
				//left green
				for(int j=0;j<n;j++)
				{	
					if(lg[i][j]==1 && (2*i-j)<n && rr[i][2*i-j]==1)sum+=rr[i][n]-1;
					else if(lg[i][j]==1)sum+=rr[i][n];
				}
				//left red
				for(int j=0;j<n;j++)
				{
					if(lr[i][j]==1 && (2*i-j)<n && rg[i][2*i-j]==1)sum+=rg[i][n]-1;
					else if(lr[i][j]==1)sum+=rg[i][n];
				}
				
			}
		}
		// cout<<"lr:\n";
		// rep(i,0,n)
		// {rep(j,0,n+1)cout<<lr[i][j]<<" ";cout<<'\n';}
		// cout<<"rb:\n";
		// rep(i,0,n)
		// {rep(j,0,n+1)cout<<rb[i][j]<<" ";cout<<'\n';}

		
		cout<<sum;
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<int>;

#define rep(i, n)  for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)
#define Cast(dig, n) static_cast<std::bitset<(dig)>>(n)

const int INF = 2147483647;
const ll  MOD = 1000000007;

// nCrを求める
// nCr = n * (n - 1) * ... * (n - r + 1) / a!
long long int choose(int n, int r) {
    if(n == r) return 1;
    if(n < r) return 0;
    if(r == 0) return 1;
    if(r == 1) return n;
    return choose(n-1, r-1) + choose(n-1, r);
}

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

    // key: 玉のナンバー value: 個数
    map<int, int> table;
    vec a(n);

    rep(i, n) {
        cin >> a[i];
        table[a[i]]++;
    }

    ll sum = 0;
    for(auto itr : table) {
        auto k = itr.first;
        auto v = itr.second;
        sum += choose(v, 2);
    }

    rep(i, n) {
        ll ans = ((table[a[i]] > 0) ? table[a[i]] - 1 : 0);
        cout << sum - ans << endl;
    }
    
    return 0;
}

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

public class Main {
	
	int count = 1;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		for(int i = 0; i < n-1; i++) {
			if(a[i] != a[i+1]) {
				count++;
			}
		}
		
		System.out.println(count);
		
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

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

Measured memory_bytes: 23252
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <functional>
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
// constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  int N = S.size();
  ll ans = 0;
  ll cnt = 0;
  for(int i=0; i<N; i++){
    if(S[i] == 'B'){
      cnt++;
    }else{
      ans += cnt;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3744
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <cstdlib>
#define mp make_pair
#define pb push_back
#define mem(i,a) memset(i,a,sizeof(i))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int DMAX=100000+5;
const int MOD=1000000000+7;
template<class T> inline void read(T &x){
	x=0;
	T f=1;
	char ch=getchar();
	while(ch<'0' || ch>'9'){
		if(ch=='-'){
			f=-1;
		}
		ch=getchar();
	}
	while(ch<='9' && ch>='0'){
		x=x*10+(ch-'0');
		ch=getchar();
	}
	x*=f;
}
ll n;
ll ans=0;
int main(){
	read(n);
	for(ll i=1;i*i<=(n-1);i++){
		if((n-1)%i==0){
			ans+=2;
		}
		if(i*i==(n-1)){
			ans--;
		}
	}
	ans--;
//	cout<<ans<<" ";
	for(ll i=2;i*i<=n;i++){
		if(n%i!=0){
			continue;
		}
		ll p=n;
		while(p%i==0){
			p/=i;
		}
		if(p%i==1){
			ans++;
		}
	}
	printf("%lld\n", ans+1);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, i, j;
  int max = 0;
  
  cin >> N;
  
  vector<string> s(N);
  
  for (i = 0; i < N; i++) cin >> s.at(i);
  
  cin >> M;
  
  vector<string> t(M);
  
  for (i = 0; i < M; i++) cin >> t.at(i);
  
  vector<int> s_word(N, 0);
  vector<int> t_word(M, 0);
  
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      if(s.at(i) == s.at(j)) s_word.at(i) += 1;
    }
    for (j = 0; j < M; j++) {
      if(s.at(i) == t.at(j)) s_word.at(i) -= 1;
    }
    if (max < s_word.at(i)) max = s_word.at(i);
  }

  for (i = 0; i < M; i++) {
    for (j = 0; j < N; j++) {
      if(t.at(i) == s.at(j)) t_word.at(i) += 1;
    }
    for (j = 0; j < M; j++) {
      if(t.at(i) == t.at(j)) t_word.at(i) -= 1;
    }
    if (max < t_word.at(i)) max = t_word.at(i);
  }
  
  cout << max << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1500;
const int q=1e9+7;
inline int Plus(int x,int y) {return (x+=y)>=q?x-q:x;}
inline void Pe(int &x,int y) {x=Plus(x,y);}
inline int Sub(int x,int y) {return (x-=y)<0?x+q:x;}
inline void Se(int &x,int y) {x=Sub(x,y);}
inline int Multi(int x,int y) {return 1ll*x*y%q;}
inline void Me(int &x,int y) {x=Multi(x,y);}
inline int mi(int x,int y) {
	int ret=1;
	for (;y;y>>=1,Me(x,x)) if (y&1) Me(ret,x);
	return ret;
}
int d[maxn],s=0,n,k,f[maxn],ans=0;
int main() {
	cin>>n>>k;
	for (int i=1;i*i<=n;++i) if (n%i==0) {
		d[++s]=i;
		if (i*i!=n) d[++s]=n/i;
	}
	sort(d+1,d+s+1);
	for (int i=1;i<=s;++i) {
		int di=d[i],&fi=f[i]=mi(k,(di+1)/2);
		for (int j=1;j<i;++j) if (di%d[j]==0) Se(fi,f[j]);
		Pe(ans,((1ll*fi*di)>>(~di&1))%q);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;

int main(){
	int N;
	cin >> N;
	LL ans=0;
	for(int i=1; i<=N; i++){
		if(i%3&&i%5) ans+=i;
	}
	cout << ans << endl;

	return 0;
}


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

int n, m;
string u[256];
bool open;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) cin >> u[i];
  open = false;
  scanf("%d", &m);
  string t;
  for (int i = 0; i < m; i++) {
    cin >> t;
    bool flag = true;
    for (int j = 0; j < n; j++) {
      if (t == u[j]) {
        if (open) cout << "Closed by " << t << "\n";
        else cout << "Opened by " << t << "\n";
        open = !open;
        flag = false;
        break;
      }
    }
    if (flag) cout << "Unknown " << t << "\n";
  }
}



Measured memory_bytes: 3280
#include <iostream>

int main()
{
	long long x;
	std::cin >> x;
	
	long long amount = 100;
	int cnt;
	for (cnt = 0; amount < x; cnt++) {
		amount *= 1.01;
	}
	
	std::cout << cnt << std::endl;
	
	return 0;
}


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

int main(){
	int a, b, c ;
	int n = 0;
	cin >> a >> b >> c ;
	while(1){
		if(c % a == 0){
		n++;
		}
		if(a == b){
			break;
		}
		a++;
	}
	cout << n << endl;
	
	return 0;
} 

Measured memory_bytes: 1164
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
ll N, S;
ll f(ll b, ll n)
{
    if (n < b)
    {
        return n;
    }
    return f(b, n / b) + n % b;
}
int main()
{
    cin >> N;
    cin >> S;
    if (S == N)
    {
        cout << N + 1 << endl;
        return 0;
    }
    bool ok = false;
    ll b = 2;
    ll result = LL_INF;
    while (true)
    {

        if (f(b, N) == S)
        {
            ok = true;
            result = min(result, b);
            break;
        }
        b++;
        if (b * b > N)
        {
            break;
        }
    }

    ll sn = sqrt(N) + 10;
    while (true)
    {
        if (sn == 0)
        {
            break;
        }
        ll b = (N - S) / sn + 1;
        if (b <= 1)
        {
            sn--;
            continue;
        }
        if (f(b, N) == S)
        {
            ok = true;
            result = min(result, b);
            break;
        }
        sn--;
        if (sn == 0)
        {
            break;
        }
    }

    if (not ok)
    {
        cout << -1 << endl;
        return 0;
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
ans = "Yes"
for i in range(N-1):
    if H[i+1] > H[i]:
        H[i+1]-= 1
       
    elif H[i+1] == H[i]:
        continue
    else:
        ans = "No"
        break
print(ans)


Measured memory_bytes: 15020
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
void magicSquare(vector<vector<int> > &v1) {
  int n = v1.size();
  int row = (n / 2 + 1), column = n / 2;
  
  v1[row][column] = 1;
  for(int cnt = 2; cnt <= n * n; ++cnt) {
	row = (row == n - 1 ? 0 : row + 1);
	column = (column == n - 1 ? 0 : column + 1);

	while(v1[row][column] != 0) {
	  row = (row == n - 1 ? 0 : row + 1);
	  column = (column == 0 ? n - 1 : column - 1);
	}
	v1[row][column] = cnt;
  }
}

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

	vector<vector<int> > v1(n, vector<int>(n, 0));
	magicSquare(v1);
	for(int i = 0; i < n; ++i) {
	  for(int j = 0; j < n; ++j) {
		cout << right << setw(4) << v1[i][j];
	  }
	  cout << endl;
	}
  }
  return 0;
}

Measured memory_bytes: 3088
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll a, b, c, d, e, f, g;
  cin>>a>>b>>c>>d>>e>>f>>g;
  ll ans = 0;
  int num;
  num = a%2 + d%2 + e%2;
  if(num>=2 && a>=1 && d>=1 && e>=1) {
    ans += 3;
    a--;
    d--;
    e--;
  }
  ans += 2*(a/2);
  a %= 2;
  ans += b;
  b = 0;
  ans += 2*(d/2);
  d %= 2;
  ans += 2*(e/2);
  e %= 2;
  if(a==1 && d==1 && e==1) {
    ans += 3;
    a = 0;
    d = 0;
    e = 0;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3616
class Node
	attr_accessor :prev, :next, :value
	def initialize value
		@value = value
	end
end

class DoubllyLinkedList
	def initialize
		@head = @tail = nil
	end

	def insert value
		node = Node.new value
		if @head.nil?
			@tail = node
		else
			node.next = @head
			@head.prev = node
		end
		@head = node
	end

	def delete value
		return unless @head
		if @head.value == value
			deleteFirst nil
		else
			node = @head.next
			node = node.next while node && node.value != value
		end
		if node
			unless node.next
				deleteLast nil
			else
				node.prev.next = node.next
				node.next.prev = node.prev
			end
		end
	end

	def deleteFirst dummy
		return unless @head
		if @head.next
			@head = @head.next
			@head.prev = nil
		else
			@head = @tail = nil
		end
	end

	def deleteLast dummy
		return unless @tail
		if @tail.prev
			@tail = @tail.prev
			@tail.next = nil
		else
			@head = @tail = nil
		end
	end

	def values
		arr = []
		node = @head
		while node
			arr << node.value
			node = node.next
		end
		return arr
	end
end

dll = DoubllyLinkedList.new
n = gets.to_i
n.times{
	line = gets.chomp.split
	dll.send line[0], line[1]
}
puts dll.values.join(" ")

Measured memory_bytes: 145356
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vs vector<string>
const int inf=1e9+1;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846

int main(){
	int i,a,b,c;
	cin>>a>>b>>c;
	int flag=0;
	loop(i,1,101){
		if((i*a)%b==c){
			flag=1;
		}
	}
	if(flag==1){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int x=0,l=0,k=0,co[27]={0};
    char arf[27]={0},b[120000]={0},arfg[27]={0};
    for(x=0;x<26;x++){
        arf[x]='a'+x;
        arfg[x]='A'+x;
    }
    while(scanf(" %c",&b[l]) != EOF){
        l++;
    }

    for(x=0;x<26;x++){
        for(k=0;k<l;k++){
            if(arf[x]==b[k]||arfg[x]==b[k]){
                co[x]+=1;
            }
        }
    }
    for(x=0;x<26;x++){
        printf("%c : %d\n",arf[x],co[x]);
    }
    return 0;
}

Measured memory_bytes: 664
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<usize>();
    let n = v[0];
    let k = v[1];

    let mut hs: Vec<u32> = vec![];
    for _ in 0..n {
        hs.push(read::<u32>());
    }
    hs.sort();

    let mut v1 = vec![];
    for i in 0..(n-k+1) {
        v1.push(hs[i + k - 1] - hs[i]);
    }
    let ans = v1.iter().min().unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 4352
def examA():
    N = I(); A = I()
    ans = N*N - A
    print(ans)


import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examA()

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

int main(){
    string T;
    cin >> T;
    for(int i = 0; i < T.size();i++){
        if(T[i] == '?'){
            T[i] = 'D';
        }
    } 
    cout << T << endl;
}

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

using namespace std;
const double pi=acos(-1.0);
const double eps=1e-9;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define re return
#define vi vector <int> 
#define pii pair <int,int>
#define pll pair <long long , long long>
typedef long long ll;

const int N=(int)2e5+5;
int n,a[N],ans;

int main()
{
	ios:: sync_with_stdio(false);
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		a[i]--;
	}
	for(int i=0;i<n;i++)
		if(a[a[i]]==i)ans++;
	cout << ans/2;
	return 0;
}

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

//CBABCDZA
//ans 5
// len 8

int main (void){
	int i = 0;
	int len = 0;
	char str[200001];
	int head = 0, tail = 0;

	scanf("%s", str);
	len = strlen(str);
	while(1){
		if(str[i] == 'A') break;
		i++;
	}
	head = i; //2

	i = 0;
	while(1){
		tail = len - i -1;
		if(str[tail] == 'Z' ) break;
		i++;
	}
	//tail 6

	
	//printf("%s\n", str);

	printf("%d\n", tail-head+1);
	return 0;
	
	
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll N, Q;
    cin >> N >> Q;
    vec A(N), s(N+1, 0), s2(N+2, 0);
    Rep (i, N) {
        cin >> A[i];
        s[i+1] = s[i] + A[i];
        s2[i+2] = s2[i] + A[i];
    }

    // printvec(s);
    // printvec(s2);

    while (Q--) {
        ll X;
        cin >> X;

        ll ok = N-1, ng = 0;
        while (abs(ok-ng) > 1) {
            ll mid = (ok+ng)/2;
            auto check = [&] (ll x) -> bool {
                if (X > A[x]) {
                    return false;
                }
                ll takahashi = N - x - 1;
                ll aoki = x - (lower_bound(A.begin(), A.end(), 2*X - A[x]) - A.begin());
                // cout << mid << " " << takahashi << " " << aoki << "\n";
                if (takahashi <= aoki) return true;
                else return false;
            };
            if (check(mid)) ok = mid;
            else ng = mid;
        }
        // cout << ok << "\n";
        ll ans = s[N] - s[ok];
        if (2*ok-N+1 >= 0) ans += s2[2*ok-N+1];
        cout << ans << "\n";


    }
}

Measured memory_bytes: 5560
#include <stdio.h>

int main(void)
{
  	char a[11], b[11], c[11];
  
	scanf("%s%s%s", a, b, c);

  	printf("%c%c%c\n", a[0]-'a'+'A', b[0]-'a'+'A', c[0]-'a'+'A');

    return 0;
}

Measured memory_bytes: 128
sx,sy,tx,ty=map(int,input().split())
x=tx-sx
y=ty-sy
print('U'*y+'R'*x+'D'*y+'L'*(x+1)+'U'*(y+1)+'R'*(x+1)+'D'+'R'+'D'*(y+1)+'L'*(x+1)+'U')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
#define debug(a) cerr << #a << ": " << a << endl
 
typedef long long ll;
typedef pair<int, int> ii;
 
#define x first
#define y second
 
const int N = 510;

int n;

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
 
	cin >> n;

	for (int i = 1; i <= n - 1; i++) {
		for (int j = i + 1; j <= n; j++) {
			int k;
			for (k = 0; k < 10; k++) {
				if ((i & 1 << k) != (j & 1 << k)) break;
			}

			printf("%d ", k + 1);
		}
		
		printf("\n");
	}
 
	return 0;
}

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

int main() {
    int a, b;

    cin >> a >> b;

    if (a == b) {
        cout << 1 << endl;
    }
    else if ((a + b) % 2 == 0) {
        cout << ((a + b) / 2) << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void Solve(){
	int N,K,T,U,V,L;
	cin >> N >> K >> T >> U >> V >> L;

	vector<int> D(N);
	REP(i,0,N) cin >> D[i];

	double time=0;
	int carot=0,limit=0;
	REP(i,0,L){
		dump(i);
		bool flag=false;
		REP(j,0,N) if(D[j]==i){
			flag=true;
			break;
		}
		
		if(flag&&carot+1>K){
			limit=T*V;
			flag=false;
		}
		if(flag) ++carot;
		if(limit==0&&carot>0){
			limit=T*V;
			--carot;
		}
		
		if(limit>0) time+=1./V;
		else time+=1./U;

		if(limit>0) --limit;
	}

	cout << fixed << setprecision(9) << time << endl;
}

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

Measured memory_bytes: 1268
#include<stdio.h>
#include<string.h>
main()
{
	int a[8]={1,3,5,7,8,10,12},b[4]={4,6,9,11};
	int d,e;
	int i,m=0,n=0;
	scanf("%d%d",&d,&e);
	for(i=0;i<7;i++)
	{
		if(a[i]==d)m=1;
	if(e==a[i])n=1;
	}
	if(m==0||n==0){
		m=0;n=0;
	for(i=0;i<4;i++)
	{
		if(d==b[i])m=1;
	 	if(e==b[i])n=1;
   	}
   }
 if(d==2&&e==2){
	   	m=1;
	   	n=1;
	   }
	   if(m==1&&n==1)printf("Yes\n");
	   else printf("No\n"); 	                     
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




#define def 0
template<class V, int NV> class StarrySkyTree { // by kmjp
public:
	V comp(V l, V r) { return max(l, r); };

	vector<V> val, ma;
	StarrySkyTree() {
		val = vector<V>(NV * 2, def);
		ma = vector<V>(NV * 2, def);
	}

	V getval(int x, int y, int l = 0, int r = NV, int k = 1) { // [x,y)
		if (r <= x || y <= l) return def;
		if (x <= l && r <= y) return ma[k];
		auto a = comp(getval(x, y, l, (l + r) / 2, k * 2), getval(x, y, (l + r) / 2, r, k * 2 + 1));
		a += val[k];
		return a;
	}
	void update(int x, int y, V v, int l = 0, int r = NV, int k = 1) { // [x,y)
		if (l >= r) return;
		if (x <= l && r <= y) {
			val[k] += v; ma[k] += v;
		}
		else if (l < y && x < r) {
			update(x, y, v, l, (l + r) / 2, k * 2);
			update(x, y, v, (l + r) / 2, r, k * 2 + 1);
			ma[k] = comp(ma[k * 2], ma[k * 2 + 1]);
			ma[k] += val[k];
		}
	}
};
int N, M;
int L[301010], R[301010];
StarrySkyTree<int, 1<<20> st;
vector<pair<int, int>> buf;
//-----------------------------------------------------------------
int main() {
	cin >> N >> M;
	rep(i, 0, N) scanf("%d %d", &L[i], &R[i]);

	rep(i, 0, N) buf.push_back({R[i] - L[i] + 1, i});
	buf.push_back({ INT_MAX / 2, -1 });
	sort(buf.begin(), buf.end());
	int idx = 0;
	int oth = N;

	rep(m, 1, M + 1) {
		while (buf[idx].first == m) {
			int i = buf[idx].second;
			int l = L[i];
			int r = R[i];
			st.update(l, r + 1, 1);
			oth--;
			idx++;
		}

		int ans = oth;
		for (int i = 0; i <= M; i += m) {
			ans += st.getval(i, i + 1);
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 23152
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>
#include<limits.h>

int main()
{
	int i, flag;
	double xa[5],ya[5],xb[5],yb[5];

	while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&xa[1],&ya[1],&xa[2],&ya[2],&xb[1],&yb[1],&xb[2],&yb[2]) != EOF){
		xa[3] = xa[2], ya[3] = ya[1], xa[4] = xa[1], ya[4] = ya[2];
		xb[3] = xb[2], yb[3] = yb[1], xb[4] = xb[1], yb[4] = yb[2];

		flag = 0;
		for(i=1; i<=4; i++){
			if(xa[i] >= xb[1] && xa[i] <= xb[2] && ya[i] >= yb[1] && ya[i] <= yb[2]){
				printf("YES\n");
				flag = 1;
				break;
			}
		}
		if(flag)
			continue;
		for(i=1; i<=4; i++){
			if(xb[i] >= xa[1] && xb[i] <= xa[2] && yb[i] >= ya[1] && yb[i] <= ya[2]){
				printf("YES\n");
				flag = 1;
				break;
			}
		}
		if(flag)
			continue;
		if((xa[1] >= xb[1] && xa[3] <= xb[3] && ya[1] <= yb[1] && ya[4] >= yb[4]) ||
			xb[1] >= xa[1] && xb[3] <= xa[3] && yb[1] <= ya[1] && yb[4] >= ya[4]){
			printf("YES\n");
			continue;
		}
		printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 612
import sys
sys.setrecursionlimit(1000000)

h,w=map(int,input().split())
s=[input() for _ in range(h)]
t=[[None]*w for _ in range(h)]

def dfs(i,j,color):

  if not (0<=i<h and 0<=j<w):return 0,0
  if s[i][j]==color: return 0,0
  if t[i][j]:return 0,0

  t[i][j]=True
  wh,bl=0,0
  if s[i][j]=="#":
    bl+=1
  else:
    wh+=1

  tmp1,tmp2=dfs(i+1,j,s[i][j])
  wh,bl=wh+tmp1,bl+tmp2

  tmp1,tmp2=dfs(i-1,j,s[i][j])
  wh,bl=wh+tmp1,bl+tmp2
        
  tmp1,tmp2=dfs(i,j-1,s[i][j])
  wh,bl=wh+tmp1,bl+tmp2

  tmp1,tmp2=dfs(i,j+1,s[i][j])
  wh,bl=wh+tmp1,bl+tmp2

  return wh,bl

ans=0
for i in range(h):
  for j in range(w):
    a,b=dfs(i,j,"!")
    ans+=a*b

print(ans)

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

using namespace std;

int main(){
  int n,i=0,bef;
  long long MOD = 1000000007;
  cin >> n;
  string s,t;
  cin >> s;
  cin >> t;
  long long ret = 0;
  if(s[0]==t[0]){
    ret=3;
    i++;
    bef=0;
  }else{
    ret = 6;
    i+=2;
    bef=1;
  }
  for(;i<n;){
    if(s[i]==t[i]){
      if(bef==0){//左が縦
        ret=(ret*2)%MOD;
      }
      i++;
      bef=0;
    }else{//今横
      if(bef==0){//左が縦
        ret=(ret*2)%MOD;
      }else{
        ret=(ret*3)%MOD;
      }
      i+=2;
      bef=1;
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 8
#define NOT_FREE 0
#define FREE 1
int row[N], col[N], dpos[15], dneg[15], A[N][N];
int i, j, n, r, c;

void printBoard()
{
	for (i = 0; i < N; i++)
	{
		for (j = 0; j < N; j++)
		{
			if (A[i][j] && row[i] != j)return;
		}
	}
	for (i = 0; i < N; i++)
	{
		for (j = 0; j < N; j++)
		{
			if (row[i] == j) printf("Q");
			else { printf("."); }
		}
		printf("\n");
	}
}


void putQueen(int i)
{
	int j;
	if (i == N)
	{
		printBoard();
		return;
	}

	for (j = 0; j < N; j++)
	{
		if (col[j] == NOT_FREE || dpos[i + j] == NOT_FREE || dneg[i - j + N - 1] == NOT_FREE) continue;
		row[i] = j;
		col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE;
		putQueen(i + 1);
		col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;
	}
}



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

	for (i = 0; i < 15; i++)
	{
		dpos[i] = dneg[i] = FREE;
	}

	for (i = 0; i < N; i++)
	{
		col[i] = row[i] = FREE;
		for (j = 0; j < N; j++)
		{
			A[i][j] = 0;
		}
	}



	for (i = 0; i < n; i++)
	{
		scanf("%d%d", &r, &c);
		A[r][c] = 90;
	}
	putQueen(0);
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>bool chmax(T &a, const T &b) { if (a<=b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<=a) { a=b; return 1; } return 0; }
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n,k;
    cin>>n>>k;
    map<int,priority_queue<ll>> mp;
    rep(i,n) {
        int t;
        ll d;
        cin>>t>>d;
        mp[t].push(d);
    }
    
    priority_queue<ll> nokori;
    vector<ll> vec;
    for(auto &p:mp) {
        auto &q=p.second;
        vec.push_back(q.top());
        q.pop();
        while(sz(q)) {
            nokori.push(q.top());
            q.pop();
        }
    }
    
    sort(all(vec),greater<ll>());
    while(sz(vec)>k) {
        vec.pop_back();
    }
    reverse(all(vec));
    
    
    ll ans=0;
    for(ll x:vec) {
        ans+=x;
        //cout<<x<<endl;
    }
    rep(i,k-sz(vec)) {
        if(!sz(nokori)) continue;
        ans+=nokori.top();
        nokori.pop();
    }
    
    ll m=(ll)sz(vec);
    ans+=m*m;
    for(ll x:vec) {
        if(sz(nokori) && -x-m*m+(m-1)*(m-1)+nokori.top()>0) {
            ans+=-x-m*m+(m-1)*(m-1)+nokori.top();
            nokori.pop();
            m--;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 12280
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	vector<int> a;
	
	cin >> n;
	for(int i = 0; i < n; ++i){
		int buf;
		cin >> buf;
		a.push_back(buf);
	}
	
	int odd = 0;
	for(const auto &i : a){
		if(i % 2 == 1) ++odd;
	}
	
	cout << (odd % 2 == 0 ? "YES" : "NO");
	
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <cassert>
#define REP(i,l,n) for(int i=l;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define NMAX 1000
#define MMAX 100
int flag;
int ans;
int n,m;
int input;
int table[MMAX];
using namespace std;
int main() {
  while(1){
    cin >> n;
    cin >> m;
    if(n==0&&m==0) return 0;
    rep(i,m){
      table[i] = 0;
    }
    rep(i,n){
      rep(j,m){
        cin >> input;
        table[j] += input;
      }
    }
    flag = 0;
    for(int i = n;i>=0;i--){
      rep(j,m){
        if(table[j] == i){
          if(flag == 1) cout << " ";
          cout << j+1;
          flag = 1;
        }
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n, k;
    cin >> n >> k;
    ll ans;
    ll a = n%k;
    ll b = abs(a-k);
    ans = min(a, b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256