akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,k;
int a[52];

vi V;

int main(){
  scanf("%d%d",&n,&k);
  REP(i,n)scanf("%d",a+i);
  int turn = k+1;
  vi mins(k,-1);
  int cnt = 0;
  bool odduse = false;
  REP(i,n){
    int need = max(0,turn-a[i]);
    if(2*need-1 > k || cnt+need > k){
      puts("-1"); return 0;
    }
    if(2*need-1 == k){
      odduse = true;
    }
    cnt += need;
  }
  int it = 1;
  REP(i,n){
    int need = max(0,turn-a[i]);
    while(true){
      if(2*(need+1)-1 > k)break;
      if(odduse && 2*(need+1)-1 == k)break;
      if(cnt+1 > k)break;
      need++;
      cnt++;
      if(2*need-1 == k){
        odduse = true;
        break;
      }
    }
    if(2*need-1 == k){
      REP(j,k)if(j%2==0)mins[j]=i;
    }else{
      while(need--){
        mins[it] = i;
        it += 2;
        if(it>=k)it=0;
      }
    }
  }
  // DEBUG_VEC(mins);
  vi V;
  int bef = -1;
  REP(j,turn){
    int last = j==turn-1 ? (bef+1)%n : mins[j];
    REP(i,n)if(i!=bef && i!=last){
      V.push_back(i);
    }
    V.push_back(last);
    bef = last;
    // DEBUG_VEC(V);
  }
  printf("%d\n",(int)V.size());
  REP(i,V.size())printf("%d%c",V[i]+1,i==(int)V.size()-1 ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a>=b && a>=c)
  cout<<b+c<<endl;
  else if(b>=a && b>=c)
    cout<<a+c<<endl;
  else
    cout<<a+b<<endl;
  return(0);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;

int main() {fio;
	int n, l;
	cin >> n >> l;
	vector <int> a(n);
	for(int &u : a) cin >> u;
	pair <int, int> best = {-1, -1};
	for(int i = 0; i < n - 1; i++) {
		best = max(best, {a[i] + a[i + 1], i});
	}
	if(best.first < l) {
		cout << "Impossible";
	} else {
		cout << "Possible\n";
		// for(int i = 0; i < n - 1; i++) {
		// 	cout << (best.second + 1 + i) % (n - 1) + 1 << endl;
		// }
		// cout << best.second << endl;
		for(int i = n - 1; i >= best.second + 2; i--) {
			cout << i << endl;
		}
		for(int j = 0; j <= best.second; j++) {
			cout << j + 1 << endl;
		}
	}
    return 0;
}

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

N = int(input())
A = list(map(int, input().split()))

bit = 1
for a in A:
    bit |= (bit<<a)

S = sum(A)
for i in range((S+1)//2, S+1):
    if bit&(1<<i):
        print(i)
        break

Measured memory_bytes: 5424
#include <stdio.h>

int main() {
  int n;
  int b, f, r, v;
  int i, j, k;

  int tenants[4][3][10] = {{{}}};

  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf("%d %d %d %d", &b, &f, &r, &v);
    tenants[b-1][f-1][r-1] += v;
  }

  for(i = 0; i < 4; ++i) {
    for(j = 0; j < 3; ++j) {
      for(k = 0; k < 10; ++k) {
	printf(" %d", tenants[i][j][k]);
      }
      printf("\n");
    }
    if(i != 3) printf("####################\n");
  }

  return 0;
}




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

int main() { int N;
  cin >> N;
  vector<int> v1(N);
  vector<int> v2(N);
  int s = 0;

  for (int i = 0; i < N; i++) {
    cin >> v1.at(i) >> v2.at(i);
    s = s + v2.at(i) - v1.at(i) + 1;
  }
  cout << s << endl;
}


Measured memory_bytes: 3572
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int n;

int sum(int x){
  return !x ? 0 : sum(x / 10) + x % 10;
}

int main(){
  scanf("%d", &n);
  int ans = inf;
  for(int a = 1; a < n; ++a){
    ans = min(ans, sum(a) + sum(n - a));
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main (int argc, char **argv){
	int n = 0;
	int p[20] = {0};
	int check = 0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	for(int i=1;i<n-1;i++){
		if(p[i-1]>p[i+1]){
			if(p[i]>=p[i+1]&&p[i]<p[i-1])
				check++;
		}
		else if(p[i-1]<p[i+1]){
			if(p[i]<p[i+1]&&p[i]>=p[i-1])
				check++;
		}
		
		else if(p[i-1]==p[i+1]){
			if(p[i]<p[i+1])
				check++;
		}
	}
	printf("%d",check);
	return 0;
}



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

#define BOLT ios_base::sync_with_stdio(0)
#define newline cout << "\n"
#define eline cerr << "\n"
#define IN_FILE freopen("input.txt", "r", stdin)
#define OUT_FILE freopen("output.txt", "w", stdout)

// g++ -o contest contest.cpp
long long path[100000];
long long dp[100000];
int n;

void USEFILE(){
    IN_FILE;
    OUT_FILE;
}

void reset(){
    memset(path, 0, sizeof path);
    memset(dp, -1, sizeof dp);
}

long long process(int i){
    long long ans;
    if(i>=n) return 0;
    if(dp[i] != -1) return dp[i];
    if(i == n-1)
        ans = 0;
    else if(i == n-2){
        ans = abs(path[i] - path[i+1]);
    }
    else 
        ans = min( abs( path[i]-path[i+1]) + process(i+1), abs( path[i] - path[i+2] ) + process(i+2) );

    dp[i] = ans;
    return ans;
}


void solve(int kase){
    reset();
    cin >> n;
    for(int i = 0 ; i < n; i++){
        cin >> path[i];
    } 
    cout << process(0);newline;
}


int main(){
    BOLT;
    //USEFILE();
    int t, kase = 0;
    // cin >> t;
    // while(t--)
    //      solve(++kase);
    solve(0);

    return 0;
}


Measured memory_bytes: 8332
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
#define S second
#define F first
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=20000005;
int n,k,x,t,a,b,m;
string s;
vi v;

void solve(){
	cin >> x;
	cout << (x^1);
}

int main(){

	int t= 1;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3608
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        io.r<int>();
        double[][] d = io.r<double>(2, ' ');
        io.w(DISTANCE.MANHATTAN(d[0], d[1]));
        io.w(DISTANCE.EUCLIDEAN(d[0], d[1]));
        io.w(DISTANCE.MINKOWSKI(3, d[0], d[1]));
        io.w(DISTANCE.CHEBYSHEV(d[0], d[1]));
        io.wflush();
    }
}
#region DISTANCE
namespace LIB
{
    public class DISTANCE
    {
        public static double MINKOWSKI(int m, double[] a, double[] b)
        {
            double r = 0;
            for (int i = 0; i < a.Count(); i++) { double d = Math.Abs(a[i] - b[i]); r += Math.Pow(d, m); }
            return Math.Pow(r, (double)1 / m);
        }
        public static double MANHATTAN(double[] a, double[] b) { return MINKOWSKI(1, a, b); }
        public static double EUCLIDEAN(double[] a, double[] b) { return MINKOWSKI(2, a, b); }
        public static double CHEBYSHEV(double[] a, double[] b)
        {
            double r = 0;
            for (int i = 0; i < a.Count(); i++) { double d = Math.Abs(a[i] - b[i]); if (d > r) { r = d; } }
            return r;
        }
    }
}
#endregion
namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
    public class math
    {
        public static double distance(int p, double[] a, double[] b)
        {
            int c = a.Count(); double d = 0; for (int i = 0; i < c; i++) { d += Math.Pow(Math.Abs(a[i] - b[i]), p); }
            return Math.Pow(d, (double)1 / p);
        }
    }
}

Measured memory_bytes: 10528
#include <stdio.h>

//int dp[50];
/*
int fibonacci(int n){
  if(n == 0 || n == 1){
    return 1;
  }
  if(dp[n] != -1){
    return dp[n];
  }
  return fibonacci(n - 2) + fibonacci(n - 1);
}
*/
int main(){
  int n, i, a = 0, b = 1,y = 0;
  /*
  for(i = 0; i < 50; i++){
    dp[i] = -1;
  }
  */
  scanf("%d",&n);

  //printf("%d\n",fibonacci(n));

  i = 0;
  while (i <= n) {
        
    a = b;
    b = y;
    y = a + b;
        
    if(i == n) printf("%d\n", y);
    i += 1;
  }

  return 0;
}



Measured memory_bytes: 2148
#include <iostream>

using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;
  if (n >= k) {
    if (n % k == 0) cout << 0;
    else cout << k - n % k;
  } else {
    long long r = k - n;
    cout << min(r, k - r);
  }
}


