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

int main(void) {
	int N[100000] = { 0 };
	long int n, x, y, sa = 0, ans1,ans2=0;
	int i =0;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> N[i];
	}
	sort(N,  N+n);
	x = N[n-1];
	y = N[n - 1] / 2 ;
	for (i = 0;i < n-1;i++) {
		if (N[i] <= y &&  y <= N[i + 1]) {
			ans1 = N[i];
			ans2 = N[i + 1];
			break;
		}
	}
	if (ans1 == 0) {
		cout << x << " " << N[n - 2] << endl;
	} else if(abs(ans1-y)>=abs(ans2-y)){
		cout << x << " " << ans2 << endl;
	} else
		cout << x << " " << ans1 << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

    	/*Scanner = テキスト入力を扱うためのクラス
		 *キーボードからの入力を受けつける場合は
		 *System.inを使って下記のように記述
		 */
		Scanner scan = new Scanner(System.in);

		//forループ文用に変数準備
		int i;
		int j;

		/*while文で無限ループ設定
		 * if文でbreakをかける
		 */

		while(true){
			int H = scan.nextInt();
			int W = scan.nextInt();

		//Constraintsの条件も追加しました。
			if(H == 0 && W == 0 || H >= 300 || W >= 300)break;
			for(j = 0; j < H; j++){
				for(i = 0; i < W; i++){
					/*2つのfor文を組み合わせることで座標を指定するように出力が出来ている？（イメージ）
					 * 動かすことはできたがイメージレベルなので理解しなければならない
					 */
					if(i == W-1 || i == 0 || j == H-1 || j == 0){
						System.out.print("#");

					} else {
						System.out.print(".");
					}
				}
					System.out.println();
			}
				System.out.println();
		}
	}
}

Measured memory_bytes: 24668
#include<stdio.h>

int main(void){
	int n,tem,a=0,b=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&tem);
		if(tem%2==0){
			a+=1;
			if(tem%3 == 0 || tem%5==0){
				b+=1;
			}
		}
	}
	if(a==b){
		printf("APPROVED");
	}else{
		printf("DENIED");
	}

	return 0;
}
		

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
	int p,a,b,c,i,n,x;
	while(1)
	{
	scanf("%d %d %d",&a,&b,&c);
	if(a==0)return 0;
	if(a<c){
		p=a;
		a=c;
		c=a;
	}
	if(a<b){
		p=a;
		a=b;
		b=a;
	}
	double r=sqrt(b*b+c*c);
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&x);
		if(r<(double)x*2)printf("OK\n");
		else printf("NA\n");
	}
	}
}
		

Measured memory_bytes: 1012
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	while(true){
		int N=in();
		if(!N) break;
		auto A=vecin(N);

		int num=0;
		while(true){
			int f=0;
			map<int,int> C;
			REP(i,N) C[A[i]]++;
			REP(i,N){
				if(A[i]!=C[A[i]]){
					f++;
					A[i] = C[A[i]];
				}
			}
			if(!f) break;
			num++;
		}
		out(num);
		PRINTALL(A);
	}
	return 0;
}



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

#define NS (100005)
#define FIR first
#define SEC second

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

template<typename _Tp> inline void IN(_Tp &dig)
{
	char c; bool flag = 0; dig = 0;
	while (c = getchar(), !isdigit(c)) if (c == '-') flag = 1;
	while (isdigit(c)) dig = dig * 10 + c - '0', c = getchar();
	if (flag) dig = -dig;
}

int n, m;

PII P[NS];

LL ans;

