akhauriyash/Code-Regression huggingface dataset:
using System;
class latte
{
    static void Main()
    {
        while (true)
        {
            string s = Console.ReadLine();
            if (s == null) break;

            string[] t = s.Split();
            int a = int.Parse(t[0]);
            int b = int.Parse(t[1]);
            int c = a + b;
            Console.WriteLine(c.ToString().Length);
        }
    }
}

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

int main(){

  int N,M;

  cin>>N>>M;

  int s[11][11];
  int k[11];
  
  int cnt[11]={ };
  
  for(int i=0;i<M;i++){
	cin>>k[i];

	for(int j=0;j<k[i];j++){
	  cin>>s[i][j];

	  cnt[s[i][j]]++;
	}
  }
  
  int ans=0;
  int p[11];

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


  int cnt1=0;

  int ansansans=0;
  while(1){

	if(cnt1>>(N)==0x01){
	  break;
	}
	
	int bit[10]={ };

	int ansans=1;
	for(int i=0;i<M;i++){

	  int ans=0;
	  for(int j=0;j<k[i];j++){

		if((cnt1>>(s[i][j]-1)) & 0x01){
		  ans++;
		}
	  }

	  if(ansans&&(ans%2==p[i])){
		ansans=1;
	  }else{
		ansans=0;
	  }
	  
	}

	if(ansans==1){
	  ansansans++;
	}

	cnt1++;
		
  }
  

  
  cout<<ansansans<<endl;

  
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int MOD = 1_000_000_007;
		char[] T = sc.next().toCharArray();
		int N = T.length;
		long[][] dp = new long[N+1][4];
		dp[0][0] = 1;
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < 4; j++)
				dp[i+1][j] = dp[i][j] % MOD;
			if(T[i] == 'A')
				dp[i+1][1] += dp[i][0];
			else if(T[i] == 'B')
				dp[i+1][2] += dp[i][1];
			else if(T[i] == 'C')
				dp[i+1][3] += dp[i][2];
			else {
				for(int j = 0; j < 4; j++)
					dp[i+1][j] *= 3;
				dp[i+1][1] += dp[i][0];
				dp[i+1][2] += dp[i][1];
				dp[i+1][3] += dp[i][2];
			}
		}
		System.out.println(dp[N][3] % MOD);
	}

}

Measured memory_bytes: 31160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

const int MAX_N = 2e5+10;
int N;
string s[MAX_N];

void solve()
{
	set<string> has;
	for(int i=0;i<N;++i)has.insert(s[i]);
	cout << has.size() << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i=0;i<N;++i)cin >>s[i];
	solve();
	return 0;
}


Measured memory_bytes: 25536
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
void print() { cout << "\n"; }
template <class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////

using bit = bitset<17>;
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,A,B; cin >> N >> A >> B;

    if (__builtin_popcount(A)%2==__builtin_popcount(B)%2) {
        cout << "NO" << ln;
        return 0;
    }
    cout << "YES" << ln;

    auto dfs=[](auto&& self, int n, bit a, bit b)->vector<bit> {
        if (!n) {
            vector<bit> ret = {a,b};
            return ret;
        }
        if (a.test(n)^b.test(n)) {
            auto c = a;
            c.flip(0);
            auto P = self(self,n-1,a,c);
            c.flip(n);
            auto Q = self(self,n-1,c,b);
            vector<bit> ret;
            int L = P.size();
            rep(i,L) ret.emplace_back(P[i]);
            rep(i,L) ret.emplace_back(Q[i]);
            return ret;
        } else {
            auto P = self(self,n-1,a,b);
            a.flip(n);
            auto c = P[1];
            c.flip(n);
            auto Q = self(self,n-1,a,c);
            vector<bit> ret;
            int L = P.size();
            ret.emplace_back(P[0]);
            rep(i,L) ret.emplace_back(Q[i]);
            for (int i = 1; i < L; i++) ret.emplace_back(P[i]);
            return ret;
        }
    };
    bit x(A);
    bit y(B);
    auto ans = dfs(dfs,N-1,x,y);
    for (auto i : ans) cout << i.to_ullong() << " ";
    cout << ln;
}


Measured memory_bytes: 2392
D = gets.to_i
C,*S = (0..D).map{gets.split.map &:to_i}
C.count(0)>1 and S.each {|s|
  26.times {|i| if s[i]==0 && i!=(z||=i); s[z]<s[i] ? (s[z]=0; z=i) : (s[i]=0) end }
}
L,M,N = [-1]*27,8,3
def calc(d,n)
  s = S[d]
  t = (0..25).map {s[_1] > 0 ? C[_1]*(d-L[_1])+s[_1] : 0}
  i = (0..25).max_by(M){t[_1]}.max_by {|i|
    next t[i]  if n == 0 || d+1 >= D || t[i] == 0
    l,L[i] = L[i],d
    calc(d+1,n-1)[1].tap {L[i]=l}
  }
  [i, t[i]]
end
D.times { p 1 + i=calc(_1,N)[0]; L[i]=_1 }

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

