akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int N; cin >> N;
    vector <int> X(N);
    rep(i,N) cin >> X[i];
    
    vector <int> Y=X;
    sort(Y.begin(),Y.end());
    rep(i,N){
        if (Y[N/2]>X[i]){
            cout << Y[N/2] << endl;
        }
        else{
            cout << Y[N/2-1] << endl;
        }
    }
    return 0;
}

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

#define rep(i,n) for(signed i=0;i<n;++i)
#define int long long
#define str string
#define debg(a) cout<<#a<<":"<<a<<endl;
#define print(a) cout<<a<<endl;
#define end cout<<endl;
#define elif else if


int a,b,c,i,j,k,n,m,x,y,z;
str s,t;
vector<signed> v;

signed main(){
  
  cin>>a>>b;
  int ans=(a*b)/2;
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 764
// F.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	int m, k;
	cin >> m >> k;
	int b = 1 << m;
	vector<int> ans;
	if (k == 0) {
		for (int i = 0; i < b; ++i) {
			ans.push_back(i);
			ans.push_back(i);
		}
	} else if (m > 1 && k < b) {
		ans.clear();
		ans.push_back(0);
		ans.push_back(k);
		ans.push_back(0);
		for (int i = 1; i < b; ++i) {
			if (i != k) {
				ans.push_back(i);
			}
		}
		ans.push_back(k);
		for (int i = b - 1; i >= 1; --i) {
			if (i != k) {
				ans.push_back(i);
			}
		}
	} else {
		ans = { -1 };
	}
	for (int a : ans) {
		cout << " " << a;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 2932
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll n;
double a[114];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	double ans = 0;
	rep(i, n)ans += (double)1 / a[i];
	cout << setprecision(15) << (double)1 / ans << endl;
	ggr
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    vector<pair<bool, ll>> balls;
    ll N, M;
    ll count = 0;
    cin >> N >> M;
    balls.resize(N, {false, 1});
    balls[0] = {true, 1};
    rep(i, M) {
        ll x, y;
        cin >> x >> y;
        x--; y--;
        balls[x].second--;
        balls[y].second++;
        if(balls[x].first) balls[y].first = true;
        if(balls[x].second <= 0) balls[x].first = false;
    }
    iter(b, balls) if(b.first) count++;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 1792
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ct=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if (500*i)+(100*j)+(50*k)==x:
                ct+=1
print(ct)

Measured memory_bytes: 39536
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
#define LL long long 
int main(){
     int a,b,c;
     LL k;
     cin >> a >> b >> c >> k;
     if (k & 1){
          cout << b - a << endl;
     }else {
         cout << a - b << endl;
     }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
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;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, x, y; cin >> n >> x >> y;
    x--; y--;
    vector<vector<int>> dist(n, vector<int>(n, 0));
    rep(i, n) rep(j, n) {
        if (i==j) dist[i][j] = 0;
        dist[i][j] = min({
            abs(j-i),
            abs(j-y) + abs(x-i) + 1,
            abs(j-x) + abs(y-i) + 1
        });
    }
    // rep1(i, n-1) {
    //     int ans = 0;
    //     rep(j, n) for(int k=j+1; k<n; ++k) {
    //         if (dist[j][k] == i) {
    //             ans++;
    //             // cout << j << " " << k << endl;
    //         }
    //     }
    //     cout << ans << endl;
    // }
    vector<int> ans(n);
    rep(i, n) for (int j=i+1; j<n; ++j) {
        ans[dist[i][j]]++;
    }
    rep1(i, n-1) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[110][110];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
ll mazei[110][110];
int main() {
	cin >> s;
	if (s == "keyence") {
		cout << "YES" << endl;
		return 0;
	}
	rep(i, s.size()-1) {
		for (ll j = i ; j < s.size(); j++) {
			string str = "";
			str += s.substr(0, i - 1);
			str += s.substr(j, s.size() - 1);
			if (str == "keyence") {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
typedef long long ll;
int p;
int mul(int a,int b){return(ll)a*b%p;}
int pow(int a,int b){
	int s=1;
	while(b){
		if(b&1)s=mul(s,a);
		a=mul(a,a);
		b>>=1;
	}
	return s;
}
int fac[3010],rfac[3010],st[3010][3010],pw[9000010],p2[3010];
void pre(int n){
	int i,j;
	fac[0]=1;
	for(i=1;i<=n;i++)fac[i]=mul(fac[i-1],i);
	rfac[n]=pow(fac[n],p-2);
	for(i=n;i>0;i--)rfac[i-1]=mul(rfac[i],i);
	p2[0]=1;
	for(i=1;i<=n;i++)p2[i]=p2[i-1]*2%(p-1);
	pw[0]=1;
	for(i=1;i<=n*n;i++)pw[i]=mul(pw[i-1],2);
	n++;
	st[0][0]=1;
	for(i=1;i<=n;i++){
		for(j=1;j<=i;j++)st[i][j]=(mul(st[i-1][j],j)+st[i-1][j-1])%p;
	}
}
int C(int n,int k){return mul(fac[n],mul(rfac[k],rfac[n-k]));}
int main(){
	int n,i,j,s,t;
	scanf("%d%d",&n,&p);
	pre(n);
	s=0;
	for(i=0;i<=n;i++){
		t=0;
		for(j=0;j<=i;j++)(t+=mul(st[i+1][j+1],pw[(n-i)*j]))%=p;
		(s+=(i&1?-1:1)*mul(C(n,i),mul(t,pow(2,p2[n-i]))))%=p;
	}
	printf("%d",(s+p)%p);
}

Measured memory_bytes: 70656
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int[] a = new int[3];
        for (int i = 0; i < s.length; i++) {
            int x = s[i] - 'a';
            a[x]++;
        }
        int max = Math.max(a[0], Math.max(a[1], a[2]));
        int min = Math.min(a[0], Math.min(a[1], a[2]));
        System.out.println(max-min < 2 ? "YES" : "NO");
        sc.close();

    }

}


Measured memory_bytes: 26208
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

int is_col_ok(int stage[3][3],int type){
	for(int y=0;y<3;y++){
		if(stage[y][0] == stage[y][1] &&
			stage[y][1] == stage[y][2] &&
			stage[y][2] == type){
				return true;
		}
	}

	return false;
}

bool is_row_ok(int stage[3][3],int type){
	for(int x=0;x<3;x++){
		if(stage[0][x] == stage[1][x] &&
			stage[1][x] == stage[2][x] &&
			stage[2][x] == type){
				return true;
		}
	}

	return false;
}

bool is_diag_ok(int stage[3][3],int type){
	if(stage[0][0] == stage[1][1] &&
		stage[1][1] == stage[2][2] &&
		stage[2][2] == type){
			return true;
	}

	else if(stage[0][2] == stage[1][1] &&
		stage[1][1] == stage[2][0] &&
		stage[2][0] == type){
			return true;
	}

	return false;
}


int main(){
	string str;
	int stage[3][3];

	while(getline(cin,str)){
		for(int i=0;i<str.size();i++){
			int y = i / 3;
			int x = i % 3;

			if(str[i]=='s'){
				stage[y][x] = 0;
			}
			else if(str[i]=='o'){
				stage[y][x] = 1;
			}
			else if(str[i]=='x'){
				stage[y][x] = -1;
			}	
		}

		if(is_col_ok(stage,1) || is_row_ok(stage,1) || is_diag_ok(stage,1)){
			cout << "o" << endl;
		}

		else if(is_col_ok(stage,-1) || is_row_ok(stage,-1) || is_diag_ok(stage,-1)){
			cout << "x" << endl;
		}
		else{
			cout << "d" << endl;
		}
	}
}

Measured memory_bytes: 0
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();
    int B = sc.nextInt();

    sc.close();

    int count = 1;
    int all = A;

    while (all < B) {
      all = all - 1 + A;
      count++;
    }

    if (B == 1){
      count = 0;
    }
    
    System.out.println(count);

  }

}

Measured memory_bytes: 21972
# include <iostream>

int main(){
  int input = 0;
  for(int i = 0; i < 10000; i++){
    std::cin >> input;
    if(input == 0) 
      break;
    std::cout << "Case " << i+1 << ": " << input << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3000
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

int digit(ll n) {
  return to_string(n).size();
}

void solve(ll N) {
  int res = 1e9;
  for (ll i = 1; i * i <= N; ++i) {
    if (N % i) continue;
    ll j = N / i;
    chmin(res, max(digit(i), digit(j)));
  }
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	solve(N);
	return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn._

object Main extends App {


  val n = readInt()
  val S = Array.fill(n)(readLine())

  def solve() = {
    val strAndCntSeq = S.groupBy(identity).mapValues(_.length).toSeq
    val maxCnt = strAndCntSeq.map(_._2).max
    strAndCntSeq.foldLeft(Seq.empty[String]) { case (acc, (str, cnt)) =>
      if(cnt == maxCnt) str +: acc else acc
    }.sorted.mkString("\n")
  }

  println(solve())

}



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

int main(){
    string s,t;
    cin>>s>>t;
    cout<<(s+t[t.size()-1]==t?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 3628
from itertools import accumulate
N, Q =map(int, input().split())
s = input()

lr = [[int(i) for i in input().split()] for i in range(Q)] 

AC = [0]*(N-1)

for i in range(N-1):
  if s[i:i+2] == 'AC':
    AC[i] = 1
  

B = [0] +AC
B = list(accumulate(B))
for i in lr:
  print(B[i[1]-1]-B[i[0]-1])
  

Measured memory_bytes: 26920
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

//累乗(nのk乗）
long long ruijou(ll n, ll k){
    if(k==0) return 1;
    int x=k/2;
    long long t=ruijou(n,x);
    
    if(k%2==1) return n*t*t;
    else return t*t;
}

int main(){
  ll N; cin>>N;
  ll K=N*25;
  K/=27;
  ll T=K*1.08;
  ll J=(K+1)*1.08;
  if(T==N) cout<<K<<endl;
  else if(J==N) cout<<K+1<<endl;
  else cout<<":("<<endl;
  

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define ALLOC(size,type) ((type *) calloc ((size), sizeof (type)))

typedef struct union_find_depth {
  i32 *parent;
  i32 *depth;
  i32 size;
} union_find;

union_find* new_union_find (const i32 n) {
  union_find *u = ALLOC (1, union_find);
  u->parent = ALLOC (n, i32);
  u->depth = ALLOC (n, i32);
  u->size = n;
  for (i32 i = 0; i < n; ++i) {
    u->parent[i] = -1;
  }
  return u;
}

i32 root (union_find *u, i32 x) {
  while (u->parent[x] >= 0) {
    x = u->parent[x];
  }
  return x;
}

i32 depth (union_find *u, i32 x) {
  i32 sum = 0;
  while (u->parent[x] >= 0) {
    sum += u->depth[x];
    x = u->parent[x];
  }
  return sum;
}

int unite (union_find *u, i32 x, i32 y, i32 w) {
  w += depth (u, x);
  w -= depth (u, y);
  x = root (u, x);
  y = root (u, y);
  if (x == y) {
    return w == 0;
  }
  if (u->parent[x] > u->parent[y]) {
    i32 swap = x;
    x = y;
    y = swap;
    w = -w;
  }
  u->depth[y] = w;
  u->parent[x] += u->parent[y];
  u->parent[y] = x;
  return 1;
}

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  union_find *u = new_union_find (n + 1);
  while (m--) {
    i32 l, r, d;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &l, &r, &d);
    if (!unite (u, l, r, d)) {
      puts ("No");
      return;
    }
  }
  puts ("Yes");
}

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


Measured memory_bytes: 896
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string S;
  cin >> S;
  // R,G,B
  const string str = "RGB";
  array<vector<int>, 3> RGB;
  fill(begin(RGB), end(RGB), vector<int>(N + 1, 0));
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < N; ++j)if (S[j] == str[i])++RGB[i][j + 1];
    partial_sum(next(begin(RGB[i])), end(RGB[i]), next(begin(RGB[i])));
  }
  int64_t ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      if (S[i] == S[j])continue;
      for (int k = 0; k < 3; ++k) {
        if (str[k] == S[i] || str[k] == S[j])continue;
        ans += RGB[k][N] - RGB[k][j];
        if (j + (j - i) < N && str[k] == S[j + (j - i)])--ans;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3712
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        // String arr = new String[N];
        List<String> arr = new ArrayList<String>();
        for(int i = 0; i < N;i++){
            arr.add(String.valueOf(S.charAt(i)));
        }
        for(int j = 0; j < N-1; j++){
            if(arr.get(j).equals(arr.get(j+1))){
                arr.set(j, "0");
            }
        }
        // List<String> remove = new ArrayList<>();
        // arr.removeAll("0");
        arr.removeAll(Arrays.asList("0"));


        System.out.println(arr.size());
    }
}

Measured memory_bytes: 31088
#include<cstdio>
#include <algorithm>

using namespace std;
 
int main(void)
{
int arr[3];
scanf("%d %d %d",&arr[0],&arr[1],&arr[2]);
sort(arr,arr+3);
printf("%d %d %d\n",arr[0],arr[1],arr[2]);
return 0; 
}

Measured memory_bytes: 1040
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
	static void Main(string[] args)
	{
        int n = int.Parse(Console.ReadLine());
        int h = int.Parse(Console.ReadLine());
        int w = int.Parse(Console.ReadLine());

        //出力
        Console.WriteLine($"{CountNotice(n, h, w)}");
	}

    static int CountNotice(int n, int h, int w)
    {
        if (n < h || n < w || w <= 0 || h <= 0)
            return 0;

        int rtv = 0;
        for(int i=0; i<n-h+1; i++)
            for(int j=0; j<n-w+1; j++)
                rtv++;
        return rtv;
    }
}

Measured memory_bytes: 11220
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        HashMap<Integer,Integer>dic=new HashMap<Integer,Integer>();
        int N=sc.nextInt();
        int a[]=new int [N];
        for(int i=0;i<N;i++){
            a[i]=sc.nextInt();
            dic.put(a[i],0);
        }
        for(int i=0;i<N;i++){
            dic.put(a[i],dic.get(a[i])+1);
        }
        int ans=0;
        for(Integer key:dic.keySet()){
            if(dic.get(key)%2!=0){
                ans++;
            }
        }
        System.out.println(ans);
    }
}

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

int main(){
  int H, W;
  cin >> H >> W;
  vector<char> a(H * W);
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> a.at( i * W + j);
    }
  }
  vector<char> line(W + 2, '#');
  for (int i = 0; i < W + 2; i++)
    cout << line.at(i);
  cout << endl;

  for (int i = 0; i < H; i ++){
    cout << '#';
    for (int j = 0; j < W; j++)
      cout << a.at(i * W + j);
    cout << '#' << endl;
  }
  for (int i = 0; i < W + 2; i++)
    cout << line.at(i);
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
#define show(x) cout << #x << " is " << x << "\n";
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
    string s;
    cin>>s;
    if(s == "ARC") cout<<"ABC";
    else cout<<"ARC";

	return 0;
}


