akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int i,j,l,r,x,y=0;
    cin>>l>>r;
    i=r/l;
    j=log(i)/log(2);
    for(x=l;x<=r;x*=2){y++;}
    cout<<y<<endl;
    
    
    

}

Measured memory_bytes: 256
#include<iostream>
#define INF 0x7fffffff;
using namespace std;
const int maxn=500010;
int a[maxn];
int L[maxn/2+2],R[maxn/2+2];
int n,cnt=0;
void merge(int a[],int left,int mid ,int right){
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;i++)L[i]=a[left+i];
	for(int i=0;i<n2;i++)R[i]=a[mid+i];
	int i=0,j=0;
	L[n1]=R[n2]=INF;
	for(int k=left;k<right;k++){
		cnt++;
		if(L[i]<R[j])
			a[k]=L[i++];
		else
			a[k]=R[j++];
	}
}
void mergesort(int a[],int left,int right ){
	if(left+1<right){
		int mid=(left+right)/2;
		mergesort(a,left,mid);
		mergesort(a,mid,right);
		merge(a,left,mid,right);
	}
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	mergesort(a,0,n);
	for(int i=0;i<n;i++){
		if(i>0)cout<<" ";
		cout<<a[i];
	}
	cout<<endl;
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 6888
S = input()
ans = "None"
W = {"a":0, "b":0, "c":0, "d":0,"e":0,"f":0,"g":0,"h":0,"i":0,"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,"u":0,"v":0,"w":0,"x":0,"y":0,"z":0}
P = "abcdefghijklmnopqrstuvwxyz"
for i in S:
  W[i] += 1
for p in P:
  if W[p] == 0:
    ans = p
    break
print(ans)
    


Measured memory_bytes: 3316
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

vector<LL> solve2(LL H, LL W) {
	if (H <= 1) return{};
	LL h1 = H / 2;
	LL h2 = H - h1;
	return{ h1 * W, h2 * W };
}

LL solve(LL H, LL W) {
	LL ret = 1000000000;
	ret *= ret;
	for (LL h = 1; h <= H - 1; h++) {
		LL a1 = h * W;
		vector<LL> V = solve2(H - h, W);
		if (SZ(V) > 1) {
			V.push_back(a1);
			sort(ALL(V));
			ret = MIN(ret, V[2] - V[0]);
		}
		V = solve2(W, H - h);
		if (SZ(V) > 1) {
			V.push_back(a1);
			sort(ALL(V));
			ret = MIN(ret, V[2] - V[0]);
		}
	}
	return ret;
}

int main()
{
	LL H, W;
	scanf("%lld %lld", &H, &W);
	LL ans = solve(H, W);
	LL ans2 = solve(W, H);
	ans = MIN(ans, ans2);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <numeric>
using namespace std;

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

	if (S == "SUN") cout << '7' << endl;
	if (S == "MON") cout << '6' << endl;
	if (S == "TUE") cout << '5' << endl;
	if (S == "WED") cout << '4' << endl;
	if (S == "THU") cout << '3' << endl;
	if (S == "FRI") cout << '2' << endl;
	if (S == "SAT") cout << '1' << endl;


	return 0;

}

Measured memory_bytes: 256
// УЛЬЯНА САМАЯ ЛУЧШАЯ!!!!!!!!

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::abs;
using std::min;
using std::max;
using std::swap;

using std::map;
using std::pair;
using std::set;
using std::string;
using std::vector;

using std::sort;
using std::reverse;

using ll = long long;

#define forn(i, n) for (ll i = 0; i < (ll) n; ++i)
#define sz(a) static_cast<int>(a.size())
#define push_back emplace_back
#define endl '\n'

class solver {
private:
    double TIME;

    static const ll INF = static_cast<ll>(1e9) + 7;
    static const int MAXN = static_cast<ll>(1e2) + 17;
    const int MAGIC = 51;

    int a, b, c;

public:
    static bool FLAG;

    solver() {
        TIME = static_cast<double>(clock()) / CLOCKS_PER_SEC;
    }

    bool read() {
        if (!(cin >> a >> b >> c))
            return false;

        return true;
    }

    void solve() {
        if (a % 2 == b % 2 && b % 2 == c % 2) {
            cout << ((3 * max({a, b, c}) - (a + b + c)) / 2) << endl;
        } else {
            if (a % 2 == b % 2)
                ++a, ++b;
            else if (a % 2 == c % 2)
                ++a, ++c;
            else
                ++b, ++c;

            cout << 1 + ((3 * max({a, b, c}) - (a + b + c)) / 2) << endl;
        }
    }

    ~solver() {
#ifdef SEREZHKA
        if (FLAG)
            cerr << "Time elapsed: " << static_cast<double>(clock()) / CLOCKS_PER_SEC - TIME << endl;
#endif
    }
};

bool solver::FLAG = true;

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    cerr << std::fixed << std::setprecision(5);

#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
    std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');
#else
    std::mt19937 rand(time(NULL));
#endif

    while (solver::FLAG) {
        solver solution;

        if (!solution.read())
            solver::FLAG = false;
        else
            solution.solve();
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <vector>

using namespace std;


int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (auto &a : A) cin >> a;
  partial_sum(begin(A), end(A), begin(A));
  transform(begin(A), end(A), begin(A),
            [&](long long x) { return abs(2 * x - A.back()); });
  cout << *min_element(begin(A), end(A)) << endl;
}


Measured memory_bytes: 1792
n=int(input())
a=list(input())
b=list(input())
c=list(input())
ans=0
for i in range(n):
    if ( a[i] == b[i] and b[i] != c[i] ) or ( b[i] == c[i] and c[i] != a[i] ) or ( c[i] == a[i] and a[i] != b[i] ):
        ans+=1
    elif a[i] != b[i] and b[i] != c[i] and c[i] != a[i]:
        ans+=2
print(ans)


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			if(N >= 30) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 32732
N, M = map(int, input().split())
ballcount = []
for i in range(0, N):
	ballcount.append(1)
redlist = [True]
for i in range(1, N):
	redlist.append(False)
for i in range(0, M):
	x, y = map(int, input().split())
	if redlist[x-1]: redlist[y-1] = True
	ballcount[x-1] -= 1
	ballcount[y-1] += 1
	if ballcount[x-1] == 0: redlist[x-1] = False
cnt = 0
for i in range(0, N):
	if redlist[i]: cnt += 1
print(cnt)

Measured memory_bytes: 52360
import java.util.Scanner;

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

        String a = sc.next();
        if(a.matches("[A-Z]")) {
            System.out.println("A");
        } else {
            System.out.println("a");
        }
    }
}


