akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int main(){
  vector<int> N,save1,save2;
  int n;
  cin >> n;
  for(int i=1;i<=2*n;i++){
    N.push_back(i);
  }
  int m,k;
  cin >> m;
  for(int i=0;i<m;i++){
    cin >> k;
    if(k==0){
      save1.assign(&N[0],&N[n]);
      save2.assign(&N[n],&N[2*n]);
      N.clear();
      for(int j=0;j<n;j++){
        N.push_back(save1[j]);
        N.push_back(save2[j]);
      }
    }else{
      save1.assign(&N[0],&N[k]);
      save2.assign(&N[k],&N[2*n]);
      N.clear();
      for(int j=0;j<save2.size();j++){
        N.push_back(save2[j]);
      }
      for(int j=0;j<save1.size();j++){
        N.push_back(save1[j]);
      }
    }
  }
  for(int i=0;i<2*n;i++){
    cout << N[i] << endl;
  }
  return 0;
}
      

Measured memory_bytes: 1228
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> dp(5);
    rep(i, n) {
        dp[0] += a[i]; // 0

        if (a[i] == 0) dp[1] += 2; // even > 0
        else dp[1] += a[i] % 2;

        dp[2] += (a[i] + 1) % 2; // odd > 0

        if (a[i] == 0) dp[3] += 2; // even > 0
        else dp[3] += a[i] % 2;

        dp[4] += a[i]; // 0

        rep(k, 4) chmin(dp[k+1], dp[k]);
    }
    cout << dp[4] << endl;
}

Measured memory_bytes: 1920
/*  HARD WORK FOREVER PAYS  */
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define turbo(){	\
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL); \
}
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
int main() 
{ 
	turbo();
	ll n,i=1,ans=1;
	cin>>n;
	for(i=1;i<=100000;i++){
		ans=(i*(i-1))/2;
		if(ans>=n){
			cout<<i-1<<"\n";
			return 0;
		}
	}
    return 0; 
} 

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M,count=0;
  cin>>N>>M;
  for(int i=0;i<N+1;i++){
    for(int j=0;j<N+1;j++){
      if(M-i-j<=N&&M-i-j>=0)count+=1;
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;
const int maxn = 100005;

struct vec
{
    /* data */
    int u, next, c;
    vec(int uu = 0, int nn = 0,int cc = 0) : u(uu), next(nn), c(cc) {}
} e[maxn << 1];
int head[maxn];
int num_e;

void init(int n)
{
    for (int i = 0; i <= n; i++)
        head[i] = -1;
    num_e = 0;
}

void add(int u, int v)
{
    e[num_e] = vec(u, head[v], 0);
    head[v] = num_e++;
    e[num_e] = vec(v, head[u], 0);
    head[u] = num_e++;
}

int n, x, y, res;

void dfs(int u, int f, int fc)
{
    int c = 0;
    for (int i = head[u]; ~i; i = e[i].next)
    {
        int v = e[i].u;
        if (v == f)
            continue;
        c++;
        if (c==fc)c++;
        e[i].c=c;
        e[i^1].c=c;
        dfs(v,u,c);
    }
    res=max(c,res);
}

int main()
{
    scanf("%d", &n);
    init(n);
    for (int i = 1; i < n; i++)
    {
        scanf("%d%d", &x, &y);
        add(x, y);
    }
    res=0;
    dfs(1,0,0);
    printf("%d\n",res);
    for(int i=0;i<n-1;i++){
        printf("%d\n",e[i<<1].c);
    }
    return 0;
}


Measured memory_bytes: 5632
import math


import math


def main():
    N, K = map(int, input().split())
    ans = 0
    for i in range(N): 
        tmp = K / (i+1)
        a = math.log2(tmp)
        if a < 0:
            a = 0
        elif not a.is_integer():
            a = int(a) + 1
        '''
        if tmp.is_integer():
            tmp = int(tmp)
            if not (tmp and ):
                a = int(math.log2(tmp))
        else:
            a = int(math.log2(tmp)) + 1
        '''
        ans += 0.5 ** a
    ans /= N

    print('{:.15f}'.format(ans))


main()
    


Measured memory_bytes: 3060
#include<stdio.h>

int main(){
    int i;
    double x[4],y[4];

    while(1){
        for(i = 0;i < 4;i++){
            if(scanf("%lf%lf",&x[i],&y[i])==EOF)return 0;
        }

        if((x[0]<=x[2]&&x[2]<=x[1]||x[2]<=x[0]&&x[0]<=x[3])&&((y[0]<=y[2]&&y[2]<=y[1]||y[2]<=y[0]&&y[0]<=y[3])))puts("YES");
        else puts("NO");
    }
    return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
int a[51],n,k,t,sum;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	t=n-k;
	for(int i=n;i>t;i--) sum+=a[i];
	cout<<sum<<endl;
	return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n; cin >> n;
	vector<int> a(n),nxt(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	
	int la=n;
	for(int i=n-1;i>=0;i--){
		nxt[i]=la;
		if(a[i]){
			la=i;
		}
	}
	
	
	long long ans=0;
	for(int i=0;i<n;i++){
		int cur=i, num=a[i], lax=-1;
		while(1){
			lax=cur;
			cur=nxt[cur];
			if(cur==n)
				break;
			
			if((num&a[cur])==0){
				num|=a[cur];
			}
			else
				break;
		}
		ans+=cur-i;
	}
	
	cout <<ans << endl;
	return 0;
}

Measured memory_bytes: 4788
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int A = 0;
		int B = 0;
		int AB = 0;
		int O = 0;
		while(stdIn.hasNext()) {
			String[] a = stdIn.next().split(",");
			if(a[1].equals("A")) {
				A++;
			}
			if(a[1].equals("B")) {
				B++;
			}
			if(a[1].equals("AB")) {
				AB++;
			}
			if(a[1].equals("O")) {
				O++;
			}
		}
		System.out.println(A+"\n"+B+"\n"+AB+"\n"+O);
	}
}

Measured memory_bytes: 17160
#include <stdio.h>

int main(){
    double a,b,c,d,e,f;
    double x,y;
    
    while (scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) != EOF) {
        x=(double)((c*e-b*f)/(a*e-b*d));
        y=(double)((c*d-a*f)/(b*d-a*e));
        if(-0.0005<x && x<=0)
            x=0;
        if(-0.0005<y && y<=0)
            y=0;
        printf("%.3f %.3f\n",x,y);
    }
    
    return 0;
}

