akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int a, b, c, k;
  cin >> a >> b >> c;
  cin >> k;
  REP(i, k) {
    if (a < b && b < c) break;
    if (b <= a) {
      b *= 2;
      continue;
    }
    if (c <= b) {
      c *= 2;
      continue;
    }
  }

  if (a < b && b < c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
import java.util.*;
import java.lang.*;

class Counter<T> extends TreeMap<T,Long>{
    public Counter(){
        super();
    }
    public Counter(T[] array){
        super();
        for(int i=0; i<array.length; i++) this.add(array[i], 1L);
    }
    public Counter(List<T> list){
        super();
        for(T elm:list) this.add(elm, 1L);
    }
    public Counter(Map<T,Long> m){
        super(m);
    }

    public Long count(Object elm){
        return getOrDefault(elm,0L);
    }
    public void add(T elm, long amount){
        if(!this.containsKey(elm)) put(elm, amount);
        else replace(elm, get(elm)+amount);
        if(this.count(elm)==0) this.remove(elm);
    }
    public void addOne(T elm){
        this.add(elm, 1L);
    }
}

public class Main {
    static void possible(){
        System.out.println("Yes");
        System.exit(0);
    }
    static void impossible(){
        System.out.println("No");
        System.exit(0);
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = 1<<N;
        Counter<Long> S = new Counter<>();
        for(int k=0; k<K; k++) S.addOne(sc.nextLong());

        long firstSlime = S.lastKey();

        Counter<Long> currentSlimes = new Counter<>();
        Counter<Long> unfoundSlimes = new Counter<>(S);
        currentSlimes.addOne(firstSlime);
        unfoundSlimes.add(firstSlime, -1L);

        for(int t=0; t<N; t++){
            Counter<Long> nextSlimes = new Counter<>(currentSlimes);
            for(Long slimeHealth: currentSlimes.keySet()){
                long smileAmount = currentSlimes.get(slimeHealth);
                for(long a=0; a<smileAmount; a++){
                    Long weakerSlime = unfoundSlimes.lowerKey(slimeHealth);
                    if(weakerSlime==null) impossible();
                    nextSlimes.addOne(weakerSlime);
                    unfoundSlimes.add(weakerSlime, -1L);
                }
            }
            //System.err.println(nextSlimes);
            currentSlimes = nextSlimes;
        }

        possible();


    }
}


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

int main(){
    string s;
    cin >> s;
    int ans=0,memo=0;
    int now = 0;
    int n = s.size();
    rep(i,n){
        if(s[i]-'0' != now) ans++;
        now = 1-now;
    }
    now = 1;
    rep(i,n){
        if(s[i]-'0' != now) memo++;
        now = 1-now;
    }
    ans = min(ans,memo);
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;

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

  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
 
using namespace std;
 
int main()
{
  int N;
  cin >> N;
  
  int a[N];
  for(int i = 0; i < N; i++) 
  {
    cin >> a[i];
    if(a[i] % 2 != 0)
    {
      cout << 0 << endl;
  	return 0;
    }
}
    
  
  int cnt = 1;
  int b = 0;
  
  while(1)
  {
      for(int i = 0; i < N; i++) 
  		{
    		a[i] /= 2;
    		if(a[i] % 2 != 0) b = 1;
  		}
    if(b) break;
    ++cnt;
  }
  
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
n,x = map(int, input().split())
al = list(map(int, input().split()))

res = 0
for i in range(n-1):
    a1 = al[i]
    a2 = al[i+1]
    if a1+a2>x:
        d = a1+a2-x
        res += d
        if a2>=d:
            al[i+1] -= d
        else:
            al[i+1] = 0

print(res)

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

void solve(){
	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	long long cnt = 0;
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			for(int k = j + 1; k < n; k++){
				if(a[i] != a[j] && a[j] != a[k] && a[i] + a[j] > a[k]) cnt++; 
			}
		}
	}
	cout << cnt << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int t = 1;
	//cin >> t;
	while(t--) solve();
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;


int main() {
    string s;
    cin >> s;
    int s_kosu = 0;
    int ans = 0;
    REP(i, s.size()) {
        if(s[i] == 'S') {
            s_kosu++;
        } else {
            if(s_kosu > 0) {
                s_kosu--;
                ans++;
            }
        }
    }
    cout << s.size() - 2*ans << endl;

    return 0;
}

Measured memory_bytes: 640
N=int(input())
li = list(map(int,input().split()))

flag = 0

for i in li:
  if i%2 ==0:
    if i%3 != 0 and i%5 != 0:
      print('DENIED')
      flag = 1
      break
    else:
      continue
      
if flag == 0:
  print('APPROVED')

Measured memory_bytes: 2940
//#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  ll A[N], B[N];
  for (int i = 0; i <= N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  ll s = 0;
  for (int i = 0; i < N; i++) {
    s += min(A[i], B[i]);
    B[i] -= min(A[i], B[i]);
    A[i] -= min(A[i], B[i]);
    s += min(A[i + 1], B[i]);
    A[i+1] -= min(A[i + 1], B[i]);
  }
  cout << s << "\n";
  return 0;
}

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>>N;
    vector<string>vec;
    REP(i,N){
        string s;
        cin>>s;
        vector<char> c;
        REP(j,10){
            c.pb(s[j]);
        }
        sort(all(c));
        REP(j,10){
            s[j]=c[j];
        }
        vec.pb(s);
    }
    sort(all(vec));
    ll cnt;cnt=1;
    ll ans;ans=0;
    REP1(i,N-1){
        if(vec[i]==vec[i-1]){
            cnt++;
        }else{
            if(cnt>1){
                ans+=cnt*(cnt-1)/2;
            }
            cnt=1;
        }
    }
    if(cnt>1){
        ans+=cnt*(cnt-1)/2;
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 5748
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

struct edge {
  int from;
  int to;
  ld cost;
};
bool operator<(const edge&l, const edge&r) {
  return l.cost < r.cost;
}
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};
int main() {
  int N, M; cin >> N >> M;
  vector<pair<ld, ld>>ps;
  for (int i = 0; i < N; ++i) {
    ld x, y; cin >> x >> y;
    ps.emplace_back(x, y);
  }
  vector < edge>edges;
  
  for (int i = 0; i < M; ++i) {
    int a, b; cin >> a >> b; a--; b--;
    ld dis = sqrt((ps[a].first - ps[b].first)*(ps[a].first - ps[b].first) + (ps[a].second - ps[b].second)*(ps[a].second - ps[b].second));
    edges.push_back(edge{ a,b,dis });
  }
  sort(edges.begin(), edges.end());
  reverse(edges.begin(), edges.end());
  UnionFind uf(N);
  ld ans = 0;
  for (int i = 0; i < M; ++i) {
    edge e(edges[i]);
    if(uf.root(e.from) != uf.root(e.to)) {
      uf.unionSet(e.from, e.to);
    }
    else {
      ans += e.cost;
    }
  }
  cout <<fixed<<setprecision(22)<< ans << endl;

  return 0;
}

Measured memory_bytes: 4360
#include<iostream>
using namespace std;
int h[24]={0},m[24][60]={0},N,M,z,p,count=0;
int in(){
    cin>>N;
    count+=N;
    for(int a=0;a<N;a++){
        cin>>z>>p;
          if(h[z]==1&&m[z][p]==1)
                count--;
        h[z]=1;m[z][p]=1;
    }
    cin>>M;
    count+=M;
    for(int b=0;b<M;b++){
        cin>>z>>p;
            if(h[z]==1&&m[z][p]==1)
                count--;
        h[z]=1;m[z][p]=1;
    
    }

}
int out(){
    for(int c=0;c<24;c++){
for(int d=0;d<60;d++){
if(h[c]==1&&m[c][d]==1){
cout<<c<<":";
    if(d<10){
cout<<0;
       
    }
cout<<d;
  
if(count!=1)
cout<<" ";
count--;
}
}
}
cout<<endl;
}
int main(){
in();
out();
return 0;

}

Measured memory_bytes: 1168
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード
 
//ループ
#define rep(i, n) for(int i = 0; i < (n); i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ
 
//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;
const double PI = acos(-1); //π
 
using namespace std;
 
//ソート
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 
//#include "./lib/generic/search.h"

//文字列入力した小数値を小数点なくして返す
int changeDoubleToInt(string decimal){ 
    decimal.erase(1, 1); //小数点削除
    int n_decimal = atoi(decimal.c_str()); //c_strでchar*に変換後、atoiでintに変換
    return n_decimal;
}

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

int main(){
   int n;
   cin >> n;
   vector<int> a(n);
   int finaldown=-1, finalup=-1;
   rep(i,n) cin >> a[i];
   ll x=1000;
   rep(i,n-1){
       int s = a[i];
       int t = a[i+1];
       if(s<t){
           ll k = x/s; //株購入
           x %= s;
           x += k*t;
       }
   }
   cout << x << endl;
   return 0;
}

Measured memory_bytes: 3624
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		String ans = "";
		for(int i=0;i<str.length();i++) {
			ans += (char) ( 'A' + (str.charAt(i) + 23 - 'A') % 26 );
		}
		System.out.println(ans);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
//s.empty() //emptyなら1を出力 入っていれば0を出力
/*//ABC018-B 部分的にreverseをかける解法
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n) cin>>a.at(i)>>b.at(i);
  rep(i,n)a.at(i)--;
  rep(i,n)b.at(i)--;
  string t;
  rep(i,n){
    t = s;
    for(int k=0;k<=b.at(i)-a.at(i);k++){
      t.at(a.at(i)+k) = s.at(b.at(i)-k);
    }
    s = t;
  }
  cout << s << endl;
}
*///ABC018-B
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,a,b;
  cin >> n >> a >>b;
  int flag = 0;
  for(int i=0;i<1010;i=i+n){
    if(a<=i&&i<=b)flag=1;
  }
  if(flag==1)cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
}


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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> A(N);
    //int cnt_pos = 0, cnt_neg = 0;
    vector<int> pos, neg;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        //cnt_pos += (A[i] > 0);
        //cnt_neg += (A[i] < 0);
        if (A[i] >= 0) pos.push_back(A[i]);
        else if (A[i] < 0) neg.push_back(A[i]);
    }
    //int cnt0 = N - cnt_pos - cnt_neg;
    sort(begin(pos), end(pos));
    sort(begin(neg), end(neg));

    int res = 0;
    vector<pair<int, int>> ops;
    if (pos.empty()) {
        int x = neg[N - 1];
        res = x;
        for (int i = 0; i < N - 1; ++i) {
            res += -neg[i];
        }
        int cur = x;
        for (int i = 0; i < N - 1; ++i) {
            ops.emplace_back(cur, neg[i]);
            cur -= neg[i];
        }
    } else if (neg.empty()) {
        int x = pos[0];
        res = -x;
        for (int i = 1; i < N; ++i) {
            res += pos[i];
        }
        int cur = x;
        for (int i = 1; i + 1 < N; ++i) {
            ops.emplace_back(cur, pos[i]);
            cur -= pos[i];
        }
        ops.emplace_back(pos.back(), cur);
    } else {
        for (int i = 0; i < N; ++i) {
            res += abs(A[i]);
        }
        int cur1 = neg[0];
        for (int i = 1; i < (int)pos.size(); ++i) {
            int y = pos[i];
            ops.emplace_back(cur1, y);
            cur1 -= y;
        }
        int cur2 = pos[0];
        for (int i = 1; i < (int)neg.size(); ++i) {
            ops.emplace_back(cur2, neg[i]);
            cur2 -= neg[i];
        }
        ops.emplace_back(cur2, cur1);
    }
    cout << res << "\n";
    for (const auto p : ops) {
        int a = p.first, b = p.second;
        cout << a << " " << b << "\n";
    }


    return 0;
}

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

