akhauriyash/Code-Regression huggingface dataset:
n = int(input())
L = [-1]*(n+1)
def fib(i,L):
    if i <= 1:
        return 1
    else:
        if L[i] != -1:
            return L[i]
        else:
            L[i] = fib(i-1,L)+fib(i-2,L)
            return L[i]
        return fib(i-1,L)+fib(i-2,L)
print(fib(n,L))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int main()
{
    ull a, b;
    cin>>a>>b;
    if(a==1 || b==1)
    {
        cout<<1<<endl;
        return 0;
    }
    else if(a==2 || b==2)
    {
        cout<<(a*b)/2<<endl;
        return 0;
    }
    else
    {
        ull c = a*b;
        if(c%2==0)
        {
            cout<<c/2<<endl;
        }
        else
        {
            cout<<c/2+1<<endl;
        }
    }
}

Measured memory_bytes: 256
import java.util.*;
//Long型を使いましょう
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N =  sc.nextInt();
    int K =  sc.nextInt();
    long ans = 0;
    long cnt;
    for(int a= 1;a<=N;a++){
      long ak = a%K;
      long bk = (K-ak)%K;
      long ck = (K-ak)%K;
      if((bk+ck)%K ==0){
       long bc = (K-ak)%K;
       if (bc == 0){
          cnt = 0;
       }else{
          cnt = 1;
       }
       cnt += (N-bc)/K;
       ans += cnt*cnt;
      }
    
    }
    System.out.println(ans);
    
  }
}

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

int main() 
{
	long long n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	if ((a & 1) == (b & 1)) printf("%lld\n", (b - a) >> 1);
	else printf("%lld\n", ((b - a - 1) >> 1) + std::min(n - b + 1, a));
	return 0;
}


Measured memory_bytes: 1736
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();
        char[] ca1 = s1.toUpperCase().toCharArray();
        char[] ca2 = s2.toUpperCase().toCharArray();
        char[] ca3 = s3.toUpperCase().toCharArray();
        
        System.out.println(ca1[0] + ""+ ca2[0] + ca3[0]);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll pancake[5005]={0};
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++) cin>>pancake[i];
  ll ans=17441744;
  for(int j=0;j<=pancake[0];j++){
  //  cout<<j<<": ";
    ll pk[5005]={0};
    for(int i=0;i<n;i++) pk[i]=pancake[i];
    ll kans=j;
    pk[0]-=j;
    for(int i=0;i<n-1;i++){
      pk[i+1]=max(pk[i+1]-pk[i],(ll)0);
      kans+=2*pk[i];
      //cout<<pk[i+1]<<" ";
    }
    kans+=pk[n-1];
    ans=min(ans,kans);
//    cout<<kans<<endl;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3160
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 1005;
const int MM = 1000000007;

int D[MX];
ll F[MX], I[MX], FI[MX];
ll dp[2][MX][MX];
int N;

int main()
{
	F[0] = I[1] = FI[0] = 1;
	for(int i = 2; i < MX; i++) I[i] = (MM - MM/i) * I[MM%i] % MM;
	for(int i = 1; i < MX; i++) F[i] = F[i-1] * i % MM;
	for(int i = 1; i < MX; i++) FI[i] = FI[i-1] * I[i] % MM;
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d", D+i);
	sort(D, D+N);
	if(D[0] >= 2) return !printf("%lld\n", F[N-1] * I[2] % MM);

	ll ans = 0;
	/*
	for(int i = 0; i < 1<<N; i++){
		ll mul = 1;
		int sz = 0, sum = 0, ch = 1;
		for(int j = 0; j < N; j++){
			if(~i&1<<j) continue;
			if(D[j] <= 1 ) ch = 0;
			mul = mul * (D[j]-1) % MM;
			sz++;
			sum += D[j]-2;
		}
		if( !ch || sum <= 0 || sz <= 2) continue;
		mul = mul * F[sz-1] % MM * F[N-sz-1] % MM * sum % MM;
		ans = (ans + mul) % MM;
	} // */
	
	auto S = dp[0], E = dp[1];
	S[0][0] = 1;
	for(int i = 1; i <= N; i++){
		memset(E, 0, sizeof dp[0]);
		E[0][0] = 1;
		for(int j = 1; j <= N; j++){
			if(D[i] >= 2){
				for(int k = 0; k <= 2*N; k++){
					E[j][k] = (S[j][k] + (k >= D[i]? S[j-1][k-D[i]] * (D[i]-1) : 0)) % MM;
				}
			}
			else{
				for(int k = 0; k <= 2*N; k++){
					E[j][k] = S[j][k];
				}
			}
		}
		swap(S, E);
	}
	for(int i = 3; i <= N; i++){
		for(int j = i*2+1; j <= N*2; j++){
			ans = (ans + S[i][j] * F[i-1] % MM * F[N-i-1] % MM * (j-i*2)) % MM;
		}
	}

	for(int i = 0; i < N; i++) ans = ans * FI[D[i]-1] % MM;
	printf("%lld\n", ans * I[2] % MM);
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if ((N / 10)% 111 == 0 || (N % 1000)% 111 == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3540
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

def linearSearch(S, T):
    c = 0
    for i in range(len(T)):
        for j in range(len(S)):
            if S[j] == T[i]:
                c += 1
                break
    return c

r = linearSearch(S, T)
print(r)


Measured memory_bytes: 6552
N,K = map(int,input().split())
d = {}
for i in list(map(int,input().split())):
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1
l = []
for k,v in sorted(d.items(), key=lambda x: x[1]):
    l.append(v)

ans = 0
for i in range(len(l)-K):
    ans += l[i]

print(ans)

Measured memory_bytes: 37400
#include<algorithm>  
#include<iostream>  
#include<cstdio>  
#include<map>  
#include<set>  
using namespace std;  
string s, t;  
set<string> S;  
  
void Work()  
{  
    int lens = s.size();  
    int lent = t.size();  
    for(int i = 0; i < lens; i++)  
    {  
        if(s[i] == '?' || s[i] == t[0])
        {  
            string tmp = s;             
            for(int j = 0; j < i; j++)  
                if(tmp[j] == '?')  
                    tmp[j] ='a';      
            bool can = false;  
            for(int j = 0; j < lent; j++)   
            {  
  
                if(tmp[i+j]!= '?' && tmp[i+j] != t[j])  
                    break;  
                tmp[i+j] = t[j];  
                if(j == lent - 1) can = true;  
            }  
            if(can)  
            {  
                for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';
                S.insert(tmp);  
            }  
        }  
    }  
    if(S.size() == 0) cout << "UNRESTORABLE" << endl;  
    else cout << *S.begin() << endl;  
}  
int main()  
{  
    cin >> s >> t;  
    Work();  
}  

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

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

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
using namespace std;
#define MAX 100000

int main()
{

  int N, K;
  scanf("%d %d", &N, &K);

  int A[N], minNum = MAX + 1;
  vector<int> minIndexs;
  for (int i = 0; i < N; i++)
  {
    scanf("%d", &A[i]);
  }

  int g;
  int a = (N - K) % (K - 1);
  if (a == 0){
    g = (N - K) / (K - 1) + 1;
  } else {
    g = (N - K) / (K - 1) + 2;
  }

  cout << g << endl;

  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
ll x=100;
const double PI = 3.14159265358979323846;
int main(){
  ll a;
  string b;
  cin >> a >> b;
  ll c=a/100;
  ll d=(b[0]-'0')*100+(b[2]-'0')*10+(b[3]-'0');
  cout << a*d/x << endl;
}  


Measured memory_bytes: 3620
import java.util.Scanner;

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

			for (int i=0; i<3; i++) {
				no[i] = sc.nextInt();
			}

			for (int i=0; i<3; i++) {
				int a;
				a = Math.min(no[0], no[1]);
				a = Math.min(a, no[2]);
				for (int j=0; j<3; j++) {
					if (a == no[j]) {
						no[j] = 10001;
						break;
					}
				}
				result[i] = a;
			}

			//結果アウトプット
			for (int i=0; i<3; i++) {
				System.out.print(result[i]);
				if (i < 2) System.out.print(" ");
				else System.out.println("");
			}
		}
	}
}


Measured memory_bytes: 26140
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
ll Gcd(ll a, ll b) {
	long long gcd;
	long long c = max(a, b);
	long long d = min(a, b);
	while (true) {
		if (c % d == 0) {
			gcd = d;
			goto C;
		}
		else {
			c -= d;
			if (c <= d) {
				swap(c, d);
			}
		}
	}
C:return gcd;
}
int main() {
	ll n, a[114514], k, maxx = 0, gcd; cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		maxx = max(maxx, a[i]);
		if (i == 0)gcd = a[0];
		else gcd = Gcd(gcd, a[i]);
	}
	if (k % gcd == 0 && k <= maxx)cout << "POSSIBLE\n";
	else cout << "IMPOSSIBLE\n";
	char c; cin >> c;
}

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

