akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <map>
#include <bitset>
#include <string>
#include <set>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <stack>
#include <cstdlib>
#include <numeric>
#include <cassert>
#include <complex>
#include <iterator>
//#include <unordered_map>
using namespace std;
#define maxn 200007
#define maxm 400007
#define maxq 1000007
#define maxl 1234
#define modn 1000000007
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define scanl2(a,b) scanf("%lld%lld",&a,&b)
#define scans(a) scanf("%s",a)
#define scans2(a,b) scanf("%s%s",a,b)
#define scand(a) scanf("%lf",&a)
#define scan2(a,b) scanf("%d%d",&a,&b)
#define scand2(a,b) scanf("%lf%lf",&a,&b)
#define scan3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scan4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scan5(a,b,c,d,e) scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)
#define print(a) printf("%d\n",a);
#define printl(a) printf("%lld\n",a);
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i=a;i>= b;i--)
#define fscan(a) fscanf(stream,"%d", &a);
#define mp      make_pair	
#define pb      push_back
#define eb      emplace_back
#define mm(a,b) memset(a,b,sizeof a)
#define log2(n) (double)(log(n) / log(2.0))
#define _crt_disable_perfcrit_locks
#define bll __int128
#pragma warning(disable:4996)
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef map <char, int> mci;
typedef map <char, char> mcc;
typedef pair <char, int> pci;
typedef complex<double> cd;
typedef vector<complex<double> > vcd;
const double eps = 1e-8;
const double PI = 2 * acos(0.0);

int cc, bb; char ch; inline int F() {
	while (ch = getchar(), (ch < 48 || ch> 57) && ch != '-'); ch == '-' ? cc = bb = 0 : (cc = ch - '0', bb = 1);
	while (ch = getchar(), ch > 47 && ch < 58)cc = (cc << 1) + (cc << 3) + (ch ^ 48); return bb ? cc : -cc;
}
void write(int x) {
	int y = 10, len = 1;
	while (y <= x) { y *= 10; len++; }
	while (len--) { y /= 10; putchar(x / y + 48); x %= y; }
}
ll pow2(ll a, ll b, ll mod) {
	ll r = 1, base = a;
	while (b) {
		if (b & 1) r = r * base % mod;
		base = base * base % mod;
		b >>= 1;
	}
	return r;
}
ll inv(ll a, ll n) {
	return pow2(a, n - 2, n);
	//return pow2(a, oula(n) - 1, n);
}
ll gcd(ll a, ll b) {
	ll r;
	while (b != 0) {
		r = a % b;
		a = b;
		b = r;
	}
	return a;
}
int n, k;
ll e[maxn];
void euler() {
	for (int i = 1; i < 100007; i++)
		e[i] = i;
	for (int i = 2; i < 100007; i++)
		if (e[i] == i)
			for (int j = i; j < 100007; j += i)
				e[j] -= e[j] / i;
	for (int i = 2; i < maxn; i++)
		e[i] += e[i - 1];
}
int main() {
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	//FILE* stream = fopen("L:/20.in", "rb+")
	cin >> k >> n;
	euler();
	ll res = 0;
	ll r;
	for (ll i = 1; i <= n; i = r + 1) {
		r = n / (n / i);
		res += (e[r] - e[i - 1]) * pow2(n / i, k, modn) % modn;
	}
	cout << res % modn << endl;
	return 0;
}

Measured memory_bytes: 5176
package main

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