int main() {
  int N, M;
  
  
  cin >> N;
  vector<string> blue_card(N);
  for (int i = 0; i < N; i++) {
    cin >> blue_card.at(i);
  }
  
  cin >> M;
  vector<string> red_card(M);
  for (int i = 0; i < M; i++) {
    cin >> red_card.at(i);
  }
  
  string target_word = "";
  int best_point = 0;
  for (int i = 0; i < N; i++) {
    int counter = 0;
    target_word = blue_card.at(i);
    for (int j = i; j < N; j++) {
      if (target_word == blue_card.at(j)) {
        counter++;
      }
    }
    for (int k = 0; k < M; k++) {
      if (target_word == red_card.at(k)) {
        counter--;
      }
    }
    if (counter > best_point) {
      best_point = counter;
    }
  }
  
  
  /*
  for (int i = 0; i < N; i++) {
    cout << blue_card.at(i);
  }
  cout << endl;
  for (int i = 0; i < M; i++) {
    cout << red_card.at(i);
  }
  cout << endl;
  */
  cout << best_point << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#define N1 1501
#define N2 1000
using namespace std;
int hcnt[N1*N2],wcnt[N1*N2];
int main(){
  int N,M,h[N1],w[N1];
  vector<int> H,W;
  set<int> S;
  while(1){
    cin >> N >> M;
    if(N==0&&M==0) break;
    for(int i=0;i<N;i++){
      cin >> h[i];
      if(i>0) h[i]+=h[i-1];
      H.push_back(h[i]);
    }
    for(int i=0;i<M;i++){
      cin >> w[i];
      if(i>0) w[i]+=w[i-1];
      W.push_back(w[i]);
    }
    int l=1;
    while(l!=N+1){
      for(int i=l;i<N;i++){
	H.push_back(h[i]-h[i-l]);
      }
      l++;
    }
    l=1;
    while(l!=M+1){
      for(int i=l;i<M;i++){
	W.push_back(w[i]-w[i-l]);
      }
      l++;
    }
    sort(H.begin(),H.end());
    sort(W.begin(),W.end());
    for(int i=0;i<N1*N2;i++) hcnt[i]=wcnt[i]=0;
    for(int i=0;i<H.size();i++){
      S.insert(H[i]);
      hcnt[H[i]]++;
    }
    int k=0;
    for(set<int>::iterator it=S.begin();it!=S.end();it++){
      for(int i=k;i<W.size();i++){
	if((*it)==W[i]){
	  wcnt[(*it)]++;
	}else if((*it)<W[i]){
	  k=i;
	  break;
	}
      }
    }
    int sum=0;
    for(set<int>::iterator it=S.begin();it!=S.end();it++){
      if(hcnt[(*it)]!=0&&wcnt[(*it)]!=0) sum+=hcnt[(*it)]*wcnt[(*it)];
    }
    cout << sum << endl;
    H.clear();
    W.clear();
    S.clear();
  }
  return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll s(n);
  rep(i,n-1){
    ll a; cin>>a; a--;
    s[a]++;
  }
  rep(i,n){
    cout<<s[i]<<endl;
  }
}

Measured memory_bytes: 4756
// Best practice

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key

signed main() {
   tezz
   
    string s;
    cin >> s;
    int n=s.length();
    for(int i=0; i<n; i++){
        cout << "x";
    }
    
  
   return 0;
}



Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(dead_code)]
const MOD: i32 = 1e9 as i32 + 7;