int main() {
	int n,i,count=0;
	scanf("%d",&n);
	int *arr = new int[n];
	for(i=0; i<n; i++){
		scanf("%d",&arr[i]);
	}
	for(i=0; i<n; i++){
		if(i == (arr[arr[i]-1]-1)){
			count++;
		}
	}
	printf("%d",count/2);
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
int count;
int mergeSort(int A[],int left,int right);
int merge(int A[],int left,int mid,int right);
int main(){
  int i,j,m,n,count,A[500000];
  count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  count=mergeSort(A,0,n);
  for(i = 0; i < n-1; i++)
    printf("%d ", A[i]);
  printf("%d",A[n-1]);
  printf("\n");
  printf("%d\n",count);
  return 0;
}


int mergeSort(int A[],int left,int right){
  int mid,i,j,k,con=0;

  if(left+1<right){
  mid=(left+right)/2;
  mergeSort(A,left,mid);
  mergeSort(A,mid,right);
  con=merge(A,left,mid,right);
  }
  return con;
}

int merge(int *A,int left,int mid,int right){
  int i,j,k=0,L[500000],R[500000],n1,n2;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=1000000000;
  R[n2]=1000000000;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
      count++;
    }
    else{
      A[k]=R[j];
      j=j+1;
      count++;
    }
  }
  return count;
}

