akhauriyash/Code-Regression huggingface dataset:
#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 <iomanip>
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<long 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; }
#define INF 1LL<<60

struct Po {
    int x;
    int y;
};

ll mod = 1e9 + 7;
int H, W, N;
vector<ll> facts(201010), inv_facts(201010), inv(201010);

bool operator<(const Po& a, const Po& b)
{
    return a.x + a.y < b.x + b.y;
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll get_num_routs(Po s, Po t) {
    ll num_routs = (facts[t.x + t.y - s.x - s.y] * inv_facts[t.x - s.x]) % mod;
    num_routs= (num_routs * inv_facts[t.y - s.y]) % mod;
    return num_routs;
} 

int main() {
    cin >> H >> W >> N;
    H--; W--;
    // vector<int> r(N), c(N);
    vector<Po> points;
    REP(i, N) {
        int x, y;
        cin >> x >> y;
        points.push_back(Po{y-1, x-1});
    }

    facts[0] = 1;
    inv_facts[0] = 1;
    for(ll i=1; i<=H+W+2; ++i) facts[i] = (facts[i-1] * i) % mod;
    
    inv[1] = 1;
    for (ll i = 2; i <= H+W+2; ++i) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    inv_facts[0] = inv_facts[1] = 1;
    for (ll i = 2; i <= H+W+2; ++i) inv_facts[i] = inv_facts[i - 1] * inv[i] % mod;

    vector<vector<int>> children(N+2, vector<int>(0));
    points.push_back(Po{0, 0});
    points.push_back(Po{W, H});
    sort(points.begin(), points.end());
    REP(i, N+2) {
        Po pi = points[i];
        REP(j, N+2) {
            if(j == i) continue;
            Po pj = points[j];
            if(pi.x <= pj.x && pi.y <= pj.y) children[i].push_back(j);
        }
    }
    
    vector<vector<ll>> dp(N+2, vector<ll>(2, 0)); // dp[i][0]: i番目の点に偶数個の点を経由して到達する方法
    dp[0][0] = 1;
    dp[0][1] = 0;

    FOR(i, 0, N+1) {
        for(auto c: children[i]) {
            // cerr << "x = " << points[c].x << " y = " << points[c].y << endl;
            dp[c][1] += get_num_routs(points[i], points[c]) * dp[i][0];
            dp[c][1] %= mod;

            dp[c][0] += get_num_routs(points[i], points[c]) * dp[i][1];
            dp[c][0] %= mod;
        }
    }

    cerr << dp[N+1][0] << " " << dp[N+1][1] << endl;
    cout << (dp[N+1][1] - dp[N+1][0] + mod) % mod << endl;
    return 0;
}

Measured memory_bytes: 29440
#include <bits/stdc++.h>
using namespace std;
string s;
int n, dp[202020][2];
int solve(int pos, int last){
    if(dp[pos][last] != -1){
        return dp[pos][last];
    }
    if(pos == -1){
        return 1e9;
    }
    if(s[pos] == '.' && last == 0){
        dp[pos][last] = solve(pos - 1, 1);
        dp[pos][last] = min(dp[pos][last], 1 + solve(pos - 1, 0));
    }
    else if(s[pos] == '.' && last == 1){
        dp[pos][last] = solve(pos - 1, 1);
    }
    else if(s[pos] == '#' && last == 0){
        dp[pos][last] = solve(pos - 1, 0);
        dp[pos][last] = min(dp[pos][last], 1 + solve(pos - 1, 1));
    }
    else if(s[pos] == '#' && last == 1){
        dp[pos][last] = 1 + solve(pos - 1, 1);
    }
    return dp[pos][last];
}
int main(){
    //freopen("test.in", "r+", stdin);
    cin >> n;
    cin >> s;
    s += "#";
    memset(dp, -1, sizeof dp);
    cout << solve(n - 1, 0) << endl;
}


Measured memory_bytes: 13572
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int N=100005;

int n,m;
int fa[N],dis[N];
int find(int x) 
{
	if (x==fa[x]) return x;
	int t=find(fa[x]);
	dis[x]+=dis[fa[x]];
	return fa[x]=t;
}


int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) fa[i]=i;
	
	int x,y,d,fx,fy;
	bool o=true;
	while (m--) 
	{
		scanf("%d%d%d",&y,&x,&d);
		if (!o) continue;

		fx=find(x),fy=find(y);
		if (fx==fy) 
		{
			if (dis[x]-dis[y]!=d) o=false;
		}
		else 
		{
			fa[fx]=fy;
			dis[fx]=-dis[x]+dis[y]+d;
		}
	}
	if (o) puts("Yes");else puts("No");
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define all(c) (c).begin(), (c).end()
const int INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;

const int MAX = 1e5 + 9;
vector<vector<int>> G(MAX);
vector<int> dist(MAX, -1);
int ans = 0;

