akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
  int size;

  cin>>size;

  int array[size],exchange,count=0;
  for(int i = 0;i < size;i++)
    cin >> array[i];

  bool flag = true;

  while(flag){
    flag = false;
    for(int i = 0;i < size-1;i++){
      if(array[i]>array[i+1]){
        exchange = array[i];
        array[i] = array[i+1];
        array[i+1] = exchange;
        count++;
        flag = true;
      }
    }
  }

  for(int i = 0;i < size-1;i++)
    cout << array[i] << " ";
  cout<<array[size-1]<<endl;
  cout<<count<<endl;

  return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;

using ll = long long;

int main(void){
    int N, M;
    cin >> N >> M;
    vector<vector<pair<int, int>>> vv(N);
    for (int i=0; i<M; i++){
        int p, y;
        cin >> p >> y;
        p--;
        vv[p].emplace_back(y, i);
    }
    vector<pair<int, int>> ans(M);
    for (int i=0; i<N; i++){
        sort(vv[i].begin(), vv[i].end());
        for (int j=0; j<vv[i].size(); j++){
            int index = vv[i][j].second;
            ans[index] = make_pair(i+1, j+1);
        }
    }
    
    for (int i=0; i<M; i++){
        printf("%06d%06d\n", ans[i].first, ans[i].second);
    }
    
}


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

