akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n, m; cin >> n >> m;
    VI s(m), t(m);
    vector<VI> g(n);
    FOR(i, 0, m) {
        cin >> s[i] >> t[i];
        --s[i], --t[i];
        g[s[i]].push_back(t[i]);
    }

    double ans = INF;
    vector<double> dp;
    FOR(i, 0, n) {
        dp.clear(), dp.resize(n, 0);
        rFOR(now, 0, n - 1) {
            double sum = 0, Max = 0;
            for (int to : g[now]) {
                sum += dp[to];
                chmax(Max, dp[to]);
            }
            int cnt = g[now].size();
            if (now == i && 1 < cnt) {
                --cnt;
                sum -= Max;
            }
            dp[now] = sum / cnt + 1;
        }
        chmin(ans, dp[0]);
    }
    
    cout << ans << "\n";
}


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

int main(){
    string S;
    cin >> S;
    int N = S.size();
    vector<vector<int>> dp(26, vector<int>(N+1, -1));
    vector<int> l(26, 0); //l[i] = ('a'+i)から始まるn文字の全ての文字列が作れる最大のn
    for (int i = 0; i < 26; i++) dp[i][0] = N;
    for (int i = N-1; i >= 0; i--) {
        int c = S[i] - 'a';
        int t = N;
        for (int j = 0; j < 26; j++) t = min(t, l[j]);
        if (l[c] == t) {
            l[c]++;
            dp[c][t+1] = i;
        }
    }
    
    //for (int i = 0; i < 26; i++) cout << dp[i][1] << " " << dp[i][2] << " " << dp[i][3] << endl;
    
    pair<int, int> st;
    st = {0, l[0]};
    for (int i = 1; i < 26; i++) {
        if (st.second > l[i]) st = {i, l[i]};
    }
    
    int pos = 0;
    int now = st.second;
    string ans = "";
    while(now >= 0) {
        int lim = N;
        for (int i = 0; i < 26; i++) lim = min(lim, dp[i][now]);
        vector<bool> use(26, false);
        for (int i = pos; i < lim; i++) {
            use[S[i]-'a'] = true;
        }
        for (int i = 0; i < 26; i++) {
            if (!use[i]) {
                ans += (char)('a'+i);
                pos = lim;
                while (pos < N && (S[pos] - 'a' != i)) pos++;
                pos++;
                break;
            }
        }
        now--;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 21764
def trial_divishion(n):
    factors = []

    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            factors.append(i)
            
    if n != 1:
        factors.append(n)
        
    return factors
    
a, b = map(int, input().split())
print(len(set(trial_divishion(a)) & set(trial_divishion(b))) + 1)

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

int main(){
  int a[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      scanf("%d",&a[i][j]);}}
  int n;
  scanf("%d",&n);
  int b[n];
  for(int k=0;k<n;k++){
    scanf("%d",&b[k]);
    for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      if(a[i][j]==b[k]) a[i][j]=0;}}
  }

  int ans=0;

  for(int i=0;i<3;i++){
    if(a[0][i]==0 && a[1][i]==0 && a[2][i]==0) ans=1;}
  for(int i=0;i<3;i++){
    if(a[i][0]==0 && a[i][1]==0 && a[i][2]==0) ans=1;}
  if(a[0][0]==0 && a[1][1]==0 && a[2][2]==0) ans=1;
  if(a[2][0]==0 && a[1][1]==0 && a[0][2]==0) ans=1;
  

  if(ans) printf("Yes\n");
  else printf("No\n");


  return 0;
}


Measured memory_bytes: 128
N = int(input())
coord = [[i for i in map(int,input().split())] for j in range(N)]

ans = 0

import itertools
import math
for path in itertools.permutations(list(range(N))):
  for i in range(N-1):
    x1 = coord[path[i]][0]
    y1 = coord[path[i]][1]
    x2 = coord[path[i+1]][0]
    y2 = coord[path[i+1]][1]
    ans += ((x1-x2)**2 + (y1-y2)**2)**0.5
    
print(ans/math.factorial(N))

Measured memory_bytes: 3188
#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  using mint = modint<1000000007>;

  int n, x;
  std::cin >> n >> x;
  std::vector<int> s(n);
  for (auto &e : s) {
    std::cin >> e;
  }
  std::sort(s.begin(), s.end());

  std::vector<std::vector<mint>> dp(n + 1, std::vector<mint>(x + 1));

  for (int i = 0; i <= x; ++i) {
    dp[0][i] = i;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= x; ++j) {
      dp[i + 1][j] = dp[i][j] * i + dp[i][j % s[i]];
    }
  }

  std::cout << dp[n][x].value() << std::endl;

  return 0;
}