Measured memory_bytes: 2728
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector


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

int64_t N, C; cin >> N >> C;
VVI D(C, VI(C)), t(3, VI(C, 0));
rep(i, 0, C) invec(D[i]);
rep(i, 1, N+1) rep(j, 1, N+1) {
    int x; cin >> x;
    ++t[(i + j)%3][x-1];
}

int ans = INF;
rep(i, 0, C) rep(j, 0, C) if (i != j) rep(k, 0, C) if (i != k && j != k){
    int tt = 0;
    rep(l, 0, C) tt += D[l][i] * t[0][l];
    rep(l, 0, C) tt += D[l][j] * t[1][l];
    rep(l, 0, C) tt += D[l][k] * t[2][l];
    ans = min(ans, tt);
}


cout << ans << "\n";

}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;

const int S_N = 4;
const int P_N = 2;

int main(){
    int res = 0;
    rep(i, P_N){
        int sum = 0;
        rep(j, S_N){
            int score; cin >> score;
            sum += score;
            res = max(res, sum);
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1160
x,y,z,K = (int(i) for i in input().split(" "))

a_ = sorted([int(i) for i in input().split(" ")])[::-1]
b_ = sorted([int(i) for i in input().split(" ")])[::-1]
c_ = sorted([int(i) for i in input().split(" ")])[::-1]

res = []
for i in range(x):
    for j in range(y):
        for k in range(z):
            if (i+1)*(j+1)*(k+1) <= K:
                res.append(a_[i]+b_[j]+c_[k])
            else:
                break

res = sorted(res)[::-1]

for i in range(K):
    print(res[i])

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

int main() 
{
  long long health, num, count = 0;
	 
	 cin >> health >> num;
	 long long arr[num];
		long long i = 0;


	 while(num--)
	 {
		 
		 cin>> arr[i];
		 count+=arr[i];
		 i++;
		 
	 }


	if(count >= health)
	{
		cout << "Yes";
	}
	else{
		cout << "No";
	}

}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main()
{
	int s;
	cin >> s;
	bool flag[1000006]={};

	flag[s-1]=true;

	int i;

	for(i=2;i<=1000006;i++)
	{
		if(s%2==0)
			s/=2;
		else
			s=3*s+1;

		if(flag[s-1])break;
		flag[s-1]=true;
	}

	cout << i << endl;
}


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

int main()
{
    string s;
    cin>>s;
    if((s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]) || (s[0]==s[2] && s[1]==s[3] && s[0]!=s[1]) || (s[1]==s[2] && s[0]==s[3] && s[0]!=s[1])){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3620
import sys
N, A, B = map(int, input().split())
if (B-A) % 2 == 0:
    ans = (B-A)//2
    print(ans)
    sys.exit()
if A-1 <= N-B:
    ans = A
    B -= A
    A = 1
else:
    ans = N-B+1
    A += ans
    B = N
if A != B:
    ans = ans+(B-A)//2
print(ans)


Measured memory_bytes: 9056
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    string S; cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import collections

n,q=map(int, input().split())
cnt=[0]*(n+1) # 添字で指定しやすいように一つ多い １以降を使用する
g=[[] for _ in range(n+1)]
for _ in range(n-1):
  a,b=map(int, input().split())
  g[a].append(b)
  g[b].append(a)
for _ in range(q):
  v,val=map(int, input().split())
  cnt[v]+=val
q=collections.deque()
q.append(1)
checked_=[0]*(n+1)
while q:
  v=q.pop()
  checked_[v]=1
  for u in g[v]:
    if checked_[u]==1:
      continue
    cnt[u]+=cnt[v]
    q.append(u)
print(*cnt[1:])


Measured memory_bytes: 105740
heads ([]:_) = []
heads matrix =
  let h = reverse $ map (head) matrix
      r = map (drop 1) matrix
  in
    h:(heads r)

rot90 ([]:_) = []
rot90 matrix = heads matrix

main = do
  c <- getContents
  let i = lines c
      a90 = rot90 i
      a180= rot90 a90
      a270= rot90 a180
  putStrLn "90"
  mapM_ putStrLn a90
  putStrLn "180"
  mapM_ putStrLn a180
  putStrLn "270"
  mapM_ putStrLn a270

Measured memory_bytes: 3472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int dp[1010][1010];

int main() {
    int q;
    cin>>q;
    while(q--){
        string s,t;
        cin>>s>>t;
        int n=s.size(),m=t.size();
        rep(i,1010){
            rep(j,1010){
                dp[i][j]=0;
            }
        }
        rep(i,n){
            rep(j,m){
                if(s[i]==t[j]) dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
                dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j]);
                dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1]);
            }
        }

        cout<<dp[n][m]<<endl;
    }

    return 0;
}