void dfs(int v, int p, int d) {
  for (int u : G[v]) {
    if (u == p) continue;
    dist[u] = d + 1;
    dfs(u, v, d + 1);
  }
}

void dfs2(int v, int p, int d) {
  for (int u : G[v]) {
    if (u == p && d > 1) continue;
    int t = d + (dist[u] % 2 == d % 2 ? 0 : 1);
    if (dist[u] <= t) {
      ans = max(ans, t);
      continue;
    }
    // dump(v, u, dist[u], p, d);
    ans = max(ans, dist[u] - 1);
    dfs2(u, v, d + 1);
  }
}

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

  int n, u, v;
  cin >> n >> u >> v;
  --u, --v;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dist[v] = 0;
  // dump(G);
  dfs(v, -1, 0);
  // dump(dist);
  dfs2(u, -1, 0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11264
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;
//dx[4]={0,1,0,-1};
//dy[4]={1,0,-1,0};

int main(){
	int a,b,c,d,p,q,r,s;
	cin>>a>>b>>c>>d;
	FOR(i,0,c-a){
		cout<<"R";
	}
	FOR(i,0,d-b){
		cout<<"U";
	}
	FOR(i,0,c-a){
		cout<<"L";
	}
	FOR(i,0,d-b){
		cout<<"D";
	}
	cout<<"L";
	FOR(i,0,(d+1)-b){
		cout<<"U";
	}
	FOR(i,0,c-(a-1)){
		cout<<"R";
	}
	cout<<"D";

	cout<<"R";
	FOR(i,0,(d+1)-b){
		cout<<"D";
	}
	FOR(i,0,c-(a-1)){
		cout<<"L";
	}
	cout<<"U";
	

	cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int n,m;
struct qq
{
	int p,c;
}s[15];
bool ok[15];
int ans;
void check ()
{
	int lalal=0,now=0;
	for (int u=1;u<=n;u++)
	{
		if (ok[u])
		{
			lalal=lalal+s[u].p;
			now=now+u*s[u].p+s[u].c;
		}
	}
	if (now>=m)
	{
		ans=min(ans,lalal);
		return ;
	}
	for (int u=n;u>=1;u--)
	{
		if (ok[u]) continue;
		int t=(m-now);
		int need=t/u;
		if (t%u!=0) need++;
		if (s[u].p>=need)
		{
			lalal=lalal+need;
			ans=min(ans,lalal);
			return ;
		}
		else
		{
			lalal=lalal+s[u].p;
			now=now+u*s[u].p+s[u].c;
		}
		if (now>=m)
		{
			ans=min(ans,lalal);
			return ;
		}
	}
}
void dfs (int x)
{
	if (x>n)	
	{
		check();
		return ;
	}
	ok[x]=true;dfs(x+1);
	ok[x]=false;dfs(x+1);
}
int main()
{
	scanf("%d%d",&n,&m);m/=100;
	ans=(1<<28);
	for (int u=1;u<=n;u++)		
	{
		scanf("%d%d",&s[u].p,&s[u].c);
		s[u].c/=100;
	}
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n , m , l  , x , y, cnt[300] ,value[300] , need[300] ,cnt2[300];
string s , t ;
char a[]={'U','D','L','R'};
void solve (char &x)
{
    if(x=='U')       x='D';
    else if(x=='D')  x='U';
    else if(x=='R')  x='L';
    else             x='R';
}
int main()
{
    value['U']=-1 , value['D']=1 , value['R']=1 , value['L']=-1;
    cin>>n>>m>>l>>x>>y>>s>>t;
    need['R']=m-y+1 , need['D']=n-x+1 , need['L']=-y , need['U']=-x;
    for(int i=0;i<l;i++)
    {
        char g=t[i];
        solve(g);
        cnt[s[i]]+=value[s[i]];

        for(int j=0;j<4;j++)
            if(cnt[a[j]]==need[a[j]])
            return cout<<"NO", 0 ;

        if(cnt[g]+value[t[i]]!=need[t[i]])
            cnt[g]-=value[g];

    }
    cout<<"YES" ;
    return 0;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin>>s;
int n=s.size();
string ans;
if(n<26){
    map<char,int> dic;
    rep(i,n){
        dic[s[i]]++;
    }
    rep(i,26){
        char c = 'a' + i;
        if(!dic[c]){
            ans=s+c;
            break;
        }
    }
}
else{
    if(s=="zyxwvutsrqponmlkjihgfedcba"){
        ans="-1";
    }
    else{
        string _s=s;
        next_permutation(_s.begin(),_s.end());
        rep(i,26){
            if(s[i]!=_s[i]){
                ans=_s.substr(0,i+1);
                break;
            }
        }
    }
    // int r=25;
    // rep(i,r){
    //     reps(j,r,i+1)
    //     if(s[r-j]<s[r-i]){
    //         char c=s[r-j];
    //         s[r-j]=s[r-i];
    //         s[r-i]=c;
    //         ans=s.substr(0,26-j);
    //         break;
    //     }
    //     if(ans!="-1")break;
    // }
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3528
#include<stdio.h>

void swap(int *x, int *y);

int main()
{
  while(1)
    {
      int a, b;
      scanf("%d %d",&a ,&b);
      if(a == 0 && b == 0) break;
      else if(a > b) swap(&a, &b);
      printf("%d %d\n",a,b);
    }
  return 0;
}

void swap(int *x,int *y)
{
  int tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX



 
void solve()
{
    int n;
    cin >> n;
    int ans = 0;
    rep(i,1,n)
        rep(j,1,n)
            rep(k,1,n)
                ans += __gcd(i,__gcd(j,k));
    cout << ans << endl;
}


signed main()
{
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    

    class ClassMain {

        public static string numB(int n) {
            switch(n){
                case 1: return "";
                case 2: return "k";
                case 3: return "s";
                case 4: return "t";
                case 5: return "n";
                case 6: return "h";
                case 7: return "m";
                case 8: return "y";
                case 9: return "r";
            }
            return "";

        }
        public static string flipB(char ch) {
            switch (ch) {
                case 'T': return "a";
                case 'L': return "i";
                case 'U': return "u";
                case 'R': return "e";
            }
            return "o";

        }

        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                char[] chrs = line.ToCharArray();
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i<chrs.Length; i+=2) {
                    if (chrs[i] != '0') { 
                        sb.Append(numB(chrs[i] - '0')); 
                        sb.Append(flipB(chrs[i+1]));
                    }
                    else {//if 0 wa wo n.
                        if (chrs[i + 1] == 'U') { sb.Append("nn"); }
                        else if (chrs[i + 1] == 'D') { sb.Append("wo"); }
                        else if (chrs[i + 1] == 'T') { sb.Append("wa"); }
                    }
                }
                Console.WriteLine(sb.ToString());
                
            }
        }

    }

    
}

Measured memory_bytes: 17560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[100000];
int cum[100010];
int cnt1, cnt2;
int s, t;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cum[i + 1] = cum[i] + a[i];
	}
	for (int i = 1; i <= n; i++) {
		if (i % 2 && cum[i] + s <= 0) {
			cnt1 += 1 - (cum[i] + s);
			s += 1 - (cum[i] + s);
		}
		if (!(i % 2) && 0 <= cum[i] + s) {
			cnt1 += cum[i] + s + 1;
			s -= cum[i] + s + 1;
		}
		if (i % 2 && 0 <= cum[i] + t) {
			cnt2 += cum[i] + t + 1;
			t -= cum[i] + t + 1;
		}
		if (!(i % 2) && cum[i] + t <= 0) {
			cnt2 += 1 - (cum[i] + t);
			t += 1 - (cum[i] + t);
		}
	}
	cout << min(cnt1, cnt2) << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,c=0;
    cin>>n>>m;
   int a[m];
   for(int i=0;i<m;i++){
       cin>>a[i];
       c+=a[i];
   }
   if(n>=c){
       cout<<n-c;
   }else{
       cout<<"-1";
   }
    return 0;
}

Measured memory_bytes: 3592
#include<stdio.h> 
int main() { 
    int W,H,x,y,r; 
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r); 
    if (W>=x+r && H>=y+r && r<=x && r<=y && x>=0 && y>=0)
        printf("Yes\n");
        else printf("No\n");
        return 0; } 