int main(){
  vector<int> A(3);
  for(int i=0;i<3;i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  if((A.at(0)+A.at(1))==A.at(2)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

using namespace std;

bool check(int n)
{
    char s[16];
    sprintf(s, "%d", n);
    
    int len = strlen(s);
    for (int i = 0; i < len - i - 1; i++){
        if (s[i] != s[len - i  - 1]) return (false);
    }
    return (true);
}

int main()
{
    int n;
    
    scanf("%d", &n);
    
    for (int d = 0; ; d++){
        if (check(n - d)){
            printf("%d\n", n - d);
            return (0);
        }
        if (check(n + d)){
            printf("%d\n", n + d);
            return (0);
        }
    }
    
    return (-1);
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
long long a[300010];
long long pre[300010];
long long post[300010];
long long n;
priority_queue<long long,vector<long long>,greater<long long> >pq_min;
priority_queue<long long>pq_max;
#define max(a,b) (a)>(b)?(a):(b)
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    long long sum1=0;
    long long sum2=0;
    for(long long i=0;i<3*n;++i)
    {
        cin>>a[i];
        if(i>=0&&i<n)
        {
            pq_min.push(a[i]);
            sum1+=a[i];
        }
        else if(i>=2*n&&i<3*n)
        {
            pq_max.push(a[i]);
            sum2+=a[i];
        }
    }
    long long ans=LLONG_MIN;
    pre[n-1]=sum1;
    for(long long i=n;i<2*n;++i)
    {
        pq_min.push(a[i]);
        sum1+=a[i];
        if(pq_min.size()>n)
        {
            sum1-=pq_min.top();
            pq_min.pop();
        }
        pre[i]=sum1;
    }
    post[2*n-1]=sum2;
    ans=max(ans,pre[2*n-1]-post[2*n-1]);
    for(long long i=2*n-2;i>=n-1;--i)
    {
        pq_max.push(a[i+1]);
        sum2+=a[i+1];
        if(pq_max.size()>n)
        {
            sum2-=pq_max.top();
            pq_max.pop();
        }
        post[i]=sum2;
        ans=max(ans,pre[i]-post[i]);
    }
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 7796
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
int n,t[100005],x[100005],y[100005],lt,lx,ly;
bool no;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",&t[i],&x[i],&y[i]);
		int dif = abs(lx-x[i]) + abs(ly-y[i]);
		if(dif > t[i]-lt || ((t[i]-lt-dif)&1)) no = 1;
	}
	if(no) printf("No\n");
	else printf("Yes\n");
	
	return 0;
}


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

  
int main()
{
  int n, k = 0;
  scanf("%d", &n);
  vector<int> h(n);
  for(int i = 0; i < n; ++i)
    scanf("%d", &h[i]);
  if (h[0] >= h[1]) h[0]--;
  for(int i = 1; i < n-1; ++i)
    if (h[i] >= h[i+1] && h[i-1] < h[i]) 
      h[i]--;
  //for(int i = 0; i < n; ++i)
  //printf("%d\n",h[i]);
  for(int i = 0; i < n-1; ++i)
    if (h[i] > h[i+1]){
      printf("No");
      return 0;
    }
  printf("Yes");
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
void Main(){
    int S;cin>>S;
    cout<<(S<1200?"ABC":"ARC")<<endl;
}
int main(){
    Main();
    return 0;
}


Measured memory_bytes: 256
n=gets.chomp.to_i
f=true
p_x=0
p_y=0
p_t=0
n.times do |i|
  t,x,y=gets.chomp.split.map(&:to_i)
  dis=(p_x-x).abs+(p_y-y).abs
  time=t-p_t
  z=time-dis
  if z<0 || z.odd? then
    puts 'No'
    exit
  end
  p_x=x
  p_y=y
  p_t=t
end
puts 'Yes'

Measured memory_bytes: 1788
N, A, B = map(int, input().split())
S = input()
l = list(S)
#l is composed of a, b, and c

k = 0
for i in range(0, N):
    if l[i] == 'c':
        l[i] = 'No'
    elif l[i] == 'a' and k < A+B:
        l[i] = 'Yes'
        k += 1
    elif l[i] == 'b' and k < A+B:
        l[i] = 'passedb'
        k += 1
        #A's and B's ranked in the top A+Bth among all the A's andB's tentatively passed now 
        #C's were rejected now
#l is now composed of Yes(a), passedb, No(c), a, and b

m = 0
for j in range(0, N):
    if l[j] == 'passedb':
        if m < B:
            l[j] = 'Yes'
            m += 1
        else:
            l[j] = 'No'
    #B's ranked in the top Bth among all the B's passed now
    elif l[j] == 'b':
        l[j] = 'No'
    #the other B's were rejected now
#l is now composed of Yes, No, 

t = 0
for k in range(N):
    if l[k] == 'Yes':
        t += 1
    elif l[k] == 'a' and t < A+B:
        l[k] = 'Yes'
        t += 1
    else:
        l[k] = 'No'

for i in range(N):
    print(l[i])

#全体として
#cを弾く。上位a+b位のAとBについて全員とおしpassedA, passedBに置換
#passedBの中で上位b位に入っていない人をNoにする
#もう一回Aを対象に選考

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector <int> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = k + 1; i <= n; i++)
    {
        if (a[i] > a[i - k])
            cout << "Yes\n";
        else
            cout << "No\n";
    }
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 1000000007
#define ff first
#define ss second
#define pb push_back  
#define INF 1000000000000

									// nestedcode

ll dp[15][15];

 int main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   ll n,i,p,last,first,j;
   cin>>n;
   for(i=1;i<=n;i++){
   	p = i;
   	last = i%10;
   	while(p){
   		if(p<10){
   			first = p;
		   }
		  
		   p/=10;
	   }
	   
	   dp[first][last]++;
   }
   
   ll ans = 0;
   for(i=1;i<10;i++){
   	for(j=1;j<10;j++){
   		ans += (dp[i][j] * dp[j][i]);
	   }
   }
   cout<<ans;
   
}

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

using namespace std;

const int MAX = 300000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	COMinit();
	int H,W,A,B; cin >> H >> W >> A >> B;
	long long ans=COM(H+W-2,H-1),tmp=0;
	for(int i=H-A;i<H;++i)
		(tmp+=(COM(i+B-1,B-1)*COM(H-i-1+W-B-1,W-B-1))%MOD)%=MOD;
	cout << (ans-tmp+MOD)%MOD << endl;
	
	return 0;
}


