akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int n, k, q;
    cin >> n >> k >> q;
    vi a(n);

    rep(i, q)
    {
        int b;
        cin >> b;
        a[b - 1]++;
    }

    rep(i, n)
    {
        //cout << "a : " << a[i] << endl;
        if (abs(a[i] - q) >= k)
            cout << "No" << endl;
        else
            cout << "Yes" << endl;
    }

    // vi count(n, k);
    // rep(i, )

    //     rep(i, q)
    // {
    //     rep(j, n)
    //     {
    //         // cout << "i : " << i
    //         //      << ", j : " << j << endl;
    //         if (a[i] - 1 != j)
    //         {
    //             //cout << "a[i] " << a[i] << endl;
    //             //cout << "ans1" << ans[j] << endl;
    //             ans[j]--;
    //             //cout << "ans2" << ans[j] << endl;
    //         }
    //     }
    // }

    // rep(i, n)
    // {
    //     if (ans[i] <= 0)
    //         cout << "No" << endl;
    //     else
    //         cout << "Yes" << endl;
    // }

    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;

namespace D2019PC
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] s = Console.ReadLine().Split(' ');
            int[] n = s.Select(x => int.Parse(x)).ToArray();

            int result = 0;

            result = n[0] - (n[1] - 1);

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int>a(n+1,0);
	int num,count=0;
	repp(i, 0, n) {
		cin >> num;
		if (num <= n)++a[num];
		else ++count;
	}
	for (int i = 0; i <= n; ++i) {
		if (a[i] - i < 0)count += a[i];
		else count += a[i] - i;
	}
	cout << count << endl;
	return 0;
}

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

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
using namespace std;
using ll = long long;
using lld = long long;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