Measured memory_bytes: 3612
#include <iostream>

int main(){
  int n;
  std::cin >> n;
  char buf[100000];
  int sum;
  std::cin >> buf;
  char tmp=' ';
  for(int i = 0 ; i< n;i++){
   	if(tmp!=buf[i]){
      tmp = buf[i];
      sum++;
    }
  }
  std::cout << sum << std::endl;
  return 0 ; 
}

Measured memory_bytes: 384
#include<iostream>
#include<set>

using namespace std;

set<int> s;

int is_poss_to_win(int dp[],int point)
{
  if(point <= 0)
    return 0;

  if(dp[point] != -1)
    return dp[point];

  int temp = 0;
  for(auto it = s.begin(); it!=s.end(); it++)
  {
    if(point - (*it) >= 0)
    {
      if(is_poss_to_win(dp,point - (*it)) == 0)
      {
        temp = 1;
        break;
      }
    }
  }

  return dp[point] = temp;


}

int main()
{
  int n , k;
  cin>>n>>k;
  int dp[k+1];
  int temp;

  for(int i = 0 ; i<n ; i++)
  {
    cin>>temp;
    s.insert(temp);
  }

  for(int i = 0 ; i<=k; i++ )
      dp[i] =-1;

  if(is_poss_to_win(dp,k))
  {
    cout<<"First";
  }
  else
    cout<<"Second";
  
  return 0;
}

