akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int sea[60][60];
int w,h;

void f(int x,int y){
//cout<<x<<" "<<y<<endl;
	int i,j;
/*for(i=0;i<h;i++){
	for(j=0;j<w;j++){
		cout<<sea[i][j]<<" ";
	}
	cout<<endl;
}*/
	sea[y][x]=0;
	for(i=-1;i<2;i++){
		for(j=-1;j<2;j++){
			if(y+i<0||h<=y+i||x+j<0||w<=x+j)continue;
			if(sea[y+i][x+j]==1)f(x+j,y+i);
		}
	}
}

int main() {
	while(w=in(),h=in()){
		int i,j;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				cin>>sea[i][j];
			}
		}
		/*for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				cout<<sea[i][j]<<" ";
			}
			cout<<endl;
		}*/
		int res=0;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(sea[i][j]==1){
					f(j,i);
					res++;
				}
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
//#include<set>

using namespace std;

int main() {
  string left = "qwertasdfgzxcvb";
  string right = "yuiophjklnm";
  string str;
  while(cin>>str && str!="#") {
    int cnt = -1;
    string nowHand = "none";
    string lastHand = "none";
    for(int i=0; i<str.size(); i++) {
      bool flag = false;
      for(int j=0; j<right.length() && flag==false; j++) {
	if(str[i] == right[j]) {
	  lastHand = nowHand;
	  nowHand = "right";
	  flag = true;
	}
      }
      if(flag == false) {
	lastHand = nowHand;
	nowHand = "left";
      }
      if(lastHand != nowHand) {
	cnt++;
      }
    }
    cout<<cnt<<endl;
  }
}

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

const int MAX_N=303030;

int n;
ll dat[2*MAX_N-1];

void init(int N=202020){
  n=1;
  while(n<N) n*=2;
  for(int i=0;i<2*n-1;i++) dat[i]=LLONG_MAX;
}

// ｋ番目の値をaに変更
void update(int k, ll a){
  k+=n-1;
  dat[k]=a;
  while(k>0){
    k=(k-1)/2;
    dat[k]=min(dat[k*2+1],dat[k*2+2]);
  }
}

