akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    static int bubblesort(int a[], int size){
        int tmp;
        int time = 0;
        for(int i = 0; i < size-1; i++){
            for(int j = size-1; j>i; j--){
                if(a[j-1] > a[j]){
                    tmp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = tmp;
                    time++;
                }
            }
        }
        return time;
    }
    
    static public void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A[] = new int[N];
        for(int i = 0; i<N; i++){
            A[i] = sc.nextInt();
        }
        int time = bubblesort(A, N);
        for(int i = 0; i<N; i++){
            System.out.printf("%d", A[i]);
            if(i < N-1) System.out.printf(" ");
        }
        System.out.printf("\n%d\n", time);
        sc.close();
    }
    
}


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

int main(){
    int a[3];
    for(int i=0; i<3; i++) cin >> a[i];
    sort(a, a+3);
    cout << abs(a[0]-a[1])+abs(a[1]-a[2]) << endl;
    return 0;
}

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

int main() {
  int N,A;
  cin >> N;
  string ans="APPROVED";
  rep(i,N){
    cin >> A;
    if(A%2==0){
     if(A%3!=0 && A%5!=0) ans="DENIED"; 
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int N, M;
int X[114514], Y[114514], Z[114514];

int uf[114514], ufSize[114514];;

void ufInit(void) {
	int i;
	for (i = 1; i <= N; i++) {
		uf[i] = i;
		ufSize[i] = 1;
	}
}

int ufGet(int kugyu) {
	return uf[kugyu] == kugyu ? kugyu : (uf[kugyu] = ufGet(uf[kugyu]));
}

int ufGetSize(int kugyu) {
	return ufSize[ufGet(kugyu)];
}

int ufIsSame(int asumisu, int mizuhasu) {
	return ufGet(asumisu) == ufGet(mizuhasu);
}

void ufMerge(int tomatuharuka, int igutiyuka) {
	int maaya = ufGet(tomatuharuka), sumipe = ufGet(igutiyuka);
	if (maaya != sumipe) {
		int satorina = ufGetSize(maaya), zaasan = ufGetSize(sumipe);
		if (satorina < zaasan) {
			uf[maaya] = sumipe;
			ufSize[sumipe] += ufSize[maaya];
		} else {
			uf[sumipe] = maaya;
			ufSize[maaya] += ufSize[sumipe];
		}
	}
}

int main(void) {
	int i;
	int emirin = 1;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < M; i++) {
		if (scanf("%d%d%d", &X[i], &Y[i], &Z[i]) != 3) return 1;
	}
	ufInit();
	for (i = 0; i < M; i++) {
		ufMerge(X[i], Y[i]);
	}
	for (i = 2; i <= N; i++) {
		if (!ufIsSame(1, i)) {
			emirin++;
			ufMerge(1, i);
		}
	}
	printf("%d\n", emirin);
	return 0;
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 a,b,c,d;
  cin >> a >> b >> c >> d;
  vector<int64> x,y;
  x.pb(a);
  x.pb(b);
  if(a <= 0 && 0 <= b)x.pb(0);
  y.pb(c);
  y.pb(d);
  if(c <= 0 && 0 <= d)y.pb(0);

  int64 ans = -llinf;
  for(auto xi : x){
    for(auto yi : y){
      chmax(ans,xi*yi);
    }
  }
  ANS(ans);
  return 0;
}

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

int cntr[4], cntl[4];
int main() {
	double r, l;
	while (cin >> r >> l) {
		if (r >= 1.1)cntr[3]++;
		else if (r >= 0.6)cntr[2]++;
		else if (r >= 0.2)cntr[1]++;
		else cntr[0]++;
		if (l >= 1.1)cntl[3]++;
		else if (l >= 0.6)cntl[2]++;
		else if (l >= 0.2)cntl[1]++;
		else cntl[0]++;
	}
	rep(i, 4) {
		cout << cntr[3 - i] << ' ' << cntl[3 - i] << endl;
	}
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }


    long long a = 0;
    long long ans = 0;
    int left = 0;
    for(int i=0; i<N; i++){
        while((a | A[i]) != a + A[i]){
            a -= A[left];
            left++;
        }
        a += A[i];
        ans += i - left + 1;
        //cout << i << " " << left << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
n, k = gets.split.map(&:to_i)
s = gets.chomp
# データ終了の目印を付加
s += "D"
hand_standing = []
standing = []

previous = ""
count = 1

hand_standing << 0 if s[0] == "0"

s.chars do |char|
  if previous == char
    count += 1
  else
    if previous == "0"
      standing << count
    elsif previous == "1"
      hand_standing << count
    end
    previous = char
    count = 1
  end
end

hand_standing << 0 if s[-2] == "0"

hand_standing_sum = []
(k + 1).times { hand_standing_sum.push(hand_standing.shift) unless hand_standing.empty? }
standing_sum = []
k.times { standing_sum.push(standing.shift) unless standing.empty? }
current = hand_standing_sum.inject(0, :+) + standing_sum.inject(0, :+)
ans = current

until hand_standing.empty?
  previous_1 = hand_standing_sum.shift
  current_1 = hand_standing.shift
  hand_standing_sum.push(current_1)
  previous_2 = standing_sum.shift
  current_2 = standing.shift
  standing_sum.push(current_2)
  current += current_1 + current_2 - previous_1 - previous_2
  ans = current if ans < current
end

puts ans


Measured memory_bytes: 3708
from collections import defaultdict
debug = print
def debug(*va): pass

def longest_by_topological_sort(N, nexts, prevs):
    visited = [-1] * N
    max_dist = 0
    que = list(range(N))
    while len(que):
        p = que.pop()
        if visited[p] == -1:
            if all(visited[q] != -1 for q in prevs[p]):
                dist = 0
                for q in prevs[p]:
                    dist = max(dist, visited[q] + 1)
                visited[p] = dist
                max_dist = max(max_dist, dist)
                for n in nexts[p]:
                    que.append(n)
    return max_dist

def test_separate():
    import time
    N = 10**5
    t0 = time.time()
    print(longest_by_topological_sort(N, defaultdict(list), defaultdict(list)))
    print('elapsed', time.time() - t0)

def test_fanout():
    import time
    N = 10**5
    nn, pp = defaultdict(list), defaultdict(list)
    for i in range(1, N):
        nn[0].append(i)
        pp[i].append(0)
    t0 = time.time()
    print(longest_by_topological_sort(N, nn, pp))
    print('elapsed', time.time() - t0)

def test_middle():
    import time
    N = 10**5
    nn, pp = defaultdict(list), defaultdict(list)
    for i in range(1, N):
        # fanout
        nn[0].append(i)
        pp[i].append(0)
        # fanin
        nn[i].append(1)
        pp[1].append(i)
    t0 = time.time()
    print(longest_by_topological_sort(N, nn, pp))
    print('elapsed', time.time() - t0)

if __name__ == '__main__':
    N, M = map(int, input().split())

    nextnodes = [defaultdict(list), defaultdict(list)]
    for i in range(M):
        x, y = map(int, input().split())
        nextnodes[0][x - 1].append(y - 1)
        nextnodes[1][y - 1].append(x - 1)

    max_dist = longest_by_topological_sort(N, nextnodes[0], nextnodes[1])
    print(max_dist)


Measured memory_bytes: 57824
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 60;
constexpr auto mod = 1000000007;
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    map<char, VI> map;

    FOR(i, 0, s.length())map[s[i]].push_back(i);
    for (auto a : map) {
        VI m = a.second;
        FOR(i, 0, m.size() - 1) {
            if (m[i + 1] - m[i] + 1 <= 3) {
                cout << m[i] + 1 << " " << m[i + 1] + 1 << "\n";
                return 0;
            }
        }
    }

    cout << "-1 -1\n";
}

Measured memory_bytes: 1228
#include<iostream>
#include <complex>
#include <cmath>
#include<cstdio>
using namespace std;
typedef complex<double> xy_t;

xy_t P[110];
double cross_product(xy_t a, xy_t b) { 
    return (conj(a)*b).imag(); 
}

int main() {
// 入力例 読み込んだ点の個数を N とする
    int N=0;
    double x, y;
    while (scanf("%lf,%lf", &x, &y)!=EOF) {
       P[N++] = xy_t(x,y);
    }
// 面積計算
    double sum = 0.0;
    for (int i=0; i+2<N; ++i) {
        xy_t a=P[0], b=P[i+1], c=P[i+2];
        sum +=  cross_product(b-a,c-a)/2;// 三角形 abc の面積を加算
    }
    printf("%.6f\n", abs(sum));
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	string S1,S2;
	cin>>S1>>S2;
	S1.push_back('1');S1.push_back('3');
	S2.push_back('2');S2.push_back('4');
	ll ans;
	int start;
	int joutai;
	if(S1[0] == S2[0]){
		ans = 3;
		start = 1;
		joutai = 1;
	}
	else{
		ans = 6;
		start = 2;
		joutai = 2;
	}
	for (int i = start; i <= N; ++i){
		if(S1[i] == S2[i]){
			if(joutai == 1){
				ans *= 2;
				ans %= MOD;
			}else{
				ans *= 1;
				ans %= MOD;
			}
			joutai = 1;
		}
		else if(S1[i] == S1[i+1]&&S2[i]==S2[i+1]){
			if(joutai == 1){
				ans *= 2;
				ans %= MOD;
			}else{
				ans *= 3;
				ans %= MOD;
			}
			i++;
			joutai = 2;
		}
		else{
			break;
		}
		ans %= MOD;
		/*cerr<<ans<<endl;
		cerr<<S1[i]<<endl;
*/	}
	ans %= MOD;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
ll MOD = 1000000007;
ll INF = 2147483647;
double EPS = 1e-12;
double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

int main(){
  string S;cin >> S;
  int N = S.size();
  int ans = 100000000;
  rep(i,N-1){
    if(S[i] != S[i+1]){
      ans = min((ll)ans,max(i+1,N-i-1));
    }
  }
  if(ans == 100000000){
    cout << N << endl;
    return 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
Scanner kb=new Scanner(System.in);
//a,b,?§????
double a=kb.nextDouble(),b=kb.nextDouble();
double c=kb.nextDouble();
double d=Math.sqrt(a*a+b*b-2*a*b*Math.cos(Math.toRadians(c)));
//??¢????????¨??????????????????
double s,l=0,h=0;
s=a*b*Math.sin(Math.toRadians(c))/2;
l=a+b+d;
h=2*s/a;

System.out.println(s);
System.out.println(l);
System.out.println(h);
	}

}

Measured memory_bytes: 27884
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int K;
  cin >> K;

  vector<int> A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  cout << A[K-1] << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define ll long long

ll f(int n,ll m){
	if(n==0)return !!m;
	if(m==0)return 0;
	m--;
	ll nnn=(4LL<<(n-1))-3;
	ll ret=0;
	if(m>=nnn){
		m-=nnn;
		ret+=(nnn+1)/2;
		if(m)m--,ret++;
	}
	if(m<=0)return ret;
	return ret+f(n-1,m);
}
int main(){
	int n;
	ll m;
	scanf("%d%lld",&n,&m);
	printf("%lld",f(n,m));
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<queue>
#include<utility>

using namespace std;

int main(){

  int n=1,m,ans=0;
  int a[1000]={0};

 while(n!=0){
    cin>>n>>m;
   if(n==0) break;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

 
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){

      if(i!=j && a[i]+a[j]<=m && a[i]+a[j]>ans){
	  ans=a[i]+a[j];
	}     
      
    }
  }

  

  
  if(ans!=0){
    cout<<ans<<endl;
  }else{
    cout<<"NONE"<<endl;
  }
  ans=0;
}

return 0;
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef map<string, int> msi;
typedef pair<int, int> PII;

int main() {
    string s; cin >> s;
    if(s[s.size()-1] == 's') cout << s << "es" << endl;
    else cout << s << 's' << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int N;
    cin >> N;
    int W[N];
    REP(i, N) cin >> W[i];

    int s1 = 0;
    int s2 = 0;
    REP(i, N) s2 += W[i];
    int ret = abs(s1-s2);

    REP(i, N)
    {
        s1 += W[i];
        s2 -= W[i];
        ret = min(ret, abs(s1-s2));
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
dp=[1]*N
listA=[]
for i in range(M):
  a=int(input())
  listA+=[a]
  dp[a-1]=0
setA=set(listA)    
if (1 not in setA) and (2 not in setA) and N!=1:
  dp[1]=2
for i in range(2,N):
  if i+1 not in setA:
    dp[i]=dp[i-1]+dp[i-2]
ans=dp[-1]%(10**9+7)
print(ans)

Measured memory_bytes: 460020
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a % 3 == 0)
        puts("Possible");
    else if (b % 3 == 0)
        puts("Possible");
    else if ((a + b) % 3 == 0)
        puts("Possible");
    else 
        puts("Impossible");
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  long double A, B;
  cin >> A >> B;
  ll ans = floor(A * B);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3744
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;
queue<pair<int,int> >q;
int n,m,nn;
vector<pair<int,int> >v[100010];
vector<int>nv[300010];
bool vis[300010];
int cur[100010];
vector<int>col[1000010];
vector<int>res;
void dfs(int x,int c)
{
	vis[x]=true;
	res.push_back(x);
	for(int i=cur[x];i<v[x].size();i++)
	{
		if(v[x][i].first!=c)break;
		cur[x]++;
		int y=v[x][i].second;
		if(vis[y])continue;
		dfs(y,c);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	nn=n;
	for(int i=1;i<=m;i++)
	{
		int x,y,c;
		scanf("%d%d%d",&x,&y,&c);
		v[x].push_back(make_pair(c,y));
		v[y].push_back(make_pair(c,x));
		col[c].push_back(x);
		col[c].push_back(y);
	}
	for(int i=1;i<=n;i++)
	{
		sort(v[i].begin(),v[i].end());
	}
	for(int i=1;i<=1000000;i++)
	{
		if(!col[i].size())continue;
		for(int j=0;j<col[i].size();j++)
		{
			vis[col[i][j]]=false;
		} 
		for(int j=0;j<col[i].size();j++)
		{
			int x=col[i][j];
			if(vis[x])continue;
			res.clear();
			dfs(x,i);
			nn++;
			for(int k=0;k<res.size();k++)
			{
				nv[nn].push_back(res[k]);
				nv[res[k]].push_back(nn);
			}
		}
	}
	memset(vis,false,sizeof(vis));
	q.push(make_pair(1,0));
	vis[1]=true;
	while(!q.empty())
	{
		int x=q.front().first,w=q.front().second;
		q.pop();
		if(x==n)
		{
			printf("%d",w/2);
			return 0;
		}
		for(int i=0;i<nv[x].size();i++)
		{
			int y=nv[x][i];
			if(vis[y])continue;
			vis[y]=true;
			q.push(make_pair(y,w+1));
		}
	}
	printf("-1");
	return 0;
} 

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
  return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
  return a / gcd(a, b) * b;
}

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

int main()
{
  llint n, m;
  ci >> n >> m;

  cnt += min(n, m / 2);

  m -= n * 2;
  if(m <= 3) {
    co << cnt << en;
    return 0;
  }

  co << cnt + m / 4 << en;
  
  return 0;
}


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

int main(){
    int S; cin >> S;
    int fs = S/100,tf = S%100;

    if(fs >= 1 && fs <= 12){
        if(tf >= 1 && tf <= 12){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "MMYY" << endl;
        }
    }else{
        if(tf >= 1 && tf <= 12){
            cout << "YYMM" << endl;
        }else{
            cout << "NA" << endl;
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int i, cnt = 0;
		int N = sc.nextInt();
		String name = sc.next();
		String[] board = new String[N];
		for(i=0; i<N; i++)board[i] = sc.next();
		
		for(i=0; i<N; i++){
			cnt += Main.Check(name, board[i]);
		}
		System.out.println(cnt);
	}
	
	
	public static int Check(String name, String board){
		int i, j, k, space, next;
		boolean flag = false;
		char[] nameC = name.toCharArray();
		char[] boardC = board.toCharArray();
		
		for(i=0; i<board.length(); i++){
			if(nameC[0] == boardC[i]){
				for(j=i; j<board.length(); j++){
					if(nameC[1] == boardC[j]){
						space = j - i;
						for(k=2, next=j+space; next<board.length(); next+=space, k++){
							flag = false;
							if(nameC[k] == boardC[next]){
								flag = true;
								if(k==name.length()-1)return 1;
							}
							if(flag == false)break;
						}		
					}
				}
			}
		}
		return 0;
	}
}

Measured memory_bytes: 27552
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define um unordered_map
#define all(x) (x).begin(),(x).end()
#define forn(i,n) for(int i=0;i<int(n);++i)
#define for1(i,n) for(int i=1;i<=int(n);++i)
#define che(x) cout<<#x<<" having "<<x<<endl 
using namespace std;
typedef long double ld;typedef long long ll;
typedef vector<int> vi;typedef vector<pair<int, int>> vpi;typedef vector<vi> vvi;
typedef vector<ll> vll;typedef vector<pair<ll, ll>> vpll;typedef vector<vll> vvll;
template<class T>bool uin(T &a,T b){return a>b?(a=b,true):false;}
template<class T>bool uax(T &a,T b){return a<b?(a=b,true):false;}
const ll MOD=1e9+7,INF=1e18;
/********************************************************************************/
 

 
int32_t main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);
    cout.precision(10);cout<<fixed;
 
    int n;
    string s;
    cin>>n>>s;
    if(n<3200) cout<<"red"<<endl;
    else cout<<s<<endl;

    return 0;
}

Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline void reverse(Type& arr) { reverse(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1e9 + 7;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
using P = pair<ll, ll>;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll N;
    cin >> N;
    using XYS = vector<P>;
    vector<ll> A(N);
    vector<XYS> xys(N);
    rep(i, N)
    {
        cin >> A[i];
        vector<P> xy(A[i]);
        rep(j, A[i])
        {
            P p;
            cin >> p.first >> p.second;
            --p.first;
            xy[j] = p;
        }
        xys[i] = xy;
    }
    //
    uint16_t maxBit = 1 << N;
    vector<int32_t> buffer(N,-1);
    ll maxSyojiki = 0;
    for (uint16_t bits = 0; bits < maxBit; ++bits)
    {
        bool valid = true;
        //
        for (int mi = 0; mi < N; ++mi)
        {
            //
            auto& xy = xys[mi];
            // 正直者の場合
            if (bits & (1 << mi))
            {
                for(auto& p: xy)
                {
                    bool t = (bits & (1 << p.first));
                    if (p.second != t)
                    {
                        valid = false;
                        goto EXIT;
                    }
                }
            }
        }
    EXIT:
        if (valid)
        {
            ll count = 0;
            rep(i,N)
            {
                if (bits & (1 << i)) ++count;
            }
            chmax(maxSyojiki, count);
        }
    }
    cout << maxSyojiki;

    //
    return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
using namespace std;
int main(){

  string s;
  int r=0;
  cin>>s;
  if(s[0]=='A') r++;
  for(int i=0;i<s.size()-1;i++){
    if(s[i+1]<=s[i]) r++;
    
  }
  cout<<r<<endl;
  
  return 0;

}

Measured memory_bytes: 3148
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define printP(x) "(" << (x).first << ", " << (x).second << ")"
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint n;

int main(void)
{
	cin >> n;
	if((n&(n-1)) == 0){
		cout << "No" << endl;
		return 0;
	}
	
	cout << "Yes" << endl;
	cout << 1 << " " << 2 << endl;
	cout << 2 << " " << 3 << endl;
	cout << 3 << " " << n+1 << endl;
	cout << n+1 << " " << n+2 << endl;
	cout << n+2 << " " << n+3 << endl;
	if(n <= 3) return 0;
	
	for(int i = 1; i < n/4; i++){
		for(int j = 0; j < 3; j++){
			cout << i*4+j << " " << i*4+j+1 << endl;
			cout << n+i*4+j << " " << n+i*4+j+1 << endl;
		}
		cout << n+(i-1)*4+3 << " " << i*4 << endl;
		cout << i*4+3 << " " << n+i*4 << endl;
	}
	
	llint x = n/4*4;
	if(n%4 == 0){
		llint mul = 1;
		for(; mul <= x; mul *= 2);
		mul /= 2;
		cout << mul << " " << x << endl;
		cout << x-mul+1 << " " << n+x << endl;
		return 0;
	}
	if(n%4 >= 1){
		cout << 1 << " " << x << endl;
		cout << x << " " << x+1 << endl;
		cout << 1 << " " << n+x+1 << endl;
		cout << n+x+1 << " " << n+x << endl;
	}
	if(n%4 >= 2){
		cout << 2 << " " << x+2 << endl;
		cout << n+x+1 << " " << n+x+2 << endl;
	}
	if(n%4 >= 3){
		cout << 2 << " " << x+3 << endl;
		cout << x << " " << n+x+3 << endl;
	}
	
	return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<pll> ab(n);
  for (int i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    ab[i] = pii(a, b);
  }
  sort(ab.begin(), ab.end(), [](pll a, pll b) { return a.first < b.first; });

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll buy_m = min(m, ab[i].second);
    m -= buy_m;
    ans += ab[i].first * buy_m;
    if (m == 0) {
      break;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};

vector<lint> G[200050]; // MAX_V,隣接リスト
lint root;

lint parent[20][200050]; // logMAX_V,MAX_V
lint depth[200050];

void LCAdfs(lint v,lint p,lint d){
    parent[0][v]=p;
    depth[v]=d;
    rep(i,G[v].size()) if(G[v][i]!=p) LCAdfs(G[v][i],v,d+1);
}

void LCAinit(lint V){
    LCAdfs(root,-1,0);
    for(int k=0;k+1<20;k++){
        for(int v=0;v<V;v++){
            if(parent[k][v]<0) parent[k+1][v]=-1;
            else parent[k+1][v]=parent[k][parent[k][v]];
        }
    }
}

lint LCA(lint u,lint v){
    if(depth[u]>depth[v]) swap(u,v);
    for(int k=0;k<20;k++){
        if((depth[v]-depth[u])>>k&1) v=parent[k][v];
    }
    if(u==v) return u;
    for(int k=20-1;k>=0;k--){
        if(parent[k][u]!=parent[k][v]){
            u=parent[k][u];
            v=parent[k][v];
        }
    }
    return parent[0][u];
}

vector<int> path(int s,int t){
    int lca=LCA(s,t);
    vector<int> ps,pt;
    int now=s;
    while(true){
        if(now==lca) break;
        ps.push_back(now);
        now=parent[0][now];
    }
    now=t;
    while(true){
        pt.push_back(now);
        if(now==lca) break;
        now=parent[0][now];
    }
    reverse(pt.begin(),pt.end());
    ps.insert(ps.end(),pt.begin(),pt.end());
    return ps;
}

bool reach[100050];
int fe,sn;
int dfs(int now){
    if(now==sn) return 0;
    if(reach[now]) return 0;
    reach[now]=true;
    int res=1;
    rep(i,G[now].size()) res+=dfs(G[now][i]);
    return res;
}

int main(void){
    int N;
    cin >> N;
    rep(i,N-1){
        int u,v;
        cin >> u >> v;
        u--,v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    LCAinit(N);
    vector<int> way=path(0,N-1);
    fe=way[(way.size()-1)/2],sn=way[(way.size()+1)/2];
    int fecnt=dfs(fe);
    int sncnt=N-fecnt;
    if(fecnt<=sncnt) cout << "Snuke" << endl;
    else cout << "Fennec" << endl;
}


Measured memory_bytes: 32924
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<cctype>
#include<map>
#include<set>
#include<deque>
#include<iomanip>
typedef long long LL;
using namespace std;
int main()
{
	int x,a,b;
	cin>>x>>a>>b;
	int ans = 0;
	ans = x-a;
	while(ans>=b)
	{
		ans-=b;
	}
	cout<<ans<<endl;
	return 0; 
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
ll N;
ll dist[805];
ll p[805];
ll d[805];
vector<l_l> pathes[805];

void dfs(int now, int from) {
    for(int i = 0; i < pathes[now].size(); i++) {
        int to = pathes[now][i].first;
        if(to == from) continue;
        ll newcost = dist[now] + pathes[now][i].second;
        dist[to] = newcost;
        dfs(to, now);
    }
}

int main() {
    while(true) {
        cin >> N;
        if(N == 0) break;
        for(int i = 1; i <= N; i++) {
            pathes[i].clear();

        }
        ll sum = 0;
        for(int i = 2; i <= N; i++) cin >> p[i];
        for(int i = 2; i <= N; i++) cin >> d[i];
        for(int i = 2; i <= N; i++) {
            sum += 3 * d[i];
            pathes[p[i]].push_back({i, d[i]});
            pathes[i].push_back({p[i], d[i]});
        }
        for(int i = 1; i <= N; i++) {
            if(pathes[i].size() != 1) continue;
            sum -= pathes[i][0].second * 2;
        }
        //cerr << sum << endl;
        ll ans = sum;
        for(int i = 1; i <= N; i++) {
            if(pathes[i].size() == 1) continue;
            dist[i] = 0;
            dfs(i, -1);
            for(int j = i + 1; j <= N; j++) {
                if(pathes[j].size() == 1) continue;
                ans = min(ans, sum - dist[j]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3320
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main() {
    int n;
    cin >> n;
    ll deka = 1000000000+1;
    set<ll> stl, str;
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        stl.insert(a+b);
        str.insert((deka-a)+b);
    }
    cout << max(*stl.rbegin()-*stl.begin(), *str.rbegin()-*str.begin()) << endl;
    return 0;
}


Measured memory_bytes: 22336
#include<iostream>
using namespace std ;
int main()
{
    int a,b,c;
    cin >> a >> b >> c ;
    if(a-b==0)
    {
        cout << c << endl;
    }
    else if(c<=a-b)
    {
        cout << "0" << endl;
    }
    else{cout << c-a+b << endl;}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> g[10000];
int ans[10000];
int aa;
vector<ll> c;
void dfs(int idx,int par = -1)
{
	ans[idx] = c[aa++];
	for(auto &i:g[idx])
	{
		if(i==par)continue;
		dfs(i,idx);
	}
}

ll dfs2(int idx,int par=-1)
{
	ll res = 0;
	for(auto &i:g[idx])
	{
		if(i==par)continue;
		res+= min(ans[i],ans[idx]);
		res += dfs2(i,idx);
	}
	return res;
}

int main()
{
	int n;
	cin >> n;
//	vector<int > c(n);

	for(int i = 0;i<n-1;i++)
	{
		int x,y;
		cin >> x >> y;
		x--;y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i = 0;i<n;i++)
	{
		int a;
		cin >> a;
		c.push_back(a);
	}
	sort(c.begin(),c.end(),greater<>());
	int idx;
	for(int i = 0;i<n;i++)if(g[i].size()==1)idx=i;
	dfs(idx);
	cout<<dfs2(idx)<<endl;
	for(int i = 0;i<n;i++)cout<<ans[i]<<' ';
	cout<<endl;

	return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const int N = 1e5 + 4;
int parent[N], depth[N];

void init_sets(int n) {
	for (int i = 1; i <= n; i++) {
		parent[i] = i;
		depth[i] = 0;
	}
}

int find_set(int u) {
	if (parent[u] == u) return u;
	return parent[u] = find_set(parent[u]);
}

void union_sets(int u, int v) {
	u = find_set(u);
	v = find_set(v);
	if (u == v) return;
	if (depth[u] < depth[v]) swap(u, v);
	parent[v] = u;
	if (depth[u] == depth[v]) ++depth[u];
}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, m; scanf("%d%d", &n, &m);
	vi pos(n+1);
	for (int i = 1; i <= n; i++) {
		int x; scanf("%d", &x);
		pos[x] = i;
	}

	init_sets(n);
	while (m-- > 0) {
		int a, b;
		scanf("%d%d", &a, &b);
		union_sets(a, b);
	}
	int answer = 0;
	for (int i = 1; i <= n; i++) {
		if (find_set(i) == find_set(pos[i])) ++answer;
	}
	printf("%d\n", answer);
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
char x[2000][1000];
int main() {
	int H, W; cin >> H >> W;
	for (int i = 0; i < 2 * H; i += 2) {
		for (int j = 0; j < W; j++) {
			cin >> x[i][j]; x[i + 1][j] = x[i][j];
		}
	}
	for (int i = 0; i < 2 * H; i++) {
		for (int j = 0; j < W; j++) {
			cout << x[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 512
N = int(input())
T, A = map(int, (input().split()))
H = list(map(int, (input().split())))
tem_h = [(T - i * 0.006) for i in H]
ans = 0
min = 100000

for n, i in enumerate(tem_h):
    dif = abs(A - i)
    if min > dif:
        min = dif
        ans = n + 1

print(ans)

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


#define fast_IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
typedef long long int lli;
typedef long long ll;
typedef long double ld;


signed main(){
    fast_IO;
    int t=1;
    //cin>>t;
    while(t--){
        ll n;
        cin>>n;
        string s;
        while(n){
            --n;
            s+=(n%26)+'a';
            n=n/26;
        }
        reverse(s.begin(),s.end());
        cout<<s;
    }   
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->left);
    cout << " " << u->key;
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL) return;
    cout << " " << u->key;
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, x;
    string com;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> com;
        if (com == "insert") {
            cin >> x;
            insert(x);
        } else if (com == "print") {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }
}



Measured memory_bytes: 26540
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    string s;
    cin>>s;
    rep(i,0,s.size()) s[i]='x';
    cout<<s<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        long sum = 0;

        int i = 0;
        for (i = 0; i <= N; i++) {
            sum += i;
            if (sum >= N) {
                break;
            }
        }
        for (int j = 1; j <= i; j++) {
            if (j == (sum - N)) {
                continue;
            }
            System.out.println(j);
        }
    }
}


Measured memory_bytes: 24276
#include <iostream>
#include <cmath>
#include <map>
using namespace std;

int r,n,L,R,h,i,x;

int main(){
	
	while(cin>>r>>n,r){

		
		map<int,int> A,B;
		for(i=0;i<n;i++){
			cin>>L>>R>>h;
			for(x=L;x<=R;x++){
				if(x!=R)A[x]=max(A[x],h);
				if(x!=L)B[x]=max(B[x],h);
			}	
		}
		double res=99;
		for(i=-r;i<=r-1;i++){
			res=min(res,min(r-sqrt(r*r-i*i)+A[i],r-sqrt(r*r-(i+1)*(i+1))+B[i+1]));
		}
		cout<<res<<"\n";
		
	}
	
	return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))

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

struct Spell {
	int size; string s;
	Spell(int _size, string _s) : size(_size), s(_s) {}
};
bool operator > (const Spell& a, const Spell& b) {
	if (a.size > b.size) return true;
	if (a.size == b.size) return a.s < b.s;
	return false;
}

int h, w;
string pat[11];

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

void solve() {
	set<string> finds;
	set<Spell, greater<Spell> > setp;
	
	for_(i,0,h) for_(j,0,w) {
		for_(d,0,8) {
			int sx = (j + dx[d] + w) % w, sy = (i + dy[d] + h) % h;
			string s = "";
			s += pat[i][j];
			
			while (sx != j || sy != i) {
				s += pat[sy][sx];
				sx = (sx + dx[d] + w) % w;
				sy = (sy + dy[d] + h) % h;
			
				if (finds.find(s) != finds.end()) {
					setp.insert(Spell((int)s.size(), s));
				} else {
					finds.insert(s);
				}
			}
		}
	}
	
	if ((int)setp.size() == 0) {
		cout << 0 << endl;
		return;
	}
	set<Spell, greater<Spell> >::iterator it = setp.begin();
	cout << (*setp.begin()).s << endl;
}

int main() {
	while (cin >> h >> w, h) {
		for_(i,0,h) cin >> pat[i];
		solve();
	}
	return 0;
}

Measured memory_bytes: 36116
/*
Author : Gaurav Singh
*/
#include<bits/stdc++.h>
using namespace std;
#define N 5005
#define MOD 1000000007
#define ll long long
#define ld long double
#define ull unsigned long long
#define li long int
#define str string
#define vll vector<ll>
#define pb push_back
#define frn(i,n) for(ll (i) = 0; (i) <(n) ; (i)=(i+1))
#define fr(i,n) for(ll (i) = 1; (i) <=(n) ; (i)=(i+1))
#define frev(i,n) for(ll (i) = n-1; (i) >=(0) ; (i)--)
#define fr1(j,a,b,c) for(ll (j) = a; (j) <c ; (i)=(i+b))
#define w(t) while(t--)
#define fast ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
void solve(){
    ull n,i,s=1,st=0;
    cin>>n;
    ull A[n+5];
    frn(i,n){
        cin>>A[i];
        if(A[i]==0){
            st=1;
        }
    }
    if(st){
        cout<<0;
    }
    else{
        frn(i,n){
            if(A[i] <=1000000000000000000/s){
              s *=A[i];
              }
          	else{
              cout<<-1;
              return;
              }
        }
        cout<<s;
    }
}
int main()
{   
   fast;
   int t=1;
   //cin>>t;
    w(t){
        solve();
    }
   return 0;
}   
            


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

int main(){
  string S;
  int K;
  cin>>S>>K;
  int L=S.size();
  vector<vector<int>> dp(L+2,vector<int>(K+1));
  int X=0;
  for(int i=0;i<L;i++){
    int A=S[i]-'0';
    for(int j=0;j<K;j++){
      dp[i+1][j+1]=dp[i][j+1]+9*dp[i][j];
    }
    dp[i+2][0]=1;
    if(A){
      X++;
      if(X<=K){
        dp[i+1][X]+=A-1;
        dp[i+1][X-1]++;
      }
    }
  }
  if(X>=K){
    dp[L][K]++;
  }
  cout<<dp[L][K]<<endl;
    
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define eps 1e-9;
#define MOD 1000000007;
#define INV_10 299473306;
using namespace std;
int main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  string s;
  cin >> s;
  if(s[2]==s[3] && s[4]==s[5])
  	cout << "Yes\n";
  else
  	cout << "No\n";
}

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {
  ll n,m;
    ci(n>>m);
  
  vll A(m);
  FOR(i,0,n){
    ll k;
      ci(k);
    FOR(j,0,k){
      ll a;
        ci(a);
      A[a-1]++;
    }
  }
  
  ll ans=0;
  
  FOR(i,0,m){
    if(A[i]==n){
      ans++;
    }
  }
    co(ans)
}

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

using namespace std;

int main()
{
    int a,b,c,x,y;

    cin>>a>>b>>c>>x>>y;

    int d=(a+b)/2;
    int res;
    if(d<=c){
        int k1=a*x + b*y;
        int k2=max(x,y)*2*c;
        res=min(k1,k2);
    }
    else{
        int k=min(x,y);
        if(x>=y){
             int k1=k*c*2 +  (x-k)*a;
             int k2=max(x,y)*c*2;
             res=min(k1,k2);
        }
        else{
            int k1=k*c*2 +  (y-k)*b;
             int k2=max(x,y)*c*2;
             res=min(k1,k2);
        }

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


Measured memory_bytes: 256
def solve(n,arr):
    maxh = 0
    h = 0
    for i in range(1,n):
        curr = arr[i]
        curh = arr[i-1]
        f = max(curr,curh)
        maxh = max(f,maxh)

        if curr < maxh:
            h += maxh - curr

        # print(f"curr:{curr},curh:{curh},maxh:{maxh}")
        # print(f"h:{h}")

    return h
        



n = int(input())
arr = list(map(int, input().strip().split()))

print(solve(n,arr))

Measured memory_bytes: 32176
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
#define N 300005
struct node{
	int x, y;
}l[N];
int f[N*9], n, m, k, cnt;
bool cmp(node a, node b){
	return a.y<b.y;
}
void upd(int t, int l, int r, int x, int y){
	if (l==r){
		f[t]+=y;
		return;
	}
	int mid=l+r>>1;
	if (x<=mid) upd(t<<1, l, mid, x, y);
	else upd((t<<1)+1,mid+1,r,x,y);
	f[t]=max(f[t<<1],f[(t<<1)+1]);
}
int main(){
	n=read(), m=read(), k=read();
	for (int i=1;i<=k;i++)
		l[++cnt].x=read(),
		l[cnt].y=read(),
		upd(1,1,n,l[cnt].x,1);
	sort(l+1,l+1+cnt,cmp);
	int ans=f[1];
	for (int i=1, j=i;i<=cnt;){
		while (j<=cnt && l[j].y==l[i].y) upd(1,1,n,l[j++].x,-1);
		ans=max(ans,f[1]+j-i);
		while(i<j) upd(1,1,n,l[i++].x,1);
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 10040
#include <bits/stdc++.h>
 
using namespace std;
 
// typedef
typedef long long ll;
typedef long double ldbl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
 
// container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
// repetition
#define FOR(i,m,n) for (ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define RFOR(i,m,n) for (ll (i) = ((ll) (m)-1); (i) >= ((ll) n); --(i))
#define REP(i,n) FOR(i,0,n)
 
// i/o
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl
 
// constant
const double PI  = acos(-1.0);
const int    MOD = (int)(1e9 + 7);
// DO NOT set INFTY_XXXs constants. They may bring some BUG! Use MAX_XXXs in climit instead.
 
// clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
// debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl


template<typename T>
inline vector<T> cin_vector(const size_t n) {
     vector<T> vec;
    vec.reserve(n);
    REP(i, n) {
        T element; cin >> element;
        vec.push_back(element);
    }
    return vec;
}

template<typename T>
inline vector< vector<T> > cin_matrix(const size_t m, const size_t n) {
    vector< vector<T> > matrix;
    matrix.reserve(m);
    REP(i, m) {
        vector<T> vec = cin_vector<T>(n);
        matrix.push_back(vec);
    }
    return matrix;
}

template<typename T>
inline void cout_vector(const vector<T>& vec) {
    REP(i, SZ(vec)-1) {
       cout << vec[i] << ' ';
    }
    cout << vec[SZ(vec)-1] << endl;
}

template<typename T>
inline void cout_matrix(vector< vector<T> > matrix) {
    for(const vector<T>& vec : matrix) {
         cout_vector<T>(vec);
    }
}


int main() {
    string s; cin >> s;
    ll k; cin >> k;
    ll one_num = 0;
    while (1) {
        if (s[one_num] == '1') {
            one_num++;
        } else {
            break;
        }
    }
    if (one_num > 0) {
        if (k <= one_num) {
            cout << '1' << endl;
        } else {
            cout << s[one_num] << endl;
        }
    } else {
        cout << s[0] << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::string s;
    std::cin >> s;
    bool f = s[0] == s[1] || s[1] == s[2] || s[2] == s[3];
    std::cout << (f ? "Bad" : "Good") << std::endl;

    return 0;
}


Measured memory_bytes: 256