int main(){
    int n;
    cin >> n;
    long long ans = 0;
    for(long long  i = 1; i <= n; i++){
        if(i % 3 == 0 || i % 5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
}

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

int main()
{
	int n,i,j;
	cin>>n;
	int a[n+1],b[n+1],c[n];
	for(i=1;i<n+1;i++)
		cin>>a[i];
	for(i=1;i<n+1;i++)
		cin>>b[i];
	for(i=1;i<n;i++)
		cin>>c[i];
	int ans=0;
	for(i=1;i<n+1;i++)
	{
		j=a[i];
		ans+=b[j];
		if(i-1>=0 && a[i-1]+1==a[i])
			ans+=c[j-1];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

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

int k, a, b;

int main() {
    read(k), read(a), read(b);
    for (int i = a; i <= b; ++i) {
        if (i % k == 0) {
            puts("OK");
            return 0;
        }
    }
    puts("NG");
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <iostream>
using namespace std;
// node最大量
#define MAX 100000
#define NIL -1

struct Node {
    int parent;
    int left;
    int right;
};

// 配列で保持する
Node gNode[MAX];

// 先行順巡回
void preParse(int u){
    if(u == NIL)return;
    printf(" %d",u);
    preParse(gNode[u].left);
    preParse(gNode[u].right);
}

// 中間順巡回
void inParse(int u){
    if(u == NIL)return;
    inParse(gNode[u].left);
    printf(" %d",u);
    inParse(gNode[u].right);
}

// 後行順巡回
void postParse(int u){
    if(u == NIL) return;
    postParse(gNode[u].left);
    postParse(gNode[u].right);
    printf(" %d",u);
}

int main(){
    int left,right,v,n,root = 0;
    cin >> n;
    // 初期化
    for(int i = 0;i < n;++i){
        gNode[i].parent = gNode[i].left = gNode[i].right = NIL;
    }
    
    for(int i = 0;i < n;++i){
        cin >> v >> left >> right;
        gNode[v].left = left;
        gNode[v].right = right;
        // 親の設定
        if(left != NIL){
            gNode[left].parent = v;
        }
        if(right != NIL){
            gNode[right].parent = v;
        }
    }

    // rootを探す
    for(int i = 0;i < n;++i){
        if(gNode[i].parent == NIL){
            root = i;
        }
    }
    
    cout << "Preorder\n";
    preParse(root);
    cout << "\n";
    cout << "Inorder\n";
    inParse(root);
    cout << "\n";
    cout << "Postorder\n";
    postParse(root);
    cout << "\n";
    
    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)N;i++)
#define p(s) cout<<(s)<<endl
#define ck(n,a,b) (a)<=(n)&&(n)<(b)
typedef long long ll;
using namespace std;
const int inf=1e9;

int main(){
	int n;
	cin>>n;
	int a[100010];
	REP(i,0,n){
		cin>>a[i];
	}
	ll ans[2];

	REP(hugou,0,2){
		ans[hugou]=0;
		ll sum=0;
		REP(i,0,n){
			sum+=a[i];
			if(i%2==hugou&&sum>=0){
				ans[hugou]+=sum+1;
				sum=-1;
			}else if(i%2!=hugou&&sum<=0){
				ans[hugou]+=-sum+1;
				sum=1;
			}
		}
	}
	p(min(ans[0],ans[1]));
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;


int main()
{
	int R;
	cin >> R;
	double p = 3.1415926535;
	cout << 2.0 * R * p << endl;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() {
	int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
	tx -= sx; ty -= sy;
	rep(i, ty)cout << "U";
	rep(i, tx)cout << "R";
	rep(i, ty)cout << "D";
	rep(i, tx)cout << "L";
	cout << "D";
	rep(i, tx + 1)cout << "R";
	rep(i, ty + 1)cout << "U";
	cout << "L";
	cout << "U";
	rep(i, tx + 1)cout << "L";
	rep(i, ty + 1)cout << "D";
	cout << "R" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n[3] , a , b , c;
    for( int i = 0 ; i < 3 ; i++) {
        cin >> n[i];
    }
    a = n[0];
    b = n[1];
    c = n[2];
    n[0] = min( min( a , b ) , c );
    n[2] = max( max( a , b ) , c );
    n[1] = a + b + c - n[0] - n[2];
    int x = n[2] - n[1] + ( n[1] - n[0] ) / 2;
    if( ( n[1] - n[0] ) % 2 == 0 ) {
        cout << x;
    } else{
        cout << x + 2;
    }
}

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

using namespace std;

#define ll long long
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 1e6 + 5;
const ll MOD =  1e9 + 7;
int arr[mxn];
int n, m, k, q;
string s, t;

void solve() {
    cin >> n;
    cout << (1 - n) << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    //cin >> T;
    while(T--) solve();
    return 0;
}


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

int main()
{
    int N ;
    cin >> N ;
    string S ;
    cin >> S;
    string x ;
    int y = 0;
    for(int i =0 ; i<N ;i++){
        if(S[i]=='(')
            y++;
        else
            y--;
        if(y<0)
            x = '('+x ,y++;
        x+=S[i];
}
    while(y--)
        x+=')';
    cout << x;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {


    // 最小本数
    // 最大本数

    // 桁数

    // 桁目を何にしたか
    // 残り


    // 大きい順に優先
    // 残り桁数＊最小本数＜＝残り本数＆＆残り桁数＊最大本数＞＝残り本数なら可能

    map<int, int> u = {
            {1, 2},
            {2, 5},
            {3, 5},
            {4, 4},
            {5, 5},
            {6, 6},
            {7, 3},
            {8, 7},
            {9, 6},
    };

    int n, m;
    cin >> n >> m;

    vector<int> v(m);
    rep(i, m) cin >> v[i];
    sort(v.rbegin(), v.rend());

    int mi = INT_MAX;
    for (int i : v) cmin(mi, u[i]);
    int ma = 0;
    for (int i : v) cmax(ma, u[i]);

    vector<int> dp(n + 100, -1);
    vector<int> prev(n + 100, -1);
    dp[0] = 0;

    rep(i, n) {
        if (dp[i] == -1) continue;
        for (int j : v) {
            int use = u[j];
            int next_keta = dp[i] + 1;
            int next_use = i + use;
            if (dp[next_use] <= next_keta) {
                dp[next_use] = next_keta;
                prev[next_use] = j;
            }
        }
    }

    int k = dp[n];

    int a = n;
    while (a > 0) {
        for (int i : v) {
            int use = u[i];
            int back = a - use;
            if (back < 0) continue;
            if (dp[a] - 1 == dp[back]) {
                cout << i;
                a = back;
                break;
            }
        }
    }


}


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

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

int main() {
	ios::sync_with_stdio(false);
	
	int n, c=0;
	string w, r;
	cin>>w;
	cin>>n;
	rep(i, n) {
		cin>>r;
		r+=r;
		if(r.find(w)!=string::npos)c++;
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 1212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = int.Parse(ReadLine());
        var a = ReadLine().Split().Select(int.Parse).ToArray();
        var q = int.Parse(ReadLine());
        long l = 0;
        Dictionary<int, int> w = new Dictionary<int, int>();
        for(int i = 0; i < n; i++)
        {
            if(!w.ContainsKey(a[i]))
                w.Add(a[i], 0);
            w[a[i]]++;
            l += a[i];
        }
        for(int i = 0; i < q; i++)
        {
            var b = ReadLine().Split().Select(int.Parse).ToArray();
            if(!w.ContainsKey(b[0]))
                w.Add(b[0], 0);
            if(!w.ContainsKey(b[1]))
                w.Add(b[1], 0);
            w[b[1]] += w[b[0]];
            l += (long)(b[1] - b[0]) * w[b[0]];
            w[b[0]] = 0;
            WriteLine(l);
        }
    }
}

Measured memory_bytes: 35860
#include <stdio.h>
t[101],a,i,M;
int main(void){
    for(;~scanf("%d",&a);){
        t[a]++;
        if(M<t[a]){
            M=t[a];
        }
    }
    for(i=1;i<101;i++){
        if(M==t[i]){
            printf("%d\n",i);
        }
    }
}

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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

int main() {
  ll N, K;
  cin >> N >> K;

  ll M = (N - 1) * (N - 2) / 2 - K;
  if (M < 0) {
    cout << "-1\n";
    return 0;
  }

  cout << (M + N - 1) << BR;
  for (int i = 2; i <= N; i++) {
    cout << "1" << SP << i << BR;
  }

  for (int i = 2; i <= N; i++) {
    for (int j =  i + 1; j <= N; j++) {
      if (M) {
        cout << i << SP << j << BR;
        M--;
      } else {
        return 0;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

const ll mod=1e9+9;
const ll MAXN=5e3+5;
const ll inf=1e17;

int main()
{
    fastio;
    string s,t;
    cin>>s>>t;
    ll a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(u==s) a--;
    else b--;
    cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
long long INF = 1e10;
/************************  DEFINE  ****************************/

/************************ FUNCTION ****************************/

/************************   MAIN   ****************************/
int main(void){
    int n;cin>>n;
  	cout << 180*(n-2) <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

int N, T;

int takahashi(const vector<int>&A) {
	auto amax = A, amin = A;
	REP(i, 1, A.size())amin[i] = min(amin[i - 1], amin[i]);
	for (int i = A.size() - 2; 0 <= i; i--)amax[i] = max(amax[i + 1], amax[i]);
	int bestsagaku = 0, bestnum = 0;
	rep(i, A.size()) {
		int nowsagaku = A[i] - amin[i];
		if (bestsagaku == nowsagaku)bestnum++;
		else if (bestsagaku < nowsagaku) {
			bestsagaku = nowsagaku;
			bestnum = 1;
		}
	}
	return bestnum;
}

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

	cin >> N >> T;
	assert(2 <= N);
	vector<int>A(N);
	rep(i, N)cin >> A[i];

	cout << takahashi(A) << endl;


	return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    vi x(5); REP(i, 5) cin >> x[i];
    int k; cin >> k;
    REP(i, 4)
    {
        for(int j = i+1; j < 5; j++)
        {
            if(x[j] - x[i] > k)
            {
                cout << ":(" << endl;
                return;
            }
        }
    }
    cout << "Yay!" << endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

S=get_nsp
T=get_nsp
ans=0
3.times do|i|
  ans+=1 if S[i]==T[i]
end
puts ans

Measured memory_bytes: 1788
#include <cstdio>
#ifdef _MSC_VER
#include <conio.h>
#else
#define getch()
#endif
#include <string>
#include <queue>
#include <string.h>

using std::string;
using std::queue;

int main(){
	queue<char> Input;
	string Str="";
	char Buf[11]="";
	scanf("%s",Buf);
	for(int i=0;i<strlen(Buf);i++){
		Input.push(Buf[i]);
	}
	while(Input.empty()!=true){
		char Top=Input.front();
		Input.pop();
		switch(Top){
		case '0':
			//printf("Pushed 0\n");
			Str.push_back('0');
			break;
		case '1':
			//printf("Pushed 1\n");
			Str.push_back('1');
			break;
		case 'B':
			if(Str.empty()!=true){
				//printf("Erased\n");
				Str.erase(Str.size()-1);
			}
			break;
		}
	}
	printf("%s\n",Str.c_str());
	getch();
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){

  int a[4];
  rep(i,4)cin >> a[i];
  cout << a[2]-(a[3]-a[1]) << " " << a[3]+(a[2]-a[0]) << " " << a[0]-(a[3]-a[1]) << " " << a[1]+(a[2]-a[0]) << endl;




  return 0;
}


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



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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int t,a,b;


main() {
    cin >> t >> a >> b;
    ct(min(t*a,b))
}

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

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        if (i < 10) ++ans;
        if(i >= 100 && i < 1000) ++ans;
        if(i >= 10000 && i < 100000) ++ans;
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){

	int n,ans=0;
	cin>>n;

	vector<int> arr = {9,900,90000,900000};

	if(n<10){
		ans = n;
	}else if(n>=10 && n <100){
		ans = 9;
	}else if(n>=100 && n<1000){
		ans = 9 + (n - 100 + 1);
	}else if(n>=1000 && n<10000){
		ans = 9 + 900;
	}else if(n>=10000 && n<100000){
		ans = 9 + 900 + (n-10000+1);
	}else if(n>=100000){
		ans = 9 + 900 + 90000;
	}

	cout<<ans<<"\n";

	return 0;
}


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

int main(void){
  int id;
  double height, weight;
  while(scanf("%d,%lf,%lf", &id, &weight, &height) != EOF){
    double bmi = weight / (height * height);
    if(bmi >= 25) cout << id << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;


char p[5][10][10];
ll lp[5][10][10];
char cban[5][11];
ll lban[20][20];
ll h[10],w[10];
ll n,m;
ll ans;
bool ok;

void dfs(ll look,ll skip){
	if(look == 4){
		ll cnt = 0;
		for(int i=1;i<=4;i++){
			for(int j=1;j<=10;j++){
				if(lban[i][j] != 1){
					break;
				}
				cnt++;
			}
		}
		if(cnt == 40){
			ok = true;
		}else{
			//cout << cnt << endl;
		}
		return;
	}else if(look == skip){
		dfs(look+1,skip);
	}else{
		
		for(int i=1;i<=4-h[look]+1;i++){
			for(int j=1;j<=10-w[look]+1;j++){
				bool oksou = true;
				for(int bi=0;bi<h[look];bi++){
					for(int bj=0;bj<w[look];bj++){
						lban[i+bi][j+bj] += lp[look][bi][bj];
						if(lban[i+bi][j+bj] >= 2)oksou = false;
					}
				}
				if(oksou){
					dfs(look+1,skip);
				}else{
					//cout << "damesou" << endl;
				}
				for(int bi=0;bi<h[look];bi++){
					for(int bj=0;bj<w[look];bj++){
						lban[i+bi][j+bj] -= lp[look][bi][bj];
					}
				}
			}
		}
		return;
	}
	return;
}


void solve(){
	for(int i=0;i<4;i++){
		cin >> cban[i];
	}
	for(int i=0;i<4;i++){
		for(int j=0;j<10;j++){
			if(cban[i][j] == '#'){
				lban[i+1][j+1] = 1;
			}else{
				lban[i+1][j+1] = 0;
			}
		}
	}
	ok = false;
	dfs(0,0);
	if(!ok){
		dfs(0,1);
	}
	if(!ok){
		dfs(0,2);
	}
	if(!ok){
		dfs(0,3);
	}
	
	if(ok){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

}

int main(){
	for(int i=0;i<4;i++){
		cin >> h[i] >> w[i];
		for(int j=0;j<h[i];j++){
			cin >> p[i][j];
			for(int k=0;k<w[i];k++){
				if(p[i][j][k] == '#'){
					lp[i][j][k] = 1;
				}else{
					lp[i][j][k] = 0;
				}
			}

		}
	}
	cin >> n;
	for(int i=0;i<n;i++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    intl len = s.length();
    char c[len];
    rep(i,len){
        c[i] = s[i];
    }
    sort(c,c + len);
    bool f = true;
    rep(i,len-1){
        if(c[i] == c[i+1])f = false;
    }
    fp(f,"yes","no");
    return 0;
}

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

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String n = sc.next();
        for (int i = 0; i < n.length() - 1; i++) {
            if (n.charAt(i) == n.charAt(i + 1)) {
                System.out.println("Bad");
                return;
            }
        }
        System.out.println("Good");
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


Measured memory_bytes: 21972
#include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;
         
        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define Test(){int t;cin >> t;for(int i=1;i<=t;i++){cout << "Case #" << i << ": ";solve();}}
        #define test(){int t; cin>>t; for(int i=1;i<=t;i++){solve();}}
        #define vi vector<int>
        #define vii vector<pair<int,int> > 
        #define vci vector<pair<char,int> >
        #define vic vector<pair<int,char> > 
        #define N 20005
        #define pb push_back
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
		
	
		void solve()
		{
			int n;
			cin>>n;
			
			int a[n];
			loop(i,n)
			cin>>a[i];
			
			int sum[n+1];
		
			sum[n-1]=a[n-1];
			for(int i=n-2;i>=0;i--)
			{
				sum[i]=(sum[i+1]+a[i])%MOD;
			}
			int ans=0;
			for(int i=0;i<n-1;i++)
			{
				ans=(ans+(a[i]*sum[i+1])%MOD)%MOD;
			}
			cout<<ans<<endl;
		}
		signed main()
		{
		//	test();
		solve();
		}

Measured memory_bytes: 6708
#include<iostream>
using namespace std;
int main(void)
{
	int i,n,a[100001],e=0,o=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%2==0) e++;
		else o++;
	}
	if(o%2!=0) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(int argc,char const* argv[])
{
  int n;
  cin >> n;
  vector <int> s(n,0);
  vector <int> buckets(101,0);
  int seiseki=0;
  bool fix=false;
  for(int i=0;i<n;i++)
    {
      cin >> s[i];
      seiseki+=s[i];
      buckets[s[i]]++;
    }
  if(seiseki % 10 ==0)
    {
      for(int i=1;i<100;i++)
	{
	  if(buckets[i] !=0 && i % 10 !=0)
	    {
	      seiseki-=i;
	      fix=true;
	      break;
	    }
	}
      if(!fix)seiseki=0;
    }
  cout << seiseki << endl;
  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x);
		y = y >> 1;
		x = (x * x);
	}
	return res;
}
double dist(ll x1,ll y1, ll x2,ll y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n, maxi = 0;
	cin >> n;
	vector<ll> arr(n, 0);
	f(i, 0, n)
		cin >> arr[i];
	ll c = 0;
	f(i, 1, n)
	{
		if (arr[i] <= arr[i - 1])
			c += 1;
		else
		{
			
			maxi = max(maxi, c);
			c = 0;
		}
	}
	maxi = max(maxi, c);
	cout << maxi;
	return 0;
}


Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val s = sc.next()

  val e = Array(n) { 0 } // east
  val w = Array(n) { 0 } // west

  for ((i, si) in s.withIndex()) {
    if (si == 'E') {
      e[i] = 1
    }
    if (si == 'W') {
      w[i] = 1
    }
  }

  var wc = 0
  var arrayW = Array(n) { 0 }
  for (i in 0 until n) {
    arrayW[i] = wc
    if (s[i] == 'W') wc++
  }
  // println(arrayW.joinToString(""))

  var ec = 0
  var arrayE = Array(n) { 0 }
  for (i in n-1 downTo 0) {
    arrayE[i] = ec
    if (s[i] == 'E') ec++
  }
  // println(arrayE.joinToString(""))

  var min = Int.MAX_VALUE
  for (i in 0 until n) {
    val tmp = arrayW[i] + arrayE[i]
    min = Math.min(min, tmp)
  }
  println(min)

}


Measured memory_bytes: 65204
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  string S;
  cin >> N >> S;
  int lb = 0;
  int rw = count(S.begin(), S.end(), '.');
  int ans = lb + rw;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == '.') {
      rw--;
    } else {
      lb++;
    }
    ans = min(ans, lb + rw);
  }
  cout << ans << endl;
}


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

// Union-Find木 (経路圧縮あり、ランク無し、サイズあり)
// ref. https://www.slideshare.net/chokudai/union-find-49066733
struct UnionFind {
  vector<int> parent;
  vector<int> size;

  UnionFind(int n) {
    parent.resize(n);
    size.resize(n, 1);
    for (int i = 0; i < n; i++) {
      // parent[i] = i ならば根
      parent.at(i) = i;
    }
  }

  // 木の根を求める
  int root(int x) {
    // 頂点 x が根の場合は根の値を返す
    if (parent.at(x) == x) {
      return x;
    // 頂点 x が根ではない場合は経路圧縮を行いつつ、根の値を返す
    } else {
      // 経路圧縮
      parent.at(x) = root(parent.at(x));
      return parent.at(x);
    }
  }

  // 頂点 x と y が同じ集合に属するか否か
  bool same(int x, int y) {
    return root(x) == root(y);
  }

  // 頂点 x が所属する集合のサイズを求める
  int size_of(int x) {
    return size.at(root(x));
  }

  // 頂点 x と y の属する集合を併合
  void unite(int x, int y) {
    // 2頂点の根を求める
    x = root(x);
    y = root(y);

    // 頂点 x と y が同じ集合に所属している場合は併合する必要がない
    if (x == y) { return; }

    // 要素数が多い方に併合する
    if (size.at(x) > size.at(y)) {
      // 以下の親子関係となる
      // (x == root of x || y == root of y のケースもある)
      //
      // [y] --> [root of y] --+
      //                       |--> [root of x]
      // [x] ------------------+
      //
      parent.at(y) = x;
      size.at(x) += size.at(y);
    } else {
      parent.at(x) = y;
      size.at(y) += size.at(x);
    }
  }
};

int main() {
  int n; // 人数
  cin >> n;
  int m; // 情報の数
  cin >> m;

  vector<pair<int, int>> a(m); // 情報
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    a.at(i) = make_pair(x, y);
  }

  UnionFind uf(n);
  for (int i = 0; i < (int)a.size(); i++) {
    pair<int, int> p = a.at(i);
    uf.unite(p.first, p.second);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, uf.size_of(i));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6380
#define pi 3.14159265358979323846
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
//#include <iomanip> : 表示桁数

using namespace std;

int N;
long long int ans = 1;
long long int Comb(int, int);
long long int powSP(long long int,int, int);

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

	//main process
	if (D[0] != 0) {
		ans = 0;
	} else {
		int nPast = 0;
		int iPast = 0;
		sort(D.begin(), D.end());
		for (int i = 1;i < N;i++) {
			if (nPast != D[i]) {
				Dcount.push_back(i - iPast);
				nPast++;
				iPast = i;
				if (nPast != D[i]) { //飛びはありえない
					ans = 0;
					break;
				}
			}
		}
		Dcount.push_back(N - iPast);

		if (Dcount[0] != 1) {
			ans = 0;
		}

		if (ans != 0) {
			for (int i = 1;i < Dcount.size();i++) {
				ans = (long long int)powSP(ans, Dcount[i - 1], Dcount[i]);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

long long int powSP(long long int ans,int p, int q) {
	for (int i = 0;i < q;i++) {
		ans = ans * p % 998244353;
	}
	return ans;
}

long long int Comb( int p, int q) {
	long long int C = 1;
	long long int j = p;
	for (int i = 0;i < q;i++) {
		C *= j;
		j--;
	}
	for (int i = 1;i <= q;i++) {
		C /= i;
	}

	return C;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <sstream>

using namespace std;

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

    int ans = 0;

    for(int tmp500 = 0; tmp500 <= A; tmp500++){
        for(int tmp100 = 0; tmp100 <= B; tmp100++){
            for(int tmp50 = 0; tmp50 <= C; tmp50++){
                if(tmp500 * 500 + tmp100 * 100 + tmp50 * 50 == X){
                    ans++;
                }
            }
        }
    }

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


Measured memory_bytes: 256
using System;

public class AtCoder{
	public static void Main(){
		string[] s;
		s = NextS();
		
		int n;
		n = int.Parse(s[0]);
		
		int[] L = new int[n*2];
		s = NextS();
		for(int i=0; i<n*2; i++){
		    L[i] = int.Parse(s[i]);
		}
		
		Array.Sort(L);
		 
		int ans = 0;
		for(int i=0; i<n*2; i = i+2){
		    ans += L[i];
		}
		
		Console.WriteLine(ans);
	}

	public static void DebugWL(object x){ System.Diagnostics.Debug.WriteLine(x); }
	public static string[] NextS(){ return Console.ReadLine().Trim().Split(' '); }
}


Measured memory_bytes: 11348
package main

import (
	"fmt"
)

func main() {
	var n, y int
	fmt.Scan(&n, &y)
	for i := 0; i <= n; i++ {
		for j := 0; j <= n-i; j++ {
			k := n - i - j
			if 10000*i+5000*j+1000*k == y {
				fmt.Println(i, j, k)
				return
			}
		}
	}
	fmt.Println("-1 -1 -1")
}


Measured memory_bytes: 1836
#include <cstdio>

int main(void)
{
  int n, a, b, c, d;
  scanf("%d", &n);
  a = (n / 1000) % 10;
  b = (n / 100) % 10;
  c = (n / 10) % 10;
  d = n % 10;
  if (a == b || b == c || c == d)
    printf("Bad\n");
  else
    printf("Good\n");
  return 0;
}

Measured memory_bytes: 128
# --- cofing: utf-8 ---

n = int(input())

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

def mod2(a, cnt):
    if sum([i % 2 for i in a]) == 0:
        a = [i / 2 for i in a]
        cnt += 1
        return mod2(a, cnt)
    else:
        return cnt

print(mod2(a, 0))

Measured memory_bytes: 9228
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

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

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int X = scan.nextInt();
        int Y = scan.nextInt();
        for (int i = 0; i <= X; i++) {
            int total = i * 2 + (X - i) * 4;
            if (total == Y) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


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

#define F first
#define S second
#define PB push_back
#define POP pop_back
#define sz(x) (int)(x.size())

using namespace std;

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

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

	int n;
	cin >> n;
	cout << n + n * n + n * n * n << endl;
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define repf(i, n) for(int i=1; i<(int)(n+1); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    set<int> st = {1, 2, 3};
    int a;
    cin >> a; st.erase(a);
    cin >> a; st.erase(a);
    for(auto c: st) cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define llint long long
#define mod 1000000007

using namespace std;

llint N, M;

llint fact(llint n)
{
	llint ret = 1;
	for(int i = 1; i <= n; i++){
		ret *= i;
		ret %= mod;
	}
	return ret;
}

int main(void)
{
	cin >> N >> M;
	
	llint ans;
	if(abs(N - M) >= 2){
		cout << 0 << endl;
		return 0;
	}
	
	ans = fact(N) * fact(M);
	ans %= mod;
	
	if(N == M){
		ans *= 2;
		ans %= mod;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#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 ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

#define MAX 20


using namespace std;

int rec(int ls,int p,int q,int a,int n){
	int count=0;
	if(p==0){
		return 1;
	}
	if(n<=0){
		return 0;
	}
	for(int y=ls;y<=a;y++){
		if(q<=y*p){
			count+=rec(y,p*y-q,q*y,a/y,n-1);
		}
	}
	return count;
}


int main(){
	int p, q, a, n;
	while(cin>>p>>q>>a>>n&&p||q||a||n){
		cout<<rec(1, p, q, a, n)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}


fun main() {
    val N = nextLong()
    if (N % 2 == 1L) {
        println(0)
        return
    }
    var n = N
    var ans = 0L
    while (n > 0L) {
        ans += n / 10
        n /= 5
    }
    println(ans)
}

Measured memory_bytes: 34436
#include <iostream>
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int X;
    cin >> X;
    vector<int> v;
    v.push_back(1);
    for (int i = 2; i <= X; i++){
        int k = 2;
        int t = i;
        while(pow(t,k) <= X){
            //cout << t << "**" << k << endl;
            //t = pow(t,k);
            v.push_back(pow(t,k));
            k++;
        }
    }
    cout << *max_element(all(v)) << endl;


    return 0;
}


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

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


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

class Program_B
{
  static void Main(string[] args)
  {
    float N = 0;
    var D = 0;
    {
      var input = Console.ReadLine().Split(' ');
      N = float.Parse(input[0]);
      D = Int32.Parse(input[1]);
    }
    Console.WriteLine( Math.Ceiling( N/(D*2+1)));
  }
}



Measured memory_bytes: 11092
def Attack(i):
  goukei = 0
  if (i == 1):
    return 1
  else:
    goukei = goukei + 1
    goukei = goukei + Attack(int(i/2)) * 2
    return goukei

H = int(input())
goukei2 = Attack(H)

print(goukei2)



Measured memory_bytes: 2940
#include <stdio.h>

int main(void)
{
	int n;
	scanf("%d", &n);

	int i, t[101], sum = 0;
	for(i = 0; i < n; i++) {
		scanf("%d", &t[i]);
		sum += t[i];
	}

	int m, p, x;
	scanf("%d", &m);
	for(i = 0; i < m; i++) {
		scanf("%d %d", &p, &x);
		printf("%d\n", sum + x - t[p - 1]);
	}
	return 0;
}

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

int main(){
  string s;
  int count=0;
  cin>>s;
  
  for(int i=0;i<(s.size()/2);i++){
    if(s.at(i)!=s.at(s.size()-1-i)){
      count++;
    }
  }
  cout <<count<<endl;
        
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...) \
  { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  void solve() {
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    i64 ans = 0;
    vector<bool> win(n);
    for (int i = 0; i < n; ++i) {
      if (i - k < 0 || t[i] != t[i - k]) {
        if (t[i] == 'r')
          ans += p;
        else if (t[i] == 's')
          ans += r;
        else
          ans += s;
        win[i] = 1;
      } else {
        if (win[i - k]) {
          win[i] = 0;
        } else {
          win[i] = 1;
          if (t[i] == 'r')
            ans += p;
          else if (t[i] == 's')
            ans += r;
          else
            ans += s;
        }
      }
    }
    cout << ans << '\n';
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 998244353
const int MAX = 510000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
	ll n,m,k;
	cin>>n>>m>>k;
	ll ans=0;
   COMinit();

    // 計算例
 //   cout << COM(100000, 50000) << endl;	
	for(ll i=0;i<=k;i++){
		ll sum=COM(n-1,i);
		ll r=m*modpow(m-1,n-i-1,inf);
		r%=inf;
		ans+=r*sum;
		ans%=inf;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 15480
s = input()
a = s.count("a")
b = s.count("b")
c = s.count("c")
n = len(s)
if (0 <= a - (n // 3) <= 1) & (0 <= b - (n // 3) <= 1) & (0 <= c - (n // 3) <= 1):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include <iostream>
using namespace std;

int main(void) {
	int m, f, r;
	char c;
	while (1) {
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1)
			break;
		if (m == -1 || f == -1)
			c = 'F';
		else if ((m + f) >= 80)
			c = 'A';
		else if ((m + f) >= 65)
			c = 'B';
		else if ((m + f) >= 50)
			c = 'C';
		else if ((m + f) >= 30) {
			if (r >= 50)
				c = 'C';
			else
				c = 'D';
		} else
			c = 'F';
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
function main(arg) {
	arg = arg.trim().split(/\n/);
  	var words = arg[1].split(' '),
  		s = words[0], t = words[1],
        num = arg[0], out = '';
	for (var i = 0; i < num; i++){
    	out += s[i]+t[i]
    }
  	console.log(out);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
n,k,a[1<<17],i,l,L,s1,s2,w;M(int*a){return*a-*1[&a];}main(){for(;scanf("%d%d",&n,&k)*n;){for(i=0;i<k;i++)scanf("%d",a+i);qsort(a,k,4,M);L=a[k]=0;for(s1=s2=i=w=!*a;i<=k;i++){if(a[s1]-s1==a[i]-i){l=i-s1+1;l>L?L=l:0;}else{if(w&&s2==w&&a[w]>1){l=i-s1+1;l>L?L=l:0;}s2=s1;s1=i;}if(w&&a[s2]-s2==a[i]-i-1){l=i-s2+2;l>L?L=l:0;}}if(w&&a[k-1]<n){l=k-s2+1;l>L?L=l:0;}printf("%d\n",L);}}

Measured memory_bytes: 976