akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
	int N;
	cin >> N;

	vector<int> A;
	inputVector(A, N);

	if (A[0] != 0) {
		cout << -1 << endl;
		return 0;
	}

	REP(i, 1, N - 1) {
		if (A[i] > A[i - 1] && A[i] - A[i - 1] != 1) {
			cout << -1 << endl;
			return 0;
		}
	}

	int ret = 0;
	int prev = N;
	for (int i = N - 1; i >= 0; i--) {
		if (i == N - 1 || A[i] != A[i + 1] - 1) {
			ret += A[i];
		}
	}

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


bool input() {
  return true;
}

void solve(){
}

int main() {
  double a,b,c,d; cin >>a >>b >>c >>d;
  double res = (a-c)*(a-c) + (b-d)*(b-d);
  res = sqrt(res);
  cout <<fixed <<setprecision(12) <<res <<endl;
}


Measured memory_bytes: 3272
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main() {
    double pi = 3.14159265358979323846;
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double radh, radm;
    radh = ((h + m / 60) / 6) * pi;
    radm = m / 30 * pi;
    double ans;
    ans = sqrt(a * a + b * b - 2 * a * b * cos(abs(radh - radm)));
    cout << fixed << setprecision(20) << ans << endl;
}

Measured memory_bytes: 4164
#include<cstdio>
#include<cstring>
int main()
{
	char a[100500];
	scanf("%s",a);
	int len = strlen(a);
	int sum=0;
	for(int i = 0; i < len-1; i++)
	{
		if(a[i]!=a[i+1])
		sum++;
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	char box[12][12]={0};
	while(cin>>box[1][1]){
		for(int i=2;i<=8;++i){
			cin>>box[i][1];
		}
		
		for(int i=2;i<=8;++i){
			for(int j=1;j<=8;++j){
				cin>>box[j][i];
			}
		}
		int firstx=-1,firsty;
		for(int i=1;i<=8&&firstx==-1;++i){
			for(int j=1;j<=8;++j){
				if(firstx==-1&&box[j][i]=='1'){
					firstx=j;
					firsty=i;
					break;
				}
			}
		}
		if(box[firstx][firsty+3]=='1'){
			cout<<'B'<<endl;
		}
		else if(box[firstx+3][firsty]=='1'){
			cout<<'C'<<endl;
		}
		else if(box[firstx-1][firsty+2]=='1'){
			cout<<'D'<<endl;
		}
		else if(box[firstx+2][firsty+1]=='1'){
			cout<<'E'<<endl;
		}
		else if(box[firstx+1][firsty+2]=='1'){
			cout<<'F'<<endl;
		}
		else if(box[firstx-1][firsty+1]=='1'){
			cout<<'G'<<endl;
		}
		else {
			cout<<'A'<<endl;
		}
	}
	return 0;
}

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

const int MAXN = 1e6 + 10, MOD = 1e9 + 7;
long long dp[MAXN];
bool O[MAXN];
int n, m;

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a;
		cin >> a;
		O[a] = 1;
	}
	dp[0] = 1;
	for (int i = 1; i <= n; i++) {
		if (O[i])
			continue;
		dp[i] = dp[i - 1] + dp[i - 2];
		dp[i] %= MOD;
	}
	cout << dp[n];
}


Measured memory_bytes: 1152
#include<stdio.h>

int
main()
{
    int S;
    int h, m, s;

    scanf("%d", &S);
    h = S / (60 * 60);
    m = (S / 60) % 60;
    s = S % 60;

    printf("%d:%d:%d\n", h, m, s);

    return 0;
}


Measured memory_bytes: 2056
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <algorithm>   //sort,二分探索,など
#include <bitset>      //固定長bit集合
#include <chrono>      //実行時間計測
#include <cmath>       //pow,logなど
#include <complex>     //複素数
#include <deque>       //両端アクセスのキュー
#include <functional>  //sortのgreater
#include <iomanip>     //setprecision(浮動小数点の出力の誤差)
#include <iostream>    //入出力
#include <iterator>    //集合演算(積集合,和集合,差集合など)
#include <map>         //map(辞書)
#include <numeric>     //iota(整数列の生成),gcdとlcm,accumulate
#include <queue>       //キュー
#include <set>         //集合（順序保持）
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility> //pair
#include <vector>  //可変長配列
using namespace std;
typedef long long ll;
typedef long double ld;

#define REP(i, n) for (int i = 0; i < ll(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < ll(b); i++)
#define FORD(i, a, b) for (int i = a; i > ll(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size()) // sizeをsize_tからllに直しておく
const long long INF = 1e12;
const int MOD = 1e9 + 7;
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define Umap unordered_map
#define Uset unordered_set
#define int long long
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000

// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed#c%E3%81%A7%E3%81%AE%E5%AE%9F%E8%A3%85
void print() { cout << endl; }

template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T> void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}

template <class T> void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}

void add(long long &a, long long b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

signed main() {

    string s;
    cin >> s;

    int ls = s.length();

    int ret = 0;

    REPD(i, ls-1) {
        if (i % 2 == 0) {
            continue;
        }
        int subls = i / 2 + 1;
        if (s.substr(0, subls) == s.substr(subls, subls)) {
            ret = subls*2;
            break;
        }
    }

    print(ret);
}


Measured memory_bytes: 3604
/**
*    author:  Taichicchi
*    created: 07.09.2020 08:03:06
**/

#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int R;
    cin >> R;
    
    float ans;

    ans = M_PI * (2 * R);

    printf("%f\n", ans);

    return 0;
}

