akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mp make_pair
#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++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int W,H,N;
cin>>W>>H>>N;
vector<int>x(N),y(N),a(N);
map<int,int> c;
c[1]=0;
c[2]=W;
c[3]=0;
c[4]=H;
rep(i,N){
    cin>>x[i]>>y[i]>>a[i];
        if(a[i]==1){
            c[1]=max(c[1],x[i]);
        }
        else if(a[i]==2){
            c[2]=min(c[2],x[i]);
        }
        else if(a[i]==3){
            c[3]=max(c[3],y[i]);
        }
        else if(a[i]==4){
            c[4]=min(c[4],y[i]);
        }
}
int S=0;
if((c[2]-c[1])>=0 && (c[4]-c[3])>=0){
    S=(c[2]-c[1])*(c[4]-c[3]);
}
cout<<S<<endl;

//system("pause");
return 0;
}

Measured memory_bytes: 256
N = int(input())
T, A = 1, 1
for i in range(N):
    t, a = map(int, input().split())
    if T % t == 0:
        n1 = T // t
    else:
        n1 = T // t + 1
    if A % a == 0:
        n2 = A // a
    else:
        n2 = A // a + 1
    #print('--',n1, n2)
    n = max(n1, n2)
    T = n*t
    A = n*a
    #print('--------',T, A)
    
print(T+A)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include<math.h>
int main(){
    char s[1001], t[1001];
    scanf("%s", s);
    scanf("%s", t);
    int tam= strlen(s)- strlen(t)+1;
    int min= 1002;
    int tt= strlen(t);
    
    for(int i=0; i<tam;++i){
        int num=0, cont=0;
        for(int j=i; j< tt+i;++j){
            if(s[j]!= t[num])
                cont++;
            num++;
        }
        if(cont < min)
            min=cont;
    }
    printf("%d\n", min);
    return 0;
}

Measured memory_bytes: 1676
// user:halahen
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1010;
long long i,j,k;
long long n,m,t1,t2,t3,t4,x,y;
long long a[maxn],b[maxn],f[maxn],ans[maxn];
long long read(){
	long long tot=0,fh=1;
	char c=getchar();
	while ((c<'0')||(c>'9')){ if(c=='-') fh=-1; c=getchar(); }
	while ((c>='0')&&(c<='9')){ tot=tot*10+c-'0'; c=getchar(); }
	return tot*fh;
}
long long dis(long long x,long long y,long long tx,long long ty){
	return (abs(x-tx)+abs(y-ty));
}
int main(){
	n=read();
	for (i=1;i<=n;i++){
		a[i]=read(); b[i]=read();
		if ((((a[i]+b[i])%2)+2)%2==0){
			t1++;
		}
	}
	if ((t1!=0)&&(t1!=n)){
		printf("-1\n"); return 0;
	}
	if (t1==n){
		m=32;
		f[1]=1; f[2]=1;
		for (i=3;i<=m;i++){
			f[i]=f[i-1]*2;
		}
	}
	else{
		m=31;
		f[1]=1;
		for (i=2;i<=m;i++){
			f[i]=f[i-1]*2;
		}
	}
	for (i=1;i<=m/2;i++) swap(f[i],f[m-i+1]);
	printf("%lld\n",m);
	for (i=1;i<=m;i++) printf("%lld ",f[i]); printf("\n");
	for (i=1;i<=n;i++){
		x=0; y=0;
		for (j=1;j<=m;j++){
			t1=dis(x-f[j],y,a[i],b[i]);
			t2=dis(x+f[j],y,a[i],b[i]);
			t3=dis(x,y-f[j],a[i],b[i]);
			t4=dis(x,y+f[j],a[i],b[i]);
			if ((t1<=t2)&&(t1<=t3)&&(t1<=t4)){
				ans[j]=1;
				x=x-f[j]; y=y;
			}
			else{
				if ((t2<=t1)&&(t2<=t3)&&(t2<=t4)){
					ans[j]=2;
					x=x+f[j]; y=y;
				}
				else{	
					if ((t3<=t2)&&(t3<=t1)&&(t3<=t4)){
						ans[j]=3;
						x=x; y=y-f[j];
					}	
					else{
						if ((t4<=t2)&&(t4<=t3)&&(t4<=t1)){
							ans[j]=4;
							x=x; y=y+f[j];
						}
					}
				}
			}
		}
		if ((x!=a[i])||(y!=b[i])){
			printf("NO");
		}
		for (j=1;j<=m;j++){
			if (ans[j]==1) printf("L");
			if (ans[j]==2) printf("R");
			if (ans[j]==3) printf("D");
			if (ans[j]==4) printf("U");
		}
		printf("\n");
	}
	return 0;
}

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