Measured memory_bytes: 7296
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left # bisect_left(list, value)
#from fractions import gcd

sys.setrecursionlimit(10**7)
N = int(input())

if N%2==0:
    print(N//2)
else:
    print(N//2+1)




Measured memory_bytes: 38256
#include<stdio.h>
	#include<stdlib.h>
	
	int main(){
	int n,r;
	int p,c;
	int i,j=0,k,l=0;
	
	int box[50] = {0};
	int pre[50] = {0};
	
	while(1){
	scanf("%d %d",&n,&r);
	
	if(n==0 && r==0){
		break;
	}
	
	for(i=0;i<n;i++){
		box[i] = n-i;
		pre[i] = box[i];
	}
	
	for(j=0;j<r;j++){
		scanf("%d %d",&p,&c);
	
		for(i=0;i<c;i++){
			box[i] = pre[p+i-1];
		}
		
		for(;i<c+p-1;i++){
			box[i] = pre[i-c];
		}
		
		for(i=0;i<n;i++){
			pre[i] = box[i];
		}
		
	}
	
	printf("%d\n",box[0]);
	
	
	}
	
	return 0;
	}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    ll check=0;
    rep(i,n){
        ll a;cin >> a;
        if(a%2)check++;
    }
    if(check%2)cout <<"NO" <<endl;
    else cout << "YES" <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>








int n,m,c,res,p[60],a[60],b[60];







int findSet(int u)
{
	if(p[u]<0)return u;
	p[u]=findSet(p[u]);
	return p[u];
}

void unionSet(int u,int v)
{
	u=findSet(u);
	v=findSet(v);
	if(u==v)return;
	if(p[u]<p[v])
	{
		p[u]+=p[v];
		p[v]=u;
	}
	else
	{
		p[v]+=p[u];
		p[u]=v;
	}
}







void solve()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>a[i]>>b[i];
	}
	res=0;
	for(int i=1;i<=m;i++)
	{
		for(int i=1;i<=n;i++)p[i]=-1;
		for(int j=1;j<=m;j++)
		{
			if(j==i)continue;
			unionSet(a[j],b[j]);
		}
		c=0;
		for(int i=1;i<=n;i++)if(p[i]<0)c++;
		if(c>1)res++;
	}
	cout<<res<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	int n,m,x,y;
	cin >> n >> m >> x >> y;
	int a[n];
	int b[m];

	int maxx = INT_MIN;
	for(int i=0 ; i<n ; i++)
	{
		cin >> a[i];
		maxx = max(maxx , a[i]);
	}

	int minn = INT_MAX;
	for(int i=0 ; i<m ; i++)
	{
		cin >> b[i];
		minn = min(minn , b[i]);
	}

	maxx = max(x , maxx);
	minn = min(y , minn);

	if(maxx < minn)
		cout << "No War";
	else
		cout << "War";

	return 0;
}

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

using namespace std;
const int N = 1e5+5;
typedef long long ll;
ll a[N];