Measured memory_bytes: 3748
#include<stdio.h>
#define N 100

 int main(){
     int matrix[N][N];
     int i,j,n,u,k,v;

     scanf("%d",&n);
     for(i=0;i<n;i++){
         for(j=0;j<n;j++){
             matrix[i][j] = 0;
         }
     }
    for(i=0;i<n;i++){
         scanf("%d%d",&u,&k);
         u--;
         for(j=0;j<k;j++){
             scanf("%d",&v);
             v--;
             matrix[u][v]=1;
         }
     }
    for(i=0;i<n;i++){
         for(j=0;j<n;j++){
             printf("%d",matrix[i][j]);
            if(j != n-1) printf(" ");
         }
         printf("\n");
    }
    return 0;
 }


Measured memory_bytes: 2104
N,K = map(int,input().split())

def log2(n):
    res = 0
    while n > 1:
        n /= 2
        res += 1
    return res

def ceil(n): # ceiling関数
    if n > int(n):
        return(int(n)+1)
    else:
        return(int(n))

a = []
for i in range(1,N+1):
    k = ceil(log2(K/i))
    if i < K:
        a.append(k)
    else:
        a.append(0)
m = max(a)
s = sum([2**(m-a[i]) for i in range(len(a))])
print(s/(N*(2**m)))


Measured memory_bytes: 46132
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    long long k;
    cin>>s;
    cin>>k;
    int pos=-1;
    for(int i=0;i<(int)s.size();i++)
    {
        if(s[i]!='1')
        {
            pos=i;
            break;
        }
    }
    if(pos<0)
    {
        printf("1\n");
    }
    else if(pos==0)
    {
        printf("%c\n",s[0]);
    }
    else
    {
        if(k<=pos) printf("1\n");
        else printf("%c\n",s[pos]);
    }
}


Measured memory_bytes: 384
#include<stdio.h>
 
int main()
{
  int A[100];
  int N;
  int key;
  int i, j, k;
 
  //Read N and keys
  scanf("%d", &N);
  for(i=0; i<N; i++)scanf("%d",&A[i]);
 
  //Sort
  for(i=0; i<N; i++){
    key=A[i];
    j=i-1;
 
      //if A[j]>key, change A[j] to A[j+1]
    while(j>=0 && A[j]>key){
      A[j+1]=A[j];
      j=j-1;
    }
    A[j+1]=key;
 
      //print
    for(k=0; k<N; k++){
      printf("%d", A[k]);
      if(k<N-1)printf(" ");
    }
    printf("\n");
  } 
  return 0;
}

Measured memory_bytes: 1772
#include<stdio.h>

int main(void){
    int N,D,X,T,i,x;
    int A[100];
    
    scanf("%d%d%d",&N,&D,&X);
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    for(i=0;i<N;i++){
        x=(D-1)/A[i];
        T +=x+1;
    }
    T += X;
    printf("%d\n",T);
     return 0;
}     

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