Measured memory_bytes: 5584
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<class T, class Func = function<T(T,T)>>
class CumulativeSum{
public:
    vector<T>sum;
    T e;
    CumulativeSum(const vector<T>v,T e,const Func& f = [](T a, T b){return a + b;}) : sum(v.size()),e(e){
        copy(v.begin(),v.end(),sum.begin());
        T past = 0;
        for(auto & itr : sum){
            itr = f(itr,past);
            past = itr;
        }
    }
    //[l,r)
    auto query(int l, int r, const Func& f = [](T a,T b){return a - b;}){
        if(r > 0) return f(sum[r - 1],(l == 0 ? e : sum[l - 1]));
        else return e;
        
    }
    auto begin(){
        return sum.begin();
    }
    auto end(){
        return sum.end();
    }
    auto& operator[] (int idx){
        return sum[idx];
    }
};
int main(){
    int N,K; cin >> N >> K;
    vector<Int>v(N);
    vector<Int>u;
    for(auto& e  : v) cin >> e;
    auto csum = CumulativeSum<Int>(v,0LL);
    for(int i = 0; i < N; ++i){
        for(int j = i + 1; j <= N; ++j){
            u.emplace_back(csum.query(i,j));
        }
    }
    vector<bool>in_set(u.size(),true);
    for(int bit = 50; bit >=0;  --bit){
        int cnt = 0;
        for(int i = 0; i < in_set.size(); ++i){
            if(in_set[i] && ((1LL << bit) & u[i])) ++cnt;
        }
        if(cnt >= K){
            for(int i = 0; i < in_set.size(); ++i){
                if(not in_set[i]) continue;
                if((1LL << bit) & u[i]){
                    
                } else {
                    in_set[i] = false;
                }
            }
        }
    }
    vector<Int>res;
    for(int i = 0; i < in_set.size(); ++i){
        if(not in_set[i])continue;
        res.push_back(u[i]);
        if(res.size() == K) break;
    }
    cout << accumulate(res.begin(),res.end(),res.front(),[](Int sum,Int e){
        return (sum & e);
    }) << endl;
}




Measured memory_bytes: 7448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX = 510000;
ll N,count;  ll keta=0;
ll bfs(int p,vector<int> &a){
  if(p>0){
    a[p-1]=3;
  	bfs(p-1,a);
    a[p-1]=5;
  	bfs(p-1,a);
    a[p-1]=7;
    bfs(p-1,a);
    a[p-1]=0;
    bfs(p-1,a);
  }
  else{
  	ll memo=0;
    int cnt3=0,cnt5=0,cnt7=0,flag=0;
    for(int i=keta-1;i>=0;i--){
      if(i>0){if(a[i]!=0&&a[i-1]==0){flag=1;}}
      memo=10*memo+a[i];
      if(a[i]==3)cnt3++;
      if(a[i]==5)cnt5++;
      if(a[i]==7)cnt7++;
    }
    if(memo<=N&&cnt3>0&&cnt5>0&&cnt7>0&&flag==0){::count++;}
    return 0;
  }
}


int main(){
 //Nの桁数書いとく。
  cin>>N;
  ll x=N;
  for(int i=0;i<=11;i++){
  	keta++;x/=10;
    if(x==0){break;}
  }	
  vector<int>A(keta);
  
  bfs(keta,A);
  cout<<::count;
}

Measured memory_bytes: 256
import sys
for line in sys.stdin:
    n = int(line)
    ans = 0
    a=b=c=d=0
    while True:
        if d==10:
            c+=1
            d=0
        if c==10:
            b+=1
            c=0
        if b==10:
            a+=1
            b=0
        if a == 10:
            break
        #print "%d+%d+%d+%d"%(a,b,c,d)
        s = a+b+c+d
        if s == n:
            ans+=1
        d+=1
    print ans

Measured memory_bytes: 6432
#include <iostream>
#include <cstdio>

using namespace std;

int main(void) {

    int N;
    cin >> N;

    int *array = new int[N];
    for (int i = 0; i < N; ++i) {
        cin >> array[i];
    }

    int total = 0;
    for (int i = 0; i < N - 1; ++i) {
        for (int j = N - 1; j >= i + 1; --j) {
            if (array[j - 1] > array[j]) {
                int tmp = array[j - 1];
                array[j - 1] = array[j];
                array[j] = tmp;
                ++total;
            }
        }
    }

    for (int i = 0; i < N - 1; ++i) {
        printf("%d ", array[i]);
    }
    printf("%d\n", array[N - 1]);
    printf("%d\n", total);

    return 0;
}

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

 using namespace std;
 typedef long long ll;

 int main() {
   int N, H, W;

   cin >> N >> H >> W;

   int ans = 0;
   for (int i = 0; i < N; i++) {
     int h, w;
     cin >> h >> w;
     if (h >= H && w >= W) ans++;
   }

   cout << ans << endl;
 }


Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		a: [usize; n],
	}

	let mut v = vec![0; 100001];

	for i in 0..n {
		v[a[i]] += 1;
	}
	let mut max = 0;
	for i in 0..v.len()-2 {
		let sum = v[i] + v[i+1] + v[i+2];
		if max < sum {
			max = sum;
		}
	}
	println!("{}", max);
}



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

using namespace std;

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

int y,m,d;

void input(){
  cin>>y>>m>>d;
}


int days(int y,int m){
  if(y%3==0)return 20;
  if(m%2==1)return 20;
  return 19;
}
int solve(){
  int sum = 1;
  sum += days(y,m)-d;
  m++;
  while(1){
    if(m>10){
      m-=10;
      y++;
    }
    if(y==1000)break;
    sum += days(y,m);
    m++;
  }
  return sum;
}
int main(){
  int n;
  cin>>n;
  rep(i,n){
    input();
    printf("%d\n",solve());
  }
}

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

#define ENDL '\n'
#define io ios_base::sync_with_stdio(false);cin.tie(0);
#define sayy cout<<"YES"<<ENDL;
#define sayn cout<<"NO"<<ENDL;

int gcd(int a, int b){
    if(a == 0)
        return b;
    return gcd(b%a, a);
}