ll gcd(ll a, ll b)
{
  if (a < b)
  {
    return gcd(b, a);
  }
  while (b != 0)
  {
    ll tmp = b;
    b = a % b;
    a = tmp;
  }
  return a;
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while(b) {
    ll t =  a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

int bit_counter(int x) {
  if (x == 0) return 0;
  return bit_counter(x >> 1) + (x&1);
}

int main() {
  ll N;
  cin >> N;
  ll minus_count = 0;
  vector<ll> A(N);
  loop(0, N, i) {
    cin >> A[i];
    if (A[i] < 0) minus_count++;
  }

  ll sum = 0;
  loop(0, N, i) {
    sum += abs(A[i]);
  }

  if (minus_count%2 == 1) {
    ll mn = (ll)1e6;
    loop(0, N, i) {
      mn = min(abs(A[i]), mn);
    }
    sum -= 2*mn;
  }
  print(sum);
}


Measured memory_bytes: 4036
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

const ll mod = 1000000007;
const int N = 2e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n;
int f[N<<1], cntX[N<<1], cntY[N<<1];
void init() {
	mt(cntX, 0); mt(cntY, 0);
	rep(i, 1, 2 * N) f[i] = i; 
}
int fd(int x) { return x == f[x] ? x : f[x] = fd(f[x]); }
int main() {
	// 优质题解
	// https://luckyglass.github.io/2019/19June22ndArt1/
	while(~scanf("%d", &n)) {
		init();
		rep(i, 0, n) {
			int x, y; scanf("%d%d", &x, &y);
			int fx = fd(x), fy = fd(y + N);
			// dd(fx); de(fy);
			f[fy] = fx;
		}
		rep(i, 1, N) cntX[fd(i)]++;
		rep(i, 1, N) cntY[fd(N + i)]++;
		ll ret = 0;
		rep(i, 1, 2 * N) {
			// if(cntX[fd(i)]&&cntY[fd(i)]) { dd(i);dd(fd(i));dd(cntX[fd(i)]);de(cntY[fd(i)]); }
			ret += 1ll * cntX[i] * cntY[i];
		}
		printf("%lld\n", ret - n);
	}
    return 0;
}


Measured memory_bytes: 4992
import heapq
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
day = {i+1: [] for i in range(M)}
for a, b in ab:
  if a <= M:
    day[a] += [-b]
q = []
heapq.heapify(q)
pay = 0
for i in range(M):
  for b in day[i+1]:
    heapq.heappush(q, b)
  if len(q) > 0:
    pay += -heapq.heappop(q)

print(pay)
  




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

int main()
{
    long long q,h,s,d,n,a,b,i;
    cin>>q>>h>>s>>d>>n;
    a=min(q*4,min(h*2,s));
    b=min(d,a*2);
    i=(n/2)*b;
    n%=2;
    i+=(n*a);
    cout<<i;
    return 0;
}


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

using namespace std;

long long n, b, w[110], v[110], dp[110][100010]; //idx segini, val segini, minimum capacity ku brp

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin >> n >> b;
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j < 100010; j++) {
			dp[i][j] = 1e18 + 18;
		}
		dp[i][0] = 0;
	}
	for(long long i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 100010 - 1; j >= 0; j--) {
			dp[i][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
		}
		for(int j = 100010 - 1; j >= 0; j--) {
			if(i < n) {
				dp[i+1][j] = dp[i][j];
			}
		}
	}
	for(int j = 100010 - 1; j >= 0; j--) {
		if(dp[n][j] <= b) {
			cout << j << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 80128
n = gets.to_i
s = gets.chomp
arr = Array.new(n,0)
n.times do |i|
  if i != 0
    arr[i] = arr[i-1]
  end
  arr[i] += 1 if s[i] == '.'
end
min = n
(n-1).times do |i|
  count = (i+1 - arr[i])
  count += (arr[n-1] - arr[i])
  min = count if min > count
end
min = [min,arr[n-1],n-arr[n-1]].min
puts min

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

int main() {
	int N, M, a, b,rootCount = 0;
	cin >> N >> M;
	vector<pair<int, int>> vec(M);

	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		vec[i] = make_pair(a, b);
	}

	vector<int> vertex(N);
	for (int i = 0; i < N; i++) {
		vertex[i] = i + 1;
	}

	bool flg;
	do {
		if (vertex[0] == 1) {
			for (int i = 0; i < vertex.size() - 1; i++)
			{
				flg = false;
				for (auto pii : vec)
				{
					if ((vertex[i] == pii.first && vertex[i + 1] == pii.second) ||
						(vertex[i] == pii.second && vertex[i + 1] == pii.first))
					{
						flg = true;
						break;
					}
				}

				if (!flg)
				{
					break;
				}
			}

			if (flg)
			{
				rootCount++;
			}
		}
	} while (next_permutation(vertex.begin(), vertex.end()));

	cout << rootCount;
}

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


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

  bool ans = true;
  rep(i, N) {
    if (A[i] % 2 == 0) {
      if ((A[i] % 3 == 0) || (A[i] % 5 == 0)) {
        continue;
      } else {
        ans = false;
        break;
      }
    }
  }

  if (ans) {
    cout << "APPROVED" << endl;
  } else {
    cout << "DENIED" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)


int main() {

	int N;
	int a[3123];

	scanf("%d", &N);
	rep(i, N) scanf("%d", &a[i]);
	
	ll ans = 0;
	rep(i, N) {
		ans += a[i] - 1;
	}

	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main ()
{
	int n,k;
	int a = 1;
	int i = 0;
	int j = 1;
	while(scanf("%d\n%d", &n, &k)!=EOF)
	{
		if (k > 0)
		{
		while (n--)
		{
			if(a<k)
			a = a * 2;
			else
			a = a + k;
		}
		printf("%d\n",a);
		}
		else
		{
			for (int x = 1;x <= n;x++)
			{
				a = a + k;
			}
			printf("%d\n",a);
		}
		a = 1;
		i = 0;
		j = 1;
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INF = 999999999;
const int MOD = (int)1e9 + 7;
const int EPS = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  char s = 'a';
  REP(i,26){
    if ((int) S.find(s)==-1){
        cout << s << endl;
        return 0;
    }
    s++;
  }
  cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef vector < int > VI;
typedef vector < VI > VVI;
typedef pair < int , int > PII;
 
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define MP make_pair
#define SZ(x) x.size()
#define SET(a , b) memset(a , b , sizeof(a))
#define REP(i, n) for(int i = 0 ; i < n ; i++)
#define FOR(i, a, b) for(int i = a ; i <= b ; i++)
#define FORD(i, a, b) for(int i = a ; i >= b ; i--)
#define BOOST ios_base::sync_with_stdio(0);
#define TCSOLVE() int tests; cin >> tests; REP(i, tests) solve();
 
const int N = 2e5 + 5, M = 2e5 + 5, mx = 1e9, LN = 20, mod = 1e9 + 7;



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

	FOR(i, 2, 360){
		if((x * i) % 360 == 0){
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3668
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int counter = 0;
		int A[] = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		boolean flg = true;
		while (flg) {
			for (int i = 0; i < N; i++) {
				if (A[i] % 2 == 0) {
					A[i] = A[i] / 2;
				} else {
					flg = false;
					break;
				}
				if (i == N - 1) counter++;
			}
		}
		System.out.println(counter);
	}
}


Measured memory_bytes: 21844
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll N = 0;
    cin >> N;

    vll a(N);
    ll total=0;
    REP(i,N) {cin >> a[i]; total+=a[i];}

    //本文
    ll ans = INF;
    ll cnt = 0;
    REP(i,N-1){
      cnt += a[i];
      total -= a[i];
      ll ans2 = abs(total - cnt);
      ans = min(ans,ans2);
    }
    //出力
    cout << ans << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Measured memory_bytes: 4728
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

struct Coord {
  int y;
  int x;

  Coord (int y = -1, int x = -1) {
    this->y = y;
    this->x = x;
  }
};

int main() {
  int N;
  cin >> N;
  vector <Coord> balls;

  int x, y;

  for (int i = 0; i < N; ++i) {
    cin >> x >> y;

    balls.push_back(Coord(y, x));
  }

  int ans = N;

  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      Coord c1 = balls[i];
      Coord c2 = balls[j];

      ll dy = c1.y - c2.y;
      ll dx = c1.x - c2.x;

      int cnt = 0;

      for (int n = 0; n < N; ++n) {
        for (int m = 0; m < N; ++m) {
          if (n == m) continue;

          Coord c3 = balls[n];
          Coord c4 = balls[m];

          ll ny = c3.y - c4.y;
          ll nx = c3.x - c4.x;

          if (ny == dy && nx == dx) {
            ++cnt;
          }
        }
      }

      ans = min(ans, N - cnt);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


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

    vector<ll> num_all, num_odd;
    FOR(i, 1, 1000) {
        ll N = i * (i + 1) * (i + 2) / 6;
        if (N > 1e6) break;
        num_all.pb(N);
        if(N & 1) num_odd.pb(N);
    }

    const int nmax = (int)1e6 + 1;

    vi dp_all(nmax, INF), dp_odd(nmax, INF);
    dp_all[0] = 0;
    dp_odd[0] = 0;

    for(auto &e: num_all) {
        REP(i, dp_all.size()) {
            if (i + e >= nmax) break;
            dp_all[i + e] = min(dp_all[i + e], dp_all[i] + 1);
        }
    }

    for(auto &e: num_odd) {
        REP(i, dp_odd.size()) {
            if (i + e >= nmax) break;
            dp_odd[i + e] = min(dp_odd[i + e], dp_odd[i] + 1);
        }
    }

    while(1) {
        int n; cin >> n;

        if (n == 0) break;

        cout << dp_all[n] << " " << dp_odd[n] << endl;
    }

}


Measured memory_bytes: 10596
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N,K,S;
    cin >> N >> K >> S;
    if(S > N){
        for(int i = 0; i < N; i++){
            if(i < K){
                cout << S << " ";
            }else{
                cout << 1ll << " ";
            }
        }
    }else{
        for(int i = 0; i < N; i++){
            if(i < K){
                cout << S << " ";
            }else{
                cout << N + 1ll << " ";
            }
        }
    }
    cout  << endl;

}

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

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt" , "r" , stdin);
// 	freopen("output.txt" , "w" , stdout);
// #endif

	ll n, m, r;
	cin >> n >> m >> r;
	ll rp[r];
	for (ll i = 0; i < r; i++)
		cin >> rp[i];
	ll dp[n + 1][n + 1] = {0};
	for (ll i = 1; i <= n; i++)
	{
		for (ll j = 1; j <= n; j++)
		{
			if (i != j)
				dp[i][j] = INT_MAX;
		}
	}
	for (ll i = 1; i <= m; i++)
	{
		ll a, b, c;
		cin >> a >> b >> c;
		if (dp[a][b] > c)
		{
			dp[a][b] = c;
			dp[b][a] = c;
		}
	}

	for (ll k = 1; k <= n; k++)
	{
		for (ll i = 1; i <= n; i++)
		{
			for (ll j = 1; j <= n; j++)
			{
				if (dp[i][j] > dp[i][k] + dp[k][j])
					dp[i][j] = dp[i][k] + dp[k][j];
			}
		}
	}

	ll mx = INT_MAX;
	sort(rp, rp + r);
	do
	{
		ll sum = 0;
		for (ll i = 0; i < r - 1; i++)
			sum += dp[rp[i]][rp[i + 1]];
		mx = min(sum, mx);

	} while (next_permutation(rp, rp + r));

	cout << mx << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n;){
    string e[12];
    for(int i=0;i<n;i++){
      cin>>e[i];
    }
    string t;
    for(int i=0;i<m;i++){
      string tt;
      cin>>tt;
      t+=tt;
    }
    bool ma[12][5000];
    int sum=0;
    for(int i=0;i<n;i++){
      sum+=e[i].size();
      for(int j=0;j<t.size();j++){
	ma[i][j]=e[i]==t.substr(j,e[i].size());
      }
    }
    int a=0;
    for(int i=0;i+sum-1<t.size();i++){
      int x[1<<12];
      fill(begin(x),end(x),-1);
      x[0]=i;
      for(int j=0;j<1<<n;j++){
	if(x[j]>=0){
	  for(int k=0;k<n;k++){
	    if(!(j>>k&1)&&ma[k][x[j]]){
	      x[j|1<<k]=x[j]+e[k].size();
	    }
	  }
	}
      }
      a+=x[(1<<n)-1]>=0;
    }
    cout<<a<<endl;
  }
}

Measured memory_bytes: 1308
// 23 41
#include <stdio.h>
#include <stdlib.h>

int main()
{
	char str[5]; /* 念のため一個多めに */
	int A[100];
	int i, j, v, N, count, m;

	count = 0;

	scanf("%s",str);
	N = atoi( str );

	while( scanf("%s",str) != EOF ){
		A[count] = atoi(str);
		count++;
	}

	for( m = 0; m <= N - 2; m++ ){
		printf("%d",A[m]);
		printf(" ");
	}

	printf("%d\n",A[N-1]);

	for( i = 1; i <= N - 1; i++ ){
		v = A[i];
		j = i - 1;

		while(( j >= 0 ) && ( A[j] > v ) ){
			A[j+1] = A[j];
			j--;
		}

		A[j+1] = v;

		for( m = 0; m <= N - 2; m++ ){
			printf("%d",A[m]);
			printf(" ");
		}

		printf("%d\n",A[N-1]);
	}
	return 0;
}



Measured memory_bytes: 2120
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
const ll INF = LLONG_MAX;
const long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll P = 1e9 + 7;
	//const ll P = 998244353;

	ll n;
	cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];

	ll x = 0, y = 1000;
	for (ll i = 0; i < n - 1; i++) {
		if (a[i] < a[i + 1]) {
			x += y / a[i];
			y %= a[i];
		} else if (a[i] > a[i + 1]) {
			y += x * a[i];
			x = 0;
		}
	}
	cout << x * a[n - 1] + y << endl;
}

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main(){
	int a[210];
	int n,i,j,f=1;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	for(j=0;f!=0;j++){
		for(i=0;i<n;i++){
			if(a[i]%2!=0){
				f=0;
				break;
			}
			a[i]/=2;
		}
	}
	cout << j-1 << endl;
	return 0;
}


