akhauriyash/Code-Regression huggingface dataset:
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0))

def bfs(sy, sx):
    q = deque([[sy, sx]])
    dist = [[float('inf')]*w for _ in range(h)]
    dist[sy][sx] = 0 

    while q:
        y, x = q.popleft()
        for dy, dx in moves:
            ny = y + dy 
            nx = x + dx 
            if 0 <= ny < h and 0 <= nx < w and dist[ny][nx] == float('inf') and s[ny][nx] != '#':
                dist[ny][nx] = dist[y][x] + 1 
                q += [[ny, nx]]

    return dist 

d = bfs(0, 0)[h-1][w-1]
if d == float('inf'):
    print(-1)
    exit()
block = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            block += 1
print(h*w-d-block-1)

Measured memory_bytes: 40816
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;



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

	int A, B, C;
	cin >> A >> B >> C;

	if (A == B) {
		if (B == C) cout << "No" << endl;
		else cout << "Yes" << endl;
	}
	else if (A == C) {
		if (B == C) cout << "No" << endl;
		else cout << "Yes" << endl;
	}
	else if (B == C) {
		if (A == C) cout << "No" << endl;
		else cout << "Yes" << endl;
	}
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	char a[10];
	char b[10]; 
	scanf("%s %s",a,b); 
	int flag = 0 ;
	for(int i = 0 ; i < 3 ; i++){
		if(a[i] != b[2 - i])
			flag = 1; 
	}
	flag ? puts("NO"):puts("YES");
	return 0;
} 

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,l,r,maxl=0,minr=100001;
int main(){
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=m;i++){
		scanf("%d%d",&l,&r);
		maxl=max(maxl,l);
		minr=min(minr,r);
	}
	printf("%d",max(0,minr-maxl+1));
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <cmath>
#include <climits>
#include <unordered_map>

using namespace std;

#define size_t int

int main(int argc, char const *argv[]) {
  long N, P;
  scanf("%ld %ld", &N, &P);
  long k = (long)(pow(P, 1.0/N)+2.0);
  for (long i = k; i >= 0; i--) {
    if (P % (long)pow(i, N) == 0) {
      printf("%ld\n", i);
      return 0;
    }
  }
}


Measured memory_bytes: 384
INF = 10 ** 20

while True:
  n, m = map(int, input().split())
  if not n:
    break

  chairs = list("#" * n)

  def sit(s):
    if s == "A":
      chairs[chairs.index("#")] = "A"
    
    elif s == "B":
      for i in range(n - 1, -1, -1):
        if chairs[i] == "#" and (i == 0 or chairs[i - 1] != "A") and (i == n - 1 or chairs[i + 1] != "A"):
          chairs[i] = "B"
          break
      else:
        chairs[chairs.index("#")] = "B"

    elif s == "C":
      for i in range(n):
        if chairs[i] != "#":
          if i + 1 <= n - 1 and chairs[i + 1] == "#":
            chairs[i + 1] = "C"
            break
 
          elif i - 1  >= 0 and chairs[i - 1] == "#":
            chairs[i - 1] = "C"
            break

    else:
      score = [INF for _ in range(n)]
      dist = INF
      for i in range(n):
        if chairs[i] == "#":
          dist += 1
        else:
          dist = 0
        score[i] = dist

      dist = INF
      for i in range(n - 1, -1, -1):
        if chairs[i] == "#":
          dist += 1
        else:
          dist = 0
        score[i] = min(score[i], dist)
      high_score = max(score)

      chairs[score.index(high_score)] = "D"
  
  first = input()
  if first in ["A", "D"]:
    chairs[0] = first
  elif first == "B":
    chairs[-1] = "B"
  else:
    chairs[n // 2] = "C"
  
  for _ in range(m - 1):
    sit(input())
  print("".join(chairs))



Measured memory_bytes: 5608
#include <stdio.h>
#include <math.h>
int PrimeJudge(int);
#define N 10000
int main(){
  int i,n,flg,prime=0,num[N];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&num[i]);
    flg=PrimeJudge(num[i]);
    if(flg==0) prime++;
  }
  printf("%d\n",prime);
  return 0;
}
int PrimeJudge(int data){
  int i=3;
  if(data==2) return 0;
  if(data<2 || data%2==0) return -1;
  while(i<=sqrt(data)){
    if(data%i==0) return -1;
    i=i+2;
  }
  return 0;
}

Measured memory_bytes: 628
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int gcd(int a, int b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}//GCD