int main(int argc, char const* argv[])
{
	IN(n), IN(m);
	for (int i = 1; i <= n; i += 1) IN(P[i].FIR), IN(P[i].SEC);
	sort(P + 1, P + 1 + n);
	int a = 1;
	while (m)
	{
		ans += P[a].FIR, m--, P[a].SEC--;
		if (!P[a].SEC) a++;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
int a[200001];
int cmp(int a, int b){
	return a >b;
}
using namespace std;
int main(){
	
	int n, m;
	scanf("%d %d", &n, &m);
	long long  ans = 0;
	int ch;
	for(int i =0; i < n; i++){
		scanf("%d", &a[i]);
		ans += a[i];
	}
	sort(a, a+n, cmp);
	if(n <= m){
		printf("0");
	}
	else{
		for(int i = 0; i < m; i++)
			ans -= a[i];
		printf("%lld", ans);
	}
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  ll k; cin >> k;
  vector<ll> A(n), B(n);
  map<ll, ll> cnt;
  rep(i, n) {
    cin >> A[i] >> B[i];
    cnt[A[i]] += B[i];
  }
  for(auto ele: cnt) {
    if(k <= ele.second) {
      cout << ele.first << "\n";
      break;
    } else {
      k -= ele.second;
    }
  }
  return 0;
}


Measured memory_bytes: 8712
import java.util.Scanner;
import java.text.DecimalFormat;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int waru = a / b;
        int amari = a % b;
        double syou = (double)a / (double)b;

        DecimalFormat df1 = new DecimalFormat(".00000");

        System.out.println(waru + " " + amari + " " + " " + df1.format(syou));
    }
}


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

int main(){
  int x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << x2+y1-y2 << endl;
  cout << y2-x1+x2 << endl;
  cout << x1+y1-y2 << endl;
  cout << x2-x1+y1 << endl;
}
  

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

int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;

  if (S.size() != A + B + 1) goto NG;

  if (S.at(A) == '-') S.at(A) = '0';
  else goto NG;

  for (int i = 0; i < S.size(); i++) {
    if (isdigit(S.at(i)) == 0) goto NG; 
  }

  cout << "Yes" << "\n";
  return 0;
  NG: cout << "No" << "\n";
}

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

int main(){
  vector<int> A(3);
  cin >> A[0] >> A[1] >> A[2];
  sort(A.begin(), A.end());
  if(A[0]==5 && A[1]==5 && A[2]==7){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define swap(a,b) {a^=b;b^=a;a^=b;}

int main() {
    int a1,a2,a3;
    while(~scanf("%d%d%d", &a1, &a2, &a3)) {
        if (a1 > a2) {
            swap(a1,a2);
        }
        if (a1 > a3) {
            swap(a1,a3);
        }
        if (a2 > a3) {
            swap(a2,a3)
        }
        printf("%d %d %d\n", a1, a2, a3);
    }
    return 0;
}


Measured memory_bytes: 2732
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int stack[1000];
int t;

void push(int x){
  stack[++t]=x;
}

int pop(){
  t--;
  return stack[t+1];
}

int main()
{
  int n,m;
  t=0;
  char s[100];

  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      n=pop();
      m=pop();
      push(n+m);
    }
    else if(s[0]=='-'){
      m=pop();
      n=pop();
      push(n-m);
    }
    else if(s[0]=='*'){
      n=pop();
      m=pop();
      push(n*m);
    }
    else push(atoi(s));
  }
  printf("%d\n",pop());

  return 0;
}


  
	
    

  



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