Measured memory_bytes: 256
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int Mod=1e9+7;
const int N=7505;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
char s[N];
int n,m,f[N][N];
int mod(int x){return x>=Mod?x-Mod:x;}
int Pow(int x,int y){int ans=1;while(y){if(y&1)ans=1ll*ans*x%Mod;x=1ll*x*x%Mod;y>>=1;}return ans;}
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();scanf("%s",s+1);m=strlen(s+1);
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=m+n/2;j>=0;j--){
			f[i][j]=mod(f[i][j]+f[i-1][j+1]);
			if(!j)f[i][j]=mod(f[i][j]+f[i-1][j]);
			if(j)f[i][j]=mod(f[i][j]+f[i-1][j-1]*2%Mod);
		}
	}
	printf("%lld\n",1ll*f[n][m]*Pow(Pow(2,m),Mod-2)%Mod);
	return 0;
}

Measured memory_bytes: 150320
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    a,b,c=map(int, readline().rstrip().split())
    k=int(readline())
    bk=0
    ck=0
    while b <= a:
        b*=2
        bk+=1
    while c <= b:
        c*=2
        ck+=1
    if (bk+ck)<=k:
        print("Yes")
    else:
        print("No")

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 16196
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

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

	cout << ceil((double)(n-1)/(k-1)) << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    using namespace std;
    using ll = long long;
     
    int main() 
    {
     int n, cnt=0;
     cin >> n;
     string s[n];
     rep(i,n) cin >> s[i];
     sort(s, s+n);
     rep(i,n-1){
      if(s[i].compare(s[i+1]) == 0) cnt++; 
     }
     int ans = n - cnt;
     cout << ans << endl;
      return 0;
    }