int main(){
    int n,k;
    cin >> n>> k;
    vec a(n);
    int temp=0;
    int m_temp=0;
    rep(i,n){
        cin >> a[i];
        if(i>=1){
            temp=gcd(temp,a[i]); 
        }else{
            temp=a[i];
        }
        if(m_temp<a[i]){
            m_temp=a[i];
        }
    }
    cerr<<m_temp<<' '<<temp<<endl;
    if(k<=m_temp&&k%temp==0){
        cout<<"POSSIBLE"<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}

Measured memory_bytes: 4024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

int main(){
  ll M,K;
  cin >> M >> K;
  ll mpow=1;
  mpow=mpow<<M;
  if(M==1){
    if(K==0) cout<<"1 1 0 0"<<endl;
    else cout<<-1<<endl;
  }
  else if(K>=mpow){
    cout<<-1<<endl;
  }else{
    rep(i,mpow) if(i!=K) cout<<i<<" ";
    cout<<K<<" ";
    rrep(i,mpow) if(i!=K) cout<<i<<" ";
    cout<<K<<endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
typedef pair<int,int> pii;
typedef long long ll;	

ll n,arr[105],sum;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


	cin >> n;
	for (int i=0;i<n;i++){
		cin >> arr[i];
	}
	for (int i=0;i<n;i++){
		for (int j=i+1;j<n;j++){
			for (int k=j+1;k<n;k++){
				if (arr[i] != arr[j] && arr[i] != arr[k] && arr[j] != arr[k]){
					if (arr[i] + arr[j] > arr[k] && arr[j] + arr[k] > arr[i] && arr[k] + arr[i] > arr[j]){
	//					cout << arr[i] << " "  << arr[j] << " " << arr[k] <<"\n";
						sum++;
					}
				}
			}
		}
	}
	cout << sum << "\n";
	
	return 0;
}

Measured memory_bytes: 3640
#include <set>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    string S; int n;
    
    set<string> T;
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++)
    {
        cin >> S;
        
        if(i % 20 == 0 || i % 20 == 1 || i % 20 == 2 || i == 23)
        {
            printf("1\n");
        }
        else if(i % 20 == 3)
        {
            printf("2\n");
        }
        else if(i % 20 == 4)
        {
            printf("72\n");
        }
        else if(i % 20 == 5)
        {
            printf("420\n");
        }
        else if(i % 20 == 6)
        {
            printf("%d\n", 396 + (i / 20) % 5 * 4 + i / 100 * 4);
        }
        else
        {
            T.clear();
            
            for(int j = 1; j < S.size(); j++)
            {
                string A = S.substr(0, j);
                string B = S.substr(j, S.size() - j);
                
                string C = A; reverse(C.begin(), C.end());
                string D = B; reverse(D.begin(), D.end());
                
                T.insert(A + B);
                T.insert(B + A);
                T.insert(A + D);
                T.insert(D + A);
                T.insert(C + B);
                T.insert(B + C);
                T.insert(C + D);
                T.insert(D + C);
            }
            
            printf("%d\n", T.size());
        }
    }
    
    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

vector<pair<ll, ll>> prime_factorize(ll n) {
	vector<pair<ll, ll>> res;

	for (ll p = 2; p * p <= n; ++p) {
		if (n % p != 0) continue;

		int num = 0;
		while (n % p == 0) num++, n /= p;
		res.push_back({ p, num });
	}

	if (n != 1) res.push_back({ n, 1 });
	
	return res;
}

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

	auto pf = prime_factorize(n);
	ll res = 0;

	for (auto p : pf) {
		ll e = p.second;
		ll tmp = 0, cur = 1;
		while (e >= cur) e -= cur++, tmp++;
		res += tmp;
	}
	cout << res << endl;
}

Measured memory_bytes: 3600
n, m = map(int, input().split())
A = list(list(map(int, input().split())) for _ in range(n))
b = list(int(input()) for _ in range(m))

for i in range(n):
    ans = 0
    for j in range(m):
        ans += A[i][j] * b[j]
    print(ans)