int main(void){
  char S[3];
  scanf("%s", S);

  if(strlen(S) == 2) printf("%s\n", S);
  else{
    for (int i = 2; i >= 0; i--) {
      printf("%c", S[i]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 128
n = int(input())
b_list = list(map(int,input().split()))
a_list = []
for i in range(n -2):
  if b_list[i] >= b_list[i + 1]:
    a_list.append(b_list[i + 1])
  else:
    a_list.append(b_list[i])
a_list.append(b_list[0])
a_list.append(b_list[-1])
print(sum(a_list))

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

int main()
{
 int k;
 cin>>k;
 string s;
 cin>>s;
 if(s.size()<=k){
   cout<<s<<endl;
 }
 else{
   for(int i=0;i<k;i++){
     cout<<s.at(i);
   }
   cout<<"..."<<endl;
 }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x " = " << (x) << '\n';
#define P(x) cout << #x << '\n';    
#define int long long
typedef pair<int, int> pii;
const int mod = 1000000007;


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	
	int h, a;
	cin >> h >> a;
	cout << (h + a - 1) / a << '\n';
	
	return 0;
}






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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/
int n;
vector<int> c;
bool dp[105][105];
/**********************************************/

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n;
    c.resize(n);
    REP(i, n) cin >> c[i];

    REP(i, n-1){
        FOR(j, i+1, n){
            if(c[i] != c[j]) break;
            dp[i][j] = true;
        }
    }
    
    for(int len = 4; len <= n; len++){
        for(int l = 0; l < n; l++){
            int r = l + len - 1;
            if(r >= n) break;
            
            // ok ok パターン
            for(int m = l+2; m < n-1; m++){
                if(dp[l][m-1] && dp[m][r]) dp[l][r] = true;
            }
            // x ok x パターン
            if(c[l] == c[r] && dp[l+1][r-1]){
                for(int m = r; m < n; m++){
                    if(c[l] != c[m]) break;
                    dp[l][m] = true;
                }
                for(int m = l; m >= 0; m--){
                    if(c[r] != c[m]) break;
                    dp[m][r] = true;
                }
            }
            // x ok x ok x パターン
            for(int m = l+1; m < r; m++){
                if(c[l] == c[m] && c[m] == c[r]){
                    if(l + 1 != m && !dp[l+1][m-1]) continue;
                    if(m + 1 != r && !dp[m+1][r-1]) continue;
                    dp[l][r] = true;
                }
            }
        }
    }
    

    cout << (dp[0][n-1] ? "yes":"no") << endl;
}



Measured memory_bytes: 3236
fun main(args:Array<String>) {
  val (a, b) = readLine()!!.split(" ")
  when(a) {
    "H" -> {
      when(b) {
        "H" -> println("H")
        "D" -> println("D")
      }
    }
    "D" -> {
      when(b) {
        "H" -> println("D")
        "D" -> println("H")
      }
    }
  }
}

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

int main() {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);

    if (abs(a - c) <= d)
        puts("Yes");
    else if (abs(a - b) <= d && abs(b - c) <= d)
        puts("Yes");
    else
        puts("No");
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#define db(x) cout << "> " << #x << " = " \
	<< (x) << '\n'
#define db2(x, y) cout << "> " << #x << " = " \
	<< (x) << ", " << #y << " = " << (y) << '\n'
#define db3(x, y, z) cout << "> " << #x << \
	" = " << (x) << ", " << #y << " = " << \
	(y) << ", " << #z << " = " << (z) << '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
typedef map<int, int> mii;
typedef set<int> si;

int h, w, n, r, c, posU, posD, posL, posR;
string s, t;

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin >> h >> w >> n >> r >> c >> s >> t;
	posU = posD = r;
	posL = posR = c;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'U') {
			--posU;
		} else if (s[i] == 'D') {
			++posD;
		} else if (s[i] == 'L') {
			--posL;
		} else if (s[i] == 'R') {
			++posR;
		}
		if (posU < 1 || posD > h || posL < 1 || posR > w) {
			cout << "NO\n";
			return 0;
		}
		if (t[i] == 'U') {
			--posD;
			posD = max(posD, 1);
		} else if (t[i] == 'D') {
			++posU;
			posU = min(posU, h);
		} else if (t[i] == 'L') {
			--posR;
			posR = max(posR, 1);
		} else if (t[i] == 'R') {
			++posL;
			posL = min(posL, w);
		}
	}
	cout << "YES\n";
	return 0;
}


Measured memory_bytes: 920
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
const ll mod=1e9+7;



int main() {

    ll n;
    cin>>n;
    ll a[n];
    map<ll,ll> m;
    ll dp[n];
    dp[0]=1;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        if(i && m.count(a[i])==0){
            dp[i]=dp[i-1];
            m[a[i]]=i+1;
            dp[i]%=mod;
            continue;
        }
        if(i==0){
            dp[i]=1;
        }
        else{
            if(a[i]==a[i-1]){
                dp[i]=dp[i-1];
            }
            else{
                dp[i]=dp[i-1]+dp[m[a[i]]-1];
                dp[i]%=mod;
            }
        }
        m[a[i]]=i+1;
        dp[i]%=mod;
        
    }

    cout<<dp[n-1]<<endl;

}


Measured memory_bytes: 15872
<?php
fscanf(STDIN, "%d", $N);
$a = array_map("intval", explode(" ", trim(fgets(STDIN))));
rsort($a);
$sum = 0;
for($i = 0; $i < $N * 2; $i++){
  if($i%2==1){
    $sum+=$a[$i];
  }
}
printf("%d", $sum);

Measured memory_bytes: 37412
#include <bits/stdc++.h> 
using namespace std; 
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define pb push_back
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int x;
deque<ll>sol;
vector<int>gg;
ll dp[3001][3001];
bool flag[3001][3001];
ll solve(int x,int y)
{
  if(flag[x][y]!= 0)return dp[x][y];
  flag[x][y]=1;
  if(x==y){
    return dp[x][y]=gg[x];
  }
  return dp[x][y]=max(gg[x]-solve(x+1,y),gg[y]-solve(x,y-1));
}
int main()
{
  // flash;
  cin>>x;
  //memset(dp,-1,sizeof dp);
  for (int i = 0; i < x; ++i)
  {
    ll s;
    cin>> s;
    gg.pb(s);
  }
  cout<<solve(0,x-1);
  return 0;
}

Measured memory_bytes: 78464
//逆ポーランド記法
//2018-12-11
//Ebitani Akira

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top;
int array[10000];

int pop();
void push(int);


int main(){
  char s[100];
  int x,y;
  top = 0;

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      x = pop();
      y = pop();
      push( x+y );
    }
    else if ( s[0] == '-' ){
      x = pop();
      y = pop();
      push( y-x );
    }
    else if ( s[0] == '*' ){
      x = pop();
      y = pop();
      push( x*y );
    }
    else {
      push(atoi(s));

    }
  }

  printf("%d\n",pop());

  return 0;
}

void push(int x){
  
  array[++top] = x;
}

int pop(){
  top--;

  return array[top+1];
}
    








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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define MOD 1000000007

const int MAX_M = 100000;