Measured memory_bytes: 9884
def main():
    import sys
    import time
    input = sys.stdin.readline
    N = int(input())
    A = [int(x) for x in input().strip().split()]
    B = [int(x) for x in input().strip().split()]
    cnt = 0
    for a, b in zip(A, B):
        a_b = a - b
        if a_b > 0:
            cnt += a_b
        elif a_b < 0:
            cnt -= -a_b // 2
    
    if cnt <= 0:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

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

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    
    if (a != 0) cout << b / x - (a-1) / x << endl;
    else cout << b / x - a / x + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>

using namespace std;

int main() {
    const int MIN = -1000000;
    const int MAX = 1000000;

    int k, x;
    cin >> k >> x;

    pair<int, int> range;

    if (x - MIN + 1 >= k && MAX - x + 1 >= k) {
        range.first = x - (k - 1);
        range.second = x + (k - 1);
    } else if (x - MIN + 1 < k) {
        range.first = MIN;
        range.second = x + (k - 1);
    } else if (MAX - x + 1 < k) {
        range.first = x - (k - 1);
        range.second = MAX;
    }

    for (int i = range.first; i <= range.second; i++) {
        cout << i << " ";
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <cmath>
#include <iomanip>

using namespace std;


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

    if(answer>=H)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;



    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
 
 
 
void change(char *str){
  int len=strlen(str);
  int i;
  for(i=0;i<len;i++){
    if('a'<=str[i]&&str[i]<='z'){
      str[i]-=32;
    }
  }
}
 
int main(){
  char t[10000];
  char key[10000];
  char eofstr[]={"END_OF_TEXT"};
  int ans=0;
 
  scanf("%s",key);
  change(key);
 
  while(1){
    scanf("%s",t);
    if(strcmp(t,eofstr)==0){
      break;
    }
    change(t);
    if(strcmp(t,key)==0){
      ans++;
    }
  }
 
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll INF = (ll)1e18;

int N, M;
int s, t;

struct Edge {
  int src, dest;
  ll weight;
};
bool operator>(const Edge& a, const Edge& b){
  return a.weight > b.weight;
}

vector<Edge> G[2][100005];
ll cost[2][100005];


struct ST {
  ll weight;
  int i;
};
bool operator>(const ST& a, const ST& b){
  return a.weight > b.weight;
}

void dijkstra(int s, int idx){
  rep(i,N+1){
    cost[idx][i] = INF;
  }
  priority_queue<Edge,vector<Edge>,greater<Edge>> q;
  q.push((Edge){-1,s,0});

  while(!q.empty()){
    Edge e=q.top();
    q.pop();
    if(cost[idx][e.dest] != INF) continue;
    cost[idx][e.dest]=e.weight;
    FOR(it,G[idx][e.dest])
      if(cost[idx][it->dest]==INF) q.push((Edge){it->src,it->dest,e.weight+it->weight});
  }
}


int main(){
  cin >> N >> M;
  cin >> s >> t;
  rep(i,M){
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    G[0][u].push_back((Edge){u,v,a});
    G[0][v].push_back((Edge){v,u,a});
    G[1][u].push_back((Edge){u,v,b});
    G[1][v].push_back((Edge){v,u,b});
  }

  dijkstra(s, 0);
  dijkstra(t, 1);

  vector<ll> ret(N+1,0);
  priority_queue<ST,vector<ST>,greater<ST>> q;
  REP(i,1,N+1){
    q.push((ST){cost[0][i] + cost[1][i], i});
  }

  REP(i,1,N+1){
    ST st = q.top();
    while(!q.empty()){
      st = q.top();
      if(st.i >= i){
        ret[i] = st.weight;
        break;
      }else{
        q.pop();
      }
    }
  }

  REP(i,1,N+1){
    cout << 1000000000000000LL - ret[i] << endl;
  }
  
  return 0;
}



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

int main(void){
  char w[8];
  scanf("%s", w);
  if(strcmp("Sunny", &w)==0){
    printf("Cloudy");
  }else if(strcmp("Cloudy", &w)==0){
    printf("Rainy");
  }else if(strcmp("Rainy", &w)==0){
    printf("Sunny");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int p,q,r;
	cin>>p>>q>>r;
	int a[3];
	a[0]=p; a[1]=q; a[2]=r;
	sort(a,a+3);
	cout<<a[0]+a[1];
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<ll> vec; 
#define inf LLONG_MAX
#define bp __builtin_popcountll
#define pb push_back
#define ff first
#define ss second
#define P pair<ll,ll>
#define N (ll)(1<<20)
#define M 20
#define mod 1000000007
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll n,k;
string s;
ll dp[105][2][5];

ll solve(ll ind,ll tight,ll cc)
{
      if(cc>k)
            return 0;    
      if(ind==n)
            return (cc==k);
            
      ll &ans=dp[ind][tight][cc];
      
      if(ans!=-1)
            return ans;
      
      ans=0;
      
      ll r=9;
      if(tight)
            r=s[ind]-'0';
            
      for(int i=0;i<=r;i++)
      {
            ll newtight=tight;
            if(i!=r)
                  newtight=0;
                  
            ans+=solve(ind+1,newtight,cc+(i!=0));
      }
      
      return ans;
            
      
}

int32_t main()
{
      FAST;
      
      cin>>s>>k;
      n=s.size();
      
      memset(dp,-1,sizeof(dp));
      // solve(0,1,0);
      
      cout<<solve(0,1,0);
      
}

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

int main() {
    int n; cin >> n;
    vector<map<char, int>> smap(n);
    rep(i, n) {
        string s; cin >> s;
        for (auto c : s) {
            smap[i][c]++;
        }
    }
    for (char c = 'a'; c <= 'z'; c++) {
        int count = 100;
        rep(i, n) {
            count = min(count, smap[i][c]);
        }
        if (count != 0) {
            rep(j, count) {
                cout << c;
            }
        }
    }
    cout << endl;
}

Measured memory_bytes: 3660
import math
a, b, k = map(int, input().split())
lst_max_num = []
lst_both = []
max_num = max(a, b)
min_num = min(a, b)
n = int(math.sqrt(max_num))
for i in range(1, n + 1):
    if max_num % i == 0 and max_num // i != i:
        lst_max_num.append(i)
        lst_max_num.append(max_num // i)
    elif max_num % i == 0 and max_num // i == i:
        lst_max_num.append(i)

for i in lst_max_num:
    if  min_num % i == 0:
        lst_both.append(i)

lst_both = sorted(lst_both, reverse = True)
print(lst_both[k - 1])

Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
	int tc, num[100000], count=0, i, save, acd[100000];

	scanf("%d", &tc);

	for(i = 1; i<= tc; i++)
	{
		scanf("%d", &num[i]);
		acd[i] = i;
	}
	for(i = 1; i <= tc; i++)
	{
		if(acd[i] == num[i])
            save = 1;
        else
            count++;
	}
    if(count <= 2 && save == 1)
        printf("YES\n");
    else
        printf("NO\n");


	return 0;
}

Measured memory_bytes: 1640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,d,a,l,r,ce,ans=0; cin>>n>>d>>a;
    vector<pair<ll,ll>> m(n);
    vector<ll> sd(n+1,0);
    rep(i,n){
        ll x,h; cin>>x>>h;
        m[i]=mk(x,(h+a-1)/a);
    }
    sort(al(m));
    ll x,dd;
    rep(i,n){
        if(i!=0) sd[i]+=sd[i-1];
        if(m[i].second-sd[i]>0){
            dd=m[i].second-sd[i];
            ans+=dd;
            sd[i]+=dd;
            l=-1; r=n-1; x=m[i].first+2*d;
            while(l!=r){
                ce=(l+r+1)/2;
                if(x>=m[ce].first) l=ce;
                else r=ce-1;
            }
            sd[l+1]-=dd;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define LL                  long long
#define ull                 unsigned long long LL
#define scl(n)              scanf("%lld", &n)
#define scf(n)              scanf("%lf", &n)
#define sci(n)              scanf("%d", &n)
#define scii(n,m)           scanf("%d %d",&n,&m)
#define sciii(n,m,p)        scanf("%d %d %d",&n,&m,&p)

#define MOD                 1000000007
#define MODP                99999999999973LL
#define pb                  push_back
#define mp                  make_pair
#define pp                  pair<LL,LL>
#define memo(a,b)           memset(a,b,sizeof(a))
#define INF                 1e9
#define EPS                 1e-8
#define Pi                  acos(-1.0)
LL bigmod(LL b, LL p, LL md){if(p==0) return 1;if(p%2==1){ return ((b%md)*bigmod(b,p-1,md))%md;} else {LL y=bigmod(b,p/2,md);return (y*y)%md;}}
#define N 300002


LL arr[N][4];
LL dp[N][4];

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

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

    LL ans=0;
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=3;j++)
        {
            for(int k=1;k<=3;k++)
            {
                if(j==k)
                    continue;
                dp[i][j]=max(dp[i][j],arr[i][j]+dp[i-1][k]);

            }
        }
    }

    for(int i=1;i<=3;i++)
        ans=max(ans,dp[n][i]);
    cout<<ans<<endl;


    return 0;
}



/* LL dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* LL dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* LL dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* LL dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction


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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,n) for(int i=(int)(n-1);i>=0;--i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int n;
    while (cin >> n, n) {
        int cnt = 0;
        FOR(i, 1, n) {
            int sum = i;
            FOR(j, i+1, n) {
                sum += j;
                if (sum == n) {
                    cnt++;
                    break;
                } else if (sum > n) {
                    break;
                }
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
using priority_queue_small = priority_queue<int, vector<int>, greater<int> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int d;
int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> d;
  if (d == 25) cout << "Christmas" << endl;
  else if (d == 24) cout << "Christmas Eve" << endl;
  else if (d == 23) cout << "Christmas Eve Eve" << endl;
  else cout << "Christmas Eve Eve Eve" << endl;
  return 0;
}



Measured memory_bytes: 892
n=int(input())
a,b=map(int,input().split())
x,y,z=0,0,0
lst=list(map(int,input().split()))
for i in lst:
  if i<=a:
    x+=1
  elif a<i<=b:
    y+=1
  else:
    z+=1
o=[x,y,z]
print(min(o))

Measured memory_bytes: 8980
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b[110000],cnt;
string s;
signed main()
{
	cin>>a;
	rep(i,a){
		cin>>b[i];
	}
	rep(i,a){
		rep(j,i){
			cnt+=b[i]*b[j];
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int s;
vector <int> S;

int main(){
    while( cin >> s ){
        do{
            S.push_back(s);
            if( s%2 ) s = s*3+1;
            else s /= 2;
        }while( find(S.begin(), S.end(), s) == S.end() );
//        for( auto i : S ) cout << i << ' '; cout << endl;
        cout << S.size()+1 << endl;
        S.clear();
    }
    return 0;
}
/*
8
7
54

*/


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define PI 3.141592653589793238462448327950L
int main(){
    double a,b,h,m,ans,deg;
   scanf("%lf%lf%lf%lf",&a,&b,&h,&m);
  deg=fabs((h*PI/6+m*PI/360)-m*PI/30);//長針の進んだ角と短針の進んだ角の差の絶対値
  if(deg>PI)
    deg=2*PI-deg;//degを0からPIの間の角に直す
  ans=a*a+b*b-2*a*b*cos(deg);
  printf("%.15lf",sqrt(ans));
  return 0;
}


Measured memory_bytes: 2600
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


n, m = map(int, input().split())
s = set(range(1, m+1))
# print(s)
for i in range(n):
    a = list(map(int, input().split()))
    a_set = set(a[1:])
    # print(a_set)
    s &= a_set
    # print(s)
print(len(s))


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

int v[1001],w[1001],dp[10001][10001];
int N,W;


int main(){
    scanf("%d%d",&N,&W);
    for(int i = 0;i <N;i++)
        scanf("%d%d",&v[i],&w[i]);
    for(int i = 1;i <= N;i++)
        for(int j = 0;j <= W;j++){
            if(j - w[i-1] < 0)
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i-1]] + v[i-1]);
        }
    printf("%d\n",dp[N][W]);

    return 0;
}


Measured memory_bytes: 6604
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,t;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>t;
    rep(i,n)cin>>a[i]>>b[i];
    ans=LINF;
    rep(i,n){
        if(b[i]<=t)ans=min(ans,a[i]);
    }
    if(ans==LINF)Cout("TLE");
    else Cout(ans);
    return 0;
}