int main(){
    int N;
    cin>>N;
    vector<int> A(N),L(N+1),R(N+1);
    for(int i=0; i<N; i++)cin>>A[i];
    L[0]=0;R[0]=0;
    for(int i=1; i<=N; i++){
        L[i]=__gcd(L[i-1],A[i-1]);
        R[i]=__gcd(R[i-1],A[N-i]);
    }
    int ans=0;
    for(int i=0; i<=N; i++){
        int tmp=__gcd(L[i],R[N-i-1]);
        if(tmp>ans)ans=tmp;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//





int main() {

    int N, M; cin >> N >> M;
    vector<vector<int>> friends(N+1);
    rep(i,M) {
        int a, b; cin >> a >> b;
        friends[a].push_back(b);
        friends[b].push_back(a);
    }
    
    bool seen[N+1];
    rep(i,N+1) seen[i] = false;
    int ans = 0;
    for (int i = 1; i < N+1; ++i) {
        if (seen[i]) continue;

        int tmp_ans = 1;
        seen[i] = true;
        queue<int> q;
        q.push(i);
        while (!empty(q)) {
            int now = q.front();
            q.pop();
            rep(j,friends[now].size()) {
                if (seen[friends[now][j]]) continue;

                seen[friends[now][j]] = true;
                q.push(friends[now][j]);
                ++tmp_ans;
            }
        }

        ans = max(ans, tmp_ans);
    }

    cout << ans << endl;


    return 0;
}





Measured memory_bytes: 14968
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int a,b,c[3];
	cin>>a>>b;
	c[0]=a+b;
	c[1]=a-b;
	c[2]=a*b;
	sort(c,c+3);
	cout<<c[2]<<endl;
	return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill((T*)array, (T*)(array+N), val);
}
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


class DMenagerie {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        string s;
        in >> n >> s;

        bool res = false;
        string t;
        for(int bit=0; bit < (1<<2); bit++){
            int l, r;
            t = "";
            rep(i, 2){
                if((1<<i) & bit) t += 'W';
                else t += 'S';
            }

            reps(i, 1, n-2){
                if(t[i] == 'S'){
                    if(s[i] == 'o') t += t[i-1];
                    else t += (t[i-1] == 'S') ? 'W' : 'S';
                }else if(t[i] == 'W'){
                    if(s[i] == 'o') t += (t[i-1] == 'S') ? 'W' : 'S';
                    else t += t[i-1];
                }
            }

            if(t[n-1] == 'S'){
                if(s[n-1] == 'o' && t[n-2] == t[0]) res = true;
                if(s[n-1] == 'x' && t[n-2] != t[0]) res = true;
            }else if(t[n-1] == 'W'){
                if(s[n-1] == 'o' && t[n-2] != t[0]) res = true;
                if(s[n-1] == 'x' && t[n-2] == t[0]) res = true;
            }

            if(t[0] == 'S'){
                if(s[0] == 'o' && t[n-1] != t[1]) res = false;
                if(s[0] == 'x' && t[n-1] == t[1]) res = false;
            }else if(t[0] == 'W'){
                if(s[0] == 'o' && t[n-1] == t[1]) res = false;
                if(s[0] == 'x' && t[n-1] != t[1]) res = false;
            }

            if(res) break;
        }

        if(res) out << t << endl;
        else out << -1 << endl;
	}
};


int main() {
	DMenagerie solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	cout<<a+b+c-max(max(a,b),c)<<endl;
	return 0;
}

Measured memory_bytes: 256
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#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>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll N = 0, A = 0, B =0;
    cin(N);cin(A);cin(B);

    string S;
    cin(S);
    //REP(i,N) cin(X.at(i));
    ll count = 0, countb =0;

    REP(i,N){
        if(S[i]=='a'){
         if(count < A + B){
            cout << "Yes" << endl;
            count ++;
        }
        else{
            cout << "No" << endl;  
        }
        }
        if(S[i]=='b'){
        if(countb < B && count < A + B){
            cout << "Yes" << endl;
            count ++;
            countb ++;
        }
        else{
            cout << "No" << endl;  
        }
        }
        if(S[i] =='c'){
            cout << "No" << endl;
        }
    }

    //出力
    //cout << ans << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Measured memory_bytes: 3776
from collections import Counter
def main():
    N, D = int(input()), Counter(list(map(int, input().split())))
    M, T = int(input()), Counter(list(map(int, input().split())))
    result = "YES"
    for key, value in T.items():
        temp = D.get(key)
        if temp == None or temp < value:
            result = "NO"
            break
    print(result)
main()

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    string S, T;
    cin >> S >> T;

    bool ans = true;
    rep(i, S.size()) {
        if (S[i] != T[i]) ans = false;
    }

    cout << (ans ? "Yes" : "No") << endl;
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n;
  cin >> n;
  vi p(n);
  ll sum = 0;
  REP(i, 0, n){
      cin >> p[i];
      sum += p[i];
  }
  sort(all(p));
  sum -= p[n - 1] / 2;
  cout << sum << endl;




  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ull i=start;i<end;i++)
