akhauriyash/Code-Regression huggingface dataset:
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

//#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        ((a)*((b)/gcd((a),(b))))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=3e3+5;

// dp[i][j] -> max. value considering i items having at most j weight
int dp[N][N];

void solve()
{
    mem(dp,0);

    int n,t;
    cin>>n>>t;

    vector<pii> v(n+1);
    for(int i=1;i<=n;++i)
        cin>>v[i].F>>v[i].S;

    sort(all(v));

    int ans=0;
    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<t;++j)
            ans=max(ans,dp[i-1][j]+v[i].S);

        for(int j=0;j<t;++j)
        {
            if(j-v[i].F>=0)
                remax(dp[i][j],dp[i-1][j-v[i].F]+v[i].S);

            remax(dp[i][j],dp[i-1][j]);
            if(j) remax(dp[i][j],dp[i][j-1]);
        }
    }

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX

int main() {
  cin.sync_with_stdio(false);
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = INF, tmp;
  if (x < y) swap(a, b), swap(x, y);
  rep(i, x + 1) {
    tmp = a * i + (x - i) * c * 2 + max(0, y - (x - i)) * b;
    minch(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


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


void print(int* a, int n)
{
	int i = 0;
	for (i; i < n; i++)
	{
		if (i > 0)
			cout << ' ';
		cout << a[i];
	}
	cout << endl;
}

void inssert(int* a, int n)
{
	int i, j, v;
	for (int i = 1; i < n; i++)
	{
		v = a[i];
		j = i - 1;
		while (j >= 0 && a[j] > v)
		{
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		print(a, n);
	}
}

int main()
{
	int n, i, j;
	int a[100];
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	print(a, n);
	inssert(a, n);
	return 0;
}


Measured memory_bytes: 3120
import bisect
import itertools

N, M  = map(int,input().split())
A = sorted(list(map(int,input().split())))
D = []

for i in range(M):
    B, C = map(int,input().split())
    D.append((B,C))

D.sort(key = lambda x:x[1],reverse = True)

cnt = 0
ans = []
for b, c in D:
    for i in range(b):
        ans.append(c)
    cnt += b
    if cnt >=N:
        break
#print(D)
#print(ans)
res = sum(A)
for i in range(min(N,len(ans))):
    if ans[i]-A[i]>0:
        res += ans[i] - A[i]
    else:
        break
print(res)

Measured memory_bytes: 80792
#include<stdio.h>
int main() {
	int N;
	scanf("%d", &N);
	int **A = (int **)malloc(sizeof(int*) * 2);
	for (int i = 0; i < 2; i++)
	{
		A[i] = (int *)malloc(sizeof(int) * N);
	}
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < N; j++)
		{
			scanf("%d", &A[i][j]);
		}
	}
	//for (int i = 0; i < 2; i++)
	//{
	//	for (int j = 0; j < N; j++)
	//	{
	//		printf("%d ", A[i][j]);
	//	}
	//	printf("\n");
	//}
	int k, l, m, sum = 0, tmp = 0;
	int ans = 0;
	for (m = 0; m < N; m++) {
		k = 0;
		while (k <= m) {
			sum += A[0][k];
			k++;
		}
		l = m;
		while (l < N) {
			sum += A[1][l];
			l++;
		}
		if (tmp < sum) {
			tmp = sum;
		}
		sum = 0;
	}

	ans = tmp;
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
    int x = 10000;
    int n;
    for(int i = 0; i < x; i++){
        cin >> n;
        if(n == 0){
            break;
        }
        cout << "Case " << i + 1 << ": " << n << endl;

    }
    return 0;
}


Measured memory_bytes: 3020
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int c[10][10];
int H, W, A, ans;

int main()
{
    scanf("%d%d", &H, &W);
    for (int i = 0; i < 10; i++)
        for (int j = 0; j < 10; j++)
            scanf("%d", &c[i][j]);
    for(int k=0;k<10;k++)
        for(int i=0;i<10;i++)
            for (int j = 0; j < 10; j++) {
                if (c[i][j] > c[i][k] + c[k][j])
                    c[i][j] = c[i][k] + c[k][j];
            }
    ans = 0;
    for(int i=0;i<H;i++)
        for (int j = 0; j < W; j++) {
            scanf("%d", &A);
            if (A >= 0)
                ans += c[A][1];
        }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;
lli dist[2000009];
lli dp[3009][3009][2];
string str1,str2,str;
lli cnt,flag;
vector<char>vect;
lli mp1[3009],mp2[3009];
map<lli,lli>mp3,mp4;


void path(lli n1,lli n2)
{
    if(n1<0||n2<0)
        return ;

    if(str1[n1]==str2[n2]&&mp1[n1]==0&&mp2[n2]==0)
    {
        //vect.push_back(str1[n1]);
        str+=str1[n1];
        mp1[n1]=1;
        mp2[n2]=1;
    }

    if(dp[n1][n2][1]==1)
        path(n1-1,n2);
    else if(dp[n1][n2][1]==2)
        path(n1,n2-1);
    else
        path(n1-1,n2-1);

}



lli solve(lli n1,lli n2)
{
    if(dp[n1][n2][0]!=-1)
         return dp[n1][n2][0];
         
         if(n1<0||n2<0)
            return 0;

    lli ans1=0,ans2=0,ans3=0,res;

     //ans1=solve(n1-1,n2);
     //ans2=solve(n1,n2-1);
     //ans3=(str1[n1]==str2[n2])+solve(n1-1,n2-1);

     if(str1[n1]==str2[n2])
     {
         ans3=1+solve(n1-1,n2-1);
         dp[n1][n2][1]=3;
         return dp[n1][n2][0]=ans3;
     }
     else
     {
         ans1=solve(n1-1,n2);
         ans2=solve(n1,n2-1);
         res=max(ans1,ans2);
         if(ans1==res)
            dp[n1][n2][1]=1;
         else
            dp[n1][n2][1]=2;
        return dp[n1][n2][0]=res;
     }

     /*

     res=max(max(ans1,ans2),ans3);

     if(ans1==res)
         dp[n1][n2][1]=1;
     else if(ans2==res)
         dp[n1][n2][1]=2;
     else
         dp[n1][n2][1]=3;
         */

     //return dp[n1][n2][0]=res;;
}


int main()
{
    int start_s = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    lli i,j,k,value=0,n,m,q,t,a,b,c,maxi=INT_MIN,mini=INT_MAX,sum=0,ans=0,res=0,val=0,ans1=0,ans2=0,rem=0,diff=0,l,r,e,index,val1=0,val2=0,x,y,z,h=0,u,v,mid,len,tot,fl=0;

    cin>>str1;
    cin>>str2;

    for(i=0;i<str1.size();i++)
    {
        mp3[str1[i]-'a']++;
    }
    for(i=0;i<str2.size();i++)
    {
        mp4[str2[i]-'a']++;
    }
    for(i=0;i<=25;i++)
    {
        //cout<<"i="<<i<<" "<<"mp3="<<mp3[i]<<" "<<"mp="<<mp4[i]<<endl;
        if(mp3[i]==0||mp4[i]==0)
            value++;
    }

    if(value==26)
        return 0;
        
        memset(dp,-1,sizeof(dp));

    cnt=solve(str1.size()-1,str2.size()-1);

    if(cnt==0)
        return 0;

    path(str1.size()-1,str2.size()-1);

     //for(i=vect.size()-1;i>=0;i--)
       // cout<<vect[i];
    reverse(str.begin(),str.end());
    cout<<str;
}



Measured memory_bytes: 143744
N = int(input())
A = list(map(int, input().split()))

total_costs = {}
if( len(set(A)) == 1 ):
    print(0)
else:
    for i in range(-100, 101):
        cost = 0
        for a in A:
            cost += (a - i)*(a - i)
        total_costs[i] = cost
    print(min(total_costs.values()))

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

int main() {
    ll H, W;
    cin >> H >> W;

    ll ans = 999999;
    rep(h, H) {
        ll A   = h * W;
        ll B1  = ((H - h) / 2) * W;
        ll C1  = H * W - (A + B1);
        ll mn1 = max({A, B1, C1}) - min({A, B1, C1});

        ll B2  = (H - h) * (W / 2);
        ll C2  = H * W - (A + B2);
        ll mn2 = max({A, B2, C2}) - min({A, B2, C2});

        ans = min({ans, mn1, mn2});
    }

    rep(w, W) {
        ll A   = H * w;
        ll B1  = H * ((W - w) / 2);
        ll C1  = H * W - (A + B1);
        ll mn1 = max({A, B1, C1}) - min({A, B1, C1});

        ll B2  = (H / 2) * (W - w);
        ll C2  = H * W - (A + B2);
        ll mn2 = max({A, B2, C2}) - min({A, B2, C2});

        ans = min({ans, mn1, mn2});
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int N,A,B,C,D,x,y;
    cin>>N>>A>>B>>C>>D;
    x=ceil((double)N/A)*B;
    y=ceil((double)N/C)*D;
    
    
    
    
    
    cout<<min(x,y)<<endl;
    return 0;
}



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

int main(){
	int a,b,c;
	int ans;
	
	string cunning="7767555555555555555555555555555555555555545555555555555555555555555555555555555555555555555555555555555";
	
	for(int i=0;i<104;i++){
		cin>>a>>b;c=a+b;
		//-----test-----
		if(i<cunning.size()){
			cout<<cunning[i]<<endl;
			continue;
		}
		//--------------
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

bool dp[80][80][12810];
ll geta=6405;
ll A[80][80];
ll B[80][80];
//--MAIN-----------------------------------
void Main() {
    ll H,W; cin>>H>>W;
    rep(i,H){
        rep(j,W){
            cin>>A[i][j];
        }
    }
    rep(i,H){
        rep(j,W){
            cin>>B[i][j];
        }
    }
    dp[0][0][geta-A[0][0]+B[0][0]]=true;
    dp[0][0][geta+A[0][0]-B[0][0]]=true;
    rep(i,H){
        rep(j,W){
            rep(k,12810){
                if(i!=0){
                    if(k+A[i][j]-B[i][j]<=12809 and k+A[i][j]-B[i][j]>=0 and dp[i-1][j][k+A[i][j]-B[i][j]]){
                        dp[i][j][k]=true;
                    }
                    if(k-A[i][j]+B[i][j]<=12809 and k-A[i][j]+B[i][j]>=0 and dp[i-1][j][k-A[i][j]+B[i][j]]){
                        dp[i][j][k]=true;
                    }
                }
                if(j!=0){
                    if(k+A[i][j]-B[i][j]<=12809 and k+A[i][j]-B[i][j]>=0 and dp[i][j-1][k+A[i][j]-B[i][j]]){
                        dp[i][j][k]=true;
                    }
                    if(k-A[i][j]+B[i][j]<=12809 and k-A[i][j]+B[i][j]>=0 and dp[i][j-1][k-A[i][j]+B[i][j]]){
                        dp[i][j][k]=true;
                    }
                }
            }
        }
    }

    ll ans=INF2;
    rep(i,12810){
        if(dp[H-1][W-1][i]){
            mini(ans,abs(i-geta));
        }
    }

    cout<< ans<<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 80000
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <map>
#include <bitset>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+" ";
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
constexpr const ll INF = 1e15;
constexpr const ll MOD = 1000000007;
constexpr int nx[4] = {1,0,-1,0};
constexpr int ny[4] = {0,1,0,-1};
typedef pair<ll,ll> P;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    Yes((s[0] == s[1] && s[1] == s[2]) || (s[3] == s[2] && s[1] == s[2]));
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#define Number 1000001
using namespace std;

int getDigit(int num){
  int cnt=0;
  do{
    cnt++;
    num*=0.1;
  }while(num!=0);
  return cnt;
}

int getMax(int num){
  int digit=getDigit(num);
  int max=0;
  for(int i=1;i<digit;i++){
    int sp=pow(10,i);
    int l=num/sp;
    int r=num%sp;
    if(max < l*r) max = l*r;
  }
  return max;
}

int solve(int num){
  bool table[Number]={false};
  int cnt=0;
  if(num >= Number) return 0;
  table[num]=true;
  while(true){
    if(num < 10) return cnt;
    num=getMax(num);
    if(num >= Number) return 0;
    if(table[num]) return 0;
    else{
      cnt++;
      table[num]=true;
    }
  }

}

int main(){
  int n;
  cin>>n;
  while(n--){
    int q;
    cin>>q;
    cout<<solve(q)<<endl;
  }
  return 0;
}

Measured memory_bytes: 2188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main
{
    public static void main(String[] args)throws IOException {
        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
        String[]s=bufferedReader.readLine().split( " ");
        long k=Long.parseLong(s[0]),a=Long.parseLong(s[1]),b=Long.parseLong(s[2]);
        List<Long>list=new ArrayList<>();
        list.add(k+1);
        k-=((a-1)+2);
        long ans = 0;
        if(k==0)
            ans=b;
        if(k>0 && b>a) {
            ans = b;
            while (k > 1) {
                ans -= a;
                ans += b;
                k-=2;
            }
        }
        if(k==1)
            ans++;
        list.add(ans);
        System.out.println(Collections.max(list));
    }
}

Measured memory_bytes: 23892
import sys
import math
import collections
import bisect
import itertools
import decimal

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
# MOD = 10 ** 9 + 7
MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===
def prime_factorize(n):
    two = 0
    five = 0
    while n % 2 == 0:
        two += 1
        n //= 2

    while n % 5 == 0:
        five += 1
        n //= 5

    return two, five


def main():
    n = ni()
    a = [int(decimal.Decimal(input()) * (10 ** 9)) for _ in range(n)]
    res = {}
    border = 18

    twoflg = False
    fiveflg = False
    for ai in a:
        two, five = prime_factorize(ai)

        if two >= 9:
            twoflg = True
        if five >= 9:
            fiveflg = True

        if (two, five) not in res.keys():
            res[(two, five)] = 1
        else:
            res[(two, five)] += 1

    ans = 0
    if twoflg and fiveflg:
        for k, v in res.items():
            two, five = k
            for tk, tv in res.items():
                t_two, t_five = tk
                if two + t_two >= border and five + t_five >= border:
                    if two == t_two and five == t_five:
                        ans += v * (tv - 1)
                    else:
                        ans += v * tv

    print(ans // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 276920
#include <stdio.h>

#define N 100000

typedef struct{
  char mark;
   int num;
   int check;
}Card;

int partition(Card *,int,int);
void quicksort(Card *,int,int);

int main(){

  int i;
  int n;
  int judge=0;
  Card sum[N];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
  scanf(" %c%d",&sum[i].mark,&sum[i].num);
  sum[i].check = i;
  }

  quicksort(sum,0,n-1);

  for(i=0;i<n-1;i++){
    if(sum[i].num == sum[i+1].num && sum[i].check > sum[i+1].check){
      judge = 1;
      break;
    }
  }

  if(judge==1){
    printf("Not stable\n");
  }
  else{
    printf("Stable\n");
  }
  
  for(i=0;i<n;i++){
  printf("%c %d\n",sum[i].mark,sum[i].num);
  }
  
  return 0;
}

  int partition(Card *A,int p,int r){

   int i;
   int j;
  Card x;
  Card tmp;
  
   x = A[r];
   i = p-1;
   
  for(j=p;j<=r-1;j++){
    if(A[j].num <= x.num){
      i = i+1;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }    
     tmp = A[i+1];
  A[i+1] = A[r];
    A[r] = tmp;

   return i+1;
}

void quicksort(Card *A,int p,int r){

  int q;
  
  if(p < r){
  q = partition(A, p, r);
  quicksort(A, p, q-1);
  quicksort(A, q+1, r);
  }
}

Measured memory_bytes: 1776
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        long k = in.nextLong();
        k--;

        for (long i = 0; i < s.length(); i++) {
            if (s.charAt((int)i) != '1') {
                System.out.println(s.charAt((int)i));
                return;
            }

            if (i == k) {
                System.out.println(1);
                return;
            }
        }

        System.out.println(s.charAt(s.length() - 1));
    }
}

Measured memory_bytes: 35576
#include<bits/stdc++.h>
 
#define REP(i,a,b) for(int i=a,i##_end_=b;i<=i##_end_;++i)
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
typedef long long ll;
 
using namespace std;
 
void File(){
	freopen("ARC074E.in","r",stdin);
	freopen("ARC074E.out","w",stdout);
}
 
template<typename T>void read(T &_){
	T __=0,mul=1; char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')mul=-1;
		ch=getchar();
	}
	while(isdigit(ch))__=(__<<1)+(__<<3)+(ch^'0'),ch=getchar();
	_=__*mul;
}
 
const int maxn=310;
const ll mod=1e9+7;
int n,m;
vector<pii>qu[maxn];
ll dp[maxn][maxn][maxn],ans;
 
void init(){
	read(n); read(m);
	int l,r,x;
	REP(i,1,m){
		read(l); read(r); read(x);
		qu[r].push_back(mk(l,x));
	}
}
 
void work(){
	dp[0][0][0]=1;
	REP(i,0,n)REP(j,0,n)REP(k,0,n){
		if((i && i==j) || (j && j==k) || (k && i==k))continue;
		int nex=max(i,max(j,k))+1,r=nex-1;
		bool flag=true;
		REP(f,0,qu[r].size()-1){
			int l=qu[r][f].fi,x=qu[r][f].se,cnt=0;
			if(i && i>=l)++cnt;
			if(j && j>=l)++cnt;
			if(k && k>=l)++cnt;
			if(cnt!=x){
				flag=false;
				dp[i][j][k]=0;
				break;
			}
		}
		if(!flag)continue;
		(dp[nex][j][k]+=dp[i][j][k])%=mod;
		(dp[i][nex][k]+=dp[i][j][k])%=mod;
		(dp[i][j][nex]+=dp[i][j][k])%=mod;
		if(r==n)(ans+=dp[i][j][k])%=mod;
	}
	printf("%lld\n",ans);
}
 
int main(){
	//File();
	init();
	work();
	return 0;
}

Measured memory_bytes: 227584
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define debug(x) cout<<#x<<": "<<x<<" "
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
const int N=200010;
int a[N],n,k;
bool check(int mid)
{
    ll res=0;
    for(int i=1;i<=n;i++) res+=(a[i]+mid-1)/mid-1;
    return res<=k;
}
int main()
{
    IO;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    int l=1,r=1e9;
    while(l<r)
    {
        int mid=l+r>>1;
        if(check(mid)) r=mid;
        else l=mid+1;
    }
    
    cout<<l<<endl;
    return 0;
}


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

typedef long long ll;

ll N;
ll Res;

int main() {
  cin >> N;
  for (ll p = 2; p * p <= N; ++p) {
    if (N % p == 0) {
      ll c = 0;
      while (N % p == 0) {
        N /= p;
        ++c;
      }
      for (ll i = 1; i <= c; ++i) {
        c -= i;
        ++Res;
      }
    }
  }
  if (N != 1) ++Res;
  cout << Res << endl;
  return 0;
}


Measured memory_bytes: 3608
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T>
// using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define sfind(i) (*find_by_order(i))
// #define ord(i) order_of_key(i)
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define vi vector<int>
#define vl vector<ll>
#define _max(vec) (*max_element(all(vec)))
#define _min(vec) (*min_element(all(vec)))
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'  //....????
#define int ll
vector<ll> ft(1, 1LL);

/*======================================================================*/

int val[3005][3005];
int dp [3005][3005][4];
void solve(){
    // int n, k, ans = -1e18;
    // cin >> n >> k;
    // vi v(n+1), c(n+1);
    // rep(i, 1, n+1)cin >> v[i];
    // rep(i, 1, n+1)cin >> c[i];
    // rep(i, 1, n+1){
    //     int cur = i, temp = 0;
    //     rep(j, 0, k){
    //         cur = v[cur];
    //         if(v[cur] == cur){
    //             if(c[cur] < 0){
    //                 if(j == 0)temp += c[cur];
    //             }
    //             else temp += (k-j)*c[cur];
    //             break;
    //         }
    //         else temp += c[cur];
    //         ans = max(temp, ans);
    //     }
    //     ans = max(temp, ans);
    // }
    // cout << ans << endl;
    int r, c, k;
    cin >> r >> c >> k;
    rep(i, 0, r+1)rep(j, 0, c+1)val[i][j] = 0;
    rep(i, 0, k){
        int a, b, c;
        cin >> a >> b >> c;
        val[a][b] = c;
    }
    rep(i, 0, r+1)rep(j, 0, c+1)rep(k, 0, 4)dp[i][j][k] = 0;
    int ans = 0;
    rep(i, 1, r+1){
        rep(j, 1, c+1){
            dp[i][j][0] = max({dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2],dp[i-1][j][3], dp[i][j-1][0]});
            dp[i][j][1] =  max({dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3]}) + val[i][j];
            rep(k, 1, 4){
                dp[i][j][k] = max({dp[i][j-1][k-1] + val[i][j], dp[i][j][k], dp[i][j-1][k]});
            }
        }
    }
    rep(i, 0, r+1)rep(j, 0, c+1)rep(k, 0, 4)ans = max(dp[i][j][k], ans);
    cout << ans << endl;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 355728
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;// pair型は２つの値の組を表せる

int main(){
    int A,B,C; cin >> A >> B >> C;
    bool ans=false;
    if (A==B && A!=C) ans=true;
    if (B==C && B!=A) ans=true;
    if (A==C && C!=B) ans=true;
    
    if (ans) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
using namespace std;


int main()
{
	int k, x;
	cin >> k >> x;

	for(int i=x-k+1; i<x+k; i++){
		cout << i << " ";
	}
	cout << endl;

	return 0;
}

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

using namespace std;
#define int long long
int MOD = 1000000007;

signed main(){
    int A,B,K;
    cin >> A >> B >> K;
    
    int k = K;
    for(int i=0;i<k;i++){
        if(K>0){
            if(A%2!=0) A -= 1;
            A /= 2;
            B += A;
            K--;
        }
        
        if(K>0){
            if(B%2!=0) B -= 1;
            B /= 2;
            A += B;
            K--;
        }
        
    }
    
    cout << A << " " << B << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>	//cout << fixed << setprecision(桁数);

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define All(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
const int INF = 1000000000;
//#define int long long
template<class T> void chmax(T& a, T b) { if (a < b) a = b; }
template<class T> void chmin(T& a, T b) { if (a > b) a = b; }

/*****/

int N, A, B, C;
vector<int> L;

int rec(int i, int a, int b, int c) {
	if (i == N) {
		if (!a || !b || !c) return INF; // A, B, C いずれも竹は 1 本は必ず使ってないとダメ
		return abs(a - A) + abs(b - B) + abs(c - C); // 合体してできた a, b, c を A, B, C にするコスト
	}

	// 今ある竹を採用しない場合
	int res = rec(i + 1, a, b, c);

	// A, B, C を使う場合。
	// (a ? 10 : 0) とかは、最初の 1 本目は合体コストなし、2 本目からはコスト 10 かかることを意味する
	chmin(res, rec(i + 1, a + L[i], b, c) + (a ? 10 : 0));
	chmin(res, rec(i + 1, a, b + L[i], c) + (b ? 10 : 0));
	chmin(res, rec(i + 1, a, b, c + L[i]) + (c ? 10 : 0));

	return res;
}

int main()
{
	cin >> N >> A >> B >> C;
	L.resize(N);
	rep(i, N)	cin >> L.at(i);

	cout << rec(0, 0, 0, 0) << endl;

	return 0;
}


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

using namespace std;

int main(void)
{
	string a,b;
	cin >> a >> b;
	if(a.size()>b.size())
	{
		cout << "GREATER" << endl;
		return 0;
	}
	if(a.size()<b.size())
	{
		cout << "LESS" << endl;
		return 0;
	}
	cout << (a>b ? "GREATER" : a<b ? "LESS" : "EQUAL") << endl;
}

Measured memory_bytes: 256
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

// const ll MOD = (ll)1e9+7;
const ll MAX = (ll)6e3+10;



int main(void) {
   int a;
   cin>>a;
   string S;
   cin>>S;
   char ans[(ll)1e4+10];
   rep(i,0,S.size()) {
      ans[i] = S[i]+a;
      if ((int)ans[i] >(int)'Z') ans[i] = ans[i]-26;
   }
   rep(i,0,S.size()) cout<<ans[i];
   cout<<endl;
}



Measured memory_bytes: 256
import java.util.*;

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

        int sum = 0;
        int count = 1;
        while(sum < N){
            sum += count;
            count++;
        }
        
       for(int i = 1; i < count; i++){
           if(i != sum - N)
                System.out.println(i);
       }
    }
}

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

Measured memory_bytes: 256
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split()))

tmax = sum(T)
Vmax = max(V)
dp = [[-1 * float('inf') for _ in range(Vmax + 1)] for _ in range(tmax)]
dp[0][0] = 0
i = 0
j = 0
vmax = V[0]
for t in range(1, tmax):
    i += 1
    if i == T[j] + 1:
        i = 1
        j += 1
        vmax = V[j]
    for v in range(1, vmax + 1):
        acc = dp[t - 1][v - 1] + v - 0.5 if v != 0 else 0.5
        if v < vmax:
            same = dp[t - 1][v] + v + 0.25
            bra = dp[t - 1][v + 1] + v + 0.5
        else:
            same = dp[t - 1][v] + v
            bra = -float('inf')
        dp[t][v] = max(acc, same, bra)

if tmax == 1:
    print(0.25)
else:
    print(dp[-1][1] + 0.5)


Measured memory_bytes: 53596
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#define INF 1000000007
using namespace std;
using P = pair<int, int>;
using ll = long long;
int main(){
    ll n;
    cin>>n;
    ll ans=0;
    ans+=n/11*2;
    if(n%11==0)ans+=0;
    else if(n%11<=6)ans+=1;
    else ans+=2;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<vc> vcc;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 7;
void solve(){
    int n, m;  cin>>n>>m;
    vvi v(n,vi());
    for(int i = 0; i < n; i++){
        int k; cin>>k;
        for(int j = 0; j < k; j++){
            int t; cin>>t;
            v[i].pb(t);
        }
    }
    int ans=0;
    for(int i = 1; i <= m; i++){
        bool ever=true;
        for(int j = 0; j < n; j++){
            bool exists=false;
            for(int k = 0; k < v[j].size(); k++){
                if(v[j][k]==i) exists=true;
            }
            if(!exists) ever=false;
        }
        if(ever) ans++;
    }
    cout<<ans;
}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
		public static void main(String[] args) {
			
			Scanner sc = new Scanner(System.in);
			
			int N = sc.nextInt();
			String S = sc.next();
			
			int a = S.length();
			
			S = S.replaceAll("ABC", "");
			
			int b = S.length();
			
			int c = (a - b) / 3 ;
			System.out.println(c);
		}
}

Measured memory_bytes: 23764
using System;
using System.Linq;

namespace ITP1_7_A
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var input = Console.ReadLine().Split(' ');
                if (input.All(s => s == "-1"))
                    break;

                var m = int.Parse(input[0]);
                var f = int.Parse(input[1]);
                var r = int.Parse(input[2]);
                Console.WriteLine(CheckRank(m, f, r));
            }
        }

        static string CheckRank(int m,int f,int r)
        {
            var score = m + f;
            if (m == -1 || f == -1)
                return "F";
            if (score >= 80)
                return "A";
            if (65 <= score && score < 80)
                return "B";
            if (50 <= score && score < 65)
                return "C";
            if (30 <= score && score < 50)
                return r >= 50 ? "C" : "D";
            return "F";
        }
    }
}

