akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
       
       int main(void) {
           char str[26];
           scanf("%s" ,str);
           int i,j;
           int t = 0;
           
           for(i=0;str[i] != '\0';i++) {
             for(j=i+1;str[j] != '\0';j++){
               
              if(i != j && str[i] == str[j]){
               t = 1;
            }
           }
           }if(t == 0){
              printf("yes");
           }else{
              printf("no");
           }
    }


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define mp make_pair
#define P pair
#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 cbuf(buf, init) memset(buf, init, sizeof(buf))
#define modp(x, y) (((y) + (x) % (y)) % (y))
#define divd(x, y) (static_cast<double>(x) / static_cast<double>(y))

ll N, K, A[300000], B[300000];

int main()
{
    //
    cin >> N >> K;
    rep(i, 0, N) { cin >> A[i]; }

    rep(i, 0, N) { B[A[i]]++; }
    sort(B, B + 300000);
    ll mi = 0, ma = 0;
    rep(i, 0, 300000)
    {
        if (B[i] == 0) continue;
        if (mi == 0) mi = i;
        ma = i;
    }
    ll s = 0;
    if (ma - mi + 1 > K) {
        rep(i, 0, 300000)
        {
            if (B[i] == 0) continue;
            s += B[i];
            ma--;
            if (ma - mi + 1 == K) break;
        }
    }
    cout << s << endl;
}