func out(x ...interface{}) {
	//fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func calcH(i, h int) []int {
	x := make([]int, 0)
	b := i
	cnt := 0
	for i := 0; i < h; i++ {
		x = append(x, cnt)
		if b%2 == 1 {
			cnt++
		}
		b /= 2
	}

	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	H, W, K := getInt(), getInt(), getInt()
	a := make([][]int, H)
	for i := 0; i < H; i++ {
		a[i] = make([]int, W)
		s := getString()
		for j := 0; j < W; j++ {
			if s[j] == '1' {
				a[i][j] = 1
			}
		}
	}

	out(a, K)

	ans := 10000000
	n := 1 << uint(H-1)
	for i := 0; i < n; i++ {
		x := calcH(i, H)
		cnt := x[len(x)-1]
		sum := make([]int, len(x))
		for k := 0; k < W; k++ {
			flg := false
			sub := make([]int, len(x))
			for j := 0; j < H; j++ {
				pos := x[j]
				sum[pos] += a[j][k]
				sub[pos] += a[j][k]
				if sub[pos] > K {
					cnt = 10000000
				}
				if sum[pos] > K {
					flg = true
				}
			}
			out(x, flg, k)
			if flg == true {
				cnt++
				for j := 0; j < len(sum); j++ {
					sum[j] = sub[j]
				}
			}
		}
		if ans > cnt {
			out(x)
		}
		ans = min(ans, cnt)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main(){
    int N,D,X;
    cin >> N >> D >> X;
    int a[100]={0};
    for (int i=0;i<N;i++) cin >> a[i];

    int res=0;
    for (int i=0;i<N;i++){
	res++;
	int j=1;
	while (a[i]*j+1 <= D){
	    res++;
	    j++;
	}
    }

    cout << res+X << endl;

    return 0;
}

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

void read(int& s0, int& s1)
{
  char d;
  int h0, m0, h1, m1;
  cin >> h0 >> d >> m0 >> d >> s0;
  cin >> h1 >> d >> m1 >> d >> s1;
  s0 += 3600*h0 + 60*m0;
  s1 += 3600*h1 + 60*m1;
}

int main()
{
  int n;
  while (cin >> n && n != 0) {
    vector<pair<int,int> > entries(n);
    for (int i = 0; i < n; i++) {
      read(entries[i].first, entries[i].second);
    }
    sort(entries.begin(), entries.end());

    priority_queue<int, vector<int>, greater<int> > q;
    q.push(entries.front().second);
    for (int i = 1; i < n; i++) {
      if (q.top() > entries[i].first) {
        q.push(entries[i].second);
      } else {
        q.pop();
        q.push(entries[i].second);
      }
    }
    cout << q.size() << endl;
  }
  return 0;
}

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

typedef long long int   ll;
#define f(i,st,en)    for(int i=st;i<en;i++)
#define s(n)            scanf("%d",&n)
#define sc(n)           scanf("%c",&n)
#define sl(n)           scanf("%lld",&n)
#define sf(n)           scanf("%lf",&n)

using namespace std;


int main(){
    int n;
    cin>>n;
    int a[n-1];
    int ar[n]={0};
    for(int i=0;i<n-1;i++){
        int x;
        cin>>x;
        ar[x-1]++;
    }

    for(auto i:ar)cout<<i<<endl;
}


Measured memory_bytes: 4348
#include <iostream>
#include <algorithm>
#include <vector>
#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;
struct UFT{
  vector<int> par;//親
  vector<int> rank;//木の深さ
  vector<int> size;//木の大きさ
  int n;
  
  UFT(int _n)
  {
    n = _n;
    par.resize(n);
    rank.assign(n,0);
    size.assign(n,1);
    rep(i,n){
      par[i] = i;
    }
  }
  
  //xの根を返す
  int find(int x)
  {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  //x,yを併合
  void unite(int x,int y)
  {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank[x] < rank[y]){
      par[x] = y;
      size[y] += size[x];
    }
    else{
      par[y] = x;
      size[x] += size[y];
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  //x,yが同じグループにいるかどうかを返す
  bool same(int x,int y)
  {
    return find(x) == find(y);
  }

  //xの属する木のサイズを探す
  int usize(int x)
  {
    return size[find(x)];
  }
};

int main()
{
  int n,m;
  cin >> n >> m;
  vector<int> p(n);
  rep(i,n){
    cin >> p[i];
    p[i]--;
  }
  vector<int> x(m),y(m);
  rep(i,m){
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }

  UFT uf(2*n);
  rep(i,n){
    uf.unite(p[i]+n,i);
  }

  rep(i,m){
    uf.unite(x[i],y[i]);
  }

  
  int cnt=0;
  rep(i,n){
    if(uf.same(i,i+n)) cnt++;
  }
  cout << cnt << "\n";
  
  return 0;
}


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n;

int main(){
  int mi = INT_MAX;
  cin >> n;
  FOR(i,1,n){
    int a = i;
    int b = n-i;
    int cnt = 0;
    while(a%10>0 || a/10>0){
      cnt += a%10;
      a/=10;
    }
    while(b%10>0 || b/10>0){
      cnt += b%10;
      b/=10;
    }
    mi = min(mi,cnt);
  }
  cout << mi << endl;
}


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

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>* s = new vector<int>[m];
	int tmp,tmp2;
	for (int i = 0;i < m;i++) {
		cin >> tmp;
		for (int j = 0;j < tmp;j++) {
			cin >> tmp2;
			s[i].push_back(tmp2);
		}
	}
	int* p = new int[m];
	for (int i = 0;i < m;i++) {
		cin >> p[i];
	}
	int cnt = 0;
	bool flag;
	int sp;
	for (int i = 0;i < 1 << n;i++) {
		flag = true;
		for (int j = 0;j < m;j++) {
			sp = 0;
			for (int k = 0;k < s[j].size();k++) {
				if (i & 1 << (s[j][k]-1))sp = (sp + 1) % 2;
			}
			if (sp != p[j]) {
				flag = false;
				break;
			}
		}
		if (flag)cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 100;

int n, x[N][N], d;

bool valid(int i, int j){
   int dist = 0;
   for (int a = 0; a < d; ++a)
   {
      dist += (x[i][a] - x[j][a]) * (x[i][a] - x[j][a]);
   }

   int sq = sqrt(dist);

   return sq * sq == dist;
}

int32_t main(){_

   cin>>n>>d;

   for (int i = 0; i < n; ++i)
   {
      for (int j = 0; j < d; ++j)
      {
         cin>>x[i][j];
      }
   }

   int ans = 0;
   for (int i = 0; i < n; ++i)
   {
      for (int j = i+1; j < n; ++j)
      {
         if(valid(i, j)){
            ans++;
         }
      }
   }
   
   cout<<ans;
   

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int MAXN = 4e5 + 10;
using namespace std;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int n;
int A[MAXN], B[MAXN], ta[MAXN], tb[MAXN], sa, sb, tot = 0, date[MAXN], fa[MAXN];
int find(int x) {
    return fa[x] == x ? fa[x] : fa[x] = find(fa[x]);
}
int unionn(int x, int y) {
    fa[x] = y;
}
int main() {
    n = read();
    for(int i = 1; i <= n; i++) A[i] = read(), sa ^= A[i]; A[n + 1] = sa;
    for(int i = 1; i <= n; i++) B[i] = read(), sb ^= B[i]; B[n + 1] = sb;
    n++;
    memcpy(ta, A, sizeof(A)); memcpy(tb, B, sizeof(B));
    sort(ta + 1, ta + n + 1); sort(tb + 1, tb + n + 1);
    for(int i = 1; i <= n - 1; i++) if(ta[i] != tb[i]) return puts("-1"), 0;
 
    int ans = 0, sum = 0;
    for(int i = 1; i <= n; i++) 
        if(A[i] != B[i] || (i == n)) {
            date[++sum] = A[i]; date[++sum] = B[i];
            if(i < n)ans++;
        }
    if(ans == 0) return puts("0"), 0;
 
    sort(date + 1, date + sum + 1);
    sum = unique(date + 1, date + sum + 1) - date - 1;
    for(int i = 1; i <= sum; i++) fa[i] = i;
    for(int i = 1; i <= n; i++)
        if(A[i] != B[i]) {
            A[i] = lower_bound(date + 1, date + sum + 1, A[i]) - date,
            B[i] = lower_bound(date + 1, date + sum + 1, B[i]) - date;
            unionn(find(A[i]), find(B[i]));
        }
 
    for(int i = 1; i <= sum; i++)
        if(fa[i] == i) ans++;
    printf("%d", ans - 1);
 
    return 0;
}

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

int main(){
    int n,i,j,k,tmp,f;
    char input[257],ans[257];

    scanf("%d%*c",&n);
    while(n--){
        fgets(input,260,stdin);
f=0;
        for(k=1;;k+=2){
if(k%13==0)continue;
            for(j=0;j<26;j++){
                for(i=0;input[i]!='\n';i++){
                    if(input[i]==' '){
                        ans[i]=' ';
                        continue;
                    }
                    ans[i]=((input[i]-'a')*k+j)%26+'a';
                }
ans[i]=0;
                for(i=0;ans[i+3]!='\0';i++){
                    if(ans[i]=='t'&&
                            ans[i+1]=='h'&&
                            (ans[i+2]=='a'&&ans[i+3]=='t'||
                             ans[i+2]=='i'&&ans[i+3]=='s')){
                        printf("%s\n",ans);
f=1;
                        break;
                        break;
                    }
                }
            }
if(f)break;
        }
    }
    return 0;
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}


signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
  }

  int skip = 1 + N % 2;
  vector<vector<int>> dp(N + 2, vector<int>(skip + 1, -INF));
  dp[0][0] = 0;

  rep(i, N + 1) {
    rep(j, skip + 1) {
      if (j < skip)
        chmax(dp[i + 1][j + 1], dp[i][j]);

      if (i < N)
        chmax(dp[i + 2][j], dp[i][j] + A[i]);
    }
  }
  int ans = dp[N + 1][skip];
  cout << ans << endl;
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

int main(){
    fIO
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);


    double a, b, h ,m;
    cin >> a >> b >> h >> m;

    //360 / 12 = 30
    //360 / 60 = 06
    double ang1 = 30 * h + m / 2.0;
    double ang2 = 6 * m;

    double C = max(ang1, ang2) - min(ang1, ang2);
    //cout << C << "\n";
    C = (C * pi) / 180.0;
    //cout << cos(C) << "\n";
    double ans = sqrt(a * a + b * b - 2 * a * b * cos(C));

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








Measured memory_bytes: 4180
#include <bits/stdc++.h>
#define ll long long int
#define pb(x) push_back(x)
#define TEST(t) int inox,t;cin>>t; for(inox=1;inox<=t;inox++)
#define rep(i,n) for(i=0;i<n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
using namespace std;


int main(){
    ll n; ll i,f=0; cin>>n;
 // int i;
  for(i=1;i<=n;i++){
    if(i%3!=0&&i%5!=0)f+=i;
  }
  cout<<f;
}

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

int main() {
	ll N;
	cin >> N;
	vector<ll> v;
	while (N != 0) {
		v.push_back(N%10);
		N /= 10;
	}
	reverse(v.begin(), v.end());

	ll res = v[0] + 9 * (v.size() - 1);
	for (int i = 1; i < v.size(); i++) {
		if (v[i] != 9) {
			cout << res - 1 << endl;
			return 0;
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include "algorithm"
#include "iomanip"
#include "iostream"
#include "queue"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
void drop(const T& x) {
  cout << x << endl;
  exit(0);
}

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

  ll X;
  cin >> X;

  ll a = 100;
  ll ct = 0;
  while (a < X) {
    a = a + a / 100;
    ct++;
  }

  cout << ct << "\n";

  return 0;
}


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

int main() {

    int n, k;
    cin >> n >> k ;
    int h[n];
    for(int i=0; i<n; ++i){
        cin >> h[i];
    }

    int ridableHuman=0;

    for(int i=0; i<n; ++i){
        if(h[i] >= k) ridableHuman++;
    }

    cout << ridableHuman << endl;

}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    n = II()
    d = LI()

    d.sort()

    print(d[n//2] - d[n//2 -1])


main()

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int main()
{
    cin.sync_with_stdio(false);
    int N, A, B, C;
    vector<int> target(3);
    cin >> N;
    rep(i, 3) cin >> target[i];
    vector<int> l(N);
    rep(i, N) cin >> l[i];
    int ans = INF;

    rep(i, int(pow(4, N)))
    {
        vector<int> tmp(3);
        int cnt = N;
        int I = i;
        int cost = 0;
        rep(j, N)
        {
            if (I % 4 < 3)
            {

                if (tmp[I % 4] != 0)
                {
                    cost += 10;
                }
                tmp[I % 4] += l[j];
            }
            I /= 4;
        }
        bool flag = true;
        rep(j, 3)
        {
            if (tmp[j] == 0)
                flag = false;
            cost += abs(tmp[j] - target[j]);
        }
        if (!flag)
            continue;
        ans = min(ans, cost);
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long 
#define sz(x) (int)x.size()

using namespace std;

int main(){
	string a,b;
	cin>>a>>b;
	if(sz(a)>sz(b)){
		cout<<"GREATER";
		return 0;
	}
	if(sz(a)<sz(b)){
		cout<<"LESS";
		return 0;
	}
	for(int i=0;i<sz(a);i++){
		if(a[i]!=b[i]){
			if((int)a[i]>(int)b[i]){
				cout<<"GREATER";
				return 0;
			}
			else{
				cout<<"LESS";
				return 0;
			}
		}
	}
	cout<<"EQUAL";
	
	
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  int now = a.at(0) - 1;
  int c = 1;
   while(c < n + 10){
     if(now == 1) break;
     now = a.at(now) - 1;
     c++;
   }
  if(c >= n) cout << -1 << endl;
  else cout << c << endl;
}

Measured memory_bytes: 640
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input!(n: usize, m: usize, x: [usize; n]);

    let mut remainder = vec![vec![]; m];
    for &x in x.iter() {
        let r = x % m;
        remainder[r].push(x);
    }

    let mut ans = 0;
    for i in 0..m {
        if i == 0 || i * 2 == m {
            ans += remainder[i].len() / 2;
        } else if m - i < i {
            break;
        } else {
            let j = m - i;

            let len_i = remainder[i].len();
            let len_j = remainder[j].len();
            ans += cmp::min(len_i, len_j);

            let t = if len_i > len_j { i } else { j };
            remainder[t].sort();

            let mut pair = 0;
            let mut i = 1;
            while i < remainder[t].len() {
                if remainder[t][i - 1] == remainder[t][i] {
                    pair += 1;
                    i += 2;
                } else {
                    i += 1;
                }
            }

            let remain = cmp::max(len_i, len_j) - cmp::min(len_i, len_j);
            ans += cmp::min(remain / 2, pair);
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 12540
#include<bits/stdc++.h>
	#define pb push_back
	#define mp make_pair
	#define se second
	#define fi first
	#define ll long long int
	#define INF INT_MAX
	#define mod
	#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
	using namespace std;
	bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return (a.second < b.second);}
	ll gcd(ll a, ll b){if(a==0)return b;return gcd(b % a, a);}
	int main()
	{
		chutiyaap;
		ll n;cin>>n;
		ll x[10],y[10];
		long double ans=0;
		ll f=1;
		for(ll i=1;i<=n;i++)f*=i;
		for(ll i=1;i<=n;i++)cin>>x[i]>>y[i];
		ll array[]={1,2,3,4,5,6,7,8};
		do
		{
			long double dist=0;
			for(ll i=0;i<n-1;i++)dist+=sqrt((x[array[i]]-x[array[i+1]])*(x[array[i]]-x[array[i+1]])+(y[array[i]]-y[array[i+1]])*(y[array[i]]-y[array[i+1]]));
			ans+=dist;
		}
		while(next_permutation(array,array+n));
		cout<<fixed<<setprecision(15)<<ans/f;
	}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);
#define PI (3.14159265358979323846)

using ll = int64_t;
using ull = uint64_t;

using namespace std;

[[maybe_unused]] static auto __x = [](){ios_base::sync_with_stdio(0); cin.tie(0);};

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

    cout << ((b + b >= a) ? 0 : (a - b - b));

    return 0;
}


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

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    if ((n % 10) == 7)
    {
        cout << "Yes" << endl;
        return 0;
    }
    n /= 10;
    if ((n % 10) == 7)
    {
        cout << "Yes" << endl;
        return 0;
    }
    n /= 10;
    if ((n % 10) == 7)
    {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3592
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))
ret = [0 for _ in range(n+1)]
#後ろから求める
for i,a_i in enumerate(a[-1::-1]):
    cur_ret_sum = sum(ret[n-i::n-i])%2
    if a_i!=cur_ret_sum:
        ret[n-i]=1
m = sum(ret[1::])
print(m)
if m > 0:
    print(" ".join([str(i) for i,v in enumerate(ret) if v==1]))

Measured memory_bytes: 15772
#include <iostream>
using namespace std;
int main(){
  int N,B[100];
  cin >> N;N--;
  for(int i=0;i<N;i++){
    cin >> B[i];
  }
  int sum=B[0]+B[N-1];
  for(int i=0;i<N-1;i++){
    sum+=min(B[i],B[i+1]);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int n;
	//vector<int> A;
	//vector<int>	B;
	scanf("%d", &n);
	int *x = new int[n+1];
	
	/*for (int i = 1; i <= n; i++){
		B.push_back(i);
	}*/
	for (int i = 1; i <= n; i++){
		scanf("%d", &x[i]);	
	}
	int count = 0;
	int numOperator = 0;
	for (int i = 1; i <= n; i++){
		
		int j = x[i];
		//printf("x[%d] = %d and ", i, j);
		if (x[j] == i){
			//printf("x[%d] = %d\r\n", j, i);
			count++;
		}
		else{
			//printf("x[%d] != %d\r\n", j, i);
		}

	}
	printf("%d", count/2);
	return 0;
}

Measured memory_bytes: 640
//created by pyoxiao on 2020/05/02
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
LL n;
void solve() {
    scanf("%lld", &n);
    LL cur = 100;
    for(int i = 1; ; i ++) {
        cur += (LL)cur * 0.01;
        if(cur >= n) {
            printf("%d\n", i);
            return;
        }
    }
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

Measured memory_bytes: 3824
#include <iostream>
#include <bitset>
using namespace std;
#define max(a,b)a>b?a:b;
bitset<10000> bit[10];
int main()
{
    int n,m,i,j,k;
    while(cin>>n>>m){
        if(n==0&&m==0)return 0;
        int cnt=0;
        for(i=0;i<n;i++){
            for(j=0;j<m;j++){
                bool a;
                cin>>a;bit[i][j]=a;
            }
        }

            int count_n=1<<n;
        for(i=0;i<count_n;i++){
                int count_=0;
            for(j=0;j<n;j++){
                if(i&(1<<j)){
                bit[j].flip();
                }
            }

            for(j=0;j<m;j++){
                int count_m=0,count_mm;
                for(k=0;k<n;k++){
                    if(bit[k][j]){count_m++;}
                }
                count_mm=max(count_m,n-count_m);
                count_+=count_mm;
            }
            cnt=max(cnt,count_);
            for(j=0;j<n;j++){
                if(i&(1<<j)){
                bit[j].flip();
                }
            }
        }
        for(i=0;i<n;i++){
            bit[i].reset();
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 1172
N = int(input())
t = [0]
x = [0]
y = [0]
for _ in range(N):
    t0, x0, y0 = map(int, input().split())
    t.append(t0)
    x.append(x0)
    y.append(y0)

count = 0
for i in range(1, len(t)):
    dt = t[i]-t[i-1]; dist = abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
    if dist > dt:
        break
    else:
        if (dt%2==0 and dist%2==0) or (dt%2==1 and dist%2==1):
            count = count + 1

if count == N:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 11740
n,p=map(int,input().split())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

li=factorization(p) 

ans=1
for i,j in li:
    if j>=n:
        temp=j
        while temp>=n:
            ans*=i
            temp-=n
print(ans)

        

Measured memory_bytes: 3064
<?php

    while(true){
        list($a, $op, $b) = explode(" ",trim(fgets(STDIN)));
        
        switch ($op) {
            case '?':
                break 2;

            case '+':
                $result = $a + $b;
                break;
            
            case '-':
                $result =  $a - $b;
                break;

            case '*':
                $result =  $a * $b;
                break;

            case '/':
                $result = $a / $b;
                break;
        }
        
        printf("%d\n",$result);

    }
 

Measured memory_bytes: 15372
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
#define R(i,n) for(int i = 1; i<=n; i++)
typedef long long ll;
using namespace std;

int main(){
  int n,m,c,ans=0;
  cin >> n >> m >> c;
  vector<int> b(m,0), a(m,0);
  r(i,m)cin >> b.at(i);
  while(n--){
    int count=0;
    r(i,m){
      cin >> a.at(i);
      count+=b.at(i)*a.at(i);
    }
    if(count+c>0)ans++;
  }
  cout << ans << endl;
}

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int n;
  int b[26]={0};
  cin >> n;
  REP(i,n){
	string s;
	cin >> s;
	int a[26] = {0};
	REP(j,s.size()){
	  a[s[j]-'a']++;
	}
	REP(j,26){
	  if(i==0) b[j] = a[j];
	  b[j] = min(b[j], a[j]);
	}
  }
  REP(i,26){
	REP(j,b[i]) cout << (char)(i + 'a');
  }
  cout << endl;
}


Measured memory_bytes: 256
import math
import copy
from collections import Counter
from _ast import Or
 
 
 
def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:
 
            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l
 

a=nCast(inputArr(5))


                   
   

def func():
    min=10
    for k in a:
        if k%10!=0 and k%10<min:
            min=k%10
    sum=0
    for k in a:
        if k%10==0:
            sum+=k
        elif min==-1 or k%10!=min:
            sum+=(int(k/10)+1)*10
        else:
    
            sum+=k
            min=-1
    return sum
print(func())


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k=0,a,b,flag=0;
  cin>>n;
  for(int i=0;i<n;i++){
      cin>>a>>b;
      if(a==b){
          k++;
      }
      else{
          k=0;
      }
      if(k==3){
          flag=1;
          break;
      }
  }
  if(k>=3 || flag==1)
  cout<<"Yes";
  else{
      cout<<"No";
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define ul unsigned long long
#define ll long long
#define ld long double

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

  int a=n*(n-1)/2+m*(m-1)/2;
  cout<<a<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define cY cout << "Yes" << endl;
#define cN cout << "No" << endl;

ll gcd(ll a,ll b){
  if(a < b) swap(a,b);
  int r = a % b;
  while(r != 0){
    a = b;
    b = r;
    r = a % b;
  }
    return b;
}
    
int main() {
  int k,sum = 0;
  cin >> k;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int l=1;l<=k;l++){
        sum += gcd(i,gcd(j,l));
      }
    }
  }
  cout << sum << endl;
  return 0;
}


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

int combination(int n, int r)
{
  if (n < r) return 0;
  else if (r == 0 || r == n) return 1;
  else if (r == 1) return n;
  
  int prod_n = 1;
  int prod_r = 1;
  
  for (int i = n; i > n - r; i --)
    prod_n *= i;
  for (int i = 2; i <= r; i ++)
    prod_r *= i;
  return (double)prod_n / (double)prod_r;
}

int main()
{
  int n, m;
  cin >> n >> m;
  
  cout << combination(n, 2) + combination(m, 2) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

bool chkP (string s, string p); // contains matchSP
bool matchP (string s, string p);

int main () {
    // input
    string s, p;
    cin >> s >> p;

    // thinking
    chkP(s,p);

    // output
    if ( chkP(s, p) ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

bool chkP ( string s, string p ) {
    bool result = false;
    int len_s = s.length();
    int len_p = p.length();
    string s2 = s + s;
    for (int i=0; i<len_s; i++) {
        if ( matchP ( s2.substr(i, len_p), p ) ) {
            result = true;
            break;
        }
    }
    return result;
}


bool matchP (string s, string p) {// s: s partial
    if (s == p) {
        return true;
    } else {
        return false;
    }
}


Measured memory_bytes: 3240
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    L=list(map(int,input().split()))
    L.sort()
    if L[N-1]<sum(L[:N-1]):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
(defun next (s)
  (if (evenp s) (/ s 2)
    (1+ (* 3 s))))

(setf array (make-array 1000000))
(setf a_i (read))

(dotimes (i-1 1000000)
  (if (= 1 (aref array a_i)) (return (princ (1+ i-1))))
  (setf (aref array a_i) 1)
  (setf a_i (next a_i)))

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

#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second

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

using namespace std;


int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   
   string sym; cin >> sym;
   int n = 0;
   for(char i : sym){
      if(i == '+') n++;
      else n--;
   }
   cout << n;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int sum=0;
    for(int i=a;i<b+1;i++){
        int c=i%10;
        int d=(i%100)/10;
        int e=(i%1000)/100;
        int f=(i%10000)/1000;
        int g=(i%100000)/10000;
        if(c==g&&d==f){
            sum++;
        }
        else{
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int c = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        c += i % 2 == 0 && a % 2 == 1;
    }

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

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

    if(a>b) cout << a - 1 << endl;
    else cout << a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
#define ll long long

int a[110];
int main() {
	int n;
	int d[110];
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> d[i];
		for (int j = 1; j <= 100; j++) {
			if (d[i] == j)a[j] = 1;
		}
	}
	int ans = 0;
	for (int i = 1; i <= 100; i++)ans += a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    String a = scanner.next();
		    String s = scanner.next();
		    String c = scanner.next();
		    
		    System.out.println("A" +  s.substring(0,1) + "C" );
		    
		    scanner.close(); }
		  }

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
 
int main()
{
    long long int n;
    cin >> n;
    long long int arr[n],sum=0,ans=0,fans=1e18;
    for(int i=0;i<n;i++)
    {
        cin >> arr[i];
        sum+=arr[i];
    }
    for(int i=0;i<n;i++)
    {
        ans+=arr[i];
        fans=min(fans,abs(ans-(sum-ans)));
    }
    cout << fans << endl;
    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ans(N);
  for (int i = 0; i < M; i ++ ){
    int a,b;
    cin >> a >> b;
    for (int j = 0; j < N; j++){
      if (j+1 == a || j+1 == b)
        ans.at(j) += 1;
    }
  }
  for (int i = 0; i < N; i++){
    cout << ans.at(i) << endl;
  }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>

using namespace std;

#define N 10010
typedef long long ll;
ll p[N],q[N];
class RollingHash2{
private:
  ll aa[N];
  ll bb[N];
  ll P,Q;
public:
  RollingHash2(){}
  RollingHash2(string &s,ll _P,ll _Q){
    int n=s.size();
    aa[0]=bb[0]=0;
    P=_P;
    Q=_Q;
    // hash値を計算
    for(int i=1;i<=n;i++)aa[i]=aa[i-1]*P+s[i-1];
    for(int i=1;i<=n;i++)bb[i]=bb[i-1]*Q+s[i-1];
  }
  pair<ll,ll> getHash(int x,int y){
    return make_pair(aa[y+1]-aa[x]*p[y-x+1],
		     bb[y+1]-bb[x]*q[y-x+1]);
  }
};
RollingHash2 fHash;

// 格文字列のハッシュ値
pair<ll,ll> hashVal[12];
string strs[12];
string fullTxt;
int n,m;
int dp[1<<12][12];
int dfs(int pos,int mask,int cur){
  if(mask==(1<<n)-1)return true;
  else if(dp[mask][cur]>=0)return dp[mask][cur];
  bool res=false;
  for(int i=0;i<n;i++){
    if((mask>>i)&1)continue;
    // ハッシュ値が一致する場合
    if(fHash.getHash(pos,pos+strs[i].size()-1)
       ==hashVal[i]){
      res|=dfs(pos+strs[i].size(),mask|(1<<i),i);
      if(res)return res;
    }
  }
  return dp[mask][cur]=res;
}

ll fact[20];
int main(){
  const ll P=1000000007;
  const ll Q=4300003200017LL;
  fact[0]=1;
  for(int i=1;i<20;i++)fact[i]=fact[i-1]*i;
  // P**iを計算
  p[0]=1;
  for(int i=1;i<=10000;i++)p[i]=p[i-1]*P;
  q[0]=1;
  for(int i=1;i<=10000;i++)q[i]=q[i-1]*Q;
  while(cin>>n>>m&&(n|m)){
    fullTxt="";
    int sz=0;
    map<string,int> scnt;
    for(int i=0;i<n;i++){
      cin>>strs[i];
      scnt[strs[i]]++;
      sz+=strs[i].size();
      // ハッシュ値を計算しておく
      RollingHash2 rh(strs[i],P,Q);
      hashVal[i]=rh.getHash(0,strs[i].size()-1);
    }
    ll divNum=1;
    for(map<string,int>::iterator it=scnt.begin();
	it!=scnt.end();it++){
      divNum*=fact[it->second];
    }
    for(int i=0;i<m;i++){
      string tmp;cin>>tmp;
      fullTxt+=tmp;
    }
    // 計算済みの結果を登録しておく
    map<pair<ll,ll>,bool> mem;
    fHash=RollingHash2(fullTxt,P,Q);
    ll res=0;
    for(int i=0;i+sz<=fullTxt.size();i++){
      pair<ll,ll> hv=fHash.getHash(i,i+sz-1);
      // 計算済みであれば
      if(mem.find(hv)!=mem.end())res+=mem[hv];
      // まだ計算済みでない
      else{
	memset(dp,-1,sizeof(dp));
	bool tmp=false;
	for(int j=0;j<n;j++){
	  if(fHash.getHash(i,i+strs[j].size()-1)
	     ==hashVal[j]){
	    tmp|=dfs(i+strs[j].size(),1<<j,j);
	    if(tmp)break;
	  }
	}
	mem[hv]=tmp;
	res+=tmp;
      }
    }
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 1812
import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val Array(h, w, s, t) = readLine.trim.split(' ')
  val state = Array.tabulate(h.toInt){_ ⇒ readLine.trim}
  val nodes = Array.tabulate(26){id ⇒ new Node(id)}
  val indices = Array.tabulate(26){i ⇒ i}.flatMap{i ⇒
    (0 until h.toInt).flatMap{y ⇒ (0 until w.toInt).map{x ⇒ Coordinate(x, y)}}.find{coord ⇒ state(coord.y)(coord.x) == ('A' + i)}.map{(_, i)}
  }
  for {(posA, i) ← indices
       (posB, j) ← indices if i != j}{
    if (posA.x == posB.x){
      if ((math.min(posA.y, posB.y) + 2 until math.max(posA.y, posB.y) - 1).forall{y ⇒ state(y)(posA.x) == '|'}) {
        nodes(i).addEdge(nodes(j))
        nodes(j).addEdge(nodes(i))
      }
    }else if (posA.y == posB.y){
      if ((math.min(posA.x, posB.x) + 2 until math.max(posA.x, posB.x) - 1).forall{x ⇒ state(posA.y)(x) == '-'}){
        nodes(i).addEdge(nodes(j))
        nodes(j).addEdge(nodes(i))
      }
    }
  }
  val minCost = Array.tabulate(26){_ ⇒ Int.MaxValue}.also{arr ⇒ arr(s.head - 'A') = 0}
  val queue = mutable.PriorityQueue()(Ordering.by[(Int, Int), Int](_._2).reverse).also{que ⇒ que.enqueue((s.head - 'A', 0))}
  while (queue.nonEmpty){
    val (top, distance) = queue.dequeue()
    if (minCost(top) == distance){
      for (next ← nodes(top).edges){
        if (minCost(next.id) - distance > 1) {
          minCost(next.id) = distance + 1
          queue.enqueue((next.id, minCost(next.id)))
        }
      }
    }
  }
  println(
    minCost(t.head - 'A')
  )

  case class Coordinate(x: Int, y: Int)
  class Node(val id: Int){
    private var mEdges: List[Node] = Nil
    def addEdge(to: Node): Unit = mEdges ::= to
    def edges: List[Node] = mEdges
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 46820
using System;

namespace ABC049
{
    class C
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var res = "NO";
            var Sc = S.ToCharArray();
            Array.Reverse(Sc);
            S = new string(Sc);

            var suffixes = new string[4] { "maerd", "esare", "resare", "remaerd" };

            for (int i = 0; i < S.Length;)
            {
                var can = false;
                for (int j = 0; j < suffixes.Length; j++)
                {
                    var suf = suffixes[j];

                    if (S.Substring(i, suf.Length) == suf)
                    {
                        can = true;
                        i += suf.Length;
                        if (i == S.Length) res = "YES";
                        break;
                    }
                }
                if (!can) break;
            }

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13108
#include<stdio.h>
int main()
{
 
 
 int t;
 
  
 scanf("%s",&t);
 if (t=='A')
  printf("T");
  if (t=='T')
    printf("A");
  if (t=='C')
    printf("G");
  if (t=='G')
    printf("C");




  
   return 0;
}
    

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)for(unsigned long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int MAX = 510000;


int main() {
  int h,w,n;
  cin >> h >> w >> n;
  cout << (n+max(h,w)-1)/max(h,w) << endl;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vi cost(n+1), sum(n+2);
    rep(i, m) {
        int a;
        cin >> a;
        cost[a]++;
    }
    rep(i, n+1) sum[i+1] = sum[i] + cost[i];
    cout << (min(sum[x]-sum[0], sum[n+1]-sum[x+1])) << endl;
    return 0;
}


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

int main() {
  int N, M;
  map<string, int> m;
  cin >> N;
  vector<string>s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
    m[s.at(i)]++;
  }
  cin >> M;
  vector<string>t(M);
  for (int i = 0; i < M; i++) {
    cin >> t.at(i);
    m[t.at(i)]--;
  }
  int ans = 0;
  for (map<string, int>::iterator ite = m.begin(); ite != m.end(); ite++) {
    if (ite->second > ans) {
      ans = ite->second;
    }
  }
  cout << ans;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int MN = 100010;
vector<pii> g[MN];
int col[MN];

void dfs(int v, int c, vi& vs) {
	col[v] = c;
	vs.pb(v);

	for (auto e : g[v]) {
		int nc = c + e.se;
		if (nc < 0) nc += 3;
		if (nc >= 3) nc -= 3;

		if (col[e.fi] == -1) {
			dfs(e.fi, nc, vs);
		}
	}
}

int main() {
	int N, M; cin >> N >> M;
	rep(i, M) {
		int a, b;
		cin >> a >> b; --a; --b;
		g[a].eb(b, 1);
		g[b].eb(a, -1);
	}

	memset(col, -1, sizeof(col));

	ll ans = 0;

	rep(i, N) if (col[i] == -1) {
		vi vs;
		dfs(i, 0, vs);
		bool ok = true;
		for (int v : vs) {
			for (auto e : g[v]) {
				int nc = col[v] + e.se;
				if (nc < 0) nc += 3;
				if (nc >= 3) nc -= 3;
				if (col[e.fi] != nc) {
					ok = false;
				}
			}
		}

		ll sz = vs.size();
		if (!ok) {
			ans += sz * sz;
		} else {
			ll num[3] = {};
			ll es = 0;
			for (int v : vs) {
				++num[col[v]];
				for (auto e : g[v]) {
					++es;
				}
			}
			es /= 2;

			if (min({num[0], num[1], num[2]}) == 0ll) {
				ans += es;
			} else {
				ans += num[0] * num[1] + num[1] * num[2] + num[2] * num[0];
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 12920
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,i,j,k,c=0;
	cin>>n;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			for(k=1;k<=n;k++)
					c=c + __gcd(i, __gcd(j,k));
	cout<<c;
}

Measured memory_bytes: 3636