int main(){
	ll n,m,k;
	cin>>n>>m>>k;
//	memset(a,0,sizeof(a));
	for(int i=0;i<k;i++){
		int x;
		cin>>x;
		a[x]+=1;
	}
	for(int i=1;i<=n;i++){
		a[i]+=m-k;
		if(a[i]<=0) puts("No");
		else puts("Yes");
	}
	
	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<list>
#include<algorithm>
using namespace std;
#define si scanf
#define so printf
#define N 200100
#define M 
#define INF  
#define mod %P
#define nxt t[j]
template<typename TP>inline bool rd(TP& r)
{
	r=0;
	char tmp=getchar();
	while(tmp<'0'||tmp>'9')
	{
		if(tmp==EOF)
			return 0;
		tmp=getchar();
	}
	while('0'<=tmp&&tmp<='9')
	{
		r=(r<<3)+(r<<1)+tmp-'0';
		tmp=getchar();
	}
	return 1;
	
} 
long long P=1000000007,ans;
int n;
int h[N],fa[N][30],x[N*2],t[N*2],tot=1;
void ade(int u,int v)
{
	++tot;
	x[tot]=h[u];
	h[u]=tot;
	t[tot]=v;
}
/*int hd[N],xd[N*2],td[N*2],lst[N];
void ins(int u,int v)
{
	++tot;
	xd[lst]=tot;
	td[tot]=v;
}*/
void fathers()
{
	for(int i=1;(1<<(i-1))<=n;++i)
	for(int j=1;j<=n;++j)
		fa[j][i]=fa[fa[j][i-1]][i-1];
}
long long f[N][2];
long long pl[N],pr[N];
int sons[N];
long long power(long long ori,long long t)
{
	long long re=1;
	while(t)
	{
		if(t&1)
			re=re*ori mod;
		ori=ori*ori mod;
		t>>=1;
	}
	return re;
}
int tr[N*2];
void add(int po,int pl)
{
	for(;po<=n+100;po+=(-po)&po)
		tr[po]+=pl;
}
int ask(int po)
{
	int re=0;
	for(;po;po-=(-po)&po)
		re+=tr[po];
	return re;
}
int l[N],r[N],cnt[N];
int d[N];
list<int> ln[N];
void init(int now)
{
	//ins(d[now],now);
	ln[d[now]].push_back(now);
	l[now]=++tot;
	for(int j=h[now];j;j=x[j])
		d[nxt]=d[now]+1,init(nxt); 
	r[now]=tot;
}
long long g[N];
queue<int> Q;
int getlca(int now)
{
	int u=now;
	for(int i=20;i>=0;--i)
		if(ask(r[fa[u][i]])-ask(l[fa[u][i]]-1)<=0)
			u=fa[u][i];
	u=fa[u][0];
	return u;
}
bool vis[N];
struct sta
{
	int po,dp;
	sta(int pos=0,int dep=0)
	{
		po=pos,dp=dep;
	}
	friend bool operator < (sta a,sta b)
	{
		return a.dp<b.dp;
	}
};
priority_queue<sta> q;
void work(int dp)
{
	int now;
	add(l[0],1);
	while(!q.empty())	q.pop();
	list<int>::iterator it;
	for(it=ln[dp].begin();it!=ln[dp].end();it++)
	{
		add(l[*it],1);
		f[*it][1]=1;
		cnt[*it]=1;
		q.push(sta(*it,d[*it]));
	}
	while(!q.empty())
	{
		now=q.top().po;
		q.pop();
		f[now][0]=(power(2,cnt[now])-f[now][1]+P)mod;
		add(l[now],-(ask(l[now])-ask(l[now]-1)));
		
		//更新lca 
		int lca=getlca(now);
		if(lca!=now)
		{
			f[lca][1]=(f[lca][1]*f[now][0]mod+g[lca]*f[now][1]mod)mod;
			g[lca]=g[lca]*f[now][0]mod;
			cnt[lca]+=cnt[now];
			add(l[lca],1);
			if(!vis[lca])
				q.push(sta(lca,d[lca])),vis[lca]=1;
		}
		
		//清空自己 
		g[now]=1;
		vis[now]=0;
		if(now)
		{
			f[now][0]=0,f[now][1]=0;
			cnt[now]=0;
		}
	}
	tot=0;
	ans=(ans+f[0][1]*power(2,n+1-cnt[0])mod)mod;
	f[0][0]=0,f[0][1]=0;
	cnt[0]=0;
}

int main()
{
	rd(n);
	for(int i=1;i<=n;++i)
	{
		rd(fa[i][0]);
		ade(fa[i][0],i);
	}
	for(int i=0;i<=n;++i)
		g[i]=1;
	fathers();
	tot=0;
	init(0);
	for(int i=0;i<=n;++i)
		if(!ln[i].empty())
			work(i);
		else
			break;
	so("%lld\n",ans);
	return 0;
} 

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

int main() {
  int A, B;
  cin >> A >> B;
  if (A == 1) A += 13;
  if (B == 1) B += 13;
  
  if (A > B) cout << "Alice" << endl;
  else if (A < B) cout << "Bob" << endl;
  else cout << "Draw" << endl;
  
  return 0;
}

Measured memory_bytes: 256
import bisect;import heapq;import itertools;import math;import operator;import os;import re;import string;import sys;from collections import Counter, deque, defaultdict;from copy import deepcopy;from decimal import Decimal;from fractions import gcd;from functools import lru_cache, reduce;from operator import itemgetter, mul, add, xor;import numpy as np;sys.setrecursionlimit(2147483647);INF = float("inf");IINF = 10 ** 18;MOD = 10 ** 9 + 7

# ここからコード開始

A, B = map(int, input().split())
print(max(A+B,A-B,A*B))

Measured memory_bytes: 13784
class Main:
    s = list(map(int, input().split()))
    n = s[0]
    k = s[1]
    sum = 0
    kSum = 0
    list = [int(i) for i in input().split()]
    newList = sorted(list, reverse=True)
    list[:k]
    for num in newList:
        sum += num
    for kNum in newList[:k]:
        kSum += kNum
    print(sum-kSum)

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

int sumOfDigits(int n){
    int retval = 0;

    while(n>0){
        retval += n%10;
        n /= 10;
    }

    return retval;
}

int main(){
    int sum = 0;
    int N, A, B;
    cin >> N >> A >> B;

    for(int i=1;i<=N;i++){
        int tmp = sumOfDigits(i);
        if(A <= tmp && tmp <= B){
            sum += i;
        }
    }

    cout << sum << endl;
}

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

int main(){
  int n;
  std::cin >> n;
  vector<int> s(n);
  vector<vector<int> > val(10);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> s[i];
    val[s[i]%10].push_back(s[i]);
    ans += s[i];
  }
  int sum = 0;
  for (int i = 0; i < 10; i++) {
    sort(val[i].begin(), val[i].end());
    sum += val[i].size()*i;
  }
  if(sum%10 == 0){
    for (int i = 1; i < 10; i++) {
      if(val[i].size() != 0){
        std::cout << ans - val[i][0] << std::endl;
        return 0;
      }
    }
    std::cout << 0 << std::endl;
  }else{
    std::cout << ans << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*
dp[i][j][k]表示剩余装有1个寿司的盘子数为i，装有2个的盘子数为j，装有3个的盘子数为k，此时的期望次数
拿到非空盘的概率为 p=(i+j+k)/n 所以期望次数为 t=1/p=n/(i+j+k)
dp[i][j][j]
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e2 + 2;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, m;
int a[5];
double dp[MAXN][MAXN][MAXN];
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        int x;
        scanf("%d", &x);
        a[x]++;
    }
    for (int k = 0; k <= n; k++)
        for (int j = 0; j <= n - k; j++)
            for (int i = 0; i <= n - k - j; i++)
            {
                if (!i && !j && !k)
                    continue;
                double x = i + j + k, t = (1.0 * n) / (1.0 * (i + j + k));
                if (k)
                    dp[i][j][k] += dp[i][j + 1][k - 1] * (1.0 * k) / x;
                if (j)
                    dp[i][j][k] += dp[i + 1][j - 1][k] * (1.0 * j) / x;
                if (i)
                    dp[i][j][k] += dp[i - 1][j][k] * (1.0 * i) / x;
                dp[i][j][k] += t;
            }
    printf("%.10f\n", dp[a[1]][a[2]][a[3]]);
    return 0;
}