int main()
{
    char a[150];
    cin>>a;
    long long k;
    cin>>k;
    int num = 0;
    int len = strlen(a);
    while(a[num] == '1')
    {
        num++;
    }
    if(!num) cout<<a[0]<<endl;
    else if(num >= k)
        cout<<'1'<<endl;
    else
        cout<<a[num]<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
using graph = vector<vector<int>>;
using ll = long long;
using p = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < (n); ++i)
    {
        cin >> a[i];
    }

    vector<int> b(1000005);
    for (int i = 0; i < (n); ++i)
    {
        if (b[a[i]] != 0)
        {
            b[a[i]] = 2;
            continue;
        }
        for (int j = a[i]; j < (1000005); j += a[i])
        {
            b[j]++;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        if (b[a[i]] == 1)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7960
r, c = map(int, input().split())
matrix = [[0 for j in range(c+1)] for i in range(r+1)]

for i in range(r):
    l = list(map(int, input().split()))
    l.append(sum(l))
    for j in range(c+1):
        matrix[i][j] = l[j]
        matrix[r][j] += l[j]

for row in matrix:
    row_str = list(map(str, row))
    print(' '.join(row_str))


Measured memory_bytes: 5696
import kotlin.math.*

//private val inp = java.io.File("in")
private val inp = System.`in`
private val reader = inp.bufferedReader()
private val wr = java.io.PrintWriter(System.out.bufferedWriter())

private fun readLn(): String = reader.readLine()
private fun readInt(): Int = readLn().toInt()
private fun readStrs(): List<String> = readLn().split(" ")
private fun readInts(): IntArray = readStrs().map { it.toInt() }.toIntArray()
private fun readChars(): CharArray = readStrs().map { it.single() }.toCharArray()

fun main() {
    val (s, w) = readInts()
    println(if (w >= s) "unsafe" else "safe")
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  string s[H];
  
  for (int i = 0; i < H; ++i) {
    cin >> s[i];
  }
    
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      
      if (s[i].at(j) == '#') continue;
      
      char mine = '0';
      for (int k = i - 1; k <= i + 1; ++k) {
        for (int l = j - 1; l <= j + 1; ++l) {
          if (k < 0 || H <= k) continue;
          if (l < 0 || W <= l) continue;
          if (s[k].at(l) == '#') mine++;
       }
      }
      s[i].at(j) = mine;
    }
  }
  
  for (int i = 0; i < H; ++i) {
    cout << s[i] << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
   
using namespace std;
   
struct Card {
   
    char mark;
    int value;
   
};
   
void bubbleSort (struct Card C[], int n) {
   
    int i, j;
    Card v;
   
    for (i = 0; i < n; i++) {
   
        for (j = n - 1; j >= i + 1; j--) {
   
            if (C[j].value < C[j - 1].value) {
   
                v = C[j];
                C[j] = C[j - 1];
                C[j - 1] = v;
   
            }
   
        }
   
    }
   
}
   
void selectionSort (struct Card C[], int n) {
   
    int i, j, minj;
    Card v;
   
    for (i = 0; i < n; i++) {
   
        minj = i;
   
        for (j = i; j < n; j++) {
   
            if (C[j].value < C[minj].value) {
   
                minj = j;
   
            }
   
        }
   
        v = C[i];
        C[i] = C[minj];
        C[minj] = v;
   
    }
   
}
   
void print (struct Card C[], int n) {
   
    int i;
   
    for (i = 0; i < n; i++) {
   
        if (i > 0) {
   
            cout << " ";
   
        }
   
        cout << C[i].mark << C[i].value;
   
    }
   
    cout << endl;
   
}
   
bool isStable (struct Card C1[], struct Card C2[], int n) {
   
    int i;
   
    for (i = 0; i < n; i++) {
   
        if (C1[i].mark != C2[i].mark) {
   
            return false;
   
        }
   
    }
   
    return true;
   
}
   
int main () {
   
    Card C1[100], C2[100];
    int i, n;
   
    cin >> n;
   
    for (i = 0; i < n; i++) {
   
        cin >> C1[i].mark >> C1[i].value;
   
    }
 
    for (i = 0; i < n; i++) {
 
        C2[i] = C1[i];
 
    }
   
    bubbleSort (C1, n);
    selectionSort (C2, n);
   
    print (C1, n);
    cout << "Stable" << endl;
   
    print (C2, n);
    if (isStable (C1, C2, n)) {
   
        cout << "Stable" << endl;
   
    } else {
   
        cout << "Not stable" << endl;
   
    }
   
    return 0;
   
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
const int calk[] = {4, 9, 4};

typedef struct {
  int i;
  int p;
  int q;
  int r;
} Eiyo;

int main(void){
  int N;
  while(cin >> N, N){
    vector<Eiyo> v(N);
    int cnt = 0;
    int P, Q, R, C;
    for(int i=0; i < N; i++){
      int j, p, q, r;
      cin >> j >> p >> q >> r;
      Eiyo tmp = {j, p, q, r};
      v[i] = tmp;
    }
    cin >> P >> Q >> R >> C;
    for(int i=0; i < N; i++){
      if(v[i].p != -1 && v[i].p <= P && v[i].q <= Q && v[i].r <= R && (v[i].p*calk[0]+v[i].q*calk[1]+v[i].r*calk[2]) <= C){
        cout << v[i].i << endl;
        cnt++;
      }
    }
    if(cnt == 0)
      cout << "NA" << endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    ll h, w, a, b;
    cin >> h >> w >> a >> b;

    rep(i, b){
        rep(j, a) cout << 0;
        rep(j, w-a) cout << 1;
        cout << endl;
    }
    rep(i, h-b){
        rep(j, a) cout << 1;
        rep(j, w-a) cout << 0;
        cout << endl;
    }
}


Measured memory_bytes: 1280
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define scan(n,v) v.resize(n); rep(i,n){ cin>>v[i];}
#define MOD 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define be begin
#define pb push_back
#define fi first
#define se second
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
//------------------------------------------------------
ll n,x;
vector<ll> a;
void input(){
    cin>>n>>x;
    scan(n,a);
}
void src(){
    ll ans=0;
    sort(ALL(a));
    rep(i,n){
        x-=a[i];
        if(x>=0){ans++;}else{break;}
    }
    if(x>0) ans--;
    cout<<ans;
}   
int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <vector>
# include <queue>
# include <cstring>
# include <cstdio>
# include <algorithm>
# include <cmath>
# include <cstdlib>
# include <map>
# include <set>
# define eps 1e-15
# define inf 2000000000
# define MAXN 100010
# define MOD 1000000007
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int k = (int) (log((double)n)/log(2.0));
	printf("%d\n",1<<k);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void)
{
	int i,sum,g,p,N,flag;
	char s[100003];
	scanf("%s",s);
	N=strlen(s);
	g=0;
	p=0;
	for(i=0;i<=N-1;i++){
		if(s[i]=='g'){
			g++;}
			else
			p++;}
			
	printf("%d",N/2-p);
	
		
	return 0;
}

Measured memory_bytes: 256
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    string s;
    cin >> s;
    int n = s.length();
    vector<int> dp(n), dpE(n);

    dp[n-1] = s[n-1] - '0';
    dpE[n-1] = '9' - s[n-1] + 1;
    for (int i = n-2; i >= 0; i--) {
        dp[i] = s[i] - '0' + std::min(dp[i+1], dpE[i+1] + 1);
        dpE[i] = std::min('9' - s[i] + 1 + dp[i+1], '9' - s[i] + dpE[i+1]);
    }

    cout << std::min(dp[0], 1 + dpE[0]) << "\n";
}



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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  string s;
  cin >> s;

  int a, b, c, d;
  a = s[0]-'0'; b = s[1]-'0'; c = s[2]-'0'; d = s[3]-'0';
  
  if(a-b-c-d == 7) printf("%d-%d-%d-%d=7\n",a,b,c,d);
  else if(a-b-c+d == 7) printf("%d-%d-%d+%d=7\n",a,b,c,d);
  else if(a-b+c+d == 7) printf("%d-%d+%d+%d=7\n",a,b,c,d);
  else if(a-b+c-d == 7) printf("%d-%d+%d-%d=7\n",a,b,c,d);
  else if(a+b+c-d == 7) printf("%d+%d+%d-%d=7\n",a,b,c,d);
  else if(a+b-c+d == 7) printf("%d+%d-%d+%d=7\n",a,b,c,d);
  else if(a+b-c-d == 7) printf("%d+%d-%d-%d=7\n",a,b,c,d);
  else if(a+b+c+d == 7) printf("%d+%d+%d+%d=7\n",a,b,c,d);


}

Measured memory_bytes: 3732
#include <iostream>
 #include <vector>
 using namespace std;
 int main(){
 int N;
 cin>>N;
 vector<int> A(N);
 for(int i=0;i<N;i++) cin>>A[i];

 vector<int> rev(N);
 for(int i=0;i<N;i++) rev[A[i]-1]=i+1;
 for(int i=0;i<N;i++) cout<<rev[i]<<endl;
 return 0;
 }


Measured memory_bytes: 3896
s = list(input())
a = int(s[0]+s[1])
b = int(s[2]+s[3])

if (a==0 and 1 <= b <= 12) or (a >= 13 and 1 <= b <= 12):
  print("YYMM")
elif (b==0 and 1 <= a <= 12) or (b >= 13 and 1 <= a <= 12):
  print("MMYY")
elif 1 <= a<= 12 and 1<=b<=12:
  print("AMBIGUOUS")
else:
  print("NA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll N,K;

ll mod_pow(ll x,ll y){
    ll ret = 1;
    while(y){
        if(y & 1) ret = (ret*x) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return ret;
}


int main(){
    cin >> N >> K;
    ll ans = 0;
    vector<ll> v(K+1,0);
    for(ll i=K; i>=1; i--){
        ll cnt = mod_pow(K/i, N);
        for(ll j=2;i*j<=K;j++){
            cnt = (cnt + mod) - v[i*j];
            cnt %= mod;
        }
        v[i] = cnt;
        ans += (i * cnt) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}


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

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

using namespace std;

int main() {
  int64_t n, d;
  std::cin >> n >> d;
  std::vector<int64_t> x(n), y(n);
  rep(i, n) { std::cin >> x[i] >> y[i]; }

  int num = 0;
  rep(i, n) {
    if ((x[i] * x[i] + y[i] * y[i]) <= (d * d)) {
      num++;
    }
  }

  std::cout << num << std::endl;
  return 0;
}


Measured memory_bytes: 6412
#include <bits/stdc++.h>
using namespace std;
using ld = long double;

ld p[101010];

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

	int n;
	cin >> n;

	vector<ld> v(n);
	for (int i = 0; i < n; ++i) cin >> v[i];

	p[0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = i; j >= 0; --j) {
			p[j] *= (1 - v[i-1]);
			if (j != 0) p[j] += p[j-1] * v[i-1];
		}
	}
	ld s = 0;
	for (int i = n/2+1; i <= n; ++i) s += p[i];
	cout << fixed << setprecision(10) << s << '\n';
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  string s[N];
  int a[4] = {0,0,0,0};
  string str[4] = {"AC","WA","TLE","RE"};
  for (int i = 0; i < N; i++) {
    cin >> s[i];
    if (s[i] == "AC") {
      a[0]++;
    } else if (s[i] == "WA") {
      a[1]++;
    } else if (s[i] == "TLE") {
      a[2]++;
    } else {
      a[3]++;
    }
  }

  for (int i = 0; i < 4; i++) {
    cout << str[i] << " " << "x " << a[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 6728
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion

void solve() {
    vector<int> a(5);
    for (int i=0; i<6; i++) {
        int tmp;
        cin >> tmp;
        a.at(tmp)++;
    }
    if (count(a.begin(), a.end(), 3)) cout << "NO" << "\n";
    else cout << "YES" << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
a = list(map(int,input().split()))
n = a[0]
k = a[1]
b = list(map(int,input().split()))
c = [0 for x in range(0,len(b))]


for num in b:
    c[num-1] = c[num-1]+1

c.sort()
ans = 0
for i in range(0,len(c)-k):
    ans += c[i]
     
print(ans)

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

using LL = long long int;
using uLL = unsigned long long int;
using uint = unsigned int;
using ld = long double;

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(0);
    LL n, k;
    cin >> n >> k;
    LL r = n%k;
    cout << min(abs(r-k), r) << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

using namespace std;
const int MX = 1e6;
const int inf = 1e9;
//const int mod = 1e9+7;
using ll = long long;
const int mod = 1000000007;

int p[105];
signed main(){
    int x, n;
    cin >> x >> n;
    rep(i,n) {
        int a;
        cin >> a;
        p[a]++;
    }

    int ans = 0;
    int len = MX;
    rep(i,105) {
        if(p[i]==0) {
            if(len>abs(x-i)) {
                len = abs(x-i);
                ans = i;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define endl "\n"
using namespace std;

int main()
{
 	int a, b;
 	cin >> a >> b;

 	int i;
 	double ans = 0;
 	for(i = 1; i <= a; i ++)
 	{
 		double res = 1.0 / a;
 		int counter = i;
 		while(counter < b)
 		{
 			counter *= 2;
 			res /= 2;
 		}

 		ans += res;
 	}

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

const int mod=1e9+7;

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    cout << ((a%2)*(b%2)*(c%2)==0?0:min({a*b,b*c,c*a})) << endl;
}

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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

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

long double N, K;

ll mod_pow(ll base, ll index) {
    if(index == 0) return 1LL;
    ll res = mod_pow((base * base), index / 2);
    if(index & 1) (res *= base);
    return res;
}

int main() {
    cin >> N >> K;
    double ans = 0;
    REP(i, N) {
        ll now = i + 1;
        while(now < K) {
            now *= 2;
        }
        ans += (double)1 / (now / (i + 1));
    }
    cout << std::setprecision(12) << ans / N << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
typedef long long ll;
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
int main(){
    int n,m,c;cin>>n>>m>>c;
    vector<int> b(m);
    vector<vector<int>> a(n,vector<int>(m,0));
    for(auto& x:b){
        cin>>x;
    }
    int ans=0;
    rep(i,n){
        int sum=0;
        rep(j,m){
            cin>>a[i][j];
            sum+=a[i][j]*b[j];
        }
        sum+=c;
        if(sum>0){
            ans++;
        }

    }
    cout<<ans <<endl;
    

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
     Scanner sc = new Scanner(System.in);
     while(true){
      int x = sc.nextInt();
      int y = sc.nextInt();
      if ( x == 0 && y == 0){
       break;
      }
      if( x > y ){
       System.out.println(y + " " + x);
      }else{
       System.out.println(x + " " + y);
      }
     } 
    }
}


Measured memory_bytes: 34760
import scala.io.StdIn

object Main extends App {
  val Array(w, h, x, y, r) = StdIn.readLine().trim.split(' ').map(_.toInt)

  
  println(if(x - r < 0 || x + r > w || y - r < 0 || y + r > h) "No" else "Yes")
  
}



Measured memory_bytes: 44076
#include<bits/stdc++.h>//本当は必要なヘッダファイルだけインクルードするべきです
using namespace std;//本当は個別にusingするか変数や関数ごとにstd::をつけるべきです
//本当は関数内に宣言し明示的に初期化するべきです
int n;
void selectionSort(vector<char>A,vector<int>B){
  bool flag=false;
  map<int,int>c;
  for(int i=0;i<n;i++){
    c[B[i]]++;
    if(c[B[i]]==2){
      for(int j=i+1;j<n;j++){
        if(B[i]>B[j]){
          flag=true;
          break;
        }
      }
    }
  }
  for(int i=0;i<n;i++){
    int min_id=i;
    for(int j=i+1;j<n;j++){
      if(B[j]<B[min_id]){
        min_id=j;
      }
    }
    swap(A[i],A[min_id]);
    swap(B[i],B[min_id]);
  }
  for(int i=0;i<n;i++)cout<<A[i]<<B[i]<<(i==n-1?'\n':' ');
  cout<<(flag?"Not stable":"Stable")<<endl;
}
void bubbleSort(vector<char>A,vector<int>B){
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      if(B[j]<B[j-1]){
        swap(B[j],B[j-1]);
        swap(A[j],A[j-1]);
      }
    }
  }
  for(int i=0;i<n;i++)cout<<A[i]<<B[i]<<(i==n-1?'\n':' ');
  cout<<"Stable"<<endl;
}
int main(void){
  cin>>n;
  vector<char>A(n);
  vector<int>B(n);
  char c;
  int t;
  for(int i=0;i<n;i++){
    cin>>c>>t;
    A[i]=c;
    B[i]=t;
  }
  bubbleSort(A,B);
  selectionSort(A,B);
  return 0;
}



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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int r, g, b, ans=0;
    r = N/R;
    g = N/G;

    rep(i, r+1) {
        rep(j, g+1) {
            if (((N - i*R - j*G) >= 0) && (N - i*R - j*G) % B == 0) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys

def is_ok(a,b, k):
    return (a - b) * (a-b) <= k * k

def main():

    points = []

    for line in sys.stdin:
        line = line.rstrip()
        a = int(line)
        points.append(a)


    s = points[5]
    for i in range(5):
        p = points[i]
        for k in range(i+1, 5):
            q = points[k]

            if not is_ok(p, q, s):
                print(':(')
                return 0

    print('Yay!')
    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define p(x) cout << x << endl;

#define MOD 1000000007
#define PI 3.14159265359

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

    string s;
    cin >> s;

    cout << s[0] 
    << s.size() - 2 
    << s[s.size() - 1] 
    << endl;
}


Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math

N,D = map(int, sys.stdin.readline().rstrip().split())
ds = list(map(int, sys.stdin.readline().rstrip().split()))
Q, = map(int, sys.stdin.readline().rstrip().split())
qs = list(map(int, sys.stdin.readline().rstrip().split()))


targets = [1]
for d in reversed(ds):
    if(d//2 < targets[-1]):
        targets.append(targets[-1] + d)
    else:
        targets.append(targets[-1])
targets.reverse()

current = D
can_avoids = []
for i in range(N):
    d = ds[i]
    target = targets[i+1]
    #print("current:", current)
    can_avoids.append(current >= target)
    if d//2 < current:
        current -= d
        current = max(-current, current)

#print(targets)
#print(can_avoids)

for q in qs:
    if (can_avoids[q-1]):
        print("YES")
    else:
        print("NO")


exit(0)


Measured memory_bytes: 80052
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
int K;
int A[200000];
int nx[200000+1];
int sm[200000+1];
int main(){
  int e98WHCEY;
  int x;
  int y;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(e98WHCEY=(0);e98WHCEY<(K);e98WHCEY++){
    int i;
    for(i=(0);i<(N+1);i++){
      sm[i] = 0;
    }
    for(i=(0);i<(N);i++){
      x =max_L(0, i - A[i]);
      y =min_L(N-1, i + A[i]);
      sm[x]++;
      sm[y+1]--;
    }
    nx[0] = sm[0];
    for(i=(1);i<(N);i++){
      nx[i] = nx[i-1] + sm[i];
    }
    for(i=(0);i<(N);i++){
      if(A[i]!=nx[i]){
        break;
      }
    }
    if(i==N){
      break;
    }
    for(i=(0);i<(N);i++){
      A[i] = nx[i];
    }
  }
  {
    int jZyWAPpY;
    if(N==0){
      wt_L('\n');
    }
    else{
      for(jZyWAPpY=(0);jZyWAPpY<(N-1);jZyWAPpY++){
        wt_L(A[jZyWAPpY]);
        wt_L(' ');
      }
      wt_L(A[jZyWAPpY]);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N, K, A[2d5];
// int nx[2d5+1], sm[2d5+1];
// {
//   int x, y;
// 
//   rd(N,K,A(N));
// 
//   rep(K){
//     rep(i,N+1) sm[i] = 0;
//     rep(i,N){
//       x = max(0, i - A[i]);
//       y = min(N-1, i + A[i]);
//       sm[x]++;
//       sm[y+1]--;
//     }
// 
//     nx[0] = sm[0];
//     rep(i,1,N) nx[i] = nx[i-1] + sm[i];
// 
//     rep(i,N) if(A[i]!=nx[i]) break;
//     if(i==N) break;
//     rep(i,N) A[i] = nx[i];
//   }
// 
//   wt(A(N));
// }


Measured memory_bytes: 7976
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll H,W,h,w;
	cin>>H>>W>>h>>w;
	vector<vector<ll>> a(H,vector<ll>(W));
	if(H%h==0&&W%w==0) {
		cout<<"No"<<endl;
		return 0;
	}
	REP(i,H) {
		REP(j,W) a[i][j]=INF/(h*w);
	}
	for(ll i=h-1; i<H; i+=h) {
		for(ll j=w-1; j<W; j+=w) {
			a[i][j]=-(INF/(h*w)*(h*w-1)+1);
		}
	}
	cout<<"Yes"<<endl;
	REP(i,H) {
		REP(j,W) {
			cout<<a[i][j];
			if(j!=W-1) cout<<" ";
			else cout<<endl;
		}
	}
}


Measured memory_bytes: 4736
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Jan 27 17:52:26 2019
//
package main

import "fmt"

func isPrime(n int) bool {
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	var N int
	fmt.Scan(&N)

	ans := make([]int, 0)
	for i := 5; i <= 55555; i += 5 {
		if isPrime(i + 1) {
			ans = append(ans, i+1)
		}
	}

	for i := 0; i < N; i++ {
		if i != 0 {
			fmt.Print(" ")
		}
		fmt.Print(ans[i])
	}
	fmt.Println()
}


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

using namespace std;

int main() {
	
	long long n,k;
	cin >> n >> k;

	vector<long long> a(n + 1);
	vector<long long> b(n + 1,0);
	vector<long long> c(n + 1, 0);

	for (long long i = 1; i <= n; i++) {
		cin >> a[i];
	}

	long long counter = 1;
	long long numm = 1;
	long long nextnum=0;
	long long total = 0;
	while (counter <= n) {
		c[counter] = a[numm];
		b[numm] = 1;
		nextnum = a[numm];
		numm = nextnum;
		if (b[numm] == 1) {
			total = counter;
			break;
		}
		counter++;
	}
	long long loopp = 0;
	for (long long i = 1; i <= counter; i++) {
		if (c[i] == a[nextnum]) {
			loopp = i;
			break;
		}
	}

	if (k <= counter) {
		cout << c[k] << endl;
		return 0;
	}
	else {
		k = k - loopp + 1;
		k = k % (counter - loopp + 1);
		if (k != 0) {
			cout << c[k + loopp - 1] << endl;
		}
		else {
			cout << c[counter] << endl;
		}
		return 0;
	}


	return 0;
}

Measured memory_bytes: 8008
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    int n, k; cin >> n >> k;
    string s; cin >> s;
    s[k-1] = tolower(s[k-1]);
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, ll>;

// 10 で割り切れる <==> 2 で割り切れる かつ 5 で割り切れる
// f(N) が 2 で割り切れる回数と f(N) が 5 で割り切れる回数の min を求めればよい。
int main()
{
    ll N;
    cin >> N;
    if (N & 1) // 奇数の時、f(N) も奇数なので、2で割り切ることができない。よってゼロが答え。
    {
        cout << 0 << endl;
        return 0;
    }
    // 偶数の時, 二重階乗の性質より
    // min = (5で割り切れる回数)
    ll ans = 0;
    ll deno = 10;
    while(deno <= N)
    {
        ans += N / deno;
        deno *= 5;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from itertools import accumulate

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


def main():
    N, *A = map(int, read().split())

    csum = [0]
    csum.extend(accumulate(A))

    ans = 0
    for i, a in enumerate(A):
        ans = (ans + a * (csum[N] - csum[i + 1]) % MOD) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 110432
#include <iostream>
#include <complex>
#include <cmath>
#include <cstdio>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    string str;
    cin >> str;
    int res = 0;
    int i = 0;
    while(i < str.size()) {
        int J = 0, O = 0, I = 0;
        while(i < str.size() && str[i] == 'J') {
            J++;
            i++;
        }
        while(i < str.size() && str[i] == 'O') {
            O++;
            i++;
        }
        while(i < str.size() && str[i] == 'I') {
            I++;
            i++;
        }
        if (J >= O && I >= O) {
            res = max(res, O);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n,i,a,ord[100010];
  cin >> n;
  for (i=1;i<=n;i++){
    cin >> a;
    ord[a]=i;
  }
  for (i=1;i<=n;i++) cout << ord[i] << ' ';
  cout << endl;
  return 0;
}

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

const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

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

  string s;
  cin >> s;
  int a = 0, b = 0;
  for (int i = 0; i < sz(s); i++) {
    if (s[i] == '0') a++;
    else b++;
  }
  cout << min(a,b)*2 << endl;
  return 0;
}


Measured memory_bytes: 512
#include<vector>
#include<utility>
#include<cmath>
class prime_factorizer:private std::vector<std::pair<unsigned long long,unsigned long long>>{
private:
    using std::vector<std::pair<unsigned long long,unsigned long long>>::size_type;
public:
    using std::vector<std::pair<unsigned long long,unsigned long long>>::begin;
    using std::vector<std::pair<unsigned long long,unsigned long long>>::end;
    static std::vector<bool>sieve(unsigned long long n)
    {
        std::vector<bool>is_prime(n+1,true);
        is_prime[0]=is_prime[1]=false;
        for(size_type i=2;i*i<=n;++i){
            if(is_prime[i]){
                for(size_type j=i*2;j<n+1;j+=i){
                    is_prime[j]=false;
                }
            }
        }
        return is_prime;
    }
    prime_factorizer(unsigned long long n)
    {
        std::vector<bool>is_prime=sieve(sqrt(n));
        for(size_type i=2;i<is_prime.size();++i){
            if(is_prime[i]){
                unsigned long long e=0;
                while(n%i==0){
                    ++e;
                    n/=i;
                }
                if(e!=0)emplace_back(i,e);
            }
        }
        if(n!=1)emplace_back(n,1);
    }
};

#include"bits/stdc++.h"
using namespace std;
using ll=long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T=ll>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
int main()
{
    ll n=in();
    cout<<n<<':';
    prime_factorizer pf(n);
    for(auto f:pf){
        for(ll i=0;i<f.second;++i){
            cout<<' '<<f.first;
        }
    }
    cout<<endl;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int K;
    cin >> K;
    ll sum = 0;
    for (int a = 1; a < K + 1; a++) {
        for (int b = 1; b < K + 1; b++) {
            for (int c = 1; c < K + 1; c++) {
                sum += (ll)gcd(a, gcd(b, c));
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if (abs(x - a) < abs(x - b)) {
    cout << "A" << endl;
  } else {
    cout << "B" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
#include<cmath>
int main()
{
    fastio;
    float l,r,d;
    cin>>l>>r>>d;
    int a=ceil(l/d);
    int b=floor(r/d);
    cout<<b-a+1<<endl;
    return 0;
}
    




Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<int, vector<int>, greater<int> > PQG;
#define REP(i, a, n) for(ll i = (ll) a;i < (ll) n;i++)
#define fi first
#define se second
#define pb push_back
#define INF 1000000009
#define MOD 1000000007
#define MAXN 100005
#define MAXC 100000000000014
#define MAXV 1000000009

int n, a[MAXN], ans;
map<int, int> mp;

int main()
{
    cin >> n;
    REP(i, 0, n){
        cin >> a[i];
        mp[a[i]]++;
    }
    map<int, int> :: iterator p;
    for(p = mp.begin();p != mp.end();++p){
        int x = p->first;
        int n = p->second;
        if(x < n) ans += n - x;
        else if(x > n) ans += n;
    }
    cout << ans << endl;



    return 0;
}
















Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+18;

int main() {
    ios::sync_with_stdio(false);
    Int n, m, c;
    cin >> n >> m >> c;
    Int res = 0;
    vector<Int> b(m);
    for (Int i = 0; i < m; i++) cin >> b[i];
    for (Int i = 0; i < n; i++) {
        Int x = c;
        for (Int j = 0; j < m; j++) {
            Int a;
            cin >> a;
            x += a * b[j];
        }
        if (x > 0) res++;
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 256
N,M  = (int(x) for x in input().split())
Flag = True
Num  = list('?'*N)
for T in range(0,int(M)):
    s,c = input().split()
    if ([s,c]==['1','0'] and N>=2) or (Num[int(s)-1]!='?' and Num[int(s)-1]!=c):
        Flag = False
        break
    else:
        Num[int(s)-1] = c
if Flag:
    if Num[0]=='?' and N==1:
        print('0')
    elif Num[0]!='?' and N==1:
        print(Num[0])
    elif Num[0]=='?' and N>=2:
        Num[0] = '1'
        Num = ['0' if x=='?' else x for x in Num]
        print(''.join(Num))
    else:
        Num = ['0' if x=='?' else x for x in Num]
        print(''.join(Num))
else:
    print('-1')

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = 1e9+7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n),  keta(21, -1);
	rep(i, n) cin >>a[i];
	ll ans = 0, chu =0;
	rep(i, n){
		rep(j, 21) if(a[i]>>j &1){
			chu = max<ll>(chu, keta[j] + 1);
			keta[j] = i;
		}
		ans += i - chu +1;
	}
	cout << ans <<"\n";
	return 0;
}


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


int main() {
    int n,t,a; cin >> n >> t >> a;
    vector<ll> h(n);
    rep(i,n){
        cin >> h[i];
        h[i]*=6;
    }
    ll c=1000*(t-a);
    rep(i,n){
        h[i]=abs(h[i]-c);
    }
    int ans=0;
    ll min=10000000000;
    rep(i,n){
        if(min>h[i]){
            ans=i+1;
            min=h[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int N, H[100005], M, b, i;
    scanf("%d", &N);
    M=0; b=1;
    for (i=1; i<=N; i++) {
        scanf("%d", &H[i]);
        if (H[i]>M) M=H[i];
        else if (H[i]<=M-2) {
            printf("No");
            b=0;
        }
        if (b==0) break;
    }
    if (b==1) printf("Yes");
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define pi 3.14159265358979323846
#define Endl endl
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int n;
int ka[214514],inv[214514];
void setkaijo(int n){
	ka[0]=1;
	for(int i=1;i<=n;i++){
		ka[i] = ka[i-1] * i;
		ka[i] %= inf;
	}
}
int modpow(int x,int k){
	// x ^ k mod inf
	int res = 1;
	while(k>0){
		if(k%2)res = (res*x)%inf;
		x = (x*x)%inf;
		k >>=1;
	}
	return res;
}
void setinv(int n){
	for(int i=0;i<=n;i++){
		inv[i] = modpow(ka[i],(ll)inf-2);
	}
}
int comb(int n,int k){
	if( k<0 || n<0 || k>n)return 0;
	if(k==0 || k==n)return 1;
	int res = (ka[n] * inv[k]) % inf;
	res = (res*inv[n-k]) % inf;
	return res;
}
vector<int> nex[214514];
int dp[214514],sz[214514],ans[214514];
void dfs(int pos, int par){
	int res = 1, csz = 1;
	for(int i=0;i<nex[pos].size();i++){
		int nx = nex[pos][i];
		if( nx != par ){
			if( dp[nx] == 0 ) dfs( nx, pos );
			res *= dp[nx];
			res %= inf;
			res *= inv[ sz[nx] ];
			res %= inf;
			csz += sz[nx];
		}
	}
	res *= ka[csz-1];
	res %= inf;
	dp[pos] = res;
	sz[pos] = csz;
}
void dfs2(int pos, int par){
	int res = 1;
	if( par == 0 ){ ans[pos] = dp[pos]; }
	else{
		res = ans[par];
		res *= sz[pos];
		res %= inf;
		res *= modpow( n-sz[pos], inf-2 );
		res %= inf;
		ans[pos] = res;
	}
	for(int i=0;i<nex[pos].size();i++){
		int nx = nex[pos][i];
		if( nx != par ){
			dfs2( nx, pos );
		}
	}
	return ;
}
signed main(){
	cin>>n;
	setkaijo(210000);
	setinv(210000);
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		nex[x].pb(y);
		nex[y].pb(x);
	}
	dfs(1,0);
	dfs2(1,0);
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 23280
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N = II()

    if N == 1:
        print(0)
        return
    else:
        print(sum(range(N)))
        return

main()

Measured memory_bytes: 38484