Measured memory_bytes: 5376
N, K = map(int, input().split())
v = list(map(int, input().split()))

ans = 0

R = min(N, K)
for A in range(R+1):
  for B in range(R-A+1):
    C = K-(A+B)
    have = []
    have.extend(v[:A])
    have.extend(v[N-B:])
    have.sort()
    for c in range(C):
      if len(have) > 0:
        if have[0] < 0:
          have.pop(0)
        else:
          break
    ans = max(ans, sum(have))

print(ans)
      

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  int minx = 0, maxx = W, miny = 0, maxy = H;

  for (int i = 0; i < N; i++) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) { minx = x > minx ? x : minx; }
    else if (a == 2) { maxx = x < maxx ? x : maxx; }
    else if (a == 3) { miny = y > miny ? y : miny; }
    else if (a == 4) { maxy = y < maxy ? y : maxy; }
  }
  
  int yoko, tate;
  if (minx >= maxx) { yoko = 0; }
  else { yoko = maxx - minx; }
  if (miny >= maxy) { tate = 0; }
  else { tate = maxy - miny; }

  cout << yoko * tate << endl;
  return 0;
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		string s, t;
		cin >> t >> s;
		int sz = s.size();
		
		for(int j = t.size()-1;j >= 0;j--){
			string ns;
			if(t[j] == 'J'){
				ns += s[sz-1];
				ns += s.substr(0, sz-1);
			}
			if(t[j] == 'C'){
				ns += s.substr(1, sz-1);
				ns += s[0];
			}
			if(t[j] == 'E'){
				int hf = sz / 2;
				ns += s.substr((sz+1)/2, hf);
				if(sz % 2) ns += s[hf];
				ns += s.substr(0, hf);
			}
			if(t[j] == 'A'){
				reverse(s.begin(), s.end());
				ns = s;
			}			
			if(t[j] == 'P'){
				for(int k = 0;k < sz;k++){
					if(s[k] >= '0' && s[k] <= '9'){
						if(s[k] == '0'){
							s[k] = '9';
						}else{
							s[k]--;
						}
					}
				}
				ns = s;
			}
			if(t[j] == 'M'){
				for(int k = 0;k < sz;k++){
					if(s[k] >= '0' && s[k] <= '9'){
						if(s[k] == '9'){
							s[k] = '0';
						}else{
							s[k]++;
						}
					}
				}
				ns = s;
			}
			s = ns;
//			cout << t[j] << endl;
//			cout << s << endl;
		}
		cout << s << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int N, Y;