Measured memory_bytes: 215296
#include<bits/stdc++.h>
using namespace std;
typedef int wint;
struct cint{
	int num[55];
	cint(){for(int i=0;i<55;i++)num[i]=0;}
	cint operator+(const cint &a){
		cint ret;
		for(int i=0;i<55;i++)ret.num[i]=num[i]+a.num[i];
		return ret;
	}
	cint operator-(const cint &a){
		cint ret;
		for(int i=0;i<55;i++)ret.num[i]=num[i]-a.num[i];
		return ret;
	}
	cint operator-(){
		cint ret;
		for(int i=0;i<55;i++)ret.num[i]=-num[i];
		return ret;
	}
	cint operator*(const int &k){
		cint ret;
		for(int i=0;i<55;i++)ret.num[i]=num[i]*k;
		return ret;
	}
};
inline bool operator<(const cint &a,const cint &b){
	for(int i=0;i<55;i++){
		if(a.num[i]!=b.num[i])return a.num[i]<b.num[i];
	}
	return false;
}
namespace MCF{
	#define MAXN 1000
	#define MAXM 100000
	const wint wEPS=0;
	const wint wINF=1001001001;
	const cint cEPS;
	cint cINF;
	int n,m,ptr[MAXN],next[MAXM],zu[MAXM];
	wint capa[MAXM],tof;
	cint cost[MAXM],toc,d[MAXN],pot[MAXN];
	int vis[MAXN],pree[MAXN];
	void init(int _n){
		cINF.num[0]=100000;
		n=_n;m=0;memset(ptr,~0,n*4);
	}
	void ae(int u,int v,wint w,cint c){
		next[m]=ptr[u];ptr[u]=m;zu[m]=v;capa[m]=w;cost[m]=c;++m;
		next[m]=ptr[v];ptr[v]=m;zu[m]=u;capa[m]=0;cost[m]=-c;++m;
	}
	bool solve(int src,int ink,wint flo=wINF){
		int i,u,v;
		wint f;
		cint c,cc;
		memset(pot,0,n*sizeof(cint));
		for(bool cont=1;cont;){
			cont=0;
			for(u=0;u<n;++u)for(i=ptr[u];~i;i=next[i])if(capa[i]>wEPS){
				if(pot[u]+cost[i]+cEPS<pot[zu[i]]){
					pot[zu[i]]=pot[u]+cost[i];cont=1;
				}
			}
		}
		for(toc=cint(),tof=0;tof+wEPS<flo;){
			typedef pair<cint,int> node;
			priority_queue<node,vector<node>,greater<node> >q;
			for(u=0;u<n;++u){d[u]=cINF;vis[u]=0;}
			for(q.push(make_pair(d[src]=cint(),src));!q.empty();){
				c=q.top().first;u=q.top().second;q.pop();
				if(vis[u]++)continue;
				for(i=ptr[u];~i;i=next[i])if(capa[i]>wEPS){
					cc=c+cost[i]+pot[u]-pot[v=zu[i]];
					if(cc<d[v]){q.push(make_pair(d[v]=cc,v));pree[v]=i;}
				}
			}
			if(!vis[ink])return 0;
			f=flo-tof;
			for(v=ink;v!=src;v=zu[i^1]){i=pree[v];f=min(f,capa[i]);}
			for(v=ink;v!=src;v=zu[i^1]){i=pree[v];capa[i]-=f;capa[i^1]+=f;}
			tof+=f;
			toc=toc+(d[ink]-pot[src]+pot[ink])*f;
			for(u=0;u<n;++u)pot[u]=pot[u]+d[u];
		}
		return 1;
	}
}
char str[100][100];
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%s",str[i]);
	MCF::init(a*2+2);
	int s=a*2;
	int t=a*2+1;
	for(int i=0;i<a;i++){
		MCF::ae(s,i,1,cint());
		MCF::ae(a+i,t,1,cint());
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<a;j++){
			cint val;
			if('A'<=str[i][j]&&str[i][j]<='Z')val.num[str[i][j]-'A']--;
			else val.num[str[i][j]-'a'+26]--;
			MCF::ae(i,a+j,1,val);
		}
	}
	MCF::solve(s,t,a);
	for(int i=0;i<52;i++){
		for(int j=0;j<-(MCF::toc.num[i]);j++){
			if(i<26)printf("%c",'A'+i);
			else printf("%c",'a'+i-26);
		}
	}
	printf("\n");
}

Measured memory_bytes: 23836
N = int(input())
arr = list(map(int, input().split()))

