akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                            \
    cout << #v << "=(" << v[0];                              \
    FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; } \
    cout << ")" << endl;
#define mdebug(m)                                                               \
    cout << #m << "=" << endl;                                                  \
    REP(i_debug, m.size())                                                      \
    {                                                                           \
        REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; } \
        cout << endl;                                                           \
    }
#define Lower_bound(v, x) \
    distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
    distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
// #define f first
// #define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

template <typename T>
void readv(vector<T> &a)
{
    REP(i, a.size())
    cin >> a[i];
}
void readv_m1(vector<int> &a)
{
    REP(i, a.size())
    {
        cin >> a[i];
        a[i]--;
    }
}

ll mod = 1000000007;

int main()
{
    ll N;
    cin >> N;
    vec a(N);
    REP(i, N)
    {
        cin >> a[i];
    }
    ll ans = 0;
    REP(i, N)
    {
        if (i % 2 == 0 && a[i] % 2 == 1)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int h,w,t;
char a[101][101];
string ans[101];
int main()
{
	cin>>h>>w;
	for (int i=1;i<=h;i++) for (int j=1;j<=w;j++) cin>>a[i][j];
	for (int i=1;i<=h;i++)
	{
		bool frow=true;
		for (int j=1;j<=w;j++) if (a[i][j]!='.' && a[i][j]!='@') {frow=false; break;}
		if (frow) for (int j=1;j<=w;j++) a[i][j]='@';
	}
	for (int i=1;i<=w;i++)
	{
		bool fcol=true;
		for (int j=1;j<=h;j++) if (a[j][i]!='.' && a[j][i]!='@') {fcol=false; break;}
		if (fcol) for (int j=1;j<=h;j++) a[j][i]='@';
	}
	for (int i=1;i<=h;i++)
	{
		for (int j=1;j<=w;j++)
			if (a[i][j]!='@') ans[t]+=a[i][j];
			//cout<<a[i][j];
		if (ans[t].size()) cout<<ans[t]<<endl,t++;
	}
	
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
struct A { int x, y; ld t; } a[2000];
bool operator<(A a, A b) { return a.t < b.t; }
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].x >> a[i].y;
		a[i].t = atan2(a[i].y, a[i].x);
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		a[i + n] = a[i];
	}
	H t{ 0,0 };
	int ans = 0;
	for (int i = 0; i < n; i++) {
		H t = { 0,0 };
		for (int j = i; j < i + n; j++) {
			t.x += a[j].x, t.y += a[j].y;
			ans = max(ans, t.x * t.x + t.y * t.y);
		}
	}
	printf("%.30LF\n", (ld)sqrt(ans));
}

Measured memory_bytes: 256
ls_s = [int(_) for _ in input()]

ans = 2000

for i in range(len(ls_s) - 2):
    x = (100 * ls_s[i]) + (10 * ls_s[i+1]) + (ls_s[i+2])
    if abs(753 - x) < abs(753 - ans):
        ans = x

print(abs(753 - ans))

Measured memory_bytes: 3060
import sys
import re

N,M = map(int,input().split())
nums = ["0"]*N
if N != 1:
    nums[0] = "1"
checked = [False]*N

for i in range(M):
    s,c = map(int,input().split())
    s -= 1
    if not checked[s]: #初めての指定
        nums[s] = str(c)
        checked[s] = True
    elif nums[s] != str(c): #同じ場所に異なる数字が来たら作れない
        print(-1)
        sys.exit()
        
if N != 1 and nums[0] == "0":
    print(-1)
else:    
    print("".join(nums))   
    

Measured memory_bytes: 3188
#include<stdio.h>
int main(){
    int n;
	scanf("%d",&n);
	int a[n];
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int x;
	for(x=(n-1);x>=1;x--){
		printf("%d ",a[x]);
	}
	printf("%d\n",a[0]);
	return 0;
}

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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int *h=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",h+i);
  int *dp=(int *)calloc(n,sizeof(int));
  dp[1]=ABS(h[1]-h[0]);
  for(i=2;i<n;i++){
    dp[i]=MIN(ABS(h[i]-h[i-2])+dp[i-2],ABS(h[i]-h[i-1])+dp[i-1]);
  }
  printf("%d\n",dp[n-1]);
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    ll N, A, B;
    cin >> N >> A >> B;

    if ((B - A) % 2 == 0) {
        cout << (B - A) / 2 << endl;
    } else {
        cout << min(A - 1, N - B) + 1 + (B - A - 1) / 2 << endl;
    }

    return 0;
}


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