Measured memory_bytes: 256
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n = int(input())
  a = input_list()
  g = gcd_list(a)
  print(g)
  
import math
import fractions
import collections
from functools import reduce
main()

Measured memory_bytes: 16296
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

#define llong long long

using namespace std;
const int IINF = 2147483647;
const llong LLINF = 9223372036854775807;

map<long, long> FIP(long n) {
  map<long, long> ret;
  long n0 = n;
  for (long i = 2; i * i <= n0 / 2; i++) {
    while (n % i == 0) {
      n /= i;
      ret[i]++;
    }
  }
  if (n > 1) ret[n]++;
  return ret;
}

int main(){
  long n, p, ret=1;
  cin >> n >> p;
  map<long, long>m=FIP(p);
  for(pair<long, long>p: m){
    ret*=long(pow(p.first, p.second/n));
  }
  cout << ret;
  return 0;
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fi first
#define se second
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=2e5+5;
typedef pair<int,int> pi;
int fac[N],ifac[N],fa[N],mn[N],cnt[N];pi c[N];
int n,x,y,pos,sz,res;
inline int find(R int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main(){
	scanf("%d%d%d",&n,&x,&y);
	fp(i,1,n)scanf("%d%d",&c[i].se,&c[i].fi);
	sort(c+1,c+1+n);
	pos=2;
	while(pos<=n&&c[pos].se==c[1].se)++pos;
	if(pos>n)return puts("1"),0;
	fd(i,n,1)mn[c[i].se]=i,fa[i]=i;
	fd(i,n,1){
		if(i!=mn[c[i].se]&&c[i].fi+c[mn[c[i].se]].fi<=x)
			fa[find(i)]=find(mn[c[i].se]);
		else if(c[i].se!=c[1].se&&c[i].fi+c[1].fi<=y)
			fa[find(i)]=find(1);
		else if(c[i].se!=c[pos].se&&c[i].fi+c[pos].fi<=y)
			fa[find(i)]=find(pos);
	}
	fac[0]=ifac[0]=1;fp(i,1,n)fac[i]=mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=mul(ifac[i+1],i+1);
	fp(i,1,n)if(find(i)==find(1))++sz,++cnt[c[i].se];
	res=fac[sz];
	fp(i,1,n)res=mul(res,ifac[cnt[i]]);
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 5760
N,K = map(int,input().split())
A = list(map(int,input().split()))
S = [0]
beauties = []
ans = 0

for i in range(N):
    S.append(S[-1]+A[i])

for i in range(N):
    for j in range(i+1,N+1):
        beauties.append(S[j]-S[i])

for i in reversed(range(64)):
    tmp = []
    for j in range(len(beauties)):
        if (beauties[j]>>i)&1:
            tmp.append(beauties[j])
    if len(tmp)>=K:
        ans += 2**i
        beauties = tmp
        
print(ans)

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

using namespace std;

int main() {
	string S;

	cin>>S;

	int size=S.size(),count=0,ans=0,odd=0;

	for(int i=0;i<size;i++) {
		for(int j=0;j<size;j++) {
			if(S[i]==S[j]) {
				count++;
			}
		}
		if(count%2==0){
			ans+=count;
		} else {
			odd+=count;
		}
		count=0;
	}

	if(ans%2==0 && odd==0) {
		cout<<"Yes";
	} else {
		cout<<"No";
	}

	return 0;
}

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

struct node{int l,r,len;}a[300010];
int n,m,t[100010];

bool cmp(node x,node y){return x.len<y.len;}

void modify(int x,int k){for (; x<=m; t[x]+=k,x+=x&-x);}
int ask(int x){int s=0;  for (; x; s+=t[x],x-=x&-x);  return s;}

void work()
{
	scanf("%d %d",&n,&m);
	for (int i=1; i<=n; i++)
		scanf("%d %d",&a[i].l,&a[i].r),a[i].len=a[i].r-a[i].l+1;
	sort(a+1,a+n+1,cmp);
	for (int i=1,j=1,ans; i<=m; i++)
		{
			while ((j<=n)&&(a[j].len<i))  modify(a[j].l,1),modify(a[j].r+1,-1),j++;
			ans=n-j+1;
			for (int k=i; k<=m; k+=i)  ans+=ask(k);
			printf("%d\n",ans);
		}
}

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


Measured memory_bytes: 4864
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

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

    if (c - a - b < 0) {
        cout << "No" << endl;
        return 0;
    }

    if (4 * a * b < (c - a - b) * (c - a - b)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		Long n 	   = Long.parseLong(scanner.nextLine());
		Long count  = (long)Math.floor(n / 500.0);
		Long tcoun  = (long)Math.floor((n - 500 * count) / 5.0);

		System.out.println(count * 1000 + tcoun * 5);


	}
}

Measured memory_bytes: 35920
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

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

using namespace std;

int main() {
    int n;
    
    while(cin >> n, n) {
        vector<vector<int> > inp(n, vector<int>(n+1, 0));

        REP(i, n) REP(t, n+1) cin >> inp[i][t];

        /**
        bdp[ステージフラグ|装備フラグ...] = 最短時間
        */

        vector<int> bdp(1<<n, 1<<29);

        bdp[0] = 0;

        REP(i, (1<<n)) {
            // 挑むステージ
            REP(to, n) {
                // 未クリアなら
                if ( (to & (1 << to)) == 0 ) {
                    int mint = inp[to][0];
                    // 使う装備
                    for ( int eq = 1; eq < n + 1; eq++ ) {
                        // このステージに使える装備があるとき
                        if ( (i & (1 << (eq-1))) > 0 ) mint = min(mint, inp[to][eq]);
                    }
                    bdp[i|(1<<to)] = min(bdp[i] + mint, bdp[i|(1<<to)]);
                    // cout << (1<<to) << " " << bdp[1<<to] << endl;
                }
            }
        }

        // 全フラグが立っている時
        cout << bdp[(1<<n)-1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1476
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  while(1){
    string s;
    cin>>s;
    if(s[0]=='#') break;
    vector<char> v={'a','b','c','d','e','f','g','q','r','s','t','v','w','x','z'};
    string ans="";
    rep(i,s.size()){
      bool flag=false;
      rep(j,v.size()){
        if(s[i]==v[j]) flag=true;
      }
      if(flag) ans+='1';
      else ans+='0';
    }
    vector<pair<char,ll>> p;
    runlength(ans,p);
    cout<<p.size()-1<<endl;
  }
}


Measured memory_bytes: 3148
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define N 100

int m[N][N];
int MCOrder(int *p, int num);

int main(){
  int num, i, p[N+1];
  scanf("%d", &num);

  for(i = 0; i < num; i++){
    scanf("%d%d", &p[i], &p[i+1]);
  }
  printf("%d\n", MCOrder(p, num));
  return 0;
}

int MCOrder(int *p, int num){
  int i, j, k, l, r;

  for(i = 1; i <= num; i++){
    m[i][i] = 0;
  }

  for(l = 2; l <= num; l++){
    for(i = 1; i <= num-l+1; i++){
      j = i+l-1;
      m[i][j] = INT_MAX;

      for(k = i;k <= j - 1;k++){
        r = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
        m[i][j] = ((m[i][j] <= r) ? m[i][j] : r);
      }
    }
  }
  return m[1][num];
}

Measured memory_bytes: 632
r, g, b, n = map(int, input().split())
ans = 0

l = [r, g, b]
l.sort(reverse=True)
a = n // l[0]
for i in range(a+1):
    for j in range(n+1):
        if l[0]*i + l[1]*j > n:
            break
        elif (n-(l[0]*i + l[1]*j)) % l[2] == 0:
            ans += 1
print(ans)

Measured memory_bytes: 41692
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        String[] arr = new String[2];
        for(int i = 0;i < arr.length;i++) {
            arr[i] = scanner.nextLine();
        }

        String[] line1 = arr[0].split(" ");

        int n = Integer.parseInt(line1[0]);
        int m = Integer.parseInt(line1[1]);

        String[] line2 = arr[1].split(" ");

        int[] a = new int[line2.length];
        for (int i = 0; i < line2.length; i++) {
            a[i] = Integer.parseInt(line2[i]);
        }

        int sum = Arrays.stream(a).sum();

        if(sum > n){
            System.out.println(-1);
        }else{
            System.out.println(n - sum);
        }

        scanner.close();
    }
}


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

// Shortcut

#define int long long
#define ld long double
#define endl '\n'
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) for (int i = 0; i < a.size(); i++) cout << a[i] << ' ';
#define PrintVl(a) for (int i = 0; i < a.size(); i++) cout << a[i] << endl;
#define PrintA(a, n) for (int i = 0; i < n; i++) cout << a[i] << ' ';
#define PrintAl(a, n) for (int i = 0; i < n; i++) cout << a[i] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
	cout << *it << " = " << a << endl;
	DEB(++it, args...);
}