Measured memory_bytes: 2108
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			long[] array = new long[n];
			for (int i = 0; i<n; i++) array[i] = sc.nextLong();
			boolean same = true;
			int query = sc.nextInt();
			for (int i = 0; i<query; i++) {
				same = binarySearch(array,sc.nextLong());
				if (!same) break;
			}
			System.out.println(same? "1":"0");
		}
	}

	static boolean binarySearch(long[] array, long target) {
		int low = 0;
		int high = array.length-1;  //最後

		while (low <= high) {
			//System.out.println(low + "    "+ high);
			int mid = (high + low)/2;
			if (array[mid] == target) return true;
			else if (array[mid] < target) low = mid+1;
			else high = mid-1;
		}
		return false;  //最後まで見つからなかったら
	}
}



Measured memory_bytes: 121360
#include <iostream>
#include <string>
#include <vector>
#include <utility>
using namespace std;
typedef pair<int,int> MonthDay;
int main(){
  int monthnum[]={
    31,29,31,30,31,30,31,31,30,31,30,31
  };
  const string weekname[]={
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
    "Sunday"
  };
  vector<MonthDay> data;
  int month,day;
  while(cin>>month>>day){
    if(!month)break;
    data.push_back(MonthDay(month,day));
  }
  for(int i=0;i<data.size();i++){
    int daysum=0;
    for(int j=0;j<data[i].first-1;j++){
      daysum+=monthnum[j];
    }
    daysum+=data[i].second;
    int weekindex=(daysum+2)%7;
    cout<<weekname[weekindex]<<endl;
  }
}