int main(){
  ll k, s;
  //string s;
  cin >> k >> s;

  //vector<ll> a(n);
  //queue<ll> q;
  //map<string,ll> m;

  ll ans = 0;

  rep(i,0,k+1){
    rep(j,0,k+1){
      ll z = s - i - j;
      if((z>=0) && (z<=k)){
        ans++;
      }
    }
  }


  //cout << fixed << setprecision(10);
  //cout << ((ok)? "Yes" : "No") << endl;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define foreach(i,a) for(auto &i:a)
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}

using M=vector<vector<ll>>;
ll m;

ll modpow(ll a,ll p){
  ll res=1;
  ll power = a;
  while(p){
    if(p&1) (res*=power)%=m;
    (power*=power)%=m;
    p>>=1;
  }
  return res;
}

M mat_mul(const M& A, const M& B){
  M C{{0,0,0},{0,0,0},{0,0,0}};
  rep(i,3)rep(j,3)rep(k,3) {
    (C[i][j]+=A[i][k]*B[k][j])%=m;
  }
  return C;
}

void solve(){
  ll l,a,b; cin>>l>>a>>b>>m;
  vector<ll> C(19,0);
  rep(d,1,19){
    if((ll)pow(10,d)-1-(ll)a>=0){
      C[d]=((ll)pow(10,d)-1-(ll)a)/b+1;
    } else {
      C[d]=0;
    }
  }
  rep(d,18,0,-1) C[d]-=C[d-1];
  rep(d,1,19){
    C[d]=min(l,C[d]);
    l-=min(l,C[d]);
  }

  M A{{1,0,0},{0,1,0},{0,0,1}};
  rep(d,1,19){
    M res{{1,0,0},{0,1,0},{0,0,1}};
    M power{{modpow(10,d),1,0},{0,1,b%m},{0,0,1}};
    ll p=C[d];
    while(p){
      if(p&1) res=mat_mul(res,power);
      power=mat_mul(power,power);
      p>>=1;
    }
    A=mat_mul(res,A);
  }
  ll ans=0;
  ans+=(a%m)*(A[0][1])%m;
  ans+=A[0][2];
  cout<<ans%m<<"\n";
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var W, H, x, y, r int
	var result string
	fmt.Scan(&W, &H, &x, &y, &r)

	if 0 <= (x-r) && (x+r) <= W && 0 <= (y-r) && (y+r) <= H {
		result = "Yes"
	} else {
		result = "No"
	}
	fmt.Println(result)
}


Measured memory_bytes: 1156
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
ans=[]
s=x+y
for i in p:
    ans.append((i,0))
for i in q:
    ans.append((i,1))
for i in r:
    ans.append((i,2))
ans.sort(reverse=True)
res=0
cnt=0
for i , j in ans:
    if j==0:
        if x>0:
            x-=1
            cnt+=1
            res+=i
    elif j==1:
        if y>0:
            y-=1
            cnt+=1
            res+=i
    else:
        cnt+=1
        res+=i
    if cnt>=s:
        break

print(res)


Measured memory_bytes: 123108
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    string S1,S2,S3;
    cin >> S1 >> S2 >> S3;
    cout << S1[0] << S2[1] << S3[2] << endl;
}

Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

n = int(input())
s = [input() for _ in range(n)]

print(len(set(s)))


Measured memory_bytes: 35604
#include<bits/stdc++.h>
using namespace std;
const int maxn=400009;
const int inf=1e9;

int n;

struct Point{
	int x,y;char d;
	void input(){
		scanf("%d%d",&x,&y);
		d=getchar();
		while(d<'A'||d>'Z')d=getchar();
	}
}p[maxn];
int cmp(int i,int j){
	return p[i].x<p[j].x;
}
int cmp2(int i,int j){
	return p[i].y<p[j].y;
}