//    ↓ a以上b未満の区間に注意
//[a,b)の最小値を求める
//外からはquery(a,b,0,0,n)とする
ll query(int a, int b, int k, int l, int r){
  if(r<=a || b<=l) return LLONG_MAX;
  if(a<=l && r<=b) return dat[k];
  else{
    ll vl=query(a,b,k*2+1,l,(l+r)/2);
    ll vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
}

int H[202020],A[202020];

int main(){
  int N; cin>>N;
  init();
  rep(i,N) cin>>H[i];
  rep(i,N) cin>>A[i];
  ll ans=0;
  update(0,0);
  rep(i,N){
    ll tmp=-query(0,H[i],0,0,n)+A[i];
    ans=max(ans,tmp);
    update(H[i],-tmp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

struct edge{
    ll from, to, cost;
    edge(ll s, ll d, ll w) : from(s), to(d), cost(w){}
    
    bool operator < (const edge& x) const {
        return cost < x.cost;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, H, W;
    cin >> N >> H >> W;
    vector<edge> e;

    UnionFind uf(H + W + 10);

    REP(i,N){
        ll R, C, A;
        cin >> R >> C >> A;
        e.emplace_back(R, C+H, -A);
    }

    sort(e.begin(), e.end());
    
    ll ans = 0;

    REP(i,N){
        if(!uf.issame(e[i].from, e[i].to)){
            ans += e[i].cost;
            uf.unite(e[i].from, e[i].to);
        }
        else{
            if(!uf.issame(e[i].from, 0)){
                ans += e[i].cost;
                uf.unite(e[i].from,0);
            }
        }
    }
    cout << ans * (-1) << endl;
}


Measured memory_bytes: 5748
#include <stdio.h>

int search(int *,int);

int main()
{
  int i,n,q,s,count=0,t,flip=0;
  scanf("%d",&n);
  int S[n];
  for(i=0;i<n;i++)
    {
      scanf("%d",&S[i]);
    }
  scanf("%d",&q);
  int T[q];
  for(i=0;i<q;i++)
    {
      scanf("%d",&T[i]);
    } 
  for(s=0;s<q;s++)
    {
      flip=0;
      for(t=s+1;t<q;t++)
	{
	  if(T[s]==T[t])
	    {
	      flip=1;
	      break;
	    }
	}
      //printf("flip%d\n",flip);
      if(flip!=1)
	{
	  i=0;
	  while(S[i]!=T[s])
	    {
	  i++;
	  if(i==n)
	    break;
	    }
	  if(i!=n)
	    {
	  count++;
	    }
	}
    }
  printf("%d\n",count);
  return 0;
}



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

using namespace std;

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

    int n, k;

    cin >> n >> k;

    int ans = 0;

    int x = 1;

    while(true){
        if(n < x) break;
        ans++;
        x *= k;
    }

    cout << ans << endl;

    return 0;
}


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

//int abs(int x1, int x2){
//  if(x1 > x2){
//    return x1 - x2;
//  }
//  else{
//    return x2 - x1;
//  }
//}

int main(){
  int N, K;
  cin>>N>>K;
  vector<int> x(N);
  int distance_sum = 0;
  for(int i = 0; i < N; i++){
    cin>>x.at(i);
    if(x.at(i) < K*0.5){
      distance_sum += 2*x.at(i);
    }
    else{
//      distance_sum += abs(x.at(i),K);
      distance_sum += 2*(K-x.at(i));
    }
  }
  cout<<distance_sum<<"\n";
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.Math;

public class Main {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        long[] a = new long[n+1];
        for(int i=0;i<=n;i++) a[i] = sc.nextLong();
        long[] b = new long[n];
        for(int i=0;i<n;i++) b[i] = sc.nextLong();

        long ans = 0;

        for(int i=0;i<n;i++) {
            long take = Math.min(a[i], b[i]);
            b[i] -= take;
            long take2 = Math.min(a[i+1], b[i]);
            a[i+1] -= take2;
            ans += take + take2;
        }

        pw.println(ans);
        pw.close();
    }
}


Measured memory_bytes: 43684
from collections import deque
from typing import List


def get_longest_path_depth(
    graph: List[List[int]], in_degrees: List[int], first_index: int = 0
) -> int:
    """Return the depth of the longest path of DAG.
    if the given graph is not DAG, -1 is returned.
    """
    V = len(graph) + first_index
    queue = deque()
    depths = [-1] * V  # depths[i] := the length of the longest path to V_i
    for i in range(first_index, V):
        if not in_degrees[i]:
            queue.append(i)
            depths[i] = 0

    while queue:
        u = queue.popleft()
        cur_depth = depths[u]
        for v in graph[u]:
            in_degrees[v] -= 1
            if not in_degrees[v]:
                depths[v] = max(depths[v], cur_depth + 1)
                queue.append(v)

    return max(depths[first_index:]) if min(depths[1:]) != -1 else -1


def abc139_e():
    N, *A = map(int, open(0).read().split())

    ids = [[-1] * (N + 1) for _ in range(N + 1)]
    cur_id = 0
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            ids[i][j] = ids[j][i] = cur_id
            cur_id += 1

    graph = [[] for _ in range(N * (N - 1) // 2)]
    in_degrees = [0] * (N * (N - 1) // 2)
    for i, a in enumerate(zip(*[iter(A)] * (N - 1)), 1):
        source = -1
        for j in a:
            target = ids[i][j]
            if source != -1:
                graph[source].append(target)
                in_degrees[target] += 1
            source = target

    depth = get_longest_path_depth(graph, in_degrees)
    print(depth + 1 if depth != -1 else -1)


if __name__ == "__main__":
    abc139_e()


Measured memory_bytes: 144036
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const a = Number(input[0][0]);
  const b = Number(input[1][0]);
  const h = Number(input[2][0]);

  return ((a + b) * h) / 2;
};

console.log(main(read()));


Measured memory_bytes: 29648
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    int cur = 0;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        if(s == "A") cur++;
        else cur--;
        if(cur < 0) {
            puts("NO");
            return 0;
        }
    }
    puts(cur == 0 ? "YES" : "NO");
    return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
int a[200100];
int b[200100];
bool check(int k){
	// cout << k << endl;
	for(int i=0;i<2*N-1;i++){
		if(a[i]>=k)b[i] = 1;
		else b[i] = 0;
		// cout << b[i] << ' ';
	}
	// cout << endl;
	if(b[N-1]==b[N-2]||b[N-1]==b[N]){
		if(b[N-1])return true;
		else return false;
	}
	int c = 1;
	while(c<N&&b[N-1-c]==b[N-1+c]&&b[N-c]!=b[N-1-c]){
		c++;
	}		
	int bit = (c+1)%2;
	int top = b[N-1]^bit;
	if(c==N){
		if(top==1)return true;
		else return false;
	}
	vi tmp;
	tmp.pb(top);
	tmp.pb(b[N-1-c]);
	tmp.pb(b[N-1+c]);
	sort(all(tmp));
	if(tmp[1])return true;
	else return false;
}
int main(){
	cin >> N;
	for(int i=0;i<2*N-1;i++){
		cin >> a[i];
	}
	int l = 1,r = 2*N-1;
	while(r-l>1){
		int mid = (l+r)/2;
		// cout << l << ' ' << r << endl;
		if(check(mid))l = mid;
		else r = mid;
	}
	cout << l << endl;
	return 0;
}


Measured memory_bytes: 1920
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

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

    int ans = 0;
    int cnt = 0;

    for(int i = 0; i < s.size(); i++)
    {
        if(!(s.at(i) == 'A' or s.at(i) == 'C' or s.at(i) == 'G' or s.at(i) ==  'T'))
        {
            ans = max(ans, cnt);
            cnt = 0;
            continue;
        }

        cnt++;
    }

    ans = max(ans, cnt);

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a[6];
	int p[3],s[2];
	for(int i=0;i<3;i++)
		cin>>p[i];
	for(int i=0;i<2;i++)
		cin>>s[i];
	for(int i=0;i<6;i++)
		a[i]=p[i%3]+s[i%2]-50;
	for(int i=0;i<5;i++){
        for(int j=5;j>i;j--){
	        if(a[j]<a[j-1]){
	        int t=a[j];
	        a[j]=a[j-1];
	        a[j-1]=t;
	        }
        }
    }
	cout<<a[0]<<endl;
	return 0;
}

Measured memory_bytes: 1160
n,k = map(int, input().split(" "))
kai = [0,1]

for i in range(2,2000):
    kai.append(kai[-1]*i)

def comb(l,r):
    if l == r:
        return 1
    else:
        return kai[l] // kai[r] // kai[l - r]

for i in range(1,k+1):
    if i == 1:
        print(str(n-k+1))
    elif n - k < i - 1:
        print(0)
    else:
        print(comb(n-k+1,i)*comb(k-1,i-1)%(10**9+7))

Measured memory_bytes: 5748
import sys


def main():
    # input = sys.stdin.readline
    paid = int(input())

    tax_rate = 1.08

    price = paid / tax_rate
    price = int(price + 0.9)

    if paid == int(price * tax_rate):
        print(price)
    else:
        print(':(')


if __name__ == '__main__':
    main()


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

lis = [1, 6, 36, 216, 1296, 7776, 46656,
     9, 81, 729, 6561, 59049]
m = len(lis)

dp = [float('inf') for _ in range(n+1)]
dp[0] = 0

for j in range(1,n+1):
    temp = []
    for i in range(m):
        if j < lis[i]:
            continue
        else:
            temp.append(dp[j-lis[i]]+1)
    dp[j] = min(temp)

print(dp[n])


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& e : a) cin >> e;
  sort(begin(a), end(a));

  vector<pair<int, int>> v;
  int m;
  if (n == 2) {
    v.push_back({a[1], a[0]});
    m = v.front().first - v.front().second;
  } else {
    int b = upper_bound(begin(a), end(a), 0) - begin(a);
    if (b == 0) b = 1;
    if (b == n) b = n - 1;

    if (b == n - 1) {
      m = a[b];
      for (int i = 0; i < b; i++) {
        v.push_back({m, a[i]});
        m = m - a[i];
      }
    } else {
      m = a[0];
      for (int i = b; i < n - 1; i++) {
        v.push_back({m, a[i]});
        m = m - a[i];
      }
      v.push_back({a[n - 1], m});
      m = a[n - 1] - m;
      for (int i = 1; i < b; i++) {
        v.push_back({m, a[i]});
        m = m - a[i];
      }
    }
  }
  cout << m << endl;
  for (auto e : v) cout << e.first << ' ' << e.second << endl;
}


Measured memory_bytes: 3188
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

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

using namespace std;
using namespace __gnu_pbds;

#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007LL
#define PI acosl(-1)

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve()
{
	int k;
	cin >> k;
	int val = 7 % k;
	for (int i = 1; i < 1e7; i++)
	{
		if (val == 0)
		{
			cout << i;
			return;
		}
		val = ((val * 10) + 7) % k;
	}
	cout << -1;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}

Measured memory_bytes: 3660
using System;
class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        int c = int.Parse(str[2]);
        
        if(a < b && b < c)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
        
    }
    
}