Measured memory_bytes: 7120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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 <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N; cin >> N;
    VI A(N);
    REP(i,N) cin >> A[i];
    int now = 0;
    REP(i,N){
        if(A[i] == now + 1){
            now++;
        }
    }
    if(now == 0){
        cout << -1 << endl;
        return 0;
    }
    cout << N - now << endl;

}


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

int main()
{
	int m;
	cin >> m;
	while (m--){
		string str;
		cin >> str;
		set<string> s;
		for (int i = 1; i < str.size(); i++){
			string a(str, 0, i);
			string b = a;
			reverse(b.begin(), b.end());
			string c(str, i, str.size() - i);
			string d = c;
			reverse(d.begin(), d.end());
			
			//cout << a << " " << b << " " << c << " " << d << endl;
			
			s.insert(a + c);
			s.insert(a + d);
			s.insert(b + c);
			s.insert(b + d);
			s.insert(c + a);
			s.insert(d + a);
			s.insert(c + b);
			s.insert(d + b);
		}
		cout << s.size() << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1292
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll i,j,n,k,a[200010];
  cin >> n >>k;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  if(k==0){
    sort(a,a+n,greater<int>());
    cout << a[0] << endl;
    return 0;
  }
  ll min=0,max=1000000001;
  while(abs(min-max)>1){
    ll mid=(min+max)/2;
    ll sum=0,ch=0;
    for(j=0;j<n;j++){
      if(a[j]<=mid){
        continue;
      }
      ll x=a[j];
      if(x%mid==0){
        sum+=(x/mid)-1;
      }
      else{
        sum+=(x/mid);
      }
      if(sum>k){
        ch=1;
        break;
      }
    }
    if(ch==0){
      max=mid;
    }
    else{
      min=mid;
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 5136
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;



int main(){
    ll N,K;cin>>N>>K;
    ll x[100010],MIN=999999999999999;
    rep(i,0,N)cin>>x[i];
    rep(i,0,N-K+1){
        ll tmp;
        if(x[i]>0)tmp=x[i+K-1];
        else if(x[i+K-1]<0)tmp=-x[i];
        else tmp=max(abs(x[i+K-1]),abs(x[i]))+2*min(abs(x[i+K-1]),abs(x[i]));
        MIN=min(tmp,MIN);
    }
    cout<<MIN<<endl;
}







Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NK = Console.ReadLine().Split(' ');
            int N = int.Parse(NK[0]);
            int K = int.Parse(NK[1]);
            if (K == 1) Console.WriteLine(0.ToString());
            else if (N >= K)
            {
                Console.WriteLine((N-K).ToString());
            }
        }
    }
}

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

int main(){
    int a,b;
    cin>>a>>b;
    string ans;
    if(a+b==15) ans="+";
    else if(a*b==15) ans="*";
    else ans="x";
    cout<<ans<<endl;
    return 0;
}


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

t = [0]

for i in range(N):
    t.append(int(input().rstrip()))


index = 1
found = False
for i in range(N):
    if t[index] == 2:
        found = True
        break

    index = t[index]


print(i + 1 if found else -1)




Measured memory_bytes: 7208
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int k = scan.nextInt();
        Map<Integer, Integer> xM = new HashMap();
        Map<Integer, Integer> yM = new HashMap();
        Set<String> S = new HashSet();
        for (int i = 1; i <= k; i++) {
            int x = scan.nextInt();
            int y = scan.nextInt();
            xM.put(x, xM.getOrDefault(x, 0) + 1);
            yM.put(y, yM.getOrDefault(y, 0) + 1);
            String st = x + "-" + y;
            S.add(st);
        }
        int mxNum = 0;
        for (int val : xM.values()) mxNum = Math.max(mxNum, val);
        int myNum = 0;
        for (int val : yM.values()) myNum = Math.max(myNum, val);
        List<Integer> listx = new ArrayList();
        for (int key : xM.keySet()) {
            if (xM.get(key) == mxNum) listx.add(key);
        }
        List<Integer> listy = new ArrayList();
        for (int key : yM.keySet()) {
            if (yM.get(key) == myNum) listy.add(key);
        }
        int ans = mxNum + myNum - 1;
        for (int i = 0; i < listx.size(); i++) {
            for (int j = 0; j < listy.size(); j++) {
                String st = listx.get(i) + "-" + listy.get(j);
                if (S.contains(st) == false) {
                    System.out.println(ans + 1);
                    return;
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 152008
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/*-------------ここまで---------------------------------------------*/

//C++(GCC9.2.1)

signed main() {
    //宣言
    int N;
    int S = 1;
    cin >> N;
    vector<int>vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec[i];
        if (vec[i] == S) {
            S++;
        }
    }
    if (S == 1) {
        cout << -1 << endl;
    }
    else {
        cout << N - (S - 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 4820
#include<bits/stdc++.h>
using namespace std;
int main()
{
     string s;
     cin>>s;
     string str ="CODEFESTIVAL2016";
     int res  = 0;
     for(int i =0 ;i<str.length();i++)
     {
          if(s[i]!=str[i])
          {
               res++;
          }
      }
     cout<<res<<endl;
     return 0;
}

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

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

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


int main()
{
   su;
   int H,W,h,w;
   cin>>H>>W>>h>>w;
   cout<<(H-h)*(W-w)<<nl;
   return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
// atoi : atoi(変数名.c_str())
// to_string(数値)
// %0桁数d とすると表示桁数が「桁数」に満たない場合に0埋めされる
// find(): int i = 変数名.find(“文字列”) 何番目にあるかを得る
// cout << (条件 ? "Yes" : "No") << endl;
// printf("%02d:%02d:%02d",hour,minute,second);
// 降順 sort(a.begin(),a.end(),greater<int>());
// bitset<ビット数> 変数名;  // すべてのビットが0の状態で初期化される
// bitset<ビット数> 変数名("ビット列");  // 指定したビット列で初期化される
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int gcd(int a,int b){
  if(a < b) swap(a,b);
  if(b == 0) return a;
  return gcd(b,a%b);
}

int main(){
  long n,m;
  string s,t;
  cin >> n >> m >> s >> t;
  long g = gcd(n,m);
  long l = (n * m)/g;
  long i=0,j=0;
  while(i < s.size() && j < t.size()){
    long sx = (l/n)*i;
    long tx = (l/m)*j;
    if(sx == tx){
      if(s.at(i) != t.at(j)){
        cout << -1 << endl;
        return 0;
      }
      i++;
      j++;
    }else if(sx < tx){
      i++;
    }else{
      j++;
    }
  }
  cout << l << endl;
}

Measured memory_bytes: 512
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

s = list(read())
flg = True
for i in range(1, len(s) + 1):
    if i % 2 == 1:
        if s[i - 1] == "R" or s[i - 1] == "U" or s[i - 1] == "D":
            pass
        else:
            flg = False
    else:
        if s[i - 1] == "L" or s[i - 1] == "U" or s[i - 1] == "D":
            pass
        else:
            flg = False

if flg:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 6864
#include<stdio.h>
int main(){


  int x,y;

  /*0<=x
    y<=10000*/
    while(1){
    scanf("%d %d",&x,&y);
    if(x == 0 && y == 0)break;
    
  
    if (x>y){
      printf("%d %d\n",y,x);
    }
    if (x<y){ 
      printf("%d %d\n",x,y);
     }
    if (x==y){
      printf("%d %d\n",x,y);
    }
    }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 1e9 + 7
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.begin(), v.end(), greater<ll>()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
using namespace std;
int main() {
    ll a, b;
    cin >> a >> b;
    ll nos = 1;
    ll ct = 0;
    while(nos < b) {
        nos += a;
        nos -= 1;
        ++ct;
    }
    cout << ct;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=sorted([int(i) for i in input().split()])
import bisect

def hantei(now):
    num=0
    for ax in a:
        bi = bisect.bisect_left(a,now-ax)
        num+= bi
#         print(now,ax,bi)
    return n**2-num

mi = a[0]*2-1
ma = a[-1]*2+1
kotae=ma
while mi<ma:
    now=(mi+ma)//2
    which = hantei(now)<=m#なんか判定
    if which:
        ma=now
        kotae=now
    else:
        mi=now+1
kotae-=1

suma=[0]*(n+1)
suma[-2]=a[-1]
for i in range(n-2,-1,-1):
    suma[i] = suma[i+1]+a[i]
    
ans=0
kazu=0
for ax in a:
    bi = bisect.bisect_left(a,kotae-ax)
    ans+= (n-bi)*ax+suma[bi]
    kazu+=n-bi
print(ans-(kazu-m)*kotae)


Measured memory_bytes: 55744
#include <algorithm>
#include <iostream>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>

using namespace std;

#define ll long long
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define pb push_back

ll power(int x, unsigned int y){
    ll res = 1;
    while(y > 0){
        if(y & 1) res = res * x;
        y >>= 1;
        x *= x;
    }
    return res;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a, b;
    cin >> a >> b;
    cout << (a*b);

}

Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(10)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }

class vec2d {
public:
	double x, y;
	vec2d(double x, double y) :x(x), y(y) {}
	double norm2() const {
		return x * x + y * y;
	}
	vec2d operator+(vec2d v) {
		return vec2d(x + v.x, y + v.y);
	}
	vec2d operator-(vec2d v) {
		return vec2d(x - v.x, y - v.y);
	}
	vec2d operator*(double k) const {
		return vec2d(x * k, y * k);
	}
	vec2d operator/(double k)const {
		return vec2d(x / k, y / k);
	}
	double operator*(const vec2d&v)const {
		return x * v.x + y * v.y;
	}
	static vec2d projection(const vec2d&a, const vec2d&b) {
		return a * (a * b) / a.norm2();
	}
};
signed main() {
	SETP;
	int xp1 = in(), yp1 = in(), xp2 = in(), yp2 = in();
	vec2d a(xp2 - xp1, yp2 - yp1);
	int q = in();
	REP(i, q) {
		int x = in(), y = in();
		vec2d b(x - xp1, y - yp1);
		vec2d proj = vec2d::projection(a, b);
		vec2d t = proj - b;
		vec2d ref = b + t * 2;
		cout << ref.x + xp1 << ' ' << ref.y + yp1 << endl;
	}
}


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

int H, W, C, M, Nw, Nc, Nm, Win, Wout, Cin, Cout, Mio, s, t, res;
int cap[310][310];
bool used[310];
enum { source = 300, sink, nwin, nwout, ncin, ncout, nmio };

bool dfs(int v)
{
    used[v] = true;
    for(int i = 0; i < 310; ++i)
        if(cap[v][i] > 0 && !used[i])
            if(i == sink || dfs(i)) {
                --cap[v][i]; ++cap[i][v]; return true;
            }
    return false;
}

int main()
{
    while(cin >> H >> W >> C >> M && H >= 0)
    {
        memset(cap, 0, sizeof(cap));
        cin >> cap[nwin][nwout] >> cap[ncin][ncout] >> cap[nmio][sink];
    	Mio = (Cout = (Cin = (Wout = (Win = H) + W) + W) + C) + C;

        for(int i = 0; i < H; ++i)
            cap[source][i] = cap[i][nwin] = 1;
        for(int i = 0; i < W; ++i) {
            cin >> s;
            for(int j = 0; j < s; ++j) { cin >> t; cap[t-1][Win+i] = 1; }
            cap[Win+i][Wout+i] = cap[Wout+i][ncin] = 1;
        }
        for(int i = 0; i < C; ++i) {
            cin >> s;
            for(int j = 0; j < s; ++j) { cin >> t; cap[Wout+t-1][Cin+i] = 1; }
            cap[nwout][Cin+i] = cap[Cin+i][Cout+i] = cap[Cout+i][nmio] = 1;
        }
        for(int i = 0; i < M; ++i) {
            cin >> s;
            for(int j = 0; j < s; ++j) { cin >> t; cap[Cout+t-1][Mio+i] = 1; }
            cap[ncout][Mio+i] = cap[Mio+i][sink] = 1;
        }

        res = 0;
        do fill_n(used, 310, false); while(dfs(source) && ++res);
        cout << res << endl;
    }
}

Measured memory_bytes: 1248
#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 k;
  string s;
  cin >> k;
  for(int i=1;i<=k;i++)
   s += "ACL";
    
  cout << s << endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <queue>

using namespace std;
using llint = long long int;

int n;
map<int, int> memo;
int longest = 1;

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int x;
    cin >> x;
    int tmp = memo[x - 1] + 1;
    memo[x] = tmp;
    if (tmp > longest)
    {
      longest = tmp;
    }
  }
  cout << n - longest << endl;
  return 0;
}


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

const int mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0) :x((x % mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) {
			x -= mod;
		}
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) {
			x -= mod;
		}
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	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 pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct Sieve {
	int n;
	vector<int> f, primes;
	Sieve(int n = 1) :n(n), f(n + 1) {
		f[0] = f[1] = -1;
		for (ll i = 2; i <= n; i++) {
			if (f[i]) {
				continue;
			}
			primes.push_back(i);
			f[i] = i;
			for (ll j = i * i; j <= n; j += i) {
				if (!f[j]) {
					f[j] = i;
				}
			}
		}
	}

	bool isPrime(int x) {
		return f[x] == x;
	}

	vector<int> factorList(int x) {
		vector<int> res;
		while (x != 1) {
			res.push_back(f[x]);
			x /= f[x];
		}
		return res;
	}

	vector<P> factor(int x) {
		vector<int> fl = factorList(x);
		if (fl.size() == 0) {
			return {};
		}
		vector<P> res(1, P(fl[0], 0));
		for (int p : fl) {
			if (res.back().first == p) {
				res.back().second++;
			}
			else {
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
};

int main() {
	Sieve sieve(1e6);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	map<int, int> mp;
	rep(i, n) {
		auto f = sieve.factor(a[i]);
		for (auto p : f) {
			mp[p.first] = max(mp[p.first], p.second);
		}
	}

	mint lcm = 1;
	for (auto p : mp) {
		rep(i, p.second) {
			lcm *= p.first;
		}
	}

	mint ans;
	rep(i, n) {
		mint b = lcm / a[i];
		ans += b;
	}
	cout << ans.x << endl;
}

Measured memory_bytes: 4984
///
// File:  a.go
// Author: ymiyamoto
//
// Created on Sat Apr 14 21:51:07 2018
//
package main

import (
	"fmt"
)

var A, B, X int

func main() {
	fmt.Scan(&A, &B, &X)

	if 0 <= X-A && X-A <= B {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>

typedef long long ll;

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

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

Measured memory_bytes: 3612
# coding:utf-8

INF = float('inf')


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


S = input()
T = input()

A = []
B = []
tmp = []
tmp2 = []

cnt = 0
for s in S:
    if s in tmp:
        A.append(tmp.index(s))
    else:
        tmp.append(s)
        A.append(cnt)
        cnt += 1


cnt = 0
for t in T:
    if t in tmp2:
        B.append(tmp2.index(t))
    else:
        tmp2.append(t)
        B.append(cnt)
        cnt += 1

if A == B:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 6832
#include<stdio.h>

int n,A[20];

int main() {
  int q,i,m;

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

  scanf("%d",&q);
  for(i = 0 ; i < q ; i++) {
    scanf("%d",&m);
    if(result(0,m))
      printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int result(int x, int y) {

  if(x >= n) return 0;
  if(A[x] == y) return 1;
  if(result(x+1,y)) return 1;
  if(result(x+1,y-A[x])) return 1;
  return 0;
}



Measured memory_bytes: 2104
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let s = read::<String>().chars().collect::<Vec<_>>();
    let s1 = (0..n / 2).map(|x| s[x]).collect::<Vec<_>>();
    let s2 = (n / 2..n).map(|x| s[x]).collect::<Vec<_>>();
    if s1 == s2 {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc= new Scanner(System.in);
		
		int  N= sc.nextInt();
		sc.close();
		int ans=0;		
		for(int a= 1;a<N;a++){
			for(int b= 1; a*b<N;b++){
				ans++;
			}
		}
		
		System.out.println(ans);
		
		
	}

}


Measured memory_bytes: 35696
#include <bits/stdc++.h>
using namespace std;
const long long INF = 100000000000;
int main()
{
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<long long> s(A), t(B);
    for (int i = 0; i < A; i++)
    {
        cin >> s[i];
    }
    for (int i = 0; i < B; i++)
    {
        cin >> t[i];
    }
    s.push_back(INF), s.push_back(-INF);
    t.push_back(INF), t.push_back(-INF);
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    for (int i = 0; i < Q; i++)
    {
        long long x;
        cin >> x;
        long long res = INF;
        long long d1, d2;
        long long a = lower_bound(s.begin(), s.end(), x) - s.begin();
        long long b = lower_bound(t.begin(), t.end(), x) - t.begin();
        for (int j = 0; j <= 1; j++)
        {
            for (int k = 0; k <= 1; k++)
            {
                d1 = abs(s[a - j] - x) + abs(t[b - k] - s[a - j]);
                d2 = abs(t[b - k] - x) + abs(s[a - j] - t[b - k]);
                res = min(res, min(d1, d2));
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 2912
import sys
s=input()
t=input()
n=10**5
k=0
h=[]
for i in range(len(s)-len(t)+1):
    h=s[i:i+len(t)]
    l=0
    for j in range(len(t)):
        if h[j]!=t[j]:
            l+=1
    n=min(n,l)
print(n)


Measured memory_bytes: 9048
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

struct ST;
int n;
vector<string> s;
vector<ST> sts(1);
struct ST{
	vector<int> e;
	vector<int> tp;
	ST(): tp(26), e(26, -1) {}
};

void STadd(string ts){
	auto si=0;
	for(int i=ts.size()-1; i>=0; i--){
		char c=ts[i];
		int ci=c-'a';

		if(i>=1){
			int nsi=sts[si].e[ci];
			if(nsi== -1){
				sts.push_back(ST());
				nsi=sts.size()-1;
				sts[si].e[ci]=nsi;
			}
			si=nsi;
		}
		else{//i==0
			sts[si].tp[ci]++;
		}
	}
}

int main(){
	cin>>n;
	s=vector<string>(n);
	rep(i, n) cin>>s[i];

	map<char, int> sm1;

	rep(i, n){
		if(s[i].size()==1){
			sm1[s[i][0]]++;
		}
		else{
			STadd(s[i]);
		}
	}

	ll cnt=0;
	rep(i, n){
		vector<int> deta(26, 0);
		rep(j, s[i].size()) deta[s[i][j]-'a']++;
		rep(k, 26) if(deta[k]>0) cnt+=sm1['a'+k];

		int si=0;
		for(int j=s[i].size()-1; j>=0; j--){
			if(j<s[i].size()-1){
				int nsi=sts[si].e[s[i][j+1]-'a'];
				if(nsi== -1) break;
				si=nsi;
				rep(k, 26) if(deta[k]>0){
					cnt+= sts[si].tp[k];
				}
			}
			deta[s[i][j]-'a']--;
		}
	}
	cnt-=n;

	cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 269652
#include<stdio.h>

int main() {
	int i, j, n, num, card, a[4][13] = {0, 0};
	char c;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf(" %c", &c);
		scanf("%d", &num);

		if (c == 'S') {
			card = 0;
		}
		else if (c == 'H') {
			card = 1;
		}
		else if (c == 'C') {
			card = 2;
		}
		else if (c == 'D') {
			card = 3;
		}
		a[card][num - 1] = 1;
	}
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			if (a[i][j] == 0) {
				if (i == 0) {
					printf("S %d\n", j + 1);
				} else if (i == 1) {
					printf("H %d\n", j + 1);
				} else if (i == 2) {
					printf("C %d\n", j + 1);
				} else if (i == 3) {
					printf("D %d\n", j + 1);
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
typedef vector<int> vint;
typedef pair<int,int> pii;
#define fst first
#define scn second
#define mp make_pair
int dp[100010][11];
int c[100010];
int main(){
    int n,m;    cin>>n>>m;
    vector<vint> edge(n);
    for(int i=0;i<m;i++){
        int a,b;    cin>>a>>b;  a--;    b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    int q;  cin>>q;
    priority_queue<pair<int,pii> > pq;
    for(int i=1;i<=q;i++){
        int v,d;    cin>>v>>d>>c[i];    v--;
        for(int j=0;j<=d;j++)   dp[v][j]=max(dp[v][j],i);
        pq.push(mp(d,mp(i,v)));
    }
    while(!pq.empty()){
        auto it=pq.top();   pq.pop();
        int d=it.fst,c=it.scn.fst,pos=it.scn.scn;
        if(c!=dp[pos][d])   continue;
        if(d==0)    continue;
        d--;
        for(int i=0;i<edge[pos].size();i++){
            int to=edge[pos][i];
            if(c>dp[to][d]){
                for(int j=0;j<=d;j++)   dp[to][j]=max(dp[to][j],c);
                pq.push(mp(d,mp(c,to)));
            }
        }
    }
    for(int i=0;i<n;i++)    cout<<c[dp[i][0]]<<endl;
    return 0;
}

Measured memory_bytes: 19308
#include <bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string t;
    cin >> t;
    bool n = false, w = false, s = false, e = false;
    for(int i = 0; i < t.length(); i++){
    	if(t[i] == 'N') n = true;
    	if(t[i] == 'W') w = true;
    	if(t[i] == 'S') s = true;
    	if(t[i] == 'E') e = true;
    }
    bool ans = false;
    if(n && w && s && e) ans = true;
    else if(n && !w && s && !e) ans = true;
    else if(!n && w && !s && e) ans = true;
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

static const long long INFTY = (1LL<<32);
int egs[9900];
int N[100];
int v, e;
long long D[100][100];

void floyd() {
	for (int k = 0;k < v ;k++) {
		for (int i = 0;i < v;i++) {
			if (D[i][k] == INFTY) continue;
			for (int j = 0;j < v ;j++) {
				if (D[k][j] == INFTY) continue;
				D[i][j]=min(D[i][j], D[i][k] + D[k][j]);
			}
		}
	}
}
int main() {
	int s, t, d;
	cin >> v >> e;
	
	for (int i = 0;i <v;i++) {
		for (int j = 0;j < v;j++) {
			if (i == j) { D[i][j] = 0; }
			else { D[i][j] = INFTY; }
		}
	}
	for (int i = 0;i < e;i++) {
		cin >> s >> t>> d;
		D[s][t] = d;
	}
	floyd();
	for (int i = 0;i < v;i++) {
		if (D[i][i] < 0) {
			cout<< "NEGATIVE CYCLE" << endl;
			return 0;
		}
	}
	for (int i =0;i < v ;i++) {
		for (int j = 0;j < v;j++) {
		    if(j)cout<<" ";
			if (D[i][j] == INFTY) {
				cout << "INF";
			}
			else {
				cout << D[i][j];
			}
		}
		cout << endl;
	}
	return 0;
}


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

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;

int main(){
  int h, w;
  cin>>h>>w;
  vector<string> v(h);
  string s = "";
  rep(i,w+2) s+='#';
  rep(i,h) {
    cin>>v[i];
    v[i].push_back('#');
  }
  std::cout << s << std::endl;
  rep(i,h) {
    std::cout << '#';
    std::cout << v[i] << endl;
  }
  std::cout << s << std::endl;

  return 0;
}


Measured memory_bytes: 888
// https://www.hamayanhamayan.com/entry/2019/10/27/233431_2
// http://atriasoft.work/compe-programming/861

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long K = sc.nextLong();
    int[] A = new int[N]; // cost digest
    int[] F = new int[N]; // uneasiness
    long sumA = 0;
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
      sumA += A[i];
    }
    if (sumA <= K) {
      System.out.println(0);
      return;
    }
    for (int i = 0; i < N; i++) {
      F[i] = sc.nextInt();
    }

    A =
        Arrays.stream(A)
            .boxed()
            .sorted(Comparator.reverseOrder())
            .mapToInt(Integer::intValue)
            .toArray();
    Arrays.sort(F);

    // binary-search
    long l = 0, r = Long.MAX_VALUE;
    while (l < r) {
      long m = (l + r) / 2;
      if (isPossible(m, A, F, K)) {
        r = m;
      } else {
        l = m + 1;
      }
    }
    System.out.println(l);
  }

  static boolean isPossible(long af, int[] A, int[] F, long K) {
    long prep = 0;
    for (int i = 0; i < A.length; i++) {
      long need = af / F[i];
      prep += Math.max(0, A[i] - need);
    }
    return prep <= K;
  }
}


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

int main(){
    string s,t;
    cin >> s >> t;
    //string ss = s + s;
    //vector<vector<int>> DP(26,vector<int>(s.size()));
    vector<int> memo[26];
    int n = s.size();
    rep(i,n){
        memo[s[i] - 'a'].push_back(i);    
    }
    rep(i,n){
        memo[s[i] - 'a'].push_back(i+n);    
    }
    /*rep(i,ss.size()){
        memo[ss[i] - 'a'].insert(i);        
    }*/
    int cur = 0;
    //int p = 0;
    ll ans = 0;
    //cout << "aaa"<<endl;
    int nt = t.size();
    int ns = s.size();

    rep(i,nt){
        auto itr = lower_bound(memo[t[i]-'a'].begin(), memo[t[i]-'a'].end(), cur);// - memo[t[i] - '0'].begin();
        if(itr == memo[t[i] -'a'].end()){
            cout << -1 << endl;
            return 0;
        }else{
            cur = *itr+1;
            if(cur >= ns){
                cur -= ns;
                ans += ns;
            }

        }
    }
    ans += cur;
    cout << ans << endl;
    /*
    vector<vector<int>> DP();
    map<char,int> ms,mt;
    rep(i,s.size()){ 
        ms[s[i]]++;
    }
    rep(i,t.size()){ 
        mt[t[i]]++;
    }
    rep(i,t.size()){
        if(ms[t[i]] <= 0){
            cout << -1 << endl;
            return 0;
        }
    }
    int Mq = 0;
    //int rr = 0;
    rep(i,t.size()){
        int q = (mt[t[i]])/ ms[t[i]];
        //int r = (mt[t[i]])% ms[t[i]];
        Mq = max(Mq, q);
        /*if(qq < q){
            qq = q;
            rr = r;
        }*//*
        //int nneed = max(nneed, (mt[t[i]] + ms[t[i]] - 1 )/ ms[t[i]]);
    }
    //Mq++;
    map<char,int> memo; 
    rep(i,t.size()){
        int q = (mt[t[i]])/ ms[t[i]];
        if(Mq == q){
            int r = (mt[t[i]])% ms[t[i]];
            memo[t[i]] = max(memo[t[i]], r);
        }
    }
    int tmp = -1;
    rep(i,t.size()){
        memo[t[i]]--;
        if(memo[t[i]] <= 0){
            tmp = i+1;
        }
    }
  //  if(Mq != 1){
    cout << Mq*t.size() + tmp << endl;
//        return 0;*/


}

Measured memory_bytes: 1724
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		int s = 0;
		int e = W.length()-1;
		int ans = 0;
		while(s < e){
			if(W.charAt(s) != W.charAt(e)){
				ans ++;
			}
			s++;
			e--;
		}

		System.out.println(ans);



	}


}


Measured memory_bytes: 21204
from collections import deque

def solve(N, X, Y):
    ret = 0
    counter = 0
    stack = deque()
    cities = [i for i in range(N)]
    for city_idx in cities:
        stack.append([0, city_idx, cities[:city_idx] + cities[city_idx + 1:]])

    while stack:
        dist, city_idx, rest = stack.pop()
        if not rest:
            ret += dist
            counter += 1

        for idx, next_city_idx in enumerate(rest):
            stack.append([dist + ((X[city_idx] - X[next_city_idx])**2 + (Y[city_idx] - Y[next_city_idx])**2)**(1/2), next_city_idx, rest[:idx] + rest[idx + 1:]])

    print(ret / counter)

if __name__ == "__main__":
    N = int(input())
    X = []
    Y = []

    for _ in range(N):
        x, y = map(int, input().split())
        X.append(x)
        Y.append(y)

    solve(N, X, Y)

Measured memory_bytes: 44268