ans = 0
for i in range(len(arr)):
    for j in range(i,len(arr),1):
        for k in range(j,len(arr),1):
            if arr[i] == arr[j] or arr[i] == arr[k] or arr[j] == arr[k]:
                continue
            if arr[k] < arr[i]+arr[j] and arr[i] < arr[j]+arr[k] and arr[j] < arr[i]+arr[k]:
                ans += 1

print(ans)


Measured memory_bytes: 68368
N=int(input())
A=[]
B=[]
for i in range(N):
    a=int(input())
    A.append(a)
    B.append(a)

ans=0
if N==1:
    print(A[0]//2)
    exit()

for i in range(N):
    if i==(N-1):
        ans+=A[i]//2
        break
    if i==0:
        ans+=A[i]//2
        ans+=min(A[i]%2,A[i+1])
        A[i+1]=max(0,A[i+1]-A[i]%2)
        continue
    ans+=A[i]//2
    ans+=min(A[i]%2,A[i+1])
    A[i+1]=max(0,A[i+1]-A[i]%2)
print(ans)

Measured memory_bytes: 56408
int1 = lambda x: int(x) - 1

N, M = map(int, input().split())
H = list(map(int, input().split()))

nei = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int1, input().split())
    nei[A].append(B)
    nei[B].append(A)

good = [True] * N

for i in range(N):
    if good[i]:
        for n in nei[i]:
            if H[i] <= H[n]:
                good[i] = False
                break
            else:
                good[n] = False

print(sum(good))

Measured memory_bytes: 30308
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,ans,k,pd[101];
signed main()
{
	int x,y;
	scanf("%lld%lld",&n,&k);
	ans=n;
	for(int i=1;i<=k;i++)
	{
		scanf("%lld",&x);
		for(int i=1;i<=x;i++)
		{
			scanf("%lld",&y);
			if(pd[y]==0)
			pd[y]=1,ans--;
		}
	}
	printf("%lld",ans);
    return 0;
}

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

bool cmp(tuple<string, int, int> a, tuple<string, int, int> b) {
  string city_a = get<0>(a);
  string city_b = get<0>(b);
  int val_a = get<1>(a);
  int val_b = get<1>(b);
  if (city_a == city_b) {
    return val_a > val_b;
  }
  return city_a < city_b;
}