fn main() {
    input!(h1: i32, m1: i32, h2: i32, m2: i32, k: i32);
    let mut min1 = h1 * 60 + m1;
    let min2 = h2 * 60 + m2;
    println!("{}", if min1 + k >= min2 { 0 } else { min2 - min1 - k });
}


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

const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  rep(i,n) cin >> v[i];

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

  rep(i,n-1) {
    v[i+1] = (v[i] + v[i+1])/2;
  }

  cout<<v[n-1]<<endl;
  return 0;
}

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

signed main()
{
	int n;
	std::cin >> n;
	std::vector<int> dp(n + 1);
	dp[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		dp[i] = dp[i - 1] + 1;
		for (int j = 6; j <= i; j *= 6)
			dp[i] = std::min(dp[i], dp[i - j] + 1);
		for (int j = 9; j <= i; j *= 9)
			dp[i] = std::min(dp[i], dp[i - j] + 1);
	}
	std::cout << dp[n] << std::endl;
	return 0;
}


Measured memory_bytes: 640
//defines e includes
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define rep1(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, a, b) for(int i=(int)a;i<(int)b;i++)
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define p_b pop_back
#define p_f pop_front
#define mp make_pair
#define MAX 100010
#define oo INT_MAX
using namespace std;
//tipagem de pares
typedef pair<int, int> ii;
typedef pair<char, char> cc;
typedef pair<int, char> ic;
typedef pair<char, int> ci;
//tipagem de vetores
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vii;
typedef vector<bool> vb;
//tipagem de outras estruturas
typedef queue<int> qi;
typedef deque<int> dqi;
//tipagem de tipos primitivos
typedef long long int ll;
typedef unsigned long long int ull;