Measured memory_bytes: 17908
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 305;
const int mod = 998244353;

ll p[maxn];
int n,a[maxn];
ll f[maxn][maxn*maxn][2][2];

void pd(ll&ret,ll val){
  ret+=val;
  if(ret>=mod)ret-=mod;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
  cin>>n;
  int sum = 0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  p[0]=1;
  for(int i=1;i<=n;i++)p[i] = p[i-1]*2%mod;
  f[0][0][0][0]=1;
  for(int i=0;i<n;i++)
    for(int j=0;j<=sum;j++)
      for(int k=0;k<2;k++)
        for(int q=0;q<2;q++){
          if(f[i][j][k][q]==0LL)continue;
          pd(f[i+1][j][k|1][q],f[i][j][k][q]);
          pd(f[i+1][j][k][q|1], f[i][j][k][q]);
          pd(f[i+1][j+a[i+1]][k][q], f[i][j][k][q]);
        }
  ll ret = 1;
  for(int i=0;i<n;i++)ret=ret*3%mod;
  ret=(ret+mod-3)%mod;
  //cout<<p[n]<<endl;
  ret=(ret+mod-3*(p[n]+mod-2)%mod)%mod;
  //cout<<ret<<endl;
  for(int i=(sum+1)/2;i<=sum;i++){
    //cout<<f[n][i][1][1]<<endl;
    ret=(ret+mod-3*f[n][i][1][1]%mod)%mod;
  }
  cout<<ret<<endl;
  return 0;
}

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