#define N 303
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
ld dp[N][N][N],p[N][N][N];
int main() 
{
    fastio();
  ll n;cin>>n;
  vector<ll>v(4,0);
  loop(i,0,n)
  {
  	int x;cin>>x;
  	v[x]++;
  }

  memset(dp,0,sizeof(dp));
  memset(p,0,sizeof(p));
  p[v[1]][v[2]][v[3]] = 1;
  for(int c = n;c>=0;c--)
  {
  	for(int b = n;b>=0;b--)
  	{
  		for(int a = n;a>=0;a--)
  		{
  			if((a+b+c)>n || (a+b+c) == 0)continue;

  			ld pw = ((ld)(n-(a+b+c)))/n;
  			ld ew = pw/(1-pw) + 1;
  			dp[a][b][c] += ew*p[a][b][c] ;
  			if(a)
  			{
  				ld p_go = ((ld)a)/(a+b+c);
  				p[a-1][b][c] += p[a][b][c]*p_go;
  				dp[a-1][b][c] += dp[a][b][c]*p_go;
  			}
  			if(b)
  			{
  				ld p_go = ((ld)b)/(a+b+c);
  				p[a+1][b-1][c] += p[a][b][c]*p_go;
  				dp[a+1][b-1][c] += dp[a][b][c]*p_go;
  			}
  			if(c)
  			{
  				ld p_go = ((ld)c)/(a+b+c);
  				p[a][b+1][c-1] += p[a][b][c]*p_go;
  				dp[a][b+1][c-1] += dp[a][b][c]*p_go;
  			}
  		}
  	}
  }
  cout<<fixed<<setprecision(10)<<dp[0][0][0]<<endl;

  return 0;
}

Measured memory_bytes: 869632
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  int N; cin >> N;
  map<int,int> C;
  for (int n = 2; n <= N; n++) {
    int nn = n;
    for (int i = 2; i <= nn; i++) {
      while (nn%i == 0) {
        C[i]++;
        nn /= i;
      }
    }
  }
  ll ans = 1LL;
  for(auto c : C){
    ans *= c.second + 1;
    ans %= MOD;
  }

  std::cout << ans << '\n';
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  int N;
  cin >> N;
  auto A = make_v< int >(N, N - 1);
  cin >> A;
  for(auto &vs : A) for(auto &p : vs) --p;

  set< pair< int, int > > match;
  vector< int > deg(N);
  for(int i = 0; i < N; i++) {
    if(A[A[i][deg[i]]][deg[A[i][deg[i]]]] == i) {
      match.emplace(minmax(i, A[i][deg[i]]));
    }
  }
  int add = 0;
  while(match.size()) {
    set< pair< int, int > > nxt;
    ++add;
    for(auto &p : match) {
      deg[p.first]++;
      deg[p.second]++;
      for(int i : {p.first, p.second}) {
        if(deg[i] < N - 1) {
          if(A[A[i][deg[i]]][deg[A[i][deg[i]]]] == i) {
            nxt.emplace(minmax(i, A[i][deg[i]]));
          }
        }
      }
    }
    nxt.swap(match);
  }


  if(*min_element(begin(deg), end(deg)) == N - 1) cout << add << endl;
  else cout << -1 << endl;
}





Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;



int main()
{
	int a, b, c, d;
	
	int k, n;
	cin >> k>> n;
	vector<int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	a = k - A[n-1] + A[0];
	for (int i = 0; i < n-1; i++) {
		if (A[i + 1] - A[i] > a) {
			a = A[i + 1] - A[i];
		}
	}

	cout << k - a;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  char c;
  cin >> c;
  cout << (char)(c + 1) << endl;
  return 0;
}

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

signed main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (auto&& u : s) cin >> u;

  vector<vector<int>> l(h + 2, vector<int>(w + 2, 0));
  vector<vector<int>> r(h + 2, vector<int>(w + 2, 0));
  vector<vector<int>> u(h + 2, vector<int>(w + 2, 0));
  vector<vector<int>> d(h + 2, vector<int>(w + 2, 0));

  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) {
      if (s[i - 1][j - 1] == '.') {
        l[i][j] = l[i][j - 1] + 1;
        u[i][j] = u[i - 1][j] + 1;
      }
    }

  for (int i = h; i >= 1; i--)
    for (int j = w; j >= 1; j--) {
      if (s[i - 1][j - 1] == '.') {
        r[i][j] = r[i][j + 1] + 1;
        d[i][j] = d[i + 1][j] + 1;
      }
    }

  int ret = 0;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) {
      if (s[i - 1][j - 1] == '.')
        ret = max(ret, l[i][j] + u[i][j] + r[i][j] + d[i][j] - 3);
    }
  cout << ret << endl;
}