Measured memory_bytes: 35476
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
#define SWAP(var,a,b) {var tmp=a; a=b; b=tmp;}

int main()
{
  string str;
  int n;
  cin >> str >> n;
  string order;
  string buf;
  char c;
  int a,b;
  string p;
  string ShowString[100];
  int count=0;

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

      cin >> order >> a >> b;

      if(order=="replace")
	{
	  cin >> p ;
	  
	  str.replace(a,b-a+1,p);
	}
      else if(order=="reverse")
	{
	  /*
	  for(int j=a,k=0;j<(b-a+1)/2;j++,k++)
	    {
	      c=str[j];
	      str[j]=str[b-k];
	      str[b-k]=c;
	      cout << str[j] << str[b-k];
	      }*/
	  // SWAP(char,str[j],str[b-k]);
	  buf=str.substr(a,b-a+1);
	  for(int j=0;j<b-a+1;j++)
	    str[a+j]=buf[b-a-j];
	}
      else if(order=="print")
	{
	  ShowString[count]=str.substr(a,b-a+1);
	  count++;
	}
      else 
	cout << "error \n";
    }

  for(int i=0;i<count;i++)
    cout << ShowString[i] << endl;
 
  return 0;

}

Measured memory_bytes: 3208
#include <iostream>
        #include <cstdio>
        #include <cstdlib>
        #include <cmath>
        #include <climits>
        #include <cstring>
        #include <algorithm>
        #include <numeric>
        #include <vector>
        #include <queue>
        #include <map>
        #include <set>
        #include <string>
         
        #define sp ' '
        #define endl '\n'
        #define Endl '\n'
        #define st first
        #define nd second
        #define pb push_back
        #define mp make_pair
        #define FOR(YY, yy) for(int yy = 0; yy < YY; ++yy)
         
        using namespace std;
        typedef long long int ll;
        typedef unsigned long long int ull;
        typedef vector<int> vi;
        typedef vector< vector<int> > vvi;
        typedef vector< pair<int, int> > vii;
        typedef vector< pair< int, pair<int, int> > > vpip;
        typedef pair<int, int> ii;
         
        const int MOD = 1e9 + 7;
        const int INF = 2e9;
         
        int main(int argc, char **argv)
        {
            ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
            int N; cin >> N;
            ull K; cin >> K;
         
            vector<ll> A(N), F(N);
         
            for(auto &a: A) cin >> a;
            for(auto &f: F) cin >> f;
         
            sort(A.rbegin(), A.rend());
            sort(F.begin(), F.end());
         
            ll high = A[0]*F.back(), low = -1;
         
            while(high - low > 1)
            {
                ll required = 0;
                ll mid = (high + low)/2;
         
                for(int i = 0; i < N; ++i)
                {
                    required += max(0LL, A[i] - (mid/F[i]));
                }
                if(required <= K) high = mid;
                else low = mid;
            }
            cout << high << endl;
         
            return 0;
        }
         
        //cikisir
         