int main(){
  long long N,M,K;
  cin >> N >> M >> K;
  vector<long long> A(N),B(M);
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(i>0) A[i] += A[i-1];
  }
  for(int i=0;i<M;i++){
    cin >> B[i];
    if(i>0) B[i] += B[i-1];
  }
  
  long long ans = upper_bound(B.begin(),B.end(),K) - B.begin();
  for(int i=0;i<N;i++){
    if(K<A[i]) break;
    long long x = upper_bound(B.begin(),B.end(),K-A[i]) - B.begin();
    ans = max(ans,(i+1)+x);
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6372
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int H,W,h,w;
    cin>>H>>W>>h>>w;
    int ans=(H-h)*(W-w);
    OUT(ans);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define NIL  -1


bool prime_number(int x) {
	if (x == 1)return false;
	for (int i = 2; i*i <= x; i++) {
		if (x%i == 0)return false;
	}
	return true;
}

long long Pow(long long a, long long n) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}

int A[100000];


int main() {
	cin.tie(0);
	cout.tie(0);

	
	ios::sync_with_stdio(false);
	CST(10);

	double N;
	cin >> N;

	cout << N * 2.0*pi << endl;
	
	return 0;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pll  = pair<ll,ll>;
using vll  = vector<pll>;
using vvll = vector<vll>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define dmax(a,b) a=max(a,b)

int main() {
    int n; cin >> n;
    vll a(1<<n);
    vvll dp(1<<n, vll(2));
    rep(i,1<<n) {
        cin >> a[i].first;
        a[i].second = i;
        dp[i][0] = a[i];
    }
    rep(b,1<<n) {
        rep(i,n) {
            int nb = b | (1<<i);
            if (nb == b) continue;
            set<pll> S;
            rep(j,2) {
                S.insert(dp[b][j]);
                S.insert(dp[nb][j]);
            }
            auto mx = S.rbegin();
            dp[nb][0] = *mx;
            dp[nb][1] = *++mx;
        }
    }
    ll ans = 0;
    rng(i,1,1<<n) {
        dmax(ans, dp[i][0].first + dp[i][1].first);
        cout << ans << endl;
    }
    return 0;
}


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

long long n, m;

int main(){
	scanf("%lld%lld", &n, &m);
	if (m / 2 <= n){
		return printf("%lld\n", m / 2), 0;
	}
	long long x = m - 2 * n;
	return printf("%lld", x / 4 + n), 0;
}

Measured memory_bytes: 768
# -*- coding: utf-8 -*-
"""
Created on Thu May  3 21:24:25 2018
ALDS1_6_B
@author: maezawa
"""

n = int(input())
a = list(map(int, input().split()))

def partition(a, p, r):
    x = a[r]
    i = p - 1
    for j in range(p, r):
        if a[j] <= x:
            i += 1
            temp = a[i]
            a[i] = a[j]
            a[j] = temp
    temp = a[i+1]
    a[i+1] = a[r]
    a[r] = temp
    return i+1
    
mid = partition(a, 0, len(a)-1)
print(a[0], end='')
for i in range(1, mid):
    print(' {}'.format(a[i]), end='')
print(' [{}]'.format(a[mid]), end='')
for i in range(mid+1,len(a)):
    print(' {}'.format(a[i]), end='')
print()


Measured memory_bytes: 16396
import java.util.*;

class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      	
      int n = sc.nextInt();
      int k = sc.nextInt();
      int q = sc.nextInt();
      int[] a = new int[q];
      int[] ppl = new int[n];
      
      for(int i=0;i<q;i++){
      	a[i] = sc.nextInt();
      }
      
      for(int i=0;i<n;i++){
      	ppl[i] = k - q;
      }
      
      for(int i=0;i<q;i++){
      	ppl[a[i]-1] += 1;
      }
      
      for(int i=0;i<n;i++){
      	if(ppl[i] > 0){
          System.out.println("Yes");
        } else {
          System.out.println("No");	
        }
      }
      
	      
    }
}

Measured memory_bytes: 61204
using System;
class Program
{
  static void Main(string[] args)
  {
    // スペース区切りの整数の入力
    int a,b,k;
    string[] input = Console.ReadLine().Split(' ');
    a  = int.Parse(input[0]);
    b  = int.Parse(input[1]);
    k  = int.Parse(input[2]);



    for (int i=0;i<k;i++){
      Console.WriteLine(a+i);
      if (a+i >=b)break;
    }

    for (int i=k-1;i>=0;i--){
      if (a+k > b-i)continue;
      Console.WriteLine(b-i);
    }


  }


}

Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int x, y;
	cin >> x >> y;
	int a[12] = { 1,3,1,2,1,2,1,1,2,1,2,1};
	cout << (a[x-1] == a[y-1] ? "Yes" : "No") << endl;
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <list>
#include <map>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define rep(i,n) for(register int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
const int dx[]={0,1,-1,0},dy[]={1,0,0,-1};
const int MOD=1e9+7;
const int N=2e5+10;