// Functions

#define bend(a) a.begin(),a.end()
#define mset(a) memset(a, 0, sizeof(a));
#define sortV(a) sort(bend(a));
#define sortA(a, n) sort(a, a + n);
#define rev(s) reverse(bend(a));

// Data Structure

#define pque priority_queue
#define mts multiset
typedef vector <int> vi;
typedef pair <int, int> ii;
typedef vector <vi > vvi;
typedef vector <ii > vii;

const int N = 1e5 + 5, mod = 1e9 + 7, inf = 1e18 + 7;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    int a[m];
    For(i, 0, m) cin >> a[i];
    sort(a, a + m);
    int b[m];
    For(i, 0, m - 1) b[i] = a[i + 1] - a[i];
    sort(b, b + m - 1);
    int ans = 0;
    For(i, 0, max(m - n, 0ll)) ans += b[i];
    cout << ans;
}

/*
----------------------------------+
INPUT:                            |
==============================    |

==============================    |
----------------------------------+
OUTPUT:                           |
==============================    |

==============================    |
----------------------------------+
*/

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

ll n;
ll x[505];
ll res[505*505];
ll cnt[505];

int main(){
	cin>>n;
  rep(i,n){
    cin>>x[i];
    x[i]--;
  }

  rep(i,n*n){
    bool done=false;
    rep(j,n){
      if(x[j]==i){
        if(cnt[j]<j){
          cout<<"No"<<endl;
          return 0;
        }
        cnt[j]++;
        res[i]=j;
        done=true;
        break;
      }
    }
    if(done)continue;
    ll midx=-1;
    rep(j,n){
      if(x[j]>i&&cnt[j]<j){
        if(midx==-1||x[midx]>x[j]){
          midx=j;
        }
      }
    }
    if(midx==-1){
      rep(j,n){
        if(x[j]<i&&cnt[j]<n){
          res[i]=j;
          cnt[j]++;
          done=true;
          break;
        }
      }
      if(!done){
        cout<<"No"<<endl;
        return 0;
      }
    }else{
      res[i]=midx;
      cnt[midx]++;
    }
  }

  cout<<"Yes"<<endl;
  rep(i,n*n)cout<<res[i]+1<<" ";
  cout<<endl;
	return 0;
}