Measured memory_bytes: 3328
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt() * 2;
    int x = sc.nextInt();
    int y = sc.nextInt();
    int total = a * x + b * y;
    while(x>0&&y>0){
      total = Math.min(total,total -a -b +c);
      x--;
      y--;
    }
    while(x>0){
      total = Math.min(total,total -a +c);
      x--;
    }
    while(y>0){
      total = Math.min(total,total -b +c);
      y--;
    }
    System.out.println(total);
  }
}


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

using namespace std;

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

  int n, a, b;
  cin >> n >> a >> b;
  vector<int> h(n);
  int maxh = 0;
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
    maxh = max(maxh, h[i]);
  }
  int additional = a - b;
  int l = 0, r = 2 * maxh / b;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    int cnt = 0;
    int base = b * m;
    for (int i = 0; i < n; ++i) {
      cnt += max(0, ((h[i] - base) + additional - 1) / additional);
      if (m < cnt)
        break;
    }
    if (m < cnt) {
      l = m;
    } else {
      r = m;
    }
  }
  cout << r << "\n";
}


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

#define MAX 100001
int num[MAX];

int main(){
	int n;	cin>>n;
	for(int i=0;i<n;i++){
		int a;	cin>>a;
		if(a-1>=0) num[a-1]++;
		num[a]++;
		if(a+1<=100000) num[a+1]++;
	}

	int ans=0;
	for(int i=0;i<MAX;i++){
		ans=max(ans,num[i]);
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
//コンビネーションを10^9+7で割った余りを求める
const int MOD=1000000007;
const int MAX = 1000000;
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 sub(long long a,long long b){
    long long ans = ((a%MOD)-(b%MOD))%MOD;
    if(ans>=0){
        return ans;
    }
    else{
        return ans+MOD;
    }
}
int main(){
    int n,k;
    cin >>n >> k;
    vector<int64_t> a(n);
    rep(i,n){
        cin>>a[i];
    }
    COMinit();
    if(k==1){
        cout<<0<<endl;
        return 0;
    }
    all(a);
    int64_t maxx=0,minx=0;
    for(int i=k-1;i<n;i++){
        maxx += (a[i]%MOD*COM(i,k-1))%MOD;
        maxx %= MOD;
    }
    for(int i=n-k;i>=0;i--){
        minx += (a[i]%MOD*COM(n-i-1,k-1))%MOD;
        minx %= MOD;
    }
    cout<<sub(maxx,minx)<<endl;

}

Measured memory_bytes: 24448
#include <iostream>

using namespace std;
bool isPalin(string x);
int main() {
    string x;
    cin>>x;
    isPalin(x)?cout<<"Yes":cout<<"No";
}
bool isPalin(string x){
    int mid,len=x.length()-1;
    for(int i=0;i<=len;i++){
        if(x[i]==x[len-i])
        continue;
        else
        return false;
    }
    mid=((len-1)/2);
    for(int i=0;i<=mid;i++){
        if(x[i]==x[mid-i])
        continue;
        else
        return false;
    }
    mid=((len+3)/2);
    for(int i=mid;i<=len;i++){
        if(x[i]==x[len-i])
        continue;
        else
        return false;
    }
    return true;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin >> n >> k;
  vector<double> vec(n);
  for(int i = 0; i < n; i++) {
    cin >> vec.at(i);
    vec.at(i) = (vec.at(i) + 1) / 2;
  }
  double sum = 0;
  for(int i = 0; i < k; i++) {
    sum += vec.at(i);
  }
  double ans = sum;
  for(int i = 0; i < n - k; i++) {
    sum = sum - vec.at(i) + vec.at(i + k);
    ans = max(ans,sum);
  }
  cout << fixed << setprecision(10);
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
//#define ll long long
using namespace std;

int inf = 1e18;
const int N = 5e5+5;
int mod = 1e9+7;
/*void dfs(int u,int par,int maxx)
{


    for(int v:adj[u])
    {
        if(v==par)
            continue;
        dfs(v,u,maxx);
    }
}


int ncr(int n , int r ){
	r = min(r,n-r);
	int res = 1 ;
	for(int i = 1 ; i <= r ; i++ ){
		( res *= n-i+1 )%= mod;
		res /= i ;
	}
	return res ;
}
*/
//ll powmod(ll a,ll b) {ll res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}

int arr[N];
int help(int n)
{
    int ans = 0;
    for(int i=0;i<64;++i)
    {
        int ct = 0;
        int k = (1ll<<i);
        for(int j=0;j<n;++j)
        {
            if(arr[j]&k)
                ct++;
        }
        ans+= k%mod*ct%mod*(n-ct)%mod;
        ans%=mod;
    }
    return ans;
}
int32_t main()
{
    io
    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        int n;
        cin>>n;
        rep(i,0,n)
        cin>>arr[i];
        int ans = help(n);
        cout<<ans%mod<<el;


    }



    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>

using namespace std;

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

    vector<vector<int>> mod0(n + 1, vector<int>(0));
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j += i) {
            mod0[j].push_back(i);
        }
    }

    vector<int> a(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    vector<int> res(0);
    vector<int> cnt(n + 1, 0);
    for (int i = n; i >= 1; i--) {
        if (cnt[i] % 2 != a[i]) {
            res.push_back(i);

            for (int j = 0; j < static_cast<int>(mod0[i].size()); j++) {
                cnt[mod0[i][j]]++;
            }
        }
    }

    cout << res.size() << endl;
    for (int i = 0; i < static_cast<int>(res.size()); i++) {
        cout << (i == 0 ? "" : " ") << res[i];
    }
    if (res.size() > 0) {
        cout << endl;
    }
}


Measured memory_bytes: 24312
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int N, M, C, A[25][25], B[25], cnt = 0;

int calc(int i){
    int ans = 0;
    
    rep(j,M) ans += B[j] * A[i][j];

    return ans + C;
}


void solve(){
    rep(i,N) if(calc(i) > 0) cnt++;

    cout << cnt << endl;
}

int main(){
    cin >> N >> M >> C;

    rep(i,M) cin >> B[i];

    rep(i,N) rep(j,M) cin >> A[i][j];

    solve();
}


Measured memory_bytes: 256
s = input()
if len(s)%2 == 0:
    ans = "10"*(len(s)//2)
    ans2 = "01"*(len(s)//2)
    cnt = 0
    cnt2 = 0
    for i in range(len(s)):
        if ans[i] != s[i]:
            cnt+=1
        if ans2[i] != s[i]:
            cnt2+=1
else:
    ans = "10"*(len(s)//2)+"1"
    ans2 = "01"*(len(s)//2) + "0"
    cnt = 0
    cnt2 = 0
    for i in range(len(s)):
        if ans[i] != s[i]:
            cnt+=1
        if ans2[i] != s[i]:
            cnt2+=1
ans = min(cnt,cnt2)
print(ans)

Measured memory_bytes: 3316
import Control.Monad
 
import Data.Ord
import Data.List
import Data.Function
import Data.Maybe
 
import qualified Data.ByteString.Char8 as BS
 
import Debug.Trace
 
tuplify2 :: [a] -> (a, a)
tuplify2 (x:y:_) = (x, y)
tuplify2 _ = undefined
 
readInt = read :: String -> Integer
readIntTuple = tuplify2 . map readInt . words
readIntList = map readInt . words
 
getInt = readInt <$> getLine
getIntList = readIntList <$> getLine
getIntMatrix = map readIntList . lines <$> getContents
getIntTuple = readIntTuple <$> getLine
getIntTuples = map readIntTuple . lines <$> getContents

main = do
  [a,b,c,d] <- getIntList
  print $ (f a b 1) - (f a b c) - (f a b d) + (f a b (lcm c d))

-- a以上b以下でxで割り切れる数を返す
f a b x = ((maxGuard - minGuard) `div` x) - 1
  where
    minGuard = (a-1) - ((a-1) `mod` x)  -- aより小さいxの倍数
    maxGuard = (b+x) - ((b+x) `mod` x)  -- bより大きいxの倍数


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll A, B, C;
        cin >> A >> B >> C;
        rep(m, 1, 1001) {
                if (A * m % B == C) {
                        cout << "YES" << endl;
                        return 0;
                }
        }
        cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c,n) for(int i=c;i<n;i++)
 
int main() {
  long long int a,b,c,k,ans=0;
  cin>>a>>b>>c>>k;

  while(k>0){
    if(a!=0){
      if(a<k){ans+=a;k-=a;a=0;}
      else{ans+=k;k-=a;a-=k;}
    }
    else if(b!=0){k-=b;b=0;}
    else{
      if(c<k){ans-=c;k-=c;c=0;}
      else{ans-=k;k-=c;c-=k;}
    }
    //cout<<k;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,m,i,x,y,s,ans=1;
	cin>>n>>m;
	vector<ll> vi;
	for(i=1;i<=sqrt(m);i++){
		if(m%i==0){
			if(m/i==i){
				vi.pb(i);
			}
			else{
				vi.pb(i);
				vi.pb(m/i);
			}
		}
	}
	sort(vi.begin(),vi.end());
	for(auto x:vi){
	    y=m/x;
	    s=n;
	    if(s<=y){
	        ans=x;
	    }
	}
	cout<<ans;
}

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

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long[] abcxy = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var a = abcxy[0];
        var b = abcxy[1];
        var c = abcxy[2];
        var d = abcxy[3];
        var e = abcxy[4];

        // ABピザを使わない場合
        var ans = a * d + b * e;

        // ABピザを使う場合
        //if (a > c)
        //{
        var tmp1 = c * d * 2;
        if (e > d)
        {
            tmp1 += b * (e - d);
        }
        ans = Math.Min(ans, tmp1);
        //}

        //if (b > c)
        //{
        var tmp2 = c * e * 2;
        if (d > e)
        {
            tmp2 += a * (d - e);
        }
        ans = Math.Min(ans, tmp2);

        //}

        //if (a > c && b > c)
        //{
        if (d > e)
        {
            ans = Math.Min(ans, c * d * 2);
        }
        else
        {
            ans = Math.Min(ans, c * e * 2);
        }

        //}


        Console.WriteLine(ans);
    }
}


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

int main(){
	 string S;
    cin >> S;
    int L = S.size();
    string ans = "AC";
    if(S[0] != 'A'){
        ans = "WA"; 
        }
    int cnt = 0;
    for(int i = 1; i < L; ++i){
        if(isupper(S[i])){//isuper large string
            if(i == 1 || i == L - 1 || S[i] != 'C'){
                ans = "WA"; 
                }
                ++cnt; 
            }
        }
    if(cnt != 1){
        ans = "WA"; 
        }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#ifdef DEBUG
std::ostream& dout = cout;
#else
stringstream dout;
#endif
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int a[3][3];
    rep(i,3){
        rep(j,3){
            cin>>a[i][j];
        }
    }
    int n;
    cin>>n;
    rep(i,n){
        int in;
        cin>>in;
        rep(j,3){
            rep(k,3){
                if(a[j][k]==in)a[j][k]=0;
            }
        }
    }
    if((a[0][0]==a[1][1]&&a[0][0]==a[2][2])||(a[0][2]==a[1][1]&&a[1][1]==a[2][0])){
        cout<<"Yes"<<endl;
        return 0;
    }
    bool b[3]={true,true,true};
    rep(i,3){
        bool bo=true;
        rep(j,3){
            if(a[i][j]!=0){
                bo=false;
                b[j]=false;
            }
        }
        if(bo){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    if(b[0]||b[1]||b[2])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for((i)=0; (i)<(int)(n); ++(i))
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
const int inf = 1<<28;

int limit, n, m, x;
int e0[102], s0[102], e1[102], s1[102];
int dp[102][1002];

void solve() {
  int i, j, k, l, ii, jj;
  string in;
  rep (i,n) cin >> in >> e0[i] >> s0[i];
  rep (i,m) cin >> in >> e1[i] >> s1[i];

  //memset(dp, -1, sizeof dp);
  rep (i,102) fill(dp[i], dp[i] + 1002, -inf);
  // dp[A][B] := AlÌlðB~ÅÙÁ½êÌÅåÌ«x
  // 0lð0~ÅÙÁ½êÍ«x0ÆÝÈµ
  // »êÈOÌê(1lð0~Æ©-1~Æ©ÁÄ¢¤ÌÍ)
  // -INFµÄ¨­Kvª Á½±ÆÉCÃ¢½
  // «xÌlªå«­ÈéêÍ±ê¶áÊÚ©àË
  // æÁÄdp[0][0] = 0ÌÝú»µÄ¨­
  dp[0][0] = 0;
  for (i = 0; i < m; ++i) {
    for (j = i; j >= 0; --j) {
      for (k = e1[i]; k <= limit; ++k) {
        dp[j+1][k] = max(dp[j+1][k], dp[j][k - e1[i]] + s1[i]);
      }
    }
  }
  
  int ans = -inf;
  for (i = x; i <= m; ++i) {
    for (j = 0; j <= limit; ++j) if (dp[i][j] >= 0) {
      for (k = 0; k < n; ++k) {
        if (j + e0[k] <= limit) ans = max(ans, dp[i][j] + s0[k]);
        for (l = 0; l < k; ++l) {
          if (j + e0[k] + e0[l] <= limit) {
            ans = max(ans, dp[i][j] + s0[k] + s0[l]);
          }
        }
      }
    }
  }
  cout << ans << endl;
}

int main() {
  while (cin >> limit >> n >> m >> x, limit) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 1324
import java.util.*;

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

        int N = sc.nextInt();
        int[] v = new int[N];
        double ans = 0;

        ArrayList<Integer> list = new ArrayList<Integer>();

        for(int i=0; i<N; i++){
            list.add(sc.nextInt());
        }
        Collections.sort(list);
        ans = list.get(0);

        for(int i=1; i<N; i++){
            ans = (ans + list.get(i)) / 2;
        }

        if(ans==(int)ans)
        System.out.println((int)ans);
        else if(ans!=(int)ans)
        System.out.println(ans);
    }
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int partition(vector<int> &A, int p, int r){
    int x = A[r];
    int i = p-1;
    for(int j=p; j<r; j++){
        if(A[j]<=x){
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

int main()
{
    int n; cin >> n;
    vector<int> A(n);
    rep(i,n) scanf("%d", &A[i]);
    int std = partition(A, 0 , n-1);
    rep(i,n){
        if(i == std) cout << "[";
        cout << A[i];
        if(i == std) cout << "]";
        if(i != n-1) cout << " ";
    }cout << endl;
}   


Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;



int main () {

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

	int a, b, c;
	cin >> a >> b >> c;
	cout << c-min(c, a-b);

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	
	string s;
	
	cin>>s;
	
	cout<<count(s.begin(), s.end(), 'o') * 100 + 700<<endl;
	
	return 0;
}

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

	
		
  int n;
  cin>>n;
  string s;
  cin>>s;
  
  if( n&1 ) cout<< "No\n";
  else 
  {

  	  for( int i = 0; i < n/2 ; i++)
  	  {
  	  	if( s[i] != s[n/2 + i]) 
  	  	{

  	  		cout << "No\n";
  	  		return 0;
  	  	}
  	  }
      cout << "Yes\n";
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
int n,now,can=0;
ll l;
ll a[100010];
int main(){
	scanf("%d%lld",&n,&l);
	int i,j;
	for(i=1;i<=n;++i)  scanf("%lld",&a[i]);
	for(i=1;i<n;++i){
		if(a[i]+a[i+1]>=l){
			can=1;now=i;break ;
		}
	}
	if(!can){
		printf("Impossible\n");return 0;
	}
	else{
		printf("Possible\n");
		for(i=1;i<now;++i){
			printf("%d\n",i);
		}
		for(i=n-1;i>=now;--i)  printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


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

    int d = 0;
    int cnt = 1;
    rep(i, N) {
        d = d + L[i];
        if (d <= X) cnt++;
        else break;
    }
    print(cnt);
}


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

#define INF 2147483647
#define LINF 9223372036854775807
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()

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

ll x;

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

	cin>>x;
	ll idx=1,ans=0;
	while (ans<x) ans+=idx,idx++;
	cout<<idx-1<<endl;

	return 0;
}


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

int main()
{
	string N;

	cin >> N;

	if (N[0] == N[2])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
// have you mooed today?
bool isprime(int& num)
{
    static int c;
    static int max;
    if(num == 1) return false;
    if(num == 2) return true;
    if(num % 2 == 0) return false;
    max = ceil(sqrt(num));

    for(c=3; c < max+1; c+=2)
        if(num % c ==0) return false;
    return true;
}

int main()
{
    int ans =0;
    int c;
    int buff;
    vector<int> prime;
    for(c=1;c<=999999;c++)
    {
        if(isprime(c)) ans++;
        prime.push_back(ans);
    }
    while(cin >> buff)
    {
        cout << prime[buff -1] << endl;
    }
    return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void)
{    
    string s;
    cin >> s;
    rep(i, (ll)s.size()) {
        if(s[i] == ',') s[i] = ' ';
        cout << s[i];
    }
    cout << endl;
	
    
    
    
    
    
    
    
}

Measured memory_bytes: 3568
n,kk=gets.split.map(&:to_i)
v=gets.split.map(&:to_i)

r = (0..kk).map do |k|
    i = k
    vv = []
    while i >= 0
        vv << i
        i -= 2 
    end
    vv.map!.with_index {|m,i| [m,k-i]}
    vv.map { |e|
        (e[1]+1).times.map{ |m| 
            v.rotate(-m)[0..e[1]-1].max(e[0]).inject(:+).to_i 
        }.max 
    }.max
end

p r.max

Measured memory_bytes: 3384
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
    int x,y;
    while(true){
        cin >> x >> y;
        if(x==0 && y==0) break;
        if(x < y){
            printf("%d %d\n",x,y);
        }else{
            printf("%d %d\n",y,x);
        }
    }
    return 0;
}


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

using namespace std;

const int inf = 1 << 25;

struct edge
{
  int to, cap, rev, id, isrev;
  edge(){}
  edge(int to, int cap, int rev, int id, int isrev):to(to), cap(cap), rev(rev), id(id), isrev(isrev){}
};

struct Dinic
{
  vector< vector<edge> > G;
  vector<int> level, iter;
  Dinic(int V):G(V), level(V), iter(V){};
  void add_edge(int f, int t, int id)
  {
    G[f].push_back(edge(t, 1, (int)G[t].size(), id, 0));
    G[t].push_back(edge(f, 1, (int)G[f].size()-1, id, 1));
  }
  void bfs(int s)
  {
    fill(level.begin(), level.end(), -1);
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()) {
      int v = que.front(); que.pop();
      for(int i = 0; i < (int)G[v].size(); i++) {
	edge& e = G[v][i];
	if(e.cap > 0 && level[e.to] < 0) {
	  level[e.to] = level[v] + 1;
	  que.push(e.to);
	}
      }
    }
  }
  int dfs(int v, int t, int f)
  {
    if(v == t) return f;
    for(int &i = iter[v]; i < (int)G[v].size(); i++) {
      edge& e = G[v][i];
      if(e.cap > 0 && level[v] < level[e.to]) {
	int d = dfs(e.to, t, min(f, e.cap));
	if(d > 0) {
	  e.cap -= d;
	  G[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }
  int max_flow(int s, int t)
  {
    int flow = 0;
    while(1) {
      bfs(s);
      if(level[t] < 0) return flow;
      fill(iter.begin(), iter.end(), 0);
      int f; while((f = dfs(s, t, inf)) > 0) flow += f;
    }
  }
};

int main()
{
  int N, M; cin >> N >> M;
  Dinic dinic(N);
  for(int i = 0; i < M; i++) {
    int X, Y; cin >> X >> Y; X--, Y--;
    dinic.add_edge(X, Y, i);
  }
  int S, T; cin >> S >> T; S--, T--;
  int ans = dinic.max_flow(S, T);
  vector<int> used_rev;
  for(int v = 0; v < (int)dinic.G.size(); v++) {
    for(int i = 0; i < (int)dinic.G[v].size(); i++) {
      edge e = dinic.G[v][i];
      if(e.cap < 1 && e.isrev == 1) used_rev.push_back(e.id);
    }
  }
  sort(used_rev.begin(), used_rev.end());
  cout << ans << endl;
  cout << (int)used_rev.size() << endl;
  for(int i = 0; i < (int)used_rev.size(); i++) cout << used_rev[i]+1 << endl;
  return 0;
}

Measured memory_bytes: 3248
def main():

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

    all = 0
    for v in a: all ^= v

    ans = []
    for v in a:
        ans.append(v^all)
    return " ".join(map(str, ans))


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 41984
#include <stdio.h>

int main(){
  int bubble[100];
  int n,i,j,flag,d,t=0;

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

  flag =1;
  while(flag){
    flag=0;
    for(j=n-1; j >=1; j--){
      if(bubble[j] < bubble[j-1]){
	d=bubble[j-1];
	bubble[j-1]=bubble[j];
	bubble[j]=d;
	flag=1;
	t++;
      }
    }
  }

  for(i=0; i < n; i++){
    printf("%d",bubble[i]);
    if(i==n-1){
      printf("\n");
    }
    else
      printf(" ");
  }
  printf("%d\n",t);

  return 0;
}

Measured memory_bytes: 604
// Code by Nguyen Huu Lam
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
const LL MaxN = 1 + 2e5, MOD = 7 + 1e9;

LL n, a[MaxN], d[MaxN], kq = 1;
string s;

void InOut(){
    #define TASK "ABC"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
}

int main(){
    // InOut();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    cin >> s;
    n *= 2;
    for(int i = 0 ; i < n ; ++i)
    if(s[i] == 'W') a[i] = 0;
    else a[i] = 1;
    if(!a[0] || !a[n - 1]){
        cout << 0 << endl;
        return 0;
    }
    LL k = 1;
    d[0] = 1;
    for(int i = 1 ; i < n ; ++i)
    if(k % 2 == a[i]){
        d[i] = 0;
        k--;
    }
    else{
        d[i] = 1;
        k++;   
    }
    LL s = 0;
    for(int i = 0 ; i < n ; ++i) s += d[i];
    if(s != n / 2){
        cout << 0 << endl;
        return 0;
    }
    k = 0;
    for(int i = 0 ; i < n ; ++i)
    if(!d[i]){
        kq = (kq * k) % MOD;
        k--;
    } else k++;
    for(int i = 1 ; i <= n / 2 ; ++i) kq = (kq * i) % MOD;
    cout << kq << endl;

    return 0;
}

Measured memory_bytes: 3732
# Problem D-D
H, W = [int(x) for x in input().strip().split(' ')]
image = []
for row in range(H):
    image.append(input().strip())
print("#" * (W + 2))
for i in range(H):
    print("#" + image[i] + "#")
print("#" * (W + 2))


Measured memory_bytes: 3060
import sys
from collections import deque
def input(): return sys.stdin.readline()
def inpl(): return [int(i) for i in input().split()]
from collections import defaultdict
N, M = inpl()
Edge = defaultdict(lambda: [])
Pcan = defaultdict(lambda: 0)

Par = set(range(N)) 
for _ in range(N-1+M):
    A, B = inpl()
    Par.discard(B-1)
    Edge[A-1].append(B-1)
    Pcan[B-1] += 1
par = list(Par)[0]
dist = [0]*N
Q = deque([par])

while Q:
    st = Q.pop()
    for en in Edge[st]:
        if dist[en] < dist[st] + 1:
            dist[en] = dist[st] + 1
            if Pcan[en] == 1:
                Q.append(en)
            else:
                Pcan[en] -= 1
Ans = [0]*N
Q = deque([par]) 
while Q:
    st = Q.pop()
    for en in Edge[st]:
        if dist[en] == dist[st] + 1:
            Ans[en] = st+1
            Q.appendleft(en)
for i in Ans:
    print(i)    


Measured memory_bytes: 49036
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n=0,m,a,b,c,d,e;
	long double z,w;
	string str;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b;
	if(a<=b){cout<<a;}
	else{cout<<a-1;}




	cout<<endl;
} 


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f3f;
const int maxn = 1e5+500;
ll T,n,m;
int main() {
    string s;
    cin>>s;
    int cnt = 0;
    string s1="",s2="";
    for(int i=0;i<s.length();i++){
    	s1+=s[i];
    	if(s1!=s2){
    		cnt++;
    		s2 = s1;
    		s1 ="";
		}
	}
	cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 640
<?php
//??¨???????????????while
//?¨??????\?????§$H ??¨???$W?????\???
while(list($H , $W) = explode(" ", trim(fgets(STDIN)))){

    if($H == "0" && $W == "0"){
        return 1;
    }

//$H???????????????$W???????????????
    for($i = 1; $i <= $H ;$i++){
        for($j = 1; $j <= $W; $j++){
            echo "#";
            if($j == $W){
                echo PHP_EOL;
            }
        }
        if($i == $H){
            echo PHP_EOL;
        }
    }
}
?>

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

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define kk(n)    ff(k, n)
#define xx(n)    ff(x, n)
#define yy(n)    ff(y, n)
#define ii(n)    ff(i, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define kkk(a, b) fff(k, a, b)
#define xxx(a, b) fff(x, a, b)
#define yyy(a, b) fff(y, a, b)
#define iii(a, b) fff(i, a, b)
#define bb begin()
#define ee end()
#define uu first
#define vv second
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#define zz(array, byte)   memset(array, byte, sizeof(array));

using LL = long long;
using DD = long double;
using pii = pair<int, int>;


const LL  INFLL  = 0x7f7f7f7f7f7f7f7fLL;
const int INFint = 0x7f7f7f7f;  //Works with memset(..).
   


int N, K;
vector<int> aa;
int rr = 0;


void backtrack(int level, int base, vector<int> &previous) {
    int skip = (1 << level);
    int otherbase = base + (1 << (level-1));
    if (otherbase >= len(aa)) {
        //One left.
        int remaining = aa[base];
        //printf("Remainging %d\n", remaining);
        iii (K-remaining, K) {
            if (previous[i]) {
                //printf("Got on %d\n", i);
                ++rr;
                return;
            }
        }
        return;
    }
    ii (2) {
        if (1 == i)
            swap(base, otherbase);
        vector<int> here(all(previous));
        for (int k = base; k < len(aa); k += skip) {
            int a = aa[k];
            for (int x = K-a; x >= 0; --x) {
                if (here[x])
                    here[x+a] = 1;
            }
        }
        backtrack(level+1, otherbase, here);
    }
}


int main() {
    //ios_base::sync_with_stdio(false);     cin.tie(NULL);
    //cout << '\n';     //Avoid flushing with endl.
    cout.precision(16);


    cin >> N >> K;

    ii (N) {
        int a;
        cin >> a;
        if (a >= K)
            continue;
        aa.append(a);
    }

    N = len(aa);

    if (N == 0) {
        cout << "0\n";
        return 0;
    }

    
    vector<int> have(K+1, 0);
    have[0] = 1;
    backtrack(1, 0, have);
    
    cout << len(aa) - rr << '\n';
    

    return 0;
}



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

int main(){
    long long int N, score;
    
    cin >> N;
    score = 1;
    for (long long int i = 1; i <= N; i++) {
        score = i * score % 1000000007;
    }

    cout << score << endl;
    
    return 0;
}

Measured memory_bytes: 256
//

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

int main(){
  string s;
  cin >> s;
  int cnt = 700;
  for(int i = 0; i < 3; i++){
    if(s[i] == 'o') cnt += 100;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
s = str(input())

if s[-1] == '2':
    print('hon')
elif s[-1] == '4':
    print('hon')
elif s[-1] == '5':
    print('hon')
elif s[-1] == '7':
    print('hon')
elif s[-1] == '9':
    print('hon')
elif s[-1] == '0':
    print('pon')
elif s[-1] == '1':
    print('pon')
elif s[-1] == '6':
    print('pon')
elif s[-1] == '8':
    print('pon')
else:
    print('bon')


Measured memory_bytes: 9076
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1};
const vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0};
const vi d4y = {0, 1, 0, -1};

//----------------ここからだよ-------------------

int main(){
    int N; cin>>N;
    string S,T; cin>>S>>T;

    string ans;
    rep(i,N){
        ans += S[i];
        ans += T[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384