Measured memory_bytes: 6016
/*
 * Author : Sadi
 * Wed 08/07/2020
 * 20:15:18.86
 */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

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

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int k, x;
    cin >> k >> x;
    for(int i = x - k + 1; i <= x + k - 1; ++i) {
    	cout << i << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
int a[maxn];
long long pre[maxn];
int main(){
    int n;
    cin>>n;
    for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    memset(pre, 0, sizeof(pre));
    long long tot = 0;
    for(int i = 1; i <= n; ++i){
        pre[i] = pre[i - 1] + 1LL * a[i];
        tot += a[i];
    }
    long long ans = 1e17;
    if(n == 2){
        cout<<abs(a[1] - a[2])<<endl;
    }
    else{
        for(int i = 1; i < n; ++i){
            ans = min(ans, abs(pre[i] - (tot - pre[i])));
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
int main()
{
	char a[Max];
	scanf("%s",a);
	int len=strlen(a);
	printf("%c%d%c",a[0],len-2,a[len-1]);
    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    string s;
    int q;
    cin >> s >> q;

    int n = s.size();
    deque<char> deq;
    REP(i, n){
        deq.push_back(s[i]);
    }

    bool rev = false;

    REP(i, q){
        int t;
        cin >> t;
        if(t == 1){
            rev = !rev;
        }else{
            int f;
            char c;
            cin >> f >> c;
            f--;
            if(f ^ rev){
                deq.push_back(c);
            }else{
                deq.push_front(c);
            }
        }
    }

    if(rev){
        RREP(i, deq.size()){
            cout << deq[i];
        }
    }else{
        REP(i, deq.size()){
            cout << deq[i];
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 896
// AtCoder Begineer Contest 127

#include <iostream>
#include <vector>

using namespace std;

int main(){
    int r, D, X_2000;
    vector<int> X;
    cin >> r >> D >> X_2000;

    X.push_back(X_2000);
    for(int j = 0; j < 10; j++ ){
        X.push_back(r*X[j] - D);
    }

    for (int k = 1; k<11; k++) cout << X[k] << endl;

}


Measured memory_bytes: 256
/*
ID: seekho
PROG: friday
LANG: C++14                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
const int N = 100005;

int memo[N];
vector<int> g[N];
int vis[N];
int mx = 0;

void dfs(int v) {
	if(vis[v]) return;
	vis[v] = 1;

	int mx1 = -1, mx2 = -1;
	for(auto u : g[v]) {
		if(!vis[u]) 
			dfs(u);
		
		// if(mx1 < memo[u]) {
		// 	swap(mx2, mx1);
		// 	mx1 = memo[u];
		// }
		// else if(memo[u] > mx2) mx2 = memo[u];
		mx1 = max(mx1, memo[u]);
	}

	mx = max(mx, mx1 + 1);	
	memo[v] = mx1 + 1;
	return;
}

int32_t main() {

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

    int n,m;
    cin >> n >> m;

    int x,y;
    rep(i,m) {
    	cin >> x >> y;
    	g[x].pb(y);
    } 
    repA(i,1,n)
    	dfs(i);
    cout << mx << '\n';
}

Measured memory_bytes: 9344
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)


def lcm(a, b):
    return a * b // gcd(a, b)


N = int(input())

ret = 1

for _ in range(N):
    ret = lcm(ret, int(input()))

print(ret)


Measured memory_bytes: 2940
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	xm := make(map[int]int)
	for i := 2; i <= n; i++ {
		x := i
		for j := 2; j <= i; j++ {
			for x%j == 0 {
				xm[j]++
				x /= j
			}
		}
	}

	const mod = 1000000007
	ans := 1
	for _, v := range xm {
		ans *= v + 1
		ans %= mod
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
h,w=map(int,input().split())
list=[]
for i in range(h):
    a=input()
    if "#" in a:
        list.append(a)
h=len(list)
d=[0]*w
for i in range(h):
    for j in range(w):
        if list[i][j]=="#":
            d[j]=1
for i in range(h):
    ans=""
    for j in range(w):
        ans+=list[i][j]*d[j]
    print(ans)

Measured memory_bytes: 9136
import sys
from itertools import permutations as perm
from bisect import bisect_left as bisect
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


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


def gcd(a, b):
    # greatest common divisor
    while b > 0:
        a, b = b, a % b

    return a


def solve():
    def get_ans(c1, c2, c3):
        ret = 0
        lenc3 = len(RGB[c3])
        for c1i in range(len(RGB[c1])):
            tmp = bisect(RGB[c2], RGB[c1][c1i])
            for c2i in range(tmp, len(RGB[c2])):
                c3i = bisect(RGB[c3], RGB[c2][c2i])
                if lenc3 == c3i:
                    continue
                # print(c1i, c2i, c3i)
                c21d = RGB[c2][c2i] - RGB[c1][c1i]
                t = bisect(RGB[c3], RGB[c2][c2i] + c21d, c3i)

                if lenc3 != t and RGB[c3][t] - RGB[c2][c2i] == c21d:
                    ret += lenc3 - c3i - 1
                else:
                    ret += lenc3 - c3i

        return ret
    int(input())
    S = list(input().strip())
    RGB = {k: [] for k in "RGB"}
    for i, s in enumerate(S):
        RGB[s].append(i)

    ans = 0
    # print(RGB)
    for c1, c2, c3 in perm(list("RGB")):
        # print(c1, c2, c3)
        ans += get_ans(c1, c2, c3)
        # print(ans)
    print(ans)


solve()


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

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

n, m = readmi()
t = readt()
h = []
for i in t:
    a = i * (-1)
    heapq.heappush(h, a)
for i in range(m):
    t = heapq.heappop(h)
    t *= -1
    t //= 2
    t *= -1
    heapq.heappush(h, t)
s = 0
for i in h:
    s += i * (-1)
print(s)

Measured memory_bytes: 16780
// 入力とかに使うもの
var reader = require('readline').createInterface({ input: process.stdin, output: process.stdout });
var lines = [];
reader.on('line', function (line) { lines.push(line); });

// メイン
reader.on('close', function () {
	var a = lines[0].split(" ");
	var b = "";
	for(var c in a) b = b + a[c].slice(0,1);
	console.log(b);
});

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

#define ll long long
#define ar array
#define ld long double
#define endl "\n"
#define fori(i,k,n) for(int i = k;i<n; i++)
const int mxN=1e3;
ll w, h, l, u, r, d;

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

int main(){
    fastio();
    int n,m;
    cin>>n>>m;
    vector<int> a(m);
    int sum = 0;
    fori(i,0,m)cin>>a[i],sum+=a[i];
    if(sum>n)cout<<-1<<endl;
    else cout<<n-sum<<endl;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
#define fr(n) for(ll i=0;i<n;i++)
using namespace std;
using ll = long long;
int main()
{
ll n;
ll b[150],flag[150];
vector<char> v;
memset(b,0,sizeof(b));
memset(flag,0,sizeof(flag));
string s;
cin>>n>>s;
for(ll i=0;i<n;i++)
{
	b[(int)s[i]]++;
}
for(ll i=0;i<n;i++)
{
if(b[(int)s[i]]>1)
{
v.push_back(s[i]);
}
}
ll c=0,max=0;
fr(v.size())
{
	if(b[(int)v[i]]>1 && flag[(int)v[i]]==0)
	{
	b[(int)v[i]]--;
	flag[(int)v[i]]=1;
	c++;
	}
	else if(b[(int)v[i]]==1)
	c--;
	else
	b[(int)v[i]]--;
	if(c>max)
	max=c;
	//cout<<c<<"\n";
}
cout<<max;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
double h1,s1,h2,s2;
cin>>h1>>s1>>h2>>s2;

if(ceil(h2/s1) <= ceil(h1/s2))
    cout<<"Yes";
else
    cout<<"No";
}

Measured memory_bytes: 3688
/*
  Author - KISHAN TIWARI
  Dream bigger. Do bigger.
  Wake up with determination. Go to bed with satisfaction.
*/
//Sometimes later becomes never. Do it now.
#include<bits/stdc++.h>
using namespace std;
#define ll           long long
#define f(i,a,b)     for(ll i=a;i<b;i++)
#define mod          1000000007
#define fi           first
#define se           second
#define pa           pair <ll,ll>
#define mp           make_pair
#define pb           push_back
#define ve           vector<ll>
#define vep          vector< pa >
#define all(a)       a.begin(), a.end()
#define sz(x)        (ll)x.size()
#define c(t)         cout<<t<<"\n"
using namespace std;
void solve()
{  ll n;
cin>>n;
ll x=n*(n-1)/2;
c(x);
}
int main()
{
    ios::sync_with_stdio(true);
   //freopen ("input.txt","r",stdin);
   //freopen ("output.txt","w",stdout);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {

        solve();
    }
return 0;
}


Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 06.07.2020 09:38:22       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, y;
  cin >> x >> y;
  int ans = 0;
  if (x <= 3) {
    ans += (4 - x) * 100000;
  }
  if (y <= 3) {
    ans += (4 - y) * 100000;
  }
  if (x == 1 && y == 1) {
    ans += 400000;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define pp(a, b) pair <a, b>
#define ll long long
#define ld long double
#define all(a) a.begin(), a.end()
#define pi pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define itr iterator
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
#define int ll
#define endl "\n"
 
using namespace __gnu_pbds;
using namespace std;
 
template <class T> T printr(T p) { cout << p << '\n'; return 0; }
template <class T> T printe(T p) { cout << p << '\n'; exit(0); }
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif
 
ll power(ll x, ll y, ll p){ 
   ll res = 1;
   x = x % p;  
   while (y > 0) {
      if (y & 1) 
         res = (res * x) % p; 
      y = y >> 1;
      x = (x * x) % p; 
   }
   return res;
}
 
const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;
 
const int M = 1e12;

int32_t main()
{
    IOS;
    #ifndef ONLINe5E_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif

    int n, k;
    cin >> n >> k;

    int a[n];
    fori(n) cin >> a[i];

    int dp[n];
    dp[0] = 0;

    fori(n) {
        if(i==0)continue;
        else {
            dp[i] = LONG_LONG_MAX;
            for(int j = 1; j <= k && i-j >= 0; j++){
                dp[i] = min(dp[i], dp[i-j] + abs(a[i]-a[i-j]) );
            }
        }
    }

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

    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}

//g++ -DLOCAL -DDEBUG -std=c++17 -Wshadow -Wall -o "c" "icpc.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g

Measured memory_bytes: 1792
# ABC 061 D
# 有向グラフ各辺のコストを集めて最大化する問題だが、全部符号を変えれば最短経路問題にできる

from math import isinf


class Edge(object):

    def __init__(self, src, dst, cost):
        self.src = src
        self.dst = dst
        self.cost = cost


class BellmanFord(object):

    def __init__(self, v_len, edges, start):
        """
        隣接行列を使っていないので、有向グラフにのみ適用可能。
        ベルマンフォード法によって最短経路を求める。
        ダイクストラと違って負の数も扱えるが、O(|V||E|) なのでダイクストラより遅い。

        :param v_len: グラフのノード数 通常は|V|、1-indexedなグラフなら |V| + 1
        :param edges: 辺のリスト
        :param start: 始点 単一視点最短経路問題として解くので必要
        """
        self._dist = [float('inf') for _ in range(v_len)]  # 始点から各頂点までの最短距離
        self._prev = [float('inf') for _ in range(v_len)]  # 最短経路における，その頂点の前の頂点のIDを格納する

        self._solve(edges, start)

    def _solve(self, edges, start):
        self._dist[start] = 0

        cnt = 0
        while True:  # 更新は高々 |V| - 1 回で終わる
            cnt += 1
            updated = False
            for e in edges:
                if self._dist[e.src] + e.cost < self._dist[e.dst]:
                    self._dist[e.dst] = self._dist[e.src] + e.cost
                    self._prev[e.dst] = e.src
                    if cnt >= len(self._dist):
                        self._dist[e.dst] = float('-inf')
                    updated = True
            if not updated:
                break

    def distance(self, goal):
        """
        負の閉路を含む場合は -inf を返す。
        """
        return self._dist[goal]

    def path(self, goal):
        """
        負の閉路を含む場合は計算が終わらない。
        """
        path = list()
        path.append(goal)
        cursor = goal

        while not isinf(self._prev[cursor]):
            path.append(self._prev[cursor])
            cursor = self._prev[cursor]

        return list(reversed(path))


N, M = map(int, input().split())
edges = list()
for _ in range(M):
    a, b, c = map(int, input().split())
    edges.append(Edge(a, b, -1 * c))
bf = BellmanFord(N + 1, edges, 1)
print(-1 * bf.distance(N))


Measured memory_bytes: 3568
# AOJ 0608: Water Rate
# Python3 2018.7.2 bal4u

import sys
from sys import stdin
input = stdin.readline

a, b, c, d, p = [int(input()) for i in range(5)]
pa, pb = p*a, b
if p > c: pb += (p-c)*d
print(min(pa, pb))


Measured memory_bytes: 5604
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main() {
    int n;
    cin >> n;
    FOR(i, 1, 50000) {
        if ((int) (i * 1.08) == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define TASK "file"

#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long i64;
typedef long double dbl;
const dbl PI = acos(-1.0L);
const dbl EPS = 1e-12L;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

namespace task {
string s;

int main() {
  cin >> s;
  cout << string(s.size(), 'x') << '\n';
  return 0;
}
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(11);
  cout.setf(ios::fixed);
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#elif defined(TASK)
  freopen(TASK".in", "r", stdin);
  freopen(TASK".out", "w", stdout);
#endif
  return task::main();
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include<string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n; string s; cin >> n >> s;
    vector<int> w(n+1,0), e(n+1,0);
    for(int i = 0; i<n; ++i){
        w[i+1] = w[i] + (s[i] == 'W');
        e[i+1] = e[i] + (s[i] == 'E');
    }
    int ans = e[n] - e[1];
    for(int i = 1; i<n; ++i){
        int tmp_ans = w[i] + e[n] - e[i+1];
        if(tmp_ans < ans)ans = tmp_ans;
    }
    cout << ans << endl; return 0;
}

Measured memory_bytes: 3076
/*
	*#*#*#* Author GaryMr *#*#*#*
########################################################################
	是否可以简化问题：
	抓住数据范围哪里小
	dfs or bfs
	是否可以化具体为抽象
	字符串问题是否可以用数学模拟递归过程（取c[i]或不取来算结果）
	二分？左闭右开？
	long long？
	逆向思维？
	dp？
	贪心？
	树的直径:随便找一点再走到它最远的点A，再从A最远的点走到最远B的点。AB就是树的直径
	匹配括号 左减右>=0
	多组数据清空？
	dp优化用g？
	线段树：大小为n的8倍
	线段树：左闭右开！
	线段树：find： if(l>=b||r<=a) return 0x3f3f3f3f; if(r<=b&&l>=a) return tree[k];
	线段树：满二叉树 
	循环跳出条件 
	代数设出每个值寻找关系？
	优先队列：priority_queue<类型> q;   
	priority_queue<类,vector<类>, less<类> > pq1; 　　　 // 使用递减	
	priority_queue<类，vector<类>, greater<类> > pq2; 　　// 使用递增
	判断括号，判断是否长度为偶数
	1<<ceil(log2(double(n)))
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;a++)
#define rl(a,b,c) for(int a=b;a>=c;a--)
#define niv vector<int>
#define LL long long
#define IT iterator
#define FIR first
#define SEC second
using namespace std;
const int MAX=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
struct newtype{
	double head;
	double tail;
}each_coin[3000];
double dp[3000][3000];
int main(){
	int n;scanf("%d",&n);
	rb(i,1,n){
		double pi;cin>>pi;
		each_coin[i].head=pi;
		each_coin[i].tail=1-pi;
	}
	dp[1][0]=each_coin[1].head;
	dp[1][1]=each_coin[1].tail;
	rb(i,2,n){
		rb(j,0,i){
			dp[i][j]=dp[i-1][j]*each_coin[i].head+dp[i-1][j-1]*each_coin[i].tail;
		}
	}
	double final=0;
	for(int i=0;(n-i)>i;i++){
		final+=dp[n][i];
	}
	printf("%.16lf",final);
	return 0;
}

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

const int kmod = 1000000007;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;

    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % kmod;
        inv[i] = kmod - inv[kmod % i] * (kmod / i) % kmod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % kmod;
    }
}

long long comb(int n, int k)
{
    if (n < k) {
        return 0;
    }
    if (n < 0 || k < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[k] * fact_inv[n - k] % kmod) % kmod;
}

int main()
{
    init_comb();
    int h, w, a, b;
    std::cin >> h >> w >> a >> b;

    long long ans = 0;
    for (int i = b; i < w; i++) {
        ans += comb(h - a - 1 + i, i) * comb(a - 1 + (w - 1 - i), a - 1);
        ans %= kmod;
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int s;
  cin >> s;
  int up = s/100;
  int down = s%100;
  bool a = (up>0)&&(up<=12);
  bool b = (down>0)&&(down<=12);
  if(a&b){
    cout << "AMBIGUOUS" << endl;
  }else if(a){
    cout << "MMYY" << endl;
  }else if(b){
    cout << "YYMM" << endl;
  }else{
    cout << "NA" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
vector<int> A(4) ;
rep(i,4) cin >> A[i] ;
int ans = 0 ;
if(A[0] > A[1] ) ans += A[1] ;
else ans +=  A[0] ;
if( A[2] > A[3] ) ans += A[3] ;
else ans += A[2] ;
cout << ans  << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005
using namespace std;
const int mod = 1e9+7;
int n;
char a;
int p = 0;
int lst[100000];
long long rez=1;
int main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    for(int i = 1 ;i <= n; i++){
        cin >> a;
        lst[a]++;
    }
    for(char i = 'a' ; i <= 'z' ; i++){
        rez = (rez*(lst[i]+1))%mod;
    }
    rez = (rez + mod - 1)%mod;
    cout << rez;
}



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

#include <vector>
#include <string>
int main(){
    int h,w,k; cin >> h >> w >> k;
    vector<vector<int>> date(h,vector<int>(w));
    for(int i=0; i<h; i++){
        string str; cin >> str;
        for(int j=0; j<w; j++){
            if(str[j]=='.'){
                date[i][j] = 0;
            } else date[i][j] = 1;
        }
    }
    int ans = 0;
    for(int i=0; i<(1<<h); i++){
        for(int j=0; j < (1<<w); j++){
            int total=0;
            for(int x=0; x<h; x++){
                if((i>>x)&1)continue;
                for(int y=0; y<w; y++){
                    if(!((j>>y)&1)) total += date[x][y];
                }
            }
            if(total==k)ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <map>
#include <algorithm>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::map<std::string, int> freq;
	std::cin >> n;
	long long ans = 0;
	while(n--) {
		std::string str;
		std::cin >> str;
		std::sort(str.begin(), str.end());
		ans += freq[str]++;
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.14159265358979
#define EPS 1e-8
#define mod 1000000007
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define endl "\n"
	 
const ll INF=(ll)2e18;
		
		
		
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
				
	ll n,k;
	cin>>n>>k;
	
	vector<ll> v(n+1);
	
	for(ll i=1;i<=n;i++)
	{
		cin>>v[i];
		v[i]--;
	}
	vector<ll> pref(n+1,0);
	
	for(ll i=1;i<=n;i++)
	{
		pref[i]=pref[i-1];
		pref[i]+=v[i];
		pref[i]%=k;
		
	}
	
	map<ll,ll> rem;
	ll ans=0;
	for(ll i=0;i<min(k,n+1);i++)
	{
		ans+=rem[pref[i]];
		rem[pref[i]]++;
	}
	
	for(ll i=k;i<=n;i++)
	{
		rem[pref[i-k]]--;
		ans+=rem[pref[i]];
		rem[pref[i]]++;
	}
	cout<<ans;
}


Measured memory_bytes: 15872
// JAI SHREE RAM
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for(int i=0;i<n;i++)
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define sec second
#define fir first
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
// #define all(a) (a).begin(),(a).end()
#define vec vector<int>
#define M_PI           3.14159265358979323846  /* pi */
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast
	ll x;
	cin >> x;
	bool flag = false;
	ll i,j;
	for ( i = -250; i < 250; i++)
	{
		for ( j = -250; j < 250; j++)
		{
			if(i*i*i*i*i-j*j*j*j*j==x)
				{
					flag=true;
					goto end;
				}
		}
	}
	end:
	if(flag)
	cout << i<<" "<<j << endl;

	return 0;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  vll S('z' - 'a' + 1, kMax);
  REP(i, 0, N) {
    string s;
    cin >> s;
    vll v('z' - 'a' + 1, 0);
    REP(j, 0, s.size()) {
      v[s[j] - 'a']++;
    }
    REP(j, 0, S.size()) {
      S[j] = min(S[j], v[j]);
    }
  }

  REP(i, 0, S.size()) {
    if (S[i] > 0) {
      REP(j, 0, S[i]) {
        cout << char('a' + i);
      }
    }
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=(1<<18)+10;
int n,k,s,t,m;
vector<int> a;
ll C[55][55],ways[55];
ll cnt[maxn];
void solve()
{
	for(int i=0;i<m;i++)
	{
		for(int msk=0;msk<(1<<m);msk++)
		{
			if(!(msk>>i&1))
			{
				cnt[msk^(1<<i)]+=cnt[msk];
			}
		}
	}
}
int main()
{
	scanf("%d%d%d%d",&n,&k,&s,&t);
	for(int i=0;i<n;i++)
	{
		int x;
		scanf("%d",&x);
		if(((x&s)==s)&&((x|t)==t))a.push_back(x);
	}
	if(a.empty())
	{
		printf("0\n");
		return 0;
	}
	n=a.size();
	C[0][0]=1;
	for(int i=1;i<55;i++)
	{
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;j++)C[i][j]=C[i-1][j]+C[i-1][j-1];
	}
	for(int i=0;i<55;i++)
	{
		for(int j=0;j<=i&&j<k;j++)ways[i]+=C[i][j];
	//	if(i<=n)cout<<i<<" "<<ways[i]<<endl;
	}
	int free=(s^t);
	vector<int> bts;
	bts.clear();
	for(int i=0;i<18;i++)if(free>>i&1)bts.push_back(i);
	m=bts.size();
	for(int i=0;i<n;i++)
	{
		int tmp=a[i];
		a[i]=0;
		for(int j=0;j<m;j++)if(tmp>>bts[j]&1)a[i]|=(1<<j);
	//	cout<<a[i]<<endl;
	}
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		memset(cnt,0,sizeof(cnt));
		for(int j=i+1;j<n;j++)
		{
			cnt[a[i]^a[j]]++;
		}
	//	for(int j=0;j<(1<<m);j++)cout<<cnt[j]<<endl;system("pause");
		solve();
		for(int j=0;j<(1<<m);j++)
		{
			int sz=__builtin_popcount(j);
			if(sz&1)ans-=ways[cnt[j]];
			else ans+=ways[cnt[j]];
		}
	}
	if(ans<0)ans=-ans;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 5840
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, n) for (int i = (a); i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;
const ll mod = (ll)1e9 + 7;

int main() {
  int n;
  cin >> n;
  int ac = 0, wa = 0, tle = 0, re = 0;
  rep(i, n) {
    string s;
    cin >> s;
    if (s == "AC") ac++;
    if (s == "WA") wa++;
    if (s == "TLE") tle++;
    if (s == "RE") re++;
  }
  cout << "AC x " << ac << "\nWA x " << wa << "\nTLE x " << tle << "\nRE x " << re << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
using namespace std;

int N, MOD = 998244353;
int y[200020], d1[200020], d2[200020], pow2[200020], s[4][200020];
pair<int,int> p[200020];

inline void add(int i, int* d) { for(;i <= N; i+=i&-i) d[i] += 1; }
inline int  sum(int i, int* d) { int ret=0; for(; i > 0; i-=i&-i) ret += d[i]; return ret; }

int main() {
	scanf("%d", &N);
	for(int i=0; i < N; ++i) {
		scanf("%d%d", &p[i].first, &p[i].second);
		y[i] = p[i].second;
	}
	sort(p, p + N);
	sort(y, y + N);

	for(int i = 0; i < N; ++i) {
		int yi = upper_bound(y, y+N, p[i].second) - y;
		s[0][i] = sum(yi, d1);
		s[1][i] = i - s[0][i];
		add(yi, d1);
	}
	for(int i = N-1; i >= 0; --i) {
		int yi = upper_bound(y, y+N, p[i].second) - y;
		s[2][i] = sum(yi, d2);
		s[3][i] = (N-1-i) - s[2][i];
		add(yi, d2);
	}

	pow2[0] = 1;
	for(int i = 1; i <= N; ++i) pow2[i] = pow2[i-1] * 2 % MOD;

	long ans = 0, tmp1[4], tmp2[4];
	for(int i = 0; i < N; ++i) {
		for(int j = 0; j < 4; ++j) {
			tmp1[j] = pow2[s[j][i]];
			tmp2[j] = tmp1[j] - 1;
		}
		ans = (ans + tmp2[0] * tmp1[1] % MOD * tmp1[2] % MOD * tmp2[3] % MOD) % MOD;
		ans = (ans + tmp1[0] * tmp2[1] % MOD * tmp2[2] % MOD * tmp1[3] % MOD) % MOD;
		ans = (ans - tmp2[0] * tmp2[1] % MOD * tmp2[2] % MOD * tmp2[3] % MOD + MOD) % MOD;
		ans = (ans + tmp1[0] * tmp1[1] % MOD * tmp1[2] % MOD * tmp1[3] % MOD) % MOD;
	}

	printf("%ld\n", ans);
	return 0;
}


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

int main()
{
    string s;
    cin >> s;

    int flag=0;

    int n=s.size();
    for(int i=0;i<n;i++)
    {
        if((i%2!=0) && s[i]=='R')
        {
            flag=1;
            cout << "No" << endl;
            break;
        }
        else if((i%2==0) && s[i]=='L')
        {
            flag=1;
            cout << "No" << endl;
            break;
        }
    }
    if(flag==0)
       cout << "Yes" << endl;
}

Measured memory_bytes: 256
import math


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


N = int(input())
N_diviors = make_divisors(N)
N_diviors_len = len(N_diviors)
N_sqrt = math.sqrt(N)

for i in range(N_diviors_len):
    if N_sqrt <= N_diviors[i]:
        print(N_diviors[i] + int(N / N_diviors[i]) - 2)
        break


Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;

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

  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1;
  for (ll i = 0; i < n; i++) {
    if (log10(ans) + log10(a[i]) > 18.0) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  if (ans > 1000000000000000000ull) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4080
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N;
    cin >> N;
    vector<int> C(N-1), S(N-1), F(N-1);
    REP(i, N-1){
        cin >> C[i] >> S[i] >> F[i];
    }

    REP(i, N){
        int t = 0;
        FOR(j, i, N-1){
            if(t < S[j]) t = S[j];
            while(t%F[j] != 0) t++;
            t += C[j];
        }
        cout << t << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
N = input()
A = [0] + map(int, raw_input().split()) + [0]
cost = sum([abs(A[i] - A[i + 1]) for i in range(N + 1)])
for i in range(N):
    a, b, c = A[i:i + 3]
    print cost - abs(a - b) - abs(b - c) + abs(a - c)


Measured memory_bytes: 13544
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  string s;
  cin>>s; 
  if(s.at(2)==s.at(3)&&s.at(4)==s.at(5)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }

}







Measured memory_bytes: 256