Measured memory_bytes: 3072
#include <cstdio>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int Ans[100016];
int Now[100016];

int main() {
    int N;
    scanf("%d", &N);
    vector<pair<int, int> > A, B;
    for(int n=0; n<N; ++n) {
        int a;
        scanf("%d", &a);
        A.emplace_back(a, n);
    }
    for(int n=0; n<N; ++n) {
        int b;
        scanf("%d", &b);
        B.emplace_back(b, n);
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    for(int n=0; n<N; ++n) {
        if(B[n].first<A[n].first) {
            printf("No\n");
            return 0;
        }
    }
    for(int n=1; n<N; ++n) {
        if(A[n].first<=B[n-1].first) {
            printf("Yes\n");
            return 0;
        }
    }
    for(int n=0; n<N; ++n) {
        Now[n] = n;
        Ans[B[n].second] = A[n].second;
    }
    for(int n=0; n<N-1; ++n) {
        if(Now[n]==Ans[n]) {
            printf("Yes\n");
            return 0;
        }
        int ans = Ans[n];
        for(int i=N-1; n<i; --i) {
            if(ans==Now[i]) {
                Now[i] = Now[n];
                break;
            }
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const string& e_) { return "\"" + e_ + "\""; }
string to_string (char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string (bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string (T e_) {
	string s_ = "[ ";
	for (const auto& x_ : e_) s_ += to_string(x_) + " ";
	return s_ + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e_) {
	return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	ll n, a, b;
	cin >> n;

	for(int i = 1; i <= sqrt(n); i++){
		if(n%i == 0){
			a = i;
			b = n/i;
		}
	}
	cout << (a + b - 2) ;
}

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

int harshad(int n){
    int sum;
    sum = 0;
    while(n > 0){
        sum += n%10;
        n /= 10;
    }

    return sum;
}

int main(){
    int n, s;
    cin >> n;
    s = harshad(n);
    if(n%s == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String str = sc.next();
		int array[] = new int[N];
		Arrays.fill(array, 0);
		for(int i = 0; i < N; i++) {
			if(i == 0) {
				for(int j = 1; j < N; j++) {
					if(str.substring(j, j + 1).equals("E")) {
						array[0]++;
					}
				}
			} else {
				if(str.substring(i - 1, i).equals("W")) {
					array[i] = array[i - 1] + 1;
				} else {
					array[i] = array[i - 1];
				}
				if(str.substring(i, i + 1).equals("E")) {
					array[i]--;
				}
			}
		}
		Arrays.sort(array);
		System.out.println(array[0]);
	}
}


Measured memory_bytes: 48740
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    private static FastScanner fs = new FastScanner();
    public static void main(String[] args) {

        char s[] = fs.next().toCharArray();
        int n = s.length;
        if(s[n-1]=='s') {

            String str = new String(s);
            str+="es";
            System.out.println(str);

        }
        else {
         String str = new String(s);
         str +='s';
            System.out.println(str);
        }
    }


    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
        int  gcd(int a,int b)
        {
            while (b > 0)
            {
                int  temp = b;
                b = a % b;
                a = temp;
            }
            return a;
        }
        private int upper(int arr[],int key){
            int low = 0;
            int high = arr.length-1;
            while(low < high){
                int mid = low + (high - low+1)/2;
                if(arr[mid] <= key){
                    low = mid;
                }
                else{
                    high = mid-1;
                }
            }
            return low;
        }
        public int lower(int arr[],int key){
            int low = 0;
            int high = arr.length-1;
            while(low < high){
                int mid = low + (high - low)/2;
                if(arr[mid] >= key){
                    high = mid;
                }
                else{
                    low = mid+1;
                }
            }
            return low;
        }
    }
}

Measured memory_bytes: 36600
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from copy import copy 
def main():
    S = readline().decode().rstrip()    
    P = int(1e9)+7
    dp = [0 for _ in range(13)]
    dp[0] = 1
    mul = 1
    for s in reversed(S):
        nxDP = [0 for _ in range(13)]
        if s == '?':
            for i in range(10):
                for j in range(13):
                    nxr = (i*mul+j)%13
                    nxDP[nxr] += dp[j]
                    nxDP[nxr] %= P
        else:
            for j in range(13):
                nxr = ((ord(s)-ord('0'))*mul+j)%13
                nxDP[nxr] += dp[j]
                nxDP[nxr] %= P
        dp = copy(nxDP)
        mul *= 10
        mul %= 13

    print(dp[5])
if __name__ == '__main__':
    main()

Measured memory_bytes: 44396
#include <iostream>
#include <cstring>
#include <cstdio>

template <class T>
inline void read(T &x)
{
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

std::string str;
int l;
char s[20];

int main()
{
    std::cin >> str;
    for (int i = 0; str[i]; ++i)
    {
        if (str[i] == 'B') l -= l ? 1 : 0;
        else    s[++l] = str[i];
    }
    for (int i = 1; i <= l; ++i) std::cout << s[i];
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    int n = s.length();
    if(t.substring(0, n).equals(s)){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}





Measured memory_bytes: 35780
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  ll A[N]; rep(i,N) cin >> A[i];
  rep(i,N-1) A[i+1] += A[i];

  int l[N] = {};
  for(int i=1; i<N; i++) {
    l[i] = l[i-1];
    while(l[i]<i) {
      if (min(A[l[i]], A[i]-A[l[i]]) < min(A[l[i]+1], A[i]-A[l[i]+1])) l[i]++;
      else break;
    }
  }

  int r[N] = {}; fill_n(r,N,N-1);
  for(int i=N-2; i>=0; i--) {
    r[i] = r[i+1];
    while(r[i]>i) {
      if (min(A[N-1]-A[r[i]], A[r[i]]-A[i]) < min(A[N-1]-A[r[i]-1], A[r[i]-1]-A[i])) r[i]--;
      else break;
    }
  }

  ll result = LLINF;
  rep(i,N-1) {
    ll dmin = min(min(A[l[i]], A[i]-A[l[i]]), min(A[N-1]-A[r[i]], A[r[i]]-A[i]));
    ll dmax = max(max(A[l[i]], A[i]-A[l[i]]), max(A[N-1]-A[r[i]], A[r[i]]-A[i]));
    result = min(result, dmax-dmin);
    // cout << A[i] << " " << l[i] << " " << r[i] << endl;
  }


  cout << result << endl;
  return 0;
}

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

bool is_prime(const unsigned n)
{
  switch (n)
  {
  case 0: // fall-through
  case 1:
    return false;
  case 2: // fall-through
  case 3:
    return true;
  } // n > 3 が保証された

  if (n % 2 == 0)
    return false;
  if (n % 3 == 0)
    return false;
  // 2と3の倍数でないので6の倍数ではないことが保証された

  if (n % 6 != 1 && n % 6 != 5)
    return false;
  // 6の倍数前後の数(素数かもしれない数)であることが保証された

  // 6の倍数前後の数を使って試し割りをする
  for (unsigned i = 5; i * i <= n; i += 6)
  {
    if (n % i == 0)
      return false; // 6n-1
    if (n % (i + 2) == 0)
      return false; // 6n+1
  }

  return true;
}

int main()
{
  long long int X;
  cin >> X;
  long long int ans = 0;
  bool ok = false;
  while (!ok)
  {
    if (is_prime(X))
    {
      ans = X;
      ok = true;
      break;
    }
    else
      X++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
from operator import itemgetter
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,c = map(int,readline().split())
ch = [[[0,0]] for _ in range(c)]
for i in range(n):
    s,t,c = map(int,readline().split())
    ch[c-1].append([s,t])
imos = [0]*(10**5+1)
for i in ch:
    i.sort()
    for j in range(1,len(i)):
        s,t = i[j]
        if i[j-1][1] < s:
            imos[s-1] += 1
        else:
            imos[s] += 1
        imos[t] -= 1

for i in range(1,len(imos)):
    imos[i] += imos[i-1]

print(max(imos))



Measured memory_bytes: 53084
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
  
  int N;
  cin >> N;
  
  vector<int> V(N, 0);
  for(int i = 0; i < V.size(); i++){
    cin >> V[i];
  }
  
  double inv = 0;
  
  for(int i = 0; i < V.size(); i++){
    inv += 1 / (double)V[i];      
  }
  
  cout << 1 / inv;
  
}

Measured memory_bytes: 256
from sys import stdin,setrecursionlimit
setrecursionlimit(10**7)
n,m = map(int,stdin.readline().rstrip().split())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
mi = 0
ma = n
for i,j in li:
    mi = max(mi,i)
    ma = min(ma,j)
if mi > ma:
    print(0)
else:
    print(ma-mi+1)

Measured memory_bytes: 27336