Measured memory_bytes: 9260
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <deque>
using namespace std;
using Graph = vector< vector<int> >;
using ll = long long int;

int cnt_depth[200010], pow2[200010];
const ll MOD = 1000000007;

struct Node {
    ll a, b, c;
    Node() {
        a = b = c = 0;
    }
    Node(ll x, ll y, ll z) : a(x), b(y), c(z) {}
};

Node merge(Node lhs, Node rhs) {
    Node res;
    res.a = (lhs.a * rhs.a) % MOD;
    res.b = ((lhs.a * rhs.b) % MOD + (lhs.b * rhs.a) % MOD) % MOD;
    res.c = 0;
    (res.c += lhs.c * (rhs.a + rhs.b + rhs.c)) %= MOD;
    (res.c += lhs.b * (rhs.b + rhs.c)) %= MOD;
    (res.c += lhs.a * rhs.c) %= MOD;
    return res;
}

deque<Node> solve(Graph &G, int cur, int depth=0) {
    cnt_depth[depth]++;
    deque<Node> res;

    int sz = 0;
    for(auto to : G[cur]) {
        auto nxt = solve(G, to, depth + 1);
        if(res.size() < nxt.size()) swap(res, nxt);

        for(size_t i=0; i<nxt.size(); i++) {
            res[i] = merge(res[i], nxt[i]);
        }
        sz = max<int>(sz, nxt.size());
    }

    for(int i=0; i<sz; i++) {
        (res[i].a += res[i].c) %= MOD;
        res[i].c = 0;
    }

    res.push_front(Node(1, 1, 0));
    return res;
}

