akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    int N, M;
    cin>>N>>M;
    cout<<N*(N-1)/2+M*(M-1)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  1000000007
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;


int bigmod(int a,int p){
    if (p==0) return 1;
    if (p&1){
        int p1=a%mod;
        int p2 = bigmod(a,p-1)%mod;
        return (p1*p2)%mod;
    }
    int p1=bigmod(a,p/2)%mod;
    return (p1*p1)%mod;
}

int fermat(int n,int a){
    int x=1,y=1;
    for (int i=1;i<=a;i++){
        y = (y*i)%mod;
        x = (x*(n-i+1))%mod;
    }
    return (x*bigmod(y,mod-2))%mod; 
}

inline void solve(){
    int n,a,b; 
    cin>>n>>a>>b; 
    cout << ((bigmod(2,n)-fermat(n,a)-fermat(n,b)-1)+(6LL*mod))%mod << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

int main(){
    //input
    int a,b,k;
    cin >> a >> b >> k;
    if(b-a < 2*k){
        for(int i=a;i<=b;i++){
            cout << i << endl;
        }
    }else{
        for(int i=a;i<a+k;i++){
            cout << i << endl;
        }
        for(int i=b-k+1;i<=b;i++){
            cout << i << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
shop = [tuple(map(int, input().split())) for _ in range(N)]

shop.sort(key=lambda x: x[0])
ans = 0

for i in range(N):
    buy = min(M, shop[i][1])
    ans += buy * shop[i][0]
    M -= buy
    if M == 0:
        print(ans)
        exit()


Measured memory_bytes: 18140
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using ll = long long;
using P = pair<long long, long long>;
using MATRIX = vector< vector<ll> >;
template <class T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <class T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}

struct UnionFind {
  vector<long long> size, par;
  UnionFind(long long n) {
    size.resize(n, 0);
    par.resize(n, 0);
    for(long long i = 0; i < n; i++) {
      maketree(i);
    }
  }

  void maketree(long long x) {
    par[x] = x;
    size[x] = 1;
  }

  long long root(long long x) {
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(long long x, long long y) {
    long long rx = root(x);
    long long ry = root(y);
    if(rx == ry) return;
    if(size[rx] < size[ry]) par[rx] = ry;
    else {
      par[ry] = rx;
      if(size[rx] == size[ry]) size[rx]++;
    }
  }

  bool same(long long x, long long y) {
    long long rx = root(x);
    long long ry = root(y);
    return rx == ry;
  }
};

int main() {
  long long N, M;
  cin >> N >> M;
  UnionFind tree(2 * N);
  rep(i, M) {
    long long a, b;
    cin >> a >> b;
    a--;b--;
    tree.unite(a, b + N);
    tree.unite(a + N, b);
  }
  bool f = false;
  long long cnt = 0;
  rep(i, N) {
    if(tree.same(i, i + N)) {
      cout << N * (N - 1) / 2 - M << endl;
      return 0;
    }
  }
  rep(i, N) {
    if(tree.same(0, i)) {
      cnt++;
    }
  }
  cout << cnt * (N - cnt) - M << endl;
  return 0;
}

Measured memory_bytes: 6428
import sys
from math import floor

n= int(sys.stdin.readline())
a= [ int(x) for x in sys.stdin.readline().split() ]
ans= [-1]*n
c = floor(n/2) + 1
for i in range(c,n+1):
    j= i-1
    ans[j]= a[j]
#
for i in range(c-2,-1,-1):
    j= i+1
    s= a[i]
    for k in range(2*j,n+1,j): s+= ans[k-1]
    ans[i]= s%2
#
m= sum(ans)
print( m )
if m>0:
    for i in range(n):
        if ans[i]: print( i+1,end=" " )


Measured memory_bytes: 7248
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
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; }

int main(){

    int y,m,d;
    scanf("%d/%d/%d", &y,&m,&d);
    if(y*10000+m*100+d <= 20190430)cout<<"Heisei"<<endl;
    else cout<<"TBD"<<endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
a_idx = ord('a')
S_Lis = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [],
         13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: [], 22: [], 23: [], 24: [], 25: []}
T_Lis = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], 10: [], 11: [], 12: [],
         13: [], 14: [], 15: [], 16: [], 17: [], 18: [], 19: [], 20: [], 21: [], 22: [], 23: [], 24: [], 25: []}
leng = len(S)
for i in range(leng):
    S_Lis[ord(S[i])-a_idx].append(i)
    T_Lis[ord(T[i])-a_idx].append(i)
for i in range(26):
    tmpS = S_Lis[i]
    if len(tmpS) == 0 or tmpS == T_Lis[i]:
        continue
    else:
        flag = True
        for j in T_Lis.values():
            if tmpS == j:
                flag = False
                break
        if flag:
            print("No")
            exit()
print("Yes")

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

using namespace std;

int n,s;

int f(int deps,int cnt,int sum)
{
    if(deps == 10){
        if(cnt == n && sum == s)return 1;
        return 0;
    }
    return f(deps + 1,cnt + 1,sum + deps)+f(deps + 1,cnt,sum);
}

int main()
{
    while(1){
    cin >> n >> s;
    if(n == 0 && s == 0)break;
    printf("%d\n",f(0,0,0));
    }
    return 0;
}

Measured memory_bytes: 1144
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int sum = sc.nextInt();
		int h = sum/3600;
		int m = (sum%3600)/60;
		int s = ((sum%3600)%60);
		System.out.println(h+":"+m+":"+s);
	}
}