Measured memory_bytes: 2812
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Ai = Slist();
            Ai.Sort();
            Ai.Reverse();
            var dct = new Dictionary<long, long>();
            foreach (var a in Ai)
            {
                if (!dct.ContainsKey(a)) dct.Add(a, 0);
                ++dct[a];
            }

            var bou = new List<long>();
            foreach (var a in Ai.Distinct())
            {
                if (2 <= dct[a])
                {
                    bou.Add(a);
                    if (4 <= dct[a])
                        bou.Add(a);
                }
                if (2 <= bou.Count)
                {
                    WriteLine(bou[0] * bou[1]);
                    return;
                }
            }
            WriteLine(0);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 27360
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll POW3(ll x,ll n,ll m){
  x%=m;
  if(n==0)return 1;
  if(n%2==0)return POW3(x*x,n/2,m)%m;
  return x*POW3(x,n-1,m)%m;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

ll lcm(ll u, ll v) {
  return u*v/gcd(u,v);
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)//xのm進数でのx^nの位の値
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)//xのn進数での桁数
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)//x!のnで割り切れる回数
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)//xのnで割り切れる回数
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

ll SGS(ll x,ll y, ll m)//1+x+…+x^(y-1)をmで割った余り
{
  if(y==0)return 0;
  if(y%2==0){
    return (1+POW3(x,y/2,m))*SGS(x,y/2,m)%m;
  }
  return (1+x*SGS(x,y-1,m))%m;
}