int main(){
    io

    long long int a, b;
    cin >> a >> b;

    cout << a*b / gcd(a,b) << ENDL;

    return 0;
}

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

using namespace std;

namespace {

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }

    struct Edge {
        int from, to, cost;
        Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
    };

    int N, M, L, S, T;
    vector< vector<Edge> > G;
    vector<int> J, E;
    bool input() {
        cin >> N >> M >> L >> S >> T;
        if (N == 0) return false;
        S--;
        G.clear(); G.resize(N);
        for (int i = 0; i < M; i++) {
            int a, b, c; cin >> a >> b >> c;
            a--; b--;
            G[a].push_back(Edge(a, b, c));
            G[b].push_back(Edge(b, a, c));
        }
        J.clear(); J.resize(L);
        E.clear(); E.resize(L);
        for (int i = 0; i < L; i++) {
            cin >> J[i] >> E[i];
            J[i]--;
        }
        return true;
    }

    vector< vector<int> > W;
    const int INF = 1<<28;

    struct State {
        int v, bit, cost;
        State(int v, int bit, int cost) : v(v), bit(bit), cost(cost) {}
    };

    void solve() {
        W.clear(); W.resize(N, vector<int>(N, INF));
        for (int i = 0; i < N; i++) W[i][i] = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < G[i].size(); j++) {
                const Edge& e = G[i][j];
                W[ e.from ][ e.to ] = e.cost;
            }
        }
        for (int k = 0; k < N; k++) {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    W[i][j] = min(W[i][j], W[i][k] + W[k][j]);
                }
            }
        }
        vector< vector<int> > dp(L, vector<int>(1 << L, INF));
        queue<State> Q;
        for (int i = 0; i < L; i++) {
            Q.push(State(i, 1<<i, W[S][J[i]] + E[i]));
            dp[i][1<<i] = W[S][J[i]] + E[i];
        }
        while (!Q.empty()) {
            State s = Q.front(); Q.pop();
            for (int n = 0; n < L; n++) {
                if (s.bit & (1 << n)) continue;
                int nbit = s.bit | (1 << n);
                int ncost = s.cost + W[ J[s.v] ][ J[n] ] + E[n];
                if (ncost + W[J[n]][S] > T) continue;
                if (dp[n][nbit] > ncost) {
                    dp[n][nbit] = ncost;
                    Q.push(State(n, nbit, ncost));
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < L; i++) {
            for (int bit = 0; bit < (1 << L); bit++) {
                if (dp[i][bit] + W[ J[i] ][ S ] <= T) {
                    ans = max(ans, __builtin_popcount(bit));
                }
            }
        }
        cout << ans << endl;
    }
}

int main() {
    while (input()) solve();
    return 0;
}

Measured memory_bytes: 23172
H,W = map(int, input().split())

ans = H*W
if H%3 == 0 or W%3 == 0:
    ans = 0
else:
    h = H//2+min(1, H%2)
    for i in range(1, W):
        ans = min(ans, max(H*i, h*(W-i))-min(H*i, (H-h)*(W-i)))
    w = W//2+min(1, W%2)
    for i in range(1, H):
        ans = min(ans, max(W*i, w*(H-i))-min(W*i, (W-w)*(H-i)))
        
    ans = min(ans, H, W)
            
print(ans)

Measured memory_bytes: 3064
S = input()

if S[0] != 'A':
    print('WA')
    exit()

if S[2:-1].count('C') != 1:
    print('WA')
    exit()

i = S[2:-1].find('C')

if i >= 0:
    S = S[1:2 + i] + S[2 + i + 1:]
    if S.islower():
        print('AC')
        exit()
    else:
        print('WA')
        exit()
else:
    print('WA')

Measured memory_bytes: 3060
extern crate core;

use std::io::{self, Read};
use std::collections::HashMap;

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let list = input.split_whitespace().collect::<Vec<_>>();
    let n = list[0].parse::<usize>().unwrap();
    let s = list.clone().into_iter().skip(1).take(n).collect::<Vec<_>>();
    let m = list[1 + n].parse::<usize>().unwrap();
    let t = list.clone()
        .into_iter()
        .skip(2 + n)
        .take(m)
        .collect::<Vec<_>>();
    let mut map = HashMap::new();
    for x in s {
        let v = map.get(&x).map(|x| x + 1).unwrap_or(1);
        map.insert(x, v);
    }

    for x in t {
        let v = map.get(&x).map(|x| x - 1).unwrap_or(-1);
        map.insert(x, v);
    }

    let mut max = None;
    for (a, b) in map.into_iter() {
        max = Some(match max {
            None => (a, b),
            Some((_, y)) if b > y => (a, b),
            Some((x, y)) => (x, y),
        });
    }

    std::cmp::max(max.unwrap().1, 0).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!(super::run($input.to_string()), $output.to_string());
                }
            )*
        }
    }
}

tests! {
    test1: "3
apple
orange
apple
1
grape" => "2",
    test2: "3
apple
orange
apple
5
apple
apple
apple
apple
apple" => "1",
    test3: "1
voldemort
10
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort
voldemort" => "0",
    test4: "6
red
red
blue
yellow
yellow
red
5
red
red
yellow
green
blue" => "1",
}


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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	bool turn = 0;
	while(min(a, c) > 0) {
		if(!turn)
			c -= b;
		else
			a -= d;
		if(min(a, c) < 1)
			break;
		turn ^= 1;
	}
	cout << (turn ? "No" : "Yes");
}


Measured memory_bytes: 3136
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