int main() {
  int n;
  cin >> n;
  vector<tuple<string, int, int>> v;
  for (int i = 0; i < n; i++) {
    string s;
    int k;
    cin >> s >> k;
    v.push_back(make_tuple(s, k, i + 1));
  }
  sort(v.begin(), v.end(), cmp);
  for (int i = 0; i < n; i++) {
    cout << get<2>(v[i]) << '\n';
  }
  return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
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 main(void) {
    int n, m;
    cin >> n >> m;

    if(m==1) {
        cout << 1 << " " << 2 << endl;
        return 0;
    }

    int l = 1, r = m + 2;
    for(int im=0;im<m;im++) {
        cout << l << " " << l+(m-im) << endl;
        l++;
        swap(l, r);
    }

    return 0;
}


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

int main() {
	int A, B, T;
	int ans=0,i;
	cin >> A >> B >> T;
	i = A;
	while (i <= T + 0.5) {
		i += A;
		ans += B;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
function main() {
  function dfs(n,l,r){
    if(n.length === 0) return true;
    return (n[0] > l[0] && dfs(n.slice(1), [n[0]].concat(l), r)) ||
            (n[0] > r[0] && dfs(n.slice(1), l, [n[0]].concat(r)));
  }
  var
  i,
  n = parseInt(input[0], 10),
  nums = input.slice(1);
  for(i = 0; i < n; i++) {
    console.log(dfs(nums[i].split(' ').map(parseFloat), [0], [0]) ? 'YES' : 'NO');
  }
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];

    ll ans = 0;
    ll T = accumulate(B.begin(), B.end(), 0LL);
    ll j = M;
    rep(i, N + 1) {
        while (j > 0 && T > K) {
            j--;
            T -= B[j];
        }
        if (T <= K) ans = max(ans, i + j);
        if (i == N) continue;
        T += A[i];
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 6344
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>

#define rep(i,n) for((i)=0;i<(int)(n);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)

using namespace std;


int main() {
	int a, b;
	cin >> a >> b;
	if (a > 9 || b > 9) {
		cout << -1;
	}
	else {
		cout << a * b;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int maxm = 100100;
const int maxn = 300100;
int m;
namespace BIT
{
	int v[maxm];
	int lowbit(int x)
	{
		return x & -x;
	}
	void add(int pos, int a)
	{
		for(int i = pos; i <= m; i += lowbit(i))
			v[i] += a;
	}
	int sum(int pos)
	{
		int ans = 0;
		for(int i = pos; i; i -= lowbit(i))
			ans += v[i];
		return ans;
	}
}
struct segment
{
	int l, r;
	bool operator<(const segment &a) const
	{
		return r - l + 1 < a.r - a.l + 1;
	}
}s[maxn];
int n;
int main()
{
	//freopen("Snuke10.in", "r", stdin);
	//freopen("Snuke10.out", "w", stdout);
	std::ios::sync_with_stdio(false);
	using namespace BIT;
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		cin >> s[i].l >> s[i].r;
	sort(s + 1, s + n + 1);
	int j = 1;
	for(int i = 1; i <= m; i ++)
	{
		for(; j <= n && s[j].r - s[j].l + 1 < i; j ++)
		{
			add(s[j].l, 1);
			add(s[j].r + 1, -1);
		}
		int ans = 0;
		for(int j = 0; j <= m; j += i)
			ans += sum(j);
		cout << ans + n - j + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N, K;
    cin >> N >> K;

    p(N-K+1);
    
    return 0;
}

Measured memory_bytes: 256
inputs = gets.chomp.split.map(&:to_i)
a = inputs[0]
b = inputs[1]
k = inputs[2]

if a >= k
  a = a - k
  puts a, b
elsif a + b >= k
  b = b - (k - a)
  a = 0
  puts a, b
else
  puts 0, 0
end

Measured memory_bytes: 1788
n,m = map(int, input().split())

if abs(n-m) > 1:
  print(0)
  exit()

mod = 10**9+7
ans = 1
for i in range(1,n+1):
  ans *= i
  ans %= mod
for i in range(1,m+1):
  ans *= i
  ans %= mod
if (n+m)%2 == 0:
  ans *= 2
  ans %= mod
print(ans)

Measured memory_bytes: 9192
#include <stdio.h>

void search(int n, char c, char s[], int x[]);

int main()
{
    int n;

    scanf("%d", &n);

    char st[n];
    int num[n], i;

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

    search(n, 'S', st, num);
    search(n, 'H', st, num);
    search(n, 'C', st, num);
    search(n, 'D', st, num);

    return 0;
}

void search(int n, char c, char s[], int x[]) {
    int i, j, flag = 0;
    for (i = 1; i <= 13; i++) {
      flag = 0;
        for (j = 0; j < n; j++) {
            if (s[j] == c && x[j] == i) {
                flag = 1;
		break;
            }
        }
        if (flag == 0) {
            printf("%c %d\n", c, i);
        }
    }

    return ;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;

int main() {
    int n, a; cin >> n >> a;
    int sum = 0;
    int x[n + 1]; rrep(i, 1, n + 1) {cin >> x[i]; sum += x[i];}
    //x1, x2, ..., xj からk個選んで合計sにする
    ll dp[n + 1][n + 1][n * a + 1];
    rep(s, n * a + 1) rep(j, n + 1) rep(k, n + 1) {
        if (j >= 1 && s < x[j]) dp[j][k][s] = dp[j - 1][k][s]; //xj選ばない
        else if (j >= 1 && k >= 1 && s >= x[j]) dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]];
        else if (j == 0 && k == 0 && s == 0) dp[j][k][s] = 1;
        else dp[j][k][s] = 0;
    }
    /*
    rep(s, sum + 1) {
        cout << s << endl;
        rep(j, n + 1) {
            rep(k, n + 1) {
                cout << dp[j][k][s] << " ";
                
            }
            cout << endl;
        }
        cout << endl;
    }
    */
    ll ans = 0;
    rrep(k, 1, n + 1) ans += dp[n][k][k * a];
    cout << ans << endl;
}



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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/
int n;
vector<int> a;
/**********************************************/

LL combination(LL n, LL k)
{
  if(k < 0 || n < k) return (0);
  LL ret = 1;
  for(LL i = 1; i <= k; ++i) {
    ret *= n--;
    ret /= i;
  }
  return (ret);
}
class AbsDist
{
public:
  AbsDist(double ref) :_ref(ref){};
  bool operator() (int l, int r) const {
    return abs((double)l - _ref) < abs((double)r - _ref);
  }
private:
  double _ref;
};

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

    cin >> n;
    a.resize(n);
    REP(i, n) cin >> a[i];
    
    sort(all(a));


    int max_num = a.back();
    a.pop_back();
    
    sort(all(a), AbsDist{(double)max_num/2.0});
    
    cout << max_num << " " << a[0] << endl;
}


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

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

typedef long long ll;

long long mod_div(long long a, long long b) {
	if (a % b == 0)return a / b;
	long long tmp = MOD - 2, c = b, ret = 1;
	while (tmp > 0) {
		if (tmp & 1) {
			ret *= c; ret %= MOD;
		}
		c *= c; c %= MOD; tmp >>= 1;
	}
	return a*ret%MOD;
}


ll dp[4][111111];

int main() {

	string str; cin >> str;

	ll tmp = 1;
	ll cou = 0;
	REP(i, str.size()) {
		if (str[i] == '?')cou++;
	}
	REP(i, cou) {
		tmp *= 3;
		tmp %= MOD;
	}

	dp[0][0] = tmp;
	REP(j, 4) {
		REP(i, str.size()) {
			if (dp[j][i]) {
				if (j < 3) {
					if (str[i] == 'A' + j) {
						dp[j + 1][i + 1] += dp[j][i];
						dp[j + 1][i + 1] %= MOD;
					}
					else if (str[i] == '?') {
						dp[j + 1][i + 1] += mod_div(dp[j][i], 3);
						dp[j + 1][i + 1] %= MOD;
					}
				}
				dp[j][i + 1] += dp[j][i];
				dp[j][i + 1] %= MOD;
			}
		}
	}

	cout << dp[3][str.size()] << endl;

	return 0;
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    Int n = s.size();
    for (Int i = 0; i < n - 1; i++) {
        for (Int j = i + 1; j < n; j++) {
            string t = s.substr(0, i + 1) + s.substr(j);
            if (t == "keyence") {
                dump("YES");
                return 0;
            }
        }
    }
    dump("NO");
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
	ll n_;
	cin>>n_;
	__int128 n=n_;
	reps(h,1,353535)reps(w,1,h+1){
		auto p=n*h*w;
		auto q=-n*h+4*h*w-n*w;
		if(q>0 && p>=0 && p%q==0){
			cout<<h<<" "<<w<<" "<<(ll)(p/q)<<endl;
			return 0;
		}
	}
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<vector>

#define MAX 5000

using namespace std;

void input();

int lose[MAX + 1];
int n, m, w[100000 + 1], l[100000 + 1];
queue<int> q;

int main() {

	bool yes = false;
	input();

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

		int t = 0, cnt = 0;
		for (int j = 1; j <= n; j++) {
			if (lose[j] == 0) {
				t = j;
				cnt++;

			}
		}
		if (cnt >= 2) yes = true;
		lose[t] = 5000 ;
		q.push(t);
		for (int j = 0; j < m; j++) if (w[j]==t) lose[l[j]]--;

	}
	for (int i = 0; i < n; i++) {
		int ans = q.front();
		cout << ans << endl;
		q.pop();
	}
	if (yes == true) cout << 1 << endl;
	else cout << 0 << endl;

	//cin >> n;
	return 0;
}

void input() {

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> w[i] >> l[i];
		lose[l[i]]++;

	}
}



Measured memory_bytes: 4000
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<ll, ll> P;
ll v[41];
ll A[100000];
int main() {
	int N;
	cin >> N;
	ll K;
	cin >> K;
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		ans += A[i];
	}
	for (int i = 0; i <= 40; i++) {
		int cnt = 0;
		for (int j = 0; j < N; j++) {
			if (A[j] & (1LL << i)) cnt++;
		}
		v[i] = (N - 2 * cnt)*(1LL << i);
	}
	vector<P> vec;
	for (int bit = 0; bit < (1 << 20); bit++) {
		ll sum = 0;
		for (int i = 0; i < 20; i++) {
			if (bit&(1 << i)) {
				sum += v[i];
			}
		}
		vec.emplace_back(P(bit, sum));
	}
	sort(vec.begin(), vec.end());
	int m = 1;
	for (int i = 1; i < (1 << 20); i++) {
		if (vec[m - 1].second < vec[i].second) {
			vec[m++] = vec[i];
		}
	}
	ll res = 0;
	for (int bit = 0; bit < (1 << 21); bit++) {
		ll sum = 0;
		ll w = 0;
		for (int i = 0; i < 21; i++) {
			if (bit&(1 << i)) {
				sum += v[i + 20];
				w += (1LL << (i + 20));
			}
		}
		if (w <= K) {
			ll t = (lower_bound(vec.begin(), vec.begin() + m, make_pair(K - w, 1LL << 62)) - 1)->second;
			res = max(res, sum + t);
		}
	}
	ans += res;
	cout << ans << endl;
}

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

def main():
	n, k = map(int, input().strip().split())
	v = list(map(int, input().strip().split()))
	ans = 0
	for a in range(k+1):
		for b in range(k-a+1):
			if a + b > n:
				continue
			t = sorted(v[:a] + v[n-b:])
			for i in range(k-a-b):
				if i < len(t) and t[i] < 0:
					t[i] = 0
			ans = max(ans, sum(t))
	print(ans)
if __name__ == '__main__':
	main()


Measured memory_bytes: 41452
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ac(n), pena(n);
  rep(i, m) {
    int p;
    string s;
    cin >> p >> s;
    p--;
    if(ac.at(p)) continue;
    if(s == "WA") {
      pena.at(p)++;
    }
    else {
      ac.at(p) = 1;
    }
  }
  int AC = 0;
  int PENA = 0;
  rep(i, n) {
    AC += ac.at(i);
    if(ac.at(i)) PENA += pena.at(i);
  }
  cout << AC << " " << PENA << endl;
}

Measured memory_bytes: 1024
n = gets.to_i
s = gets.chomp
h0 = {}
h1 = {}
h2 = {}
n.times do |i|
  h1.keys.each do |k2|
    if h2.key?(k2 + s[i]) == false
      h2[k2 + s[i]] = 1
    end
  end
  h0.keys.each do |k1|
    if h1.key?(k1 + s[i]) == false
      h1[k1 + s[i]] = 1
    end
  end
  if h0.key?(s[i]) == false
    h0[s[i]] = 1
  end
end
puts h2.keys.size

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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MOD  1000000007
#define mod1 1000000009
#define var    int n,m,i,j,c=0,t,l,r,mid,z=0,k,x,y
#define aloc(n,t) ((t*)malloc((n)*sizeof(t)))

int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

int n,m,a[200005],b[200005];

int main()
{
    sf(n);
    ll ans  = 0;
    for(int i=1;i<=n;i++)
    {
        ans+= (n/i);
        if(n%i==0)ans--;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3764
n,a,b=map(int,input().split())
c1=c2=0
for i in input():
  if c1+c2>=a+b:
    print("No")
  elif i=="a":
    print("Yes")
    c1+=1
  elif i=="b":
    if c2>=b:
      print("No")
    else:
      print("Yes")
      c2+=1
  else:
    print("No")

Measured memory_bytes: 4144
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
typedef priority_queue<p> pq;
typedef priority_queue<p, vector<p>, greater<p>> gpq;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    vector<int> l(n);
    ll ans = 0;

    cin >> n;
    REP(i, n){
        int t;
        cin >> t;
        l[i] = t;
    }

    sort(ALL(l), greater<int>());

    FOR(i, 0, n)
    {
        FOR(j, i+1, n)
        {
            FOR(k, j+1, n)
            {
                int len = l[i] + l[j] + l[k];
                int ma = max(l[i], max(l[j], l[k]));
                int rest = len - ma;

                if(ma < rest)
                {
                    ans++;
                }else
                {
                    break;
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 16640