ll SSGS(ll x,ll y,ll m)//Σ[k=1→y](1+x+…+x^(k-1))をmで割った余り
{
  if(y==0)return 0;
  if(y==1)return 1;
  if(y%2==0){
    return (SSGS(x,y/2,m)*(POW3(x,y/2,m)+1)%m+SGS(x,y/2,m)*y/2%m)%m;
  }
  return (SSGS(x,y-1,m)*x%m+y)%m;
}

int main()
{
  ll n,a[320000],s=0,t[320000],w=0,r[320000],ans=-INF;
  cin >> n;
  rep(i,3*n)cin >> a[i];
  priority_queue<int,vector<int>,greater<int>>p;
  priority_queue<int>q;
  rep(i,n){
    p.push(a[i]);
    s+=a[i];
  }
  t[n-1]=s;
  FOR(i,n,2*n){
    p.push(a[i]);
    t[i]=t[i-1]-p.top()+a[i];
    p.pop();
  }
  ROF(i,2*n,3*n){
    w+=a[i];
    q.push(a[i]);
  }
  r[2*n]=w;
  ROF(i,n,2*n){
    q.push(a[i]);
    r[i]=r[i+1]-q.top()+a[i];
    q.pop();
  }
  FOR(i,n-1,2*n){
    ans=max(ans,t[i]-r[i+1]);
  }
  printf("%lld",ans);
} 