double p1(const int* x, const int* y, const int n)
{
	double p1 = 0.0;

	for (int i=0; i<n; i++)
		p1 += fabs(double(x[i] - y[i]));

	return p1;

}

double p2(const int* x, const int* y, const int n)
{
	double p2 = 0.0;
	double p2_app = 0.0;

	for (int i=0; i<n; i++)
		p2_app += pow(fabs(double(x[i] - y[i])), 2);

	p2 = sqrt(p2_app);


	return p2;

}

double p3(const int* x, const int* y, const int n)
{
	double p3 = 0.0;
	double p3_app = 0.0;

	for (int i=0; i<n; i++)
		p3_app += pow(fabs(double(x[i] - y[i])), 3);

	p3 = cbrt(p3_app);

	return p3;

}

double p_inf(const int* x, const int* y, const int n)
{
	double p_inf = 0.0;
	double p_inf_app = 0.0;

	for (int i=0; i<n; i++) {
		p_inf_app = fabs(double(x[i] - y[i]));
		if (p_inf_app > p_inf)
			p_inf = p_inf_app;
	}

	return p_inf;

}

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

	int x[n] = {0};
	int y[n] = {0};

	for (int i=0; i<n; i++)
		cin >> x[i];
	for (int i=0; i<n; i++)
		cin >> y[i];

	cout << fixed << setprecision(6) << p1(x,y,n) << '\n'
		 << fixed << setprecision(6) << p2(x,y,n) << '\n'
		 << fixed << setprecision(6) << p3(x,y,n) << '\n'
		 << fixed << setprecision(6) << p_inf(x,y,n) << '\n';
	
	return 0; 
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
int n,m,flag;
char s[1010][1010],ans[1010][1010];
void solve7() {
	m=7;
	for (int i=1;i<=m;i++)
	for (int j=1;j<=m;j++) s[i][j]='.';
	for (int i=1;i<m;i+=3)
		for (int j=1;j<m;j+=3) {
			s[i][j+1]=s[i][j+2]='a';
			s[i+1][j]=s[i+2][j]='b';
		}
	char ch='c';
	for (int i=1;i<m;i+=2) {
		s[i][m]=ch,s[i+1][m]=ch;
		if (ch=='c') ch='d'; else ch='c';
	}
	ch='c';
	for (int i=1;i<m;i+=2) {
		s[m][i]=ch,s[m][i+1]=ch;
		if (ch=='c') ch='d'; else ch='c';
	}
}
void solve6() {
	m=6;
	for (int i=1;i<=m;i++)
	for (int j=1;j<=m;j++) s[i][j]='.';
	s[1][1]=s[1][2]='a';
	s[1][5]=s[1][6]='b';
	s[2][4]=s[2][5]='c';
	s[4][2]=s[4][3]='d';
	s[5][1]=s[5][2]='e';
	s[6][5]=s[6][6]='f';
	s[2][1]=s[3][1]='g';
	s[1][3]=s[2][3]='h';
	s[3][6]=s[4][6]='i';
	s[3][4]=s[4][4]='j';
	s[5][3]=s[6][3]='k';
	s[5][4]=s[6][4]='l';
}
void solve5() {
	m=5;
	for (int i=1;i<=m;i++)
	for (int j=1;j<=m;j++) s[i][j]='.';
	for (int i=1;i<=m;i+=5)
	for (int j=1;j<=m;j+=5) {
		s[i][j]=s[i][j+1]='a';
		s[i][j+2]=s[i][j+3]='b';
		s[i][j+4]=s[i+1][j+4]='c';
		s[i+1][j]=s[i+2][j]='d';
		s[i+1][j+2]=s[i+1][j+3]='e';
		s[i+2][j+1]=s[i+3][j+1]='f';
		s[i+2][j+4]=s[i+3][j+4]='g';
		s[i+3][j]=s[i+4][j]='i';
		s[i+4][j+1]=s[i+4][j+2]='j';
		s[i+4][j+3]=s[i+4][j+4]='h';
	}
}
void solve4() {
	m=4;
	for (int i=1;i<=m;i++)
	for (int j=1;j<=m;j++) s[i][j]='.';
	s[1][1]=s[1][2]='a';
	s[1][3]=s[2][3]='b';
	s[1][4]=s[2][4]='c';
	s[2][1]=s[2][2]='d';
	s[3][1]=s[4][1]='e';
	s[3][2]=s[4][2]='f';
	s[3][3]=s[3][4]='g';
	s[4][3]=s[4][4]='h';
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	if (n==2) { printf("-1\n"); return 0; }
	for (int i=1;i<=n;i++)
	for (int j=1;j<=n;j++) ans[i][j]='.';
	if (n%3==0) {
		for (int i=1;i<=n;i+=3)
		for (int j=1;j<=n;j+=3) {
			ans[i][j+1]=ans[i][j+2]='a';
			ans[i+1][j]=ans[i+2][j]='b';
		}
	} else {
		int t=n/4-1;
		solve4();
		for (int i=1;i<=t*4;i+=4) {
			for (int x=1;x<=4;x++)
			for (int y=1;y<=4;y++)
				ans[i+x-1][i+y-1]=s[x][y];
		}
		t=n-t*4;
		if (t==4) solve4();
		else if (t==5) solve5();
		else if (t==6) solve6();
		else solve7();
		int i=1+(n/4-1)*4;
		for (int x=1;x<=t;x++)
		for (int y=1;y<=t;y++)
			ans[i+x-1][i+y-1]=s[x][y];
	}
	for (int i=1;i<=n;i++)
		printf("%s\n",ans[i]+1);
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 2176
#include <stdio.h>
#include <iostream>
#include <cmath>
#include<vector>
#include <ios>
#include <iomanip>
#include<algorithm>
using namespace std;

int main() {
	int N;
	cin >> N;
	int *A = new int[N];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N - 1; i++)cout << A[i] << " ";
	cout << A[N - 1] << endl;
	for (int i = 1; i < N ; i++) {
		int v = A[i];
		int j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		for (int i = 0; i < N - 1; i++)cout << A[i] << " ";
		cout << A[N - 1] << endl;
	}
}



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

