akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

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

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

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


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

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

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

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

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

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

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

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

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

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

vector< int > z_algorithm(const string &s) {
  vector< int > prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int) s.size();
  return prefix;
}

int main() {
  int N, K;
  cin >> N >> K;

  vector< string > S(N);
  cin >> S;

  vector< bitset< 10001 > > reach(N + 1);
  reach.back().set(K);
  for(int i = N - 1; i >= 1; --i) {
    reach[i] = reach[i + 1] | (reach[i + 1] >> S[i].size());
  }

  bitset< 10001 > dp;
  dp[0] = true;

  string ans;
  for(int i = 0; i < N; ++i) {

    vector< int > d = z_algorithm(S[i] + ans);
    for(int j = 0; j <= ans.size() && j + S[i].size() <= K; ++j) {
      int t = (j == ans.size() ? 0 : d[S[i].size() + j]);

      if(dp[j] && reach[i + 1][j + S[i].size()] && (j == ans.size() || (t < S[i].size() && ans[j + t] > S[i][t]))) {
        ans = ans.substr(0, j) + S[i];
        for(int l = j + t + 1; l <= K; ++l) dp[l] = false;
        dp[j + S[i].size()] = true;
        break;
      }
    }
  }

  cout << ans << endl;
}


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

ll INF = 1e18;
ll MOD = 1e9+7;

int main() {
    string N; cin >> N;
    for(auto ch : N) {
        if(ch == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while(true){
    C -= B;
    if(C <= 0){
      cout << "Yes";
      break;
    }
    A -= D;
    if(A <= 0){
      cout << "No";
      break;
    }
  }
  cout << endl;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  for (int i = 0; i * 4 <= n; ++i) {
    if ((n - i * 4) % 7 == 0) {
      out("Yes");
      return 0;
    }
  }
  out("No");
}


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

int main()
{
  string S,T;
  cin>>S>>T;
  int a=1e9;
  rep(si,S.size()-T.size()+1){
    int cnt=0;
    rep(ti,T.size()){
      if(S[si+ti]!=T[ti]) cnt++;
    }
    a = min(a,cnt);
  }
  cout<<a<<endl;
  return 0;
}

Measured memory_bytes: 3612
#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 n;
  cin >> n;
  double ans = 0;
  rep(i,n){
    double x; string u;
    cin >> x >> u;
    if(u=="JPY"){
      ans+=x;
    }else{
      ans+=x*380000.0;
    }
  }
  cout << ans << endl;
}


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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

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


	set<ll> st({1, 2, 3, 4, 5, 6, 7, 8, 9});
	set<ll> st2 = st;

	rep(i, 9){
		set<ll> tmp = st2;
		st2.clear();

		for(auto it : tmp){
			ll pre =  it % 10;
			if(pre == 0){
				st2.insert(it * 10 + 0);
				st2.insert(it * 10 + 1);
				st.insert(it * 10 + 0);
				st.insert(it * 10 + 1);
			}else if(pre == 9){
				st2.insert(it * 10 + 8);
				st2.insert(it * 10 + 9);
				st.insert(it * 10 + 8);
				st.insert(it * 10 + 9);
			}
			else{
				st2.insert(it * 10 + pre - 1);
				st2.insert(it * 10 + pre);
				st2.insert(it * 10 + pre + 1);
				st.insert(it * 10 + pre - 1);
				st.insert(it * 10 + pre);
				st.insert(it * 10 + pre + 1);
			}
		}
	}

	ll cnt = 1;
	for(auto it : st){
		if(cnt == k){
			cout << it << endl;
			return 0;
		}
		cnt++;
	}

	/*
	int cnt = 0;
	for(ll i = 1; i < 3334566667; ++i){
		cout << i << endl;
		bool f = true;
		ll tmp = i;
		vector<ll> dig(12);
		int cnt2 = 0;
		while(tmp != 0){
			dig[cnt2] = tmp % 10;
			tmp /= 10;
			cnt2++;
		}

		ll succ = 1;
		rep(j, cnt2-1){
			if(abs(dig[j] - dig[j+1]) > 1){
				f = false;

				break;
			}
			succ *= 10;
		}

		if(f){
			cnt++;
			if(cnt == k){
				cout << i << endl;
				return 0;
			}
		}
	}
	*/

	return 0;
}


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

using namespace std;

typedef long long int lld;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(15);
    cout << fixed;

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

    int ans = 0;

    for (int i = 0; i < n; i++) {
        int x = 0;
        cin >> x;
        if (x >= k)
            ans++;
    }

    cout << ans << '\n';



    
    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;