vector<int>G[maxn];
int ans=inf;
void work(){
	for(int i=0;i<maxn;++i)G[i].clear();
	for(int i=1;i<=n;++i){
		int t=p[i].x+p[i].y;
		G[t].push_back(i);
	}
	for(int i=0;i<maxn;++i){
		sort(G[i].begin(),G[i].end(),cmp);
		int mxD=-inf,mxR=-inf;
		for(int j=0;j<G[i].size();++j){
			int id=G[i][j];
			if(p[id].d=='L'){
				ans=min(ans,p[id].x-mxD);
			}else if(p[id].d=='U'){
				ans=min(ans,p[id].x-mxR);
			}else if(p[id].d=='D'){
				mxD=max(mxD,p[id].x);
			}else{
				mxR=max(mxR,p[id].x);
			}
		}
	}
}
int ans2=inf;
void work2(){
	for(int i=0;i<maxn;++i)G[i].clear();
	for(int i=1;i<=n;++i){
		G[p[i].x].push_back(i);
	}
	for(int i=0;i<maxn;++i){
		sort(G[i].begin(),G[i].end(),cmp2);
		int mx=-inf;
		for(int j=0;j<G[i].size();++j){
			int id=G[i][j];
			if(p[id].d=='L'||p[id].d=='R')continue;
			if(p[id].d=='D'){
				ans2=min(ans2,p[id].y-mx);
			}else{
				mx=max(mx,p[id].y);
			}
		}
	}
	
	//
	
	for(int i=0;i<maxn;++i)G[i].clear();
	for(int i=1;i<=n;++i){
		G[p[i].y].push_back(i);
	}
	for(int i=0;i<maxn;++i){
		sort(G[i].begin(),G[i].end(),cmp);
		int mx=-inf;
		for(int j=0;j<G[i].size();++j){
			int id=G[i][j];
			if(p[id].d=='U'||p[id].d=='D')continue;
			if(p[id].d=='L'){
				ans2=min(ans2,p[id].x-mx);
			}else{
				mx=max(mx,p[id].x);
			}
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)p[i].input();
	
	work2();
	
	work();
	
	for(int i=1;i<=n;++i){
		p[i].y=200000-p[i].y;
		if(p[i].d=='U')p[i].d='D';
		else if(p[i].d=='D')p[i].d='U';
	}
	work();
	
	long long t=min(1LL*ans*10,1LL*ans2*5);
	if(t>=inf)printf("SAFE\n");
	else printf("%lld\n",t);
	
	return 0;
}

Measured memory_bytes: 28352
<?php
  $N = trim(fgets(STDIN));
  $array = array();
  
  for($i = 0; $i < $N; $i++){
    $num = trim(fgets(STDIN));
    $exist = false;
    for($j = 0; $j < count($array); $j++){
      if($array[$j] == $num){
        $exist = true;
      }
    }
    if(!$exist){
      $array[] = $num;
    }
  }
  
  echo count($array);
?>

Measured memory_bytes: 3576
H, W = map(int, input().split())
S = []
for i in range(H):
    s = list(input().split())
    S.append(s)
for i in range(H):
    alph = 'A'
    for j in range(W):
        if S[i][j] == "snuke":
            print(chr(ord(alph) + j) + str(i + 1))
            break


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int  n,m;
  cin >> n >> m;
  int a,i;
  priority_queue<int> que;//宣言 
  for(i=0;i<n;i++){
    cin >> a;
    que.push(a);//()内のかずをpush
  }
  for(i=0;i<m;i++){
    int x=que.top();
    que.pop();
    x=x/2;
    que.push(x);
  }
  long long ans=0;
  for(i=0;i<n;i++){
  int x=que.top();
    que.pop();
    ans+=x;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3840
#include <iostream>
#include <vector>
using namespace std;
const int N = 1e5 + 1;
void set_primes(vector<bool>& v) {
    int i, j;
    v[0] = v[1] = false;
    for (i = 2; i * i <= N; ++i) {
        if (v[i]) {
            for (j = i * i; j < N; j += i) {
                v[j] = false;
            }
        } 
    }
}
int main() {
    vector<bool> primes(N, true);
    set_primes(primes);
    vector<int> nr_sim(N);
    int i;
    nr_sim[0] = 0;
    for(i = 1; i <= N; i += 2) {
        nr_sim[i] = nr_sim[i-1];
        if(primes[i] && primes[(i+1)/2]) ++nr_sim[i];
        nr_sim[i + 1] = nr_sim[i];
    }
    int q;
    cin>>q;
    while(q--) {
        int l, r;
        cin>>l>>r;
        cout<<nr_sim[r] - nr_sim[l - 1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;




int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	ll N, K;
	cin >> N >> K;
	vector<pair<ll, ll>> num(N);
	for (ll i = 0; i < N; i++) {
		cin >> num[i].first >> num[i].second;
	}

	sort(num.begin(), num.end());

	ll count = 0;
	for (ll i = 0; i < N; i++) {
		count += num[i].second;
		if (count >= K) {
			cout << num[i].first;
			return 0;
		}
	}



}	




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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin>>N>>K;
    VEC2(v,N,2);
    FOR(i,0,N){
      ll in1,in2;
      cin>>in1>>in2;
      v[i][0]=in1;
      v[i][1]=in2;
    }
    sortAl(v);
    ll p=0;
    FOR(i,0,N){
      p+=v[i][1];
      if(p>=K){
        cout<<v[i][0]<<endl;
        break;
      }
    }
}


Measured memory_bytes: 5760
class DirectedGraph
  class Edge
    attr_accessor :to, :cost

    def initialize(to, cost)
      @to, @cost = to, cost
    end

    def inspect
      [@to, @cost]
    end
  end

  def initialize
    @graph = Hash.new { |hash, key| hash[key] = [] }
  end

  def connect(i, j, d)
    @graph[i] << Edge.new(j, d)
  end

  def bellman_ford(s, v_size)
    ds = Hash.new { |hash, key| hash[key] = Float::INFINITY }
    ds[s] = 0
    @graph.each_key do |from|
      @graph[from].each do |e|
        if (ds[e.to] > ds[from] + e.cost)
          ds[e.to] = ds[from] + e.cost
        end
      end
    end
    has_neg_loop?(ds, v_size) ? nil : ds
  end

  def has_neg_loop?(ds, v_size)
    ns = Hash.new { |hash, key| hash[key] = false }
    @graph.each_key do |from|
      @graph[from].each do |e|
        if (ds[e.to] > ds[from] + e.cost)
          ds[e.to] = ds[from] + e.cost
          ns[e.to] = true
        end
      end
    end
    ns[v_size]
  end

  def inspect
    @graph.map { |key, value| [key, value] }.to_h
  end
end

n, m = gets.split.map(&:to_i)
g = DirectedGraph.new
m.times do
  a, b, c = gets.split.map(&:to_i)
  g.connect(a, b, -c)
end
ans = g.bellman_ford(1, n)
puts ans ? -ans[n] : "inf"

Measured memory_bytes: 2300
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;
	int x, L;

map<vector<int>, int> Map;
vector<int> amax, amin;

int calc(vector<int> &amax, vector<int> &amin){
	int x = 0, y = 0;
	int bit = 1;
	RREP(i, L){
		x += amax[i] * bit;
		y += amin[i] * bit;
		bit *= 10;
	}
	return x - y;
}

void solve(vector<int> &a, int cnt){
//REP(i,L) cout << a[i]; cout << endl;
	if(Map.find(a) != Map.end()) {
		cout << Map[a] << " ";
		int y = 0;
		int bit = 1;
		RREP(i, L){
			y += a[i] * bit;
			bit *= 10;
		}
		cout << y << " ";
		cout << cnt - Map[a] << endl;
		return;
	}
	Map[a] = cnt;
	amax.resize(L);
	amin.resize(L);
	REP(i,L){
		amax[i] = a[i];
		amin[i] = a[i];
	}
	sort(ALL(amin));
	sort(ALL(amax), greater<int>());
/*
REP(i,L) cout << amax[i];cout << " - ";
REP(i,L) cout << amin[i];cout << endl;
*/
	int x = calc(amax, amin);
	vector<int> next(L);
	RREP(i, L){
		if(!x) next[i] = 0;
		next[i] = x%10;
		x /= 10;
	}
	return solve(next, cnt + 1);
}

int main(void){
	while(cin >> x >> L, x || L){
		Map.clear();
		vector<int> a(L);
		RREP(i,L){
			if(!x) a[i] = 0;
			a[i] = x%10;
			x /= 10;
		}
		solve(a, 0);
	}
	
	return 0;
}

Measured memory_bytes: 1224
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  set<char> c;
  REP(i, 0, n) {
    string s;
    cin >> s;
    for (auto ch: s)c.insert(ch);
  }
  cout << (c.size() == 4 ? "Four" : "Three") << endl;
}


Measured memory_bytes: 256
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>
#include	<math.h>

int		main(void)
{
	double	r;
	double	menseki, ennsyuu;

	scanf("%lf",&r);

	menseki = M_PI*(r*r);
	ennsyuu = 2*r*M_PI;

	printf("%f %f\n",menseki,ennsyuu);

	return 0;
}

Measured memory_bytes: 648
N = int(input())
p = list(map(int, input().split()))
counter = 0
for g in range(1, N - 1):
    if p[g - 1] < p[g] < p[g + 1]:
        counter += 1
    if p[g + 1] < p[g] < p[g - 1]:
        counter += 1

print(counter)


Measured memory_bytes: 38384
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
typedef long long int ll;
#define REP(i,n) for(int i=0;i<signed(n);i++)
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
const ll MOD = 1000000007;
const ll INF = 9e9;
ll N, M, ans = INF;
ll A[300010], S[301000];

using namespace std;
int main() {
	fill(begin(A), end(A), 0);
	fill(begin(S), end(S), 0);
	N = M = 0;
	std::ios_base::sync_with_stdio(false);
	cin >> N;
	REP(i, N) {
		cin >> A[i];
		S[i] += A[i];
		S[i + 1] = S[i];
	}
	//a:右半分の区切り i:真ん中 b:左半分
	//s:右の和 t:左の和
	ll a = 0, b = 2, s, t;
	REP(i, N - 1) {
		if (i == b)b++;
		s = (S[i] - S[a]) - S[a];
		t = (S[N - 1] - S[b]) - (S[b] - S[i]);
		bool f = true;
		if (i == 0)continue;
		while (f) {
			f = false;
			if (a + 1 == i)continue;
			if (abs(s)>abs(s - A[a + 1] * 2)) {
				s -= A[a + 1] * 2;
				a++; f = true;
			}
		}
		f = true;
		while (f) {
			f = false;
			if (b + 1 == N - 1 || b == N - 1)continue;
			if (abs(t)>abs(t - A[b + 1] * 2)) {
				t -= A[b + 1] * 2;
				b++; f = true;
			}
		}
		ans = min(ans, (max({ S[a],S[i] - S[a],S[b] - S[i],S[N - 1] - S[b] })
			- min({ S[a],S[i] - S[a],S[b] - S[i],S[N - 1] - S[b] })));
	}
	cout << ans << endl;
	cin >> a;
	return 0;
}


Measured memory_bytes: 4992
import heapq


class Dijkstra:

    def __init__(self, rote_map, start_point, goal_point=None):
        self.rote_map = rote_map
        self.start_point = start_point
        self.goal_point = goal_point

    def execute(self):
        num_of_city = len(self.rote_map)
        dist = [float("inf") for _ in range(num_of_city)]
        prev = [float("inf") for _ in range(num_of_city)]

        dist[self.start_point] = 0
        heap_q = []
        heapq.heappush(heap_q, (0, self.start_point))
        route_count = [0 for _ in range(num_of_city)]
        route_count[self.start_point] = 1
        while len(heap_q) != 0:
            prev_cost, src = heapq.heappop(heap_q)

            if dist[src] < prev_cost:
                continue

            for dest, cost in self.rote_map[src].items():
                if cost != float("inf") and dist[dest] > dist[src] + cost:
                    dist[dest] = dist[src] + cost
                    heapq.heappush(heap_q, (dist[dest], dest))
                    prev[dest] = src
                if dist[dest] == dist[src] + cost:
                    route_count[dest] += route_count[src]

        if self.goal_point is not None:
            return self._get_path(self.goal_point, prev)
        else:
            return dist, route_count

    def _get_path(self, goal, prev):
        path = [goal]
        dest = goal

        while prev[dest] != float("inf"):
            path.append(prev[dest])
            dest = prev[dest]

        return list(reversed(path))


N = int(input())
graph = [dict() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    graph[a - 1][b - 1] = 1
    graph[b - 1][a - 1] = 1

path = Dijkstra(graph, 0, N - 1).execute()
cost = len(path) - 1

black = 1
if cost % 2 == 0:
    tmp = (cost - 1) // 2
    black += tmp + 1
else:
    tmp = (cost - 1) // 2
    black += tmp
not_path = set(path[black:])
visited = [False for _ in range(N)]
q = [0]
visited[0] = False
while len(q) != 0:
    dist = q.pop()
    for d in graph[dist].keys():
        if visited[d] or d in not_path:
            continue
        q.append(d)
        visited[d] = True
for p in tuple(path):
    visited[p] = False
for v in visited:
    if v:
        black += 1
white = N - black

if black > white:
    print("Fennec")
else:
    print("Snuke")


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

using namespace std;

long long a[400001];
                                       
int main () {
	int  n;
	cin >> n;
	for (int i = 1;i <= 3 * n;i ++) {
		cin >> a[i];
	}
	sort (a + 1, a + 3 * n + 1);
	long long kol = 0, ans = 0;
	for (int i = 3 * n - 1;i >= 1;i -= 2) {
		kol ++;
		if (kol > n) break;
		ans += a[i];
	}
	cout << ans;
	return 0;
}


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



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

  double dp[n+1][n+1];
  memset(dp,0,sizeof(dp));

  dp[0][0] = 1;
  for(int i=1;i<=n;i++)
  {
      for(int j=0;j<=i;j++)
      {
          if(j==0)
            dp[i][j] = dp[i-1][j] * (1-a[i-1]);
          else
          {
              dp[i][j] = dp[i-1][j-1] * a[i-1] + dp[i-1][j]*(1-a[i-1]);
          }
      }
  }

  double ans = 0;
  for(int i=n/2+1;i<=n;i++)
    ans = ans+ dp[n][i];
    
  cout<<std::fixed<<std::setprecision(13)<<ans<<endl;
  
}

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

int f(map<int,int> m,map<int,int> m2){

    int a=0,b=0,c=0;

    for(auto it: m){
        if(it.second>a){
            a = it.second;
            b = it.first;
        }
    }
    for(auto it: m2){
        if(it.second>c && it.first!=b){
            c = it.second;
        }
    }

    return a+c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n,x;
    cin>>n;

    map<int,int> m,m2;

    for(int i=1; i<=n; i++){
        cin>>x;
        if(i&1)
            m[x]++;
        else m2[x]++;
    }

    int ans = n - max(f(m,m2),f(m2,m));

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priotity_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ld PI=abs(acos(-1));
string s[3];

int main(){
	cin >> s[0] >> s[1] >> s[2];
	
	int i=0,j=0,k=0,now=0;
	while(1){
		char pos = s[now][(now==2?k:(now==1?j:i))];
		(now==2?k:(now==1?j:i))++;
		now=pos-'a';
		
		if(i>s[0].size()){cout << 'A' << endl; break;}
		else if(j>s[1].size()){cout << 'B' << endl; break;}
		else if(k>s[2].size()){cout << 'C' << endl; break;}
	}
	
	return 0;
}


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

ma = -float("inf")
mi = float("inf")
ma2 = -float("inf")
mi2 = float("inf")
for i in range(N):
    x,y = list(map(int,input().split()))
    ma = max(ma,x+y)
    mi = min(mi,x+y)
    ma2 = max(ma2,10**9-x+y)
    mi2 = min(mi2,10**9-x+y)
print(max(ma-mi,ma2-mi2))

Measured memory_bytes: 9160
#!/usr/bin/env python3
import math
N, K = map(int, input().split())
ans = 0
pows = []
for n in range(1, N + 1):
    p = n
    seq = 0
    while p < K:
        seq += 1
        p *= 2
    pows.append(seq)

s = sum(pows)
c = 0
for p in pows:
    c += pow(2, s - p)
print(c / (pow(2, s) * N))


Measured memory_bytes: 3864
N = int(input())
a = []
for i in range(N):
    a.append(int(input())-1)

#print(a)
light = 0
counter = 0

while True:
    if light == 1:
        break
    if counter > N:
        counter = -1
        break
    #print(light)
    push = a[light]
    light = push
    counter += 1

print(counter)

Measured memory_bytes: 7084
#include<bits/stdc++.h>
//#include <iostream>
//#include <iomanip>
//#include <vector>
//#include <cmath>
//#include <algorithm>
using namespace std;


#define F first
#define PB push_back
#define MP make_pair

typedef long long ll;

ll p = pow(10, 9) + 7;



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

    int N, M;
    cin >> N >> M;
    vector<vector<char> > g(N, vector<char>(M));
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < M; j++)
        {
            cin >> g[i][j];
        }
    }

    vector<vector<int> > dp(N, vector<int>(M));
    dp[0][0] = 1;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < M; j++)
        {
            if(i == 0 && j == 0)continue;
            if(i > 0 && g[i - 1][j] != '#')
            {
                dp[i][j] += dp[i - 1][j];
                dp[i][j] = dp[i][j]%p;
            }
            if(j > 0 && g[i][j - 1] != '#')
            {
                dp[i][j] += dp[i][j - 1];
                dp[i][j] = dp[i][j]%p;
            }
        }
    }
    cout << dp[N - 1][M - 1] << endl;









    return 0;
}