int main() {
    ll N, ans = 0; cin >> N;

    Graph G(N+1);
    pow2[0] = 1, pow2[1] = 2;
    for(int i=1; i<=N; i++) {
        int par; cin >> par;
        G[par].push_back(i);
        pow2[i+1] = (pow2[i] * 2) % MOD;
    }

    auto deq = solve(G, 0);
    for(size_t i=0; i<deq.size(); i++) {
        (ans += deq[i].b * pow2[N + 1 - cnt_depth[i]]) %= MOD;
    }

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


Measured memory_bytes: 178304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
template<class T>vector<T> inarr(int s,int e, T init){
	vector<T> v;T x;
	for(int i=0;i<s;++i)v.push_back(init);
	for(int i=s;i<e;++i){cin>>x;v.push_back(x);}
	return v;
}

ll N,M;
vl A;

bool check(ll x){ // x以上の和: x<=ai+aj -> x-ai<=aj
	ll total = 0; // count_aj を集計
	for(auto ai:A){
		ll pos_aj = lower_bound(all(A), x-ai) - A.begin();
		ll count_aj = N; // aj に該当するデータの個数
		count_aj -= pos_aj;
		total += count_aj;
	}
	return total < M; // x以上の和 < M個?
}

ll solve(){
	sort(all(A));
	// binary search
	ll ng = 2*A[0], ok = 2*A[N-1]+1; // [ng,ok):[l.r)
	while(ng+1<ok){ // l+1 < r
		ll x = (ok+ng)/2; // x:mid
		if(check(x)) ok = x; // (x 以上の和 < M個)? ok=x: ng=x
		else ng = x;
	}
	// ng=x-1, ok=x
	vl csum(N+1); rp(i,0,N) csum[i+1] = csum[i] + A[i]; // 累積和A
	ll ans = 0;
	for(auto ai:A){ // ng<ai+aj -> ng-ai<aj
		ll pos_aj = upper_bound(all(A), ng-ai) - A.begin();
		ll count_aj = N - pos_aj;
		ans += count_aj * ai + (csum[N] - csum[pos_aj]);
		M -= count_aj;
	}
	ans += M * ng;
	return ans;
}

int main(){
	cin>>N>>M;
	A = inarr<ll>(0,N,0);
	cout<< solve() <<endl;
}


Measured memory_bytes: 1908
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

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

    for (int i = 0; i < n; i++)
    {
        cin >> q[i];
    }

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

    int ord_p = 0, ord_q = 0;

    int ord = 0;
    do
    {
        if (r == p)
        {
            ord_p = ord;
        }

        if (r == q)
        {
            ord_q = ord;
        }

        ord++;
    } while (next_permutation(r.begin(), r.end()));

    cout << abs(ord_p - ord_q) << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << (H-h)*(W-w) << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

signed main(){
	string s;
	cin >> s;

	int ans = 1e8;
	rep(i,s.size() - 2){
		ans = min(ans, abs(753 - static_cast<int>(stoi(s.substr(i,3)))));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

void main() {
    readln.chomp.pipe!(str =>
        (str.length%2==0) != (str.front==str.back)
    ).pipe!(a => a?"Second":"First").writeln;
}


Measured memory_bytes: 508
# https://atcoder.jp/contests/abc147/tasks/abc147_c
# 制約が少ない→全探索可能
# 全探索によって矛盾がない場合を探す

# 問題はどうやって矛盾しているかどうかをどうやって判別するか
# katei[i]で1のあるiが成り立っているか確かめれば良い(矛盾しなければ良い)
# つまり、ある人の発言において、正直者ものの{i} in {katei[i]==1}となる
# かつ、不親切ものの{i} not in {j|katei[i]==1}となればよい。


N = int(input())
syoujiki = []
fusin = []
for _ in range(N):
    a = int(input())
    syou = set()
    fusi = set()
    for _ in range(a):
        x, y = list(map(int, input().split()))
        if y == 1:
            syou.add(x - 1)  # 0 based inexにする
        else:
            fusi.add(x - 1)
    syoujiki.append(syou)
    fusin.append(fusi)


def is_ok(n):  # katei[i]はbinaryなのでnで表現しn>>iでアクセスすることにする。
    # 過程集合の作成
    ret = 0
    katei = set()
    for i in range(N):
        if (n >> i) % 2:  # その桁が1なら
            katei.add(i)
            ret += 1

    # for syou, fusi in zip(syoujiki, fusin):
    #     for s in syou:

    for i in katei:  # 仮定でおいたi番目の人の発言を考慮する
        cond1 = syoujiki[i].issubset(katei)  # ここがおかしい。いま言及しているものしか考えられない
        cond2 = fusin[i].isdisjoint(katei)
        # cond1とcond2を最後までみたいすときにtrueにしたい
        # →満たさないときにfalseにする
        if (not cond1) or (not cond2):
            return 0
    return ret


ans = 0
for katei in range(1 << N):
    ans = max(is_ok(katei), ans)

print(ans)


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


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int A,B;
  cin>>A>>B;
  int ans = max(A+B,A-B);
  ans = max(ans,A*B);
  cout<<ans;  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lint long long
#define P pair<int, int>

int main(){
    int N, x;
    
    cin >> N >> x;
    
    int a[N];
    
    for(int i = 0; i < N; ++i){
        cin >> a[i];
    }
    
    lint ans = 0;
    
    for(int i = 0; i < N - 1; ++i){
        if(a[i] + a[i + 1] > x){
            ans += (lint)a[i] + a[i + 1] - x;
            a[i + 1] = max(x - a[i], 0);
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 768
import heapq

#N,Mを取得
n,m = map(int,input().split())
#A_iを取得する…と見せかけて、A_iを-1倍したものをListで取得
a = list(map(lambda x:int(x)*(-1),input().split()))

#AをListから、priority queueと言うものに変換(コレはheap queueだけど、まあ同じ)
heapq.heapify(a)

for _ in range(m):  #割引券持ってるだけ使い続ける
    x = heapq.heappop(a) * -1       #priority queueの先頭の値(一番値が小さい)を取り出して、-1をかけて元の値に戻す。
    x //= 2     #割引する
    heapq.heappush(a,-1*x)      #   priority queueにお返しする(-1をかけなおして)。

#割引が終わったら、合計金額を取得する。
print(-sum(a))


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MOD = 1e9+7;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

const int MAXN = 500 + 3;
int H[MAXN][MAXN];
bool occ[MAXN][MAXN];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void dfs(int y, int x) {
    int z = H[y][x] + occ[y][x];
    for (int t = 0; t < 4; t++) {
        int ny = y + dy[t], nx = x + dx[t];
        if (H[ny][nx] > z) {
            H[ny][nx] = z;
            dfs(ny, nx);
        }
    }
}

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

    int n;
    cin >> n;

    // 外までの距離
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            H[i][j] = min(min(i, n + 1- i), min(j, n + 1 - j)) - 1;
            occ[i][j] = true;
        }
    }

    int res = 0;
    for (int it = 0; it < n * n; it++) {
        int id;
        cin >> id;
        int y = (id + n - 1) / n;
        int x = id % n;
        if (x == 0) x += n;
        res += H[y][x];
        occ[y][x] = false;
        dfs(y, x);
    }

    cout << res << endl;

    return 0;
}

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

namespace rika
{
	template <typename T>
	class edge
	{
	public:
		int to;
		T cost;

		edge() = default;
		edge( const edge<T>& ) = default;
		edge( edge<T> && ) = default;
		edge& operator =( const edge<T>& ) = default;
		edge& operator =( edge<T> && ) = default;

		~edge() = default;

		edge( int _to, T _cost ) : to( _to ), cost( _cost ) {}
	};
}

namespace rika
{
	namespace internal
	{
		template <typename TValue, typename TGraph>
		std::pair<TValue, int> visit( int from, int v, const TGraph &g )
		{
			auto r = std::make_pair( TValue(), v );
			try
			{
				for( auto it = g[v].begin(); it != g[v].end(); ++it )
				{
					if( it->to == from )
						continue;
					auto r2 = visit<TValue>( v, it->to, g );
					if( r2.first + it->cost >= r.first )
						r = std::make_pair( r2.first + it->cost, r2.second );
				}
			}
			catch (...) {
				printf("hoge\n");
			}
			return r;
		}
	}

	template <typename TValue, typename TGraph>
	TValue tree_diameter( const TGraph &g )
	{
		using namespace internal;
		auto r1 = visit<TValue>( -1, 0, g );
		auto r2 = visit<TValue>( -1, r1.second, g );
		return r2.first;
	}
}

#include<bits/stdc++.h>
using namespace std;
using namespace rika;
int main()
{
	int N;
	cin >> N;
	vector<vector<edge<int>>> g( N * 10 );
	for( int i = 0; i < N - 1; i++ )
	{
		int s, t, w;
		cin >> s >> t >> w;
		g[s].push_back( edge<int>( t, w ) );
		g[t].push_back( edge<int>( s, w ) );
	}
	cout << tree_diameter<int>( g ) << endl;
}

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


const int N=1e6,OO = 0x3f3f3f3f;
int d()
{
    int ret;
    scanf("%d", &ret);
    return ret;
}
long long lld()
{
    long long ret;
    scanf("%lld", &ret);
    return ret;
}

int main(){
    int a=d(),b=d(),c=d();
    if((a+b)>=c)
    puts("Yes");
    else
    puts("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef double ld;
typedef vi poly;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=105;
int f[N][N][N],t[N][N],C[N][N],coef[N][N][N],po[N][N*N];
int n,m,K;

namespace{
	int P;
	int fix(int x){
		return x>=P?x-P:x;
	}
	void add(int &x,int y){
		x=(x+y>=P?x+y-P:x+y);
	}
	int mul(int x,int y){
		return (ll)x*y%P;
	}
	int power(int x,int p){
		int res=1;
		for(;p;p>>=1,x=mul(x,x))
			if(p&1)res=mul(res,x);
		return res;
	}
}

void init(){
	C[0][0]=1;
	rep(i,1,100){
		C[i][0]=1;
		rep(j,1,100)
			C[i][j]=fix(C[i-1][j-1]+C[i-1][j]);
	}
	rep(i,1,100)rep(j,0,100){
		coef[i][j][0]=1;
		coef[i][j][1]=fix(power(i,j)+P-power(i-1,j));
		rep(k,2,100)
			coef[i][j][k]=mul(coef[i][j][k-1],coef[i][j][1]);
	}
	rep(i,0,100){
		po[i][0]=1;
		rep(j,1,10000)po[i][j]=mul(po[i][j-1],i);
	}
}

int main(){
	read(n),read(m);
	read(K),read(P);
	init(),f[0][0][0]=1;
	rep(k,0,K-1){
		memset(t,0,sizeof t);
		rep(i,0,n)rep(j,0,m)
			if(f[k][i][j])
				rep(x,0,n-i){
					int cc=mul(po[K-k][j*x],coef[k+1][m-j][x]);
					add(t[i+x][j],mul(f[k][i][j],mul(C[n-i][x],cc)));
				}
		rep(i,0,n)rep(j,0,m)
			if(t[i][j])
				rep(y,0,m-j){
					int cc=mul(po[k+1][(n-i)*y],coef[K-k][i][y]);
					add(f[k+1][i][j+y],mul(t[i][j],mul(C[m-j][y],cc)));
				}
	}
	printf("%d\n",f[K][n][m]);
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;

const ll INF = 1e18;

map<ll, ll> cache;

ll A, B, C, D;

ll calc(ll n) {
    if (n == 0) return 0;

    auto it = cache.find(n);

    if (it != cache.end()) {
        return it->second;
    }

    ll ans = INF;
    if (n <= INF/D) {
        ans = n*D;
    }

    int a = n%2, b = n%3, c = n%5;

    ans = min(ans, calc(n/2) + A + a*D);
    if (n > 2) {
        ans = min(ans, calc(n/2+1) + A + (2-a)*D);
    }

    ans = min(ans, calc(n/3) + B + b*D);
    if (n > 1) {
        ans = min(ans, calc(n/3+1) + B + (3-b)*D);
    }

    ans = min(ans, calc(n/5) + C + c*D);
    if (n > 1) {
        ans = min(ans, calc(n/5+1) + C + (5-c)*D);
    }

    return cache[n] = ans;
}

void solve() {

    ll n;
    cin >> n >> A >> B >> C >> D;
    cache.clear();
    cout << calc(n) << endl;

}

int main() {

    int T = 1;
    scanf("%d", &T);
    while (T--) solve();

    return 0;
}

Measured memory_bytes: 5012