Measured memory_bytes: 8568
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;


int main() {
    #ifndef ONLINE_JUDGE
	// freopen("test.in", "r", stdin);
    #endif
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, x, y; cin >> n >> x >> y;
    x -= 1; y -= 1;
    vi dist(n);
    for_(i, 0, n) dist[i] = n-i;

    for (int i = n-1; i > x; i--) {
        int nd, od;
        for (int j = y-1; j >= 0; j--) {
            nd = min(1 + abs(y - i) + abs(x - j), abs(j-x) + 1 + abs (y - i)); od = i - j;
            if (nd >= od) continue;
            // cout << od << " -> " << nd << endl;
            dist[od] -= 1;
            dist[nd] += 1;
        }
    }

    for_(i, 1, n) cout << dist[i] << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
m={}
for line in sys.stdin.readlines():
    p=int(line.rstrip())
    m.setdefault(p,0)
    m[p]+=1

x=sorted(m.items(),key=lambda x:x[1],reverse=True)
tmp=x[0][1]
ans=[v for v,k in x if tmp == k]
for l in ans:
    print l

Measured memory_bytes: 4224
#define DBG 0 //submission 0
#if DBG==1
    #include <algorithm>
    #include <ctime>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <iostream>
    #include <cmath>
#else
    #include <bits/stdc++.h>
#endif

using namespace std;

int main(){
    //long long ans = 0,sum = 0;
    //long long N,K; 
    int N,L,i,j,k,tmp=0,ans = 0;
    //string S;
    cin >> N >> L;
    
    tmp = L;
    for (i=2;i<N+1;i++){
        if(abs(L+i-1) < abs(tmp)){
            ans += tmp;
            tmp = L+i-1;
        }else{
            ans += L+i-1;
        }
    }
    

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n, m;
	while (cin>>n>>m,n|m){
		vector<int> vi1;
		vector<int> vi2;
		int sum1 = 0;
		int sum2 = 0;
		int sum=0;
		REP(i, n+m){
			int x;
			cin >> x;
			if (i < n){
				vi1.push_back(x);
				sum1 += x;
			}
			else {
				vi2.push_back(x);
				sum2 += x;
			}
			sum += x;
		}
		int k, l;
		int ans = 0;
		for (int i = 0; i < vi1.size();i++){
			for (int j = 0; j < vi2.size(); j++){
				if ( vi1[i]*2 - vi2[j]*2-sum1 + sum2 ==0 ){
					k = i;
					l = j;
					ans = 1;
					break;
				}
				if (ans == 1)break;
			}
		}
		if(ans==1)printf("%d %d\n", vi1[k], vi2[l]);
		else printf("-1\n");
	}
}

Measured memory_bytes: 1196
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <functional>

using namespace std;

int main() {
    int n;
    long long l[87] = { 0 };
  
    cin >> n;

    l[0] = 2;
    l[1] = 1;

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

    cout << l[n] << endl;
    
  return 0;
  
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n, *v, *c;
    cin >> n;
    v = new int [n];
    c = new int[n];
    int ans = 0;
    
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }

    for (int i = 0; i < n; i++) {
        if ((v[i] - c[i]) > 0)
            ans += (v[i] - c[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
#define MAX 100000007
 
static unsigned char is_not_prime[((MAX + 1) + 7) / 8];
 
static inline int get_bit(int i) {
    return (is_not_prime[i >> 3] >> (i & 7)) & 1;
}
 
static inline void set_bit(int i) {
    is_not_prime[i >> 3] |= (1 << (i & 7));
}
 
void init(void) {
    int i, j;
    set_bit(0);
    set_bit(1);
    for (j = 4; j <= MAX; j += 2) set_bit(j);
    for (i = 3; i * i <= MAX; i += 2) {
        if (!get_bit(i)) {
            for (j = i * i; j <= MAX; j += i) set_bit(j);
        }
    }
}
 
int main(void) {
    int N, i;
    int count = 0;
    init();
    if (scanf("%d", &N) != 1) return 1;
    for (i = 0; i < N; i++) {
        int q;
        if (scanf("%d", &q) != 1) return 1;
        if (!get_bit(q)) count++;
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 13980
h = {}
S=gets.chomp.split('')
S.each{|a|
	h[a].nil? ? h[a] = 1 : h[a] += 1
}
sum = 0
h.each{|k,v|
	sum += v*(v-1)/2
}
puts 1+S.size*(S.size-1)/2-sum



Measured memory_bytes: 12796
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
ifstream f("A.in");
ofstream g("A.out");
typedef long long ll;
typedef pair<int,int> pi;
int t,T;
const int dim=1e6+10;
int viz[dim],n;
ll all,x,maxi;
bool pw,prim[dim];

void Sieve()
{
    prim[1]=1;
    for(int i=2;i<=maxi;i++)
    if(!prim[i])
    for(int j=i+i;j<=maxi;j+=i) prim[j]=1;

    for(int i=1;i<=maxi;i++)
    if(!prim[i])
    {
        int cnt=0;
        if(viz[i]) cnt=viz[i];
        for(int j=i+i;j<=maxi;j+=i)
        {
            prim[j]=1;
            if(viz[j])cnt+=viz[j];
        }

        if( cnt > 1 )
        {
            pw=1;
            return;
        }
    }
}

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

    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;

        maxi=max(maxi,x);

        viz[x]++;

        if(i==1) all=x;
        else all=__gcd(all,x);
    }

    Sieve();

    if( pw == 1 )
    {
        if(all==1) cout<<"setwise coprime";
        else cout<<"not coprime";
    }
    else cout<<"pairwise coprime";

    return 0;
}


Measured memory_bytes: 8540
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	NK := sc.nextInts()
	N := NK[0]
	K := NK[1]

	var cnt int
	for {
		tmp := powInt(K, cnt)
		if tmp > N {
			break
		}
		cnt++
	}
	fmt.Println(cnt)
}

/* template functions */
var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	K := getStdinInt64()
	var i int64 = 0
	var temp int64 = 0
	for i = 0; i < 1000000; i++ {
		temp = (temp*10 + 7) % K
		if temp == 0 {
			fmt.Printf("%d\n", i+1)
			return
		}
	}
	fmt.Printf("%d\n", -1)
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntU64() uint64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return uint64(rtn)
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func getStdinIntArrU64() []uint64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]uint64, len(list))
	for idx, val := range list {
		r, _ := strconv.ParseInt(val, 10, 64)
		rtn[idx] = uint64(r)
	}
	return rtn
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
func abs64(n int64) int64 {
	if n < 0 {
		return -n
	}
	return n
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


int main()
{
    ll n;
    cin >> n;
    ll a[n],sum[n];
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    sum[0] = a[0];
    for(int i = 1; i < n; i++){
        sum[i] = sum[i-1] + a[i];
    }
    for(int i = n-1; i >= 1; i--){
        if(a[i] <= sum[i-1]*2){
            ans++;
        }else{
            break;
        }
    }
    cout << ++ans << endl;
}


Measured memory_bytes: 1792
from copy import copy
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a_counter=Counter(a)
ans=0
for i in a_counter:
    ans+=(a_counter[i])*(a_counter[i]-1)//2
for j in a:
    true_ans=copy(ans)
    true_ans=true_ans-((a_counter[j])*(a_counter[j]-1)//2-(a_counter[j]-1)*(a_counter[j]-2)//2)
    print(true_ans)

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

#define int long long
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)  
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rap(i,a,n) for (int i = a; i < (n); i++) 
#define rrap(i,n,a) for (int i = (n)-1; i >= a; i--) 
#define LL_MAX 9223372036854775807

typedef vector<int> vi;  
typedef pair<int,int> ii;  
typedef vector<ii> vii;  
typedef list<int> li;  
typedef unordered_map<int,int> mii;

vi v;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    v.assign(n,0);

    rep(i,n-1) {
        int a;
        cin >> a;
        a--;
        v[a]++;
    }

    rep(i,n) {
        cout << v[i] << '\n';
    }

    return 0;
    //compile: g++ -std=c++14 -O2 -Wall NAME.cpp -o NAME
}


Measured memory_bytes: 4788
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
			PrintWriter out=new PrintWriter(System.out);
	FastScanner fs=new FastScanner();
	int x=fs.nextInt();
	int y=fs.nextInt();
	int a=(4*x-y)/2;
	if(y%2==0&&a>=0&&a<=x)
	out.println("Yes");
	
		else
		out.println("No");
	out.close();
		
	
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble(){
		    return Double.parseDouble(next());
		}
}
}


Measured memory_bytes: 25384