Measured memory_bytes: 158592
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int ans=0;
  for(int i=1;i<=100;i++){
    if(1000*i>=n){
      ans=1000*i;
      break;
    }
  }
  cout<<ans-n<<endl;
  return 0;
}

Measured memory_bytes: 3632
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int[] l = new int[N];
	int max = 0;
	int maxI = 0;
	for(int i = 0; i<N; i++) {
	    l[i] = sc.nextInt();
	    if(max < l[i]) {
		max = l[i];
		maxI = i;
	    }
	}
	int others = 0;
	for(int i = 0; i<N; i++) {
	    if(i == maxI) continue;
	    others += l[i];
	}
	if(others > max) {
	    System.out.println("Yes");
	}else {
	    System.out.println("No");
	}
    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, W;
    cin >> n >> W;

    ll w0, v0;
    cin >> w0 >> v0;

    vl weight(n), value(n);
    vvl x(4);  // x[i][j] : 重さw0+iの品物でj番目に高い価値
    weight[0] = w0, value[0] = v0;
    x[0].pb(v0);
    exrep(i, 1, n-1) {
        cin >> weight[i] >> value[i];
        x[weight[i] - w0].pb(value[i]);
    }

    rep(i, 4) {
        sort(rall(x[i]));
    }

    vl rui0(x[0].size()+1);  // rui0[i+1] : x[0][0]からx[0][i]までの和
    rep(i, x[0].size()) {
        rui0[i+1] = rui0[i] + x[0][i];
    }
    vl rui1(x[1].size()+1);  // rui1[i+1] : x[1][0]からx[1][i]までの和
    rep(i, x[1].size()) {
        rui1[i+1] = rui1[i] + x[1][i];
    }
    vl rui2(x[2].size()+1);  // rui2[i+1] : x[2][0]からx[2][i]までの和
    rep(i, x[2].size()) {
        rui2[i+1] = rui2[i] + x[2][i];
    }
    vl rui3(x[3].size()+1);  // rui3[i+1] : x[3][0]からx[3][i]までの和
    rep(i, x[3].size()) {
        rui3[i+1] = rui3[i] + x[3][i];
    }

    ll ans = 0;
    exrep(a, 0, x[0].size()) {
        exrep(b, 0, x[1].size()) {
            exrep(c, 0, x[2].size()) {
                exrep(d, 0, x[3].size()) {
                    ll sumW = w0*a + (w0+1)*b + (w0+2)*c + (w0+3)*d;
                    if(sumW <= W) {
                        chmax(ans, rui0[a] + rui1[b] + rui2[c] + rui3[d]);
                    }
                }
            }
        }
    }

    out(ans);
    re0;
}

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

int main(){
  int N;
  scanf("%d", &N);
  bool first = false;
  int A;
  for (int i=0; i<N; i++){
    scanf("%d", &A);
    if (A%2==1){
      first = true;
    }
  }
  printf("%s\n",first?"first":"second");
  return 0;
}


Measured memory_bytes: 256
N,A,B,C,D = map(int,input().split())
S = input()
if '##' in S[A:C]:
    print('No')
elif '##' in S[B:D]:
    print('No')
elif C>D:
    #print(S[B - 2:D + 1])
    if not '...' in S[B-2:D+1]:
        print('No')
    else:
        print('Yes')
else:
    print('Yes')


Measured memory_bytes: 63308
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
   char a[100001];
   int dp[100001];