void solve(){
    cin >> N >> Y;
    for(int x = 0; x < Y / 1000; ++x){
        for(int y = 0; y < Y / 1000; ++y){
            int z = N - x - y;
            if(z >= 0 && 1ll * x * 10000ll + 1ll * y * 5000ll + 1ll * z * 1000ll == Y){
                cout << x << " " << y << " " << z << "\n";
                return;
            }
        }
    }
    cout << "-1 -1 -1\n";
}

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

    solve();
    
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 25 20:54:45 2020

@author: naoki
"""

N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(N-K):
    a = A[i]
    b = A[i+K]
    if a<b:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 94188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int a, b;
  cin >> a >> b;
  cout << max({a+b, a-b, a*b}) << endl;
}


Measured memory_bytes: 256
# B - Good Distance
import math

N, D = map(int, input().split())
p = [[0 for n in range(D)] for m in range(N)]
#print(p)

for i in range(N):
    input_line = input().split(' ')
    p_line = [int(s) for s in input_line]
    for j in range(D):
        p[i][j] = p_line[j]

#print(p)
cnt = 0
for i in range(N):
    for j in range(i,N):
        if i == j:
            continue

        distance = 0
        for k in range(D):
            distance += (p[i][k] - p[j][k])**2
        distance = math.sqrt(distance)
        #print(i,j,distance)
        if distance.is_integer():
            cnt += 1
print(cnt)


Measured memory_bytes: 3064
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
h = Hash.new(0)
anyc = 0
a.each do |aa|
  if aa < 3200
    c = aa / 400
    h[c] += 1
  else
    anyc += 1
  end
end


cmin = [h.keys.length, 1].max

cmax = h.keys.length + anyc

puts [cmin, cmax].join(" ")

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	
	int height=0;
	int d = b - a;
	for(int i=1;i<=d;i++){
		height += i;
	}

	int ans = height - b;

	cout<< ans <<endl;

	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int n, a[200005];


int main()
{
	int tmp, num = 0;
	long long sum = 0, sum1 = 0;
	cin >> n;
	while (n--)
	{
		cin >> tmp;
		a[num] = tmp - num;
		if (a[num] < 0)sum1++;
		num++;
	}
	sort(a, a + num);
	int kk = a[(num - 1) / 2];
	for (int i = 0;i < num;i++)
		sum += abs(a[i] - kk);
	cout <<sum;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>

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

using namespace std;
int main() {
	int n;
	cin >> n;
	cout << n * n << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
#include<numeric>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
  }

  sort(a.begin(), a.end());
  ll top = a[n-1];

  ll near = LLINF;
  ll t = LLINF;
  rep (i, n-1) {
    if (t > abs(a[i] - top/2)) {
      t = abs(a[i] - top/2);
      near = a[i];
    }
  }

  if (n&1) {
    ll near2 = LLINF;
    ll t2 = LLINF;
    rep (i, n-1) {
      if (t2 > abs(a[i] - (top/2 + 1))) {
        t2 = abs(a[i] - (top/2 + 1));
        near2 = a[i];
      }
    }
    if (t > t2) {
      cout << top << " " << near2 << endl;
    } else {
      cout << top << " " << near << endl;
    }
  } else {
    cout << top << " " << near << endl;
  }

  //  auto b = upper_bound(a.begin(), a.end()-1, top/2);
  //  auto c = b-1;
  //  
  //  ll tmpb = LLINF; ll tmpc = LLINF;
  //  if (b != a.end()-1) {
  //    tmpb = *b;
  //  }
  //  
  //  if (b != a.begin()) {
  //    tmpc = *c;
  //  }
  //  
  //  if (top % 2 == 0) {
  //    if (abs(top-tmpb) < abs(top-tmpc)) {
  //      cout << top << " " << tmpb << endl;
  //    } else {
  //      cout << top << " " << tmpc << endl;
  //    }
  //  } else {
  //    if (abs(top+1-tmpb) < abs(top-tmpc)) {
  //      cout << top << " " << tmpb << endl;
  //    } else {
  //      cout << top << " " << tmpc << endl;
  //    }
  //  }
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	ll n; cin>>n;
	vector<ll> l(n);
	rep(i,0,n) cin>>l[i];
	ll ans=0;
	rep(i,0,n){
		ll a=l[i];
		rep(j,i+1,n){
			ll b=l[j];
			rep(k,j+1,n){
				ll c=l[k];
				if(a!=b and b!= c and a!=c){
					if(a+b > c and b+c > a and c+a > b){
						ans++;
					}
				}

			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e6+5;//最大1e9 
const int mod=998244353; 
int prime[MAXN],mu[MAXN],pnum=0;
bool vis[MAXN];//是否是素数 
ll a[MAXN],cnt[MAXN],value[MAXN];
ll inv[MAXN];
ll f[MAXN];
ll qkpow(ll a,ll p,ll mod){
    ll t=1,tt=a%mod;
    while(p){
        if(p&1)t=t*tt%mod;
        tt=tt*tt%mod;
        p>>=1;
    }
    return (t+mod)%mod;
}
ll getInv(ll a){
    return qkpow(a,mod-2,mod);
}
void sieve(){//素数+莫比乌斯函数线性筛 
	memset(vis,true,sizeof(vis)); 
	vis[0]=vis[1]=false; 
	mu[1]=1;
	f[1]=1;
	for(int i=2;i<MAXN;i++)
		inv[i]=getInv(i);
	for(int i=2;i<MAXN;i++){
		if(vis[i]){//i is a prime
			prime[pnum++]=i;
			mu[i]=(-1+mod)%mod;//mu(p)=-1
			f[i]=((1-i)%mod*inv[i]%mod+mod)%mod;//f[p]=(1-p)*inv(p) 
		} 
		for(int j=0;j<pnum&&1LL*i*prime[j]<MAXN;j++){//遍历当前素数 
			int x=prime[j];
			vis[i*x]=false;
			if(i%x==0){//x是i的最小素因子 
				mu[i*x]=0;//mu(p^k)=0,k>1 
				f[i*x]=(f[i]*inv[x]%mod+mod)%mod;
				break;
			}
			else{//i,x互质 
				mu[i*x]=(-mu[i]+mod)%mod;//积性函数性质,mu(x)=-1 
				f[i*x]=((f[i]*i%mod)%mod*inv[i]%mod*inv[x]%mod-f[i]+mod)%mod;
			}
		}
	}
}
int n;
int main(){
	sieve();
	//for(int i=1;i<=100;i++)
	//	cout<<f[i]<<endl;
	memset(cnt,0,sizeof cnt);
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",a+i);
		cnt[a[i]]++;
	}
	for(int i=1;i<=MAXN;i++)
		for(int j=i;j<=MAXN;j+=i)
			value[i]=(value[i]+1ll*j*cnt[j]%mod+mod)%mod;
	
	//for(int i=0;i<100;i++)
	//	cout<<value[i]<<endl;
	ll ans=0;
	for(int i=1;i<=MAXN;i++)
		ans=(ans+1ll*value[i]*value[i]%mod*f[i]%mod+mod)%mod;
	//	cout<<ans<<endl;
	for(int i=0;i<n;i++)
		ans=(ans-a[i]+mod)%mod;//cout<<ans<<endl;
	printf("%lld",1ll*ans*inv[2]%mod);
}

Measured memory_bytes: 41216
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

#define MAX_N 12
#define EPS 1e-7

double boxlen;
int n;
double r[MAX_N];
double dp[MAX_N][1 << MAX_N];

double sq(double x){
	return x * x;
}

double dist(int i, int j){
	return sqrt(sq(r[i] + r[j]) - sq(r[i] - r[j]));
}

void solve(){
	double INF = 1e99;

	for(int S = 0; S < (1 << n); ++S){
		for(int i = 0; i < n; ++i){
			dp[i][S] = INF;
		}
	}

	for(int i = 0; i < n; ++i){
		dp[i][1 << i] = r[i];
	}

	for(int S = 0; S < (1 << n); ++S){
		for(int i = 0; i < n; ++i){
			if(((S >> i) & 1) != 0){
				for(int j = 0; j < n; ++j){
					if(((S >> j) & 1) == 0){
						int next = S | (1 << j);
						dp[j][next] = min(dp[j][next], dp[i][S] + dist(i, j));
					}
				}
			}
		}
	}

	double minlen = INF;
	for(int i = 0; i < n; ++i){
		minlen = min(minlen, dp[i][(1 << n) - 1] + r[i]);
	}

	if(minlen < boxlen + EPS){
		printf("OK\n");
	}
	else{
		printf("NA\n");
	}
}

int main(){
	while(scanf("%lf", &boxlen) != EOF){
		n = 0;
		char nextch = ' ';
		while(nextch == ' '){
			scanf("%lf%c", &r[n], &nextch);
			++n;
		}
		solve();
	}
}

Measured memory_bytes: 1416
#include <iostream>
#include <cstring>
using namespace std;
const int N=100000;
char str[N];
int main()
{
    int k;cin>>k;
    cin>>str;
    int len=strlen(str);
    if(len<=k)cout<<str<<endl;
    else {
        for(int i=0;i<k;i++)cout<<str[i];
        cout<<"..."<<endl;
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n,f[100004],m;
int F(int x){
	return f[x]==x?x:f[x]=F(f[x]); 
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)f[i]=i;
	for(int i=0;i<m;i++){
		int a,b;cin>>a>>b;
		a=F(a),b=F(b);
		if(a!=b)f[a]=b;
	}
	int ans=0;
	for(int i=1;i<=n;i++)if(F(i)==i)ans++;
	cout<<ans-1;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int>data(n);
  rep(i,0,m){
    int a,b;
    cin >> a >> b;
    --a;--b;
    data[a]++;
    data[b]++;
  }
  rep(i,0,n){
    if(data[i]%2 != 0){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 3772
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;

int main(){
    string A, B, C;
    cin >> A >> B >> C;

    int Alen = A.length();
    int Blen = B.length();
    int Clen = C.length();

    if(A[Alen-1] == B[0] && B[Blen-1] == C[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  long long n,a,b,c;
  cin>>n>>a>>b;
  
  c=n%(a+b);
  if(c<=a) cout<<a*(n/(a+b))+c<<endl;
  else cout<<a*(n/(a+b))+a<<endl;
  
}

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

int main(){
    string s;
    cin >> s;
    if(s.at(0)==s.at(1)&& s.at(1)==s.at(2) && s.at(2)==s.at(0)) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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,k;
    cin>>n>>k;
    vector<string> a(n);
    rep(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    rep(i,n){
        cout<<a[i];
    }
    cout<< endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N, M;
  while(cin >> N >> M && N){
    static bool dp[5022][1 << 12] = {};
    memset(dp, 0, sizeof(dp));
    string word[12];
    REP(i, N) cin >> word[i];
    string s;
    REP(i, M){
      string t; cin >> t;
      s += t;
    }
    int L = s.size();
    bool match[5000][12] = {};
    for(int i = 0; i < N; i++){
      for(int j = 0; j + word[i].size() <= L; j++){
        if(word[i] == s.substr(j, word[i].size())) match[j][i] = true;
      }
    }
    REP(i, L + 1) dp[i][0] = true;
    REP(i, L){
      REP(j, N) if(match[i][j]){
        REP(S, 1 << N) if(0 == (S >> j & 1) && dp[i][S]){
          dp[i + word[j].size()][S | (1 << j)] = true;
        }
      }
    }
    int ans = 0;
    REP(i, L + 1) if(dp[i][(1 << N) - 1]) ans ++;
    cout << ans << endl;
  }
  return 0;
}

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

long long po(int x,int y){
	long long ans=1;
	for(int i=0;i<y;i++)ans*=x;
	return ans;
}

int main(){
	int N,P;
	cin >> N >> P;
	bool odd=false;
	long long ans;
	for(int i=0;i<N;i++){
		int A;
		cin >> A;
		if(A%2==1)odd=true;
	}
	if(odd){
		ans=po(2,N-1);
	}
	else{
		if(P==1)ans=0;
		else ans=po(2,N);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    char c;
    cin >> c;
    c++;
    cout << c;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>

/*
for(int i=0;i<n;i++)
printf("%d\n",n)
scanf("%d",&n)
*/

using namespace std;
int n;

int main(){
    scanf("%d",&n);
    cout<<(n==7 or n==5 or n==3 ? "YES":"NO")<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=1e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false); 

    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) {
        cin >> a[i];
        a[i]-=i+1;
    }
    sort(a.begin(),a.end());
    ll mid=a[n/2];
    ll ans=0;
    rep(i,n) ans+=abs(a[i]-mid);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4684
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
W = [sys.stdin.readline().rstrip() for _ in range(N)]
i = 0
ok = True
while i < N - 1:
    j = i + 1
    ok &= W[i][-1] == W[j][0]
    i+=1
if ok and len(set(W)) == N:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 20860
import java.util.*;

public class Main {
	public static void main(String[] args) {
		new Main().execute();
	}

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		Point[] red = new Point[N];
		Point[] blue = new Point[N];

		for (int i = 0; i < N; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			red[i] = new Point(x, y);
		}

		for (int i = 0; i < N; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			blue[i] = new Point(x, y);
		}

		Comparator<Point> cmp = new Comparator<Main.Point>() {
			@Override
			public int compare(Point o1, Point o2) {
				// TODO Auto-generated method stub
				if (o1.x == o2.x) {
					return o1.y - o2.y;
				} else {
					return o1.x - o2.x;
				}
			}
		};

		Arrays.sort(red, cmp);
		Arrays.sort(blue, cmp);
		boolean[] matched = new boolean[N];
		int pairs = 0;

		for (int i = 0; i < N; i++) {
			int bx = blue[i].x;
			int j = 0;
			int my = -1;
			int k = -1;
			while (j < red.length && red[j].x < bx) {
				if (!matched[j] && matchable(red[j], blue[i]) && my < red[j].y) {
					my = red[j].y;
					k = j;
				}
				j++;
			}
			if (k >= 0) {
				pairs += 1;
				matched[k] = true;
			}
		}
		System.out.println(pairs);

		sc.close();

	}

	private boolean matchable(Point r, Point b) {
		return (r.x < b.x) && (r.y < b.y);
	}

	class Point {
		public final int x;
		public final int y;

		public Point(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}

}

Measured memory_bytes: 21972
N = int(input())
H = [[0,0,0] for i in range(N)]
H[0] = list(map(int, input().split()))
for i in range(1, N):
    abc = list(map(int, input().split()))
    for j in range(3):
        H[i][j] = max(H[i-1][j-1],H[i-1][(j+1)%3])+abc[j]

print(max(H[-1]))

Measured memory_bytes: 28756
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
const ll nax=2e5+7;

ll n,smt[nax<<4],dp[nax],a[nax],h[nax];

void build(ll node = 1,ll start = 1, ll end = n){
	if (start==end)	smt[node]=dp[start];
	
	else {
		ll mid=(start+end)>>1;
		
		build(node<<1,start,mid);
		build(node<<1|1,mid+1,end);
		
		smt[node]=max(smt[node<<1],smt[node<<1|1]);
	}
}

void update(ll index,ll val,ll node = 1,ll start = 1, ll end = n){
	if (start==end) {
		smt[node] = val;
		dp[index] = val;
	}
	
	else{
		ll mid=(start+end)>>1;
		
		if (index<=mid) update(index,val,node<<1,start,mid);
		
		else  update(index,val,node<<1|1,mid+1,end);
		
		smt[node]=max(smt[node<<1],smt[node<<1|1]);
	}
}

ll query(ll l,ll r,ll node = 1,ll start = 1, ll end = n){
	if (end<l||start>r) return 0;
	
	if (l<=start&&end<=r) return smt[node];
	
	ll mid=(start+end)>>1;
	
	return max(query(l,r,node<<1,start,mid),query(l,r,node<<1|1,mid+1,end));
}

int main(){
//	freopen("input.inp","r",stdin);
//	freopen("output.out","w",stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin>>n;
	
	for (ll i=0;i<n;++i) cin>>a[i];
	for (ll i=0;i<n;++i) cin>>h[i];
	
	for (ll i=0;i<n;++i){
		dp[a[i]]=query(1,a[i]-1)+h[i];
		update(a[i],dp[a[i]]);
	}
	
	cout<<*max_element(dp+1,dp+n+1)<<"\n";
}

Measured memory_bytes: 12444
# coding: utf-8
# Your code here!
N,L=map(int,input().split())
l=list(map(int,input().split()))
judge="Impossible"
index=0

for i in range(N-1):
    if (l[i]+l[i+1])>=L:
        judge="Possible"
        index=i
        break

print(judge)
if judge=="Impossible":
    exit()

for i in range(0,index):
    print(i+1)

for i in range(index+2,N)[::-1]:
    print(i)

print(index+1)




Measured memory_bytes: 14052
#include<iostream>
using namespace std;
int main(){
long i,j;
double a,b,aa[7]={35.5,37.5,40,43,50,55,70},bb[7]={71,77,83,89,105,116,148};
while(cin>>a>>b){
for(i=0;i<7;i++)if(a<aa[i])break;j=i;
for(i=j;i<7;i++)if(b<bb[i])break;
if(i==0)cout<<"AA";
if(i==1)cout<<"A";
cout<<"AAABCDEN"[i];
if(i==7)cout<<"A";
cout<<endl;
}
return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define YESNO(i) if((i)) puts("YES");else puts("NO");
#define YesNo(i) if((i)) puts("Yes");else puts("No");
#define yesno(i) if((i)) puts("yes");else puts("no");
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k,a,b;cin>>k>>a>>b;
  bool isok=false;
  for(ll i=a;i<=b;++i) if(i%k==0) isok=true;
  if(isok) puts("OK");else puts("NG");
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    ll k, a, b;
    cin >> k >> a >> b;
    ll res;
    if(b <= a + 2){
        cout << k + 1 << endl;
    }else if(k < a + 1){
        cout << k + 1 << endl;
    }else{
        cout << a + (k - a + 1) / 2 * (b - a) + ((k - a + 1) % 2);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
vector<int> i;
vector<int> u;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a=0,b,c,d=0,e=0,f,g;
  string s;
  cin >>a;
  for(int n=0;n<a;n++){
    cin >>c;
    i.push_back(c);
  }
  cin >>b;
  for(int n=0;n<b;n++){
    cin >>c;
    u.push_back(c);
  }
  sort(i.begin(),i.end());
  sort(u.begin(),u.end());
  c=-1;
  for(int n=0;n<b;n++){
    for(int m=c+1;m<a;m++){
      if(u[n]==i[m]){
	c=m,d++;
	break;
      }
    }
  }
  if(d==b) cout <<"YES\n";
  else cout <<"NO\n";
  return (0);
}


Measured memory_bytes: 2548