inline int read(){
	int ww=1,xx=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') ww=-ww;ch=getchar();}
	while(isdigit(ch)){xx=(xx<<1)+(xx<<3)+(ch^48);ch=getchar();}
	return ww*xx;
}

int n;
char s[N];

void init(){
	n=read();
	scanf("%s",s);
}

void solve(){
	LL ans=1,tmp=0;
	for(int i=0;i<2*n;i++){
		if(!(((s[i]=='W')^tmp)&1)) tmp++;
		else ans=1LL*ans*tmp%MOD,tmp--;
	}
	if(tmp) puts("0");
	else {
		for(int i=1;i<=n;i++) ans=1LL*ans*i%MOD;
		printf("%d\n",ans);
	}
}

signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	init();
	solve();
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
main(){
  int a[12],i,sum=0,km=0;
  double x,y;

  while(1){
    if(scanf("%d",&a[0]) == EOF) break;
    for(i=1;i<12;i++){
      scanf(",%d",&a[i]);
    }
    
    for(i=0;i<10;i++){
      sum += a[i];
    }
    
    x = (double)sum/(a[10]+a[11]);
    y = a[10]*x;
    
    for(i=0;i<10;i++){
      km += a[i];
      if(y<=km){
	printf("%d\n",i+1);
	sum=0; km=0;
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<cmath>
using namespace std;
typedef vector<int> vi;
set<string> cands;
int dy[]={-1,-1,-1,0,0,1,1,1};
int dx[]={-1,0,1,-1,1,-1,0,1};
int maxlength=0,h,w;
string ans="";
vector<int> pri;
bool arr[10005];
void func()
{
  for(int i=0;i<=10000;i++)
    {
      arr[i]=true;
    }
  for(int i=2;i<=sqrt(10000);i++)
    {
      if(arr[i])
	{
	  for(int j=2*i;j<=10000;j+=i)
	    {
	      if(j%i==0)arr[j]=false;
	    }
	}
    }
  for(int i=2;i<10000;i++)
    {
      if(arr[i]) pri.push_back(i);
    }
}

int main()
{
  func();
  while(1) 
    {
      int m,a,b;
      cin >> m >> a >> b;
      if(!m) break;
      int ans=0;
      int height=0,width=0;
      for(int i=0;i<pri.size();i++)
	{
	  for(int j=0;j<pri.size();j++)
	    {
	      if(pri[i]*pri[j]<=m && (double)pri[j]/pri[i]>=(double)a/b && (double)pri[j]/pri[i]<=1)
		{
		  if(pri[i]*pri[j]>ans)
		    {
		      ans=pri[i]*pri[j];
		      height=pri[i];
		      width=pri[j];
		    }
		}
	    }
	}
      
      cout << width << ' ' << height << endl;
    }
  return 0;
}



Measured memory_bytes: 3120
#coding:UTF-8
def BS(N,A):
    count=0
    flag=True
    while flag==True:
        flag=False
        for i in range(1,N):
            if A[N-i]<A[N-i-1]:
                swap=A[N-i]
                A[N-i]=A[N-i-1]
                A[N-i-1]=swap
                flag=True
                count+=1
    for i in range(len(A)):
        A[i]=str(A[i])
    print(" ".join(A))
    print(count)

if __name__=="__main__":
    N=int(input())
    a=input()
    A=a.split(" ")
    for i in range(len(A)):
        A[i]=int(A[i])
    BS(N,A)

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

int main() {
	int N,Y;
	cin >> N >> Y;
	int y10 = 10000,y5 = 5000,y1 = 1000;
	int a=0,b=0,c=0;
	for(int i = 0;i <= N;i++)
	{
		for(int j = 0;j <= N - i;j++)
		{
			if(y10 * i + y5 * j + y1 * (N - i - j) == Y)
			{
				cout << i << ' ' << j << ' ' << N - i - j << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<iterator>
#include<iomanip>
#include<cmath>
#include<map>
#include<string.h>
#include<algorithm>

using namespace std;
void ll(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main(){

	ll();


	string s;
	cin >> s;
	int x, y;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'A'){
			x = i;
			break;
		}
	}
	for (int i = s.length() - 1; i >= 0; i--)
	{
		if (s[i] == 'Z'){
			y = i;
			break;
		}
	}
	cout << (y - x) + 1 << endl;
}

Measured memory_bytes: 3740
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (map.containsKey(a[i])) {
                map.put(a[i], map.get(a[i]) + 1);
            } else {
                map.put(a[i], 1);
            }
        }
        int c = 0;
        for (int i = 0; i < n; i++) {
            int x = a[i];
            boolean flg = true;
            for (int j = 2 ; j * j <= x; j++) {
                if (x % j == 0) {
                    if (map.containsKey(j)) {
                        flg = false;
                    }
                    if (map.containsKey(x / j)) {
                        flg = false;
                    }
                }
            }
            if (map.get(x) > 1) {
                flg = false;
            }
            if (flg) {
                c++;
            }
        }
        if (n == 1) {
            System.out.println(1);
            return;
        }
        if (map.size() == 1) {
            System.out.println(0);
            return;
        }
        if (map.containsKey(1) && map.get(1) == 1) {
            System.out.println(1);
            return;
        }
        if (map.containsKey(1) && map.get(1) > 1) {
            System.out.println(0);
            return;
        }

        System.out.println(c);

    }

}

Measured memory_bytes: 73784
#include <stdio.h>

int main(void)
{
	int N, A, sum = 0, i;
	scanf("%d", &N);
	for (i = 0; i < N; ++i) {
		scanf("%d", &A);
		if (A % 2) ++sum;
	}
	if (sum % 2) puts("NO");
	else puts("YES");
	return 0;
}

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

int main(int argc, char const *argv[])
{
	int a,b;
	cin>>a>>b;
	if (a>9||b>9)
	{
		cout<<"-1\n";
	}
	else
	{
		cout<<a*b<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

#define f first
#define se second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pi pair<int, int>
#define all(x) x.begin(), x.end()
#define lp(i, n) for (int i = 0; i < n; i++)
#define mem(a, v) memset(a, v, sizeof(a))
#define X real()
#define Y imag()
#define angle(a) (atan2(a.Y, a.X))
#define vec(a, b) ((b) - (a))
//#define length(a) (hypot(a.Y , a.X))
#define normalize(a) (a) / length(a)
#define dotP(a, b) ((conj(a) * b).X)
#define crossP(a, b) ((conj(a) * b).Y)
#define same(p1, p2) (dotP(vec(p1, p2), vec(p1, p2)) < EPS)
#define lengthSqr(a) dotP(a, a)
#define rotate0(p, ang) ((p)*exp(point(0, ang)))
#define rotateA(p, ang, about) (rotate0(vec(about, p), ang) + about)
#define reflect0(v, m) conj(v / m) * m
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const double PI = acos(-1.0);
const double EPS = (1e-10);
const long long int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
typedef long long int ll;
typedef unsigned long long ull;
typedef complex<double> point;
long long fastpow(ll n, ll x) {
  if (!x)
    return 1;
  if (x % 2)
    return n * fastpow(n, x - 1);
  ll p = fastpow(n, x / 2);
  p %= mod;
  p *= p;
  p %= mod;
  return p;
}

ll my_mod(ll num, ll mod) {
  ll ret = num % mod;
  while (ret < 0)
    ret += mod;
  return ret;
}

ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
long double dist(pair<ll, ll> &a, pair<ll, ll> &b) {
  return sqrt(
      ((a.f - b.f) * (a.f - b.f) * 1.0 + (a.se - b.se) * (a.se - b.se)));
}
/*vector<int> ap;
bool np[MX];
void s(){
    mem(np , 1);
    np[1] = np[0] = 0;
    for(ll i = 2 ; i*i<= MX ;i++){
        if(np[i]){
            for(ll j= i*i ; j <MX; j+=i) np[j] = 0;
        }
    }
    for(ll i = 2 ; i< MX ; i++) if(np[i]) ap.pb(i);
}*/
const ll MX = 2e5+5;
int n;
vector<int> h(MX);
vector<ll> a(MX);
vector<ll> seg(MX*4);
void update(int index , int l ,int r, int toUpdate,ll v){
	if(toUpdate < l || toUpdate > r) return;
	if(l == r){
		 seg[index] = v;
		 return;
	}
	int mid = (l+r)>>1;
	if(toUpdate <= mid) update(2*index,l,mid,toUpdate,v);
	else update(2*index+1,mid+1,r,toUpdate,v);
	seg[index] = max(seg[2*index] ,seg[2*index+1]);
}
ll query(int index,int l,int r,int L,int R){
	if(R < l || L > r) return 0;
	if(l>=L && r<= R) return seg[index];
	return max(query(2*index,l,(l+r)>>1,L,R)
	,query(2*index +1 , ((l+r)>>1) +1 ,r,L,R));
}

int main()
{
    IO;
    cin>>n;
    for(int i = 0 ; i< n ;i++)cin>>h[i];
    for(int i = 0 ; i< n ;i++)cin>>a[i];
    ll ans = 0;
    for(int i = 0 ; i < n; i++){
		ll cmax = query(1,0,n-1,0,h[i]-1);
		ans = max(ans, cmax+a[i]);
		update(1,0,n-1,h[i],a[i]+cmax);
	}
	cout<<ans;
    return 0;
}



Measured memory_bytes: 8832
#include <stdio.h>

typedef struct List {
	struct List *next;
	int v;
} list;

const int Mod = 1000000007;

int main()
{
	int i, N, u, w;
	list *adj[100001], e[200001], *p;
	scanf("%d", &N);
	for (i = 0; i < N - 1; i++) {
		scanf("%d %d", &u, &w);
		e[i*2].v = w;
		e[i*2+1].v = u;
		e[i*2].next = adj[u];
		e[i*2+1].next = adj[w];
		adj[u] = &(e[i*2]);
		adj[w] = &(e[i*2+1]);
	}
	
	int par[100001] = {}, q[100001], head, tail;
	par[1] = 1;
	q[0] = 1;
	for (head = 0, tail = 1; head < tail; head++) {
		u = q[head];
		for (p = adj[u]; p != NULL; p = p->next) {
			w = p->v;
			if (par[w] == 0) {
				par[w] = u;
				q[tail++] = w;
			}
		}
	}
	
	long long dp[100001][2] = {};
	for (head--; head >= 0; head--) {
		u = q[head];
		dp[u][0] = 1;
		dp[u][1] = 1;
		for (p = adj[u]; p != NULL; p = p->next) {
			w = p->v;
			if (w == par[u]) continue;
			dp[u][0] = dp[u][0] * (dp[w][0] + dp[w][1]) % Mod;
			dp[u][1] = dp[u][1] * dp[w][0] % Mod;
		}
	}
	printf("%lld\n", (dp[1][0] + dp[1][1]) % Mod);
	fflush(stdout);
	return 0;
}

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

int main()
{
    int a,b;
    double n;
    cin>>a>>b;
    if (b<10) n=sqrt(a*10+b);
    else if (b<100) n=sqrt(a*100+b);
    else n=sqrt(a*1000+b);
    int m=n;
    if (n==m) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, m, i, j, k, l, count;
  cin >> h >> m;
  vector<vector<char>>  list(10000,vector<char>(10000));
  for(i=0;i<h;i++) {
    for(j=0;j<m;j++) {
      cin >> list.at(i).at(j);
    }
  }  
  for(i=0;i<h;i++) {
    count = 0;
    for(j=0;j<m;j++) {
      if(list.at(i).at(j) == '#') {
        count++;
      }
    }
    if(count == 0) {
      for(k=i;k<h;k++) {
        for(l=0;l<m;l++) {
          list.at(k).at(l) = list.at(k+1).at(l);
        }
      }
      h--;
      i--;
    }
  }
  
   for(i=0;i<m;i++) {
    count = 0;
    for(j=0;j<h;j++) {
      if(list.at(j).at(i) == '#') {
        count++;
      }
    }
    if(count == 0) {
      for(k=i;k<m;k++) {
        for(l=0;l<h;l++) {
          list.at(l).at(k) = list.at(l).at(k+1);
        }
      }
      m--;
      i--;
    }
  }
   for(i=0;i<h;i++) {
     for(j=0;j<m;j++) {
       cout << list.at(i).at(j);
     }
   cout << endl;
   }
  return 0;
}
     
    
        
      
    
    

Measured memory_bytes: 101196
S = input()

def rec(n, s):
    if n == 1:
        ans = 0
        for i in s.split("+"):
            ans += int(i)
        return ans
    
    # 文字列の後ろからn番目に"+"を入れるか否か
    return rec(n-1, s) + rec(n-1, s[:-n+1]+"+"+s[-n+1:])

print(rec(len(S), S))

Measured memory_bytes: 3060
import sys

N = int(input())
S = list(input())

count = sys.maxsize
ans = S[1:].count("E")

for i in range(N-1):
    count = min(ans, count)
    if S[i] == "W":
        if S[i+1] == "W":
            ans += 1
    elif S[i] == "E":
        if S[i+1] == "E":
            ans -= 1

count = min(ans, count)
print(count)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w, n;
	pii xy[214514];
	cin>>h>>w>>n;
	REP(i, n){
		cin>>xy[i].first>>xy[i].second;
		--xy[i].first;
		--xy[i].second;
	}
	sort(xy, xy+n);
	int ans=h, cnt=0;
	REP(i, n){
		if(xy[i].first==xy[i].second+cnt){
			++cnt;
		}
		else if(xy[i].first>xy[i].second+cnt){
			CHMIN(ans, xy[i].first);
		}
		// DEBUG(cnt);
		// DEBUG(ans);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1920
#include<stdio.h>
int main(void) {
	int N, C, p=0, x, a = 0, b=0, c, d;
	scanf("%d", &N);
	scanf("%d", &C);
	for (a = 0; a < C; a++) {
		scanf("%d", &p);
		b = b + p;
	}
	x = b % (1+N);
	if (x == 0) {
		x = b / (1 + N);
		printf("%d\n", x);
	}
	else if (x == b) {
		c = 1;
		printf("%d\n", c);
	}
	else {
		c = b / (N + 1);
		c = c + 1;
		printf("%d\n", c);
	}
	return 0;
}


Measured memory_bytes: 2728
#include<bits/stdc++.h>
    using namespace std;
    signed main(){
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    long long n,sum;
    cin>>n;
    for(int i=1;i<n;i++) sum+=i;
    cout<<sum<<'\n';
    return 0;
    }

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int dp[55][55][2][1333];
int bef[1030][55][55];
signed main(){
	int n,m;
	while(cin>>n>>m,n){
		vs in(n);
		rep(i,n)cin>>in[i];
		string text="";
		rep(i,m){
			string s;
			cin>>s;
			text+=s;
		}
		int sum=0;
		rep(i,n)sum+=in[i].size();
		m=text.size();
		vvi isok(m,vi(n));
		rep(i,m)rep(j,n){
			if(text.substr(i,in[j].size())==in[j])isok[i][j]=1;
		}
		int co=0;
		rep(i,m){
			if(i+sum>m)continue;
			vi dp(1<<n);
			dp[0]=1;
			rep(j,1<<n)if(dp[j]){
				int c=0;
				rep(k,n)if(j&1<<k)c+=in[k].size();
				rep(k,n)if((j&1<<k)==0){
					if(isok[i+c][k])dp[j|1<<k]=1;
				}
			}
			if(dp[(1<<n)-1]){
//				cout<<i<<endl;
				co++;
			}
		}
		cout<<co<<endl;
	}
}







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


class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        string N = s[0];
        long x = long.Parse(s[1]);
        long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        long temp = 0;
        Array.Sort(a);
        if(a.Sum() < x)
        {
            Console.WriteLine(a.Length - 1);
            return;
        }

        for(long i = 0; i < a.Length; i++)
        {
            x -= a[i];

            //temp = i;
            if(x < 0)
            {
                break;
            }
            temp++;
        }
        Console.WriteLine(temp);
    }
}


Measured memory_bytes: 13396
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ADivideACuboid solver = new ADivideACuboid();
        solver.solve(1, in, out);
        out.close();
    }

    static class ADivideACuboid {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
            out.println(a * b * c % 2 == 0 ? 0 : Math.min(a * b, Math.min(b * c, c * a)));
        }

    }
}



Measured memory_bytes: 21844
//ABC 133 C Remainder Minimization 2019

#include <iostream>

using namespace std;

int main() {
    int l, r;
    cin >> l >> r;
    int min=2019;
    for(int i=l; i<r; i++) {
        for(int j=i+1; j<=r; j++) {
            if(min>(i%2019)*(j%2019)%2019) {
                min=(i%2019)*(j%2019)%2019;
            }
            if(min==0) {
                cout << min << endl;
                return 0;
            }
        }
    }
    cout << min << endl;
    return 0;
}

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

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

int main(){
    int r, g, b;
    cin >> r >> g >> b;

    int num = 100 * r + 10 * g + b;
    if(num % 4 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int swap(int N,int p[N]);

int main(){
	int N,i,ans;
	scanf("%d",&N);
	if(2>N||N>100000)return -1;
	int p[N];
	for(i=0;i<N;i++){
		scanf("%d",&p[i]);
	}
	ans=swap(N,p);
	printf("%d",ans);
}

int swap(int N,int p[N]){
	int cnt=0,i;
	for(i=0;i<N;i++){
		if(i+1==p[i]){
			if(i==N-1){
				p[i]^=p[i-11];
				p[i-1]^=p[i];
				p[i]^=p[i-1];
				cnt++;
				break;
			}
			if(i+1==p[i+1]){
				continue;
			}
			p[i]^=p[i+1];
			p[i+1]^=p[i];
			p[i]^=p[i+1];
			cnt++;
		}
	}
	return cnt;
}


Measured memory_bytes: 512
using System;
using System.Linq;
using CompLib.Util;

public class Program
{
    int N;
    long A, B, C, D;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.NextLong();
        B = sc.NextLong();
        C = sc.NextLong();
        D = sc.NextLong();

        // +に移動 r回
        for (int r = 0; r < N; r++)
        {
            // -に移動 l回
            int l = N - r - 1;

            // 移動できる右端
            long max = D * r - C * l;
            // 左端
            long min = C * r - D * l;

            if (A + min <= B && B <= A + max)
            {
                Console.WriteLine("YES");
                return;
            }
        }
        Console.WriteLine("NO");
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast()    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod   1000000007
int main()
{
	fast()
	int x,y;
    cin>>x>>y;
    int Y=(y-2*x);
    if(y%1)
    cout<<"No";
    else if(Y<0)
    cout<<"No";
    else if(Y%2!=0)
    cout<<"No";
    else if((Y/2)<=x)
    cout<<"Yes";
    else
    cout<<"No";
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  int a, b; cin >> a >> b;
  int p1 = 0, p2 = 0, p3 = 0;
  REP(i, n) {
    int tmp; cin >> tmp;
    if(tmp <= a) {
      p1++;
    } else if(tmp <= b) {
      p2++;
    } else {
      p3++;
    }
  }
  cout << min(p1, min(p2, p3)) << endl;
}


Measured memory_bytes: 256