Measured memory_bytes: 26344
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int>>;

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

    int n;
    cin >> n;
    vector<pair<int, int>> r_points(n);
    vector<pair<int, int>> b_points(n);

    rep(i, n)
    {
        int a, b;
        cin >> a >> b;
        r_points[i] = mp(a, b);
    }
    rep(i, n)
    {
        int c, d;
        cin >> c >> d;
        b_points[i] = mp(c, d);
    }

    sort(r_points.begin(), r_points.end());
    sort(b_points.begin(), b_points.end());

    int r_idx = 0;
    int b_idx = 0;
    int cnt = 0;
    vector<pair<int, int>> br_pair;
    rep(i, n)
    {
        auto b_val = b_points[i];
        int bx = b_val.first;
        int by = b_val.second;
        int dist = 10000;
        int idx = -1;
        rep(j, r_points.size())
        {
            auto r_val = r_points[j];
            int rx = r_val.first;
            int ry = r_val.second;
            if (rx < bx && ry < by && by - ry < dist)
            {
                idx = j;
                dist = by - ry;
            }
        }
        if (idx >= 0)
        {
            br_pair.pb(mp(i, idx));
            r_points.erase(r_points.begin() + idx);
        }
    }

    cout << br_pair.size() << endl;
    //system("pause");
    return 0;
}

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

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

    int a, b;
    cin >> a >> b;
    if (a > b) {
        for (int i = 0; i < a; i++) {
            cout << b;
        }
    } else {
        for (int i = 0; i < b; i++) {
            cout << a;
        }
    }
    return 0;
}


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

using namespace std;

const int MAX_N = 260;
int n;
string grid[MAX_N];
int max_len;
int memo[MAX_N][MAX_N][4];

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

int rec(int y, int x, int d)
{
    if (memo[y][x][d] >= 0)
        return memo[y][x][d];

    int nx = x + dx[d];
    int ny = y + dy[d];

    if (nx < 0 || nx >= n || ny < 0 || ny >= n)
        return 1;
    if (grid[ny][nx] == '0')
        return 1;

    return memo[y][x][d] = (rec(ny, nx, d) + 1);
}

int main()
{
    while (cin >> n, n) {
        max_len = 0;
        for (int i = 0; i < n; i++) 
            cin >> grid[i];

        for (int i = 0; i <= n; i++)
            for (int j = 0; j <= n; j++)
                for (int k = 0; k < 4; k++)
                    memo[i][j][k] = -1;

        for (int y = 0; y < n; y++) 
            for (int x = 0; x < n; x++) 
                if (grid[y][x] == '1') {
                    for (int k = 0; k < 4; k++) 
                        max_len = max(max_len, rec(y, x, k));
                }

        cout << max_len << endl;
    }

    return 0;
}

Measured memory_bytes: 2352
from itertools import chain
n = input()
target = list([[""]])

def next753(string_list):
    x = []
    for string in string_list:
        x.append("3" + string)
        x.append("5" + string)
        x.append("7" + string)
    return x

ans = 0
for i in range(0, len(n)):
    target.append(next753(target[i]))
new = filter(lambda x: int(x) <= int(n),list(chain.from_iterable(target[3:])))
for i in list(new):
    if (("3" in i) and ("5" in i) and ("7" in i)):
        ans += 1
print(ans)

Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    ll x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    if(abs(x)/abs(d) >= k){
        cout << abs(x - d*k) << endl;
    }else{
        

            x = abs(x);
            ll y = x/d;
            ll a = x - d*y;
            ll b = x-d*y-d;
            if(y%2 == k%2){
                if(y == k+1){
                    cout << a << endl;
                    return 0;
                }
                cout << min(a,abs(a-2*d)) << endl;
            }else{
                if(y == k+1){
                    cout << abs(b) << endl;
                    return 0;
                }
                cout << min(abs(b),b+2*d) << endl;
            }
        
    }
    return 0;
}

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

using namespace std;

using ll = long long;

using Graph = vector< vector<int> >;

bool dfs(int cur, vector<int>& memo, Graph& g, vector<int>& order) {
	memo[cur] = 1;
	for (int nex : g[cur]) {
		if (memo[nex] == 2) continue;
		if (memo[nex] == 1) return false;
		if (!dfs(nex, memo, g, order)) return false;
	}
	memo[cur] = 2;
	order.push_back(cur);
	return true;
}

bool tsort(Graph& g, vector<int>& order) {
	vector<int> memo(g.size(), 0);
	for (int i = 0; i < g.size(); i++) {
		if (memo[i] != 0) continue;
		if (!dfs(i, memo, g, order)) return false;
	}
	reverse(order.begin(), order.end());
	return true;
}

