akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<string> s(m);
    for(int i = 0; i < m; i++) cin >> s[i];
    int p, d = INF;
    vector<int> E(n + 1, 0), W(n + 1, 0);
    for(int i = 0; i < m; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            E[j] += (s[i][j - 1] == 'E');
        }
        for(int j = n; j >= 1; j--)
        {
            W[j - 1] += (s[i][j - 1] == 'W');
        }
    }
    for(int j = 1; j <= n; j++) E[j] += E[j - 1];
    for(int j = n; j >= 1; j--) W[j - 1] += W[j];
    int num = INF, ans = -1;
    for(int i = 0; i <= n; i++)
    {
        if(E[i] + W[i] < num)
        {
            num = E[i] + W[i];
            ans = i;
        }
    }
    cout << ans << " " << ans + 1 << endl;
    return 0;
}




Measured memory_bytes: 4532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;
    REP(i, N-1) {
        vector<bool> X(26), Y(26);
        REP(j, N) {
            if (j <= i) X[S[j]-'a'] = true;
            else Y[S[j]-'a'] = true;
        }
        int cnt = 0;
        REP(j, 26) {
            if (X[j] && Y[j]) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

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

using namespace std;

#define show(x) cerr << #x << " = " << x << endl;


int main()
{

  int a, b;
  cin>>a>>b;

  if((a+b)>=10)
  {
    string ans = "error";
    cout<< ans<<endl;
  }
  else
  {

    int ans = a+b;
    cout<< ans<<endl;
  }




  return 0;
}


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

pair<pair<string,int>,int> pa[110];
int main(){
  int N;
  cin >> N;
  string s;
  int p;
  for(int i=0;i<N;i++){
      cin >> s >> p;
      pa[i]=make_pair(make_pair(s,-p),i);
  }
  sort(pa,pa+N);
  for(int i=0;i<N;i++) cout << pa[i].second+1 << endl;;
}


Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())
A = list(sorted(map(int, input().split())))
B = list(sorted(map(int, input().split())))
C = list(sorted(map(int, input().split())))

ans = 0
for i, b in enumerate(B):
    left = -1
    right = N
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if C[mid] > b:
            right = mid
        else:
            left = mid
    Cs = N - right

    left = -1
    right = N
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if A[mid] >= b:
            right = mid
        else:
            left = mid
    As = right
    ans += As * Cs
print(ans)


Measured memory_bytes: 29344
X,N=map(int,input().split())
if N==0: print(X)
else:
    p=list(map(int,input().split()))
    m=10000
    ans=N
    for i in range(-101,101):
        if m>abs((i+1)-X) and not i+1 in p:
            m=abs((i+1)-X)
            ans=i+1
    print(ans)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 200005;
int n, D[N];
vector < int > Adj[N];
void DFS(int v, int p)
{
	for (int &u : Adj[v])
		if (u != p)
			D[u] = D[v] + 1, DFS(u, v);
}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
	{
		int v, u;
		scanf("%d%d", &v, &u);
		Adj[v].pb(u);
		Adj[u].pb(v);
	}
	DFS(1, 0);
	int id = 1;
	for (int i = 1; i <= n; i++)
		if (D[i] > D[id])
			id = i;
	D[id] = 0; DFS(id, 0);
	for (int i = 1; i <= n; i++)
		if (D[i] > D[id])
			id = i;
	int d = D[id];
	if (d % 3 == 1) return !printf("Second\n");
	return !printf("First\n");
}


Measured memory_bytes: 21376
#include <stdio.h>
#include <stdlib.h>

int n;
int a[100001] = {0};

int cmp(const void *a, const void *b){
    return( *((int *)a) - *((int *)b) ) ;
}

int main(void){
    int i, s = 0;
    scanf("%d", &n);
    for ( i = 0; i < n; i++)
        scanf("%d", &a[i]);
    qsort(a, n, sizeof(int), cmp);

    for(i = 0; i < n ; i++){
        if(a[i] == a[i + 1]){
            i++;
        } else {
            s++;
        }
    }
    printf("%d\n", s);
    return 0;
}