Measured memory_bytes: 1200
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int INF = 1e9;

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	rep(i, n) cin >> a[i] >> b[i] >> c[i];
	vector<vector<int>> dp(n,vector<int>(3));
	dp[0][0] = max(b[0],c[0]);
	dp[0][1] = max(a[0],c[0]);
	dp[0][2] = max(a[0],b[0]);
	rep(i, n - 1) {
		rep(j, 3) {
			if (j == 0) {
				dp[i + 1][j] = max(dp[i][1] + b[i + 1], dp[i][2] + c[i + 1]);
			}
			else if (j == 1) {
				dp[i + 1][j] = max(dp[i][0] + a[i + 1], dp[i][2] + c[i + 1]);
			}
			else {
				dp[i + 1][j] = max(dp[i][0] + a[i + 1], dp[i][1] + b[i + 1]);
			}
		}
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
}


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

#define ntest 0

using namespace std;

int n;
int a[1010000];
int allGcd, cntCoprime;
set<int> factors;
int minprime[1010000];
void prepare() {
    for (int i = 2; i * i <= 1000000; ++i) {
        for (int j = i * i; j <= 1000000; j+=i) minprime[j] = i;
    }
    for (int i = 1; i <= 1000000; ++i) if (!minprime[i]) minprime[i] = i;
}
int coprime(int x) {
    if (x == 1) return 1;
    set<int> fac;
    while(x != 1) {
        fac.insert(minprime[x]);
        x /= minprime[x];
    }
    for (auto &i : fac) if (!factors.insert(i).second) return 0;
    return 1;
}
void solve() {
    prepare();
    cin >> n;
    allGcd = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        allGcd = __gcd(allGcd, a[i]);
    }
    for (int i = n; i >= 1; --i) {
        if (coprime(a[i])) ++cntCoprime;
    }
    //cout << "cnt: " << cntCoprime << '\n';
    if (cntCoprime == n) cout << "pairwise coprime\n";
    else if (allGcd == 1) cout << "setwise coprime\n";
    else cout << "not coprime\n";
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    if(ntest){
        int t;
        cin >> t;
        while(t--) solve();
    } else {
        solve();
    }

}




Measured memory_bytes: 15044
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines  

N = int(input())//2
S = input().rstrip().decode()

ans = "Yes "if S[:N] == S[N:] else "No"
print(ans)

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

int bst[6];
int jr[6];
char str[5005];
set<int> st;
int n, m;
int main(){
    scanf("%s", str);
    scanf("%d",&m);
    jr[0] = 1;
    for(int i=1;i<=5;i++){
        jr[i] = jr[i-1] * 27;
    }
    n = (int)strlen(str);
    for(int i=0;i<5;i++) bst[i] = jr[5] + 1;
    for(int i=0;i<n;i++){
        int val = 0;
        for(int j=0;j<5;j++){
            if(i+j >= n) break;
            val += jr[4-j] * ((str[i+j] - 'a') + 1);
            //printf("%d\n", val);
            for(int k=0;k<5;k++){
                if(bst[k] > val){
                    for(int l=3;l>=k;l--){
                        bst[l+1] = bst[l];
                    }
                    bst[k] = val;
                    break;
                }else if(bst[k] == val) break;
            }
        }
    }
    //for(int i=0;i<5;i++) printf("%d\n", bst[i]);
    for(int i=4;i>=0;i--){
        int target = (bst[m-1]%jr[i+1]) / jr[i];
        if(target != 0) printf("%c", target+'a'-1);
    }
    printf("\n");
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int A = cin.Int();
			int B = cin.Int();
			int M = cin.Int();
			var a = cin.ArrayInt(A);
			var b = cin.ArrayInt(B);

			int mina = a.Min();
			int minb = b.Min();

			int ans = mina + minb;
			for (int i = 0; i < M; i++) {
				int x = cin.Int() - 1;
				int y = cin.Int() - 1;
				int c = cin.Int();

				int temp = a[x] + b[y] - c;
				ans = Math.Min(ans, temp);
			}

			Console.WriteLine(Math.Max(ans, 0));
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 33248
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>

using namespace std;

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

	int n;
	cin >> n;
	int dp[n+1];
	for(int i=2; i<=n; i++) dp[i] = n;

	vector<int> nums(1);
	nums[0] = 1;
	int tmp;
	
	for(int i=1;;i++){
		tmp = pow(6,i);
		if (tmp <= n) nums.push_back(tmp);
		else		break;
	}
	for(int i=1;;i++){
		tmp = pow(9,i);
		if (tmp <= n) nums.push_back(tmp);
		else		break;
	}
	sort(nums.begin(), nums.end());

	dp[0] = 0; dp[1] = 1;

	for(int i=2;i<=n;i++){
		for(auto x=nums.begin(); x!= nums.end(); x++){
			tmp = i- *x;
			if(tmp >= 0) dp[i] = min(dp[i], dp[tmp] + 1);
			else break;
		}
	}

	cout << dp[n] << "\n"; 
				
	
	return 0;
}