int main()
{
	
	fastio;
	int n, k;
	cin >> n >> k;
	int h[n], i;
	rep1(i, n){
		cin >> h[i];
	}
	sort(h, h+n);
	for(i=n-1;i>=0 && k > 0;i--){
		h[i] = 0;
		k--;
	}
	ll ans = 0;
	for(i=0;i<n;i++){
		if(h[i] > 0){
			ans += h[i];
		}
	}
	cout << ans << endl;

	return 0;
}

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

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

fn main() {
    let o = read::<String>().chars().collect::<Vec<_>>();
    let e = read::<String>().chars().collect::<Vec<_>>();
    let mut ans = vec![];
    for i in 0..e.len() {
        ans.push(o[i]);
        ans.push(e[i]);
    }
    if o.len() > e.len() {
        ans.push(o[o.len() - 1]);
    }
    for ch in ans {
        print!("{}", ch);
    }
    println!("");
}

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

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


Measured memory_bytes: 4352
#include<cstdio>
#include<stack>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;
int main(){
    int r,c,n,x,y,x1,y1;
    stack<int> s;
    vector<pair<int,int> > v;
    scanf("%d %d %d",&r,&c,&n);
    for(int i=0;i<n;i++){
        scanf("%d %d %d %d",&x,&y,&x1,&y1);
        if((x==0||y==0||x==r||y==c)&&(x1==0||y1==0||x1==r||y1==c)){
            if(x==0){
                v.push_back(make_pair(y,i));
            }
            else if(y==c){
                v.push_back(make_pair(c+x,i));
            }
            else if(x==r){
                v.push_back(make_pair(2*c+r-y,i));
            }
            else{
                v.push_back(make_pair(2*c+2*r-x,i));
            }
            if(x1==0){
                v.push_back(make_pair(y1,i));
            }
            else if(y1==c){
                v.push_back(make_pair(c+x1,i));
            }
            else if(x1==r){
                v.push_back(make_pair(2*c+r-y1,i));
            }
            else{
                v.push_back(make_pair(2*c+2*r-x1,i));
            }
        }
    }
    if(v.size()){
        sort(v.begin(),v.end());
        s.push(v[0].second);
        for(int i=1;i<v.size();i++){
            if(!s.empty()&&v[i].second==s.top()){
                s.pop();
            }
            else{
                s.push(v[i].second);
            }
        }
    }
    if(s.size()){
        printf("NO\n");
    }
    else{
        printf("YES\n");
    }
}

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