Measured memory_bytes: 892
import math
N = int(input())
def solver(N):
    times = math.ceil(math.sqrt(N))
    counter = 0
    for i in range(1,times):
        for j in range(i,N//i + 1):
            C = N - i * j
            if C > 0:
                if i == j:
                    counter += 1
                else:
                    counter += 2
    return counter
print(solver(N))

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
 int main() {
   int N, K, X;
   cin >> N >> K;
   X = 1;
   for(int i = 0; i < N; i++){
     if(X <= K){
       X = X * 2;
     }
     
     else{
      X = X + K;
     }
   }
  cout << X << endl;
 }

Measured memory_bytes: 384
def read():
    S = input()
    T = input()
    return S, T


def diff(a, b):
    ans = 0
    for i in range(len(a)):
        if a[i] != b[i]:
            ans += 1
    return ans

def func(S, T):
    lt = len(T)
    ans = lt
    for i in range(len(S) - len(T) + 1):
        d = diff(T, S[i:i+lt])
        if d < ans:
            ans = d
    return ans


if __name__ == '__main__':
    S, T = read()
    print(func(S, T))



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

using namespace std;

#define ll long long
int m = 1000000007;

ll bin_pow(int a, int pow) {
    if (pow == 1) return a % m;
    if (pow % 2 == 0) {
        ll tmp = bin_pow(a, pow / 2) % m;
        return tmp * tmp % m;
    }
    return (a % m) * (bin_pow(a, pow - 1) % m) % m;
}

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

    int n;
    cin >> n;

    map<int, int> mp;
    vector<int> a(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        int tmp = a[i];
        for (int j = 2; tmp > 1 && j * j <= a[i]; j++) {
            int cnt = 0;
            while ((tmp % j) == 0) {
                tmp /= j;
                cnt++;
            }
            if (cnt != 0) mp[j] = max(mp[j], cnt);
        }
        if (tmp != 1) {
            mp[tmp] = max(mp[tmp], 1);
        }
    }

    ll res = 1;

    for (auto mm : mp) {
        res *= bin_pow(mm.first, mm.second);
        res %= m;
    }

    ll ans = 0;

    for (int i = 0; i < n; i++) {
        ans += res * bin_pow(a[i], m - 2);
        ans %= m;
    }

    cout << ans;

    return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;

  if (N % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }

  rep(i, N / 2) {
    if (S.at(i) != S.at(i + N / 2)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
A, B, C, D, E, F = map(int, input().split())
sato = set()
miz = set()
for i in range(F//100//A + 1):
	for j in range(F//100//B + 1):
		if i*A + j*B <= F//100:
			miz.add((i*A + j*B)*100)

for i in range(F//C + 1):
	for j in range(F//D + 1):
		if i*C + j*D <= F:
			sato.add(i*C + j*D)
miz = list(miz)
sato = list(sato)
#print(sorted(miz), sorted(sato))
node = 0
note = [100*A, 0]
for i in range(len(miz)):
	if miz[i] == 0:
		continue
	for j in range(len(sato)):
		c = 100*sato[j]/miz[i]
		q = miz[i] + sato[j]
		if c > E:
			pass
		elif q > F:
			pass
		elif c > node:
			note = [miz[i] + sato[j], sato[j]]
			node = c

print(*note)

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

int h,i,j,n,k,b,*p,y[81][5],u;
queue<int> q,w,e,r,t;

int main(){
	cin >> n >> k;
	p = new int[n+4];
	
	for(i=0; i<n+4; i++){
		p[i] = 0;
	}
	
	for(i=0; i<k; i++){
		cin >> b;
		cin >> p[b+1];
	}
	
	q.push(1);
	w.push(0);
	e.push(0);
	r.push((p[3])?p[3]:0);
	t.push((p[4])?p[4]:0);
	
	for(i=2; i<n+2; i++){
		b=0;
		for(; q.size(); ){
			for(h=1; h<4; h++){
				if(p[i]){
					y[b][0] = q.front();
					y[b][1] = e.front();
					y[b][2] = p[i];
					y[b][3] = t.front();
					y[b++][4] = (p[i+3])?p[i+3]:0;
					break;
				}else if(!((w.front() == h && e.front() == h) || (e.front() == h && h == r.front()) || (h == r.front() && h == t.front()))){
					y[b][0] = q.front();
					y[b][1] = e.front();
					y[b][2] = h;
					y[b][3] = t.front();
					y[b++][4] = (p[i+3])?p[i+3]:0;
				}
			}
			q.pop();
			w.pop();
			e.pop();
			r.pop();
			t.pop();
		}
		for(j=0; j<b; j++){
			if(y[j][0] != -1){
				for(h=0; h<b; h++){
					if((j != h)&&(y[j][1] == y[h][1])&&(y[j][2] == y[h][2])&&(y[j][3] == y[h][3])&&(y[j][4] == y[h][4])){
						y[j][0] += y[h][0];
						y[j][0] %= 10000;
						y[h][0] = -1;
					}
				}
				q.push(y[j][0]);
				w.push(y[j][1]);
				e.push(y[j][2]);
				r.push(y[j][3]);
				t.push(y[j][4]);
			}
		}
	}
	
	for(u=0; q.size(); ){
		u += q.front();
		q.pop();
	}
	
	cout << u%10000 << endl;
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define INIT_DIR 90
#define PI 3.141592

using namespace std;


int main(){
	double dir = INIT_DIR * PI / 180;
	double moveX = 0,moveY = 0;
	int mx = 0,my = 0;
	string tmp;
	int tp = 0,tp2 = 0;

	char copy[8];

	while(cin >> tmp){
		strcpy(copy,tmp.c_str());
		tp = atoi(strtok(copy,","));
		tp2 = atoi(strtok(NULL,","));

		if(tp == 0 && tp2 == 0){
			break;
		}

		moveX += tp * cos(dir);
		moveY += tp * sin(dir);
		dir += (tp2 * PI /180) * -1;
	}

	mx = (int)moveX;
	my = (int)moveY;

	cout << mx << endl << my << endl;

	return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main() {
	int N;
	cin >> N;
	long long count =0;
	map< string , int> sent;
	for (int i=0;i<N;i++){
		string S;
		cin >> S;
		sort(S.begin(),S.end());
		if(!(sent.count(S))){
			sent[S]=1;
		}
		else {
			sent[S]++;
			count += sent[S]-1;
		}
	}
	cout << count << endl;
}

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

int main(){
	int n, m;	cin >> n >> m;
	long long ans = 0;
	if(n > 1){
		ans += n*(n-1)/2;
	}
	if(m > 1){
		ans += m*(m-1)/2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()

template<class T> using V = vector<T>;
template<class T> using V2 = V<V<T>>;



void solve(){
  string s; cin >> s;
  int n = s.size();
  vector<int> ans(n,0);
  {
    int l=0, r=l;
    for(;l<n && r<n;){
      int L_l,L_r, R_l,R_r;
      R_l = l;
      while(s[r]=='R'){
        ++r;
        if(r==n) break;
      }
      R_r = r-1;
      L_l = r;
      while(s[r]=='L'){
        ++r;
        if(r==n) break;
      }
      L_r = r-1;
      ans[R_r] += (L_r-R_r)/2 + (L_l-R_l+1)/2;
      ans[L_l] += (L_l-R_l)/2 + (L_r-R_r+1)/2;
      l = r;
    }
  }
  FOR(i,0,n) cout << ans[i] << ' ';
}

int main(){
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

void solve(void){
    int N, D, X;
    cin >> N >> D >> X;
    int ans = X;
    rep(N, i) {
        int A; cin >> A;
        ans += (D-1) / A + 1;
    }
    cout << ans << '\n';
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REPZ(i, z, n) for(decltype(n) i = (z); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(all(v)))
#define MIN(v) (*min_element(all(v)))
#define INF 1000000000000 //1E+12
#define MOD 1000000007    //合同式の法

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<

typedef long long ll;
typedef unsigned long long ul;
// 1s間で可能なループ回数2E+8回
// intの最大値2147483647~2E+9
// long longの最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<> push_back
// 連想配列map<key,value> insert,
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 setprecision()
// to_string<->stoi
// stoll(longlong)
// stod(double)
// 大文字65-90(-32)
// 小文字97-122(+32)
using namespace std;
const ll mod=1000000000+7;
struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        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 pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main(){
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n,k; cin >> n >> k;
  mint res=0;
  for(ll j=k;j<=n+1;j++){
    mint mn=n;
    mint i=j;
    res+=i*(mn+mn+1-i)/2-i*(i-1)/2+1;
  }
  cout << res << endl;
  return 0;
}


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

int s[10000];
int t[500];

bool linersearch(int t, int n)
{
  int i;
  
  i = 0;
  while(s[i] != t){
    i++;
    if(s[i] == t) return true;
    if(i == n-1) return false;
  }
  return true;
}

int main(){
  int n,q;
  int cnt=0;
  
  cin >> n;
  for(int i=0;i < n;i++){
    cin >> s[i];
  }
  cin >> q;
  for(int i=0;i < q;i++){
    cin >> t[i];
    if(linersearch(t[i],n))cnt++;
  }
  
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3116
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli n;
    cin>>n;
    out(3*n*n);
}

Measured memory_bytes: 3592
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

// 最大積載量 P の k 台のトラックで何個の荷物を積めるか？
int check(llong P) {
  int i = 0;
  for ( int j = 0; j < k; j++ ) {
    llong s = 0;
    while( s + T[i] <= P) {
      s += T[i];
      i++;
      if ( i == n ) return n;
    }
  }
  return i;
}

int solve() {
  llong left = 0;
  llong right = 100000 * 10000;  // 荷物の個数 x 1個当たりの最大重量
  llong mid;
  while ( right - left > 1 ) {
    mid = (left + right) / 2;
    int v = check(mid);  // mid == P を決めて何個積めるかチェック
    if ( v >= n ) right = mid;
    else left = mid;
  }

  return right;
}

int main() {
  cin >> n >> k;
  for ( int i = 0; i < n; i++ ) cin >> T[i];
  llong ans = solve();
  cout << ans << endl;

  return 0;
}


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

int main(){

  
  while(1){
    int a, b;
    string op;
    cin>>a>>op>>b;
    if(op == "?") break;

    int ans;
    if(op == "+") ans = a + b;
    if(op == "-") ans = a - b;
    if(op == "*") ans = a * b;
    if(op == "/") ans = a / b;


    cout<<ans<<endl;
  }

  return 0;

 }


Measured memory_bytes: 3104
#include<iostream>
#include<cstdio>
using namespace std;
int k[101]={0},v[101][101]={0};
int d[101]={0},f[101]={0};
int cur=0;
void dfs(int id)
{
	if(d[id]!=0)
	{
		return;
	}
	cur++;
	if(d[id]==0)
	{
		d[id]=cur;
	}
	for(int i=0;i<k[id];i++)
	{
		dfs(v[id][i]);
	}
	cur++;
	f[id]=cur;
	return;
}
int main(void)
{
	int n=0,u=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&u);
		scanf("%d",&k[u]);
		for(int j=0;j<k[u];j++)
		{
			scanf("%d",&v[u][j]);
		}
	}
	for(int i=1;i<n;i++)
	{
		if(d[i]==0)
		{
			dfs(i);
		}
	}
	for(int i=1;i<=n;i++)
	{
		printf("%d %d %d\n",i,d[i],f[i]);
	}
	return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N; cin>>N;
    double p[N+1]; //P of H of coins 1 to N
    for (int i=1;i<=N;i++) cin>>p[i];
    double dp[N+1][N+1]; //i heads so far from the first j coins: dp[i][j]
    dp[0][0]=1; //this senseless, but I want dp[1][1] have value p1 so got to do this (implementation reasons)
    for (int i1=1;i1<=N;i1++) {
        dp[0][i1]=dp[0][i1-1]*(1-p[i1]); //P having 0 Hs from first j coins= product of P of Ts
        dp[i1][0]=0; //from zero coins, P is zero for anything
    }
    
    // dp relation: dp[i][j]= dp[i-1][j-1]*p[j]+dp[i][j-1]*(1-p[j])
    //Explanation: To answer i heads so far from first j coins,
    //previously we could have had 2 states from which we can answer current question.
    //1, that till now i-1 heads so far. So if we get current jth coin a Head, woohoo
    //2, that till now i heads already so far, so it is okay to get current j as a tail
    
    for (int i=1;i<=N;i++) {
        for (int j=1;j<=N;j++)
            dp[i][j]= dp[i-1][j-1]*p[j]+dp[i][j-1]*(1-p[j]);
    }
    
    double res=0;
    for (int i=N/2 +1;i<=N;i++)
        res+= dp[i][N];
    cout << fixed << setprecision(10) << res;
    return 0;
}

Measured memory_bytes: 70656
n,m=map(int,input().split())
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
mod=10**9+7
dp=[[0 for i in range(m+1)]for j in range(n+1)]
for i in range(n):
    for j in range(m):
        x=0
        if s[i]==t[j]:
            x=dp[i][j]+1
        dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j]+x)%mod
#print(dp)
print((dp[n][m]+1)%mod)

Measured memory_bytes: 75100
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

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

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();

    int n;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int b=*min_element(a, a+n);
    int c=*max_element(a, a+n);
    int ans=INT_MAX;
    for (int i=b;i<=c;i++)
    {
        int x=0;
        for (int j=0;j<n;j++)
        {
            x+=pow((i-a[j]), 2);
        }
        ans=min(ans, x);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
#define PB push_back

int main() {
  int n, m, k;
  cin >> n;
  vector<int> deck(2*n);
  for (int i = 0 ; i < 2*n ; i++) deck[i] = i+1;
  cin >> m;
  for (int c = 0 ; c < m ; c++) {
    cin >> k;
    if (k != 0) {
      vector<int> A, B;
      for (int l = 0 ; l < k ; l++) A.PB(deck[l]);
      for (int l = k ; l < 2*n ; l++) B.PB(deck[l]);
      
      for (int i = 0 ; i < B.size() ; i++) deck[i] = B[i];
      for (int i = 0 ; i < A.size() ; i++) deck[i+B.size()] = A[i];
    } 
    else {
      vector<int> B, A;
      for (int i = 0 ; i < n ; i++) B.PB(deck[i]);
      for (int i = n ; i < 2*n ; i++) A.PB(deck[i]);
      
      for (int i = 0 ; i < 2*n ; i+=2) deck[i] = B[i/2];
      for (int i = 1 ; i < 2*n ; i+=2) deck[i] = A[(int)(i/2)];
    }
  }
  for (int i = 0 ; i < 2*n ; i++) cout << deck[i] << endl;
}

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

int main(){

 int f, s, t, i, x;

 f = s = t = 0;

 for (i = 0; i < 10; i++) {
  cin >> x;

  if (x > f) {
   t = s;
   s = f;
   f = x;
  } else if (x > s) {
   t = s;
   s = x;
  } else if (x > t) {
   t = x;
  }
 }

 cout << f << "\n" << s << "\n" << t << "\n";

 return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
using ll = long long;
int main() {
  double k;
  cin>>k;
  cout << fixed << setprecision(15) << pow(k/3,3) << endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){

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

    int dig = 1;

    int a;
    int cnt = 0;
    do{
        a = k*dig;
        dig *= k;
        ++cnt;
    }while(a <= n);

    cout << cnt << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 105

int G[MAX][MAX],n;

int main(void) {
  int u,k,v,i,j;
 
  scanf("%d",&n);
  for(i=0; i<n; i++){
    for(j=0; j<1 ;j++)
      G[i][j] = 0;
  }

  for(i=0; i<n; i++){
    scanf("%d%d",&u,&k);
    for(j=0; j<k; j++){
      scanf("%d",&v);
      G[u-1][v-1] = 1;
    }
  }
    
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
        if(j != n-1)
            printf("%d ",G[i][j]);
        else printf("%d\n",G[i][j]);
    }
  }

  return 0;
}









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

int main() {
	int N, M;
	cin >> N >> M;
	int a=0, b=0, c=0, x, y, z;
	dsu d(N);
	rep(i, M) {
		cin >> x >> y;
		x--, y--;
		d.merge(x, y);
	}
	vector<vector<int>> l = d.groups();
	cout << l.size()-1 << '\n';
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;


ll factorial(ll n) {
    ll ans = 1;
    for(ll i = 1; i <= n; i++){
        ans *= i;
    }
    return ans;
}

int main() {
    int n, p; cin >> n >> p;
    int od = 0, ev = 0;
    for(int i = 0; i < n; i++) {
        int a; cin >> a;
        if(a & 1) od++;
        else ev++;
    }

    if(od == 0){
        ll ans = pow(2, n);
        if(p == 0) cout << ans<< endl;
        else cout << 0 << endl;
    }else{
        ll ans = pow(2, n - 1);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 4068
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            var expr = Console.ReadLine().Split(' ');
            var a = int.Parse(expr[0]);
            var op = expr[1];
            var b = int.Parse(expr[2]);
            if (op.Equals("+"))
            {
                Console.WriteLine(a + b);
            }
            else
            {
                Console.WriteLine(a - b);
            }
        }
    }
}

Measured memory_bytes: 2648
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	i64 n; scanf("%lld", &n);
	
	printf("%lld\n", n * (n - 1) / 2);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

#define MAX 10000
#define NIL -1
struct Node { int p, l, r; };
Node T[MAX];

void preParse(int u) {
    if(u == NIL) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParese(int u) {
    if(u == NIL) return;
    inParese(T[u].l);
    printf(" %d", u);
    inParese(T[u].r);
}

void postParse(int u) {
    if(u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    int n, i, v, l, r, root;
    scanf("%d", &n);
    for(i=0; i<n; ++i) T[i].p = NIL;
    for(i=0; i<n; ++i) {
        scanf("%d%d%d", &v, &l, &r);
        T[v].l = l, T[v].r = r;
        if(l != NIL) T[l].p = v;
        if(r != NIL) T[r].p = v;
    }
    for(i=0; i<n; ++i) 
        if(T[i].p == NIL) root = i;

    printf("Preorder\n"); preParse(root);
    printf("\nInorder\n"); inParese(root);
    printf("\nPostorder\n"); postParse(root);
    printf("\n");

    return 0;
}



Measured memory_bytes: 2760
(function(input) {
  var p = input.replace(/\n$/, '').split('\n');
  while (true) {
    var a = p.shift().split(' ').map(Number);
    var m = a.shift();
    var d = a.shift();
    if (m === 0 && d === 0) {
      return;
    }
    var date = new Date(2004, m - 1, d);
    //console.log(date);
    console.log(getWeekDay(date.getDay()) );
  }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function getWeekDay(d) {
  var week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  return week[d];
}

Measured memory_bytes: 7596
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using namespace std;


signed main(){
	int N, M;
	cin >> N >> M;

	cout << (1900*M+100*(N-M))*(int)pow(2, M) << endl;

	return 0;
}

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

#define int long long
#define mod 1000000007
#define p pair<int,int>
#define MAX 1000010

using namespace std;

int a[MAX],b[MAX];
bool vis[MAX];

vector <int> v;
vector <p> vp;
set <int> s;
set <p> sp;
map <int,int> m;
unordered_map <int,int> um;
queue <int> bq;

int32_t main()
{
    um.reserve(1<<15);
    um.max_load_factor(0.25);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s1,s2;
    cin >> s1 >> s2;

    for(int i:s1)
        a[i-'a']++;

    for(int i:s2)
        b[i-'a']++;

    multiset <int> s3,s4;

    for(int i=0;i<26;i++)
    {
        s3.insert(a[i]);
    }

    for(int i=0;i<26;i++)
    {
        s4.insert(b[i]);
    }

    if(s3 == s4)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}

Measured memory_bytes: 3220
import java.lang.StringBuilder

fun main(arr:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val waCount = (1..n).map { 0 }.toMutableList()
    val acCount = (1..n).map { 0 }.toMutableList()
    (1..m).forEach {
        val (p,s) = readLine()!!.split(" ")
        val mon = p.toInt()-1
        if(s == "AC") {
            acCount[mon]++
        } else if(acCount[mon] > 0) {
        } else {
            waCount[mon]++
        }
    }
    var ansWa = 0
    var ansAc = 0
    (0 until n).forEach {
        if(acCount[it] > 0) {
            ansAc++
            ansWa += waCount[it]
        }
    }
    println("%s %s".format(ansAc, ansWa))
}


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

using namespace std;
static const int INF = 999999999;
struct SEdge
{
	unsigned long long int From;
	unsigned long long int To;
	unsigned long long int Cost;
};
unsigned long long int V;
vector<int> d;
vector<SEdge> Edge;

void Bellman_Ford(int s)
{
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	bool update = true;
	while(update)
	{
		update = false;
		int n = Edge.size();
		for(int i = 0; i < n; ++i)
		{
			SEdge e = Edge[i];
			if(d[e.From] != INF && d[e.To] > d[e.From] + e.Cost)
			{
				d[e.To] = d[e.From] + e.Cost;
				update = true;
			}
		}
	}
}

void solve()
{
	int E;
	while(cin >> E, E)
	{
		V = 0;
		Edge.clear();
		Edge.resize(2 * E);
		for(int i = 0; i < E; ++i)
		{
			unsigned long long int From, To, Cost;
			cin >> From >> To >> Cost;
			V = max(V, max(From, To));
			Edge[2 * i + 1].To = Edge[2 * i].From = From;
			Edge[2 * i + 1].From = Edge[2 * i].To = To;
			Edge[2 * i + 1].Cost = Edge[2 * i].Cost = Cost;
		}
		++V;
		d.clear();
		d.resize(V);
		unsigned long long int Min = INF;
		int pos = 0;
		for(int i = 0; i < V; ++i)
		{
			Bellman_Ford(i);
			unsigned long long int sum = 0;
			for(int j = 0; j < V; ++j)
			{
				sum += d[j];
			}
			if(Min > sum)
			{
				Min = sum;
				pos = i;
			}
		}
		cout << pos << " " << Min << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

int calc(int n, int k, int c[]) {
  int res = 0;
  int seki = 1;
  for(int i = 0; i < n; ++i) {
    if(i-k >= 0) seki /= c[i-k];
    seki *= c[i];
    if(i+1 >= k) res = max(res,seki);
  }
  return res;
}

int main() {
  int n, k, c[101];
  while(cin >> n >> k && (n|k)) {
    for(int i = 0; i < n; ++i) {
      cin >> c[i];
    }
    int C0 = calc(n,k,c);
    int C1 = 0;
    for(int i = 0; i < n; ++i) {
      for(int j = i+1; j < n; ++j) {
	swap(c[i],c[j]);
	C1 = max(C1, calc(n,k,c));
	swap(c[i],c[j]);
      }
    }
    if(C1-C0 < 0) cout << "NO GAME" << endl;
    else cout << C1-C0 << endl;
  }
  return 0;
}

Measured memory_bytes: 864
K, A, B = map(int, input().split())
p = 1
if A + 2 >= B:
    print(1+K)
else:
    K = K - (A-1)
    p = A
    m = K // 2
    n = K % 2
    p += m * (B-A) + n
    print(p)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int main() 
{
	int z0=0,z1=0;
	string s;
	cin>>s;
	int len=s.length();
	for (int i=0;i<len;i++)
	{
		if (s[i]==49)
		{
			z1++;
		}
		else if (s[i]==48) z0++;
	}
	cout<<min(z0,z1)*2;
}

Measured memory_bytes: 512
N = int(input())
util = [[int(i) for i in input().split()] for _ in range(N)]
"""
memo = [0 for _ in range(N + 1)]
def dp(i, u, rem_i):
    if i == N:
        return u
    elif i == 0:
        ret = max(dp(i + 1, u+util[i][0], 0), dp(i + 1, u+util[i][1], 1), dp(i + 1, util[i][2], 2))
    else:
        index = list({0, 1, 2} - {rem_i})
        ret = max(dp(i + 1, u+util[i][index[0]], index[0]), dp(i + 1, u+util[i][index[1]], index[1]))
    memo[i] = ret
    print(memo)
    return ret

print(dp(0, 0, 3))
"""

memo = [{} for i in range(N)]
for i in range(3):
    memo[-1][i] = util[-1][i]
for i in range(N-2, -1, -1):
    for j in range(3):
        memo[i][j] = util[i][j] + max(memo[i+1][k] for k in range(3) if j != k)
print(max(memo[0].values()))

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

int main() {

	int N;
	string S;
	cin >> N >> S;

	int min = 0;
	int Wcount = 0;
	if (S.at(0) == 'W') Wcount++;
	for (int i = 1; i < N; i++) {
		if (S.at(i) == 'W') { Wcount++; continue; }
		if (min + 1 > Wcount) min = Wcount;
		else min++;
	}

	cout << min << endl;

	return 0;
}

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

#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  int a[5], i, p = 0;
  
  REP(i, 5){
    cin >> a[i];
    if (a[i] < 40) a[i] = 40;
    p += a[i];
  }
  cout << p / 5 << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;

int a[N],b[N];

vector<int> adj[N];

bool used[N];
bool vis[N];

int par[N];
bool dfs(int node,int last) {
   vis[node] = true;
   if(node==last) {
      return true;
   }
   for(int i=0;i<adj[node].size();++i) {
      int id = adj[node][i];
      int ch = a[id]^b[id]^node;
      if(used[id]) {
         continue;
      }
      if(vis[ch] ) {
         continue;
      }
      par[ch] = id;
      if(dfs(ch,last)){
         return true;
      }
   }
   return false;
}

void solve() {
   int n,m;
   scanf("%d%d",&n,&m);
   for(int i=0;i<m;++i) {
      scanf("%d%d",&a[i],&b[i]);
      adj[a[i]].push_back(i);
      adj[b[i]].push_back(i);
   }
   vector<int> four;
   int numberofSix = 0;
   for(int i=1;i<=n;++i) {
      if(adj[i].size()>=6) {
         ++numberofSix;
      } else if(adj[i].size()==4) {
         four.push_back(i);
      }
      if(adj[i].size()%2 != 0 ){
         printf("No\n");
         return;
      }
   }
   if(numberofSix || four.size()>=3) {
      printf("Yes\n");
      return;
   }

   if(four.size()==2) {
      bool lastVis = false;
      for(int i=0;i<3;++i) {
         memset(vis,0,sizeof(vis));
         int st = four[0], ed = four[1];
         lastVis = dfs(st,ed);
         while(ed!=st) {
            int id = par[ed];
            used[id] = true;
            int nn = a[id]^b[id]^ed;
            ed = nn;
         }
      }
      if(lastVis) {
         printf("No\n");
      } else {
         printf("Yes\n");
      }
   } else {
      printf("No\n");
   }
}
int main()
{
    //freopen("input.txt","r",stdin);
    solve();
}


Measured memory_bytes: 8192
def print_list(ele_list):
    print(" ".join(map(str, ele_list)))

def insertion_sort(ele_list):
    len_ele_list = len(ele_list)
    print_list(ele_list)
    for i in range(1, len_ele_list):
        key = ele_list[i]
        j = i - 1
        while j >= 0 and ele_list[j] > key:
            ele_list[j+1] = ele_list[j]
            j -= 1
        ele_list[j+1] = key
        print_list(ele_list)

N = int(input())
ele_list = list(map(int, input().split()))

insertion_sort(ele_list)

Measured memory_bytes: 7672
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();

		int ans = 0;
		if (a >=1 && a<=9 && b>=1 &&b<=9) {
			ans = a * b;
		} else {
			ans = -1;
		}

		System.out.println(ans);
	}

}

Measured memory_bytes: 23764
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int a[1005];
double sum;
int main()
{
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
	{
		scanf("%d",&a[i]);
		sum+=1.00000/a[i];
	}
	sum=1.00000/sum;
	printf("%lf",sum);
    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define repr(i, n) for(int i=(n-1); 1<=i; i--)
#define repr2(i, from, to) for(int i=(from-1); (int)(to)<=i; i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int to, cost; };
struct gNode { int from, to, cost; };
struct tNode { int value; int parent; vector<int> child; };


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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n/2);
	if(n & 1) res = res * x % MOD;
	return res;
}

int main(void){
	int n; cin >> n;
	vector<int> b(n);
	rep(i, n-1) cin >> b[i];
	b[n-1] = INF;

	int ans = 0;
	rep(i, n){
		if(i == 0) ans += b[i];
		else ans += min(b[i-1], b[i]);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main() {
	u64 N;
	cin >> N;
	
	vector<u64> A(N);
	
	for(u64 t=0; t<N-1; t++) {
		u64 a;
		cin >> a;
		A[a-1]++;
	}
	
	for(u64 t=0; t<N; t++) {
		cout << A[t] << endl;
	}
	return 0;
}

Measured memory_bytes: 4844
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}
vector<string> ans;
int n;
string s;
char al[12] = {'a','b','c','d','e','f','g','h','i','j','k','l'};


void dfs(string ss){
//    cout<<"333"<<endl;
//    cout<<ss<<endl;



    if(ss.size()==n){
//        cout<<"push"<<ss<<endl;
        ans.push_back(ss);
    }else{
        int k=ss.size();
        map<char,int> m;
        rep(i,ss.size()){
            m[ss[i]]++;
        }
        int msi = m.size();
        rep(i,msi+1){
            string s2 = ss+al[i];
            dfs(s2);
        }

//        if(m.size()==1){
//            rep(i,2){
//                string s2 = ss+al[i];
//                dfs(s2);
//            }
//        }else {
//
//            rep(i,k){
//                string s2 = ss+al[i];
//                dfs(s2);
//            }
//        }
    }



}

int main(){
    cin>>n;
    s='a';

    dfs(s);

    sort(ans.begin(),ans.end());
    //cout<<ans.size()<<endl;
    rep(i,ans.size()){
        cout<<ans[i]<<endl;
    }




    
return 0;
}


Measured memory_bytes: 9588
n,a = map(int,input().split())
x = list(map(int,input().split()))
max_x = max(max(x),a)
dp = [[[0]*(n*max_x+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 1
for i in range(n+1):
  for j in range(n+1):
    for k in range(n*max_x+1):
      if i>=1 and k < x[i-1]:
        dp[i][j][k] = dp[i-1][j][k]
      elif i>=1 and j>= 1 and k>= x[i-1]:
        dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]]
      else:
        continue
ans = 0
for j in range(1,n+1):
    ans += dp[n][j][j*a]
print(ans)

Measured memory_bytes: 92636
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

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

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

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

	int H, W, K; cin >> H >> W >> K;
	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	x1--, y1--, x2--, y2--;

	int INF = 100000000;

	vector<vector<bool>> C(H);
	vector<vector<int>> ans(H);
	for (int i = 0; i < H; i++) {
		C[i].resize(W);
		ans[i].resize(W);
		string s; cin >> s;
		for (int j = 0; j < W; j++) {
			ans[i][j] = INF;
			C[i][j] = (s[j] == '.');
		}
	}

	queue<pair<int, int>> q;
	q.push({ x1, y1 });
	ans[x1][y1] = 0;

	while (q.size() > 0) {
		int i0 = q.front().first;
		int j0 = q.front().second;
		q.pop();
		int n = ans[i0][j0];
		for (int k = 1; k <= K; k++) {
			int i, j;
			i = i0 - k, j = j0;
			if (i < 0 || i >= H || j < 0 || j >= W || C[i][j] == false || ans[i][j] < n + 1) { break; }
			if (ans[i][j] > n + 1) {
				ans[i][j] = n + 1;
				q.push({ i,j });
			}
		}
		for (int k = 1; k <= K; k++) {
			int i, j;
			i = i0 + k, j = j0;
			if (i < 0 || i >= H || j < 0 || j >= W || C[i][j] == false || ans[i][j] < n + 1) { break; }
			if (ans[i][j] > n + 1) {
				ans[i][j] = n + 1;
				q.push({ i,j });
			}
		}
		for (int k = 1; k <= K; k++) {
			int i, j;
			i = i0, j = j0 + k;
			if (i < 0 || i >= H || j < 0 || j >= W || C[i][j] == false || ans[i][j] < n + 1) { break; }
			if (ans[i][j] > n + 1) {
				ans[i][j] = n + 1;
				q.push({ i,j });
			}
		}
		for (int k = 1; k <= K; k++) {
			int i, j;
			i = i0, j = j0 - k;
			if (i < 0 || i >= H || j < 0 || j >= W || C[i][j] == false || ans[i][j] < n + 1) { break; }
			if (ans[i][j] > n + 1) {
				ans[i][j] = n + 1;
				q.push({ i,j });
			}
		}
	}

	if (ans[x2][y2] == INF) {
		cout << -1 << endl;
	}
	else {
		cout << ans[x2][y2] << endl;
	}

	return 0;
}

Measured memory_bytes: 8608
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-18 11:00:50
*/

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

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int a, b;
    cin >> a >> b;

    string ans = "Possible";
    if (a%3 && b%3 && (a+b)%3) ans = "Impossible";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main(){
	int k,n,x;
	char s[105];
	
	scanf("%d",&k);
	scanf("%s",s);
	
	//文字列の長さを知りたい
	n = strlen(s);
	
	if(n<=k){
		printf("%s",s);
	}
	else {
		//入力された文字数n-先頭k文字 
		x = n - k;
		
//		printf("x = %d \n",x);
//		printf("mojisuu n = %d \n",n);
		
		for(int i=0;i<k;i++){
			printf("%c",s[i]);				
		}
			printf("...");
	}
	
	return 0;
}


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

#define M 1000005
#define MOD 1000000007
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> PII;

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

//    freopen("input.txt","rt",stdin);

    int ht,st,ha,sa;
    cin>>ht>>st>>ha>>sa;
    
    int turn = 0;
    while(true)
    {
        if(ha<=0 || ht<=0)
            break;
        else
        {
            if(turn%2==0)
            {
                ha = ha - st;
            }
            else
            {
                ht = ht - sa;
            }
        }
        turn++;
    }

    if(ha<=0 && ht>0)
        cout<<"Yes\n";
    else if(ha>0 && ht<=0)
        cout<<"No\n";
}



Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
    private static int[] balls = new int[10];
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        for (int j = 0; j < N; j++) {
            for (int i = 0; i < 10; i++) {
                balls[i] = input.nextInt();
            }
            if (solveBall(0, 0, 0))
                System.out.println("YES");
            else
                System.out.println("NO");
        }
    }
    private static boolean solveBall(int n, int leftRoot, int rightRoot) {
        if (n == 9 && (balls[n] > leftRoot || balls[n] > rightRoot)) return true;
        if (balls[n] < leftRoot && balls[n] < rightRoot) return false;
        if (balls[n] > leftRoot) {
            return solveBall(n+1, balls[n], rightRoot);
        }
        if (balls[n] > rightRoot) {
            return solveBall(n + 1, leftRoot, balls[n]);
        }
        return false;
    }
}

Measured memory_bytes: 26148