int N;
vector<int> A;

int main(void) {
	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];

	string ans = "APPROVED\n";
	for (int i = 0; i < N; ++i) {
		if (A[i] % 2 == 0) {
			if ((A[i] % 3 != 0) && (A[i] % 5 != 0)) {
				ans = "DENIED\n";
				break;
			}
		}
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <map>

using namespace std;


long long aa(long long x, long long K)
{
    long long val = x % K;
    long long val2 = K - val;

    if(val > val2){
        return val2;
    }
    return val;
}


int main(int argc, char* argv[]){
    long long N, K;

    cin >> N >> K;

    cout << aa(N, K);

}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String r = sc.next();
        String g = sc.next();
        String b = sc.next();

        int ans = Integer.parseInt(r + g + b);

        if(ans % 4 == 0){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	int a;
	cin>>a;
	if(a<1200)
		cout<<"ABC"<<endl;
	else if(a<2800)
		cout<<"ARC"<<endl;
	else
		cout<<"AGC"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define lowbit(x) (x)&(-x)
const int maxd=1000000007,N=100000;
const double pi=acos(-1.0);
typedef long long ll;
int n,a,b;
vector<int> ans; 

int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

void solve(int n,int a,int b,int sta)
{
	if (n==1)
	{
		ans.push_back(a);ans.push_back(b);
		return;
	}
	int dif=a^b,bit1=lowbit(dif);
	dif^=bit1;sta^=bit1;
	int bit2=lowbit(sta);
	dif^=bit2;
	solve(n-1,a,a^dif,sta);
	solve(n-1,a^dif^bit1,b,sta);
}

int main()
{
	n=read();a=read();b=read();
	if (__builtin_popcount(a^b)%2==0) {printf("NO");return 0;}
	solve(n,a,b,(1<<n)-1);
	printf("YES\n");
	int i;
	for (i=0;i<(1<<n);i++) printf("%d ",ans[i]);
	return 0;
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
 
using namespace std;
 
 
int main(){
 int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  int x3,y3,x4,y4;
  
  x3=x2+y1-y2;
  y3=y2+x2-x1;
  x4=x3+y2-y3;
    y4=y3+x3-x2;
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<" "<<endl;
 
}

Measured memory_bytes: 256
N, T = map(int, input().split())
# 1-index
A = [0]
B = [0]
for _ in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)

# dp1[i][j] 1 ~ i の料理で j 分以内に完食できる美味しさの合計の最大値
# dp2[i][j] i ~ N の料理で j 分以内に〃
# max(DP1[i − 1][j] + DP2[i + 1][T − 1 − j]) i番目以外で T - 1 以内

dp1 = [[0] * T for _ in range(N+2)]
dp2 = [[0] * T for _ in range(N+2)]
for i in range(1, N+1):
  for j in range(T):
    dp1[i][j] = dp1[i-1][j]
    if j - A[i] >= 0:
      dp1[i][j] = max(dp1[i][j], dp1[i-1][j - A[i]] + B[i])

for i in range(N, 0, -1):
  for j in range(T):
    dp2[i][j] = dp2[i+1][j]
    if j - A[i] >= 0:
      dp2[i][j] = max(dp2[i][j], dp2[i+1][j - A[i]] + B[i])      

ans = 0
for i in range(1, N+1):
  for j in range(T):
    ans = max(ans, dp1[i-1][j] + B[i] + dp2[i+1][T - 1 - j])

print(ans)

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(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 revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

struct mint {
    // Preparation: MOD is already defined.
    ll value;

    mint(ll value = 0) : value((value % MOD + MOD) % MOD) {}

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(mint m) const {
        return pow(m.value);
    }

    mint inv() const {
        ll a = value, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        return u;
    }

    mint &operator+=(const mint a) {
        if ((value += a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((value += MOD - a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (value *= a.value) %= MOD;
        return *this;
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    int ans = 0;
    ans += n * (n - 1) / 2;
    ans += m * (m - 1) / 2;
    out(ans);
}


Measured memory_bytes: 256
import Data.Array.IArray

main = do
    getLine
    times <- map read . words <$> getLine
    getLine
    drinks <- map read . words <$> getContents
    let times' = listArray (1,length times) times :: Array Int Int
    let time = sum times
    mapM_ (print . (-) time) $ map (\(p, x) -> times'!p - x) $ tuplify drinks

tuplify (x:y:xs) = (x,y):tuplify xs
tuplify [] = []


Measured memory_bytes: 1020
void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], k = tmp[1];
    writeln(n % k != 0 ? 1 : 0);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
int N, L;
int last;
int ans[3];
int main() {
	int N, Y;
	std::cin >> N >> Y;
	Y /= 1000;
	for (int i = 0; i <= N; i++) {
		for (int j = i; j <= N; j++) {
			if ((i * 10) + ((j - i) * 5) + ((N - j) * 1) == Y){
			std::cout << i << " " << (j - i) << " " << (N - j) << std::endl;
			return 0;
			}
		}
	}
	std::cout << -1 << " " << -1 << " " << -1 << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a[n];
    //int av=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }   
    int ans=10000000;
    int sum=0;
    for(int i=-100;i<=100;i++){//a
        for(int j=0;j<n;j++){//an
        sum+=(a[j]-i)*(a[j]-i);
        }
        if(sum<ans){
            ans=sum;
        }
        sum=0;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <ctime>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;

int main() {
 // freopen("in.cpp","r",stdin);
  int n;
  ll ret=1;
  int pre=-1,s=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    int x;
    cin>>x;
    if(pre+2<=x){
      ret=ret*(s+1)%mod;
      s++;
      pre+=2;
    } else {
      ret=ret*(s+1)%mod;
    }
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 256
// a_abc098.cpp
#include <iostream>
#include <vector>
#include <string>
#include <random>
#include <algorithm>
#include <iomanip>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i = a; i < b; ++i)
#define REP(i,n)   for(int i = 0; i < n; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

ull powmod(ull a, ull b, ull mod) {ull res = 1; for(; b; b >>= 1){if (b & 1) {res = res * a % mod;} a = a * a % mod;} return res;}

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

    res = a + b;
    if (a - b > res){
        res = a - b;
    }

    if (a * b > res) {
        res = a * b;
    }

    cout << res << "\n";
}


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

cards = [[0 for i in range(13)] for j in range(4)]

for num in range(N):
    i = list(map(str, input().split()))
    if i[0] == 'S':
        cards[0][int(i[1])-1] = 1
    elif i[0] == 'H':
        cards[1][int(i[1])-1] = 1
    elif i[0] == 'C':
        cards[2][int(i[1])-1] = 1
    elif i[0] == 'D':
        cards[3][int(i[1])-1] = 1

for j in range(4):
    for k in range(13):
        if cards[j][k] == 0:
            if j == 0:
                print('S', k+1)
            elif j == 1:
                print('H', k+1)
            elif j == 2:
                print('C', k+1)
            elif j == 3:
                print('D', k+1)


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

int main() {
  int N;
  cin >> N;
  cout << fixed << setprecision(10);
  vector<int> vec(N);
  vector<double> bunsu(N);
  double b = 0;
  for( int i = 0; i < N; i++ ){
    cin >> vec.at(i);
    bunsu.at(i) = 1.00000 / vec.at(i);
    b += bunsu.at(i);
  }
  
  cout << 1.0000000000 / b << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	//
	// 速度: v = 9.8t
	// 距離: y = 4.9t^2
	//

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		
		while ((line = br.readLine()) != null) {
			double v = Double.parseDouble(line);
			double t = v / 9.8;
			double y = 4.9 * t * t;
			double N = Math.ceil(y / 5) + 1;
			System.out.println((int) N);
		}
	}
}

Measured memory_bytes: 16904
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ipr pair<ll,ll>
#define ps push_back
#define fs first
#define sc second
#define endl "\n"
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;

	char ar[n+1];
	cin>>ar;

	ll ps1[n+1],ps2[n+2];
	ps1[0]=0; ps2[n+1]=0;

	for(i=0;i<n;i++){
		if(ar[i]=='W'){
			ps1[i+1]=ps1[i]+1;
		}
		else ps1[i+1]=ps1[i];
	}
	
	for(i=n-1;i>=0;i--){
		if(ar[i]=='E'){
			ps2[i+1]=ps2[i+2]+1;
		}
		else ps2[i+1]=ps2[i+2];
	}

	ll mx=1000000000000000;
	for(i=1;i<=n;i++){
		//cout<<ps1[i-1]<<" "<<ps2[i+1]<<endl;
		k=ps1[i-1]+ps2[i+1];
		if(k<mx) mx=k;
	}
	cout<<mx;
	return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	int n=0;
	string S;
	cin>>S;
	REP(i,(int)S.length()){
		if(S[i]=='1') n++;
	}
	print(n);
	return 0;
}


Measured memory_bytes: 256
N = int(input())
Data = list(map(int,input().split()))
ans = True
for data in Data:
    if data % 2 == 0:
        if data % 3 == 0 or data % 5 == 0:
            pass
        else:
            ans = False
            break
if ans:
    print('APPROVED')
else:
    print('DENIED')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+7;
int p[MAXN];
int x[MAXN], y[MAXN];

int bap[MAXN];
int parent(int u) {
    if (u==bap[u]) return u;
    return bap[u] = parent(bap[u]);
}

set< int >grp[MAXN];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        bap[i] = i;
    }

    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        x = parent(x);
        y = parent(y);
        bap[y] = x;
    }

    for (int i = 1; i <= n; i++) {
//        cout << i << " " << parent(i) << endl;
        grp[parent(i)].insert(p[i]);
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) ans += grp[parent(i)].count(i);

    cout << ans << endl;


    return 0;
}


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

static const int MAX = 10000;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;

vector<pair<int, int>> adj[MAX]; // 重み付き有向グラフの隣接リスト表現

void dijkstra() {
  priority_queue<pair<int, int>> PQ;
  int color[MAX];
  int d[MAX];
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
    color[i] = 0;
  }

  d[0] = 0;
  PQ.push(make_pair(0, 0));
  color[0] = GRAY;

  while (!PQ.empty()) {
    pair<int, int> f = PQ.top();
    PQ.pop();
    int u = f.second;
    color[u] = BLACK;

    // priority_queueはデフォルト大きい値を優先しているため-1して保存している
    // if (d[u] < f.first * (-1)) continue;

    for (int j = 0; j < adj[u].size(); j++) {
      int v = adj[u][j].first;
      if (color[v] == BLACK) continue;
      if (d[v] > d[u] + adj[u][j].second) {
        d[v] = d[u] + adj[u][j].second;
        // priority_queueはデフォルトで大きい値を優先するため-1をかける
        PQ.push(make_pair(d[v] * (-1), v));
        color[v] = GRAY;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << i << " " << (d[i] == INFTY ? -1: d[i]) << endl;
  }
};

int main() {
  int k, u, v, c;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      adj[u].push_back(make_pair(v,c));
    }
  }

  dijkstra();
};



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

int main()
{
    int n;
    cin >> n;
    //重複の上限を2とするvectorを目標
    map<int, int> M;
    rep(i, n)
    {
        int m;
        cin >> m;
        if (M[m] < 2)
            M[m]++;
    }
    vector<int> A;
    for (auto p : M)
    {
        rep(i, p.second) A.push_back(p.first);
    }

    vector<int> seisu(1000010); //ふるい（添え字はその数に対応）
    for (auto a : A)
    {
        for (int i = a; i < 1000010; i += a)
        {
            seisu[i]++;
        }
    }

    int ans = 0;
    for (auto a : A)
    {
        if (seisu[a] == 1)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 17192
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

signed main(){
    int n;
    cin >> n;
    if(n==1){
      cout << 0 << endl;
      return 0;
    }if(n==2){
      cout << 2 << endl;
      return 0;
    }
    int k = 1;

    LOOP(i,n){
      k*=10;
      k%=MOD;
    }

    int l = 1;
    LOOP(i,n){
      l*=8;
      l%=MOD;
    }

    int m = 1;

    LOOP(i,n){
      m*=9;
      m%=MOD;
    }

    int ans = k-2*m+l+2*MOD;

    // cerr << k << ":" << m << ":" << l << endl;

    ans%=MOD;

    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int H,W,N,x,y,px,py,sumxy,hon;
int main(){
    cin>>H>>W>>N;
    for(int i=0;i<N;i++){
        cin>>x>>y;
        if(i==0){px=x;py=y;}
        if(i>0){
            while(1){
                sumxy=0;
                if(px==x&&py==y)break;
                if(px<x&&py<y){hon++;px++;py++;}else
                if(px<x&&py>y){hon++;py--;}else
                if(px>x&&py>y){hon++;px--;py--;}else
                if(px>x&&py<y){hon++;py++;}else
                if(px==x||py==y){
                    sumxy=x+y-(px+py);px=x;py=y;
                    if(sumxy<0){sumxy=sumxy*-1;}
                }
                hon+=sumxy;
            }
        }
    }
    cout<<hon<<endl;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5+5;
typedef long long ll;
char s[N];
int a[N];
int flag[N];
int main()
{
    int n;
    string s;
    cin>>n>>s;
    int l=0,r=0;
    for(int i=1;i<n;i++){
        if(s[i]=='W') r++;
    }
    int ans=n-r-1;
    for(int i=1;i<n;i++){
        if(s[i-1]=='E')  l++;
        if(s[i]=='W') r--;
        ans=min(ans,n-l-r-1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;
const bool debug = 0;
//---------------------------------//

string s;

int main() {
	cin >> s;
	
	if (s[0] == s[2]) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  string S;
  int K;
  cin>>K>>S;
  
  if(S.size()<=K)
    cout<<S<<endl;
  else{
    string T=S.substr(0,K);
    cout<<T<<"..."<<endl;
  }
  
}


Measured memory_bytes: 3592
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;

  auto win = [&](char c){
    ll ret;
    if(c == 'r') ret = p;
    if(c == 's') ret = r;
    if(c == 'p') ret = s;
    return ret;
  };

  ll ans = 0;
  repLRE(i, 0, k - 1){
    bool flg;
    for (ll j = i; j < n; j += k){
      if(j == i){
        ans += win(t[j]);
        flg = false;
        continue;
      }
      bool ok = t[j] != t[j - k];
      ok |= flg;
      if(ok) {
        ans += win(t[j]);
        flg = false;
      }
      else flg = true;
    }
  }

  cout << ans << endl;

  return 0;
}


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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2")

using namespace std;

#define f first
#define s second
#define mp make_pair
#define all(x) x.begin(), x.end()

#define EPS 1e-9

#define X real()
#define Y imag()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using point = pair<double, double>;
using Vector = complex<double>;

int main() {

	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n, m;
	
	cin >> n >> m;
	
	if(n == m) cout << "Yes\n";
	else cout << "No\n";
	
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100000];
int visited[100000];
void dfs(int a){
    visited[a] = 1;
    for (int u : adj[a]) {
        if (!visited[u])
            dfs(u);
    }
}
int main(){
    int n,m;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a>>b;
        a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(!visited[i]){
            dfs(i);
            ans++;
        }
    }
    cout << ans-1;
}

Measured memory_bytes: 9900
#include <iostream>

using namespace std;

int main()
{
	int N, K;

	int p;
	p = 1;

	cin >> N >> K;

	for (int i = 0; i < N; i++) 
	{
		int a = p * 2;
		int b = p + K;

		if (a < b) 
		{
			p = a;
		}
		else 
		{
			p = b;
		}
	}

	cout << p << endl;

	return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, b[3];
int l[100];
int ans = HINF<int>();

int calc(vector<int> vec){
	int ret = HINF<int>();
	vector<int> v = {0, 1, 2};
	do{
		int num = 0;
		REP(i, 3){
			num += abs(vec[i] - b[v[i]]);
		}
		ret = min(ret, num);
	}while(next_permutation(ALL(v)));
	return ret;
}

int main(){
	cin >> n >> b[0] >> b[1] >> b[2];
	REP(i, n){
		cin >> l[i];
	}
	REP(i, pow(4, n)){
		int pa = 0, pb = 0, pc = 0;
		int num = i;
		int cnt = 0;
		REP(j, n){
			int num2 = num % 4;
			num /= 4;
			if(num2 == 0)pa += l[j];
			else if(num2 == 1)pb += l[j];
			else if(num2 == 2)pc += l[j];
			else cnt++;
		}
		if(pa == 0 || pb == 0 || pc == 0)continue;
		vector<int> vec = {pa, pb, pc};
		if(calc(vec) + (n - cnt - 1)*10 == 3)cout << pa << " " << pb << " " << pc << " " << endl;
		ans = min(ans, calc(vec) + (n - cnt - 3)*10);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
import math
import sys
n, c = map(int, input().split())
if(n==c):
    print(1)
    sys.exit()
num = list(map(int, input().split()))
for i in range(len(num)):
    if num[i] == 1:
        first = i
        break
rightCount = math.ceil((n - first - 1) / (c - 1))
if((n - first - 1) % (c - 1) == 0):
    b = 0
else:
    b = c - 1 - ((n - first - 1) % (c - 1))

leftCount = math.ceil((first - b) / (c - 1))
print(leftCount + rightCount)

Measured memory_bytes: 13812
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())

#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7:合同式の法
 
int main(){
    ll n;
    cin >> n;

    vector<ll> a;
    ll total=0;
    REP(i,n){
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
        if(i==0){
            continue;
        }
        else{
            ll tmp1 = max(a[i-1],tmp);
            if(tmp1==a[i-1]){
                total += tmp1-tmp;
                a[i] = tmp1;
                //cout << total << endl;
            }
        }
    }
    cout << total << endl;
    return 0;
}

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

void bubbleSort(int A[], int N){
	int swap_cnt=0, flag, tmp;
	flag = 1;
	while (flag){
		flag = 0;
		for (int i=N-1; i>0; i--){
			if (A[i] < A[i-1]){
				tmp = A[i-1];
				A[i-1] = A[i];
				A[i] = tmp;
				flag = 1;
				swap_cnt++;
			}
		}
	}
	for (int i=0; i<N; i++){
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << swap_cnt << endl;
}

int main(){
	int N, A[100];

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

	bubbleSort(A, N);
}

Measured memory_bytes: 1160
printlist = []
while True:
    n = input()
    if n == 0:
        break
    a = 0
    b = 0
    i = 0
    if n != 0:
        while i != n:
            set = raw_input().split()
            set[0] = int(set[0])
            set[1] = int(set[1])

            if set[0] == set[1]:
                a += set[0]
                b += set[1]

            elif set[0] > set[1]:
                a += ( set[0] + set[1] )
            else:
                b += ( set[0] + set[1] )

            i += 1

        printlist.append(a)
        printlist.append(b)
    else:
        break

#print 'hoge'
p = len(printlist)
i = 0
while i != p:
    print printlist[i],printlist[i+1]
    i += 2

Measured memory_bytes: 4252
#include<iostream>
#include<string>
#include<vector>
#include<set>

int main () {
    int n;
    std::cin >> n;
    std::vector<std::string> w(n);
    std::set<std::string> ws;
    for (int i = 0; i < n; i++)
    {
        std::cin >> w[i];
        ws.insert(w[i]);
    }

    bool f1 = ws.size() == n ? true : false;
    bool f2 = true;
    for (int i = 0; i < n - 1; i++)
    {
        if(w[i][w[i].size()-1] != w[i+1][0]) {
            f2 = false;
        }
    }

    std::string ans = (f1 && f2) ? "Yes" : "No";
    std::cout << ans << "\n";
}

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

def solve():  
  n,k = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  digit = [0]*62
  for i in range(n):
    an = a[i]
    j = 0
    while an>0:
      digit[j] += an%2
      an //= 2
      j+=1
  digit = digit[::-1]


  dp = [[0]*2  for _ in range(63)]
  for i in range(62):
    value = 2**(62-i-1)
    temp = digit[i]

    if (dp[i][1]):
        dp[i+1][1] = max(dp[i+1][1],dp[i][1]+value*max(n-temp,temp))  
      
    if (k>>(62-i-1)&1):
      dp[i+1][1] = max(dp[i][0] +value*temp,dp[i+1][1])
      dp[i+1][0] = max(dp[i+1][0],dp[i][0]+ value*(n-temp))
    else: 
      dp[i+1][0] = max(dp[i+1][0],dp[i][0]+ value*temp)
      

  #print(dp)
  print(max(dp[-1][0],dp[-1][1]))
    
solve()

Measured memory_bytes: 14596
#include <bits/stdc++.h> // {{{
using namespace std;
// clang-format off
#define ARG4(_1,_2,_3,_4,...) _4
#define rep(...) ARG4(__VA_ARGS__,FOR,REP)(__VA_ARGS__)
#define REP(i, a) FOR(i,0,a)
#define FOR(i, a, b) for(int i=(a);i<(int)(b);++i)
#define rrep(...) ARG4(__VA_ARGS__,RFOR,RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i,0,a)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(int)(a);--i)
#define ALL(c) begin(c),end(c)
#define pb emplace_back
#define em emplace
#define fi first
#define se second
#define USE1(...) template<typename __VA_ARGS__>inline
#define USE2(T, ...) USE1(T,typename __VA_ARGS__)

using ll=long long;
template<typename T>using vec=vector<T>;
USE2(T,U)bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U)bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int)T in(){T x;cin>>x;return x;}
USE2(T=int,V=vec<T>)V reserved(int n){V v;v.reserve(n);return v;}
USE1(T=int)vec<T>in(int n){auto v=reserved<T>(n);rep(i,n)v.pb(in<T>());return v;}
USE1(T)vec<T>ndvec(T&&v,int n){return vec<T>(n,v);}
USE2(T,...Ts)auto ndvec(T&&v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T)void pu(T&&x){cout<<x;}
USE1(T)void pr(T&&x){cout<<x<<'\n';}
USE2(T,...Ts)void pr(T&&x,Ts...xs){cout<<x<<' ';pr(xs...);}
USE2(T,U)void prif(bool b,T t,U f){if(b)pr(t);else pr(f);}
USE1(T)ostream&operator<<(ostream&o,vector<T>const&v){int f=0;for(auto&&x:v){if(f++)o<<' ';o<<x;}return o;}
// clang-format on
// }}}
struct IoSetup { // {{{
  IoSetup() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout.setf(ios::fixed);
  }
} iosetup; //}}}
const int inf = 1001001001;
const ll infl = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

signed main() {
  int N = in();
  auto P = in(N);

  int ans = 0;
  rep(i, N - 1) {
      if (P[i] == i + 1) {
          swap(P[i], P[i + 1]);
          ans++;
      }
  }
  if (P[N - 1] == N) ans++;
  pr(ans);

  return 0;
}


Measured memory_bytes: 640
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
b = [k for k, v in c.items() if v == 1]
b.sort()
d = {b: i for i, b in enumerate(b)}

gg = [True] * len(b)
mx = 10 ** 6 + 1
for i in c.keys():
    for j in range(2 * i, mx, i):
        if j in d:
            gg[d[j]] = False

print(sum(gg))


Measured memory_bytes: 145020
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
using namespace std;

int main()
{
    ll n,w;
    cin>>n>>w;
    ll val[n],weight[n];
    ll dp[n+1][w+1];
    for (int i = 0; i < n; i++)
    {
        cin>>weight[i]>>val[i];
    }
    for(int i=0;i<=n;i++)
    {
        for (int j = 0; j <= w; j++)
        {
            if (i==0 || j==0) 
               dp[i][j] = 0; 
            else if(weight[i-1]<=j)
            dp[i][j]=max(val[i-1]+dp[i-1][j-weight[i-1]], dp[i-1][j]);
            else dp[i][j]=dp[i-1][j];
        }
        
    }
    cout<<dp[n][w]<<endl;
    
}

Measured memory_bytes: 79104
n, m = map(int, raw_input().split())
array = []
for i in xrange(m):
	p, y = map(int, raw_input().split())
	array.append((y, p, i))

array.sort()
hash_map = dict()
for i in xrange(m):
	y, p, id = array[i]
	if p in hash_map:
		hash_map[p].append((y,id))
	else:
		hash_map[p] = []
		hash_map[p].append((y,id))

res = []
for k, v in hash_map.iteritems():
	key = str(k)
	while len(key) < 6:
		key = '0' + key
	for i in xrange(len(v)):
		year, idx = v[i]
		id = str(i+1)
		while len(id) < 6:
			id = '0' + id
		res.append((idx, key+id))
res.sort()
for i in xrange(len(res)):
	print res[i][1]






Measured memory_bytes: 59064
#include <stdio.h>

int main()
{
   while(1){
    int h, w;
    scanf("%d%d", &h, &w);
    if (h == 0 || w == 0)
    {
        break;
    }

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            if (i == 1 || i == h || j == 1 || j == w)
            {
                printf("#");
            }
            else
            {
                printf(".");
            }
        
        }
    printf("\n");
    }
   printf("\n");
   }
   return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;

void solve() {
	unsigned m, k; cin >> m >> k;
	unsigned M = 1 << m;

	if (k == 0) {
		rep(i, M) {
			if (i != 0) cout << " ";
			cout << i << " " << i;
		}
		cout << endl; return;
	}
	if (k >= M) { cout << -1 << endl; return; }

	if (m == 1) { cout << -1 << endl; return; }

	bool done[140000] = {};
	vector<unsigned> ans;
	unsigned i = 0;
	for(unsigned t = 0; t < M; t+=4) {
		while (done[i]) i++;
		unsigned a = i;
		done[a] = done[a^k] = true;
		while (done[i]) i++;
		unsigned b = i;
		done[b] = done[b^k] = true;
		ans.push_back(a);
		ans.push_back(a^k);
		ans.push_back(b);
		ans.push_back(b^k);
		ans.push_back(a^k);
		ans.push_back(a);
		ans.push_back(b^k);
		ans.push_back(b);
	};
	rep(i, ans.size()) {
		if (i != 0) cout << " ";
		cout << ans[i];
	}
	cout << endl;
}

int main() {

	solve();

	return 0;
}


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

//string HOGE(".!\"#&%&'()*+,-/:;<=>?@[\\]^_`{|}~"); // ok
//string HOGE(".!\"#&%&'()*+,-/:"); // bad
//string HOGE(";<=>?@[\\]^_`{|}~"); // bad

//string HOGE(".!\"#&%&'"); // bad
//string HOGE("()*+,-/:;<=>?@[\\"); // bad
//string HOGE("]^_`{|}~"); // bad

//string HOGE(".!\"#&%&'()*+,-/:;<=>?@[\\"); // bad
//string HOGE("()*+,-/:;<=>?@[\\]^_`{|}~"); // bad

//string HOGE(".!\"#&%&'()*,-/:;<=>?@[\\]^_`{|}~"); // ok (no +)

//string HOGE(".!\"#&%&'()*+,-/:;<=>?@[\\]^_"); // ok -5


// included '_'

//string HOGE("_.!\"#&%&'()*+,-/:;<=>?"); // ok more -5
//string HOGE("_.!\"#&%&'()*+,-/:"); // ok more -5 
//string HOGE("_.!\"#&%"); // ok more -5 
//string HOGE("_.!"); // bad 
//string HOGE("_.!\"#&%"); // bad 
//string HOGE("_.!\"#&%&'()"); // ok
string HOGE("_.!\"#&%&'("); // ?


int main(void) {
	string s;

	int total = 0;

	while (cin >> s) {
		replace_if(s.begin(), s.end(), [](char c){ return isalpha(c) || c == '.' || HOGE.find(c) != string::npos; }, ' ');
		
		istringstream iss(s);
		int num;
		while (iss >> num) {
			total += num;
		}
	}

	cout << total << endl;

	return 0;}

Measured memory_bytes: 1224
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	int ans = 0;
	map<vector<int>,int> mp;
	
	cin>>N;
	
	for(int i = 0; i < N; i++){
		vector<int> con(26);
		string s;
		
		cin>>s;
		
		for(int j = 0; j < s.size(); j++){
			con[s[j]-'a']++;
		}
		ans += mp[con];
		
		mp[con]++;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

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

struct Node
{
    int node, len;
    Node() {node = len = 0;}
    Node(int node, int len) {this -> node = node, this -> len = len;}
};
typedef vector<Node> vg;

#define MAX 200001
#define NON 0
#define MOD 1000000007

#define FOR(type, i, a, b) for(type i = a; i < b; i++)
#define FORR(type, i, b, a) for(type i = b; i > a; i--)
#define FORE(type, i, a, b) for(type i = a; i <= b; i++)
#define FORRE(type, i, b, a) for(type i = b; i >= a; i--)

#define testBit(n, bit) ((n >> bit) & 1)
#define flipBit(n, bit) (n ^ (1ll << bit))

ll cnt[MAX];
main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n; cin >> n;
    FORE(ll, i, 2, n){
        ll num; cin >> num;
        cnt[num]++;
    }
    FORE(ll, i, 1, n) cout << cnt[i] << '\n';
}

Measured memory_bytes: 5100