int main()
{
  int n,q;
  cin>>n; cin>>q;

   getchar();
cin>>a;

memset(dp,0,sizeof(dp));


  for(int i=1;i<n;i++)
  {
      if(a[i-1]=='A'&&a[i]=='C')
        dp[i]=dp[i-1]+1;
        else
            dp[i]=dp[i-1];
  }


   while(q--)
   {
       int c,b;
    cin>>c>>b;
    if(a[c-1]=='C'&&a[c-2]=='A')
      printf("%d\n",dp[b-1]-dp[c-1-1]-1);
      else
         printf("%d\n",dp[b-1]-dp[c-1-1]);

   }
return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(x,to) for(int x=0; x<(to); ++(x))

int main() {
    int n,q,x;
    vector<int> v;
    cin >> n >> q;
    rep(i,n) {
        cin >> x;
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    rep(i,q) {
        cin >> x;
        int ans = 0, y = x;
        while(y<300000) {
            auto it = lower_bound(v.begin(), v.end(), y);
            ans = max(ans, (*--it) % x);
            y += x;
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
    string str;
    cin >> str;
    bool ans = true;
    for (int i=1;i<str.size();i++){
        if (str[i]==str[i-1]){
            ans = false;
        }
    }
    if (ans){
        cout << "Good" << endl;
    } else {
        cout << "Bad" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
//どうかACをお恵みくださいお願いしますお願いしますお願います何もしませんから
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;

using System.Linq;
namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            /*int M = int.Parse(Console.ReadLine());
            string[] n = Console.ReadLine().Split();
            for(int henkan = N;henkan < 0;henkan++)
            {
                for(int henkann = M())
            }*/
            for(int x = 0;x<N;x++)
            Console.Write("ACL");
        }
    }
}

Measured memory_bytes: 27556
#include<stdio.h>

void selectionSort(int A[101],int N){
  int t,c=0,minj;

  for(int i=0;i<N;i++){
    minj=i;
    for(int j=i;j<N;j++){
      if(A[j]<A[minj]){
        minj=j;
      }
    }
    t=A[i];
    A[i]=A[minj];
    A[minj]=t;
    if(i != minj)c++;
  }
  for(int i=0;i<N;i++){
    if(i==N-1){
    printf("%d\n",A[i]);
    break;
    }
    printf("%d ",A[i]);
  }
  printf("%d\n",c);

}


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


  return 0;
}



Measured memory_bytes: 2148
#include <iostream>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std; typedef long long ll; const int MINF=-1e9; typedef pair<int,int> P;

int main() {
  string s; cin>>s; int n=s.size();
  ll an=0, lf=0;
  for(int i=0;i<n;i++) {
    if (s[i]=='W') an+=lf;
    else lf++;
  }
  cout<<an<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll n,k,q,temp;
    cin>>n>>k>>q;
    ll arr1[n+1];
    for(ll i=1;i<=n;i++)
    {
        arr1[i]=k;
    }
    for(ll i=0;i<q;i++)
    {
        cin>>temp;
        arr1[temp]++;
    }
    for(ll i=1;i<=n;i++)
    {
        if(arr1[i]<=q)
        {
            cout<<"No"<<endl;
        }
        else
        {
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1408
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
b=[[a[i][0]+a[i][1],a[i][0]-a[i][1]] for i in range(n)]
b.sort()
ans=1
tmp=b[0][0]
for i in range(n):
  if tmp<=b[i][1]:
    ans+=1
    tmp=b[i][0]
print(ans)

Measured memory_bytes: 42716
#!/usr/bin/env/ python3
#S = input()
#N = int(input())
#A, B, C = input().split()
N, M = map(int, input().split())

#N = int(input())
#A = [int(x) for x in input().split()]

#H, W = map(int, input().split())
#S = [input() for _ in range(H)]
#print(S[0][1])

ans = 0
if N > 1: ans += N * (N - 1) / 2
if M > 1: ans += M * (M - 1) / 2
print(int(ans))

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    
    String yyyy = s.substring(0,4);
    String mm = s.substring(5,7);
    String dd = s.substring(8,10);
    
    String yyyymmdd = yyyy + mm + dd;
    int ans = Integer.parseInt(yyyymmdd);
    System.out.println(ans<=20190430?"Heisei":"TBD");
  }
}

Measured memory_bytes: 20436
#include <iostream>
#include <string>
#include <ctype.h>

using namespace std;

int main(int argc, char **argv)
{
	char ch;
	int count[26] = { 0 };

	while(cin >> ch) {
		ch = tolower(ch);
		if(ch >= 'a' && ch <= 'z') count[ch - 'a']++;
	}
	for(char ch = 'a'; ch <= 'z'; ch++) cout << ch << " : " << count[ch - 'a'] << endl;

	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
int MOD = 1e9 + 7;
//二項係数nCkを前処理 O(SIZE) 、各値 O(1)で求める.
// SIZEは求めたいkの最大値
vector<long long> fact_inv01, inv01, Com01;
 
/*  init_kCi :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk01(int n, int SIZE) {
    fact_inv01.resize(SIZE + 5);  // 逆元の積
    inv01.resize(SIZE + 5);       // 逆元
    fact_inv01[0] = fact_inv01[1] = 1;
    inv01[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        inv01[i] = MOD - inv01[MOD % i] * (MOD / i) % MOD; // 正で最小のものに揃えてる
        fact_inv01[i] = fact_inv01[i - 1] * inv01[i] % MOD;
    }
    Com01.resize(SIZE + 5);       // nCk を保存
    Com01[0] = 1;
    for (int i = 1; i < SIZE + 5; i++) {
        Com01[i] = Com01[i - 1] * ((n - i + 1) * inv01[i] % MOD) % MOD;
    }
}
long long nCk01(int k) {
    assert(!(k < 0));       // kは非負でなくてはいけない
    return Com01[k];
}
//二項係数nCkを前処理 O(SIZE) 、各値 O(1)で求める.
// SIZEは求めたいkの最大値
vector<long long> fact_inv02, inv02, Com02;
 
/*  init_kCi :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk02(int n, int SIZE) {
    fact_inv02.resize(SIZE + 5);  // 逆元の積
    inv02.resize(SIZE + 5);       // 逆元
    fact_inv02[0] = fact_inv02[1] = 1;
    inv02[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        inv02[i] = MOD - inv02[MOD % i] * (MOD / i) % MOD; // 正で最小のものに揃えてる
        fact_inv02[i] = fact_inv02[i - 1] * inv02[i] % MOD;
    }
    Com02.resize(SIZE + 5);       // nCk を保存
    Com02[0] = 1;
    for (int i = 1; i < SIZE + 5; i++) {
        Com02[i] = Com02[i - 1] * ((n - i + 1) * inv02[i] % MOD) % MOD;
    }
}
long long nCk02(int k) {
    assert(!(k < 0));       // kは非負でなくてはいけない
    return Com02[k];
}



int main() {
    int n, k;
    ll ans = 0;
    cin >> n >> k;
    init_nCk01(k - 1, k - 1);
    init_nCk02(n - k + 1, k);
    for (int i = 1; i <= k; i++) {
        ans = nCk01(i - 1)*nCk02(i);
        ans %= MOD;
        cout << ans << endl;
    }
    return 0;
}



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

using namespace std;
typedef long long ll;

int main() {
    ll h, w;
    cin >> h >> w;
    ll r = h*w;
    // horizontal-first
    for(ll y=1; y<h; y++) {
        ll rest_h = h - y;
        ll p1 = y * w;
        // horizontal-second
        ll y2 = rest_h / 2;
        ll p2 = y2 * w;
        ll p3 = (rest_h-y2) * w;
        r = min(r, max({p1,p2,p3}) - min({p1,p2,p3}));
        // vertical-second
        ll x2 = w / 2;
        ll p4 = rest_h * x2;
        ll p5 = rest_h * (w - x2);
        r = min(r, max({p1, p4, p5}) - min({p1, p4, p5}));
    }
    // vertical-first
    for(ll x=1; x<w; x++) {
        ll rest_w = w - x;
        ll p1 = h * x;
        // vertical-second
        ll x2 = rest_w / 2;
        ll p2 = h * x2;
        ll p3 = h * (rest_w - x2);
        r = min(r, max({p1,p2,p3}) - min({p1,p2,p3}));
        // horizontal-second
        ll y2 = h / 2;
        ll p4 = y2 * rest_w;
        ll p5 = (h - y2) * rest_w;
        r = min(r, max({p1, p4, p5}) - min({p1, p4, p5}));
    }
    cout << r << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#define int long 
using namespace std;

int N,M;
vector<int> graph[10];

int answer = 0;
bool visited[10];
void dfs(int v,int cnt) {
	visited[v] = true;
	cnt++;
	if(cnt == N) {
		answer++;
    }
	for(int u:graph[v]) {
		if(!visited[u]) {
			dfs(u,cnt);
		}
	}
	visited[v] = false;
}

signed main() {
	cin >> N >> M;
	for(int i = 0;i < M;i++) {
		int A,B;
		cin >> A >> B;
		graph[A - 1].push_back(B - 1);
		graph[B - 1].push_back(A - 1);
    }
	dfs(0,0);
	cout << answer << endl;
}

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

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

typedef long long unsigned int ll;

int n;
string s[50];

void solve(){
  vector<char> vs;
  rep(i, s[0].size()){
    bool can = true;
    rep(j, n-1){
      char a = s[0][i];
      int index = s[j+1].find(a);
      // cout << s[j+1] << " find " << a << endl;
      if(index != -1){
        //vs.push_back(a);
        s[j+1].erase(s[j+1].begin() +  index);
        // cout << "erase:" << s[j+1] <<endl;
      }else{
        can = false;
      }
    }
    if(can){
      vs.push_back(s[0][i]);
    }
  }
  sort(vs.begin(), vs.end());
  rep(i, vs.size()){
    cout << vs.at(i);
  }
  cout << endl;
}

int main(){
  cin >> n;
  rep(i, n){
    cin >> s[i];
  }
  solve();
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int N;
    static int M;
    static int K;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        K = sc.nextInt();
        int[][] black = new int[N+1][M+1];
        int v;
        for (int i = 0; i < N + 1; i++) {
            v  = M * i;
            if (v == K) {
                System.out.println("Yes");
                return;
            }
            black[i][0] = v;
            black[i][0] = M * i;
            for (int j = 1; j < M + 1; j++) {
                v = black[i][j - 1] + N - i - i;
                if (v == K) {
                    System.out.println("Yes");
                    return;
                }
                black[i][j] = v;
            }
        }
        System.out.println("No");
        return;
    }
}

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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

map<string, int> m;


int main(){

    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<int>> choco(h + 1, vector<int>(w + 1, 0));

    rep(i, h){
        string s;
        cin >> s;
        rep(j, w){
            if(s[j] == '1') choco[i + 1][j + 1] = 1;
        }
    }

    //2次元累積和

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            choco[i][j] += choco[i][j - 1];
        }
    }

    for(int j = 1; j <= w; j++){
        for(int i = 1; i <= h; i++){
            choco[i][j] += choco[i - 1][j];
        }
    }

    /*
    for(int i = 0; i <= h; i++){
        for(int j = 0; j <= w; j++){
            cerr << choco[i][j] << " ";
        }
        cerr << endl;
    }
    cerr << endl;
    */

    //0-indexに対応した値を代入されるものとする
    function<int(int, int, int, int)> f = [&](int y1, int x1, int y2, int x2) -> int{
        return choco.at(y2 + 1).at(x2 + 1) + choco.at(y1).at(x1) - choco.at(y2 + 1).at(x1) - choco.at(y1).at(x2 + 1);
    };

    int ans = INT_MAX;
    for(int bit = 0; bit < (1<<(h - 1)); bit++){

        vector<int> starth;
        vector<int> endh;

        starth.pback(0);

        rep(i, h - 1){
            if(bit & (1<<i)){
                endh.pback(i);
                starth.pback(i + 1);
            }
        }

        endh.pback(h - 1);

        assert(starth.size() == endh.size());

        int startx = 0;
        int endx = 0;
        int tmp = __builtin_popcount(bit);

        bool impossible = false;

        while(endx < w){

            bool cut = false;

            rep(i, starth.size()){
                int count = f(starth[i], startx, endh[i], endx);

                if(startx == endx && count > k){
                    impossible = true;
                    break;
                }else if(count > k){
                    cut = true;
                    break;
                }
            }

            if(impossible) break;

            if(cut){
                tmp++;
                startx = endx;
            }else{
                endx++;
            }
        }

        if(impossible) continue;

        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long int cmb(long long int i, long long int j) {
    if(j<0) return 0;
    
    long long int ret=1;
    for(long long int x=i; x>i-j; x--) {
        ret *= x;
    }
    for(long long int x=j; x>0; x--) {
        ret /= x;
    }
    return ret;
}

int main() {
    string N;
    long long int K;
    cin >> N >> K;
    long long int pow[4]={1, 9, 9*9, 9*9*9};
    
    long long int ans=0;
    if(N.size()-1>=K) {
        ans += cmb(N.size()-1, K)*pow[K];
    }

    if(N.size()>=K) {
        ans += cmb(N.size()-1, K-1)*pow[K-1]*(N[0]-'1');
        
        if(K==1) {
            ans++;
        } else if(K==2) {
            int i=1;
            while(i<N.size() && N[i]=='0') {
                i++;
            }

            if(i>N.size()-1) {
                ;
            } else {
                ans += cmb(N.size()-1-i, K-1)*pow[K-1]+(long long int)(N[i]-'0');
            }
        } else if(K==3) {
            int i=1;
            while(i<N.size() && N[i]=='0') {
                i++;
            }
            
            if(i>N.size()-1) {
                ;
            } else {
                ans += cmb(N.size()-1-i, K-1)*pow[K-1];
                ans += cmb(N.size()-1-i, K-2)*pow[K-2]*(long long int)(N[i]-'1');

                int j=i+1;
                while(j<N.size() && N[j]=='0') {
                    j++;
                }

                if(j<=N.size()-1) {
                    ans += cmb(N.size()-1-j, K-2)*pow[K-2]+(long long int)(N[j]-'0');
                }
            }
        }
    }
    
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using psl = pair<string, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 998244353
#define all(vec) vec.begin(), vec.end()

int main(){
    int n;
    cin >> n;
    vi d(n);
    rep(i,n) cin >> d.at(i);
    if(d.at(0) != 0){
        cout << 0 << endl;
        return 0;
    }
    sort(all(d));
    if(d.at(1) == 0){
        cout << 0 << endl;
        return 0;
    }
    vi cnt(n,0);
    rep(i,n) cnt.at(d.at(i))++;
    long ans = 1;
    vl num(n,1);
    for(int i=1;i<n;i++){
        num.at(d.at(i)) *= cnt.at(d.at(i)-1);
        num.at(d.at(i)) %= MOD;
    }
    rep(i,n){
        ans *= num.at(i);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

bool comp(pll a,pll b){
    return a.S<b.S || (a.S==b.S && a.F>b.F);
}


int main(){
    ll n;
    cin>>n;
    vector<pll> a(n);
    for(int i=0;i<n;i++){cin>>a[i].F>>a[i].S;}
    sort(a.begin(),a.end(),comp);
    ll mx=0;
    ll count=0;
    for(int i=0;i<n;i++){
        if(mx<a[i].F){mx=a[i].S; count++;}
    }
    cout<<count<<endl;
    
    
    return 0;
}


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

typedef long long ll;

ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll lcm(ll a,ll b){return a*b/gcd(a, b);}


int main(){
	ll n,m;
	cin>>n>>m;
	vector<ll>a(n),b(n);
	ll LCM,GCD;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i==0)GCD=a[0]/2,LCM=a[0]/2;
		int tmp=0;
		GCD=gcd(GCD,a[i]);
		LCM=lcm(a[i]/2,LCM);
		int x=a[i];
		while(x%2==0){
			x/=2;
			tmp++;
		}
		b[i]=tmp;
	}
	sort(b.begin(),b.end());
	sort(a.begin(),a.end());
	if(b[0]!=b[n-1]){
		cout<<0<<endl;
		return 0;
	}else{
		if(!((m/LCM)%2)){
			cout<<m/LCM/2<<endl;
		}else{
			cout<<m/LCM/2+1<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1792
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def get_yakusu(n):
    ans = set()
    for i in range(1, int(math.sqrt(n)) + 2):
        if n % i == 0:
            if i != 1:
                ans.add(i)
            if n // i != i:
                ans.add(n // i)
    return ans

def main():
    N = I()
    cnt = 0
    yakusu = get_yakusu(N)
    n1yakusu = get_yakusu(N-1)
    for n in yakusu:
        cpN = N
        loop = 0
        while True:
            loop += 1
            if loop > 100:
                break
            if cpN % n == 0:
                cpN = cpN // n
            else:
                break
        if cpN % n == 1:
            cnt += 1
    cnt += len(n1yakusu)
    print(cnt)
main()



Measured memory_bytes: 65644
#include <stdio.h>

long long n;
long long h[100010];

int main(void)
{
	scanf("%lld", &n);
	
	for(long long i = 0 ; i < n ; i++)
	{
		scanf("%lld", &h[i]);
	}
	
	for(long long i = 0 ; i < n - 1 ; i++)
	{
		if(i == 0)
		{
			if(h[i] > h[i + 1])
				h[i]--;
		}
		
		else
		{
			if(h[i] - 1 < h[i - 1])
			{
				continue;
			}
			
			else
			{
				h[i]--;
			}
		}
	}
	
	int fl = 0;
	
	for(long long i = 0 ; i < n - 1 ; i++)
	{
		if(h[i] > h[i + 1])
			fl = 1;
	}
	
	if(fl == 1)
	{
		printf("No");
	}
	
	else
	{
		printf("Yes");
	}
	
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 int a,b;
 cin >> a>>b;
 if(a<b){
     cout << 0 << endl;
 }else{
     cout << 10 << endl;
 }
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;
const int MSIZE = 100000;
const double Pi = 3.14159265358979323146;

int main(){
  string s; cin >> s;
  if(s == "ABC"){
    cout << "ARC" << endl;
  }
  else{
    cout << "ABC" << endl;
  }
  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,a,b,i,j,x,y,sum,flag,flag2;
    string s;

    while(scanf("%d",&n)==1)
    {
        cin>>s;

        x = 0;
        y = 0;
        sum = 0;
        flag = 0;
        flag2 = 0;

        for(i=0;i<n;i++)
        {
            if(s[i]=='W')x++;
            else y++;

        }

        for(i=0;i<y;i++)
        {
            if(s[i]=='W')sum++;
        }

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


    }













return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
  int t=2*n, sum=0;
    
int skew[t];
    
    for(int i=0;i<t;i++)
    { cin>>skew[i];}
    
    sort(skew, skew+t);
    
    for(int i=0;i<t;i++)
    { if (i%2==0)
    { sum+=skew[i];}
    else continue;
    }
    cout<<sum;
}
    

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<set>
#include<bitset>
#include<cmath>
#include<numeric>
#include<limits>
#include<functional>
#include <bitset>

#define REP(i, m, n) for(int i = (m); i < (n); i++)
#define rep(i,n) REP(i,0,n)
#define NIL -1
using namespace std;
typedef long long ll;
typedef long long int lli;
static const int MOD = 10000007;
static const int MAX = 100005;
// static const int NMAX = 5005;

// typedef priority_queue<int, greater<int>> RevQ;
int N, K;
vector<pair<int, int>> a(MAX);



int main(){
  cin >> N;
  // int cnt = 0;
  vector<pair<int, int>> a(N);
  int b;
  rep(i,N) {
    cin >> b;
    a[i] = make_pair(b, i+1);
  }
  sort(a.begin(), a.end());
  rep(i,N) {
    cout << a[i].second << " ";
  }
  cout << endl;
}


Measured memory_bytes: 2432
while True:

    W,H=list(map(int,input().split()))
    if W==0 and H==0:
        break

    for i in range(W):
        for j in range(H):
            if i==0 or i==W-1 or j==0 or j==H-1:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


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

int main(){
int H,W;
  cin>>H>>W;
  
  char O[H+2][W+2], a[H][W];
  for(int i=0; i<H+2; i++){
   for(int j=0; j<W+2; j++){
    O[i][j]='#'; }}
  
  for(int i=0; i<H; i++){
   for(int j=0; j<W; j++){
    cin>>a[i][j];
    O[i+1][j+1]=a[i][j]; }}
  
  for(int i=0; i<H+2; i++){
   for(int j=0; j<W+2; j++){
    cout<<O[i][j];
   }
    cout<<endl;
  }
  
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	string s;
	cin >> s;
	int a = s[0] - '0';
	int b = s[1] - '0';
	int c = s[2] - '0';
	int d = s[3] - '0';

	if(a+b+c+d == 7) printf("%d+%d+%d+%d=7\n",a,b,c,d);
	else if(a+b+c-d == 7) printf("%d+%d+%d-%d=7\n",a,b,c,d);
	else if(a+b-c+d == 7) printf("%d+%d-%d+%d=7\n",a,b,c,d);
	else if(a+b-c-d == 7) printf("%d+%d-%d-%d=7\n",a,b,c,d);
	else if(a-b+c+d == 7) printf("%d-%d+%d+%d=7\n",a,b,c,d);
	else if(a-b+c-d == 7) printf("%d-%d+%d-%d=7\n",a,b,c,d);
	else if(a-b-c+d == 7) printf("%d-%d-%d+%d=7\n",a,b,c,d);
	else if(a-b-c-d == 7) printf("%d-%d-%d-%d=7\n",a,b,c,d);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long x = sc.nextLong();
		long ans = 1;
		if(a==1){
			System.out.println(x);
			return;
		}
		for(long i = 2; Math.pow(i,a)<=x; i++){
			double c = Math.pow(i,a);
			if(x%c==0){
				ans = Math.max(ans,i);
			}
		}
		
			System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define END getchar();getchar();return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000007
typedef pair<int, int> P;

signed main() {
	int h, w, cnt = 0, bfs[100][100];
	int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
	char s[100][100];
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> s[i][j];
			if (s[i][j] == '.') {
				cnt++;
			}
		}
	}
	memset(bfs, -1, sizeof(bfs));
	queue<P>que;
	que.push(P(1, 1));
	bfs[1][1] = 0;
	while (que.size()) {
		P p = que.front();
		que.pop();
		if (p.first == h && p.second == w) break;
		for (int i = 0; i < 4; i++) {
			int ny = p.first + dy[i], nx = p.second + dx[i];
			if (bfs[ny][nx] == -1 && s[ny][nx] == '.') {
				que.push(P(ny, nx));
				bfs[ny][nx] = bfs[p.first][p.second] + 1;
			}
		}
	}
	if (bfs[h][w]==-1){
		cout << -1 << endl;
	}
	else {
		cout << cnt - bfs[h][w] - 1 << endl;
	}

	END;
}


Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;


int main(void){
  
  long long K,A,B;
  string ans = "NG";


  cin >> K >> A >> B;

  for(int i = A; i <= B; i++){
    if(i%K == 0){
      ans ="OK";
      break;
    }
  }
 
  cout << ans << endl;

  return 0;
}




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

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, u, v):
        ru = self.root(u)
        rv = self.root(v)
        if self.rank[ru] < self.rank[rv]:
            self.par[ru] = rv
        else:
            self.par[rv] = ru
            if self.rank[ru] == self.rank[rv]:
                self.rank[ru] += 1

    def same(self, u, v):
        return self.root(u) == self.root(v)


u_road = UnionFind(N)
u_train = UnionFind(N)

for i in range(K):
    p, q = map(int, input().split())
    u_road.unite(p, q)
for i in range(L):
    r, s = map(int, input().split())
    u_train.unite(r, s)

mem = [set() for _ in range(N)]
mem_dict = dict()
for i in range(N):
    a = (u_road.root(i+1), u_train.root(i+1))
    mem[i] = a
    if a in mem_dict:
        mem_dict[a] += 1
    else:
        mem_dict[a] = 1

for i in range(N):
    print(mem_dict[mem[i]], end=' ')

print()


Measured memory_bytes: 126364
from sys import exit
from collections import deque

n, m = map(int,input().split())
a = deque(int(input()) for i in range(m))

if len(a) != 0:
    base = a.popleft()
else:
    base = -1

p = 10 ** 9 + 7

dp = [1] * (n+1)

if base == 0:
    print(0)
    exit()

for i in range(1, n+1):
    if base == i:
        dp[i] = 0
        if len(a) != 0:
            base = a.popleft()
        continue
    if i == 1:
        dp[i] = 1
    else:
        dp[i] = (dp[i-2] + dp[i-1]) % p
    if dp[i] == 0:
        print(0)
        exit()

print(dp[n])

Measured memory_bytes: 8052
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

r = float(input())

area = r*r*math.pi
len = 2*r*math.pi

print("{:.5f}".format(area), "{:.5f}".format(len))





Measured memory_bytes: 6860
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


string ans = "Yes";
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((a*b) % 2 == 1 && (c + d) % 2 == 1) { ans = "No"; }
	cout << ans << endl;
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

void solve()
{
    int n,m;
    cin>>n>>m;

    vector<int> a(m);
    int sum = 0;
    rep(i,0,a.size())
    {
        cin>>a[i];
        sum += a[i];
    }

    sum = n-sum;

    if ( sum < 0 )
    {
        cout<<"-1"<<endl;
    }
    else
    {
        cout<<sum<<endl;
    }
    
}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

    while( !q.empty() )
    {
        int p = q.front();
        q.pop();

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

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

using namespace std;

int main()
{
    unsigned long long h, a;
    cin >> h >> a;
    unsigned long long m[200100];
    for (int i = 0; i < h; i++)
    {
        cin >> m[i];
    }
    sort(m, m + h);
    reverse(m, m + h);
    for (int i = 0; i < a ; i++)
    {
        m[i] = 0;
    }
    for (int i = 1; i < h; i++)
    {
        m[i] += m[i - 1];
    }
    cout << m[h - 1];
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N);
  rep(i,0,N) cin >> A[i];
  A.push_back(0);
  rev(i,N,0) A[i] += A[i + 1];
  i64 ans = 1e18;
  rep(i,1,N) {
    i64 left = A[0] - A[i];
    i64 right = A[i] - A[N];
    ans = min(ans, abs(left - right));
  }
  cout << ans << endl;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI (acos(-1))
#define _GLIBCXX_DEBUG

int main(){
  
  int n;
  cin >> n;

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

  sort(v.begin(), v.end(), greater<int>());

  int a = 0, b = 0;
  rep(i, n){
    if (i % 2 == 0) a += v[i];
    else b += v[i];
  }

  cout << a - b << endl;

}

Measured memory_bytes: 256
import bisect
n,m,v,p = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
wa = [a[0]]
for i in range(1,n):
    wa.append( wa[i-1] + a[i] )
border = a[n-p]
j = bisect.bisect_right(a,border)
for i in range(n):
    if a[i] + m >= border:
        if n-j+i+1 >= v:
            print(n-i)
            break
        else:
            if (j-i-1)*(a[i]+m)-(wa[j-1]-wa[i]) >= (v-(n-j+i+1))*m:
                print(n-i)
                break


Measured memory_bytes: 14964
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        ArrayList<Integer> input = new ArrayList<Integer>();
        
        for (int i = 0; i < 5; i++) {
            input.add(scanner.nextInt());
        }
        Collections.sort(input);
        
        for (int i = input.size()-1; i > 0; i--) {
            System.out.print(input.get(i) + " ");
        }
        System.out.println(input.get(0));
    }    
    
}

Measured memory_bytes: 17172
n, m = [int(i) for i in input().split()]
x = sorted([int(j) for j in input().split()])

distance = list()
for i in range(1, m):
    distance.append(x[i] - x[i-1])

distance = sorted(distance, reverse=True)
moved = 0
for j in range(n-1, len(distance)):
    moved = moved + distance[j]

print(moved)


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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if ((10 * b + c) % 4 == 0) printf("YES\n");
  else printf("NO\n");
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int N, T, A; cin >> N >> T >> A;
    Int res;
    Int minDiff = LLONG_MAX;
    rep(i, 0, N) {
        Int H; cin >> H;
        Int diff = abs(A*1000 - (T*1000 - H*6));
        if (diff < minDiff) {
            res = i+1;
            minDiff = diff;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
n = gets.to_i
arr = []
n.times {arr.push(gets.chomp)}

ansArr = []
arr.each do |cmd|
    # p ansArr
    if cmd[0,6] == "insert" then
        x = cmd.split(' ')[1]
        ansArr.unshift(x)
    elsif cmd[0,7] == "delete " then
        x = cmd.split(' ')[1]
        ansArr.delete_at(ansArr.find_index(x)) if ansArr.find_index(x) != nil
    elsif cmd == "deleteFirst" then
        ansArr.shift
    elsif cmd == "deleteLast" then
        ansArr.pop
    else
        puts "did not match any condition..."
    end
end

puts ansArr.join(' ')



Measured memory_bytes: 228420