int main(int argc, const char * argv[])
{
    int data[5];
    for (int i = 0; i < 5; i++) {
        cin >> data[i];
    }
    sort(&data[0],&data[5]);
    for (int i = 4; 0 <= i; i--) {
        cout << data[i];
        (i != 0)? cout << " ": cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1176
N,Y = map(int,input().split())
Y = Y/1000
torf = False
for numoft in range(N+1):
    for numof5t in range(N-numoft+1):
        numof10t = (N)-(numoft+numof5t)
        if Y == numoft + 5*numof5t + 10*numof10t:
            print(numof10t,numof5t,numoft)
            exit()
print("-1 -1 -1")

Measured memory_bytes: 3316
N = map(int, raw_input().split())

A=N[0]
B=N[1]
C=N[2]

Answerlist= [0 for i in range(3)]
Answerlist[0]=abs(A-B)
Answerlist[1]=abs(B-C)
Answerlist[2]=abs(C-A)

print(max(Answerlist))

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

public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long ans = N - 1;
		for (long i = 2; i * i <= N; ++i) {
			if (N % i != 0)
				continue;
			ans = Math.min(ans, (i - 1) + (N / i - 1));
		}
		System.out.println(ans);
	}

	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 21844
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////



int main() {
	string s;
	rd(s);
	ll ans = s.length() / 2;
	repi(i, 0, s.length()) if (s[i] == 'p') ans--;
	wrln(ans);
	return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int mini = 1000000;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      if (a <= mini) {
        mini = a;
        ans++;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 63712
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();
		if(a == b && b == c){
			System.out.println(1);
		}else if(a == b || b == c || a == c){
			System.out.println(2);
		}else{
			System.out.println(3);
		}
	}
}


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

using namespace std;

string s;

int main(int argc, char const *argv[]){
	
	cin >> s;

	for(int i=0; i<4; i++) {
		printf("%c", s[i]);
	}
	printf(" ");
	for(int i=4; i<12; i++) {
		printf("%c", s[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	double ax,ay,bx,by,cx,cy,ix,iy;
	double abx,aby,acx,acy,aix,aiy;
	double aacx,aaix,aacy,aaiy,s,t;
	int f;
	for(;;){
		f=0;
		if(scanf("%lf %lf",&ax,&ay)==EOF){break;}
		scanf("%lf %lf",&bx,&by);
		scanf("%lf %lf",&cx,&cy);
		scanf("%lf %lf",&ix,&iy);
		abx=bx-ax;
		acx=cx-ax;
		aix=ix-ax;
		aby=by-ay;
		acy=cy-ay;
		aiy=iy-ay;
		aacx=acx*aby;
		aaix=aix*aby;
		aacy=acy*abx;
		aaiy=aiy*abx;
		s=(aaiy-aaix)/(aacy-aacx);
		if(abx!=0){t=(aix-s*acx)/abx;}
		else{t=(aiy-s*acy)/aby;}
		if(s>0 && t>0 && s+t<1){f=1;}
		if(f==0){printf("NO\n");}
		else{printf("YES\n");}
	}
	return 0;
}

Measured memory_bytes: 0
/*
 * sto Qingyu orz
 * 感谢真神sqy无私的教诲。膜时队者处处阿克，只因大师sqy在他背后。不膜大师者违背了真神的旨意，真神必将降下天谴,
 * 使其天天爆零
 * 我不由自主地膜拜真神sqy。
 * Author: RainAir
 * Time: 2019-10-16 16:45:44
 */
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define fi first
#define se second
#define U unsigned
#define P std::pair
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 100000+5;
int n,a[MAXN],k;

int main(){
    scanf("%d%d",&n,&k);
    FOR(i,1,n) scanf("%d",a+i);
    std::sort(a+1,a+n+1);
    int ans = 1e9;
    FOR(l,1,n){
        int r = l+k-1;
        if(r > n) break;
        int gx = 0;
        if(a[r] <= 0) gx = std::abs(a[l]);
        else if(a[l] >= 0) gx = a[r];
        else gx = std::min(2*std::abs(a[l])+a[r],std::abs(a[l])+2*a[r]);
        ans = std::min(ans,gx);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
    int i, j, n, m, cn;
    char c, s[5] = { 'S','H','C','D','\0' };
    static int card[4][13];
    scanf("%d\n", &n);

    for (i = 0; i < n; i++) {
        scanf("%c %d\n", &c, &m);
        for (j = 0; j < 4; j++)
            if (s[j] == c)
                card[j][m - 1] = 1;
    }

    for (i = 0; i < 4; i++)
        for (j = 0; j < 13; j++)
            if (card[i][j] == 0)
                printf("%c %d\n", s[i], j + 1);

    return 0;
}


Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	string s;
	cin >> s;
	if((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
S = input()

def search(string, flg, sum):
    if flg >= len(string):
        return sum + int(string)
    before = search(string[flg:], 1, sum + int(string[:flg]))
    after = search(string, flg + 1, sum)
    sum = before + after
    return sum

print(search(S, 1, 0))

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

using namespace std;

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

	int a, b, c;
	vector<vector<int> > DP(N + 1, vector<int> (3));

	for(int index = 1; index <= N; index++){
		cin >> a >> b >> c;
		DP[index][0] = max(DP[index - 1][1], DP[index - 1][2]) + a;
		DP[index][1] = max(DP[index - 1][0], DP[index - 1][2]) + b;
		DP[index][2] = max(DP[index - 1][0], DP[index - 1][1]) + c;
	}
	
	cout << max(DP[N][0], max(DP[N][1], DP[N][2]));
	return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N;
  cin>>N;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  sort(ALL(A));
  for(int ans=A[1];1<=ans;ans--){
    int count=0;
    bool flag=1;
    rep(i,0,N){
      if(A[i]%ans!=0){
        count++;
        if(count>=2){
          flag=0;
          break;
          }
        }
      }
    if(flag){
      cout<<ans<<endl;
      break;
      }
    }
  }

Measured memory_bytes: 1024
s = int(input())

def f(a):
  if a%2 == 0:
    return a/2
  else:
    return 3*a+1

array = []
for i in range(1,1000000):
  if i == 1:
    a_new = s
  else:
    a_new = f(array[-1])
  if a_new in array:
    print(i)
    break
  array.append(a_new)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=3e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=998244353;
const ll INF=0x3f3f3f3f;

ll fac[MAXn],inv[MAXn];
ll add(ll a,ll b){
    ll ret = a+b;
    if (ret >= MOD) ret -= MOD;
    return ret;
}
ll mul(ll a,ll b){
    return a*b%MOD;
}
ll inverse(ll a){
    if (a == 1) return a;
    return mul((MOD - MOD/a),inverse(MOD%a));
}
ll C(ll a,ll b){
    return mul(mul(fac[a],inv[b]),inv[a-b]);
}
int main(){
    IOS();
    ll n,a,b,k;
    cin >> n >> a >> b >> k;
    fac[0] = inv[0] = 1;
    REP1 (i,MAXn-1) {
        fac[i] = mul(fac[i-1],i);
        inv[i] = inverse(fac[i]);
    }
    ll ans = 0;
    REP (i,MAXn*3) {
        ll tmp = k - i * a;
        if (tmp < 0 || i > n) break;
        if (tmp % b != 0) continue;
        ll j = tmp / b;
        if (j > n) continue;
        ans = add(ans,mul(C(n,i),C(n,j)));
    }
    cout << ans << endl;
}


Measured memory_bytes: 8296
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int N;
    cin >> N ;
    
    vector<int> a(N);
    
    for (int i=0; i<N; i++) {
        cin >> a.at(i);
    }
    
    int count=0;
    
    int p=1;
    

    for (int i=0; i<N; i++) {
        if( p != 2 ){
            count++;
            p=a.at(p-1);
        }
        else{
            cout <<endl << count <<endl;
            break;
        }
    }
    
    if( p != 2){
        cout <<endl << -1 <<endl;
    }
}



Measured memory_bytes: 640
package main
import "fmt"
func main() {
  var t string
  var n,w,s,e bool
  fmt.Scan(&t)
  set := make(map[string]struct{})
  for i:=0;i<len(t);i++ {
    set[t[i:i+1]] = struct{}{}
  }
  _,n = set["N"]
  _,w = set["W"]
  _,s = set["S"]
  _,e = set["E"]
  if n == s && w == e {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,M,total=0;
    cin>>N>>M;
    
    ll n=min(N,M/2);
    total+=n;
    N-=n;
    M-=2*n;
    total+=M/4;
    cout1(total)
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
using namespace std;

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int k; cin >> k;
	int o = 0, e = 0;
	for (int i = 1; i <= k; i++) {
		if (i & 1) o++;
		else e++;
	}
	cout << o * e << '\n';
}

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

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    int x0 = (f + 99) / 100 + 1;
    int y0 = f + 1;
    vector<int> x(x0 + 1), y(y0 + 1);
    x[0] = 1;
    for (int i = 0; i <= x0; i++) {
        if (i >= a && x[i - a]) x[i] = 1;
        if (i >= b && x[i - b]) x[i] = 1;
    }
    y[0] = 1;
    for (int i = 0; i <= y0; i++) {
        if (i >= c && y[i - c]) y[i] = 1;
        if (i >= d && y[i - d]) y[i] = 1;
    }

    int r0, r1;
    double m = -1.0;
    for (int i = 1; i <= x0; i++) {
        for (int j = 0; j <= y0; j++) {
            if (x[i] && y[j]) {
                double t = (double)j / (i * 100 + j);
                if (t > m && t - 1e-9 <= (double)e / (100 + e) && i * 100 + j <= f) {
                    //cout << t - 1e-9 << ' ' << (double)e / (100 + e) << endl;
                    r0 = i;
                    r1 = j;
                    m = t;
                }
            }
        }
    }

    cout << r0 * 100 + r1 << ' ' << r1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	int n;
	cin>>n;
	vector<int> one,two;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(i%2){
			one.push_back(a);
		}
		else{
			two.push_back(a);
		}
	}
	vector<int> temp;
	if(n%2==0){
		temp=two;
		two=one;
		one=temp;
	}
	if(n==1){
		cout<<two[0]<<endl;
		return 0;
	}
	if(two.size()>0){
		for(int i=two.size()-1;i>=0;i--){
			cout<<two[i]<<" ";
		}
	}
	if(one.size()>0){
		for(int i=0;i<one.size()-1;i++){
			cout<<one[i]<<" ";
		}
		cout<<one[one.size()-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3572
S = gets.chomp.chars
N = S.size

nums = Array.new(N + 1, 0)

(0).upto(N - 1) do |idx|
  if S[idx] == '<'
    nums[idx + 1] = [nums[idx + 1], nums[idx] + 1].max
  end
end

(N - 1).downto(0) do |idx|
  if S[idx] == '>'
    nums[idx] = [nums[idx],  nums[idx + 1] + 1].max
  end
end

puts nums.inject(:+)


Measured memory_bytes: 49412
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;
int main(){
	fastio;
	ll n;
	cin>>n;
	string s,t;
	cin>>s>>t;

	string res = "";
	for(ll i=0;i<n;i++){
		res += s[i];
		res += t[i];
	}
	cout<<res<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
   int hour1, minute1;
   cin>>hour1>>minute1;
   int hour2, minute2,k;
   cin>>hour2>>minute2>>k;
//   int diff_hour, diff_minute;
//
//
//   if(minute1 > minute2) {
//      hour2--;
//      minute1 += 60;
//      diff_minute = minute1 - minute2;
//   }
//   else diff_minute = minute2 - minute1;
//
//   diff_hour = hour2 - hour1;
//
//   cout<< diff_hour *60 + diff_minute -k;
    int start = (hour1*60)+minute1;
    int endd = (hour2*60)+minute2;
    int twoForu = 24*60;
    int Count = 0;
    int ans = 0;
    //cout << start << " " << endd << endl;
    if(endd < start)
    {
        ans = twoForu-start;
        ans += endd;
    }
    else
    {
        ans = endd-start;
    }
    cout << ans-k << endl;
   return 0;
}


Measured memory_bytes: 3588
object Main extends App{
    // Your code here!
    import scala.math.sqrt
    import scala.io.Source.stdin
    def is_prime(x: Int): Boolean = {
        x match {
            case 1 => return false
            case 2 | 3 => return true
            case _ => false
        }
        val last: Int = math.sqrt(x).toInt
        for(i <- 2 to last) {
            x%i match {
                case 0 => return false
                case _ => true
            }
        }
        true
    }
    def prime_num(nums: Int*): Int = {
        nums.filter(is_prime).length
    }
    val input = {for(line <- io.Source.stdin.getLines()) yield {
        line.toInt
    }}.toSeq
    val inputSeq = input.tail
    println(prime_num(inputSeq: _*))
}



Measured memory_bytes: 124020
#include<stdio.h>
#include<stdlib.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

#define INF 1e18

//配列sの中で、keyより初めて大きくなる添字を出力
int binary_search_right(long* array,int min, int max, long key){
    if(min<max){
        int mid=min+(max-min)/2;

        if(key<array[mid]) return binary_search_right(array,min,mid,key);
        else if(key>array[mid]) return binary_search_right(array,mid+1,max,key);
    }
    if(key>array[min]) return min+1;
    return min;
}

int main(void){
    int A,B,Q;
    scanf("%d%d%d",&A,&B,&Q);

    //s[1]~s[A]に格納する
    long* s;
    NEW(s,A+2);
    for(int i=1;i<=A;i++){
        scanf("%ld",&s[i]);
    }
    s[0]=-INF;
    s[A+1]=INF;
    //t[1]~t[B]に格納する
    long* t;
    NEW(t,B+2);
    for(int i=1;i<=B;i++){
        scanf("%ld",&t[i]);
    }
    t[0]=-INF;
    t[B+1]=INF;

    //x[0]~x[Q-1]に格納する
    long* x;
    NEW(x,Q);
    for(int i=0;i<Q;i++){
        scanf("%ld",&x[i]);
    }

    for(int i=0;i<Q;i++){
        long b=binary_search_right(s,0,A+1,x[i]);
        long d=binary_search_right(t,0,B+1,x[i]);

        long ans=INF;
        long tmp;
        for(int j=b-1;j<=b;j++){
            for(int k=d-1;k<=d;k++){
                //printf("x = %ld s = %ld t = %ld ",x[i], s[j],t[k]);
                tmp=labs(s[j]-x[i])+labs(t[k]-s[j]);
                ans=MIN(ans,tmp);

                tmp=labs(t[k]-x[i])+labs(s[j]-t[k]);
                ans=MIN(ans,tmp);
                //printf("→ %ld\n",ans);
            }
        }
        printf("%ld\n",ans);
    }

    return 0;
}

Measured memory_bytes: 3584
N,M = map(int,input().split())

L2R = {i:[] for i in range(N+1)}
R2L = {i:[] for i in range(N+1)}

for _ in range(M):
    L,R,D=map(int,input().split())
    L2R[L].append((R,D,L))
    R2L[R].append((L,-D,R))

x = [0 for i in range(N+1)]
f = [True for i in range(N+1)]

for i in range(1,N+1):
    if f[i]:
        f[i]=False
        x[i]=i
        que=L2R[i]+R2L[i]
        while len(que)>0:
            tmp = []
            for end,d,begin in que:
                if f[end]:
                    f[end]=False
                    x[end]=d+x[begin]
                    tmp+=L2R[end]+R2L[end]
                elif x[end]!=d+x[begin]:
                    print('No')
                    exit()
            que=tmp
print('Yes')


Measured memory_bytes: 136664