akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

struct Card{
  char suit;
  char value;
};

void bubble(struct Card A[], int n){
  int i, j;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    for ( j = n-1; j >= i+1; j-- ){
      if ( A[j].value < A[j-1].value ){
	t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int n){
  int i, j, mini;
  struct Card t;
  for ( i = 0; i < n; i++ ){
    mini = i;
    for ( j = i; j < n; j++ ){
      if ( A[j].value < A[mini].value ) mini = j;
    }
    t = A[i]; A[i] = A[mini]; A[mini] = t;
  }
}

void print(struct Card A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( i ) printf(" ");
    printf("%c%c", A[i].suit, A[i].value);
  }
  printf("\n");
}

int isStable(struct Card C1[], struct Card C2[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( C1[i].suit != C2[i].suit ) return 0;
  }
  return 1;
}

int main(){
  struct Card C1[101], C2[101];
  int n, i;
  char ch;

  scanf("%d\n", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%c%c ", &C1[i].suit, &C1[i].value);
  }

  for ( i = 0; i < n; i++ ) C2[i] = C1[i];

  bubble(C1, n);
  selection(C2, n);

  print(C1, n);
  printf("Stable\n");
  print(C2, n);
  if ( isStable(C1, C2, n) ){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, std::vector<long long> A){
  ll xr=0;
  REP(N){
    xr^=A[i];
  }
  if(xr==0){
    cout<<0<<endl;
    return;
  }
  xr=0;
  FOR(i,2,N){
    xr^=A[i];
  }
  bitset<63> xrbit(xr);
  ll sum=A[0]+A[1];
  ll ans0=0,ans1=0;
  bool x=false;
  REP(63){
    ll tmp=(sum-ans0-ans1)%(1LL<<(i+1));
    if(tmp&&xrbit[i]){
      ans1|=(1LL<<i);
      x=false;
    }else if(tmp&&!xrbit[i]){
      if(x){
        ans1|=(1LL<<(i-1));
        ans0|=(1LL<<(i-1));
        x=true;
      }else{
        cout<<-1LL<<endl;
        return;
      }
    }else if(!tmp&&!xrbit[i]){
      x=true;
    }else{
      if(x){
        ans1|=(1LL<<(i-1));
        ans0|=(1LL<<(i-1));
        ans1|=(1LL<<i);
        x=false;
      }else{
        cout<<-1LL<<endl;
        return;
      }
    }
  }
  if(ans0+ans1==A[0]+A[1]&&ans0<=A[0]){
    Rev(i,63){
      ll ii=(1LL<<i);
      if((ans1&ii)&&!(ans0&ii)){
        if(ans0+ii<=A[0]){
          ans1^=ii;
          ans0^=ii;
        }
      }
    }
    if(ans0==0)cout<<-1<<endl;
    else cout<<A[0]-ans0<<endl;
  }else{
    cout<<-1LL<<endl;
  }
}

int main(){
  cout<<setprecision(1000);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 3668
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def divisors(n):
    lower = []
    upper = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n // i)

    lower.extend(reversed(upper))
    return lower


def main():
    N = int(readline())

    ans = 0
    for n in range(1, N + 1, 2):
        if len(divisors(n)) == 8:
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int getRank(float value)
{
	if( value >= 1.1 ) return 0;
	else if( value >= 0.6 ) return 1;
	else if( value >= 0.2 ) return 2;
	else return 3;
}

int main()
{
	int leftRank[4] = {0};
	int rightRank[4] = {0};
	float left, right;
	while( scanf("%f%f", &left, &right) != EOF )
	{
		leftRank[getRank(left)]++;
		rightRank[getRank(right)]++;
	}
	for(int i = 0; i < 4; i++)
	{
		printf("%d %d\n", leftRank[i], rightRank[i]);
	}
	return (0);
}

Measured memory_bytes: 1208
n = int(input())
x = map(int, input().split())
y = map(int, input().split())

x_y = [abs(xi - yi) for xi, yi in zip(x, y)]
p1 = sum(x_y)
p2 = sum(i ** 2 for i in x_y) ** (1 / 2)
p3 = sum(i ** 3 for i in x_y) ** (1 / 3)
p_inf = max(x_y)

print(p1)
print(p2)
print(p3)
print(p_inf)

Measured memory_bytes: 6788
#include<iostream>
#include <stdlib.h> 
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
	int a[105][105],b[105],c[105];
	memset(c,0,105*sizeof(int));
	int n,m;
	while(cin>>n>>m)//???????°±?????\??????????¨????
	{
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				cin>>a[i][j];
		for(int i=1;i<=m;i++)
			cin>>b[i];
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			
			{
				c[i]+=a[i][j]*b[j];
			}
		}
		for(int i=1;i<=n;i++)
			cout<<c[i]<<endl;



	
	
	
	
	}









}
	

Measured memory_bytes: 3132
n = input()
a = list(map(int, input().split()))

while len(a) > 1:
    idx = 0
    m = a[0]
    for i in range(len(a)):
        aa = a[i]
        if aa > 0 and aa < m:
            idx = i
            m = a[idx]
    for i in range(len(a)):
        if i != idx:
            a[i] = a[i] % m
    a = [aa for aa in a if aa > 0]
print(a[0])

Measured memory_bytes: 14252
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
vector<int> G[200000];
bool del[200000];
int main() {
	int n, m; cin >> n >> m;
	string s; cin >> s;
	rep(i, m) {
		int u, v; cin >> u >> v; u--; v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	fill(del, del + n, false);
	queue<int> q;
	rep(i, n) {
		bool a = false, b = false;
		int len = G[i].size();
		rep(j, len) {
			int v = G[i][j];
			if (s[v] == 'A')a = true;
			if (s[v] == 'B')b = true;
		}
		if (!a || !b) {
			q.push(i); del[i] = true;
		}
	}
	while (!q.empty()) {
		int x = q.front(); q.pop();
		int len = G[x].size();
		rep(j, len) {
			int v = G[x][j];
			if (del[v])continue;
			int k = G[v].size();
			bool a = false, b = false;
			rep(l, k) {
				int vv = G[v][l];
				if (del[vv])continue;
				if (s[vv] == 'A') {
					a = true;
				}
				else b = true;
			}
			if (!a || !b) {
				del[v] = true; q.push(v);
			}
		}
	}
	bool out = false;
	rep(i, n) {
		if (del[i])continue;
		bool a = false, b = false;
		q.push(i); del[i] = true;
		while (!q.empty()) {
			int x = q.front(); q.pop();
				if (s[x] == 'A')a = true;
				else b = true;
			int len = G[x].size();
			rep(j, len) {
				int v = G[x][j];
				if (del[v])continue;
				del[v] = true; q.push(v);
			}
		}
		if (a&&b)out = true;
	}
	if (out)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 11140
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#include <math.h>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    int N;
    cin >> N;
    int d[N];
    for(int i=0;i<N;i++) cin >> d[i];
    sort(d,d+N);
    cout << d[N/2] - d[N/2-1] << endl;
    
}

Measured memory_bytes: 640
from sys import stdin


def main():
    A, B, C, X, Y = [int(x) for x in stdin.readline().rstrip().split()]
    if A + B <= C * 2:
        print(A * X + B * Y)
    elif X < Y:
        spam = C * 2 * X
        if B < C * 2:
            print(B * (Y - X) + spam)
        else:
            print(C * 2 * (Y - X) + spam)
    else:
        spam = C * 2 * Y
        if A < C * 2:
            print(A * (X - Y) + spam)
        else:
            print(C * 2 * (X - Y) + spam)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
long long n, k, ans = 0;

int main()
{
	scanf("%lld %lld", &n ,&k);
	if(k == 0) ans = n * n;
	else
	{
		for(int i = k + 1; i <= n; i++)
		{
			ans += (n / i) * (i - k);
			ans += max(0LL, n % i - k + 1);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll K;
    int N;
    cin >> K >> N;
    ll A[N];
    
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll e[N];
    for (int i = 0; i < N - 1; i++) {
        e[i] = A[i + 1] - A[i];
    }
    e[N - 1] = K - A[N - 1] + A[0];
    ll v = e[0];
    for (ll i : e) {
        v = max(i, v);
    }
    cout << K - v << "\n";
    return 0;
}

Measured memory_bytes: 3328
import java.util.*;
public class Main {
	final int INF = Integer.MAX_VALUE / 4;

	private void doit(){
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		
		int n = Integer.parseInt(a);
		int [][] data = new int[n][2];
		int [][] memo = new int[n][n];
		for(int i=0; i < n; i++){
			Arrays.fill(memo[i], INF);
			memo[i][i] = 0;
		}
		for(int i=0; i < n; i++){
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
		}
		for(int i = 0; i < n-1; i++){
			memo[i][i+1] = data[i][0] * data[i][1] * data[i+1][0] * data[i+1][1];
		}
		for(int k = 2; k < n; k++){
			for(int i =0; i + k < n; i++){
				for(int j = i; j < i + k; j++){
					int value2 = (data[i][0] * data[j][1]) * (data[j+1][0] * data[i+k][1]);
					int value = memo[i][j] + memo[j+1][i+k] +value2;
					memo[i][i+k] = Math.min(memo[i][i+k], value);
				}
			}
		}
		//			//debug
		//			System.out.println("D= ");
		//			for(int i=0; i < n; i++){
		//				for(int j = 0;  i+ j < n;j++){
		//					System.out.print(memo[j][i+j] + " ");
		//				}
		//				System.out.println();
		//			}

		System.out.println(memo[0][n-1]);
	}

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

Measured memory_bytes: 12000
N, W = map(int, input().split())
v_w = [list(map(int, input().split())) for _ in range(N)]
dp = [([0]*(W+1)) for _ in range(N+1)]

for item in range(1, N+1):
    value = v_w[item-1][0]
    weight = v_w[item-1][1]
    for j in range(W+1):
        if j < weight:
            dp[item][j] = max(dp[item][j], dp[item-1][j])
        else:
            dp[item][j] = max(dp[item][j], dp[item-1][j], dp[item-1][j-weight]+value)

print(dp[N][W])


Measured memory_bytes: 25520
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        siz.assign(sz_, 1LL); // assign: 再代入
        par.resize(sz_);      // resize: 再確保
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
};

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;
}

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

////////////////////////////////////////

const ll mod = 1e9+7;

////////////////////////////////////////
ll fib(ll n)
{
    ll num1 = 0,
       num2 = 1,
       tmp = 1;
    for (int i = 1; i < n; i++)
    {
        tmp = num1 + num2;
        num1 = num2;
        num2 = tmp;
    }
    return tmp;
}
int main()
{
    int N, M;
    cin >> N >> M;

    vector<int> oks(N+1,true);
    REP(i,M){
        int a; cin >> a;
        oks[a]=false;
    }

    vector<ll> dp(N+1);
    dp[0]=1;
    
    REP(now,N){
        for(int next=now+1; next<=min(N,now+2); ++next){
            if(oks[next]){
                dp[next]+=dp[now];
                dp[next]%=mod;
            }
        }
    }

    cout << dp[N] << endl;

    return 0;
}

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


int main()
{
  long long n,k;
  scanf("%lld%lld",&n,&k);
 
  long long tmp=n%k;
  
  if(tmp<llabs(tmp-k))
     {
       printf("%lld\n",tmp);
     }    
     else
     {
       printf("%lld\n",llabs(k-tmp));
     }
  
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{
    int n, a [100], i, j, b [100000], k, s;

    scanf("%d", &n);

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

    for (i = 0; i < n; i ++) {
        for (j = i + 1; j < n; j ++) {
            if (a [j] < a [i]) {
                a [j] ^= a [i];
                a [i] ^= a [j];
                a [j] ^= a [i];
            }
        }
    }

    int cnt = 0;
    for (i = 0; i < n; i ++) {
        for (j = i + 1; j < n; j ++) {
            if (a [i] != a [j]) {
                s = a [i] + a [j];
                for (k = j + 1; k < n; k ++) {
                    if (a [k] < s && a [k] != a [j]) {
                    cnt ++;
                    }
                }
            }
        }
    }

    printf("%d", cnt);
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const Int MOD = 1000000007;
Int modpow(Int x, Int y) {
    if (y == 0) return 1;
    if (y % 2 == 0) return modpow(x*x%MOD, y/2);
    return x*modpow(x, y-1)%MOD;
}
int main() {
    Int N, K; cin >> N >> K;
    vector<Int> cnt(K + 1);
    for (int i = K; i >= 1; i--) {
        Int t = modpow(K / i, N);
        for (int j = i + i; j <= K; j += i) {
            t = (t - cnt[j] + MOD) % MOD;
        }
        cnt[i] = t;
    }
    Int ans = 0;
    for (int i = 1; i <= K; i++) {
        ans = (ans + i * cnt[i]) % MOD;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3964
// https://atcoder.jp/contests/abc141/tasks/abc141_b
#include <bits/stdc++.h>
using namespace std;

int main(void){
  string S;
  cin >> S;
  string N = "UHFYEEF";
  string ans = "Yes";
  for (int i = 0; i < S.size(); i++){
    string temp;
    if (i % 2 == 0){
      temp = "RUD";
    }else{
      temp = "LUD";
    }
    if (temp.find(S[i]) == std::string::npos){
      ans = "No";
    }
  }

  cout << ans << endl;
}

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

int main() {
	int H, W, D;
	cin >> H >> W >> D;
	vector<vector<int>> A(H, vector<int>(W));
	map<int,pair<int,int>> mp;
	for(int i=0;i<H;i++) {
		for(int j=0;j<W;j++) {
			cin >> A[i][j];
			mp[A[i][j]] = make_pair(i, j);
		}
	}
	// 累積和
	vector<int> wa(H*W+1, 0);
	for(int i=1;i<=H*W;i++) {
		if(i+D <= H*W) wa[i+D] = wa[i] + (abs(mp[i].first - mp[i+D].first) + abs(mp[i].second - mp[i+D].second));
	}
	int Q;
	cin >> Q;
	for(int i=0;i<Q;i++) {
		int l, r;
		cin >> l >> r;
		cout << wa[r] - wa[l] << endl;
	}
}

Measured memory_bytes: 7424
using System;

class Program
{
	static void Main(string[] args)
	{
		int i;

		string[] strInput = Console.ReadLine().Split(' ');
		int n = int.Parse(strInput[0]);
		int k = int.Parse(strInput[1]);

		int[] p = new int[n];

		strInput = Console.ReadLine().Split(' ');
		for(i = 0; i < n; i++)
        {
			p[i] = int.Parse(strInput[i]);
        }

		int result = 0;
		Array.Sort(p);
		for(i = 0; i < k; i++)
        {
			result += p[i];
        }

		Console.WriteLine(result);

		return;
	}
}

Measured memory_bytes: 27748
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<pll,ll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define piii pair<pii, int>
#define pb push_back
const ll llinf = 2e18 + 7;
const int inf = 2e9 + 7;
const ll mod = 1e9 + 7;
const ll N = 1e6 + 7;
const ld pi = 3.14159265358979; 

void solve() {
    int n,a;
    cin>>n;
    vector<int> isprime(N,1);
    vector<int> prime(N),arr;
    for(int i=0;i<n;i++) {
        cin>>a;
        prime[a]++;
    }
    for(int i=0;i<N;i++) {
        if(prime[i]>=1) arr.pb(i);
    }
    // sort(arr.begin(),arr.end());
    int cnt =0 ;
    for(int i=0;i<arr.size();i++) {
        if(isprime[arr[i]]) {
            if(prime[arr[i]]==1)
            cnt++;
            for(int j=2*arr[i];j<N;j+=arr[i]) {
                isprime[j]=0;
            } 
        }
    }
    cout<<cnt;
}

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin>>t;
    while(t--) {
        solve();
        // cout<<"\n";
    }
    return 0; 

}


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

#define FOR(x,y,z) for(int x=y,x##_=z;x<=x##_;++x)
#define DOR(x,y,z) for(int x=y,x##_=z;x>=x##_;--x)
#define FOR_(x,y,z,s) for(int x=y,x##_=z;x<=x##_;x+=s)
#define FOR__(x,y,z) for(int x=y,x##_=z;x<=x##_;x<<=1)
#define EOR(x,y) for(int x##_=head[x],y=edge[x##_].e;x##_;y=edge[x##_=edge[x##_].to].e)
#define EGOR(x,y,z) for(int x##_=head[x],y=edge[x##_].e,z=edge[x##_].c;x##_;y=edge[x##_=edge[x##_].to].e,z=edge[x##_].c)

#define clr(x,y) memset(x,y,sizeof(x))
#define szf(x) sizeof(x)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)

#define read2(x,y) read(x),read(y)
#define read3(x,y,z) read(x),read(y),read(z)
#define read4(x,y,z,w) read3(x,y,z),read(w)
#define reads(str) sf("%s",str)

#define ts (*this)
#define sf scanf
#define pf printf

#define ll long long
#define ull unsigned long long
#define db double
#define ct clock_t
#define ck() clock()
#define rd rand()
#define rmx RAND_MAX
#define RD T*(rd*2-rmx)


using namespace std;

template<class T>bool tomin(T &x,T y){return x>y?x=y,1:0;}
template<class T>bool tomax(T &x,T y){return x<y?x=y,1:0;}
template<class T>void read(T &x){
	char c;
	x=0;
	int f=1;
	while(c=getchar(),c<'0'||c>'9')if(c=='-')f=-1;
	do x=(x<<3)+(x<<1)+(c^48);
	while(c=getchar(),c>='0'&&c<='9');
	x*=f;
}

const db Pi=acos(-1);
int main(){
	srand(time(NULL));
	int n,a,b;
	read3(n,a,b);
	pf("%d",min(n*a,b));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

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

    int ans = 0;
    for(int i=0;i<n;i++)
    {
        if( i+2 < n )
        {
            if( s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C' )
                ans++;
        }
    }
    cout<<ans,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>

using namespace std;


int main(){
	int r, n_ang;
	int ang=0;
	double x=0, y=0;

	while(1){
		scanf("%d,%d", &r, &n_ang);
		if(r==0 && n_ang==0){
			break;
		}else{
			y += r * cos(M_PI*ang/180);
			x += r * sin(M_PI*ang/180);
		}
		ang += n_ang;

	}

	cout << (int)x << endl << (int)y << endl;

	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int ull;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

ll gcd(ll a,ll b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

ll has(string x)
{
	ll h1=0,h2=0;
	x=to_lower(x);
	for (char a: x)
	{
		h1*=bases[0];
		h1+=a-'a';
		h1%=bases[3];
		h2*=bases[1];
		h2+=a-'a';
		h2%=bases[4];
	}
	return h1*(MOD+13893829)+h2;
}

const int N=300010;
int n,h[N],dp1[N],dp2;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back((raand()%MOD+13893829)%MOD);
	cin>>n;
	dp2=1;
	for (int i=0;i<n;++i)
	{
		int a;
		cin>>a;
		h[i]=a;
		if (i && h[i]==h[i-1]) continue;
		dp2=add(dp2,dp1[a]);
		dp1[a]=dp2;
	}
	cout<<dp2;
}




Measured memory_bytes: 1792
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
c = Counter(a)
m = inp()
b = inpl()
d = Counter(b)
for key in list(d):
    if c[key] < d[key]:
        print('NO')
        break
else:
    print('YES')

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = 0;
  if (a <= b) ans += a;
  else ans += b;
  if (c <= d) ans += c;
  else ans += d;
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
L = [list(map(int,input().split())) for i in range(N)]
ans = 0
import math
def d(x1,x2):
    return math.sqrt((x1[0]-x2[0])**2+(x1[1]-x2[1])**2)
for i in range(N-1):
    for j in range(i+1,N):
        ans += d(L[i],L[j])*2/N
print(ans)

Measured memory_bytes: 38384
#include<cstdio>
long long ans[51],k,tmp,to;
int main(){
//	freopen("ex.in","r",stdin);
	scanf("%lld",&k);tmp=k/50;to=k%50;
	for(int i=1;i<=50;++i) ans[i]=i-1+tmp;
	for(int i=50;i&&to;--i){
		ans[i]++;
		to--;
	}
	puts("50");
	for(int i=1;i<50;++i) printf("%lld ",ans[i]);printf("%lld",ans[50]);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

double getsquare(double x1,double y1,
		double x2,double y2,
		double x3,double y3);

int main(void) {
	double chouten[20][2];
	double s=0;
	int i;
	int max;
	for(i=0;i<20;i++) {
		if(scanf("%lf,%lf",&chouten[i][0],&chouten[i][1])==-1)break;
	}
	max=i;
	for(i=1;i<max-1;i++) {
		s+=getsquare(chouten[0][0],chouten[0][1],
			chouten[i][0],chouten[i][1],
			chouten[i+1][0],chouten[i+1][1]);
	}
	printf("%f\n",s);
	return 0;
}

double getsquare(double x1,double y1,
		double x2,double y2,
		double x3,double y3) {
	double len1,len2,len3;
	double z;
	len1=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
	len2=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
	len3=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
	z=(len1+len2+len3)/2;
	return sqrt(z*(z-len1)*(z-len2)*(z-len3));
}

Measured memory_bytes: 0
N = int(input())

XL = []
for i in range(N):
    tmp = list(map(int, input().split()))
    XL.append(tmp)
    
XL = sorted(XL, key=lambda x:x[0])

i = 0
now = 0
count = 0
while i <= len(XL)-2:
    now_arm = XL[now][0] + XL[now][1]
    if now_arm > XL[i+1][0] - XL[i+1][1]:
        count += 1
        if XL[i+1][0] + XL[i+1][1] < now_arm:
            now = i+1
        else:
            pass
    else:
        now = i+1
    i += 1    


#print(XL)
print(len(XL) - count)


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

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

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

    if (a + b + c >= 22)
        printf("bust\n");
    else
        printf("win\n");

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    ll h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) cout << 1 << endl;
    else cout << ((h * w + 1) / 2) << endl;
    return 0;
}


Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *      created : 
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << '{'; for (size_t i = 0; i < vec.size(); ++i) { os << vec[i]; if (i != vec.size() - 1) os << ','; } os << '}'; return os; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

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

  int n, a, b; cin >> n >> a >> b;
  vector<int64> v(n);
  map<int64, int> mp;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    ++mp[v[i]];
  }
  sort(v.rbegin(), v.rend());
  int64 pascal[51][51];
  fill(pascal[0], pascal[51], 0LL);
  for (int i = 0; i < 51; ++i) {
    for (int j = 0; j < i + 1; ++j) {
      if (j == 0 || j == i) {
        pascal[i][j] = 1LL;
      } else {
        pascal[i][j] = pascal[i - 1][j - 1] + pascal[i - 1][j];
      }
    }
  }

  double best_mean = 0;
  for (int i = 0; i < a; ++i) {
    best_mean += static_cast<double>(v[i]);
  }
  best_mean /= static_cast<double>(a);

  int64 ans = 0;
  int64 target = v[a - 1];
  int target_cnt = 0;
  for (int i = 0; i < a; ++i) {
    if (v[i] == target) ++target_cnt;
  }

  if (v[0] == v[a - 1]) {
    //cerr << "hi" << '\n';
    int same = 0;
    for (int i = a - 1; i <= b - 1; ++i) {
      if (v[i] == v[a - 1]) ++same;
    }
    //debug(same);
    for (int i = 0; i < same; ++i) {
      ans += pascal[mp[v[0]]][a + i];
    }
  } else {
    ans = pascal[mp[v[a - 1]]][target_cnt];
  }

  printf("%.15f\n", best_mean);
  printf("%lld\n", ans);

  return 0;
}

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

int main(void)
{
    int r;
    cin >> r;
    if (r < 1200)
        cout << "ABC" << endl;
    else if (r < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;
}


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

int main(){
  int H,W;
  cin >> H >> W;
  vector<int> w(H*W),m(2*H*W);

  int i,j,k=0;
  for(i=0; i<H*W; i++){
    cin >> w.at(i);
  }

  for(i=0; i<H; i++){
    for(j=0; j<W-1; j++){
      if(w.at(i*W+j)%2 == 1){
        w.at(i*W+j)-=1;
        w.at(i*W+j+1)+=1;
        m.at(2*k)=i*W+j;
        m.at(2*k+1)=i*W+j+1;
        k++;
      }
    }
  }

  for(i=0; i<H-1; i++){
    if(w.at((i+1)*W-1)%2 == 1){
        w.at((i+1)*W-1)-=1;
        w.at((i+2)*W-1)+=1;
        m.at(2*k)=(i+1)*W-1;
        m.at(2*k+1)=(i+2)*W-1;
        k++;
    }
  }

  cout << k << endl;
  for(i=0; i<k; i++){
    cout << m.at(2*i)/W+1 << " " << m.at(2*i)%W+1 << " " << m.at(2*i+1)/W+1 << " " << m.at(2*i+1)%W+1 << endl;
  }
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
using namespace std;
 
int gcd(int a , int b , int c){
	int ans = 0;
	for(int i = 1 ; i <= min({a,b,c}) ; ++i){
		if(a % i == 0 && b % i == 0 && c % i == 0) ans = i;
	}
	return ans;
	
}
void test_case(){
	int n;
	cin >> n;
	long long sum = 0;
	for(int a = 1 ; a <= n ; ++a){
		for(int b = 1 ; b <= n ; ++b){
			for(int c = 1 ; c <= n ; ++c){
				sum += gcd(a,b,c);
			}
		}
	}
	cout << sum;
}
int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	test_case();
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(n)      (n).begin(), (n).end()
#define ll long long
#define ull unsigned long long int
void solve() {
    int k; cin >> k;
    vector<int> vis(k,0);
    int cur = 1; int mdv = 7%k;
    while(1){
        if(mdv == 0){
            cout << cur << endl; return;
        }else if(vis[mdv]){
            cout << "-1" << endl; return;
        }else{
            vis[mdv]++;
            cur++;
            mdv = (mdv*10+7 )%k;
        }
    }    
}
int main(){
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    //Starts here , 
                
   
        solve();
    return 0;
            
}

Measured memory_bytes: 7212
//Author: master19
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ff first 
#define ss second 
#define pb push_back
#define endl "\n"
#define PI acos(-1.0)
#define mod 1000000007LL // fixed...
#define modd 1000000007LL // Can be changed for global use
#define ccy cout << "YES\n"
#define ccn cout << "NO\n"
#define cfy cout << "Yes\n"
#define cfn cout << "No\n"
#define x(arr) arr.begin(),arr.end()
#define ulli unsigned long long int
#define assign(x,val) memset(x,val,sizeof(x))
#define prec(val, dig) fixed << setprecision(dig) << val
#define vil vector < ll > 
#define vis vector < string > 
#define vip vector < pair < ll, ll > > 
#define pi pair < ll , ll > 
#define pii pair < pair < ll, ll >, ll >
#define Sort(arr) sort(arr.begin(), arr.end())
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define get(arr, num) vector < ll > arr(num); for(int i=0; i<num; i++)cin >> arr[i];
#define get_set(arr, num, st, type) set < type > st; for(int i=0; i<num; i++) st.insert(arr[i]);
#define put(arr, num) for(int i=0; i<num; i++)cout << arr[i] << " "; cout << endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > new_ds; 
ll lets_do_it();
// pi xy[] = {{-1, 0}, {1, 0} , {0, -1}, {0, 1}};
// pi dig[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
// bool isValid(ll x, ll y, ll row, ll col){
//     return ((x>=0) && (y >=0)  && (x < row) && (y < col));
// }
ll power(ll k, ll num){
	if(num == 0)
		return 1%mod;
	ll value = power(k, num/2);
	value = value%mod;
	value = ((value%mod) * (value%mod))%mod;
	if(num & 1)
		value = (value * (k%mod))%mod;
	value = value%mod;
	return value;
	
}
int main(int argc, const char** argv) {
    crap;
    ll test = 1;
    // cin >> test;
    for(int loop=0; loop<test; loop++){
        // cout << "Case #" << (loop+1) << ": "; 
        lets_do_it();
    }
    return 0;
}
ll lets_do_it(){
    string first, second;
    cin >> first >> second;
    ll count = 0;
    for(int i=0; i<first.length(); i++){
        if(first[i] != second[i])
            count++;
    }
    if(second.length()-1 != first.length() || count > 0)
        cout << "No\n";
    else
        cout << "Yes\n";
    


    return 0;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
int main() {
	int N;
	while (cin >> N, N) {
		map<int, vector<P>> v;
		priority_queue<P, vector<P>, greater<P>> Q;
		Q.push(P(0, 1000000000));
		for (int i = 0; i < N; i++) {
			string command;
			cin >> command;
			if (command == "W") {
				int l, S;
				cin >> l >> S;
				int sum = 0;
				while (!Q.empty()) {
					P p = Q.top(); Q.pop();
					int len = p.second - p.first + 1;
					if (sum + len < S) {
						sum += len;
						v[l].push_back(p);
						continue;
					}
					v[l].push_back(P(p.first, p.first + (S - sum) - 1));
					Q.push(P(p.first + (S - sum), p.second));
					break;
				}
			}
			else if (command == "D") {
				int l;
				cin >> l;
				for (P p : v[l]) {
					Q.push(p);
				}
				v[l].clear();
			}
			else {
				int l;
				cin >> l;
				bool ok = 0;
				for (auto &itr : v) {
					for (P p : itr.second) {
						if (p.first <= l && l <= p.second) {
							ok = 1;
							cout << itr.first << endl;
							break;
						}
					}
					if (ok) break;
				}
				if (!ok) cout << -1 << endl;
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 23252
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]

def count_mine(i, j, s, h, w):
  mine = 0
  # 一段上
  if i-1 >= 0 and j-1 >= 0 and s[i-1][j-1] == "#":
    mine += 1
  if i-1 >= 0 and s[i-1][j] == "#":
    mine += 1
  if i-1 >= 0 and j+1 < w and s[i-1][j+1] == "#":
    mine += 1
  
  # 真ん中
  if j-1 >= 0 and s[i][j-1] == "#":
    mine += 1
  if j+1 < w and s[i][j+1] == "#":
    mine += 1
    
  # 一段下
  if i+1 < h and j-1 >= 0 and s[i+1][j-1] == "#":
    mine += 1
  if i+1 < h and s[i+1][j] == "#":
    mine += 1
  if i+1 < h and j+1 < w and s[i+1][j+1] == "#":
    mine += 1
    
  return mine

for i in range(h):
  for j in range(w):
    if s[i][j] == ".":
      s[i][j] = count_mine(i, j, s, h, w)
  print(''.join(map(str, s[i])))
  



Measured memory_bytes: 9272
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=3e5+50;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
int main()
{
    int n,ans=0;
    ll d;
    cin>>n>>d;
    for(int i=0;i<n;++i)
    {
        ll x,y;
        cin>>x>>y;
        if((x*x+y*y)<=d*d)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(void)
{
  char str[11], ring[21];
  int n, c, len;

  scanf("%s", str);
  scanf("%d", &n);

  while(n--){
    scanf("%s", ring);
    len = strlen(ring);
    strncat(ring, ring, len);

    if(strstr(ring, str) != NULL) c++;
  }
  printf("%d\n", c);

  return 0;
}

Measured memory_bytes: 616
#include<stdio.h>
#include<stdlib.h>


typedef struct Node{
  int jisuu;
  int *child;
  int parent;
}Node;



int get_dep(Node *node,int soeji){
  int dep=0;
  Node x;
  x=node[soeji];
  while(x.parent!=-1){
    x=node[x.parent];
    dep++;
  }
  return dep;
}



int main(){
  int n,i,j,bangou;
  scanf("%d",&n);
  Node *node;
  node=malloc(n*sizeof(Node));
  for(i=0;i<n;i++){
    scanf("%d",&bangou);
    scanf("%d",&(node[bangou].jisuu));
    node[bangou].child=malloc( (node[bangou].jisuu)*sizeof(int) );
    node[bangou].parent =-1;
    for(j=0;j<node[bangou].jisuu;j++) scanf("%d",&(node[bangou].child[j]));
  }
  int cnt=0;
  for(i=0;i<n;i++){
    for(j=0;j< node[i].jisuu;j++){
      node[node[i].child[j]].parent=i;
      cnt+=1;
    }
    if(cnt==n-1) break;
  }
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d",i,node[i].parent,get_dep(node,i));
    if(node[i].parent==-1) printf(", root");
    else if(node[i].jisuu==0) printf(", leaf");
    else printf(", internal node");
    printf(", [");
    for(j=0;j<node[i].jisuu -1;j++) printf("%d, ",node[i].child[j]);
    if(node[i].jisuu!=0) printf("%d",node[i].child[node[i].jisuu -1]);
    printf("]\n");
  }
  return 0;
}






  

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n;
    cin >> n;
    int a[n];
    REP(i,n){
        cin >> a[i];
    }
    int count = 0;
    REP(i,n){
        if(a[a[i]-1]==i+1)count++;
    }
    cout << count/2 << endl;
    return 0;
}    

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n,m; cin >> n >> m;
	vvl G(n);
	rep(i,m){
		ll a,b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vl ans(n,-1);
	ans[0] = 0;
	queue<ll> q;
	q.push(0);
	while(!q.empty()){
		ll u = q.front(); q.pop();
		for(auto v : G[u]){
			if(ans[v] != -1) continue;
			ans[v] = u+1;
			q.push(v);
		}
	}
	puts("Yes");
	for(ll i=1; i<n; i++){
		cout << ans[i] << "\n";
	}
}

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

using namespace std;

int main(){
    int i,j;
    int X,N;
    int A[100];
    int count = 0;
    int p,q = 0;

    cin >> X >> N; 

    if(N == 0){
        cout << X << endl;
        return 0;
    }

    for(int i = 0 ;i < N ; i++){
        cin >> A[i];
    }

    p = X;
    for(int i = 0 ; i < N ; i++){
        if(A[i] == X){
            count = count + 1;
        }
    }

    if(count == 0){
        cout << p << endl; 
        return 0;
    }

    j = 1;
    count = 0;
   
   while(1){
       p = X-j;
       q = X+j;
        for(i = 0 ; i < N ;i++){
            if(A[i] == p){
                count = count + 1;
                p = 0;
            }else if(A[i] == q){
                count = count + 1;
                q = 0;
            }
        }

        if(count == 1){
            if(p == 0){
                cout << q << endl;
            }else if(q == 0){
                cout << p << endl;
            }
            break;
        }else if(count == 0){
            if(p > q){
                cout << q << endl;
                //cout << count << endl;
            }else if(p < q){
                cout << p << endl;
                //cout << count << endl;
            }
            break;
        }
        p = 0;
        q = 0;
        count = 0;
        j = j + 1;
   }
    return 0;
}

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

using namespace std;

const int units[4] = {10, 50, 100, 500};

int main() {
	int p;
	bool first = true;
	while(cin >> p, p) {
		if(!first) {
			cout << endl;
		}
		first = false;

		int c[4];
		int sum = 0;
		for(int i = 0; i < 4; i++) {cin >> c[i]; sum += units[i]*c[i];}

		sum -= p;
		for(int i = 3; i >= 0; i--) {
			while(sum >= units[i]) {
				sum -= units[i]; c[i]--;
			}
		}

		for(int i = 0; i < 4; i++) {
			if(c[i] > 0)
				cout << units[i] << " " << c[i] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 2968
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
#include<cstring>
#define INF 1000000000
using namespace std;
int a,b,k,x=0;
int main(){
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++)
        if(i%k==0){
            x=1;
            break;
        }
    if(x)
        cout<<"OK";
    else
        cout<<"NG";
}

Measured memory_bytes: 3636
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	LL X;
	cin >> X;
	LL NG = 0;
	LL OK = INF;
	LL mid;
	while(OK-NG>1){//ジャンプ回数の二分探索
		mid = (NG+OK)/2;
		LL res = (1+mid)*mid/2;
		if( X <= res ){
			OK = mid;
		}else{
			NG = mid;
		}
	}
	cout << OK << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 384