Measured memory_bytes: 640
/*#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,pair<int,int> >&a,pair<int,pair<int,int> >&b)
{
   return a.second.first<b.second.first;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}

int main()
{
    fast_cin;
      string s,t;
      cin>>s>>t;
      int n=s.length();
      int m=t.length();
      unsigned int dp[n+1][m+1];
      string ans;
      for(int i=0;i<=n;i++)
      {
          for(int j=0;j<=m;j++)
          {
              if(i==0||j==0)
                dp[i][j]=0;
              else if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
              else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
              if(ans.length()<dp[i][j])
                ans+=s[i];
          }
      }
      cout<<dp[n][m]<<endl;
      //cout<<ans<<endl;
    return 0;
}*/
#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,int>&a,pair<int,int>&b)
{
   return a.second>b.second;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}
void binary(int n)
{
    // array to store binary number
    int binaryNum[32];

    // counter for binary array
    int i = 0;
    while (n > 0) {

        // storing remainder in binary array
        binaryNum[i] = n % 2;
        n = n / 2;
        i++;
    }

    // printing binary array in reverse order
    for (int j = i - 1; j >= 0; j--)
        cout << binaryNum[j];
}
int main()
{
    fast_cin;
    int t;
    t=1;
    while(t--)
    {
        ll d,t,s;
        cin>>d>>t>>s;
        if(d<=s*t)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3864
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
//#define maxi 1e18
#define pll pair<ll,ll>
#define inf 1000000007
map<ll,ll> m;
int main(){
    ll a,b;
    cin>>a>>b;
    cout<<max(1ll*0,a-2*b);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<set>
#include<map>
#define MAX 1000000000+7
using namespace std;

int main() {
	int n, a, b, s = 0;
	cin >> n;
	vector<pair<int, int>> v;
	for (int i = 0;i < n;i++) {
		cin >> a >> b;
		v.push_back(make_pair(b, a));
	}
	sort(v.begin(), v.end());
	bool f = 1;
	for (int i = 0; i < n; i++) {
		s += v[i].second;
		if (s > v[i].first) {
			f = 0;
			break;
		}
	}
	if (f) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 2420
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a<b){
            if(b<c){
                System.out.printf("%d %d %d\n",a,b,c);
            }else if(a<c){
                System.out.printf("%d %d %d\n",a,c,b);
            }else{
                System.out.printf("%d %d %d\n",c,a,b);
            }
        }
        else{
            if(a<c){
                System.out.printf("%d %d %d\n",b,a,c);
            }else if(b<c){
                System.out.printf("%d %d %d\n",b,c,a);
            }else{
                System.out.printf("%d %d %d\n",c,b,a);
            }
        }
    }
}


Measured memory_bytes: 26392
n = int(input())
list_three =[]
for i in range(1, n+1):
  if i % 3 == 0:
    list_three.append(str(i))
  else:
    i2 = i
    while i2 > 1:
      amari = i2 % 10
      if amari == 3:
        list_three.append(str(i))
        break
      else:
        i2 //= 10
        continue
print(" " + " ".join(list_three))


Measured memory_bytes: 5936
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXN]; int n;
vector <pair <int, int>> mod;
void modify(char *s, int n, int x, int y) {
	for (int i = 1; i <= n; i++)
		if (s[i] == x + 'A') s[i] = y + 'A';
		else if (s[i] == y + 'A') s[i] = x + 'A';
}
void init() {
	scanf("%s", s + 1);
	int m = strlen(s + 1);
	int cnt[3] = {0, 0, 0};
	for (int i = 1; i <= m; i++)
		if (s[n] != s[i]) {
			s[++n] = s[i];
			cnt[s[i] - 'A']++;
		}
	s[n + 1] = 0;
	if (cnt[0] > cnt[1]) swap(cnt[0], cnt[1]), modify(s, n, 0, 1), mod.emplace_back(0, 1);
	if (cnt[1] > cnt[2]) swap(cnt[1], cnt[2]), modify(s, n, 1, 2), mod.emplace_back(1, 2);
	if (cnt[0] > cnt[1]) swap(cnt[0], cnt[1]), modify(s, n, 0, 1), mod.emplace_back(0, 1);
	if (cnt[0] == 0) puts(""), exit(0);
}
void sela() {
	int b = 0, c = 0;
	static int pos[MAXN]; int cnt = 0;
	for (int i = 1; i <= n; i++)
		if (s[i] == 'A') pos[++cnt] = i;
	for (int i = 1; i <= cnt; i++) {
		bool occur = false;
		for (int j = pos[i - 1] + 1; j <= pos[i] - 1; j++)
			occur |= s[j] == 'B';
		b += occur;
	}
		bool occur = false;
		for (int j = pos[cnt] + 1; j <= n; j++)
			occur |= s[j] == 'B';
		b += occur;
	for (int i = 1; i <= cnt - 1; i++)
		c += pos[i] == pos[i + 1] - 2 && s[pos[i] + 1] == 'C';
	if (b >= c) return;
	int lft = c - b, tmp = n; n = 0;
	for (int i = 1; i <= tmp; i++)
		if (s[i] == 'A') {
			if (lft != 0 && n >= 2 && s[n] == 'C' && s[n - 1] == 'A') lft--;
			else s[++n] = s[i];
		} else if (s[n] != s[i]) s[++n] = s[i];
	assert(lft == 0);
}
void delc() {
	int delta = 0;
	for (int i = 1; i <= n; i++)
		if (s[i] == 'C') delta++;
		else if (s[i] == 'B') delta--;
	assert(delta >= 0);
	int tmp = n; n = 0; s[tmp + 1] = 0;
	for (int i = 1; i <= tmp; i++)
		if (s[i] == 'C') {
			if (delta != 0 && ((n >= 1 && s[n] != s[i + 1]) || n == 0)) delta--;
			else s[++n] = s[i];
		} else s[++n] = s[i];
	assert(delta == 0);
}
void delb() {
	int a = 0, b = 0, c = 0;
	for (int i = 1; i <= n; i++)
		if (s[i] == 'C') c++;
		else if (s[i] == 'B') b++;
		else a++;
	assert(b == c && b >= a);
	int tmp = n; n = 0; s[tmp + 1] = -1;
	for (int i = 1; i <= tmp; i++)
		if (s[i] == 'A') s[++n] = s[i];
		else if (b > a && n >= 1 && s[n] != 'A' && s[i] != s[n] && s[i + 1] != s[n - 1]) n--, b--, c--;
		else s[++n] = s[i];
	s[n + 1] = 0;
}
int main() {
	init();
	sela();
	delc();
	delb();
	while (!mod.empty()) {
		modify(s, n, mod.back().first, mod.back().second);
		mod.pop_back();
	}
	printf("%s\n", s + 1);
	return 0;
}