Measured memory_bytes: 5248
a=int(input())
b=int(input())
c=int(input())
x=int(input())
z=0

for i in range(a+1):
	for j in range(b+1):
		for k in range(c+1):
			if 500*i+100*j+50*k == x:
				z+=1
print(z)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <functional>

int main()
{
	int ns[5];
	std::cin >> ns[0] >> ns[1] >> ns[2] >> ns[3] >> ns[4];
	std::sort(ns, ns+5, std::greater<int>());
	std::cout << ns[0] << " " << ns[1] << " " << ns[2] << " " << ns[3] << " "	<< ns[4];
	std::cout << std::endl;
	return 0;
}

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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define ci(a) cin>>a
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define INF 1e16
#define mod 1e9+7


int main() {
  ll n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  str s;
  cin>>s;
  bool D=true;
  FOR(i,a-1,c-1){
    if(s[i]=='#'){
      if(s[i+1]=='#'){
        D=false;
        break;
      }
    }
  }
  FOR(i,b-1,d-1){
    if(s[i]=='#'){
      if(s[i+1]=='#'){
        D=false;
        break;
      }
    }
  }
  int count=0,cou=0;
  if(c>d){
    if(s[b-2]=='.'){
      if(s[b-1]=='.'){
        if(s[b]=='.'){
          cou++;
        }
      }
    }
    if(s[d-2]=='.'){
      if(s[d-1]=='.'){
        if(s[d]=='.'){
          cou++;
        }
      }
    }
    FOR(i,b-1,d){
      if(s[i]=='.'){
        count++;
        if(count>2){
          cou++;
        }
      }
      if(s[i]=='#'){
        count=0;
      }
//      co(count);
 //     co(cou);
    }
  }
  if(c>d){
    if(D&&cou>0){
      co("Yes");
    }
    else{
      co("No");
    }
  }
  else{
    if(D){
      co("Yes");
    }
    else{
      co("No");
    }
  }
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    v.emplace_back(2020);
    cin >> m;
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x; x--;
        if(v[x]+1 < v[x+1]) v[x]++;
    }
    for (int i = 0; i < n; ++i) {
        cout << v[i] << "\n";
    }
    return 0;
}