Graph g;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	g.resize(n);

	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
	}

	vector<int> order;
	tsort(g, order);

	vector<int> dp(n, 0);
	int ans = 0;
	for (int i : order) {
		ans = max(ans, dp[i]);
		for (int j : g[i]) {
			dp[j] = max(dp[j], dp[i] + 1);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9468
def calc_log2(x, y, cnt):
    if x >= y: return cnt
    return calc_log2(x * 2, y, cnt + 1)

def calc_power(num, acc):
    if num == 0: return acc
    else: return calc_power(num - 1, acc * 2)

n, k = list(map(int,input().split()))

max_log2 = calc_log2(1, k, 0)

li = [0] * n
molecure = 0
for i in range(n):
    molecure += calc_power(max_log2 - calc_log2(i + 1, k, 0), 1)

denominator = n * calc_power(max_log2, 1)

print(float(molecure) / denominator)

Measured memory_bytes: 55148
#include<iostream>
using namespace std;
 
int main(){
  int a,b;

  cin >> a >> b;

  if (a>b) {
    cout << "a > b" << endl;
  } else if (a<b) {
    cout << "a < b" << endl;
  } else {
    cout << "a == b" << endl;
  }

  return 0;		 
}



Measured memory_bytes: 3088
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

int main(){
    int N;
    long long A[100001];
    cin>>N;
    for(int i=0;i<N;i++) scanf("%lli", &A[i]);
    long long ans=0;
    long long sum=0;
    for(int i=0;i<N;i++){
        if(A[i]!=0){
            sum+=A[i];
        }
        if(A[i]==0){ans+=sum/2;sum=0;}
    }        
    ans+=sum/2;
    cout<<ans<<endl;
    return 0;
};


Measured memory_bytes: 1024
<?php
$inArray = [];
while (!feof(STDIN) ) {
    $inArray[] = trim(fgets(STDIN));
}

$searchWord = strtolower($inArray[0]);
$inStr = "";
$cnt = 0;

for ($i = 1; $i < count($inArray); $i++) {
    if($inArray[$i] != "END_OF_TEXT"){
        foreach (explode(' ', strtolower($inArray[$i])) as $value) {
            if($value == $searchWord){
                ++$cnt;
            }
        }
    }
}

echo $cnt.PHP_EOL;
?>


Measured memory_bytes: 9288
#include <bits/stdc++.h>
using namespace std;
const int N=(int)1e5+5;
const int md=(int)1e9 + 7;
vector<int> g[N];
int vis[N];
long long int d[N][2];
void dfs(int v){
  vis[v]=1;
  long long int pro1=1,pro2=1;
  for(int i=0;i<g[v].size();++i){
    int c=g[v][i];
    if(vis[c]){
      continue;
    }
    dfs(c);
    pro1 *= ((d[c][0] + d[c][1])%md);
    pro1 %= md;
    pro2 *= (d[c][0] % md);
    pro2 %= md;
  }
  d[v][0]=pro1;
  d[v][1]=pro2;
}
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n-1;++i){
    int x,y;
    cin>>x>>y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1);
  cout << (d[1][0] + d[1][1])%md;
}


Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() {
  cout << "Yes";
}

void no() {
  cout << "No";
}