Measured memory_bytes: 5248
import java.io.*;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int n = Integer.parseInt(br.readLine());
    String[] data = br.readLine().split(" ");
    long[] sticks = new long[n];
    
    for(int i=0; i<n; i++){
      sticks[i] = Long.parseLong(data[i]);
    }
    Arrays.sort(sticks);
    int j = n-1;
    long result = 1;
    int judge = 0;
    while (j>=1 && judge != 2){
      if (sticks[j] == sticks[j-1]) {
        result*=sticks[j];
        judge++;
        j--;
      }
      j--;
    }
    if (judge != 2){
      result = 0;
    }
    System.out.println(result);
  }
}


Measured memory_bytes: 47828
n,k = map(int,input().split())
x = [int(i) for i in input().split()]
ans = 10**9
for i in range(0,n-k+1):
	ans = min(ans,abs(x[i]-x[i+k-1])+min(abs(x[i+k-1]),abs(x[i])))
print(ans)


Measured memory_bytes: 14252
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <complex>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1.0e-9

int wrong[55][11];

int main(){
	int t,p,r;
	while(cin>>t>>p>>r,t){
		memset(wrong, 0, sizeof(wrong));
		vector<TIII> v(t);
		REP(i,t)v[i]=MT(0,0,i+1);
		REP(i,r){
			int tid, pid, tt;
			string state;
			cin >> tid >> pid >> tt >> state;
			if(state=="CORRECT"){
				v[tid-1].T1 -= 1;
				v[tid-1].T2 += tt + wrong[tid-1][pid-1]*1200;
			}else wrong[tid-1][pid-1]++;
		}
		SORT(v);
		REP(i,t)cout << v[i].T3 << " "<< -v[i].T1 << " "<< v[i].T2 << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
n = int(input())
h = list(map(int,input().split()))
dp = []

#カエルが進む足場にかかったコスト
for a in range(n):
  dp.append(a)

#カエルが最初の足場にかかったコスト
dp[0] = 0
#カエルが1つ進んだときにかかったコスト
dp[1] = abs(h[0] - h[1])
#for文を使い、カエルが進んだ経路を重複なく、計算する
#効率の良い経路を求めているのではなく、一旦全ての経路を重複せずに求めて比べている
#全探索に近い？？
for i in range(1,n-1):
  dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]),dp[i - 1] + abs(h[i + 1] - h[i - 1]))
#dpの最後配列番号を指定してそれが最小値となる
print(dp[-1])

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