int main() {
	int X, N;
	cin >> X >> N;

	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v.at(i);
	}

	int d = 1000;
	int ans = -1;
	for (int i = 0; i <= 200; i++) {
		if (count(v.begin(), v.end(), i)) {
			continue;
		}
		else {
			int n = abs(X - i);
			if (n < d) {
				d = n;
				ans = i;
			}
		}
	}
	//cout << "ans1:" << ans << endl;
	//cout << "d:" << d << endl;

	//cout << "abs:" << abs(X - (-1)) << endl;
	if (abs(X - (-1)) < d) {
		ans = -1;
	}

	cout << ans << endl;
}

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

    
int main(){
    vector<char> s(4);
    for(int i=0;i<4;i++){
        cin >> s.at(i);
    }
    bool out=true;
    for(int i=0;i<3;i++){
        if(s.at(i)==s.at(i+1)){
            out=false;
            break;
            }
    }
    if(out){cout << "Good" << endl;}
    else{cout << "Bad" << endl;}
}

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

const int maxn = 1e6;

int n, m;
vector<int> e[maxn + 10];
int check[maxn + 10];

int dem(int u)
{
    int hold = check[u] = 1;
    for (int v : e[u])
        if (!check[v]) hold += dem(v);
    return hold;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);   cout.tie(nullptr);
    if (ifstream("test.inp"))
    {
        freopen("test.inp", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            freopen("test.out", "w", stdout);
        #endif //CHECKING
    }
    else if (ifstream(taskname".inp"))
    {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    cin >> n >> m;
    for (int i = 1; i <= m; ++i)
    {
        int u, v;   cin >> u >> v;
        e[u].emplace_back(v);
        e[v].emplace_back(u);
    }

    int ans = 1;
    for (int i = 1; i <= n; ++i)
        if (!check[i]) ans = max(ans, dem(i));
    cout << ans;
}


Measured memory_bytes: 44172
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;

int n,n2;
long *a;
long ans = LONG_MIN;
long *tmp[3];

void solve(int ii, int nn2,long now,int tobasi) {
	if (ii >= n) {
		return;
	}
	if (tmp[tobasi][ii] >= now) {
		return;
	}
	tmp[tobasi][ii] = now;
	if (nn2 == n2) {
		ans = max(ans, now);
		return;
	}
	if (tobasi == 2) {
		solve(ii + 2, nn2 + 1, now + a[ii + 2], tobasi);
		if (a[ii + 3] > a[ii + 2]) {
			solve(ii + 3, nn2 + 1, now + a[ii + 3], tobasi - 1);
		}
		if (a[ii + 4] > a[ii + 3] && a[ii + 4] > a[ii + 2]) {
			solve(ii + 4, nn2 + 1, now + a[ii + 4], tobasi - 2);
		}
	}else if (tobasi == 1) {
		solve(ii + 2, nn2 + 1, now + a[ii + 2], tobasi);
		if (a[ii + 3] > a[ii + 2]) {
			solve(ii + 3, nn2 + 1, now + a[ii + 3], tobasi - 1);
		}
	}
	else {
		solve(ii + 2, nn2 + 1, now + a[ii + 2], tobasi);
	}


	return;
}

int main()
{
	int i;
	cin >> n;
	a = new long[n];
	tmp[0] = new long[n];
	tmp[1] = new long[n];
	tmp[2] = new long[n];
	for (i = 0; i < n; i++) {
		cin >> a[i];
		tmp[0][i] = LONG_MIN;
		tmp[1][i] = LONG_MIN;
		tmp[2][i] = LONG_MIN;
	}
	n2 = n / 2;


	int imax;
	if (i % 2 == 1) {
		imax = 2;
	}
	else {
		imax = 1;
	}
	for (i = 0; i <= imax; i++) {
		solve(i, 1, a[i],imax-i);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 14576
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

dp = [[0] * 3 for _ in range(n + 1)]
for i in range(1, n + 1):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            if dp[i][k] < dp[i - 1][j] + a[i - 1][k]:
                dp[i][k] = dp[i - 1][j] + a[i - 1][k]
print(max(dp[n]))

Measured memory_bytes: 75736
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;

int main(){
    int N;
    string S;
    cin >> N >> S;
    vector<int>  es(N + 1, 0);
    rep(i, N + 1){
        if(i != 0){
            // iよりも左にEがいくつ
            es[i] = es[i - 1];
            es[i] += S[i - 1] == 'E';
        }
    }
    int ans = (1 << 31) - 1;
    rep(i, N){
        int tmp;
        tmp = i - es[i];
        tmp += es[N] - es[i + 1];
        ans = min(tmp, ans);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1796
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func debug(a ...interface{}) {
	if os.Getenv("ONLINE_JUDGE") == "false" {
		fmt.Fprintln(os.Stderr, a...)
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInts(n)
	b := scanInts(n)

	am := map[int]int{}
	bm := map[int]int{}
	for i := 0; i < n; i++ {
		am[a[i]]++
		bm[b[i]]++
	}

	ma := 0
	for i, e := range am {
		if _, ok := bm[i]; !ok {
			continue
		}
		if n-e < bm[i] {
			fmt.Fprintln(wr, "No")
			return
		}
		ai := sort.Search(n, func(j int) bool { return i < a[j] })
		bi := sort.Search(n, func(j int) bool { return i <= b[j] })
		ma = max(ma, ai-bi)
	}

	fmt.Fprintln(wr, "Yes")
	for i := 0; i < n; i++ {
		fmt.Fprint(wr, b[(i-ma+n)%n], " ")
	}
	fmt.Fprintln(wr)
}


Measured memory_bytes: 26820
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

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



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

  string ans = "";
  for(int i = 0; i < s.length(); i+=2) {
    ans += s[i];
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;
int main()
{
    int a,b,c;
    int i,j;
    vector<int> v;
    
    cin>>i>>a>>b;

    c=a*i;
    if(b<=c)
    {
        c=b;
    }
    cout<<c;

    cout <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
#define pb push_back
#define pr pair<int,int>
using namespace std;
using ll = long long;
// using mod = 1000000000 + 7;
void self_max(int &a,int b){
	a = max(a,b);
}

void self_min(int &a,int b){
	a = min(a,b);
}
int main(){
	int a,b,c; cin>> a >> b >> c;
	int count = 0;
	for(int i = a;i<=b;i++){
		if(c%i == 0) count++;
	}

	cout << count << endl;

	return 0;
}



Measured memory_bytes: 3104
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long a,b;
long long gcd(long long x,long long y){
	long long t;
	while(y){
        t=x%y;
        x=y;
        y=t;
	}
	return x;
}
int main()
{
    scanf("%lld%lld",&a,&b);
    if(gcd(a,b)==b){
		printf("-1\n");
    }
    else{
        printf("%lld\n",a);
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <cmath>
using namespace std;

int val[8];
int dp[16777217];

class State{
public:
	int t,cost;

	State(int tt,int tcost){
		t = tt;
		cost = tcost;
	}
};

int change(int t,int from,int to){
	int digit = (t / val[to]) % val[1];
	return t - digit * val[to] + digit * val[from];
}

int zeroIdx(int t){
	for(int i=0;i<8;i++){
		if((t/val[i]) % val[1] == 0) return i;
	}
	return -1;
}

int DP(void){
	int start = 0;
	for(int i=0;i<8;i++){
		val[i] = (int)pow(8,i);
		start += i * val[i];
	}

	queue<State> open;
	State st(start,0);
	open.push(st);
	dp[start] = -1;

	while(!open.empty()){
		st = open.front(); open.pop();
		int idx = zeroIdx(st.t);

		if(idx >= 4){
			int aft = change(st.t,idx,idx-4);
			if(dp[aft] == 0){
				dp[aft] = st.cost + 1;
				open.push(State(aft,st.cost+1));
			}
		}
		else if(idx < 4){
			int aft = change(st.t,idx,idx+4);
			if(dp[aft] == 0){
				dp[aft] = st.cost + 1;
				open.push(State(aft,st.cost+1));
			}
		}
		if(idx % 4 > 0){
			int aft = change(st.t,idx,idx-1);
			if(dp[aft] == 0){
				dp[aft] = st.cost + 1;
				open.push(State(aft,st.cost+1));
			}
		}
		if(idx % 4 < 3){
			int aft = change(st.t,idx,idx+1);
			if(dp[aft] == 0){
				dp[aft] = st.cost + 1;
				open.push(State(aft,st.cost+1));
			}
		}
	}

	dp[start] = 0;
}

int main(void){
	DP();

	while(1){
		int sum = 0;
		for(int i=0;i<8;i++){
			int x;
			if(!(cin>>x)) return 0;
			sum += x * val[i];
		}
		cout<<dp[sum]<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  priority_queue<long long> small;
  for (int i = 0; i < N; ++i) {
    long long tmp;
    cin >> tmp;
    small.push(-tmp);
  }

  while (small.size() > 1) {
    long long first = -small.top();
    small.pop();
    long long second = -small.top();
    small.pop();

    long long tmp = second % first;
    small.push(-first);
    if (tmp == 0)
      continue;
    small.push(-tmp);
  }

  cout << -small.top() << endl;

  return 0;
}

Measured memory_bytes: 1400
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  ll n,m;
  cin>>n>>m;
  
  map<ll,ll> ma;
  ll a,b;
  rep(i,n){
    cin>>a>>b;
    ma[a]+=b;
  }
  
  ll cnt=0,sum=0;
  for(auto itr=ma.begin();itr!=ma.end();itr++){
    if(cnt+(itr->second)>m){
      sum+=(itr->first)*(m-cnt);
      break;
    }
    else{
      sum+=(itr->first)*(itr->second);
      cnt+=(itr->second);
    }
  }
    
  cout<<sum<<endl;
 
  return 0;
}

Measured memory_bytes: 9852
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define MAX 1000000007

using namespace std;

int main(void){
	int N,M;
	cin>>N>>M;
	int l,r;
	cin>>l>>r;
	rep(i,M-1){
		int tl,tr;
		cin>>tl>>tr;
		if(tl>l)l=tl;
		if(tr<r)r=tr;
		if(l>r){
			cout<<0<<endl;
			return 0;
		}
	}
	cout<<r-l+1<<endl;
	return 0;

}


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

int a[60][30];
int main() {
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    int num=s.size();
    for(int j=0;j<num;j++){
      int x=s[j]-'a';
      a[i][x]++;
    }
  }
  for(int i=0;i<26;i++){
    int kazu=INT_MAX;
    for(int j=0;j<n;j++){
      kazu=min(kazu,a[j][i]);
    }
    for(int k=0;k<kazu;k++){
      char c=i+'a';
      cout<<(char)c;
    }
  }
  cout<<endl;
  return 0;
}
    


Measured memory_bytes: 3532
/* ****TUSHAR_SEN IITR**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		ll turn=0;
		while(true)
		{
			if(turn%2==0)
			{
				c-=b;
				if(c<=0) break;
			}
			else
			{
				a-=d;
				if(a<=0) break;
			}
			turn++;
		}
		if(a<=0)
		{
			cout<<"No";
		}
		else cout<<"Yes";

	}
	return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  n = ~(-1u << n);
  m = ~(-1u << m);
  vector<string> s(n, string(m, '0'));
  auto rec = [&](auto&& self, int li, int ri, int lj, int rj) -> void {
    int mi = (li + ri) / 2;
    int mj = (lj + rj) / 2;
    s[mi][mj] = '1';
    if (ri - li == 1 and rj - lj == 1) {
      return;
    }
    if (ri - li == 1) {
      self(self, li, ri, lj, mj);
      self(self, li, ri, mj + 1, rj);
      return;
    }
    if (rj - lj == 1) {
      self(self, li, mi, lj, rj);
      self(self, mi + 1, ri, lj, rj);
      return;
    }
    self(self, li, mi, lj, mj);
    self(self, li, mi, mj + 1, rj);
    self(self, mi + 1, ri, lj, mj);
    self(self, mi + 1, ri, mj + 1, rj);
  };
  rec(rec, 0, n, 0, m);
  for (auto e : s) {
    cout << e << '\n';
  }
}


Measured memory_bytes: 2304
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion

struct edge
{
	int from;
	int to;
	ll cost;
};
bool cmp(const edge &a, const edge &b)
{
	return a.cost < b.cost;
}

int main()
{
	int n; cin >> n;
	vector<pair<ll, int>> x(n), y(n);
	rep(i, n)
	{
		ll a, b; cin >> a >> b;
		x[i] = make_pair(a, i);
		y[i] = make_pair(b, i);
	}
	sort(all(x));
	sort(all(y));
	vector<edge> edges;
	rep(i, n - 1)
	{
		edge e;
		int from = x[i].second;
		int to = x[i + 1].second;
		ll cost = x[i + 1].first - x[i].first;
		e = { from,to,cost };
		edges.push_back(e);
	}
	rep(i, n - 1)
	{
		edge e;
		int from = y[i].second;
		int to = y[i + 1].second;
		ll cost = y[i + 1].first - y[i].first;
		e = { from,to,cost };
		edges.push_back(e);
	}
	sort(all(edges), cmp);
	UnionFind uf(n);
	ll res = 0;
	for (edge e : edges)
	{
		if (!uf.issame(e.from, e.to))
		{
			res += e.cost;
			uf.merge(e.from, e.to);
		}
	}
	cout << res << endl;
}

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

int main(){
	string s1,s2;
	
	cin >> s1 >> s2;
	int j = 0;
	for(int i = 0;i < s1.size();i++){
		cout << s1[i];
		if(j < s2.size()) cout << s2[j++];
	}
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    set<string> ss;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        ss.insert(s);
    }

    cout << ss.size() << endl;

    return 0;
}


Measured memory_bytes: 19208
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
#define rep(i, s, n) for(int i(s); i < int(n); ++i)
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;

using P = pair<i64, bool>;

signed main()
{
  iostreamBooster();
  int H, W;
  cin >> W >> H;

  vector<P> cost;
  cost.reserve(H+W);

  rep(i, 0, W) {
    i64 c; cin >> c;
    cost.emplace_back(c, true);
  }
  rep(i, 0, H) {
    i64 c; cin >> c;
    cost.emplace_back(c, false);
  }

  sort(ALL(cost));
  i64 ans = 0;
  i64 numX = W+1;
  i64 numY = H+1;

  for (const auto &e : cost) {
    const bool connectYoko = e.second;
    if (connectYoko) {
      ans += e.first * numY;
      --numX;
    } else {
      ans += e.first * numX;
      --numY;
    }
  }

  cout << ans << endl;

  return 0;
}



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

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

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

const ll MOD = 1e9+7;

class modComb{
private:
    const ll MAX_N, M;
    vector<ll> fact, invfact;

    ll extgcd(ll a, ll b, ll &x, ll &y){
        ll g = a; x = 1; y = 0;
                if(b) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
        return g;
    }

    ll invMod(ll a){
        ll x, y;
        if(extgcd(a, M, x, y) == 1) return (x + M) % M;
        else return 0;
    }
public:
    modComb(const ll n, const ll mod) : MAX_N(n), M(mod){
        fact.resize(MAX_N, 1);
        for(int i = 2; i < MAX_N; i++)
            fact[i] = (fact[i-1] * i) % M;
        invfact.resize(MAX_N, 1);
        invfact[MAX_N-1] = invMod(fact[MAX_N-1]);
        for(int i = MAX_N-2; i >= 1; i--)
            invfact[i] = (invfact[i+1] * (i+1)) % M;
    }

    ll operator()(const ll n, const ll r){
        if(n < 0 || r < 0 || n < r) return 0;
        return (((fact[n] * invfact[n-r]) % M) * invfact[r]) % M;
    }
};

int main(void) {
  int n;
  cin >> n;
  n++;
  vi a(n);
  REP(i, n) cin >> a[i];
  vector<vi> p(n);
  REP(i, n) p[a[i]].push_back(i);
  int k;
  REP(i, n) if(p[i].size() == 2) k = i;

  modComb nCr(n + 100, MOD);
  for(int i = 1; i <= n; i++) {
    ll x = nCr(n, i);
    int bb = i - 1;
    int aa = p[k][0] + (n - p[k][1] - 1);
    ll y = nCr(aa, bb);
    cout << ((x + MOD - y) % MOD) << endl;
  }
}


Measured memory_bytes: 8704
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

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

Measured memory_bytes: 256
import itertools

N = int(input())

ans = [0] * (10 ** 4)
for x, y, z in itertools.product(range(1, 100), repeat=3):
    a = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
    if a <= N:
        ans[a - 1] += 1
print(*ans[:N], sep='\n')


Measured memory_bytes: 9368
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   int k,x,n,ans;
   cin>>k>>x;
   n=k*2-1;
   ans=x-k+1;
   rep(i,n){
   cout<<ans<<" ";
     ans++;
   }
  cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

constexpr lnt MOD = 998244353;
struct mint
{
    lnt v;
    mint():v(0){}
    mint(lnt v):v((v+MOD)%MOD){}
    mint operator-()const{ return mint(0) - *this; }
    mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
    mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
    mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
    mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }
    mint operator+(const mint& a)const{ return mint(*this) += a; }
    mint operator-(const mint& a)const{ return mint(*this) -= a; }
    mint operator*(const mint& a)const{ return mint(*this) *= a; }
    mint operator/(const mint& a)const{ return mint(*this) /= a; }
    bool operator<(const mint& a)const{ return v < a.v; }
    bool operator==(const mint& a)const{ return v == a.v; }
    mint pow(lnt k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
    mint inv()const{ return pow(MOD-2); }
    static mint comb(lnt n, lnt k) { if(n-k<k) k=n-k; mint num(1), dom(1); for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; } return num/dom; }
    static std::vector<mint> construct_comb(int n) {
        std::vector<mint> c(n+1); mint a = 1; c[0] = a; for(int i=1;i<=n;i++) { a = a*mint(n+1-i)/i; c[i] = a; } return c;
    }
    static std::vector<mint> construct_fact(int n) { std::vector<mint> f(n+1,1); for(int i=2;i<=n;i++) f[i]=f[i-1]*i; return f; }
};
std::istream& operator>>(std::istream&i,mint&a){ lnt t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


int main() {
	std::string s;
	std::cin >> s;
	int k;
	std::cin >> k;
	std::vector<lnt> v;
	for(int i=0;i<s.size();i++) {
		int start=i;
		while(i<s.size()&&s[i]=='1') i++;
		v.emplace_back(i-start);
	}
	std::reverse(all(s));
	std::reverse(all(v));
	debug(v);
	if(!v.empty()) v.pop_back();
	int n=v.size();
	int m=0;
	for(auto x:v) m+=x;
	std::vector<std::vector<std::vector<mint> > > dp(n+1,std::vector<std::vector<mint> >(m+1,std::vector<mint> (m+1,0)));
	dp[0][0][std::min(k,m)]=1;
	rep(i,n) {
		rep(x,m+1) rep(y,m+1) {
			if(dp[i][x][y]==mint(0)) continue;
			rep(j,v[i]+1) {
				if(y-j<0) break;
				dp[i+1][x+j][y-j]+=dp[i][x][y];
			}
			rep(j,x+1) {
				if(j==0) continue;
				dp[i+1][x-j][y]+=dp[i][x][y];
			}
		}
	}
	debug(n,m,k,v);
	debug(dp);
	mint ans=0;
	rep(i,m+1) rep(j,m+1) {
		ans+=dp[n][i][j];
	}
	print(ans);
}


Measured memory_bytes: 35372
#include<bits/stdc++.h>
using namespace std;
int dp[1002][1002];
int main()
{
	int h,w,m;
	cin>>h>>w>>m;
	set<int>s1,s2;
	map<int,int>row,col;
	set<pair<int,int>>p;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		p.insert({a,b});
		row[a]+=1;
		col[b]+=1;
	}
	int sum=0,val=0;
	for(auto i:row)
	{
         int l=i.second;
         sum=max(sum,l);
	}
	for(auto i:row)
	{
		if(i.second==sum)
		{
			s1.insert(i.first);
		}
	}
	for(auto i:col)
	{
		val=max(val,i.second);
	}
	for(auto i:col)
	{
		if(i.second==val)
		{
			s2.insert(i.first);
		}
	}
	int flag=0;
	for(auto it:s1)
	{
		for(auto it1:s2)
		{
			if(p.find({it,it1})==p.end())
			{
				flag=1;
				sum=sum+val;
				break;
			}

		}
		if(flag==1)
			break;
	}
	if(flag==0)
		sum=sum+val-1;
	cout<<sum;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N; ll H;
priority_queue <Pli> que;
int main(){
  cin >> N >> H;
  for (int i = 0; i < N; i++){
    ll A, B; cin >> A >> B;
    que.push({A, 0});
    que.push({B, 1});
  }

  ll ans = 0, rest = H;
  while (!que.empty()){
    Pli Q = que.top(); que.pop();
    if (Q.se == 1){
      rest -= Q.fi; ans++;
      if (rest <= 0){
        cout << ans << endl;
        return 0;
      }
    }else{
      ans += rest / Q.fi;
      if (rest % Q.fi != 0) ans++;
      cout << ans << endl;
      return 0;
    }
  }


  return 0;
}


Measured memory_bytes: 7416
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    for(int i = 0; i < N; ++i)
    {
        int atemp;
        cin >> atemp;
        A[i] = atemp;
    }
    int dist = 0;
    dist = A[0] + K - A[N-1];
    for (int i = 1; i < N; ++i)
    {
        dist = std::max(dist, A[i] - A[i - 1]);
    }
    int ans = K - dist;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,a,b;
  cin>>k>>a>>b;
  int ans=0;
  ans=b/k*k;
  if(ans>=a){
    cout<<"OK"<<endl;
  }
  else{
    cout<<"NG"<<endl;
  }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define PB push_back
#define MP make_pair
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)

int main()
{
  int n;
  sd(n);
  cout << n + pow(n, 2) + pow(n, 3);
  return 0;
}

Measured memory_bytes: 4156
N = int(input())
S = input()

L = [0] * N
R = [0] * N

for i in range(1, N):
  R[i] = R[i-1] + 1 if S[i-1] == "E" else R[i-1]
#print(R)

S = S[::-1]
for i in range(1, N):
  L[i] = L[i-1] + 1 if S[i-1] == "W" else L[i-1]
L = L[::-1]
#print(L)

LR = [0] * N
for i in range(N):
  LR[i] = L[i] + R[i]
print(N - max(LR) - 1)

Measured memory_bytes: 51932
#include<stdio.h>
char a[1000001];
void sosu();
main(){
  int x,ans=0,i;
  sosu();
  while( scanf("%d",&x)!=EOF){
    ans=0;
    for(i=2;i<=x;i++){
      if(a[i]!=1){
	ans++;
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}


void sosu(){
  int i,j;
  a[0]=1;
  a[1]=1;
  for(i=2;i*i<1000001;i++){
    if(a[i]!=1){
      for(j=i+1;j<=1000000;j++){
	if(j%i==0){
	  a[j]=1;
	}
      }
    }
  }
}

Measured memory_bytes: 1380
n = gets.to_i
xy_a = []
n.times do
  xy = gets.chomp.split
  xy.length.times do |i|
    xy[i] = xy[i].to_i
  end
  xy_a << xy
end

xy_p = xy_a.permutation.to_a
sum = 0
xy_p.each do |xys|
  length = 0
  (n-1).times do |i|
    length += Math.sqrt((xys[i][0] - xys[i+1][0]) ** 2 + (xys[i][1] - xys[i+1][1]) ** 2)
  end
  sum += length
end

puts sum / xy_p.length

Measured memory_bytes: 6780
n = int(input())

F = [0]*(n+1)
if n == 0:
    print(1)
elif n==1:
    print(1)
elif n > 1:
    F[0] = 1
    F[1] = 1

    for i in range(2,n+1):
        F[i] = F[i-1] + F[i-2]

    print(F[-1])


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

int main()
{
    int h,w,k;cin>>h>>w>>k;
    vector<vector<char>> s(h,vector<char>(w));
    vector<vector<int>> a(h,vector<int>(w,-1));
    int i,j;
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            cin>>s.at(i).at(j);
        }
    }
    int count=1;
    int final=-1;
    for(i=0;i<h;i++)
    {
        bool found=false;
        for(j=0;j<w;j++)
        {
            if(s.at(i).at(j)=='#')
            {
                if(found)count++;
                final=i;
                found=true;
            }
            a.at(i).at(j)=count;
        }
        if(!found)
        {
            for(j=0;j<w;j++)a.at(i).at(j)=-1;
        }
        else count++;
    }
    for(i=final-1;i>=0;i--)
    {
        for(j=0;j<w;j++)
        {
            if(a.at(i).at(j)==-1)a.at(i).at(j)=a.at(i+1).at(j);
        }
    }
    for(i=final+1;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            if(a.at(i).at(j)==-1)a.at(i).at(j)=a.at(final).at(j);
        }
    }
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            if(j==0)cout<<a.at(i).at(j);
            else cout<<' '<<a.at(i).at(j);
        }
        cout<<endl;
    }
}


Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int[] vals = new int[N];
		boolean can = true;
		for (int i = 0; i < vals.length; i++) {
			vals[i] = sc.nextInt() - 1;
			if (vals[i] > i) can = false;
		}
		if (!can) {
			out.println(-1);
		} else {
			List<Integer> ans = new ArrayList<>();
			for (int i = 0; i < N; i++) {
				for (int j = N - 1 - i; j >= 0; j--) {
					if (vals[j] == j) {
						ans.add(j + 1);
						for (int k = j; k + 1 < N; k++) {
							vals[k] = vals[k+1];
						}
						break;
					}
				}
			}
			Collections.reverse(ans);
			for (Integer value : ans) {
				out.println(value);
			}
		}
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 22612
mod = 10**9+7
S = list(input())
n = len(S)
dp = [[0]*13 for i in range(n)]
if S[0]=='?':
    for i in range(13):
        dp[0][i] = 1 if i<10 else 0
else:
    dp[0][int(S[0])] = 1
    
for i in range(1, n):
    if S[i]=='?':
        for j in range(13):
            for s in range(10):
                p = (j*10+s)%13
                dp[i][p] += dp[i-1][j]
                dp[i][p]%=mod
    else:
        s = int(S[i])
        for j in range(13):
            p = (j*10+s)%13
            dp[i][p] += dp[i-1][j]
            dp[i][p]%=mod
print(dp[n-1][5])
    

Measured memory_bytes: 65188
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 5e5+1;
 
typedef long long ll;
typedef long double ld;

ll n, m, k;
ll res[3001][3001][4];
ll res1[3001][3001];

ll dfs(ll i,ll j,ll cur)
{
    if(i == n || j == m || cur == 3)
        return 0;
    if(res[i][j][cur] != -1)
        return res[i][j][cur];
    ll &ans = res[i][j][cur];
    ans = 0;
    if(res1[i][j] == 0)
        ans = max({ans,dfs(i+1,j,0), dfs(i,j+1,cur)});
    else
        ans = max({ans,res1[i][j] + dfs(i+1,j,0),res1[i][j] + dfs(i,j+1,cur+1),dfs(i,j+1,cur),dfs(i+1,j,0)});
    return ans;
}
void test_case()
{
	cin >> n >> m >> k;
    memset(res,-1,sizeof(res));
    for(int i = 0; i < k; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        res1[x-1][y-1] = z;
    }
    cout << dfs(0,0,0);

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 356040
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n; cin >> n; ll ans = -1;
  
  for(ll i=1; i <= 50000; i++){
    if(int(1.08*i) == n){
      ans = i;
      break;
    }
  }
  
  if(ans == -1) cout << ":(" << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int n;
int a[100010];

int main(void){
	cin >> n;
	set<int> se;
	rep(i, n){
		int d; cin >> d;
		a[d]++;
		se.insert(d);
	}

	int cnt = 0;
	rep(i, 100010){
		if(a[i] % 2 == 0 && a[i] != 0){
			cnt++;
			// printf("%d\n", i);
		}
	}
	// printf("%d\n", cnt);
	if(cnt % 2 == 1) printf("%d\n", se.size() - 1);
	else printf("%d\n", se.size());
	return 0;
}

Measured memory_bytes: 5376
N = int(input())
b = list(map(int, input().split()))
ans = []
for i in range(N):
    for j in range(len(b) - 1, -1, -1):
        if j + 1 == b[j]:
            ans.append(b.pop(j))
            break
    else:
        print(-1)
        exit()

ans = ans[::-1]
for i in ans:
    print(i)



Measured memory_bytes: 3060
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

a,b,k = gi
ct = 0
ans = []
while ct < k
  ans << a+ct if a+ct <= b
  ans << b-ct if b-ct >= a
  ct += 1
end

puts ans.sort.uniq


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" ";
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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



void func(long long N, std::string S){

    lli lCnt=0;
    lli addL=0,addR=0;

    REP(i,0,S.size()){
        if(S[i]==')'){
            if(lCnt>0)lCnt--;
            else addL++;
        }
        else{
            lCnt++;
        }
    }

    REP(i,0,addL)cout<<"(";
    cout<<S;
    REP(i,0,lCnt)cout<<")";
    cout<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    func(N, S);
    return 0;
}


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

# 解説AC
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()

num = 7
for i in range(k):
    if num % k == 0:
        print(i + 1)
        break
    num = (num % k) * 10 + 7


Measured memory_bytes: 62624
#include "bits/stdc++.h"
using namespace std;
//template <typename... T> void read(T& ... t){ ((cin >> t), ...); }
//template <typename... T> void write(T ... t){ ((cout << t), ...); }
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
using LL = long long;
using pii = pair<int,int>;
const int INF = 2e9;
const int MAXN = 2e5 +3;
int n;
int arr[MAXN];
int brr[MAXN];

int32_t main(){ FAST;
	cin >> n;
	for(int i=1; i<=n; ++i) cin >> arr[i];
	for(int i=1; i<=n; ++i) brr[i] = arr[i];
	sort(brr+1, brr+n+1);

	for(int i=1; i<=n; ++i){
		if(arr[i] != brr[n]) cout << brr[n] << ln;
		else cout << brr[n-1] << ln;
	}
}

Measured memory_bytes: 3200
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[100005];
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n;
    scanf("%d",&n);
    int i;
    for (i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    double ans=a[n-1];
    int val;
    for (i=0;i<n;i++)
    {
        if (fabs(a[n-1]*0.5-a[i])<ans)
        {
            ans=abs(a[n-1]/2-a[i]);
            val=a[i];
        }
    }
    printf("%d %d\n",a[n-1],val);
    return 0;
} 


Measured memory_bytes: 640
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
int main()
{
	ll n,k;
	cin>>n>>k;
	ll arr[n];
	input(arr,n);
	ll dp[n];
	aset(dp,n,1e9);
	dp[0]=0,dp[1]=abs(arr[1]-arr[0]);
	for(ll i=2;i<n;i++)
	{
	for(ll j=i-1;j>=max((ll)0,i-k);j--)	
	dp[i]=min(dp[j]+abs(arr[j]-arr[i]),dp[i]);
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
def DFS(n = 1, i = 0, time = 1):
    for j in range(n):
        if A[i][j] == 1 and d[j] == 0:
            time = time + 1
            d[j] = time
            time = DFS(n, j, time)
    time = time + 1
    f[i] = time
    return time

n = int(raw_input())
A = [0] * n
for i in range(n):
    A[i] = [0] * n

for i in range(n):
    value = map(int, raw_input().split())
    u = value[0] - 1
    k = value[1]
    nodes = value[2:]
    for j in range(k):
        v = nodes[j] - 1
        A[u][v] = 1

d = [0] * n
f = [0] * n

time = 0
for i in range(n):
    if d[i] == 0:
        time = time + 1
        d[i] = time
        time = DFS(n, i, time)

for i in range(n):
    print(str(i + 1) + " " + str(d[i]) + " " + str(f[i]))

Measured memory_bytes: 6600