int main() {
  kyun;
  int a,p;
  cin >> a >> p;
  cout << (3*a+p)/2;
  hinata;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define int long long
#define maxn (100010)
int n, m, top, s[maxn], cnt[maxn], sum[maxn];

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
		ch == '-' ? f = -1, ch = getchar() : ch = getchar();
	while (ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return x * f;
}

//void sol(int x, int del) {
////	printf("X %lld %lld\n", x, del);
//	if (!x) return;
//	int pos = upper_bound(s + 1, s + top + 1, x) - s - 1; // 找到比他大的，然后-1 
////	printf("POS %lld\n", pos);
//	if (!pos) sum[1] += del, sum[x + 1] -= del;
//	else sum[pos] += (x / s[pos]) * del, sol(x % s[pos], del);
//}

void sol(int x,int v) {
//	printf("X %lld %lld\n", x, v);
	if (!x) return;
	int t = upper_bound(s+1,s+top+1,x) - s - 1;
//	printf("TT %lld\n", t);
	if (t == 0) sum[1] += v, sum[x+1] -= v;
	else {
		cnt[t] += (x / s[t]) * v;
		sol(x % s[t],v);
	}
}

signed main() {
	n = read(), m = read();
	s[++top] = n;
	int x;
	for (int i = 1; i <= m; ++i) {
		x = read();
		while (top && s[top] >= x) --top;
		s[++top] = x;
	}
	cnt[top] = 1;
	for (int i = top; i >= 2; --i) {
		cnt[i - 1] += (s[i] / s[i - 1]) * cnt[i];
//		printf("	%lld %lld %lld\n", s[i] % s[i - 1], cnt[i], i);
		sol(s[i] % s[i - 1], cnt[i]);
	}
//	for (int i = 1; i <= top; ++i) printf("%lld\n", cnt[i]);
	sum[1] += cnt[1], sum[s[1] + 1] -= cnt[1]; // s[1]为最长长度
	for (int i = 1; i <= n; ++i) sum[i] += sum[i - 1];
	for (int i = 1; i <= n; ++i) printf("%lld\n", sum[i]); 
	return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
int A[1001000],n;
bool binarysearch(int key){
    int left=0,right=n,mid;
    while(left<right){
        mid=(left+right)/2;
        if(key==A[mid]) return 1;
        if(key>A[mid]) left=mid+1;
        else if(key<A[mid]) right=mid;
    }
    return 0;
}

int main(){
    int i,q,k,sum=0;cin>>n;for(int i=0;i<n;i++) cin>>A[i];cin>>q;
    for(int i=0;i<q;i++) {
        cin>>k;
        if(binarysearch(k)){
            sum++;
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3516
#include<iostream>
#include<utility>
#include<tuple>
#include<set>
#include<list>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl;
#define int long long

const long long MAXN = 1e6;
const long long MOD = 1e9+7;
const long long INF = __LONG_LONG_MAX__ / 2;

using namespace std;

int hoge[MAXN];

bool isMatch(string s, string k, int offset) {
  if (k.length() > s.length() - offset) return false;
  for (int i = 0; i < (int)k.length(); i++)
  {
    if (s[offset+i] == '?') continue;
    if (s[offset+i] != k[i]) return false;
  }
  return true;
}

int matchPlace(string s, string k) { // no match ==> -1
  int p = -1;
  for (int i = 0; i < (int)s.length(); i++)
  {
    if (isMatch(s, k, i)) p = i;
  }
  return p;
}

string reptoa (string s){
  for (int i = 0; i < (int)s.length(); i++)
  {
    if (s[i] == '?') s[i] = 'a';
  }
  return s;
}

signed main(){
    string SP, T;
    cin >> SP >> T;
    int match_place = matchPlace(SP, T);
    if (match_place == -1){
      cout << "UNRESTORABLE" << endl;
    } else {
      cout << reptoa(SP.substr(0,match_place)) << T << reptoa(SP.substr(match_place+T.length(),  SP.length() - match_place - T.length())) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    string s;
    cin >> s;
    int ans = 0;
    rep(i, 1, s.size()){
        if(s[i] != s[i - 1]) ans++;
    }
    cout << ans << endl;
}

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

#define int long long

int N, A;
vector<int> x;
int dp[55][55][2555]; // dp[インデックス][枚数][合計] = 総数

int rec(int idx, int mai, int sum) {
  // 全部調べ終わる
  if (idx >= N) {
    return ((mai * A) == sum) && (sum != 0);
  }

  // 計算済み
  if (dp[idx][mai][sum] != -1) {
    return dp[idx][mai][sum];
  }

  int ret = 0;

  // index枚目のカードを選ぶ
  int yes = rec(idx + 1, mai + 1, sum + x[idx]);
  // index枚目のカードを選ばない
  int no = rec(idx + 1, mai, sum);

  ret += yes + no;

  return dp[idx][mai][sum] = ret;
}

signed main() {
  cin >> N >> A;
  x.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }

  memset(dp, -1, sizeof(dp));
  int ans = rec(0, 0, 0);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 60672
N = int(input())
A = list(map(int,input().split()))
M = int(input())
B = list(map(int,input().split()))

def bisect(key, L):
    left = 0
    right = len(L)-1
    while right - left >= 0:
        mid = left + (right - left) // 2
        if L[mid] == key:
            return mid
        if L[mid] > key:
            right = mid - 1
        else:
            left = mid +1
    return -1

count = 0
for b in B:
    if bisect(b,A) != -1:
        count += 1
print(count)



Measured memory_bytes: 16712
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1000000001;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int tmp = 0;
  rep(i, n) tmp += a[i];

  int count = 0;
  rep(i, n){
    if(tmp <= 4 * m * a[i]){
      count++;
    }
  }

  if(m <= count) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
//iejr Header files
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <sstream>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <limits.h>
#include <ctime>
#include <cctype>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

//iejr: Type defination
typedef unsigned long long int             ULLN;
typedef long long int                      LLN;
typedef vector<int>                        VI;
typedef vector<vector<int> >               VVI;
typedef vector<string>                     VS;
typedef vector<vector<string> >            VVS;


//iejr: Compile Options
//#define C11_Standard
//
#ifdef C11_Standard
    #include <unordered_set>
    #include <unordered_map>

    #define HASHSET                  unordered_set
    #define HASHMAP                  unordered_map;
#endif // C11_Standard


//iejr: Local Debug
//#define INPUT_REDIRECTION
//#define OUTPUT_REDIRECTION


//iejr: Main Function
int main()
{

#ifdef INPUT_REDIRECTION
    freopen( "in.txt", "r", stdin );
#endif // INPUT_REDIRECTION

#ifdef OUTPUT_REDIRECTION
    freopen( "out.txt", "w", stdout );
#endif // OUTPUT_REDIRECTION

    string A, B, C;
    while( cin >> A >> B >> C ){
        int curTurn = 0;
        int pA = 0, pB = 0, pC = 0;

        while( 1 ){
            if( curTurn == 0 ){
                if( pA == A.length() ){
                    break;
                }
                curTurn = A[pA++] - 'a';
            }
            else if( curTurn == 1 ){
                if( pB == B.length() ){
                    break;
                }
                curTurn = B[pB++] - 'a';
            }
            else{
                if( pC == C.length() ){
                    break;
                }
                curTurn = C[pC++] - 'a';
            }
        }

        printf( "%c\n", 'A' + curTurn );
    }

#ifdef INPUT_REDIRECTION
    fclose( stdin );
#endif // INPUT_REDIRECTION

#ifdef OUTPUT_REDIRECTION
    fclose( stdout );
#endif // OUTPUT_REDIRECTION

    return 0;
}


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

typedef long long LL;

#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 ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    vector<LL> A(N);
    REP(i, N) {
        cin >> A[i];
        A[i] -= i;
    }
    sort(ALL(A));
    LL b = A[N/2];
    LL res = 0;
    REP(i, N) {
        res += abs(A[i] - b);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1920
N=int(input())
S=input()
#ある場所を決めたときに、右側はすべてW,左側はすべてEになる必要がある
#この変更の数が少なければよい

#最初から最後までのwとeの累積和を計算する
sum_W=[0]*(N+1)
sum_E=[0]*(N+1)
for i in range(N):
	if S[i]=="W":
		sum_W[i+1]+=sum_W[i]+1
	else:
		sum_W[i+1]=sum_W[i]
		
	if S[i]=="E":
		sum_E[i+1]+=sum_E[i]+1
	else:
		sum_E[i+1]=sum_E[i]
ans=N
count=0
for i in range(1,N+1):
	#仮に3番目がリーダーだとすると,左右で動かなければならない人数は
	tmp=sum_W[i-1]+(sum_E[-1]-sum_E[i])
	if tmp<ans:
		ans=tmp
		count=i
print(ans)
#仮に3番目がリーダーだとすると,左右で動かなければならない人数は
#print(sum_W[2],sum_E[5]-sum_E[3])

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

// Tip : ceil ( a/b ) = 1 + floor( (a-1)/b ) !

void solve ( int test_case )
{
    char c ;
    cin >> c ;

    c ++ ;
    cout << c ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 9999999999
lists = []
if n == 0:
    print(x)
    exit()
for i in range(-1000, 1000):
    if not i in p:
        lists.append(i)
for i in lists:
    if ans > abs(x - i):
        ans = abs(x-i)
        m = i

print(m)


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

string S[3] = {"Sunny", "Cloudy", "Rainy"};

int main() {
    string s;
    cin >> s;
    if (s == S[1]) cout << S[2];
    if (s == S[2]) cout << S[0];
    if (s == S[0]) cout << S[1];
}


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

int main() {
  int N;
  cin >> N;
  vector<int>A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  double res = 0;
  for (int i = 0; i < N; i++) {
    res += double(1.0/A[i]);
  }
  cout << fixed << setprecision(6) << double(1.0/res) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[3001][3001][2];
int solve(vector<int>& vec, int i, int j, int turn)
{
	if(i > j)return 0;
	if(dp[i][j][turn] != -1)return dp[i][j][turn];
	if(turn == 1){
		return dp[i][j][turn] = max(vec[i] + solve(vec, i + 1,j,0) , vec[j] + solve(vec, i, j-1, 0));
	}
	else{
		return dp[i][j][turn] = min(solve(vec, i + 1,j,1) , solve(vec, i, j-1, 1));
	}
}
signed main()
{
	int n;
	cin >> n;
	memset(dp, -1, sizeof dp);
	vector<int> vec(n + 1);
	int sum = 0;
	for(int i = 1; i<= n; i++){
		cin >> vec[i];
		sum += vec[i];
	}
	int sum_x =  solve(vec, 1, n, 1);
	int sum_y = sum - sum_x;
	cout << sum_x - sum_y;
}

Measured memory_bytes: 144596
from heapq import heappop,heappush
from collections import defaultdict

N,Q = map(int,input().split())
events = []
for _ in range(N):
    s,t,x = map(int,input().split())
    events.append((s-x,1,x))
    events.append((t-x,2,x))

for _ in range(Q):
    d = int(input())
    events.append((d,3,0))

events.sort()

minimumStop = [float("INF")]
stopCount = {float("INF"):1}

for sec,e,x in events:
    if e == 1:
        heappush(minimumStop,x)
        if x not in stopCount:
            stopCount[x] = 0
        stopCount[x] += 1
    if e == 3:
        while stopCount[minimumStop[0]] == 0:
            heappop(minimumStop)
        if minimumStop[0] == float("INF"):
            print(-1)
        else:
            print(minimumStop[0])
    if e == 2:
        stopCount[x] -= 1


Measured memory_bytes: 208996
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>

using namespace std;

int main()
{
  int a = 0 , b = 0, c = 0, d = 0, e = 0, f = 0;
  int i = 0, j = 0;
  int a2[256], b2[512], c2[1024];
  char a3[200000], b3[200000], c3[200000];
  
  cin >> a3 >> b3;
  
  if(a3[0] == b3[0]){
    a++;
  }
  if(a3[1] == b3[1]){
    a++;
  }
  if(a3[2] == b3[2]){
    a++;
  }
  cout << a << endl;
}
  

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

int main() {
	int n; cin >> n;
	if(n == 3) {
		cout << "2 5 63" << '\n';
		return 0;
	}
	const int a[] = {2, 3, 4, 6};
	int ans[n];
	int off = 0, sum = 0;
	int k = 0;
	for(k = 0; k < n; ++k) {
		ans[k] = off + a[k % 4];
		sum += ans[k];
		if(k % 4 == 3) {
			off += 6;
		}
	}
	k %= 4;
	if(sum % 6 == 2) {
		if(k > 2) off += 6;
		ans[3] = off + 4;
	}
	if(sum % 6 == 3) {
		if(k > 1) off += 6;
		ans[3] = off + 3;
	}
	if(sum % 6 == 5) {
		if(k > 1) off += 6;
		ans[4] = off + 3;
	}
	sort(ans, ans + n);
	// int tmp = 0;
	for(int i = 0; i < n; ++i) {
		cout << ans[i] << (i == n - 1 ? "\n" : " ");
		// tmp += ans[i];
	}
	// for(int i = 0; i < n; ++i) {
	// 	assert(__gcd(ans[i], tmp) > 1);
	// }
	return 0;
}



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

long long N, M;
vector<vector<int>> adj;

long long dp[111111];
long long ep[111111];

void dfs(int s, int p=-1){
    long long res = 1;
    for(int t : adj[s]){
        if(t == p) continue;
        dfs(t, s);
        res *= (dp[t]+1);
        res %= M;
    }
    dp[s] = res;
}

void efs(int s, int p=-1){
    ep[s] = 1;
    for(int t : adj[s]){
        ep[s] *= dp[t]+1;
        ep[s] %= M;
    }

    int sz = adj[s].size();
    vector<long long> lef(sz+2, 1), rig(sz+2, 1);
    for(int i=0; i<sz; i++){
        lef[i+1] = (lef[i] * (dp[adj[s][i]] + 1)) % M;
        rig[sz-i] = (rig[sz-i+1] * (dp[adj[s][sz-i-1]] + 1)) % M;
    }

    for(int i=0; i<sz; i++){
        int t = adj[s][i];
        if(t == p) continue;
        dp[s] = (lef[i] * rig[i+2]) % M;
        efs(t, s);
    }
}


int main(){
    cin >> N >> M;
    adj.resize(N);
    for(int i=0; i<N-1; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    dfs(0);
    efs(0);
    for(int i=0; i<N; i++)
        cout << ep[i] << endl;

    return 0;
}

Measured memory_bytes: 20608
#include<cstdio>

using namespace std;

#define N 10000001

bool vis[N];
long long prime[N];

long long t[N],e[N];

int main()
{
    int n;
    scanf("%d",&n);
    int cnt=0;
    t[1]=1;
    for(int i=2;i<=n;++i)
    {
        if(!vis[i])
        {
            prime[++cnt]=i;
            t[i]=2;
            e[i]=1;
        }
        for(int j=1;j<=cnt;++j)
        {
            if(i*prime[j]>n) break;
            vis[i*prime[j]]=true;
            if(i%prime[j]==0)
            {
                t[i*prime[j]]=t[i]/(e[i]+1)*(e[i]+2);
                e[i*prime[j]]=e[i]+1;
                break;
            }
            else 
            {
                t[i*prime[j]]=t[i]*2;
                e[i*prime[j]]=1;
            }
        }
    }
    long long ans=0;
    for(long long i=1;i<=n;++i) ans+=(i*t[i]);
    printf("%lld",ans);
}

Measured memory_bytes: 172936
import sys
import heapq

N,M = map(int,sys.stdin.readline().split())
jobList={}
for i in range(N):
  a,b = map(int,sys.stdin.readline().split())
  if a in jobList:
    jobList[a].append(b)
  else:
    jobList[a]=[b]
    
heapList=[]
heapq.heapify(heapList)
ans=0
for i in range (1,M+1):
  if i in jobList:
    for val in jobList[i]:
      heapq.heappush(heapList,val*-1)
  if len(heapList)>0:
    ans+=heapq.heappop(heapList)
print(ans*-1)



Measured memory_bytes: 68956
#include<cstdio>
#include<algorithm>
inline void read(int&r)
{
	register char c;r=0;
	do c=getchar();while(c<'0'||c>'9');
	do r=r*10+c-'0',c=getchar();while(c>='0'&&c<='9');
}
 
int a[100000];
int main()
{
	int n,c,k,t,i,f,s;read(n),read(c),read(k);
	if(c==1)return printf("%d\n",n),0;
	for(i=0;i<n;i++)read(a[i]);
	std::sort(a,a+n);
 
	s=t=1,f=*a;
	for(i=1;i<n;i++)
		if(a[i]-f>k||++t>c)s++,t=1,f=a[i];
	printf("%d\n",s);
}

Measured memory_bytes: 512
N,M = map(int,input().split())
S = [0]*M
C = [0]*M
for i in range(M):
    S[i],C[i] = map(int,input().split())
answer = -1
if N == 1:
    n=0
else:
    n=10**(N-1)
for i in range(n,10**N):
    count = 0
    for j in range(M):
        if int(str(i)[S[j]-1]) == C[j]:
            count += 1
        else:
            break
    if count == M:
        answer = i
        break
    else:
        continue
print(answer)

Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  string s;cin>>s;
  string ans;

  for(int i = 0; i < (int)s.size(); i++) {
    auto c = s[i];
    if(c == 'B') {
      if(ans.size() != 0) {
        ans.pop_back();
      }
      continue;
    }
    ans += c;
  }
  cout << ans << endl;
}


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

int main(){
  int n,t;
  cin >> n >> t;
  vector<pair<int,int>> a(n);
  vector<int> b;
  for(int i = 0; i < n; ++i){
    cin >> a[i].first >> a[i].second;
    if(a[i].second <= t){
      b.push_back(a[i].first);
    }
  }
  b.push_back(0);
  if(b[0] == 0){
    cout << "TLE" << endl;
  }else{
    sort(b.begin(),b.end());
    cout << b[1] << endl;
  }
}

Measured memory_bytes: 3576
n = int(input())
lst1 = list(map(int,input().split()))
lst1.sort()
for i in range(1,n):
    lst1[i] += lst1[i-1]



for i in range(n-1,0,-1):
    if lst1[i]-lst1[i-1] > lst1[i-1]*2:
        print(n-i)
        exit()

print(n)


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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n, m;
    cin >> n >> m;
    vector<int> s(n), t(m);
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];
    ll mod = 1e9 + 7;

    vector<vector<ll>> dp(n + 1, vector<ll>(m + 1)), u(n + 1, vector<ll>(m + 1));

    forx(i, 1, n + 1) forx(j, 1, m + 1)
    {
        if (s[i - 1] == t[j - 1])
            dp[i][j] = u[i - 1][j - 1] + 1;
        u[i][j] = (u[i - 1][j] + u[i][j - 1] - u[i - 1][j - 1] + dp[i][j] + mod) % mod;
    }

    cout << u[n][m]+1LL << endl;

    return 0;
}

Measured memory_bytes: 62976
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int main(){

  int x,y,z;
  int tri=0;
  int t=0;
  int e=0;
  int d=0;
  while(cin>>x>>y>>z){
    vector<int> v;
    v.push_back(x);
    v.push_back(y);
    v.push_back(z);
    sort(v.begin(),v.end());
    if(v[0]+v[1]<=v[2])break;
    else{
      tri++;
      if(v[0]*v[0]+v[1]*v[1]==v[2]*v[2])t++;
      else if(v[0]*v[0]+v[1]*v[1]>v[2]*v[2])e++;
      else d++;
    }
  }
  cout<<tri<<" "<<t<<" "<<e<<" "<<d<<endl;
  
  return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



bool solve() {
    string s, t;
    cin >> s >> t;
    int r[26], rd[26];
    fill_n(r, 26, -1);
    fill_n(rd, 26, -1);
    
    rep(i, sz(s)) {
        int a = s[i] - 'a';
        int b = t[i] - 'a';
        
        if (r[a] < 0) r[a] = b;
        else if (r[a] != b) return 0;
        
        if (rd[b] < 0) rd[b] = a;
        else if (rd[b] != a) return 0;
        
    }
    
    return 1;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cout << (solve() ? "Yes" : "No") << endl;
}



Measured memory_bytes: 916
from functools import lru_cache
n,x=map(int,input().split())
h=[1]
for i in range(1,n):
    h.append(2*h[i-1]+3)
@lru_cache(None)
def run(l,x):
    if x==0:
        return 0
    if l==0:
        return 1
    else:
        if x<=h[l-1]+1:
            return run(l-1,x-1)
        elif x==h[l-1]+2:
            return run(l-1,h[l-1])+1
        else:
            return run(l - 1, h[l - 1]) + 1 \
                 + run(l - 1, x - h[l - 1] - 2)
print(run(n,x))


Measured memory_bytes: 42352
#include <bits/stdc++.h>
using namespace std;
 
int n, maxC;
string s;
string str[200004];
int cnt[200004];
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	memset(cnt,0,sizeof(cnt));
	
	for(int i=0; i<n; i++)
		cin>>str[i];
	
	sort(str, str+n);
	str[n] = 'A';
	int lo = 0;
	for(int i=1; i<=n; i++){
		if(str[lo] != str[i]){
			cnt[lo] = i - lo;
			lo = i;
		}
	}
	
	maxC = *max_element(cnt, cnt+n);
	for(int i=0; i<n; i++){
		if(cnt[i]==maxC){
			cout<<str[i]<<"\n";
		}
	}
	return 0;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
#include <unordered_map>
#define inputarr(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define prllarr(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" ";
#define pb push_back
#define ll long long
#define mod 1000000007
#define foi ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define in(n) scanf("%lld",&n);
#define in2(x,y) scanf("%lld %lld",&(x),&(y));
#define in3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z));
#define out(n) printf("%lld\n",n);
#define out2(x,y) printf("%lld %lld\n",x,y);
#define test(t)  ll t; in(t);while(t--)
#define set(arr,n,s) for(ll i=0;i<n;i++){arr[i]=s;}


/*error-----
convert every int to long long eg-1LL
create array with proper analysis of problem constrain
check mod also
*/
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1){res=(res*x)%p;} y=y>>1;x=(x*x)%p;}return res;}
ll modInverse(ll a,ll p){return power(a,p-2,p);}//used with feemat little

ll gcd(ll x,ll y){if(x==0 || y==0){return max(y,x);}return gcd(y%x,x);}
ll gcdExtended(ll a,ll b,ll &x,ll &y){if(a==0){x=0;y=1;return b;}ll x1,y1;ll gcd = gcdExtended(b%a,a,x1,y1);x=y1-(b/a)*x1;y=x1;return gcd;}//o(log(b))
;
ll arr[3004];
ll dp[3004][3004];
int main()
{
	ll n;
	in(n)
	for(ll i=0;i<n;i++){
		in(arr[i])
	}
	for(ll i=0;i<n;i++){
		dp[i][i]=arr[i];
	}
	for(ll sum=2;sum<=n;sum++){
		for(ll i=0;i<n;i++){
			ll end=i+sum-1;
			if(end>=n)break;
			dp[i][end]=max(arr[i]-dp[i+1][end],arr[end]-dp[i][end-1]);

		}
	}
	cout<<dp[0][n-1]<<endl;

}






Measured memory_bytes: 70016
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
const int M=300;
int N,x,y;
int dp[101][301][601];
int main(){
	cin>>N>>x>>y;
	rep(i,N+1) rep(j,301) rep(k,601) dp[i][j][k]=-1;
	dp[0][0][M]=0;
	rep(i,N){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		rep(j,301) rep(k,601) if(dp[i][j][k]>=0){
			chmax(dp[i+1][j][k],dp[i][j][k]);
			if(j+a<=x) chmax(dp[i+1][j+a][k-b],dp[i][j][k]);
			chmax(dp[i+1][j][k+c],dp[i][j][k]+d);
		}
	}
	int ans=0;
	rep(j,x+1) rep(k,601) if(k-M<=y) chmax(ans,dp[N][j][k]);
	cout<<ans<<endl;
}

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

int main()
{
  int N,K;
  cin >> N >> K;
  char S[N+1];
  cin >> S;
  if(S[K-1] == 'A')
    S[K-1] = 'a';
  if(S[K-1] == 'B')
    S[K-1] = 'b';
  if(S[K-1] == 'C')
    S[K-1] = 'c';
  cout << S << endl;
  return 0;
}
  
  


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

int n, m;
int a[300][300];
int curr[300] = { 0 }; // n

int occ[300] = { 0 }; // m
bool rem[300] = { false }; // m

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

	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j) {
			cin >> a[i][j];
			--a[i][j];
		}

	for (int i = 0; i < n; ++i)
		++occ[a[i][0]];

	int ans = n;
	for(;;) {
		int i = max_element(occ, occ + m) - occ;
		ans = min(ans, occ[i]);
		rem[i] = true;
		for (i = 0; i < n; ++i) {
			while (rem[a[i][curr[i]]]) {
				--occ[a[i][curr[i]]];
				if (++curr[i] >= m) {
					cout << ans;
					return 0;
				}
				++occ[a[i][curr[i]]];
			}
		}
	}
	return 0;
}

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

using namespace std;

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

#define MAX_N 2002
#define MAX_M 2002

int main() {
  int n, m;
  int pt[3][MAX_N];
  cin >> n >> m;
  rep(i, n) rep(j, 3) cin >> pt[j][i];

  double app[MAX_M];
  app[0] = 1;
  rep(i, m) {
    for(int j = i; j >= 0; --j) {
      app[j+1] += app[j]/3.0;
      app[j] *= 2.0/3.0;
    }
  }
  double sum[MAX_M];
  sum[0] = app[0];
  rep(i, m) sum[i+1] = sum[i]+app[i+1];

  double dp[3][MAX_M][4];
  fill((double*)dp[0], (double*)dp[3], 0.0);
  rep(i, 3) {
    rep(j, m+1) {
      dp[i][j][0] = dp[i][j][3] = 1.0;
      reps(k, 1, n) {
	int idx = (pt[i][0]*j+pt[i][k]-1)/pt[i][k] - 1;
	double p = idx < 0 ? 0 : sum[min(m, idx)];
	for(int l = 2; l >= 0; --l) {
	  if(l < 2) dp[i][j][l+1] += dp[i][j][l]*(1.0-p);
	  dp[i][j][l] *= p;
	}
	dp[i][j][3] *= 1.0-p;
      }
    }
  }

  double ev[3][MAX_M];
  const int get[3] = {5, 3, 2};
  rep(i, 3) {
    rep(j, m+1) {
      ev[i][j] = (dp[i][j][0]+dp[i][j][1]+dp[i][j][2])*get[i] - dp[i][j][3];
    }
  }

  double ans = -DBL_MAX/2;
  rep(i, m+1) {
    rep(j, m+1) {
      int k = m-i-j;
      if(k < 0) continue;
      ans = max(ans, ev[0][i]+ev[1][j]+ev[2][k]);
    }
  }
  printf("%.12f\n", ans);

  return 0;
}



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

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

    double probability = 0;
    int num = 0;
    int cnt = 0;

    for(int i = 1; i <= N; i ++){
        for(int j = 0; j <= K; j ++){
            if(K <= i * pow(2,j)){
                if(i == 1){
                    num = j;
                    probability = N * pow(2,num);
                }
                cnt += pow(2,num-j);
                break;
                
            }
        }
    }

    probability = cnt / probability;

    cout << fixed << setprecision(10);
    cout << probability << endl;

}

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

namespace ABC061A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B, C, X, Y;

            var word = Console.ReadLine().Split(' ');

            A = int.Parse(word[0]);
            B = int.Parse(word[1]);
            C = int.Parse(word[2]);

            if (A <= C && B >= C)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
n,q=gets.split.map(&:to_i)
s=gets.chomp
k=[0,0]
(n-1).times do |i|
  if s[i,2]=="AC"
    k[i+2]=k[i+1]+1
  else
    k[i+2]=k[i+1]
  end
end
q.times do
  l,r=gets.split.map(&:to_i)
  puts k[r]-k[l]
end


Measured memory_bytes: 3452