int main(void) {
    int a[3],b,c;
    int k;

    cin >> a[0] >> a[1] >> a[2];
    cin >> k;

    sort(a,a+3,greater<int>());

    cout << a[0]*(pow(2,k)-1) + a[0]+a[1]+a[2] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
#define PI 3.14159265358979
using P = pair<ll , ll>;
//using map = map<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main(){
    string s;
    cin >> s;
    string ans = "";
    ans = s.substr(0, 3);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3600
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
#define foreach(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++ it)

inline int read() {
	int x = 0, f = 1, c = getchar();
	for (;!isdigit(c);c = getchar()) if (c == '-') f ^= 1;
	for (; isdigit(c);c = getchar()) x = x * 10 + c - '0';
	return f ? x : -x;
}

int dp1[2010][2010], dp2[2010][2010], sum[2010];
int main() {
	int n = read(), k = read();
	dp1[0][0] = 1; sum[0] = 1;
	rep(i, 2005) rep(j, 2005) if (j) {
		dp1[i][j] = sum[j - 1];
		(sum[j] += dp1[i][j]) %= mod;
	}
	memset(sum, 0, sizeof sum);
	dp2[0][0] = 1; sum[0] = 1;
	rep(i, 2005) if (i) for (int j = 2005; j; -- j) {
		dp2[i][j] = sum[j - 1];
		(sum[j] += dp2[i][j]) %= mod;
	}
	for (int i = 1; i <= k; ++ i) {
		if (n - k < i - 1) {puts("0"); continue;}
		int ans = 1LL * dp2[k][i] * dp1[n - k - i + 1][i + 1] % mod;
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 31872
n = int(input())
a = []
for _ in range(n+1):
    a.append([-1])
for i in range(n):
    inp = list(map(int, input().split()))
    for j in range(n-2, -1, -1):
        a[i+1].append(inp[j])
matched = [i for i in range(1, n+1)]
finish = 0
days = 0
while True:
    used = set()
    while matched != []:
        i = matched.pop()
        p = a[i][-1]
        if p != -1 and a[p][-1] == i and (i not in used) and (p not in used) :
            a[i].pop()
            a[p].pop()
            used.add(i)
            used.add(p)
            if a[i][-1] == -1:
                finish += 1
            if a[p][-1] == -1:
                finish += 1
    days += 1
    matched = list(used)
    if len(used) == 0:
        days = -1
        break
    elif finish == n:
        break
print(days)


Measured memory_bytes: 62556
#include <bits/stdc++.h>
using namespace std;
//________
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
typedef long long ll;
typedef pair<int,int> Pii;
const int INF = 1 << 29;
//________


int main()
{
  FAST();
  int N, K;
  int a[200010];
  int kind = 0;
  Pii cnt[200010] = {};
  rep(i,200010){
    cnt[i].se = i;
  }

  cin >> N >> K;
  rep(i,N){
    cin >> a[i];
    if(cnt[a[i]].fi == 0)++kind;
    ++cnt[a[i]].fi;
  }

  // show(kind);

  sort(cnt, cnt+N+1);


  int ans = 0;
  int p = 1;
  while(kind > K){
    if(cnt[p].fi == 0){
      ++p;
      continue;
    }
    ans += cnt[p].fi;
    ++p;
    --kind;
  }

  outl(ans);
}



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

const ll mod = 1000000007;
ll dp[110][10];

int main(){
  int h, w, k; cin >> h >> w >> k;
  dp[0][1] = 1;
  
  for(int i = 1; i <= h; i++){
    for(int j = 1; j <= w; j++){
      ll cnt_l = 0, cnt_m = 0, cnt_r = 0;
      for(int bit = 0; bit < (1<<w-1); bit++){
        bool ok = true;
        for(int m = 0; m < w-2; m++){
          if(bit&(1<<m) && bit&(1<<m+1)) ok = false;
        }
        if(!ok) continue;
        int mask1 = 1<<(j-2), mask2 = 1<<(j-1);
        if(j >= 2 && (mask1 & bit)) cnt_l++;
        else if(mask2 & bit) cnt_r++;
        else cnt_m++;
      }
      dp[i][j] = (dp[i-1][j-1]*cnt_l%mod+dp[i-1][j]*cnt_m%mod + dp[i-1][j+1]*cnt_r%mod)%mod;
    }
  }
  cout << dp[h][k] << endl;
}

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

int main(){
    long N;
    cin>>N;
    long a[N],m=0;
    for(long i=0;i<N;i++){
        cin>>a[i];
        m+=a[i]-1;
    }
    
    cout<<m<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    
    for(ll N;cin>>N,N;){
        vector<string>s(N);
        for(ll i = 0; i < N; i++){
            cin >> s[i];
        }
        ll ans = 100;
        for(ll k = 1; k <= 50; k++){
            set<string>S;
            for(ll i = 0; i < N; i++){
                string tmp = "";
                tmp += s[i][0];
                for(ll j = 1; j < s[i].size(); j++){
                    ll flg = 0;
                    if(s[i][j-1] == 'a')flg = 1;
                    if(s[i][j-1] == 'i')flg = 1;
                    if(s[i][j-1] == 'u')flg = 1;
                    if(s[i][j-1] == 'e')flg = 1;
                    if(s[i][j-1] == 'o')flg = 1;
                    if(flg && tmp.size() < k)tmp += s[i][j];
                }
                S.insert(tmp);
            }
            // if(ans == 100 && S.size() == N){
            //     for(set<string>::iterator it = S.begin(); it != S.end(); it++){
            //         cout << *it << endl;
            //     }
            // }
            if(S.size() == N)ans = min(ans, k);
        }
        if(ans == 100)cout << -1 << endl;
        else cout << ans << endl;
    }
    
    return 0;    
}


Measured memory_bytes: 3224
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

using namespace std;
typedef long long ll;

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

	int a[100000];
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	sort(a, a + n, greater<int32_t>());

	int max_value = -1, max_second = -1;
	for (int i = 1; i < n; i++)
		if (max_value < min(a[i], a[0] - a[i])) {
			max_value = min(a[i], a[0] - a[i]);
			max_second = a[i];
		}

	printf("%d %d\n", a[0], max_second);

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int i,j;
	int n,x,y;
	cin>>n>>x>>y;
	x--; y--;
	VVI d(n,VI(n,inf));
	for(i=0;i<n;i++){
		for(j=i;j<n;j++){
			d[i][j]=j-i;
			d[j][i]=j-i;
		}
	}
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			chmin(d[i][j],d[i][x]+1+d[y][j]);
			chmin(d[i][j],d[i][y]+1+d[x][j]);
			d[j][i]=d[i][j];
		}
	}
	VI cnt(n,0);
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			cnt[d[i][j]]++;
			//cout<<i<<" "<<j<<" "<<d[i][j]<<endl;
		}
	}
	for(i=1;i<n;i++) cout<<cnt[i]<<endl;

}

