akhauriyash/Code-Regression huggingface dataset:
def factorial(n):
    if n == 1 or n == 0:
        return int(1)
    return int(n*factorial(n-1))

def nck(n,k):
    return int(factorial(n)/(factorial(n-k)*factorial(k)))

ans = 0
ans2 = 0
N,A,B = map(int,input().split())
v = list(map(int,input().split()))
v.sort()
for i in range(A,B+1):
    ans = max(ans,sum(v[N-i:N])/i)
print("{:.7f}".format(ans))

for i in range(A,B+1):
    if ans == sum(v[N-i:N])/i:
        n = v.count(v[N-i])
        k = i - len([p for p in v if p > v[N-i]])
        ans2 += nck(n,k)
print(int(ans2))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 100001
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<P1,ll> P2;
typedef list<int> li;
typedef list<li> lli;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	ll a;
	int b;
};
ll dp[2001][2001]={};

int main(){

	int s;
	cin>>s;
	ll ans=0;
	for(int i=3; i<s+1; i++)dp[i][1]=1;

	ans+=dp[s][1];
	for(int i=2; i<s/3+1; i++){
		for(int j=3*i; j<s+1; j++){
			dp[j][i]=dp[j-1][i];
			dp[j][i]+=dp[j-3][i-1];
			dp[j][i]%=i197;
		}
		ans+=dp[s][i];
		ans%=i197;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 16724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)



int main () {

	string s;
	cin >> s;
	int l = 0;
	int ans = 0;

	for(auto c:s){
		if(c=='R'){
			l++;
		}else{
			l--;
		}
		if(l==4){
			ans++;
			l = 0;
		}else if(l==-4){
			l = 0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3204
n,m = map(int,input().split())
for x in range(n+1):
  for y in range(n+1):
    z = n - x - y
    if (10000*x + 5000*y + 1000*z == m and x + y + z == n and 0 <= z <=n):
        print(x,y,z)
        exit()
print('-1 -1 -1')

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  int n,ans;
  scanf("%d",&n);
  if(n < 112){
    ans = 111;
  }else if(n < 223){
    ans = 222;
  }else if(n < 334){
    ans = 333;
  }else if(n < 445){
    ans = 444;
  }else if(n < 556){
    ans = 555;
  }else if(n < 667){
    ans = 666;
  }else if(n < 778){
    ans = 777;
  }else if(n < 889){
    ans = 888;
  }else{
    ans = 999;
  }
  printf("%d\n",ans);
  return 0;
}

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

int main() {
	int x;
	cin >> x;
	if (x == 0) cout << 1 << endl;
	else if (x == 1) cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 3592
package main

import "fmt"

func main() {
	// Code for B - Qualification simulator
	var N, A, B int
	fmt.Scan(&N, &A, &B)

	var S string
	fmt.Scan(&S)

	var a, b int
	for i := 0; i < N; i++ {
		if S[i] == 'a' {
			a++
			if a+b <= A+B {
				fmt.Println("Yes")
			} else {
				fmt.Println("No")
			}
		} else if S[i] == 'b' {
			b++
			if a+b <= A+B && b <= B {
				fmt.Println("Yes")
			} else {
				a--
				fmt.Println("No")
			}
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 2568
import math
results = []

while True:
    n = int(input())
    if n == 0:
        break

    s = list(map(float, input().split()))
    mean = sum(s)/len(s) 
    s = list(map(lambda x: (x - mean)**2, s))
    d = math.sqrt(sum(s)/ len(s))
    results.append(d)

for result in results:
    print(result)



Measured memory_bytes: 5776
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 1 << 19, mod = 924844033, G = 5, Gi = 554906420;
int fac[N], invfac[N];
inline int kasumi(int a, int b){
	int res = 1;
	while(b){
		if(b & 1) res = (LL) res * a % mod;
		a = (LL) a * a % mod;
		b >>= 1;
	}
	return res;
}
inline void init(int m){
	fac[0] = 1;
	for(Rint i = 1;i <= m;i ++) fac[i] = (LL) i * fac[i - 1] % mod;
	invfac[m] = kasumi(fac[m], mod - 2);
	for(Rint i = m;i;i --) invfac[i - 1] = (LL) invfac[i] * i % mod;
}
int n, siz[N], A[N], B[N], head[N], to[N << 1], nxt[N << 1];
inline void add(int a, int b){
	static int cnt = 0;
	to[++ cnt] = b; nxt[cnt] = head[a]; head[a] = cnt;
}
inline void dfs(int x, int f = 0){
	siz[x] = 1;
	for(Rint i = head[x];i;i = nxt[i])
		if(to[i] != f){
			dfs(to[i], x);
			siz[x] += siz[to[i]];
		}
}
int rev[N];
inline int calrev(int len){
	int limit = 1, L = -1;
	while(limit <= len){limit <<= 1; L ++;}
	for(Rint i = 0;i < limit;i ++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << L);
	return limit;
}
inline void NTT(int *A, int limit, int type){
	for(Rint i = 0;i < limit;i ++)
		if(i < rev[i]) swap(A[i], A[rev[i]]);
	for(Rint mid = 1;mid < limit;mid <<= 1){
		int Wn = kasumi(type == 1 ? G : Gi, (mod - 1) / (mid << 1));
		for(Rint j = 0;j < limit;j += mid << 1){
			int w = 1;
			for(Rint k = 0;k < mid;k ++, w = (LL) w * Wn % mod){
				int x = A[j + k], y = (LL) w * A[j + k + mid] % mod;
				A[j + k] = (x + y) % mod;
				A[j + k + mid] = (x - y + mod) % mod;
			}
		}
	}
	if(type == -1){
		int inv = kasumi(limit, mod - 2);
		for(Rint i = 0;i < limit;i ++) A[i] = (LL) A[i] * inv % mod;
	}
}
int main(){
	scanf("%d", &n);
	init(n << 1);
	for(Rint i = 1;i < n;i ++){
		int x, y;
		scanf("%d%d", &x, &y);
		add(x, y); add(y, x);
	}
	dfs(1);
	for(Rint i = 2;i <= n;i ++) ++ A[siz[i]], ++ A[n - siz[i]];
	for(Rint i = 0;i <= n;i ++){
		A[i] = (LL) A[i] * fac[i] % mod;
		B[i] = invfac[n - i];
	}
	int limit = calrev(n << 1);
	NTT(A, limit, 1); NTT(B, limit, 1);
	for(Rint i = 0;i < limit;i ++) A[i] = (LL) A[i] * B[i] % mod;
	NTT(A, limit, -1);
	for(Rint i = n + 1;i <= (n << 1);i ++) printf("%d\n", ((LL) n * fac[n] % mod * invfac[i - n] % mod * invfac[(n << 1) - i] % mod - (LL) A[i] * invfac[i - n] % mod + mod) % mod);
}

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

int main()
{
    int n,m,x;
    long long int sum=0;
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        cin>>x;
        sum+=x;
    }
    if(sum>n)
        cout<<-1<<endl;
    else cout<<n-sum<<endl;
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
	int price, quantity;
	int sum=0, average, sum_q=0;
	int n=0;
	while( scanf("%d,%d", &price, &quantity) != EOF ){
		n++;
		sum += price*quantity;
		sum_q += quantity;
	}
	double tmp = (double)sum_q/n;
	double  ave = round(tmp);
	average = (int) ave;
	
	cout<<sum<<endl<<average<<endl;
	return 0;
}

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

int main(void)
{
    char s[11];
    scanf("%s", s);
    char a[3]="hi";
    char b[5]="hihi";
    char c[7]="hihihi";
    char d[9]="hihihihi";
    char e[11]="hihihihihi";
    if(strcmp(s,a)==0||strcmp(s,b)==0||strcmp(s,c)==0||strcmp(s,d)==0||strcmp(s,e)==0){
        printf("Yes");
    }else{
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

struct DICE {
	int top;
	int north;
	int south;
	int east;
	int west;
	int bottom;
};
struct DICE dice[100];

void N(int I) {
	int num[6];
	num[0] = dice[I].top; num[1] = dice[I].south; num[2] = dice[I].east;
	num[3] = dice[I].west; num[4] = dice[I].north; num[5] = dice[I].bottom;
	dice[I].top = num[1]; dice[I].south = num[5]; dice[I].east = num[2];
	dice[I].west = num[3]; dice[I].north = num[0]; dice[I].bottom = num[4];
}
void S(int I) {
	int num[6];
	num[0] = dice[I].top; num[1] = dice[I].south; num[2] = dice[I].east;
	num[3] = dice[I].west; num[4] = dice[I].north; num[5] = dice[I].bottom;
	dice[I].top = num[4]; dice[I].south = num[0]; dice[I].east = num[2];
	dice[I].west = num[3]; dice[I].north = num[5]; dice[I].bottom = num[1];
}
void E(int I) {
	int num[6];
	num[0] = dice[I].top; num[1] = dice[I].south; num[2] = dice[I].east;
	num[3] = dice[I].west; num[4] = dice[I].north; num[5] = dice[I].bottom;
	dice[I].top = num[3]; dice[I].south = num[1]; dice[I].east = num[0];
	dice[I].west = num[5]; dice[I].north = num[4]; dice[I].bottom = num[2];
}
void W(int I) {
	int num[6];
	num[0] = dice[I].top; num[1] = dice[I].south; num[2] = dice[I].east;
	num[3] = dice[I].west; num[4] = dice[I].north; num[5] = dice[I].bottom;
	dice[I].top = num[2]; dice[I].south = num[1]; dice[I].east = num[5];
	dice[I].west = num[0]; dice[I].north = num[4]; dice[I].bottom = num[3];
}

int Roll(int I, int J) {
	for (int i = 0; i < 6; i++) {
		for (int j = 0; j < 4; j++) {
			if (dice[J].south == dice[I].south&&dice[J].top == dice[I].top&&dice[J].east == dice[I].east&&dice[J].west == dice[I].west&&dice[J].north == dice[I].north&&dice[J].bottom == dice[I].bottom) {
				return 1;
			}
			else {
				N(I); W(I); S(I);
			}
		}
		if (i < 3) N(I);
		else if (i == 3) E(I);
		else {
			E(I); E(I);
		}
	}
	return 0;
}

int main() {
	int n;
	int nums[6];
	int flag;
	int FLAG = 0;
	scanf("%d", &n);
	for (int I = 0; I < n; I++) {
		for (int i = 0; i < 6; i++) {
			scanf("%d", &nums[i]);
		}
		dice[I].top = nums[0]; dice[I].south = nums[1]; dice[I].east = nums[2];
		dice[I].west = nums[3]; dice[I].north = nums[4]; dice[I].bottom = nums[5];
	}

	for (int I = 0; I < n; I++) {
		for (int J = 0; J < n; J++) {
			if (I >= J)continue;
			flag = Roll(I, J);
			if (flag == 1) {
				FLAG = 1;
				break;
			}
			else continue;
		}
	}
	if (FLAG)printf("No\n");
	else printf("Yes\n");
	return 0;
}


Measured memory_bytes: 2104
#include<stdio.h>

int main()
{
	int student;
	int yet[30];
	int i;
	int temp;
	
	for(i=0;i<30;i++)
		yet[i]=0;
	
	for(i=0;i<28;i++)
	{
		scanf("%d",&student);
		temp=student;
		yet[temp-1]=1;
	}
	
	for(i=0;i<30;i++)
	{
		if(yet[i]==0)printf("%d\n",i+1);
	}
	
	return 0;
}

Measured memory_bytes: 596
import sys

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, K, L = map(int,input().split())
uf_road = UnionFind(N)
uf_train = UnionFind(N)

for i in range(K):
    p,q = map(int,input().split())
    p -= 1
    q -= 1
    uf_road.union(p,q)

for i in range(L):
    p,q = map(int,input().split())
    p -= 1
    q -= 1
    uf_train.union(p,q)

pair_list = []
for i in range(N):
    pair_list.append((uf_road.find(i), uf_train.find(i), i))

pair_list.sort()
ans = [0] * N

pair = (pair_list[0][0], pair_list[0][1])
countup_list = [pair_list[0][2]]
for i in range(1,N):
    if pair == (pair_list[i][0], pair_list[i][1]):
        countup_list.append(pair_list[i][2])
    else:
        for c in countup_list:
            ans[c] += len(countup_list)
        pair = (pair_list[i][0], pair_list[i][1])
        countup_list = [pair_list[i][2]]

for c in countup_list:
    ans[c] += len(countup_list)
    
for i in range(N):
    print(ans[i], end=" ")

Measured memory_bytes: 35048
/**
 *    AUTHOR:    __SIGSEGV__                  
 *   CREATED:   12.08.2020 21:05:41  
**/

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  vector<bool> visited(k + 1, false);
  int rem = 0, ans = -1;
  for (int i = 0; i <= k; i++) {
    rem = (rem * 10 + 7) % k;
    if (!rem) {
      ans = i + 1;
      break;
    }
  }    
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

ll pow(ll a, ll x) {
    ll ret = 1;
    while(1) {
        if (x == 0) break;
        if (x&1) ret = ret * a % mod;
        a = a * a % mod;
        x >>= 1;
    }
    return ret;
}

ll inv(ll a) {
    return pow(a, mod-2);
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> a_accum(n+1, 0);
    rep(i, n) {
        cin >> a[i];
        a_accum[i+1] = (a_accum[i] + a[i]) % mod;
    }
    ll ans = 0;
    rep(i, n) {
        ll tmp = ((a_accum[n] - a[i]) < 0) ? a_accum[n] - a[i] + mod : a_accum[n] - a[i];
        ans = (ans + tmp * a[i] % mod) % mod;
    }
    //cout << inv(2LL) << endl;
    cout << ans * inv(2LL) % mod << endl;

    return 0;
}


Measured memory_bytes: 6380
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int a, b;
	cin >> a >> b;
	for (int i = 1; i <= 1000000; ++i)
	{
		if ((i * 8) / 100 == a && b == (i * 10) / 100)
			return cout << i, 0;
	}
	cout << -1;
	return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
import sys


def read():
    return sys.stdin.readline().rstrip()


def add(arr, i, x):
    while i < len(arr):
        arr[i] += x
        i += i & -i


def range_sum(arr, a, b):
    s = 0
    i = b
    while i > 0:
        s += arr[i]
        i -= i & -i
    i = a - 1
    while i > 0:
        s -= arr[i]
        i -= i & -i
    return s


def main():
    n, q = map(int, read().split())
    c = [int(i) - 1 for i in read().split()]
    queries = iter(sorted([[i] + [int(j) for j in read().split()] for i in range(q)], key=itemgetter(2)))
    last = [0] * n
    bit = [0] * (n + 1)
    ans = [-1] * q
    k, l, r = next(queries)
    for i in range(n):
        ci = c[i]
        li = last[ci]
        if li > 0:
            add(bit, li, -1)
        last[ci] = i + 1
        add(bit, i + 1, 1)
        while i + 1 == r:
            ans[k] = range_sum(bit, l, r)
            try:
                k, l, r = next(queries)
            except StopIteration:
                break
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 239132
#include <stdio.h>

int main (void){
    int a, b, c;    //  A, B, Cの初期値
    int k;          //  操作可能な回数
    
    scanf("%d%d%d", &a, &b, &c);
    scanf("%d", &k);
    
    for (int i = 0; i < k; i++) {
        if (a < b && b < c) {
            continue;
        }
//        aを2倍することはありえない；問題は「bとcのどちらを2倍するか？」に尽きる
        else if (c <= b) {
            c *= 2;
        }
        else if (b <= a && b <= c) {
            b *= 2;
        }
    }

//    ループの結果、期待通りに並んで場合は「Yes」、それ以外は「No」を表示する
    if (a < b && b < c) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
int iinf=1<<30;
double pi=3.141592653589793238462643383279L;
double eps=1e-8;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
//#define endl "\n"
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<int,int,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int h,w;cin>>h>>w;
    int k;cin>>k;
    int ans=0;
    string s[h];
    rep(i,0,h)cin>>s[i];
    rep(i,0,1<<h){
        rep(j,0,1<<w){
            int sum=0;
            rep(ii,0,h){
                rep(jj,0,w){
                    if(((i>>ii)&1)||((j>>jj)&1))continue;
                    if(s[ii][jj]=='#')sum++;
                }
            }
            if(sum==k)ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
n = gets.to_i
p = n.times.map do
  t, x, y = gets.split.map(&:to_i)
  { t: t, x: x, y: y }
end
p = p.unshift({ t: 0, x: 0, y: 0 })

def verify_move_amount(time_diff, prev_x, prev_y, current_x, current_y)
  moves = (current_x - prev_x).abs + (current_y - prev_y).abs
  return false if time_diff < moves
  return true if time_diff == moves
  (time_diff - moves).even?
end

possible = (1..p.length-1).all? do |i|
  prev = p[i-1]
  current = p[i]
  time_diff = current[:t] - prev[:t]
  verify_move_amount(time_diff, prev[:x], prev[:y], current[:x], current[:y])
end

puts possible ? 'Yes' : 'No'


Measured memory_bytes: 36248
d = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())

print(d[k-1])

Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin >> N >> M;
  vector<vector<P>> G(N);
  for(int i=0; i<M; i++){
    int a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    G[a].emplace_back(-c,b);
  }
  vector<ll> dist(N,INF);
  dist[0] = 0;
  ll sum;
  for(int i=0; i<=2*N; i++){
    for(int v=0; v<N; v++){
      for(P suzu: G[v]){
        int nv,cost;
        tie(cost,nv) = suzu;
        chmin(dist[nv],dist[v]+cost);
      }
    }
    if(i == N-1){
      sum = dist[N-1];
    }
  }
  if(sum > dist[N-1]){
    cout << "inf\n";
  }else{
    cout << -sum << "\n";
  }

  return 0;
}

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

#define ll long long
#define vec vector<ll>
#define sortv(a); sort(a.begin(), a.end());
#define rev(a); reverse(a.begin(), a.end());
#define FOR(i,a,b) for (ll i = (ll)(a); i < (b); i++)
#define ROF(i,a,b) for (ll i = (ll)(b)-1; i >= (a); i--)

ll MOD = 1000000007;
ll INF = 1LL << 60;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	ll n,m;cin>>n>>m;
	ll out;
	if (n==1&&m==1) {
		out=1;
	} else if (n==1) {
		out=max(0,(int)m-2);
	} else if (m==1) {
		out=max(0,(int)n-2);
	} else {
		out=(m-2)*(n-2);
	}

	cout<<out;
}

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


using namespace std;

int H, N;
string S;


int main()
{

    cin >> S;



    if (S == "AAA" || S == "BBB") {
        cout << "No" << "\n";

    } else {
        cout << "Yes" << "\n";
    }


}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n,x;	//1??????????????§?????°???????¨???????
		int count;	//????¨???°
		StringBuilder sb = new StringBuilder();
		
		while (true) {
			count=0;
			n=sc.nextInt();
			x=sc.nextInt();
			
			//0 0????????????
			if(n==0 && x==0){
				break;
			}
			
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				}
			}//for
			count/=6;
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 19816
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
   int n;
   string s;
   cin>>n>>s;
   bool flag=true;
   if(n%2!=0){
     cout<<"No"<<endl;
     return 0;
   }else{
     for(int i=0;i<(n/2);i++){
       if(s[i]!=s[i+(n/2)]) flag=false;
     }
   }
   if(flag) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}



Measured memory_bytes: 256
N = int(input())
table = []
for i in range(N):
    X,L = map(int,input().split())
    table.append((X-L,X+L))
table = sorted(table, key=lambda x:x[1])

cur = 0
l_cur, r_cur = table[0]
ans = N
for i in range(1,N):
    l,r = table[i]
    if r_cur > l:
        ans -= 1
    else:
        l_cur, r_cur = l,r
print(ans)

Measured memory_bytes: 24684
s=input()
n=len(s)
ans=""
import math
for i in range(1,n):
    if i%2==1:
        continue
    ss=s[:i]
    m=len(ss)
    p=0
    for j in range(m//2):
        if ss[j]!=ss[j+m//2]:
            p=1
            break
    if p==0:
        ans=ss
print(len(ans))





Measured memory_bytes: 3060
MOD = pow(10,9)+7
S = input()[::-1]
N = len(S)

DP = [[0]*13 for i in range(N)]
K = 1
for i in range(N):
    if S[i]=="?":
        for j in range(10):
            if i==0:
                DP[0][(j*K)%13] = 1
            else:
                for k in range(13):
                    DP[i][(j*K+k)%13] += DP[i-1][k]
    else:
        j = int(S[i])*K
        if i==0:
            DP[0][(j*K)%13] = 1
        else:
            for k in range(13):
                DP[i][(j+k)%13] += DP[i-1][k]
    K = (K*10)%13
    for j in range(13):
        DP[i][j] = DP[i][j]%MOD
print(DP[N-1][5]%MOD)

Measured memory_bytes: 63528
N,M = map(int, input().split())
X = [int(x) for x in input().split()]

if M <= N:
    ans = 0
elif N == 1:
    ans = max(X) - min(X)
else:
    X.sort()
    List = []
    for i in range(M-1):
        List.append(X[i+1]-X[i])
    List.sort()
    ans = 0
    for j in range(M-N):
        ans += List[j]

print(ans)

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

int main(){
  int N; cin >> N;
  int count;
  for (int i = 1; i <= 9; i++){
    for (int j = 1; j <= 9; j++){
      if (i * j == N){
        count++;
      }
      else {
        continue;
      }
    }
  }
  if (count != 0){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
x,y = readInts()
MAX = 10**18
if x%y == 0:
    print(-1)
    exit()
while x <= 10 ** 18:
    if x%y != 0:
        print(x)
        exit()
    x += x
print(-1)


Measured memory_bytes: 10340
n=int(input())
list_ = [input() for i in range(n)]
dic = {}
for a in list_:
    if a in dic:
        dic[a] += 1
    else:
        dic[a]   = 1
maxa = max(dic.values())
ans = [x for x, y in dic.items() if y == maxa]
for A in sorted(ans):
    print(A)

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

int main(){
  int m,n,max=0,total=0,i,j,**array;

  while(1){
    scanf("%d %d",&m,&n);
    if(m==0 && n==0)break;

    array = malloc(n*sizeof(int *));
    for(i=0;i<n;i++){
      array[i] = malloc(m*sizeof(int));
    }

    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
        scanf("%d",&array[i][j]);
      }
    }
        for(j=0;j<m;j++){
      for(i=0;i<n;i++){
        total += array[i][j];
      }
      if(max <= total){
        max = total;
      }
      total = 0;
    }
    printf("%d\n",max);
    max=0;

    for(j=0;j<n;j++){
      free(array[j]);
    }
    free(array);
  }
  return 0;
}




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

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var temp = Console.ReadLine().Split(' ');
			int a = int.Parse(temp[0]);
			int b = int.Parse(temp[1]);
			Console.WriteLine((a+b >=10)?"error":(a+b).ToString());
		}
	}
}

Measured memory_bytes: 13140
#include<stdio.h>

int main(void){
    int a,b,c,d;
    scanf("%d %d %d", &a, &b, &c);
    if ( a > b ) { d = 0; d = a ; a = b ; b = d; }
    if ( b > c ) { d = 0; d = b ; b = c ; c = d; }
    if ( a > b ) { d = 0; d = a ; a = b ; b = d; }
    printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

template <class T>
T GCD(T a, T b) { return b == 0 ? a : GCD(b, a%b); }

int main()
{
  ll N, M; string S, T;
  cin >> N >> M >> S >> T;

  ll l = N*M/GCD(N, M);

  int stepn = l/M;
  int stepm = l/N;

  for (int i = 0, j = 0; i < N && j < M; i+=stepn, j+=stepm) {
    if (S[i] != T[j]) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << l << endl;
}

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n; cin >> n;
  int res = 0;
  for(int i = 0; i < n; i++){
    int a; cin >> a;
    res ^= a;
  }
  cout << (res ? "No" : "Yes") << endl;


  return 0;
}


Measured memory_bytes: 256
def resolve():
    n = int(input())
    C = [0, 0]
    S = list(map(int, input().split()))
    for i in range(2):
        tmp = 0
        for j in range(n):
            tmp += S[j]
            if (i+j)%2==0:
                if tmp <= 0:
                    C[i] += abs(tmp) + 1
                    tmp = 1
            else:
                if tmp >= 0:
                    C[i] += abs(tmp) + 1
                    tmp = -1

    print(min(C[0], C[1]))

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 14332
#include "bits/stdc++.h"

#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)

using namespace std;

using I = int;
using L = long;
using F = float;
using S = string;
using SS = stringstream;
using C = char;
using LL = long long;
using VC = vector<char>;
using VI = vector<int>;
using VL = vector<long>;
using VF = vector<float>;
using VS = vector<string>;
using VVI = vector<vector<int>>;
using VVL = vector<vector<long>>;
using PLL = pair<long, long>;
using PLF = pair<long, float>;
using PLS = pair<long, string>;
using PSL = pair<string, long>;
using PSF = pair<string, float>;
using PSS = pair<string, string>;
using MLL = map<long, long>;
using MLF = map<long, float>;
using MLS = map<long, string>;
using MSL = map<string, long>;
using MSF = map<string, float>;
using MSS = map<string, string>;

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

template <class T>
void PrintVector(const vector<T> & v) {
  for (const auto & e: v) {
    cout << e << endl;
  }
}

template <class T>
void PrintVector(const vector<T> & v, I n) {
  rep(i, 0, n - 1) {
    cout << v[i] << endl;
  }
}

//
// int main(int argc, char const *argv[]) {
//   I w_cnt = 0;
//   cin >> h >> w;
//   rep(i, 0, h - 1) {
//     rep(j, 0, w - 1) {
//       char c;
//       cin >> c;
//       maze[i][j] = c;
//       if (c == '.') { ++w_cnt; }
//     }
//   }
//   auto min_len = BFS(0, 0, h - 1, w - 1);
//   if (min_len != kMax6) { cout << w_cnt - min_len - 1 << endl; }
//   else { cout << -1 << endl; }
//   return 0;
// }

int main(int argc, char const *argv[]) {
  L n, m;
  L ans;
  cin >> n >> m;
  if (n * m == 1) ans = 1;
  else if (n == 1) ans = m - 2;
  else if (m == 1) ans = n - 2;
  else ans = (n - 2) * (m - 2);

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


Measured memory_bytes: 256
#include<cstring>
#include<ios>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=26+3;
char s[MAXN],s2[MAXN];
int len;
bool vis[MAXN];
int main(){
	ios_base::sync_with_stdio(false);
	cin>>s;
	len=strlen(s);
	for(int i=0;i<len;i++){
		vis[s[i]-'a']=1;
	}
	if(len!=26){
		cout<<s;
		for(int i=0;i<26;i++){
			if(!vis[i]){
				char tt=i+'a';
				cout<<tt<<"\n";
				break;
			}
		}
		return 0;
	}
	for(int i=0;i<len;i++){
		s2[i]=s[i];
	}
	if(!next_permutation(s2,s2+len)){
		cout<<-1<<"\n";
		return 0;
	}
	for(int i=0;i<len;i++){
		cout<<s2[i];
		if(s[i]!=s2[i]){
			break;
		}
	}
	cout<<"\n";
	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

const ll INF = 400000000000;

// dp[i][n]: もっとも右側の列がiで、これまでの列数がnのときの最小コスト
ll dp[3100][3100];

signed main() {
  rep(i,3100) rep(j,3100) dp[i][j] = INF;
  ll N, K;
  cin >> N >> K;
  vector<ll> h(N+1, 0);
  for (ll i=1; i<=N; i++)
    cin >> h[i];
  dp[0][0] = 0;
  for (ll i = 1; i<= N; i++) for (ll n = 1; n<=N; n++) {
    for (ll j = 0; j <= i-1; j++) {
      dp[i][n] = min(dp[i][n], dp[j][n-1] + max((ll)0, h[i]-h[j]));
    }
  }

  ll ans = INF;
  for (ll i=0; i<=N; i++) {
    ans = min(ans, dp[i][N-K]);
  }
  cout << ans << endl;
}


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

main(){

  ll n;
  cin>>n;
  vector<ll> a(n+1);
  rep(i,n)cin>>a[i+1];

  vector<ll> b(n+1,0);
  for(ll i=n;i>0;--i){
    ll t=0,idx=i;
    while(idx+i<=n){
      idx+=i;
      t+=b[idx];
    }
    t%=2;
    if(a[i]==t)b[i]=0;
    else b[i]=1;
  }
  
  vector<ll> ans;
  rep(i,n)if(b[i+1])ans.push_back(i+1);
  cout<<ans.size()<<endl;
  if(ans.empty())return 0;
  for(auto x:ans)cout<<x<<" ";
  cout<<endl;

}

Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
int a[maxn];
typedef long long ll;
ll mod = 1e9+7;  // 1e9+9

ll add(ll x,ll y){return (x+y)%mod;}
ll mul(ll x,ll y){return (x*y)%mod;}

ll mpow(ll x,ll y){
  ll v=1;
  for(;y;x=mul(x,x),y>>=1)
    if(y&1)v=mul(v,x);
  return v;
}

ll divi(ll x,ll y){return mul(x,mpow(y,mod-2));}

ll fact[10000000]={1}, factc=0;
ll Fact(ll x){
  while( factc < x ){
    factc++;
    fact[factc]=mul( fact[factc-1] , factc );
  }
  return fact[x];
}

ll nCr(ll n,ll r){
    if(n<r)return 0;
  return divi( Fact(n) , mul( Fact(n-r) , Fact(r) )   );
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    debug(nCr(1,2));
    int n,k;cin>>n>>k;
    rep(i,1,n)cin>>a[i];
    sort(a+1,a+1+n);
    ll mx=0,mn=0;;
    rep(i,1,n){
        mx+=a[i]*nCr(i-1,k-1); 
        mn+=a[n-i+1]*nCr(i-1,k-1);
        mx=(mx%mod+mod)%mod;
        mn=(mn%mod+mod)%mod;
        //debug(mx),debug(mn);
    }
    cout<<((mx-mn)%mod+mod)%mod<<endl;
}
/* 

 */

Measured memory_bytes: 1408
//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    public static class Task {

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int l = sc.nextInt();
            String[] strings = new String[n];
            for (int i = 0; i < n; i++) {
                strings[i] = sc.next();
            }
            Arrays.sort(strings);
            StringBuilder sb = new StringBuilder();
            for (String x: strings) sb.append(x);
            pw.println(sb.toString());

        }
    }

    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("input"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("input"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  LL L, R;
  cin >> L >> R;
  LL M = 2019;
  LL mi = 2020;
  REP(b, L + 1, R+1){
    REP(a, L, b) {
      // DUMP(a, b);
      mi = min(mi, a * b % M);
      if(mi==0){
        cout<<mi<<endl;
        return 0;
      }
    }
  }
  cout << mi << endl;

  return 0;
}


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

#define eb emplace_back
#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define ll long long

const int N = 2e6;
const int INF = 1e9;

#define int ll


void solve() {
	int n;
	cin >> n;
	int cnt = 0;
	while(true) {
		if (n == 1) {
			++cnt;
			break;
		}
		++cnt;
		n /= 2;
	}
	int res = pow(2, cnt);
	cout << res - 1 << '\n';
}

main () {
	cerr << "Ready\n";
	solve();
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N=int(input())
S=[input().strip() for i in range(N)]
S.sort(key=len)

VLIST=[[set() for j in range(len(S[i]))] for i in range(N)]

for i in range(N):
    for j in range(len(S[i])):
        VLIST[i][j]=VLIST[i][j-1]|{S[i][j]}

# ing木

Next_node_id=[[-1]*26] # "a"～"z"それぞれについて、対応する次のノードのid
Parent_id=[-1] # 親ノード
End=[[]] # そのノードを終端とするStringがあるか

ANS=0

Nodes_id=1
for i in range(N):
    S2=S[i]
    L=len(S2)

    NOW=0
    for j in range(L-1,-1,-1):
        for s in End[NOW]:
            if s in VLIST[i][j]:
                ANS+=1

        if j==0:
            End[NOW].append(S2[0])
            continue
        
        NEXT=ord(S2[j])-97
        
        if Next_node_id[NOW][NEXT]==-1: # Nodeを追加する場合
            Next_node_id[NOW][NEXT]=Nodes_id

            Next_node_id.append([-1]*26)
            Parent_id.append(NOW)
            End.append([])

            NOW=Nodes_id         
            Nodes_id+=1

        else: # 追加しない場合
            NOW=Next_node_id[NOW][NEXT]

print(ANS)


Measured memory_bytes: 893372
#include<bits/stdc++.h>
using namespace std;
template<class T>void gi(T &x){
	int f;char c;
	for(f=1,c=getchar();c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(x=0;c<='9'&&c>='0';c=getchar())x=x*10+(c&15);x*=f;
}
const int N=1e6+10,mod=1e9+7;
int Fac[N],inv[N],n,f[N];
inline int C(int n,int m){
	return 1ll*Fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
  cin>>n;
  int ans=0,li=(n+1)/2;
  Fac[0]=inv[0]=inv[1]=1;
  for(int i=1;i<=n;i++)Fac[i]=1ll*Fac[i-1]*i%mod;
  for(int i=2;i<=n;i++)inv[i]=(mod-1ll*(mod/i)*inv[mod%i]%mod)%mod;
  for(int i=2;i<=n;i++)inv[i]=1ll*inv[i]*inv[i-1]%mod;
  for(int i=li;i<n;i++)f[i]=1ll*C(i-1,n-1-i)*Fac[i]%mod*Fac[n-1-i]%mod;
  for(int i=n-1;i>=li;i--)f[i]=(f[i]-f[i-1]+mod)%mod;
  for(int i=n-1;i>=li;i--)ans=(ans+1ll*i*f[i])%mod;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 9984
function main(input) {
  var n = input[0]-0;
  var s = input[1].split(" ")[0];
  var t = input[1].split(" ")[1];
  var ans = "";
  for(var i=0;i<n;i++){
    ans += s[i] + t[i];
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll h,w;
    cin >> h >> w;
    vector<vector <char> > a;
    char x;

    F0R(i,h){
      bool whiteRow = true;
      std::vector<char> temp;
      F0R(j,w){
        cin >> x;
        temp.pb(x);
        if(x == '#') whiteRow = false;
      }
      if(!whiteRow)
        a.pb(temp);
    }

    F0Rd(i,w){
      bool whiteCol = true;
      F0R(j,sz(a)){
        if(a[j][i] == '#')
          whiteCol = false;
      }

      if(whiteCol)
        F0R(j,sz(a))
          a[j].erase(a[j].begin()+i);
    }
    F0R(i,sz(a)){
      F0R(j,sz(a[0])){
        cout << a[i][j];
      }
      cout << endl;
    }
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int at1 = (c+b-1)/b;
    int at2 = (a+d-1)/d;
    if(at1<=at2) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

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

const int N = 3005;

ll n;
double p[N], dp[N][2 * N];

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

    cin >> n;

    for (int i = 1; i <= n; ++i)
        cin >> p[i];

    dp[0][n] = 1;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= 2 * n; ++j)
            dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j + 1] * (1 - p[i]);

    double ans = 0;
    for (int i = n + 1; i <= 2 * n; ++i)
        ans += dp[n][i];

    cout << fixed << setprecision(15);
    cout << ans << endl;
}

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

using namespace std;

int main() {
  long long k;
  
  vector< vector<long long> >st (51, vector<long long>(50, 50));

  for (int i = 1; i <= 50; i++) {
    int maxi, maxv = -1;
    for (int j = 0; j < 50; j++)
      if (st[i-1][j] > maxv) {
        maxv = st[i-1][j];
        maxi = j;
      }
      for (int j = 0; j < 50; j++) {
        if (j == maxi ) st[i][j] = st[i-1][j]-50;
        else st[i][j] = st[i-1][j] + 1;
      }
  }  
  
    cin >> k; 
    cout << 50 << endl;
    long long base = k/50;
    long long rem = k%50;
    for (int i = 0; i < 50 ;i++)
      cout <<  base + st[50-rem][i] << " ";
    cout << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  string s;
  cin >> s;
  int num = 0;
  char before = s[0];
  for(int i = 1;i < s.size();i++){
    if(before != s[i]){
      num++;
      before = s[i];
    }
  }
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  100000LL
#define tmod            998244353
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll SUMD(ll n);
ll BS(vector<ll> &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
bool P[N + 1];
void Sieve(int n=N);
ll Powb(ll b,ll n);

int main()
{
//fast;
ll q=1;
//cin >> q;
while(q--)
{
    ll n,m,k,i,j,l,r,c=0,g,counter=0,u,v,d,e,w,p,x,y,flag=1;
    //n=m=i=j=l=r=a=t=b=c=u=v=w=p=x=y=0;
    cin >> n ;
    cout << n*n*n;


}
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;

}
ll BS(vector<ll> &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid]==ser)
    {
        return mid;
    }
    else if(PS[mid] > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

void Sieve(int n)
{
    memset(P,true,sizeof(P));
    P[0] = false;
    P[1]= false;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i])
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=false;
            }
        }
    }

}


Measured memory_bytes: 256
#A
x,y=map(int,input().split())
ans=0
if x==1:
    ans+=300000
elif x==2:
    ans+=200000
elif x==3:
    ans+=100000
if y==1:
    ans+=300000
elif y==2:
    ans+=200000
elif y==3:
    ans+=100000
if x==y==1:
    ans+=400000
print(ans)

Measured memory_bytes: 38256