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

typedef long long ll;
int N, W;
int w, w0, v;
vector<vector<int> > vv(4);

ll value(int I, int J, int K, int L) {
  ll result = 0;
  ll weight = 0;
  for (int i = 0; i < I; i++) {
    result += -vv[0][i];
    weight += w0;
  }
  for (int j = 0; j < J; j++) {
    result += -vv[1][j];
    weight += w0 + 1;
  }
  for (int k = 0; k < K; k++) {
    result += -vv[2][k];
    weight += w0 + 2;
  }
  for (int l = 0; l < L; l++) {
    result += -vv[3][l];
    weight += w0 + 3;
  }
  if (weight > W) return 0;
  return result;
}

int main() {
  // 入力
  cin >> N >> W;
  cin >> w0 >> v;
  vv[0].push_back(-v);
  for (int i = 1; i < N; i++) {
    cin >> w >> v;
    vv[w - w0].push_back(-v);
  }
  for (int i = 0; i < 4; i++) {
    sort(vv[i].begin(), vv[i].end());
  }
  ll ans = 0;
  for (int i = 0; i <= vv[0].size(); i++) {
    for (int j = 0; j <= vv[1].size(); j++) {
      for (int k = 0; k <= vv[2].size(); k++) {
        for (int l = 0; l <= vv[3].size(); l++) {
          ans = max(ans, value(i, j, k, l));
        }
      }
    }
  }
  // 解答
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()

if S.startswith("A") and S[2:-1].count("C") == 1 and S[1].islower() and S[-1].islower():
    deleted_S = S[2:-1].replace("C", "")
    if len(deleted_S) == 0:
        print("AC")
    elif deleted_S.islower():
        print("AC")
    else:
        print("WA")
else:
    print("WA")

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<class T>
T read() {
    T x{};
    cin >> x;
    return x;
}

template<class T>
vector<T> read(int N){
    vector<T> x(N);
    for(int i = 0; i < N; ++i){
        cin >> x[i];
    }
    return x;
}

template<class T>
void write(const T &x){ cout << x << endl; }

int main(){
    auto S = read<string>();
    
    set<char> odd = {'R', 'U', 'D' };
    set<char> even = {'L', 'U', 'D' };
    
    for(ull i = 1; i <= S.size(); ++i){
        if(i % 2 == 0 && even.end() == even.find(S[i-1])){
            write("No");
            return 0;
        }
        if(i % 2 == 1 && odd.end() == odd.find(S[i-1])){
            write("No");
            return 0;
        }
    }
    
    write("Yes");
}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

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

// 左, 下, 右, 上
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX_H 500
#define MAX_W 500
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int H, W;
int a[MAX_H][MAX_W];
int N = 0;
tuple<int, int, int, int> ops[MAX_H * MAX_W + 1];

void op(int h, int w, int d)
{
  int nw = w + dx[d], nh = h + dy[d];
  // 範囲外なら continue
  if (nw < 0 || nw >= W) return;
  if (nh < 0 || nh >= H) return;
  // 奇数なら移動させる
  // if (a[h][w] % 2 == 1) {
  // 交換する
  a[h][w]--, a[nh][nw]++;
  // y1, x1, y'1 x'1
  ops[N] = make_tuple(h + 1, w + 1, nh + 1, nw + 1);
  N++;

  // printf("%d %d %d %d\n", h + 1, w + 1, nh + 1, nw + 1);
  // cout << "=====" << endl;
  // for (int i = 0; i < H; i++) {
  //   for (int j = 0; j < W; j++) {
  //     cout << a[i][j] << " ";
  //   }
  //   cout << endl;
  // }
}

int main(void)
{
  cin >> H >> W;
  REP(i, H) REP(j, W) cin >> a[i][j];

  // 0   1   2   3
  // 左, 下, 右, 上
  // const int dx[4] = {-1, 0, 1, 0};
  // const int dy[4] = {0, -1, 0, 1};
  for (int i = 0; i < H; i++) {
    if (i % 2 == 0) {
      for (int j = 0; j < W; j++) {
        // 奇数を探して操作する
        if (a[i][j] % 2 == 0) continue;
        int d = 2;
        // 一番端っこなら下向きに送る
        if (j == W - 1) d = 3;
        op(i, j, d);
      }
    }
    else {
      for (int j = W - 1; j >= 0; j--) {
        // 奇数を探して操作する
        if (a[i][j] % 2 == 0) continue;
        int d = 0;
        if (j == 0) d = 3;
        op(i, j, d);
      }
    }
  }

  cout << N << endl;
  for (int i = 0; i < N; i++) {
    cout << get<0>(ops[i]) << " " << get<1>(ops[i]) << " " << get<2>(ops[i])
         << " " << get<3>(ops[i]) << endl;
  }
  return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"
#define cout(x) cout << (x) << endl
#define MAX 100001
using namespace std;

int printAns(int n) {
  int ans=0;
  while(n != 0) {
    ans += (n%10);
    n /= 10;
  }
  return ans;
}
int main() {
  int n,a,b;
  cin >> n >> a >> b;
  int count=0, max=0;
  for(int i=1;i<=n;i++) {
    int ans=printAns(i);
    if(a<=ans && ans<=b)
      max += i;
  }
  cout << max << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int M,N,a[20]={0},s;
  cin >> M >> N;
  for(int i=0;i<M;i++){
    for(int j=0;j<N;j++){
      cin >> s;
      if(s==1){
	a[i]++;
      }
    }
  }
  int max=0;
  for(int i=0;i<M;i++){
    if(a[i]>max)max=a[i];
  }
  cout << max << endl;
}

Measured memory_bytes: 1164
#include <iostream>
using namespace std;
int main(){
	string s;
	while(cin >> s){
		bool a[10][10] = {0};
		for(int j = 1; j <= 8; j++){
			a[1][j] = s[j-1] - 48;
		}
		for(int i = 2; i <= 8; i++){
			cin >> s;
			for(int j = 1; j <= 8; j++){
				a[i][j] = s[j-1] - 48;
			}
		}
		bool f = true;
		for(int i = 1; i <= 8 && f; i++){
			for(int j = 1; j <= 8; j++){
				if(a[i][j]){
					if(a[i][j+1] && a[i+1][j] && a[i+1][j+1]) cout << "A" << endl;
					else if(a[i+1][j] && a[i+2][j] && a[i+3][j]) cout << "B" << endl;
					else if(a[i][j+1] && a[i][j+2] && a[i][j+3]) cout << "C" << endl;
					else if(a[i+1][j-1] && a[i+1][j] && a[i+2][j-1]) cout << "D" << endl;
					else if(a[i][j+1] && a[i+1][j+1] && a[i+1][j+2]) cout << "E" << endl;
					else if(a[i+1][j] && a[i+1][j+1] && a[i+2][j+1]) cout << "F" << endl;
					else if(a[i][j+1] && a[i+1][j-1] && a[i+1][j]) cout << "G" << endl;
					f = false;
					break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1176
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

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

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

const ll MOD = 1000000007;

int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
	return 0;
}

Measured memory_bytes: 3636
/**
 * Dynamic Programming - Fibonacci Number
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

public class Main {

	static int[] fibonacci = new int[45];

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		fibonacci[0] = 1;
		fibonacci[1] = 1;
		for (int i = 2; i < fibonacci.length; i++) {
			fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2];
		}
		int n = parseInt(br.readLine());
		System.out.println(fibonacci[n]);
	} //end main
}

Measured memory_bytes: 17020
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    ll hlimit = 3 * N / 4;
    for(ll h=1; h <= hlimit; h++) {
        ll nlimit;
        if((4 * h - N) > 0) nlimit = (2 * N * h) / (4 * h - N);
        else nlimit = 3500;
        for(ll n=h; n <= nlimit; n++) {
            ll k = 4*h*n - N*n - h*N;
            if(k > 0) {
                ll l = N*h*n;
                if(l % k == 0) {
                    cout << h << " " << n << " " << l/k << endl;
                    return 0;
                }
            }
        }
    }
}

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

int n,a[3];

int main(){
    scanf("%d",&n);
    while(n--){
        for(int i=0;i<3;i++)scanf("%d",&a[i]);
        sort(a,a+3);
        if(a[2]*a[2]==a[0]*a[0]+a[1]*a[1])puts("YES");
        else puts("NO");
    }
    return 0;
}

Measured memory_bytes: 1180
#include <stdio.h>
#include <limits.h>
 
#define MAX 5000
 
int main(void) {
    int n, d[MAX];
    int sum, max;
    int i, j;
 
    while (scanf("%d", &n) != EOF) {
        if (n == 0) break;
 
        for (i = 0; i < n; i++)
            scanf("%d", &d[i]);
 
        max = INT_MIN;
        for (i = 0; i < n; i++) {
            sum = 0;
            for (j = i; j < n; j++) {
                sum += d[j];
                if (max < sum) max = sum;
            }
        }
        printf("%d\n", max);
    }
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int ans = 0;
int dfs(ll x,int n){
    if(x > n) return 0;
    int count[3];
    REP(i,3) count[i] = 0;
    
    string s = to_string(x);
    if(s.find("3") != -1 && s.find("5") != -1 && s.find("7") != -1) ans++;

    dfs(x * 10 + 3,n);
    dfs(x * 10 + 5,n);
    dfs(x * 10 + 7,n);

    return 0;
}
int main(){
    int N;
    cin >> N;
    dfs(0,N);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

typedef long long ll;

#define pb push_back
#define mp make_pair
#define x first
#define y second

const ll inf=2147483647;

//

ll read()
{
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}

void print(ll x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}

const int P=1e9+7;
int n,m,K,U;
ll f[1<<19],ans;
bool vis[20][20],pos[20][20];

#define lowbit(x) ((x)&-(x))

int main(){
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1,a,b,c;i<=K;i++)scanf("%d%d%d",&a,&b,&c),a--,b--,vis[a][b]=true,pos[a][b]=c;
	U=1<<--n,f[0]=1;
	for(int p=0;p<m;p++){
		for(int i=0;i<n;i++){
			if(!vis[p][i]||pos[p][i])
				for(int j=0,l=1<<i;j<U;j+=l<<1)for(int k=0;k<l;k++)if(f[j+k])f[j+k+l-lowbit(j)]+=f[j+k];
			if(vis[p][i])
				for(int j=0,l=1<<i,k=pos[p][i]?0:l;j<U;j+=l<<1)memset(f+j+k,0,l<<3);
		}
		for(int i=0;i<U;i++)if(f[i]>=P)f[i]%=P;
	}
	for(int i=0;i<U;i++)ans+=f[i];
	printf("%lld\n",ans%P);
	return 0;
}


Measured memory_bytes: 4352
N = int(input())
S = input()

def rot(s,n):
  ALP = ["A","B","C","D","E","F","G","H","I","J","K","L","M",
         "N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
  S = []
  for i in range (len(s)):
    S.append(s[i])
  for i in range (len(S)):
    for j in range (len(ALP)):
      if S[i] == ALP[j]:
        S[i] = ALP[(j+n)%26]
        break
  res = S[0]
  for i in range(1, len(S)):
    res+=S[i]
  return res
            
print(rot(S,N))

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


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl			'\n'

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

vector<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vector<int> primes;

	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.pb(i);
	}
	return primes;
}
set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}



// Graph------------------------------------------------------------------------
int32_t main()
{
	FIO;
	// c_p_c();
	// --------------------------------------------------
// Never GIVE UP !!!!

	int x;
	cin >> x;

	if (360 % x == 0)
		cout << 360 / x << endl;
	else
	{
		int i = 1;
		while ((i * x) % 360 != 0)
		{
			i++;
		}
		cout << i << endl;
	}


}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979

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; }


bool my_cp(pair<int, int> a, pair<int, int> b){
  return (double)b.first / (double)(b.second+1) < (double)a.first / (double)(a.second+1);
}


ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}

int N;

void dfs(string s, char m, int N){
  size_t len = s.length();
  if(len == N){
    cout << s << endl;
  }else{
    for(char c = 'a'; c <= m; c++){
      dfs(s + c, ((c == m)? (m + 1) : m), N);
    }
  }
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}





// substr(start, len)

int main(){
  int S, W;

  cin >> S >> W;

  string ans;

  if(S > W){
    ans = "safe";
  }else{
    ans ="unsafe";
  }

  cout << ans << endl;

  
  
  // cout << setprecision(8) << ans << endl;  // For double
  // CHECK if it's possible to overflow!!
}

Measured memory_bytes: 3624
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    string s;
    cin >> s;

    if (s.size()<6) cout << "No";
    else if((s.at(2)==s.at(3))&&(s.at(4)==s.at(5))) cout << "Yes";
    else cout << "No";
}

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


int primeFactors(long long int n)  
{  
	map<long long int,int > pr;
	long long int x=n;
    while (n % 2 == 0)  
    {   
    	if(pr.count(2)==0)
    		pr[2]=1;
    	else
    		pr[2]++;
        n = n/2;  
    }  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        while (n % i == 0)  
        {  
        	if(pr.count(i)==0)
    			pr[i]=1;
	    	else
	    		pr[i]++;
            n = n/i;  
        } 
	}  
    if (n > 2)
    {
    	if(pr.count(n)==0)
    		pr[n]=1;
    	else
    		pr[n]++; 
   	}
   	/*for(auto a : pr)
   		cout<< a.first << " "<< a.second<<"\n";
	*/
   	priority_queue<long long int> pq;
   	long long int cnt=0;
   	for(auto a : pr)
   	{
   		for(int i=1;i<=a.second;i++)
   		{
   			pq.push(-1*(long long int)pow(a.first,i));
   		}
   	}
   	while(x>1 && !pq.empty())
   	{
   		long long int val = -1*pq.top();
   		if(x%val==0){
   			x/=val;
   			cnt++;
   		}
   		pq.pop();
   		
   	}
    return cnt;
    
}  

int main() 
{ 
	long long int n;
	cin >> n;
	cout << primeFactors(n) ; 
	return 0; 
} 


Measured memory_bytes: 4108
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long int lli;
lli n, a, b;

bool check(vector<lli> &h, lli mid){
  lli damege = mid*b;
  for (int i = 0; i < n; i++) {
    if(h[i] <= damege)continue;
    mid -= (int)ceil((h[i] - (double)damege)/(a - b));
  }
  return mid >= 0;
}

int solve(vector<lli> &h){
  lli l = 0, r = 1e18, mid = (l + r)/2;
  while(r - l > 1){
    if(check(h, mid)){
      r = mid;
    }else{
      l = mid;
    }
    mid = (l + r)/2;
  }
  return r;
}

int main(){
  std::cin >> n >> a >> b;
  vector<lli> h(n);
  for (int i = 0; i < n; i++) {
    std::cin >> h[i];
  }
  std::cout << solve(h) << std::endl;
  return 0;
}


Measured memory_bytes: 1024
<?php

$input[] = explode(" ",trim(fgets(STDIN)));
$input[] = explode(" ",trim(fgets(STDIN)));
$input[] = explode(" ",trim(fgets(STDIN)));



$s=(string)$input[0][0];
$t=(string)$input[0][1];

$a=(int)$input[1][0];
$b=(int)$input[1][1];

$u=(string)$input[2][0];

if($s===$u){
    $a--;
}
if($t===$u){
    $b--;
}

print $a." ".$b;



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


int main()
{
	int a[5],i,val;
	val=0;
	for(i=0;i<5;i++)
	{
		cin>>a[i];	
		if(a[i]==0)
			val=i+1;
	}
	cout<<val;
	
	return 0;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

const int N = 6005;

int n,P;
int f[N][N*2];

int Plus(int x,int y) { return x+y>=P ? x+y-P : x+y; }
int Pow_mod(int x,int y){
	int ret=1;
	while(y){
		if(y&1) ret=1ll*ret*x%P;
		x=1ll*x*x%P;
		y>>=1;
	}
	return ret;
}

int main()
{
	scanf("%d%d",&n,&P);
	n*=3;
	
	f[0][n]=1; /**/
	for(int i=2;i<=n;i++) f[0][n]=1ll*f[0][n]*i%P;
	for(int i=1;i<=n;i++){
		int t=Pow_mod(i,P-2);
		for(int j=0;j<=n*2;j++){
			f[i][j]=0;
			if(j) f[i][j]=Plus(f[i][j],f[i-1][j-1]);
			if(i>=3) f[i][j]=Plus(f[i][j],f[i-3][j]);
			if(j<n*2 && i>=2) f[i][j]=Plus(f[i][j],f[i-2][j+1]);
			f[i][j]=1ll*f[i][j]*t%P;
		}
	}
	
	int ans=0;
	for(int i=n;i<=n*2;i++) ans=Plus(ans,f[n][i]);
	printf("%d\n",ans);
	
	return 0;
} 

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

using i64 = int64_t;

i64 dp[30][80] = {0};

map<i64, i64> fact_prime_factor(i64 m) {
    map<i64, i64> res;
    for(i64 j=1;j<=m;++j){
        i64 n = j;
        for (i64 i = 2; i * i <= n; i++) {
            while (n % i == 0) {
                res[i]++;
                n /= i;
            }
        }
        if (n != 1)
            res[n] += 1;
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    auto mp = fact_prime_factor(n);
    vector<i64> v;
    for(auto e: mp)v.push_back(e.second);

    dp[0][1] = 1;
    for(int i=0;i<(int)v.size();++i){
        for(int j=1;j<=75;++j){
            for(int k=1;k<=v[i]+1;++k){
                if(j*k > 75)break;
                dp[i+1][j*k] += dp[i][j];
            }
        }
    }

    cout << dp[(int)v.size()][75] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  long a, b;  scanf("%ld%ld", &a, &b);
  long ans = 0;
  long two = 1;
  while((b/a) >= two){
    ans++;
    two = two << 1;
  }
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

double max(double a, double b){ return a > b ? a : b; }

void bubbleSort(int n, int S[]){
  int i, j, t;
  for ( i = 0; i < n; i++ )
    for ( j = n-2; j >= i; j-- )
      if ( S[j] > S[j+1] ) {
	t = S[j]; S[j] = S[j+1]; S[j+1] = t;
      }
}

int main(){
  int n, i, S[1000], a, b, c, d;
  double res = 0.0;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &S[i]);

  bubbleSort(n, S);

  for ( d = 0; d < n-1; d++ ){
    c = d+1;
    a = n-1;
    b = n-2;
    if ( d == n-3 ){
      b = d-1;
    } else if ( d == n-2 ){
      a = d-2;
      b = d-1;
    }
    res = max(res, 1.0*(S[a]+S[b])/(S[c]-S[d]));
  }

  printf("%.8lf\n", res);

  return 0;
}



Measured memory_bytes: 2092
// https://atcoder.jp/contests/abc130/tasks/abc130_e

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 2*1e3;
const int M_MAX = 2*1e3;
const int S_I_MAX = 1e5;
const int T_I_MAX = 1e5;
const int MOD = 1e9+7;

int N, M;
int S[N_MAX];
int T[M_MAX];

int dp[N_MAX + 1][M_MAX + 1];

void solve() {
  REP(i, N + 1) dp[i][0] = 1;
  REP(j, M + 1) dp[0][j] = 1;
  REP(i, N) REP(j, M) {
    dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % MOD;
    if (S[i] != T[j]) {
      dp[i + 1][j + 1] = (dp[i + 1][j + 1] + MOD - dp[i][j]) % MOD;
    }
  }
  printf("%d\n", dp[N][M]);
}

void input() {
  scanf("%d%d", &N, &M);
  REP(i, N) scanf("%d", S + i);
  REP(i, M) scanf("%d", T + i);
}

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


Measured memory_bytes: 15872
#include<cstdio>
#include<cstring>
#include<iostream>

int main()
{
	char a[105], b[105];
	scanf("%s", a);
	scanf("%s", b);
	int ans = strcmp(a,b);
	if(strlen(a) > strlen(b)) ans = 1;
	if(strlen(a) < strlen(b)) ans = -1;
	if(ans > 0) printf("GREATER");
	else if(ans < 0) printf("LESS");
	else printf("EQUAL");
}


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

int main(){
	int n, count, res=0;
	cin >> n;
	for(int i=1;i<=n;i+=2){
		count=0;
		for(int j=1;j<=i;j++){
			if(i%j==0){
				count++;
			}
		}
		if(count==8){
			res++;
		}
	}
	cout << res << endl;
	return 0;
}

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

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

    int coin=0;
    for(int i=0;i<2;i++)( (A>B)? coin+=A,A--:coin+=B,B--);
    cout<<coin<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes() {
  cout << "YES" << endl;
  exit(0);
}

void no() {
  cout << "NO" << endl;
  exit(0);
}

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  REP(i, b) {
    if ((a * i) % b == c) {
      yes();
    }
  }
  no();
}

Measured memory_bytes: 256
d, n = map(int, input().split())
ans = 0
cnt = 0
i = 0

while True:
    if cnt == n:
        ans = i
        break
    i += 1
    j = i
    k = 0
    while True:
        if j%100 != 0:
            break
        j = j//100
        k += 1

    if k == d:
        cnt += 1



print(ans)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FOR(i,m,n) for (int i = m; i < (n); ++i)
#define REPR(i,n) for (int i = n; i >= 0; --i)
#define P pair<int, int>
const int INF = 1e9;
using namespace std;

const int NUM = 4;
//vector<int> a(NUM);
int a[NUM];

int main() {
    int n;
    cin >> n;
    REPR(i,3) {
        a[i] = n%10;
        n/=10;
    }
    // reverse(a.begin(), a.end());
    // scanf("%d", &a);
    //cin >> a[0] >> a[1] >> a[2] >> a[3];
    REP(x,8) {
        int sum = a[0];
        string s;
        s += (char)('0'+ a[0]);
        REP(i,3) {
            if(x&(1<<i)) {
                sum += a[i+1];
                s += '+';
                s += (char)('0' + a[i+1]);
            } else {
                sum -= a[i+1];
                s += '-';
                s += (char)('0' + a[i+1]);
            }
        }
        if(sum==7) {
            cout << s << "=7" <<  endl;
            break;
        }
    }
}

Measured memory_bytes: 3548
n,k=map(int,input().split())

ans=0
for b in range(1,n+1):
    if((n+b)//k >0 and (2*b)%k==0):
        p=((n+b)//k)
        q=(-(-b//k)) if b%k!=0 else (b//k)+1
        ans+=( p - q + 1)**2

#         for i in range( q,p+1):
#             for j in range( q,p+1):
#                 print(i*k-b,b,j*k-b)

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    vector <int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2);

    sort(vec.begin(), vec.end());

    cout << vec.at(0) << " " << vec.at(1) << " " << vec.at(2) << endl;

    
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
struct UnionFind{
    vi data;
    UnionFind(int size):data(size,-1){}
    bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int main(){
    int n,m;
    cin>>n>>m;
    vs vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    UnionFind uf(n*m);
    REP(i,n){
        REP(j,m){
            REP(k,4){
                int x=i+dx[k];
                int y=j+dy[k];
                if(0<=x&&x<n&&0<=y&&y<m){
                    if(vec[i][j]=='#'&&vec[x][y]=='#'){
                        uf.unite(i*m+j,x*m+y);
                    }
                }
            }
        }
    }
    REP(i,n){
        REP(j,m){
            if(vec[i][j]=='#'&&uf.size(i*m+j)==1){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
/*
      author : nishi5451
      created: 11.08.2020 22:10:16
*/

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


int main(){
    int n,a,b;
    cin >> n >> a >> b; 
    cout << min(n*a,b) << endl;
    return 0;
}

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

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

  vector<int> vec(N);

  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    vec.at(a-1) += 1;
    vec.at(b-1) += 1;
  }

  for (int i = 0; i < N; i++){
    cout << vec.at(i) << endl;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M=1000000007;
signed main(){
  int N,K,ans=0;
  cin>>N>>K;
  vector<int> A(N);
  for(int &i:A)
    cin>>i;
  for(int i=0;i<N;i++){
    int k=0,l;
    for(int j=0;j<i;j++)
      if(A[j]>A[i])
        k++;
    l=k;
    for(int j=i;j<N;j++)
      if(A[j]>A[i])
        l++;
    ans=(ans+k*K%M+K*(K-1)/2%M*l%M)%M;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3592
#include<cstdio>
#include<iostream>
using namespace std;
int k,n;
int a[300010];
int main() {
	scanf("%d%d",&k,&n);
	if(k&1) {
		for(int i=1; i<=n; i++)
			a[i]=(k+1)/2;
		int last=n;
		for(int i=1; i<=n/2; i++)
			if(a[last]==1) last--;
			else {
				a[last]--;
				for(int j=last+1; j<=n; j++)
					a[j]=k;
				last=n;
			}
		for(int i=1; i<=last; i++)
			printf("%d ",a[i]);
	} else {
		printf("%d ",k>>1);
		for(int i=2; i<=n; i++)
			printf("%d ",k);
	}
	return 0;
}//adhiuasgdjkasda

Measured memory_bytes: 3456
import sys
input = sys.stdin.readline

n = int(input())
dice = []

for _ in range(n):
    d_1, d_2 = map(int,input().split())
    dice.append([d_1, d_2])

ans = 0

for i in range(n-2):
    if dice[i][0] == dice[i][1]:
        if dice[i+1][0] == dice[i+1][1] and dice[i+2][0] == dice[i+2][1]:
            ans = 1
            break
        else:
            continue
        break

if ans > 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9212
#line 1 "template.cpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  ll h, w;
  cin >> h >> w;
  if (h == 1 || w == 1) {
    cout << 1 << endl;
    return 0;
  }
  ll row = (h + 1LL) / 2LL;
  ll col = (w + 1LL) / 2LL;
  cout << row * col + (h - row) * (w - col) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n;
vector<int> v[200010];
vector<int> ans(200100,0);
void dfs(int i, int p = -1){
    for(int j : v[i]){
        if(j==p) continue;
        ans[j]+=ans[i];
        dfs(j,i);
    }
}

int main(){
    //vector<int> v[200010];
    int q;
    cin>>n>>q;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    rep(i,q){
        int p,x;
        cin>>p>>x;
        p--;
        ans[p]+=x;
    }
    dfs(0);
    rep(i,n) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 23552
/* ex3_3
   Acro  */

#include <stdio.h> 
#include <math.h>
int main(void){
    int n,k,ans;
    scanf("%d %d",&n,&k);
    /* 底の変換公式 */
    ans = log(n)/log(k) + 1;
    printf("%d\n",ans);
    return 0;
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();

        long answer = s.Where(c => c == '1').Count();

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 26444
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <math.h>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <ctime>
#include <iomanip>
#include <fstream>
#include <array>
using namespace std;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define IN(x,c) (find(c.begin(),c.end(),x) != (c).end())
#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define INIT(a,v) memset(a,v,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; }

#define SPC << " " <<
#define DEBUG(x) cerr << #x << " = "; cerr << x << endl;
#define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl;

typedef pair<int,int> PII;
typedef long long int64;
typedef vector<int> VI;

int r,c,k;
int t[3000][3000];
int64 f[3000][3000][4];

void update(int64 &a, int64 b) {
	if (b>a) a=b;
}

int main() {
	//freopen("test.in","r",stdin);
	scanf("%d %d %d",&r,&c,&k);
	REP (i,k) {
		int y,x,v;
		scanf("%d %d %d",&y,&x,&v);
		y--; x--;
		t[y][x]=v;
	}
	REP (y,r) {
		REP (x,c) {
			REP (u,4) {
				if (u>0) update(f[y][x][u], t[y][x]);
				if (u>0) {
					if (x>0) update(f[y][x][u], f[y][x-1][u-1]+t[y][x]);
					if (y>0) update(f[y][x][u], f[y-1][x][3]+t[y][x]);
				}
				if (x>0) update(f[y][x][u], f[y][x-1][u]);
				if (y>0) update(f[y][x][u], f[y-1][x][3]);
				//printf("%d %d %d: %I64d\n",y,x,u,f[y][x][u]);
			}
		}
	}
	int64 ans=0;
	REP (u,4) ans=max(ans, f[r-1][c-1][u]);
	cout << ans << endl;
	return 0;
}


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

int main()
{
	int n, k;
	cin >> n >> k;
	int ans = 1;
	for(auto i = 0; i < n; ++i){
		ans = min(ans * 2, ans + k);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int64_t H, W;
  cin >> H >> W;
  if ( H == 1 || W == 1 ) {
    cout << 1;
  }
  else if ( H*W % 2 == 0 ) {
    cout << H*W/2;
  }
  else {
    cout << H*(W-1)/2 + (H/2) + 1;
  }
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define ss second
#define ff first
#define Mem(x,val) memset(x,val,sizeof x)
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n"
#define debug(a,b) cerr << #a<<" = "<<a<<"   |   "<<#b<<" = "<<b<<'\n'
#define endl '\n'
#define SZ(a) ((int)a.size())
using namespace std;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll mod = 1e9 + 7;
const int nax = 1e6+10;
void solve(){
	
}
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   //ll a, b, c, d;
   //cin >> a >> b >> c >> d;
   //cout << (c <= b ? "Yes" : "No") << endl;
   int k; cin >> k;
   while(k--) cout << "ACL";
   cout << endl;
   return 0;
}


Measured memory_bytes: 3692
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] a = new int[m];
        int[] b = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = Integer.parseInt(sc.next());
            b[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        // 空のグラフを作成
        List<HashSet<Integer>> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(new HashSet<>());
        }

        // 有向グラフを設定
        for (int i = 0; i < m; i++) {
            list.get(a[i] - 1).add(b[i] - 1);
        }

        // 探索の開始地点を設定
        Deque<Integer> deque = new ArrayDeque<>();
        int start = 0;
        deque.add(start);

        // 探索距離を保持
        int[] distance = new int[n];
        distance[start]++;

        // 探索を開始
        int goal = 0;
        while (!deque.isEmpty()) {
            int point = deque.poll();

            // 目的地判定
            if (point == n - 1) {
                goal = distance[point] - 1;
                break;
            }

            for (int nextPoint : list.get(point)) {
                if (distance[nextPoint] == 0) {
                    deque.add(nextPoint);
                    distance[nextPoint] = distance[point] + 1;
                }
            }
        }

        String result = 0 < goal && goal < 3 ? "POSSIBLE" : "IMPOSSIBLE";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


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

int main()
{
    int a,p,x;
    string b;
    cin>>a>>b;
    //int m=a.length(),n=b.lenght();
    if(b.length()==1){
        p=a*10+(b[0]-'0');
        double res=pow(p,0.5);
        if(abs(res-int(res))==0) cout<<"Yes";
        else cout<<"No";
    }
    else if (b.length()==2){
         x=(b[0]-'0')*10;
        p=a*100+x+(b[1]-'0');
        double res=pow(p,0.5);
        if(abs(res-int(res))==0) cout<<"Yes";
        else cout<<"No";

    }
    else {
         x=(b[0]-'0')*10;
        p=a*1000+100;
        double res=pow(p,0.5);
        if(abs(res-int(res))==0) cout<<"Yes";
        else cout<<"No";

    }

    return 0;
}


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

#define NMAX 305
double dp[NMAX][NMAX][NMAX];

double search(int N, int i, int j, int k) {
	if (i < 0 or j < 0 or k < 0 or i+j+k == 0) return 0.0;
	if (dp[i][j][k] > -INFINITY) return dp[i][j][k];

	double ret = 0.0, exp = (double) N/(i+j+k);
	ret += (search(N, i-1, j,   k  ) + exp) * (double) i/(i+j+k);
	ret += (search(N, i+1, j-1, k  ) + exp) * (double) j/(i+j+k);
	ret += (search(N, i,   j+1, k-1) + exp) * (double) k/(i+j+k);

	return dp[i][j][k] = ret;
}

int main() {
	int N; scanf("%d", &N);
	vector<int> pieces(N), plates(4);

	for (int &ai: pieces) {
		scanf("%d", &ai);
		plates[ai]++;
	}

	for (int i = 0; i < NMAX; ++i)
		for (int j = 0; j < NMAX; ++j)
			for (int k = 0; k < NMAX; ++k)
				dp[i][j][k] = -INFINITY;

	printf("%.10f\n", search(N, plates[1], plates[2], plates[3]));
}


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

const int INF = 1 << 30;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    vector<int> p(n);
    for (int i = 0; i < n; ++i)
      cin >> p[i];
    p.push_back(INF); // sentinel

    pair<int, int> prev(make_pair(p[0], p[0]));
    vector<pair<int, int> > ans;
    for (int i = 1; i < n+1; ++i) {
      if (p[i] != prev.second+1) {
	ans.push_back(prev);
	prev.first = prev.second = p[i];
      } else {
	prev.second = p[i];
      }
    }

    for (int i = 0; i < ans.size(); ++i) {
      if (ans[i].first == ans[i].second)
	printf("%d%s", ans[i].first, i != ans.size()-1 ? " ": "\n");
      else
	printf("%d-%d%s", ans[i].first, ans[i].second, i != ans.size()-1 ? " " : "\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
int n, m;
int a[777][777];
int col[777];
bool bad;
int W, B;
vector <pii> v;
int mem[777][777];

void dfs(int p) {
	if(col[p] == 0) ++W;
	else ++B;
	for(int i = 1; i <= n; i++) {
		if(i == p) continue;
		if(a[p][i] == 0) {
			if(col[i] == -1) {
				col[i] = col[p] ^ 1;
				dfs(i);
			} else if (col[i] == col[p]) {
				bad = true;
				return ;
			}
		}
	}
} 

int nC2(int n) {
	return (n * (n - 1)) / 2;
}

int dp(int now, int white) {
	if(now == v.size()) {
		int black = n - white;
		return nC2(white) + nC2(black);
	}
	if(mem[now][white] != -1) return mem[now][white];
	int ans = min(dp(now + 1, white + v[now].first), dp(now + 1, white + v[now].second));
	return mem[now][white] = ans;
}

int main() {
	scanf("%d %d", &n, &m);
	for(int i = 0; i < m; i++) {
		int p, q;
		scanf("%d %d", &p, &q);
		a[p][q] = a[q][p] = 1;
	}
	memset(col, -1, sizeof col);
	for(int i = 1; i <= n; i++) {
		if(col[i] == -1) {
			col[i] = 0;
			W = B = 0;
			dfs(i);
			v.emplace_back(W, B);
		}
	}
	if(bad) {
		printf("-1\n");
		exit(0);
	}
	memset(mem, -1, sizeof mem);
	printf("%d\n", dp(0, 0));
	return 0;
}

Measured memory_bytes: 4736
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())
atoz = [chr(i) for i in range(97,97+26)]

N = inp()
if N <= 999:
	print('ABC')
else:
	print('ABD')


Measured memory_bytes: 4200
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;
#define pb push_back
#define fi first

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n,k,a[1005],ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<k;i++) ans+=a[i];
	cout<<ans<<endl; 
}


Measured memory_bytes: 3164
import fractions

n = int(input())
a = list(map(int, input().split()))
ainv_sum = 0
m = 10 ** 9 + 7

for i in range(n):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i]) if i > 0 else a[i]
    ainv_sum += pow(a[i], m-2, m)
    ainv_sum %= m

print((ainv_sum * lcm) % m)

Measured memory_bytes: 6112
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 5000005

struct Node{

	int parent,left,right,size,DEPTH;
};

int num_nodes,root;
int dp[500];
Node nodes[NUM];
bool check[200005];
char buf[NUM];

void parse(){

	for(int i = 0; i < 200005; i++){
		check[i] = false;
	}

	stack<int> S;

	int depth = 0,node_id;

	for(int i = 0; buf[i] != '\0'; i++){
		if(buf[i] == '('){
			depth++;
			S.push(num_nodes);
			nodes[num_nodes].left = -1;
			nodes[num_nodes].right = -1;
			nodes[num_nodes].DEPTH = depth;

			num_nodes++;

		}else{ //buf[i] == ')'

			node_id = S.top();
			S.pop();

			if(S.empty()){

				nodes[node_id].parent = -1;

			}else{

				nodes[node_id].parent = S.top();

				if(check[nodes[node_id].parent]){

					nodes[nodes[node_id].parent].right = node_id;

				}else{

					nodes[nodes[node_id].parent].left = node_id;
					check[nodes[node_id].parent] = true;
				}
			}
			depth--;
		}
	}
}

void calc_size(int node_id,int DEPTH){

	nodes[node_id].size = 1;
	nodes[node_id].DEPTH = DEPTH;

	if(nodes[node_id].left != -1){
		calc_size(nodes[node_id].left,DEPTH+1);
		nodes[node_id].size += nodes[nodes[node_id].left].size;
	}

	if(nodes[node_id].right != -1){
		calc_size(nodes[node_id].right,DEPTH+1);
		nodes[node_id].size += nodes[nodes[node_id].right].size;
	}
}

bool is_ok(int base_tree_node,int copied_tree_node,int copied_root){

	if(nodes[base_tree_node].left == -1 && nodes[copied_tree_node].left != -1){

		return false;

	}else if(nodes[base_tree_node].left == -1 && nodes[copied_tree_node].left == -1){

		return true;

	}else if(nodes[base_tree_node].left != -1 && nodes[copied_tree_node].left == -1){

		return is_ok(nodes[base_tree_node].left,nodes[copied_root].left,copied_root) &&
				is_ok(nodes[base_tree_node].right,nodes[copied_root].right,copied_root);

	}else{ //nodes[base_tree_node].left != -1 && nodes[copied_tree_node].left != -1

		return is_ok(nodes[base_tree_node].left,nodes[copied_tree_node].left,copied_root) &&
				is_ok(nodes[base_tree_node].right,nodes[copied_tree_node].right,copied_root);
	}
}


int main(){

	scanf("%s",buf);

	num_nodes = 0;
	parse();

	root = 0;
	calc_size(root,0);

	int tmp_node,max_DEPTH = 0;

	for(int i = 0; i < num_nodes; i++){
		if(max_DEPTH < nodes[i].DEPTH){

			max_DEPTH = nodes[i].DEPTH;
			tmp_node = i;
		}
	}

	tmp_node = nodes[tmp_node].parent;
	if(tmp_node == -1){

		printf("0\n");
		return 0;
	}

	vector<int> V;

	while(true){

		if((nodes[root].size-1)%(nodes[tmp_node].size-1) == 0){

			if(is_ok(root,tmp_node,tmp_node)){
				V.push_back(nodes[tmp_node].size-1);
			}
		}

		if(tmp_node == root)break;

		tmp_node = nodes[tmp_node].parent;
	}

	for(int i = 0; i < V.size(); i++){

		dp[i] = BIG_NUM;
	}

	dp[0] = 0;

	for(int i = 1; i < V.size(); i++){
		for(int k = 0; k < i; k++){
			if(V[i]%V[k] == 0){

				dp[i] = min(dp[i],dp[k]+V[i]/V[k]-1);
			}
		}
	}

	printf("%d\n",dp[V.size()-1]);

	return 0;
}



Measured memory_bytes: 12608
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long L, R, ANS = 2019;
	cin >> L >> R;
	if (L / 2019 != R / 2019 || L % 2019 == 0 || R % 2019 == 0) {
		cout << 0 << endl;
		return 0;
	}
	for (long long i = L; i <= R; i++) {
		for (long long j = i + 1; j <= R; j++) {
			ANS = min(ANS, (i * j) % 2019);
		}
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
	int i,a,b,c,e;
	double d;
	e=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=1;i<=c;i++){
	d = (double)c/i;
	if((ceil(d)==floor(d))&&(a<=d)&&(d<=b)){
		e=e+1;
	}
	}
	
	printf("%d\n",e );
	return 0;
}

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

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D){
    cout<<"Left"<<endl;
  }
  if(A+B==C+D){
    cout<<"Balanced"<<endl;
  }
  if(A+B<C+D){
    cout<<"Right"<<endl;
  }
}


Measured memory_bytes: 256