Measured memory_bytes: 31616
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define EPS 1e-9
#define INF 5e18
#define MOD 1000000007

#define all(x) begin(x), end(x)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int N, M, X, numRow [300010], numCol [300010];
set<pair<int, int>> lol;

int main(){
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    cin >> N >> M >> X;
    int mr = 0, mc = 0;
    for(int i = 0; i < X; i++){
        int x, y; cin >> x >> y; x--; y--;
        lol.insert({x, y});
        numRow[x]++; numCol[y]++;
        mr = max(mr, numRow[x]), mc = max(mc, numCol[y]);
    }
    vector<int> maxRow, maxCol;
    for(int i = 0; i < N; i++){
        if(numRow[i] == mr)
            maxRow.push_back(i);
    }
    for(int i = 0; i < M; i++){
        if(numCol[i] == mc)
            maxCol.push_back(i);
    }
    int ret = mr+mc-1;
    for(int x : maxRow)
        for(int y : maxCol){
            if(lol.find({x, y}) != lol.end()) continue;
            ret = mr+mc;
            break;
        }
    cout << ret << '\n';
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/


Measured memory_bytes: 23788
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char a = str.charAt(0);
        char b = str.charAt(3);
        boolean flag = false;
        if (a == str.charAt(1) && a == str.charAt(2)) {
            flag = true;
        }
        if (b == str.charAt(1) && b == str.charAt(2)) {
            flag = true;
        }
        System.out.println(flag ? "Yes" : "No");

    }
}

Measured memory_bytes: 21844
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

ll power(ll x,ll y){
	ll t=1;
	while(y>0){
		if(y%2) y-=1,t=t*x%mod;
		else y/=2,x=x*x%mod;
	}
return t;
}

ll h[N];

int main(){
	ll n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	REP(i,n)
		scanf("%lld",&h[i]);
	sort(h,h+n);
	ll l=1,r=(h[n-1]+b-1)/b,mid;
	while(l<r){
		mid=(l+r)/2;
		ll spent=0;
		REP(i,n){
			if (h[i]>mid*b)
				spent+=(h[i]-mid*b+a-b-1)/(a-b);
		}
		if (spent>mid) l=mid+1;
		else r=mid;
	}
	mid=(l+r)/2;
	printf("%lld\n",mid);
	return 0;
}

Measured memory_bytes: 1024
// E - Almost Everywhere Zero
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
string N;
int K;
int lt = 0, eq = 1;//lt: <, eq: =
int dp[101][2][4];// digit DP, [|N|+1: 1 origin][lt|eq][k:0~3]

int main(){
	cin>>N>>K;
	int dn = N.size();
	dp[0][eq][0] = 1;
	rp(i,0,dn){
		int di = N[i] - '0';
		rp(k,0,4){
			dp[i+1][lt][k] = dp[i][lt][k] * 1 + dp[i][eq][k] * (di?1:0);
			if(k) dp[i+1][lt][k] += dp[i][lt][k-1] * 9 + dp[i][eq][k-1] * max(0,di-1);
			if(dp[i][eq][k]) dp[i+1][eq][k+(di>0)] = 1;
		}
	}
	cout<< dp[dn][lt][K] + dp[dn][eq][K] <<endl;
}

Measured memory_bytes: 256