Measured memory_bytes: 4352
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    long long N;
    cin >> N;
    vector<long long> vec(N);
    for (int i = 0; i < N; i++)
    {
        cin >> vec[i];
    }
    int now = 0;
    long long res = 0;
    vector<bool> have(N, false);
    while (1)
    {
        res++;
        have[now] = true;
        now = vec[now] - 1;
        if (now == 1)
        {
            cout << res << endl;
            return 0;
        }
        if (have[now])
        {
            cout << -1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = float('inf')
for l in range(0, n - k + 1):
    r = l + k - 1
    if x[r] <= 0:
        ans = min(ans, - x[l])
    elif 0 <= x[l]:
        ans = min(ans, x[r])
    else:
        assert x[l] <= 0 <= x[r]
        ans = min(ans, + x[r] - 2 * x[l])
        ans = min(ans, - x[l] + 2 * x[r])
print(ans)


Measured memory_bytes: 14096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,m;
	cin>>n>>m;
	cout << n*(n-1)/2+m*(m-1)/2;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main 
{

	public static void main(String[] args) 
	{
		Scanner scan = new Scanner(System.in);
		
		while(true)
		{
			int ruleNum = scan.nextInt();
			int packNum = scan.nextInt();
			ArrayList<Rule> rules = new ArrayList<Rule>();
//			ArrayList<Rule> permits = new ArrayList<Rule>();
//			ArrayList<Rule> denies = new ArrayList<Rule>();
			ArrayList<String> okpacks = new ArrayList<String>();
			
			if(ruleNum == 0 && packNum == 0)
			{
//				System.out.println("..... (terminated because of the limitation)");
				break;
			}
			
			for(int i = 0; i < ruleNum; i++)
			{
				String type = scan.next();
				if(type.equals("permit"))
				{
					rules.add(new Rule(scan.next(), scan.next(), 1));
				}
				
				if(type.equals("deny"))
				{
					rules.add(new Rule(scan.next(), scan.next(), 0));
				}
			}
			
			for(int i = 0; i < packNum; i++)
			{
				String ip1 = scan.next();
				String ip2 = scan.next();
				String content = scan.next();
				
				int status = 0;
				
				for(int r = 0; r < rules.size(); r++)
				{
					Rule rul = rules.get(r);
					
					if(rul.ip1matches(ip1) && rul.ip2matches(ip2))
					{
						//affected
						status = rul.type;
					}
				}
				
				if(status == 1)
				{
					okpacks.add(ip1 + " " + ip2 + " " + content);
				}
			}
			
			//print all okpacks
			System.out.println(okpacks.size());
			for(String pack : okpacks)
			{
				System.out.println(pack);
			}
		}
	}
	
	static class Rule
	{
		String ip1 = "";
		String ip2 = "";
		int type;
		
		public Rule(String ip1, String ip2, int type)
		{
			this.ip1 = ip1;
			this.ip2 = ip2;
			this.type = type;
		}
		
		boolean ip1matches(String enter)
		{
			for(int i = 0; i < ip1.length(); i++)
			{
				String curlet1 = ip1.substring(i, i+1);
				String curlet2 = enter.substring(i, i+1);
				
				if(!curlet1.equals(curlet2) && !curlet1.equals("?"))
				{
					return false;
				}
			}
			
			return true;
		}
		
		boolean ip2matches(String enter)
		{
			for(int i = 0; i < ip2.length(); i++)
			{
				String curlet1 = ip2.substring(i, i+1);
				String curlet2 = enter.substring(i, i+1);
				
				if(!curlet1.equals(curlet2) && !curlet1.equals("?"))
				{
					return false;
				}
			}
			
			return true;
		}
	}
}



Measured memory_bytes: 123712
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int dp[101][4][4][4];

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

  dp[0][3][3][3] = 1;
  rep(len,n) {
    rep(c1,4) {
      rep(c2,4) {
        rep(c3,4) {
          // 条件に当てはまるものがない場合はcontinue
          if (dp[len][c1][c2][c3] == 0) continue;
          rep(a,4) {
            // ダメな5つの条件をカットする
            if (a == 2 && c1 == 1 && c2 == 0) continue;
            if (a == 2 && c1 == 0 && c2 == 1) continue;
            if (a == 1 && c1 == 2 && c2 == 0) continue;
            if (a == 2 && c1 == 1 && c3 == 0) continue;
            if (a == 2 && c2 == 1 && c3 == 0) continue;

            // ダメな条件を抜けたら、aを足した文字列が作れる
            // S     = ...c3c2c1
            // nextS = .....c2c1a
            dp[len+1][a][c1][c2] += dp[len][c1][c2][c3];
            dp[len+1][a][c1][c2] %= mod;
          }
        }
      }
    }
  }

  int ans = 0;
  rep(c1,4) {
    rep(c2,4) {
      rep(c3,4) {
        ans += dp[n][c1][c2][c3];
        ans %= mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
a_list = list(map(int, input().split()))

ans = float("inf")
cost_list = [float("inf") for _ in range(N)]
for i in range(N):
    cost = 0
    for j in range(N):
        if i == 0:
            cost += a_list[j]
            cost_list[j] = a_list[j]
        else:
            tmp = cost_list[j]
            if tmp > a_list[- i + j]:
                cost_list[j] = a_list[- i + j]
                cost += a_list[- i + j]
            else:
                cost += tmp

    cost += x * i
    ans = min(ans, cost)
print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[N];
    for(int i = 0; i < N; i++)
    	cin >> a[i];
    int ans = 0;
    for(int i = 0; i < N; i++){
    	if(i == a[a[i]-1]-1) ans++;
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <math.h>
#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n;
	cin >> n;
	typedef pair<int,int> pair_int;
	vector<pair_int> town(n);
	vector<double> roads_length;
	rep(i,n) {
		int x_1,y_1;
		cin >> x_1 >> y_1;
		town.at(i).first = x_1;
		town.at(i).second = y_1;
		for(int j = 0; j < i; j++){
			int x_2 = town.at(j).first;
			int y_2 = town.at(j).second;
			double dis = sqrt( ((x_1-x_2)*(x_1-x_2)) + ((y_1-y_2)*(y_1-y_2)) );
			roads_length.push_back(dis);
		}
	}
	/*
	int n_factorial = n;
	for(int i = 1; i < n; i++){
		n_factorial *= i;
	}

	int c_deno = n_factorial / (n*(n-1));
	int c_nume = 1;	
	
	//r-1の階乗
	for(int i = 0; i < n-2; i++){
		c_nume *= roads_length.size() - i -1;
	}
	
	int combination = c_nume / c_deno;
	*/
	double sum = 0;
	for(int i = 0; i < roads_length.size(); i++){
		sum += roads_length.at(i);
	}

	double ans = sum * (2/(double)n);
	printf("%.10f\n", ans);
	
	
}

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

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n + 1);
  vector<ll> b(n);
  for (int i = 0; i <= n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] >= b[i]) {
      ans += b[i];
    } else {
      ans += a[i];
      b[i] -= a[i];
      if (a[i + 1] >= b[i]) {
	ans += b[i];
	a[i + 1] -= b[i];
      } else {
	ans += a[i + 1];
	a[i + 1] = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}



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

int main()
{
	int a, i, max,rupin;
	cin >> a;
	max = 0;
	int N1[a], N2[a];
	for (i = 0; i < a; i++) cin >> N1[i];
	for (i = 0; i < a; i++) cin >> N2[i];
	for (i = 0; i < a; i++) rupin += N1[i];
	rupin += N2[a - 1];
	max = rupin;
	for (i = a - 1; i > 0; i--) {
		rupin = rupin - N1[i] + N2[i - 1];
		if (rupin > max) max = rupin;
	}
	cout << max;
	return 0;
}

Measured memory_bytes: 256
var
	cnt,N,M,i,j,k,s:Longint;
	A:array[1..10,1..10]of Boolean;
	P:array[1..10]of Boolean;
	flag,now:Boolean;
begin
	read(N,M);
	for i:=1 to M do begin
		read(k);
		for j:=1 to k do begin
			read(s);
			A[i,s]:=True;
		end;
	end;
	for i:=1 to M do begin
		read(s);
		P[i]:=s=1;
	end;
	for i:=0 to (1<<N)-1 do begin
		flag:=True;
		for j:=1 to M do begin
			now:=False;
			for k:=1 to N do begin
				now:=now xor((((i>>(k-1))and 1)=1)and A[j,k]);
			end;
			if now xor P[j]then begin
				flag:=False;
				break;
			end;
		end;
		if flag then inc(cnt);
	end;
	writeln(cnt);
end.

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val aSorted = readInputLine().split(" ").map { it.toInt() }.sorted()
    
    var dupCnt = 0
    var before = -1
    
    for (a in aSorted) {
        if (a == before) {
            dupCnt++
        }
        before = a
    }
    
    println(N - dupCnt - (dupCnt % 2))
}

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


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

int main(){
    string s; cin >> s;
    int j = 0;
    int ans = 1;
    int siz = s.size();
    for(int i = 1; i < siz; i++){
    //cout <<" i is" <<  i << " j is" << j << " ans is" << ans << endl;
     if(j == 0){
        if(s[i] == s[i-1]){
            if(i == siz-1){
                ans--;
            }
            j = 1;
            i++;
        }
        ans++;
    }else{
        ans++;
        j = 0;
    }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#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 <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
 
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

long long A,B;
bool ok(long long key,long long index){
    string S = to_string(index);
    long long nagasa = S.size();
    if(index*A+nagasa*B > key) return true;
    else if(index*A+nagasa*B <= key) return false;
}
long long binary_search(long long key,long long size){
    //left,right,midはいずれもindex
    long long left = -1,right = size;
    while(right - left > 1){
        long long mid = left + (right-left)/2;
        long long hantei = ok(key,mid);
        if(hantei) right = mid;
        else left = mid;
    }
    if(left == -1)return 0;
    return left;
}

int main() {
    long long A,B,C,D;cin >> A >> B >> C >> D;
    long long ans = B;
    ans -= B/C;
    ans -= B/D;
    ans += B/(lcm(C,D));
    long long ansA = A-1;
    ansA -= (A-1)/C;
    ansA -= (A-1)/D;
    ansA += (A-1)/(lcm(C,D));

    cout << ans-ansA << endl;

    // PLEASE GIVE ME THE "ACCEPTED" !
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,m,d;
  cin>>n>>m>>d;
  if (d==0)cout<<fixed<<setprecision(10)<<(double)((double)(m-1)*(n-d)/(n*n))<<endl;
    else cout<<fixed<<setprecision(10)<<(double)((double)(m-1)*2*(n-d)/(n*n))<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    int n; cin >> n;
    cout << (1000 - n % 1000) % 1000 << endl;


    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3600
n,m=map(int,input().split())
h=list(map(int,input().split()))
a=[0 for i in range(m)]
b=[0 for i in range(m)]
for i in range(m):
  a[i],b[i]=map(int,input().split())

count=0
c=[[] for i in range(n)]
for i in range(m):
  c[a[i]-1].append(b[i]-1)
  c[b[i]-1].append(a[i]-1)
  
for i in range(n):
  max_h=0
  for j in range(len(c[i])):
    max_h=max(max_h, h[c[i][j]])
  if max_h < h[i]:
    count+=1
print(count)

Measured memory_bytes: 37332
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);

using namespace std;

int alternativo(int A,int B,int K){
    int valor = K,ind = 1;
    while(1){
        valor = ind*K;
        if(valor >= A && valor <= B){
            return 1;
        }
        else{
            if(valor > B) return 0;
            else ind++;
        }
    }
}

int main(){_
    int k,a,b;
    cin >> k;
    cin >> a >> b;
    cout << (alternativo(a,b,k) == 1 ? "OK" : "NG") << endl;
    return 0;
}


Measured memory_bytes: 3676
N = int(input())
XY = [[0]*2]*N
dis = 0
for i in range(N):
  XY[i] = [int(_) for _ in input().split()]
for i in range(N):
  Xi = XY[i][0]
  Yi = XY[i][1]
  for j in range(N):
    Xj = XY[j][0]
    Yj = XY[j][1]
    dis += ((Xi-Xj)**2 + (Yi-Yj)**2)**0.5

print(dis/N)

Measured memory_bytes: 3064
#include<iostream>
 #include<math.h>
 using namespace std ;
 int f(int x){
    int s=0;
    while(x>0) {
    s=x%10+s;
    x/=10;
	}
    return s;
	}
 int main(){
 	int N;
 	cin>>N;
    if(N%f(N)==0)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,W;
	cin>>n>>W;
	int weight,val;
	long long res=0;
	vector < long long > DP(W+1,0);
	for(int item=0;item<n;item++){
		cin>>weight>>val;
		for(int j=W;j>=0;j--){
			if(j>=weight)
				DP[j]=max(DP[j],DP[j-weight]+val);
		}
	}
	for(int i=0;i<W+1;i++){
		res=max(res,DP[i]);
	}
	cout<<res<<endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if((a + b) % 2 == 1){
    cout << (a + b) / 2 + 1 << endl;
  }
  else{
    cout << (a + b) / 2 << endl;
  }
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  string s;
  cin >> s;
  
  ll n = s.size();
  ll l,r;
  REP(i, n){
    if(s[i] =='A'){
      l = i;
      break;
    }
  }
  REP(i, n){
    ll j = n-1-i;
    if(s[j] =='Z'){
      r = j;
      break;
    }
  }  
  
  cout << r-l+1 << endl;
}

Measured memory_bytes: 720
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<string> vs;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

vvi c;

int main()
{
    rep(i, 3){
        vi in(3, 0);
        rep(j, 3) cin >> in[j];
        c.pb(in);
    }

    bool isOk = false;
    for(int a0 = 0; a0 <= min(min(c[0][0], c[0][1]), c[0][2]); a0++){
        int b0 = c[0][0] - a0; // zettai ok
        int b1 = c[0][1] - a0; // zettai ok
        int b2 = c[0][2] - a0; // zettai ok

        int a1 = c[1][0] - b0;
        if(a1 + b0 == c[1][0] && a1 + b1 == c[1][1] && a1 + b2 == c[1][2]){
            int a2 = c[2][0] - b0;
            if(a2 + b0 == c[2][0] && a2 + b1 == c[2][1] && a2 + b2 == c[2][2]){
                isOk = true;
            }
        }

    }
    if(isOk) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;

void solve() {
	int n; cin >> n;
	int k; cin >> k;
	vector<int> a(n + 1);
	vector<int> cnt_a(n + 1);
	set<int> diff_a;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		diff_a.insert(a[i]);
		cnt_a[a[i]]++;
	}
	//何種類削除する必要があるか算出
	int need = diff_a.size() - k;
	//記録した数値の出現数を昇順ソート
	//削除数を最小限に抑えたいため
	sort(cnt_a.begin(), cnt_a.end());
	int ans = 0;
	//削除する必要数分だけ出現数をカウント
	int slide = cnt_a.size() - diff_a.size();
	for (int i = slide; i < (slide + need); ++i) {
		ans += cnt_a[i];
	}
	cout << ans << endl;
	return;
}

int main() {
	solve();
  return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	int d[100];
	int count = 1;

	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> d[i];

	sort(d, d + N, greater<int>());

	for (int i = 1; i < N; i++)
	{
		if (d[i] != d[i - 1])
			count++;
	}

	cout << count << endl;

	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int x;cin>>x;
    if(x==0)cout<<1<<endl;
    else cout<<0<<endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ini(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll int64_t
#define inf LLONG_MAX

void solve()
{
    ll n,l,r,d,i,ans;
    cin>>l>>r>>d;

    ans=0;n=d;
    for(i=1;;i++)    
    {
        if(n>=l and n<=r)   ans++;
        if(n>r) break;
        n+=d;
    }
    
    cout<<ans;

}


signed main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //ll tt;    cin>>tt;    while(tt--)
    {
        solve();
     }
    cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
        
        
return 0;
}

Measured memory_bytes: 3800
#import<bits/stdc++.h>
using namespace std;
long L,R,D,M=998244353,l,r,d=1,z,A['   '];
map<long,int>m;
main(){
	cin>>l>>r;
	for(m[l]=1;l--;d=d*10%M)A[l]=(z+=d)%=M;
	for(;cin>>L>>R>>D;cout<<z<<" "){
		z=(z+D*(A[--L]-A[R]))%M;
		auto t=m.lower_bound(l=L);
		for(d=t->second;z=(z-t->second*(A[l]-A[r=min(R,t->first)])%M+M)%M,r<R;t=m.erase(t))l=t->first;
		m[L]=d;
		m[R]=D;
	}
}


Measured memory_bytes: 17672
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <tuple>

using namespace std;

int main(int argc, char* argv[]) {
	while (true) {
		int n = -1, m = -1, a, b, c;
		cin >> n >> m;
		if (n <= 0 || m <= 0) break;
		vector<tuple<int, int, int>> edges;
		vector<vector<int>> dist(n, vector<int>(n, 1 << 29));
		for (int i = 0; i < m; ++i) {
			cin >> a >> b >> c;
			--a, --b;
			edges.emplace_back(make_tuple(a, b, c));
			dist[a][b] = c;
			dist[b][a] = c;
		}
		for (int k = 0; k < n; ++k) {
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < n; ++j) {
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
		int ans = 0;
		for (int i = 0; i < m; ++i) {
			int a = get<0>(edges[i]), b = get<1>(edges[i]), c = get<2>(edges[i]);
			ans += dist[a][b] < c;
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main(void){
    string s;
    cin >> s;
    
    reverse(s.begin(), s.end());
    
    int i = 0;
    while(i < s.length()){
        if(s.substr(i, 7) == "remaerd"){
            i += 7;
        }else if(s.substr(i, 6) == "resare"){
            i += 6;
        }else if(s.substr(i, 5) == "maerd" || s.substr(i, 5) == "esare"){
            i += 5;
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
    
    return 0;
}


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

int dp[10000010];

int main(){
    int n;
    cin>>n;
    
    int sum=0;
    set<int> S;
    for(int i=1;;i++){
        sum+=i;
        S.insert(i);
        if(sum>=n){
            int diff=sum-n;
            if(diff) S.erase(diff);
            for(auto e : S) cout<<e<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3768
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 998244353;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

ll modpow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = modpow(a, b/2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * modpow(a, b-1)) % MOD;
    }
}

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

    int n; cin>>n;
    vector<int> d(n);
    int cnt0 = 0;
    vector<ll> cnt(n, 0);
    for(int i=0; i<n; i++){
        cin>>d[i];
        cnt[d[i]]++;
    }

    int dmax = *max_element(d.begin(), d.end());

    if(d[0] != 0){
        cout << 0 << endl;
        return 0;
    }

    if(1 < cnt[0]){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    for(int i=1; i<=dmax; i++){
        int pre = i - 1;
        int cur = i;
        ans *= modpow(cnt[pre], cnt[cur]);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    vector<ll> T(2), A(2), B(2);
    for(int i = 0; i < 2; ++i)  cin >> T[i];
    for(int i = 0; i < 2; ++i){
        cin >> A[i];
        A[i] *= T[i];
    }
    for(int i = 0; i < 2; ++i){
        cin >> B[i];
        B[i] *= T[i];
    }
    if(A[0] + A[1] == B[0] + B[1]){
        cout << "infinity\n";
        return 0;
    }
    if(A[0] + A[1] < B[0] + B[1])   swap(A, B);
    ll foo = B[0] - A[0];
    if(foo < 0){
        cout << 0 << endl;
        return 0;
    }
    ll bar = A[0] + A[1] - B[0] - B[1];
    ll ans = ((foo - 1) / bar + 1) * 2 - 1;
    if(foo % bar == 0)  ++ans;
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void){
char str[1010];
int i,sum;
scanf("%s",str);
while(str[0]!='0'){
i=0;
sum=0;
while(str[i]){
sum+=str[i]-'0';
i++;
}
printf("%d\n",sum);
scanf("%s",str);
}
return 0;
}

Measured memory_bytes: 536
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
sushi = [tuple(map(int, input().split())) for _ in range(N)]

sushi.sort(key=lambda x: x[1], reverse=True)

used = [0 for _ in range(N)]
dup = []
deli = 0

for i in range(K):
    t, d = sushi[i]
    if used[t - 1]:
        dup.append(d)
    used[t - 1] = 1
    deli += d

vari = sum(used)
sat = vari**2 + deli

dup.sort(reverse=True)

for i in range(N - K):
    if not dup:
        break
    t, d = sushi[K + i]
    if used[t - 1]:
        continue
    used[t - 1] = 1
    deli -= dup.pop()
    deli += d
    vari += 1
    sat = max(sat, vari**2 + deli)

print(sat)

Measured memory_bytes: 18196
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;
vector<int> color_max;

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

	for(int i=0; i<N; i++)
	{
		cin>>A[i];
	}
	
	
	for(int i=0; i<N; i++)
	{
		if(color_max.empty() || color_max[0]>=A[i])
		{
			color_max.insert(color_max.begin(),A[i]);
		}
		else
		{
			auto pos = lower_bound(color_max.begin(),color_max.end(),A[i]);
			//cout<<"distance:"<<distance(color_max.begin(),pos)<<endl;
			color_max[distance(color_max.begin(),pos) - 1] = A[i];
		}
		/*
		for(int i=0; i<color_max.size(); i++)
		{
			cout<<color_max[i]<<endl;
		}
		cout<<endl;
		*/
	}
	
	cout<<color_max.size()<<endl;
	return 0;
}

Measured memory_bytes: 1276
#include<stdio.h>

int main()
{
	int a,b;
	scanf("%d %d", &a, &b);
	int n;
	scanf("%d", &n);
	if(a < b)
	{
		a = b;
	}
	printf("%d\n", (n / a) + (n % a != 0));
	return 0;
}

Measured memory_bytes: 1732
ls = list(map(int, list(input().split()[0])))
N = len(ls)

cnt_0 = 0
cnt_1 = 0
ls_0 = ls.copy()
ls_1 = ls.copy()
for i in range(N):
    if i == 0:
        if ls_0[i] == 0:
            pass
        else:
            ls_0[i] = 0
            cnt_0 += 1
    else:
        if i % 2 == 0:
            if ls_0[i] == 0:
                pass
            else:
                ls_0[i] = 0
                cnt_0 += 1
        else:
            if ls_0[i] == 1:
                pass
            else:
                ls_0[i] = 1
                cnt_0 += 1

for i in range(N):
    if i == 0:
        if ls_1[i] == 1:
            pass
        else:
            ls_1[i] = 1
            cnt_1 += 1
    else:
        if i % 2 == 0:
            if ls_1[i] == 1:
                pass
            else:
                ls_1[i] = 1
                cnt_1 += 1
        else:
            if ls_1[i] == 0:
                pass
            else:
                ls_1[i] = 0
                cnt_1 += 1

print(min([cnt_0, cnt_1]))

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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;


int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int h,w,m;
    cin>>h>>w>>m;
    set<pair<int,int>> set;
    vector<pair<int,int>> x(w),y(h);
    for(int i=0;i<w;++i)x[i].second = i;
    for(int i=0;i<h;++i)y[i].second = i;
    for(int i=0;i<m;++i){
        int xi,yi;
        cin>>yi>>xi;
        xi--;yi--;
        x[xi].first++;
        y[yi].first++;
        set.insert({yi,xi});
    }
    sort(x.rbegin(),x.rend());
    sort(y.rbegin(),y.rend());
    int ret = 0;
    for(auto && curx : x){
        for(auto && cury : y){
            int d = set.count({cury.second,curx.second});
            ret = max(ret,curx.first + cury.first - d);
            if(d == 0)break;
        }
    }
    cout << ret << endl;
    return 0;
    
}


Measured memory_bytes: 21948
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in(),M=in();
	vector<int> A(N,1),F(N,0);
	F[0]=1;
	LOOP(M){
		int x=in()-1,y=in()-1;
		if(F[x]) F[y]=1;
		A[x]--;
		if(!A[x]) F[x]=0;
		A[y]++;
	}
	out(count(ALL(F),1));
	return 0;
}


Measured memory_bytes: 1024
s=str(input())
a=0
k=s.count('K')
u=s.count('U')
p=s.count('P')
c=s.count('C')
while True:
    if k==0 or u==0 or p==0 or c==0:
        break
    else:
        a+=1; k-=1; u-=1; p-=1; c-=1
print(a)


Measured memory_bytes: 5556
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  string s;
  cin >> s;
  cout << s.substr(0,3) << endl;

  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる

int pl;
int mi;

ll joupl(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = joupl(N, P/2);return t*t % pl;
    }return (N * joupl(N, P-1)) % pl;}

ll joumi(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = joumi(N, P/2);return t*t % mi;
    }return (N * joumi(N, P-1)) % mi;}



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

  int n;
  string s;
  cin>>n>>s;

  int ni=0;
  rep(i,n){
    if(s[i]=='1') ni++;
  }

  pl=ni+1;
  mi=ni-1;

  ll p=0;
  rep(i,n){
    p*=2;
    if(s[i]=='1') p++;
    if(p>=pl) p%=pl;
  }

  ll m=0;
  if(mi>0){
    rep(i,n){
      m*=2;
      if(s[i]=='1') m++;
      if(m>=mi) m%=mi;
    }
  }

  rep(i,n){
    ll x,y;
    if(s[i]=='1') {
      if(ni==1) {
        cout << 0 << endl;
        continue;
      }
      x=m-joumi(2,n-1-i)+mi;
      y=x%mi;
    }
    if(s[i]=='0') {
      if(ni==0) {
        cout << 1 << endl;
        continue;
      }
      x=p+joupl(2,n-1-i);
      y=x%pl;
    }
    
    int cnt=1;
    while(y>0) {
      bitset<100> b=y;
      int c=b.count();
      y%=c;
      cnt++;
    }
    cout << cnt << endl;
  }

}

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

int main(){
  int a[3];
  for(int i = 0; i<3;i++){
    cin >> a[i];
  }
  // int ans[6];
  int ans = 100000;
  for(int i = 0; i<3;i++){
    int buf = a[i];
    for(int j = 0; j<3;j++){
      if(j == i){
        continue;
      }else{
        // cout << i << j << endl;
        int buf2 = abs(a[j] - a[i]) + abs(a[3-i-j]- a[j]);
        // cout << buf2 << endl;
        ans = min(buf2 , ans);
      }
      // ans = min(2, 3);

    }
  }

  cout << ans << endl;


}


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

int main() {
	const int MAX_H = 10;
	int H, board[MAX_H][5];
	int res;
	bool updated;
	bool zeroseq;
	int seq;

	while(true){
		scanf("%d", &H);
		if (H == 0) {
			break;
		}
		for (int i = 0;i < H;i++) {
			for (int j = 0;j < 5;j++) {
				scanf("%d", &board[i][j]);
			}
		}

		updated = true;
		res = 0;
		while (updated) {
			updated = false;
			for (int i = 0;i < H;i++) {
				seq = 1;
				for (int j = 0;j < 5;j++) {
					if (j == 4 || board[i][j] != board[i][j + 1]) {
						if (seq >= 3) {
							updated = true;
							res += board[i][j] * seq;
							for (int k = 0;k < seq;k++) {
								board[i][j - k] = 0;
							}
						}
						seq = 1;
					}
					else if (j + 1 < 5 && board[i][j] == board[i][j + 1] && board[i][j] != 0) {
						seq++;
					}
				}
			}
			for (int j = 0;j < 5;j++) {
				zeroseq = true;
				for (int i = 0;i < H;i++) {
					if (board[i][j] == 0 && !zeroseq) {
						for (int k = i;k > 0;k--) {
							board[k][j] = board[k - 1][j];
						}
						board[0][j] = 0;
					}
					else {
						zeroseq = false;
					}
				}
			}
		}

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

	return 0;
}

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

int N;
long long K;
vector<long long> a;
 
int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }

    long long res = 0;
    for (int i = N-1; i >= 0; i--){
        res = 2*A[i] - res;
    }
    res = res/2;
    cout << res << endl;
    for (int i = 0; i < N-1; i++)
    {
        res = 2*A[i] - res;
        cout << res << endl;
    }
}

Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

int main(){

    int n,m,Q;
    cin >> n >> m >> Q;
   

    int city[n+1][n+1];
    for(int i = 0;i < n+1;i++){
        for(int j = 0;j < n+1;j++){
            city[i][j] = 0;
        }
    }


    int left,right;

    for(int i = 0;i < m;i++){//L
        cin >> left >> right;
        city[left][right]++;
    }

    /*REP(i,n+1){
        REP(j,n+1){
            cout << city[i][j] << " ";
        }
        cout << endl;
    }*/

    //cout << endl << endl;


    REP(i,n+1){
        REP(j,n){
            city[i][j+1] += city[i][j]; 
        }
    }

    /*REP(i,n+1){
        REP(j,n+1){
            cout << city[i][j] << " ";
        }
        cout << endl;
    }*/

    int p,q;

    for(int i = 0;i < Q;i++){

        int ans = 0;
        cin >> p >> q;
        //cout << p << " " << q << endl;

        for(int j = p;j < q+1;j++){

            ans+= city[j][q]-city[j][p-1];
            //cout << city[j][q-1] << endl;
        }

        cout << ans << endl;
    }


   
    return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b)
{
    return b ? gcd(b, a % b) : a;
}
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main()
{
    // cout << fixed << setprecision(5);
    int n;
    cin >> n;
    int a;
    rep(i, n)
    {
        cin >> a;
        if (a % 2 == 0)
        {
            if (a % 3 == 0 || a % 5 == 0)
            {
                continue;
            }
            else
            {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    // Failed to predict input format
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
  char S[200001];
  scanf("%s",S);
  int l=strlen(S);
  int P,Q;
  for(int i=0;;i++){
    if(S[i]=='A'){
      P=i;break;
    }
  }
  for(int i=l-1;;i--){
    if(S[i]=='Z'){
      Q=i;break;
    }
  }
  printf("%d\n",Q-P+1);
  return 0;
}


Measured memory_bytes: 384
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    bs :: VU.Vector Int
    bs = VU.accum (+) (VU.replicate n 0) . map (flip (,) 1 . pred) $ as
  VU.mapM_ print bs

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


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

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

using namespace std;

inline int toIndex(char dir) {
  switch(dir) {
  case 'N':
    return 0;
  case 'W':
    return 1;
  case 'S':
    return 2;
  case 'E':
    return 3;
  defalut:
    assert(false);
  }
}

void compute(string s) {
  bool find[4];
  memset(find,false,sizeof find);
  rep(i,(int)s.size()) {
    find[toIndex(s[i])] = true;
  }
  if( ( ( find[0] && find[2] ) || ( !find[0] && !find[2] )  ) && ( ( find[1] && find[3] ) || ( !find[1] && !find[3] )  ) ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
}

int main() {
  string s;
  cin >> s;
  compute(s);
  return 0;
}


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

int main(void) {
  string T;
  cin >> T;
  for (char c : T) {
    if (c == '?') {
      cout << "D";
    } else {
      cout << c;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3752
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;
int MOD = 1000000007;

signed main(){
    int x;
    cin >> x;
    int s = 0;
    rep(i,1000000){
        s += i;
        if(x <= s){
            cout << i << endl;
            return 0;
    }
    }

    return 0;   
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a
// rm -r -f test;oj dl http://arc060.contest.atcoder.jp/tasks/arc060_a

Measured memory_bytes: 256
stand = []
emp = [100]
ans = []

line = input().split()
x = int(line[0])
if int(line[1]) == 0:
  ans = x
  
elif int(line[1]) != 0:
  line2 = input().split()
  for i in range(-100,201):
    stand.append(int(i))
    
  for i in line2:
    if int(i) in stand:
      stand.remove(int(i))
  for i in stand:
    candi = abs(x - i)
    if candi < emp[0]:
      emp[0] = candi
      ans = i

print(ans)

Measured memory_bytes: 9220