Measured memory_bytes: 129920
#include<bits/stdc++.h>
 
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1000000007
#define hell2 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll unsigned long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cerr << (#x) << " is " << (x) << endl
#define INF 1e9
#define LL_MAX 1e18
// memset(array, -1, sizeof(array[0][0]) * row * count)
using namespace std;
 
ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 
bool isPerfectSquare(long double x) {long double sr = sqrt(x); return ((sr - floor(sr)) == 0); }
bool check(ll i,ll j,ll n){return (i>=0 && i<n && j>=0 &&  j<n);} //matrix boundary checking
 
 
ll ceil(const ll &a, const ll &b){return (a - 1)/b + 1;}
 
// max({a, b, c, d})
// cout << fixed for removing e notation
 
bool comp(pair<ll, ll>a, pair<ll, ll>b)
{
    if(a.se*b.fi + b.se > b.se*a.fi + a.se) return true;
    else return false;
}
 
void convert(int arr[], int n) 
{ 
    int temp[n+1];
    for(int i=1;i<=n;i++)
        temp[i] = arr[i]; 
    // memcpy(temp, arr, n*sizeof(int)); 
  
    sort(temp+1, temp+n+1);   
    unordered_map<int, int> umap;
    int val = 1; 
    for (int i = 1; i <= n; i++) 
        umap[temp[i]] = val++;
    for (int i = 1; i <= n; i++) 
        arr[i] = umap[arr[i]]; 
}
 
bool prime[10000005];
void SieveOfEratosthenes(int n) 
{
    memset(prime, true, sizeof(prime)); 
    prime[0] = prime[1] = 0;
    for (int p=2; p*p<=n; p++) 
    {
        if (prime[p] == true) 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
    }
}

int foo(int a, int b, int c)
{
    return (abs(a-b) + abs(b-c) + abs(a-c));
}
 
int main()
{
    int a, b;
    cin >> a >> b;

    if(a+b == 4) cout << 2 << "\n";
    else if(a+b == 5) cout << 1 << "\n";
    else if(a+b == 3)cout << 3 << "\n";
}

Measured memory_bytes: 256
#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>;