Measured memory_bytes: 3160
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll k,a,b,ans=1;

	in(k);
	in(a);
	in(b);

	if (b-a>1) {
		k -= a - 1;
		ans = a;
		ans += (b-a)*(k/2);
		k -= (k/2)*2;
	}
	
	ans += k;

	outn(ans);
	return 0;

}


Measured memory_bytes: 256
#19
N,M,X = map(int,input().split())
a = list(map(int,input().split()))
sum1 = 0
sum2 = 0

for i in range(M):
    if a[i] < X:
        sum1 += 1
    elif a[i] > X:
        sum2 += 1
    
if sum1 >=sum2 :
    print(sum2)
else:
    print(sum1)
    

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

int main(){
  string S, T;
  cin >> S;
  cin >> T;
  int res = 0;
  
  for(int i=0;i<S.size();i++){
    if(S[i] == T[i]) res += 1;
  }
  
  cout << res << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep0(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define re return
#define mp map<int,int>
#define N 200005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define str stringstream
using namespace std;
int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&a!=c)cout<<"Yes";
	else if(a==c&&a!=b)cout<<"Yes";
	else if(c==b&&a!=c)cout<<"Yes";
	else cout<<"No";
	re 0;
}


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

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

  if (a >= k) {
    cout << a - k << " " << b << endl;
  } else {
    cout << 0 << " " << max((LL)0, b - k + a) << endl;
  }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(a==b&&b==c)cout<<1<<endl;
	else if(a==b||b==c||a==c)cout<<2<<endl;
	else cout<<3<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int search(int A[], int n, int key) {
   int i = 0;
   A[n] = key;

   while ( A[i] != key ) {
      i++;
   }

   return i != n;
}

int main() {
   int i, n, A[10000], q, key, sum;
   sum = 0;

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

   scanf("%d", &q);
   for ( i = 0; i < q; i++ ) {
      scanf("%d", &key);
      if ( search(A, n, key) ) {
         sum++;
      }
   }

   printf("%d\n", sum);

   return 0;
}

Measured memory_bytes: 636