int main(void){
	int n, m, i;
	char a[200000], b[200000];
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	scanf("%d%d", &n, &m);
	char f=0;
	for(i=0; i<m; i++){
		int A, B;
		scanf("%d%d", &A, &B); A--; B--;
		if(A==0){
			a[B]=1;
			if(b[B]!=0){f=1; break;}
		}
		if(B==n-1){
			b[A]=1;
			if(a[A]!=0){f=1; break;}
		}
	}
	puts(f!=0?"POSSIBLE":"IMPOSSIBLE");
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<ctime>
#include<cstdlib>
#include<numeric>
#include<typeinfo>
#include<cstdio>
#include<cctype>
#include<list>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
const int inf=1e8;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009

 
int main(){
	int i,n,q,j;
	cin>>n;
	vector<int> s(n);
	loop(i,0,n){
		cin>>s[i];
	}
	cin>>q;
	int sum=0;
	loop(i,0,q){
		int t;
		cin>>t;
		loop(j,0,n){
			if(t==s[j]){
				sum++;
				break;
			}
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AOddsOfOddness solver = new AOddsOfOddness();
        solver.solve(1, in, out);
        out.close();
    }

    static class AOddsOfOddness {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int n = s.nextInt();
            double prob;
            if (n % 2 == 0) {
                prob = n / 2;
            } else {
                prob = n / 2 + 1;
            }

//        out.println(prob);
            out.println(prob / n);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 22868
class SegmentTree():
    def __init__(self, array, f, ti):
        """
        Parameters
        ----------
        array : list
            to construct segment tree from
        f : func
            binary operation of the monoid
        ti : 
            identity element of the monoid
        """
        self.f = f
        self.ti = ti
        self.n = n = 2**(len(array).bit_length())
        self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
        for i in range(n - 1, 0, -1):  # build
            dat[i] = f(dat[i << 1], dat[i << 1 | 1])

    def update(self, p, v):  # set value at position p (0-indexed)
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        f, ti, n, dat = self.f, self.ti, self.n, self.dat
        res = ti
        l += n
        r += n
        while l < r:
            if l & 1:
                res = f(res, dat[l])
                l += 1
            if r & 1:
                r -= 1
                res = f(dat[r], res)
            l >>= 1
            r >>= 1
        return res


N = int(input())
P = [int(_) for _ in input().split()]
p_i = {p: i + 1 for i, p in enumerate(P)}
SL = SegmentTree([0] * (N + 2), max, 0)
SR = SegmentTree([N + 1] * (N + 2), min, N + 1)
ans = 0
for p in range(N, 0, -1):
    i = p_i[p]
    SL.update(i, i)
    SR.update(i, i)
    il = SL.query(0, i)
    ir = SR.query(i + 1, N + 2)
    if il > 0:
        ill = SL.query(0, il)
        ans += p * (il - ill) * (ir - i)
    if ir < N + 1:
        irr = SR.query(ir + 1, N + 2)
        ans += p * (irr - ir) * (i - il)
print(ans)


Measured memory_bytes: 87076
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/math/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
#ifdef BOOST_RANGE_ALGORITHM_FOR_EACH_HPP_INCLUDED
  boost::for_each(vc, [&os](T value) {
#else
  std::for_each(vc.begin(), vc.end(), [&os](T value) {
#endif
    os << value << '\n';
    });
  return os;
}

template<class T1, class T2>
inline
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  //string S{}; std::cin >> S;
  ui A{}, B{}, T{}; cin >> A >> B >> T;
  
  ull ans{};
  for (ui i = A; i < T + 1; i += A)
    ans += B;

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

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}


mt19937 rnd(time(0));

struct DSU {
    vector<int> sz;
    vector<int> parent;

    int total;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            total--;
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        total = n;
        for (int i = 0; i < n; i++) make_set(i);
    };
};

/*
const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    if (n<k) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/

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

    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i<n; i++) cin>>a[i];
    for (int i = 0; i<n; i++) cin>>b[i];
    int A = 0;
    for (auto it: a) A^=it;
    int B = 0;
    for (auto it: b) B^=it;

    a.push_back(A);
    b.push_back(B);

    if (multiset<int>(a.begin(), a.end())!=multiset<int>(b.begin(), b.end())) {cout<<-1; return 0;}

    vector<int> a1, b1;
    for (int i = 0; i<=n-1; i++)
    {
        if (a[i]!=b[i]) {a1.push_back(a[i]); b1.push_back(b[i]);}
    }
    a1.push_back(A); b1.push_back(B);
    n = a1.size();
    if (n==1)
    {
        cout<<0; return 0;
    }

    a = a1; b = b1;

    map<int, stack<int>> mapka;

    for (int i = 0; i<n; i++) mapka[a[i]].push(i);

    map<int, int> last;

    vector<int> prm(n);

    DSU dsu(n);

    for (int i = 0; i<n; i++)
    {
        prm[i] = mapka[b[i]].top();
        mapka[b[i]].pop();
        dsu.union_sets(i, prm[i]);
        if (last.find(b[i])!=last.end()) dsu.union_sets(last[b[i]], i);
        last[b[i]] = i;
    }

    //cout<<dsu.total<<endl;

    cout<<(dsu.total-1) + (n-1);

}

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

int main(){
    int n;
    while(cin>>n && n!=0){
        vector<string> a(n);
        rep(i,n)cin >> a[i];
        bool f = 0;
        int l = 0,r=0;
        int c = 0;
        rep(i,n){
            if(a[i]=="lu"){
                l = 1;
                if(l==1&&r==1&&!f){
                    f = 1;
                    c++;
                }
            }else if(a[i]=="ru"){
                r = 1;
                if(l==1&&r==1&&!f){
                    f = 1;
                    c++;
                }
            }else if(a[i]=="ld"){
                l = 0;
                if(l==0&&r==0&&f){
                    f = 0;
                    c++;
                }
            }else{
                r = 0;
                if(l==0&&r==0&&f){
                    f = 0;
                    c++;
                }
            }
        }
        cout << c << "\n";
    }
    return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

string s;
int dp[510][510];

int dfs(int l, int r){
    if(dp[l][r] >= 0) return dp[l][r];
    dp[l][r] = 0;
    if(s[l] != 'm' || s[r] != 'w') return 0;
    For(i, l+1, r)if(s[i] == 'e'){
        int s, t;
        if(i == l+1) s = 1;
        else s = dfs(l+1, i-1);
        if(s == 0) continue;
        
        if(i == r-1) t = 1;
        else t = dfs(i+1, r-1);
        if(s && t) return dp[l][r] = 1;
    }
    return 0;
}

int main(){
    cin >> s;
    int n = s.size();
    rep(i, n)rep(j, n) dp[i][j] = -1;
    puts(dfs(0, n-1) ? "Cat" : "Rabbit");
}


Measured memory_bytes: 4220
/*
 * 1161.cc: Verbal Arithmetic
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 12;
const int MAX_M = 8;

/* typedef */

/* global variables */

int n, m, gn;
int ids[26], ds[10], exps[MAX_N][MAX_M];
bool zfs[10], used[10];

/* subroutines */

int rec(int x, int y, int co) {
  if (x >= m) return (co == 0) ? 1 : 0;

  int eid = exps[y][x];
  
  if (y == n - 1) {
    int sum = co;
    for (int i = 0; i < n - 1; i++)
      sum += (exps[i][x] >= 0) ? ds[exps[i][x]] : 0;

    int dn = sum % 10, de = ds[eid];
    if (de < 0) {
      if (! used[dn] && (! zfs[eid] || dn > 0)) {
	used[dn] = true;
	ds[eid] = dn;
	int r = rec(x + 1, 0, sum / 10);
	ds[eid] = -1;
	used[dn] = false;
	return r;
      }
    }
    else if (dn == de) return rec(x + 1, 0, sum / 10);

    return 0;
  }

  if (eid < 0 || ds[eid] >= 0) return rec(x, y + 1, co);

  int r = 0;
  for (int d = 0; d <= 9; d++)
    if (! used[d] && (! zfs[eid] || d > 0)) {
      used[d] = true;
      ds[eid] = d;
      r += rec(x, y + 1, co);
      ds[eid] = -1;
      used[d] = false;
    }
  return r;
}

/* main */

int main() {
  for (;;) {
    cin >> n;
    if (n == 0) break;

    memset(ids, -1, sizeof(ids));
    memset(ds, -1, sizeof(ds));
    memset(zfs, false, sizeof(zfs));
    memset(used, false, sizeof(used));

    gn = m = 0;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      int sn = s.size();
      if (m < sn) m = sn;
      for (int j = 0; j < sn; j++) {
	int ch = s[sn - 1 - j] - 'A';
	if (ids[ch] < 0) ids[ch] = gn++;
	exps[i][j] = ids[ch];
      }
      for (int j = sn; j < MAX_M; j++) exps[i][j] = -1;
      if (sn > 1) zfs[exps[i][sn - 1]] = true;
    }

    if (false) {
      for (int i = 0; i < n; i++) {
	for (int j = m - 1; j >= 0; j--) {
	  if (exps[i][j] >= 0) printf("%d", exps[i][j]);
	  else putchar(' ');
	}
	putchar('\n');
      }
      for (int i = 0; i < gn; i++) printf("%d", zfs[i]); putchar('\n');
    }

    int ans = rec(0, 0, 0);
    printf("%d\n", ans);
  }

  return 0;
}

Measured memory_bytes: 1204
/** Which of the favors of your Lord will you deny ? **/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>using indexed_set = tree<TIn, null_type, less<TIn>,rb_tree_tag, tree_order_statistics_node_update>;

/**

PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

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

const int nmax = 2e5+7;
const LL LINF = 1e17;

template <class T>
string to_str(T x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

vector<int>v;
int n,mn;
unordered_map<int,bool>dp;

bool solve(int k)
{
//    assert(k>=0);

    if(k<mn) return false;

    if(binary_search(ALL(v),k)) return true;

    if(dp.count(k))
        return dp[k];

    bool ok = false;

    for(int i=0; i<n; i++)
    {
        if(v[i]>k)
            break;

        if(solve(k-v[i])==false)
        {
            ok = true;
            break;
        }
    }

//    cout<<k<<" = "<<dp[k]<<endl;
    return dp[k] = ok;
}

int main()
{
    optimizeIO();

//    WRITE;

    int k;
    cin>>n>>k;

    mn = INT_MAX;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        v.push_back(x);
        mn = min(mn,v[i]);
    }

    if(solve(k))
        cout<<"First"<<endl;
    else
        cout<<"Second"<<endl;

//    cout<<dp.size()<<endl;

//    for(auto x:dp)
//    {
//        cout<<x.F<<" : "<<x.S<<endl;
//    }


    return 0;
}

/**
1 4
3

2 4
2 3

2 5
2 3

2 7
2 3

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}





Measured memory_bytes: 12016
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

for line in stdin:
    a, b, n = (int(s) for s in line.split())
    result = 0
    for i in xrange(1, n+1):
        result += (a * (10 ** i) // b) % 10
    print(result)

Measured memory_bytes: 4220
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;

int main()
{
    ll n,i,j,k;
    cin>>n;
    k=(n*(n-1))/2;
    cout<<k;
    return 0;
}


Measured memory_bytes: 256