int main()
{
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    for (int Z = X+1; Z <= Y; Z++)
    {
        bool ok = true;
        rep(i, n) if (x[i] >= Z) ok = false;
        rep(i, m) if (y[i] < Z) ok = false;
        if (ok)
        {
            cout << "No War" << endl;
            return 0;
        }
    }
    cout << "War" << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int d = N%10;
  
  if(d==2 || d==4 || d==5 || d==7 || d==9) cout << "hon"<< endl;
  else if (d == 3) cout << "bon" << endl;
  else cout << "pon" << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000000000

int main(){
  int n;
  cin >> n;
  int val;
  map<int, int> mp;
  for ( int i = 0; i < n; i++){
    cin >> val;
    mp[val]++;
  }
  int ans = 0;
  for ( map<int, int>::iterator it = mp.begin(); it != mp.end(); it++){

    if ( it->second < it->first ){
      ans += it->second;
    }else {
      ans += (it->second - it->first);
    }

  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4736
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;
typedef long long ll;
int digit_xor[50];

ll power(ll n, ll m){
  if(m==0) return 1;
  else return n*power(n, m-1);
}

void XOR(ll N){
  if((N+1)%4 <= 1){
    digit_xor[0] = 0;
  }else{
    digit_xor[0] = 1;
  }
  ll k=2;
  int count = 1;
  while(count < 50){
    if(((N+1)/k)%2==0){
      digit_xor[count] = 0;
    }else{
      if(((N+1)%k)%2==0){
        digit_xor[count] = 0;
      }else{
        digit_xor[count] = 1;
      }
    }
    k *=2;
    count++;
  }
}

int main(){
  ll A, B;
  cin >> A >> B;
  //cout << 1 <<endl;
  XOR(B);
  int digit_B[50];
  for(int i=0;i<50;i++) digit_B[i] = digit_xor[i];

  //cout << 2 <<endl;
  XOR(A-1);
  int digit_A[50];
  for(int i=0;i<50;i++) digit_A[i] = digit_xor[i];

  //cout << 3 <<endl;
  int digit_sum[50];
  for(int i=0;i<50;i++){
    if(digit_B[i]==digit_A[i]){
      digit_sum[i] = 0;
    }else{
      digit_sum[i] = 1;
    }
  }
  
  //cout << 4 <<endl;
  ll ans = 0;
  ll k = 1;
  for(int i=0;i<50;i++){
    ans += k*digit_sum[i];
    k *= 2;
  }
  cout << ans <<endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;

public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();
		int n = r.ri();
		if((n%4) == 0 || (n%7)==0) {
			print("Yes");
			return;
		}
		
		for(int c =1; c<n; c++) {
			for(int d = 1; c*4+d*7<=n; d++) {
				if(c*4+d*7 == n) {
					print("Yes");
					return;
				}
			}
		}
		
		print("No");
	}
	
	public static int getDigitSum(int n) {
		String str = ""+n;
		int sum = 0;
		for(int i = 0; i<str.length();i++) {
			sum += Integer.parseInt(""+str.charAt(i));
		}
		return sum;
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}
	
	public static void swap(int[] arr, int pos1, int pos2) {
		int temp = arr[pos1];
		arr[pos1] = arr[pos2];
		arr[pos2] = temp;
	}
	public static void swap(long[] arr, int pos1, int pos2) {
		long temp = arr[pos1];
		arr[pos1] = arr[pos2];
		arr[pos2] = temp;
	}
	
	public static String al(String s) {
		return s + "\n";
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
}

class Node {
	public int val;
	public boolean visited;
	public Node(int v) { val=v; }
}


Measured memory_bytes: 21332
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    int n;cin>>n;
    vector<long long> x(n);
    for(int i=0;i<n;++i)cin>>x[i];
    long long m,k;cin>>m>>k;
    vector<int> a(m),b(n-1),res(n-1);
    for(int i=0;i<m;++i){
        cin>>a[i];
        a[i]-=2;
    }
    for(int i=0;i<n-1;++i){
        b[i] = i;
        res[i] = i;
    }
    for(int i=0;i<m;++i){
        int tmp = b[a[i]];
        b[a[i]] = b[a[i]+1];
        b[a[i]+1] = tmp;
    }
    while(k>0){
        if(k%2==1){
            vector<int> tmp(n-1);
            for(int i=0;i<n-1;++i)tmp[i] = res[b[i]];
            for(int i=0;i<n-1;++i)res[i] = tmp[i];
        }
        vector<int> tmp(n-1);
        for(int i=0;i<n-1;++i)tmp[i] = b[b[i]];
        for(int i=0;i<n-1;++i)b[i] = tmp[i];
        k /= 2;
    }
    long long su = x[0];
    cout<<su<<endl;
    for(int i=0;i<n-1;++i){
        su += x[res[i]+1]-x[res[i]];
        cout<<su<<endl;
    }
    return 0;
}

Measured memory_bytes: 3576
n = gets.to_i
ss = n.times.map { gets.chomp }
ss.map! { |s|
  count = Hash.new { 0 }
  s.chars.map { |c|
    [c, count[c]].tap do
      count[c] += 1
    end
  }
}

puts ss.reduce(:&).map(&:first).sort.join

Measured memory_bytes: 1916
from collections import defaultdict
N=int(input())
S=input()
A=S[:N]
B=S[N:]
B=B[::-1]
def f(A):
    dd=defaultdict(int)
    for i in range(1<<N):
        a=''
        b=''
        for j in range(N):
            if i&(1<<j):
                a+=A[j]
            else:
                b+=A[j]
        dd[(a,b)]+=1
    return dd
dd1=f(A)
dd2=f(B)
ans=0
for t,c in dd1.items():
    ans+=dd2[t]*c
print(ans)

Measured memory_bytes: 200188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
// const ll INF = 1000000000000000000LL;

int main() {
	ll n;
	cin >> n;
	ll a,b;
	for(int i=sqrt(n);i>=1;i--){
		if(n%i==0){
			a = i;
			b = n/i;
			break;
		}
	}
	ll ans = a+b-2;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int main(){
    int c,n,m,s,d;
    for(;;){
        scanf("%d%d%d%d%d",&c,&n,&m,&s,&d);
        if(c==0&&n==0&&m==0&&s==0&&d==0) break;
        s--;d--;
        int path[100][100];
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                path[i][j]=-1;
            }
        }
        int fr,to,co;
        for(int i=0;i<m;i++){
            scanf("%d%d%d",&fr,&to,&co);
            fr--;to--;
            path[fr][to]=path[to][fr]=co;
        }
        int dist[100][11];
        for(int i=0;i<n;i++){
            for(int j=0;j<=c;j++){
                dist[i][j]=-1;
            }
        }
        priority_queue<PP,vector<PP>,greater<PP> > pque;
        pque.push(PP(0,P(0,s)));
        dist[s][0]=0;
        while(!pque.empty()){
            PP now=pque.top();
            pque.pop();
            int ndi=now.first,ncar=now.second.first,nat=now.second.second;
            if(dist[nat][ncar]!=-1 && dist[nat][ncar]<ndi) continue;
            for(int i=0;i<n;i++){
                if(path[nat][i]!=-1 && (dist[i][ncar]==-1 || ndi+path[nat][i]<dist[i][ncar])){
                    pque.push(PP(ndi+path[nat][i],P(ncar,i)));
                    dist[i][ncar]=ndi+path[nat][i];
                }
                if(path[nat][i]!=-1 && ncar+1<=c && (dist[i][ncar+1]==-1 || ndi+path[nat][i]/2 < dist[i][ncar+1])){
                    pque.push(PP(ndi+path[nat][i]/2,P(ncar+1,i)));
                    dist[i][ncar+1]=ndi+path[nat][i]/2;
                }
            }
        }
        int mi=INT_MAX;
        for(int i=0;i<=c;i++){
            if(dist[d][i]!=-1 && dist[d][i]<mi) mi=dist[d][i];
        }
        printf("%d\n",mi);
    }
}

Measured memory_bytes: 0
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for(ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

ll gcd(ll a, ll b) {
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    ll N;
    in >> N;
    vector<string> v{};
    unordered_map<string, ll> used_chars{};
    // solution here
    priority_queue<string, vector<string>, greater<>> q{};
    used_chars[""] = 0;
    q.emplace("");
    while(!q.empty()) {
        auto s = q.top(); q.pop();
        REP(i, used_chars[s]+1) {
            auto n = s;
            n.append(1, 'a'+i);
            used_chars[n] = used_chars[s] + (i == used_chars[s] ? 1 : 0);
            if (n.size() == N) {
                v.emplace_back(std::move(n));
            } else {
                q.emplace(std::move(n));
            }
        }
    }

    sort(v.begin(), v.end());
    for(auto x :v) {
        out << x << endl;
    }
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 18108
#include <iostream>
using namespace std;
int main() {
  int S, a, b, c, d;
  std:: string ans;

  cin >> S;

  a = S/1000;
  b = (S - a*1000) /100;
  c = (S - a*1000 - b*100)/10;
  d = (S - a*1000 - b*100 - c*10);
  if(a*10 +b==0){
      if(c*10 +d==0){
          ans = "NA";
      }else if(c*10 +d > 12){
          ans = "NA";
      }else{
          ans = "YYMM";
      }
  }else if(a*10 +b > 12){
      if(c*10 +d==0){
          ans = "NA";
      }else if(c*10 +d > 12){
          ans = "NA";
      }else{
          ans = "YYMM";
      }
  }else{
      if(c*10 +d==0){
          ans = "MMYY";
      }else if(c*10 +d > 12){
          ans = "MMYY";
      }else{
          ans = "AMBIGUOUS";
      }
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>

int main (int argc, char *argv[])
{
    int X,A,B;
    scanf("%d %d %d",&X,&A,&B);

    if ((A-B) >= 0){ 
        printf("delicious\n");
    }else if (((X+A)-B) >= 0){ 
        printf("safe\n");
    }else{
        printf("dangerous\n");
    }   

    return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF (1LL << 40)
int main() {
	int n, k, m, l;
	scanf("%d", &n);
	k = n / 500;
	m = n - k * 500;
	l = m / 5;
	printf("%d\n", k * 1000 + l * 5);
	return 0;
}

Measured memory_bytes: 128
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>

using namespace std;
using LL = long long;

constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;

int main() {
	int n;
	while (cin >> n&&n) {
		int a, maxl = 0, notzero = 0;
		for (int i = 0; i < n; i++) {
			cin >> a;
			if (a != 0)notzero++;
			maxl = max(a, maxl);
		}
		if (maxl < 2)cout << "NA" << endl;
		else cout << notzero + 1 << endl;
	}
}

Measured memory_bytes: 3092
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    long long N,K;;
    long long ans=1;
    cin >> N>>K;

    rep(i,N){
        if(ans+K>2*ans){
            ans*=2;
        }else{
            ans+=K;
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
  string str,stri;
  int n;
  cin >> str;
  n = str.size();
  for(int i=0;i < n/2;i++) {
    stri[0] = str[i];
    str[i] = str[n-i-1];
    str[n-i-1] = stri[0];
  }
  cout << str << endl;
}

Measured memory_bytes: 0
N = int(input())
s = input().strip()
d = {"W":0,"E":0}
x=[]
for i, c in enumerate(s):
    x.append(d["W"])
    d[c]+=1
d = {"W":0,"E":0}
r = N
for i, c in enumerate(s[::-1]):
    r = min(r, x[N-i-1]+d["E"])
    d[c]+=1
print(r)


Measured memory_bytes: 53584
#!/usr/bin/env python3
def main():
    import numpy as np

    N = int(input())
    testimony = np.zeros((N, N), dtype=np.int64)
    for i in range(N):
        A = int(input())
        INF = 10 ** 10
        for _ in range(A):
            x, y = map(int, input().split())
            testimony[i, x - 1] += 1 if y else -INF

    # 正直者のパターンをbit全探索
    ans = 0
    for bit in range(1 << N):
        honest = set()
        pick = np.zeros(N, dtype=np.int64)
        for i in range(N):
            if bit & (1 << i):
                honest.add(i)
                pick += testimony[i, :]
        flag = True
        for j in range(N):
            value = pick[j]
            # 下記3つの内1つでも満たしたら，仮定が間違っていると分かる.
            if (0
                    or (j in honest and value < 0)         # 正直者なのに嘘つきと言われる
                    or (j not in honest and value > 0)     # 嘘つきなのに正直者と言われる
                    or (value < 0 and value % INF != 0)):  # 正直とも嘘つきとも言われる
                flag = False
                break
        if flag:
            ans = max(ans, len(honest))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27152
let n = Int(readLine()!)!
let v = readLine()!.characters.split(" ").map{Int(String($0))!}
var num = (0..<2).map{_ in (0..<100000).map{_ in 0}}
for (i, vi) in v.enumerate() {
    num[i%2][vi-1] += 1
}
var first = [0, 0]
var second = [0, 0]
for i in 0..<100000 {
    for j in 0..<2 {
        if num[j][i] > first[j] {
            (first[j], second[j]) = (num[j][i], first[j])
        } else if num[j][i] > second[j] {
            second[j] = num[j][i]
        }
    }
}
if num[0].indexOf(first[0]) != num[1].indexOf(first[1]) {
    print(n - (first[0]+first[1]))
} else {
    print(n - max(first[0]+second[1], second[0]+first[1]))
}

Measured memory_bytes: 7236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////
int ssize;

ll cal(vector<int>v){
    int n=v.size();
    ll res=0;
    rep(i,0,n-2){
        res=max(res,v[i+1]-v[i]-1);
    }
    return res;
}



int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    
    string s;cin>>s;
    ssize=s.size();
    ll ans=inf;
    rep(i,0,25){
        vector<int>v;
        v.pb(-1);
        rep(j,0,ssize-1)if(s[j]-'a'==i)v.pb(j);
        v.pb(ssize);
        ans=min(ans,cal(v));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256