akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int x, xx, y, yy;
int main(){
	int a, b;
	scanf("%d%d%d%d", &x, &xx, &y, &yy);
	a = x / yy;
	if(x % yy != 0) a++;
	b = y / xx;
	if(y % xx != 0) b++;
	if(a >= b) printf("Yes");
	else printf("No");
	return 0;
}

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

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

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	rep(i, h)rep(j, w) {
		if (s[i][j] == '.') continue;
		bool ok = false;
		rep(k, 4) {
			int nx = i + dx[k], ny = j + dy[k];
			if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
			if (s[nx][ny] == '#') ok = true;
		}
		if (!ok) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n,max;
	long long sum = 0;
	scanf("%d",&n);
	int a[n];
	
	for(int i= 0 ; i < n ; i++)
	scanf("%d",&a[i]);
	max = a[0];
	
	for( int i = 1; i < n ; i++)
	{
		if( max  > a[i])
		sum = sum + (max - a[i]);
		else
		max = a[i];
	}
	printf("%lld",sum);
}


Measured memory_bytes: 2460
K = int(input())
A, B = map(int, input().split())
i = A // K
nK = K
OK = False
if A-B > K:
  print('OK')
else:
  while nK <= B:
    if (nK >= A) and (nK <= B):
      OK = True
      print('OK')
      break
    nK = i * K
    i = i + 1
if OK == False:
  print('NG')

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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

ll n,m;
ll a[100010],b[100010],c[100010];
l_l cb[100010];

ll ans;

signed main() {
    cin >> n >> m;
    for (int i=0;i<n;i++) {
        cin >> a[i];
    }
    for (int i=0;i<m;i++) {
        cin >> b[i] >> c[i];
        cb[i] = make_pair(c[i],b[i]);
    }
    sort(a,a+n);
    sort(cb,cb+m,greater<l_l>());

    int it;
    int nit = -1;

    for (int i=0;i<m;i++) {
        ll B = cb[i].second;
        ll C = cb[i].first;

        it = nit;
        nit = it + B;
        if(nit >= n) {
            for (int j=it+1;j<n;j++) {
                ans += max(C,a[j]);
            }
            break;
        }

        if(a[nit] > C) {
            for (int j=it+1;j<n;j++) {
                ans += max(C,a[j]);
            }
            break;
        }

        ans += C*B;
        // 後半はなくても良い
        if(i == m-1 && nit < n-1) {
            for (int j=nit+1;j<n;j++) {
                ans += a[j];
            }
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 4096
m, d = map(int, input().split())
ans = 0
for i in range(22,d+1):
    d0, d1 = int(str(i)[0]), int(str(i)[1])
    if d0 < 2 or d1 < 2: continue
    if 1 <= d0*d1 <= m: ans += 1
print(ans)

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

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

vector<long> dp(100000+10,-1);

long fact(long n){
    if(dp[n]!=-1) return dp[n];
    long act = 2;
    long modulo = pow(10,9) + 7;
    while(act<=n){
        if(dp[act]!=-1) {act++;continue;}
        dp[act] = (act*dp[act-1])%modulo;
        act++;
    }
    return dp[n];
}

main(){
    dp[0] = 1;
    dp[1] = 1;
    long modulo = pow(10,9) + 7;
    long a, b;
    scanf("%ld %ld", &a, &b);
    if(abs(a-b)>1) printf("0");
    else{
        if(a==b){
            long num = fact(a);
            num = (num*num)%modulo;
            num = (num*2)%modulo;
            printf("%ld",num);
        }else{
            long num = fact(a);
            long num2 = fact(b);
            num = (num*num2)%modulo;
            printf("%ld",num);
        }
    }
}

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

int main(){

 int H,R;
 cin >> H >> R;

 if((H+R)==0){
     cout << '0' << endl;
 }else if((H+R)>0){
     cout << '1' << endl;
 }else{
     cout << "-1" << endl;
 }

 return 0;

}


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

int main() {
    long long a , b , c , k;
    cin >> a >> b >> c >> k;
    long long ans = 0 , cnt = 0;

    for (int i = 0; i < k; i++) {
        if (cnt < a) {
            ans++;
            cnt++;
        }
        else if (cnt - a < b) {
            cnt++;
        }
        else {
            cnt++;
            ans--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3640
n, k = map(int, input().split())
num = [0] * (10 ** 5 + 1)
for i in range(n):
    a, b = map(int, input().split())
    num[a] += b
ans = 0
for i in range(10 ** 5 + 1):
    ans += num[i]
    if ans >= k:
        print(i)
        exit()

Measured memory_bytes: 5736
# print max k (sum(l[0:k-1]) < x) l[0]+l[1]+...l[k-1] < x 
def main():
  n,x = map(int,input().split())
  l = list(map(int,input().split()))
  sum_l = 0
  ans = 0
  for i in range(n):
    sum_l += l[i]
    if sum_l > x:
      ans = i+1
      break
    ans = n+1 # when 
  print(ans)

main()


Measured memory_bytes: 38256
#include <stdio.h>
double k(int a,int b){
 if(a==0) return 1;
 else return b * k(a-1,b);
}
int main(void){
 int a,b;
 scanf("%d%d",&a,&b);
 double c =b * k(a-1,b-1);
 printf("%.0lf",c);
 return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int t[500010];
ll l[500010],r[500010],sum[500010],nisum[500010],w[500010],ls[500010];
int n;
struct que
{
	ll cop[500010],tim[500010];
	int head,tail;
	void clear()
	{
		for (int i=0;i<=head;i++) cop[i]=tim[i]=0;
		head=0;tail=0;
	}
	void push(int t,long long x)
	{
		while ((head>1)&&((cop[head]-cop[head-1])*(t-tim[head-1])-(x-cop[head-1])*(tim[head]-tim[head-1])<=0)) head--;
		cop[++head]=x;tim[head]=t;tail++;
	}
	long long top(int t)
	{
		if (head<tail) tail=head;
		while ((tail>1)&&(cop[tail]-t*tim[tail]<cop[tail-1]-t*tim[tail-1])) tail--;
		//cout<<tim[tail]<<endl;
		return cop[tail]-t*tim[tail];
		//long long ans=-4e18;
		//for (int i=1;i<=head;i++) ans=max(ans,cop[i]-t*tim[i]);return ans;
	}
}que;
struct que2
{
	ll cop[500010],tim[500010];
	int head,tail;
	void clear()
	{
		for (int i=0;i<=head;i++) cop[i]=tim[i]=0;
		head=0;tail=1;
	}
	void push(int t,long long x)
	{
		while ((head>1)&&((cop[head]-cop[head-1])*(t-tim[head-1])-(x-cop[head-1])*(tim[head]-tim[head-1])<=0)) head--;
		cop[++head]=x;tim[head]=t;
	}
	long long top(int t)
	{
		while ((head>tail)&&(cop[tail]-t*tim[tail]<cop[tail+1]-t*tim[tail+1])) tail++;
		//cout<<tim[tail]<<endl;
		return cop[tail]-t*tim[tail];
	}
}que2;
void work(int pl,int pr)
{
	if (pl==pr)
	{
		w[pl]=max(w[pl],l[pl-1]+r[pl+1]+1-t[pl]);
		return;
	}
	int mid=(pl+pr)>>1;
	work(pl,mid);work(mid+1,pr);
	que2.clear();//que2.push(0,0);
	for (int i=pl-1;i<=mid;i++) que2.push(i,l[i]+sum[i]+(ll)i*(i-1)/2);
	ll x=-4e18;
	for (int i=pr;i>mid;i--)
	{
		x=max(x,que2.top(i)+(ll)i*(i+1)/2-sum[i]+r[i+1]);
		w[i]=max(w[i],x);
	}
	que2.clear();//que2.push(0,0);
	for (int i=pr+1;i>mid;i--) que2.push(n-i+1,r[i]+nisum[i]+(ll)(n-i+1)*(n-i+1-1)/2);
	x=-4e18;
	for (int i=pl;i<=mid;i++)
	{
		x=max(x,que2.top(n-i+1)+(ll)(n-i+1)*(n-i+1+1)/2-nisum[i]+l[i-1]);
		w[i]=max(w[i],x);
	}
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("myout.txt","w",stdout);
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {scanf("%d",&t[i]);sum[i]=sum[i-1]+t[i];}
	for (int i=n;i>=1;i--) nisum[i]=nisum[i+1]+t[i];
	que.clear();que.push(0,0);
	for (int i=1;i<=n;i++)
	{
		l[i]=max(l[i-1],que.top(i)+(ll)i*(i+1)/2-sum[i]);
		que.push(i,l[i]+sum[i]+(ll)i*(i-1)/2);
	}
	/*reverse(t+1,t+n+1);for (int i=1;i<=n;i++) sum[i]=sum[i-1]+t[i];
	que.clear();que.push(0,0);
	for (int i=1;i<=n;i++)
	{
		r[i]=max(r[i-1],que.top(i)+(ll)i*(i+1)/2-sum[i]);
		que.push(i,r[i]+sum[i]+(ll)i*(i-1)/2);
	}
	reverse(t+1,t+n+1);for (int i=1;i<=n;i++) sum[i]=sum[i-1]+t[i];
	reverse(r+1,r+n+1);*/
	que.clear();que.push(0,0);
	for (int i=n;i>=1;i--)
	{
		r[i]=max(r[i+1],que.top(n-i+1)+(ll)(n-i+1)*(n-i+1+1)/2-nisum[i]);
		que.push(n-i+1,r[i]+nisum[i]+(ll)(n-i+1)*(n-i+1-1)/2);
	}
	//l[i]为前i个的dp值,r[i]为i~n的dp值 
	//for (int i=1;i<=n;i++) printf("%lld\n",r[i]);return 0;
	memset(w,214,sizeof(w));//w[i]表示强制i这个题目一定要做的最大cost 
	work(1,n);
	//for (int i=1;i<=n;i++) cout<<w[i]<<endl;
	int q;scanf("%d",&q);
	while (q--)
	{
		int p;ll x;scanf("%d%lld",&p,&x);
		printf("%lld\n",max(l[p-1]+r[p+1],w[p]+t[p]-x));
	}
}

Measured memory_bytes: 33280
#include<cstdio>
int main(){
	long long x;
	scanf("%lld",&x);
	int year=0;
	long long my=100;
	while(1){
		my = (long long)(my*1.01); 
		year++;
		if(my >= x) {
			printf("%d",year);
			return 0;
		}
	}
	
}

Measured memory_bytes: 1692
#全点対間最短経路を求めるアルゴリズム

def warshall_floyd(d):
    #d[i][j]:iからjに行く最短経路
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)

n, m , l = map(int, input().split())

INF = 10 ** 11
d = [[INF]*(n+1) for _ in range(n+1)]
for i in range(m):
        x, y, z = map(int, input().split())
        if z <= l:
            d[x][y] = z
            d[y][x] = z #無向グラフならつける

for i in range(1,n+1):
    d[i][i] = 0

    

ss = warshall_floyd(d)



for i in range(1,n+1):
    for j in range(1,n+1):
        if ss[i][j] <= l:
            ss[i][j] = 1


#補給回数
vv = warshall_floyd(ss)

for i in range(1,n+1):
    for j in range(1,n+1):
        if vv[i][j] == INF:
            vv[i][j] = -1

q = int(input())
for _ in range(q):
    x, y = map(int, input().split())
    if vv[x][y] != -1:
    	print(vv[x][y]-1)
    else:
      	print(vv[x][y])

Measured memory_bytes: 53084
/*
                                                  __          __
      /\   |   |     /\   |  | |  |     /\   | / |  )   /\   |  )
     /__\  |   |    /__\  |--| |  |    /__\  |<  |-<   /__\  |-<
    /    \ |__ |__ /    \ |  | \__/   /    \ | \ |__) /    \ |  \
 
*/
 
#import<bits/stdc++.h>
typedef long long ll;
#define num 10000000
#define root 10000
#define forll(i,a,b,c) for(int i=a; i<=b; i+=c)
#define forll2(i,a,b,c) for(int i=a; i>=b; i-=c)
#define pb(n) push_back(n)
 
using namespace std;
 
int main()
{
  int a;
  cin>>a;
  if(a<30){cout<<"No\n";}
  else{cout<<"Yes\n";}
}

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

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

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

using namespace std;

int hoge[MAXN];

signed main(){
    int N;
    cin >> N;
    cout << "ABC" << N << endl;
    return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  int N, a;
  cin >> N;
  int rs = 0;
  unordered_set<int> s;
  REP(i, N) {
    cin >> a;
    if (a < 3200) {
      s.emplace(a / 400);
    } else {
      rs++;
    }
  }
  const int sz = s.size();
  const int resmin = max(1, sz);
  const int resmax = sz + rs;
  cout << resmin << " " << resmax << endl;
  return 0;
}


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

int main() {
	string s; cin >> s;
	string s1 = s.substr(0, 4); int a = stoi(s1);
	string s2 = s.substr(5, 2); int b = stoi(s2);
	if (a < 2019 || a == 2019 && b <= 4) cout << "Heisei";
	else cout << "TBD";
	cout << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	uf := newUnionFind(n + m + 1)
	var k, l int
	for i := 0; i < n; i++ {
		fmt.Scan(&k)
		for j := 0; j < k; j++ {
			fmt.Scan(&l)

			uf.unite(i, n+l)
		}
	}

	ans := "YES"
	root := uf.root(0)
	for i := 1; i < n; i++ {
		if root != uf.root(i) {
			ans = "NO"
			break
		}
	}
	fmt.Println(ans)
}

// UnionFind .
type UnionFind struct {
	par   []int
	rank  []int
	sizes []int
}

func newUnionFind(n int) UnionFind {
	u := UnionFind{}
	u.par = make([]int, n)
	u.rank = make([]int, n)
	u.sizes = make([]int, n)
	for i := 0; i < n; i++ {
		u.par[i] = i
		u.rank[i] = 0
		u.sizes[i] = 1
	}
	return u
}

func (u UnionFind) unite(x, y int) {
	x = u.root(x)
	y = u.root(y)
	if x == y {
		return
	}

	if u.rank[x] < u.rank[y] {
		u.par[x] = y
		u.sizes[y] += u.sizes[x]
	} else {
		u.par[y] = x
		u.sizes[x] += u.sizes[y]
		if u.rank[x] == u.rank[y] {
			u.rank[x]++
		}
	}
}

func (u UnionFind) root(x int) int {
	if u.par[x] == x {
		return x
	}
	u.par[x] = u.root(u.par[x])
	return u.par[x]
}

func (u UnionFind) same(x, y int) bool {
	return u.root(x) == u.root(y)
}

func (u UnionFind) size(x int) int {
	return u.sizes[u.root(x)]
}


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

int main() {
int n;
cin >>n;
vector<pair<int,int>> a(n);

for(int i=0;i<n;i++){
    int aa;
    cin >>aa;
    a.at(i)=make_pair(aa,i+1);
}
sort(a.begin(),a.end());
for(int i=0;i<n;i++){
    cout <<a.at(i).second<<" ";
}
cout <<endl;
}



Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int h, a;
    cin >> h >> a;
    int ans;
    if(h % a == 0) ans = h / a;
    else ans = h / a + 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <memory>
using namespace std;
using uint = unsigned int;

struct Edge{
	int a, b, c;
};

void dfs(const Edge pe, const int v, vector<vector<shared_ptr<Edge>>>& g) {
	int pv = (pe.a == v) ? pe.b : pe.a;
	int c = 1;
	for(uint i=0; i<g[v].size(); i++) {
		shared_ptr<Edge> e = g[v][i];
		if(e->a == pv || e->b == pv) { // parent
			continue;
		} else { // child
			uint nv = (e->a == v) ? e->b : e->a;
			if(c == pe.c) {
				c++;
			}
			e->c = c;
			c++;
			dfs(*e, nv, g);
		}
	}
}

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

	vector<vector<shared_ptr<Edge>>> G(N, vector<shared_ptr<Edge>>());
	vector<shared_ptr<Edge>> ab;
	uint max_dgree = 0;
	
	for(uint i=0; i<N-1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		shared_ptr<Edge> edge(new Edge());
		edge->a = a;
		edge->b = b;
		ab.push_back(edge);
		G[a].push_back(edge);
		G[b].push_back(edge);
		max_dgree = max(max_dgree, (uint)max(G[a].size(), G[b].size()));
	}
	
	cout << max_dgree << endl;
	
	Edge de = {-1, -1, -1}; // dummy edge;
	dfs(de, 0, G);

	for(uint i=0; i<N-1; i++) {
		cout << ab[i]->c << endl;
	}

	
	return 0;
}


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


int main(){
  int x,y,z;
  cin>>x>>y>>z;
  int a,b,c;
  a=z;
  b=x;
  c=y;
  cout<<a<<' '<<b<<' '<<c;

  }


Measured memory_bytes: 256
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
l3 = list(map(int,input().split()))

l = l1 + l2 + l3

cnt = []
for i in range(1,5):
    c = 0
    for j in l:
        if i == j:
            c += 1
    cnt.append(c)

cnt.sort()

if cnt == [1,1,2,2] :
    print("YES")
else:
    print("NO")   


Measured memory_bytes: 38512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1000000007;
int a[404],b[404];
int h[404][404];
int dp[404][404];
int main()
{
	int n,c;
	scanf("%d%d",&n,&c);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]);
	memset(h,0,sizeof(h));
	for(int i=1;i<=400;i++)
		h[0][i]=1;
	for(int i=1;i<=400;i++)
		for(int j=1;j<=400;j++)
			h[i][j]=(long long)h[i-1][j]*j%mod;
	for(int i=0;i<=400;i++)
		for(int j=1;j<=400;j++)
			(h[i][j]+=h[i][j-1])%=mod;
	memset(dp,0,sizeof(dp));
	dp[1][c]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=c;j++)
			if(dp[i][j])
			{
				for(int k=0;k<=j;k++)
					dp[i+1][j-k]=((long long)dp[i][j]*(h[k][b[i]]-h[k][a[i]-1]+mod)+dp[i+1][j-k])%mod;
			}
	printf("%d",dp[n+1][0]);
	return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
using namespace std;

#define rep(i,M,N) for (int i = M; i < N; i++)
#define rep1(i,M,N) for (int i = M; i > N; i--)
#define MAX(x,y) ((x)>(y)?(x):(y))

int main(){
    
    string s;
    while(cin>>s){
        int count = 0;
        char rev = s[0];
        for(char c:s) if(c != rev){
            rev = c;
            count ++;
        }
        cout<<count<<endl;
    }
    return 0;
}

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

int main(){
	int h,w,m;
	cin>>h>>w>>m;
	int x[h]={},y[w]={};
	int xmax=0,ymax=0;
	int xi[m],yi[m];
	for(int i=0;i<m;++i){
		cin>>xi[i]>>yi[i];
		x[xi[i]-1]++;
		y[yi[i]-1]++;
	}
	int nox=0;
	int noy=0;
	for(int i=0;i<h;++i){
		xmax=max(xmax,x[i]);
	}
	for(int i=0;i<h;++i){
		if(xmax==x[i]) ++nox;
	}
	for(int i=0;i<w;++i){
		ymax=max(ymax,y[i]);
	}
	for(int i=0;i<w;++i){
		if(ymax==y[i]) ++noy;
	}
	long long count = (nox*1LL)*noy;
	for(int i=0;i<m;++i){
		if(x[xi[i]-1]==xmax&&y[yi[i]-1]==ymax){
			--count;
		}
	}
	if(count){
		cout<<xmax+ymax;
	}else{
		cout<<xmax+ymax-1;
	}
	
}




Measured memory_bytes: 8316
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod1 = 1e9 + 7;
const int mod2 = 998244353;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int N, S;

int main()
{
	cin >> N >> S;
	vector<int> a(N);
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}

	vector<vector<ll>> dp(N + 1, vector<ll>(S + 1));

	dp[0][0] = 1;

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j <= S; j++)
		{
			if (j + a[i] <= S)
			{
				dp[i + 1][j + a[i]] += dp[i][j] % mod2;
			}
			dp[i + 1][j] += 2 * dp[i][j] % mod2;
			dp[i + 1][j] %= mod2;
		}
	}
	cout << dp[N][S] << "\n";
}

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

#define vi vector<int>

int solve(int k, vi& xs){
	sort(xs.begin(), xs.end()); // ordena o vector

	// xs.back --> Returns a reference to the last element in the vector.
	xs.back() *= (1<<k); // shiftar 1 vez pra esquerda eh multiplicar por 2

	return accumulate(xs.begin(), xs.end(), 0);
}


int main(){
	vi xs(3);

	for(int i=0; i<3; i++)
		cin>>xs[i];
	
	int k;

	cin>> k;

	auto ans = solve(k, xs);

	cout<<ans<<'\n';

	return 0;
}

/*
HOW accumulate WORKS:

accumulate(first, last, sum);
first, last : first and last elements of range 
              whose elements are to be added
sum :  initial value of the sum

*/

Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 666666
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

X, Y = map(int, input().split())

if (X + Y) % 3 != 0:
    print(0)
else:    
    bg = max(X, Y)
    sm = min(X, Y)

    z = (bg + sm) // 3
    a = z - (z * 2 - bg)
    b = z - a
    
    print(cmb(a+b,a,mod))
    

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

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

  int result = x < a ? 0 : 10;

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    sx, sy, tx, ty = map(int, rl().split())
    dx, dy = tx - sx, ty - sy
    
    ans = 'U' * dy + 'R' * dx
    ans += 'D' * dy + 'L' * dx
    ans += 'L' + 'U' * (dy + 1) + 'R' * (dx + 1) + 'D'
    ans += 'R' + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U'
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<i64> a(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	
	auto dp = make_v<i64>(n + 1, n + 1);
	auto used = make_v<bool>(n + 1, n + 1);
	for(int i = 0; i < n + 1; i++) for(int j = 0; j < n + 1; j++) used[i][j] = dp[i][j] = 0;
	std::function<i64 (int, int)> solve = [&](int L, int R) {
		if(R < 0 or L > n) return 0LL;
		if(R - L + 1 == 0) return 0LL;
		if(used[L][R]) return dp[L][R];
		
		bool turn = ((R - L + 1) % 2 == n % 2);
		if(turn) {
			if(!used[L][R]) dp[L][R] = -(1LL << 60);
			
			dp[L][R] = std::max({dp[L][R], solve(L + 1, R) + a[L], solve(L, R - 1) + a[R]});
		} else {
			if(!used[L][R]) dp[L][R] = (1LL << 60);
	
			dp[L][R] = std::min({dp[L][R], solve(L + 1, R) - a[L], solve(L, R - 1) - a[R]});
		}
		used[L][R] = true;
		return dp[L][R];
	};
	solve(0, n - 1);
	if(n == 1) dp[0][n - 1] = a[0];
	
	printf("%lld\n", dp[0][n - 1]);
	return 0;
}


Measured memory_bytes: 72576
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define N 0
#define INF 0x3f3f3f3f
#define LL long long
#define mz(x) ms(x,0)
#define ms(x,y) memset(x,y,sizeof(x))
#define mc(x,y) memcopy(x,y,sizeof(y))
#define MOD 1000000007

using namespace std ;

int main()
{
	int n ;
	LL d ;
	scanf ("%d%lld", &n, &d) ;
	
	LL d2 = d * d ;
	int sum = 0 ;
	for (int i=0; i<n; i++)
	{
		LL a, b ;
		scanf ("%lld%lld", &a, &b) ;
		
//		cout << a * a + b * b << " " << d2 << endl ;
		if (a * a + b * b <= d2)
			sum++ ;
	}
	
	cout << sum << endl ;

	return 0 ;
}

Measured memory_bytes: 3256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    public static void solve(Scanner sc) {
        long n = sc.nextLong();
        long power = 1;
        long mod = (long)(Math.pow(10, 9) + 7);
        for (int i = 1; i <= n; i++) {
            power = (power % mod) * (i % mod) % mod;
        }
        System.out.println(power);
    }
}

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

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

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

	vector<vector<pair<int, int>>> w(N + 1, vector<pair<int, int>>()); //(部屋,道番号)
	vector<pair<int, int>> result(N + 1, make_pair(N + 100, -1));	   //(距離, 道)

	int a, b;
	for (int i = 1; i < M + 1; i++)
	{
		scanf("%d %d", &a, &b);
		w[a].insert(w[a].end(), make_pair(b, i));
		w[b].insert(w[b].end(), make_pair(a, i));
	}

	queue<int> que;

	que.push(1);
	result[1].first = 0;
	result[1].second = 0;
	while (!que.empty())
	{
		int n = que.front();
		// std::cout << n << "\n";
		que.pop(); // 先頭要素を削除
		for (int i = 0; i < w[n].size(); i++)
		{
			pair<int, int> now = w[n][i];
			// cout << "now is w[" << n << "][" << i << "]=" << now.first << " " << now.second << "\n";
			if (result[now.first].first <= result[n].first + 1)
			{
				continue;
			}
			result[now.first].first = result[n].first + 1;
			result[now.first].second = n;
			que.push(now.first);
			// cout << "hoge";
		}
	}

	cout << "Yes\n";

	for (int i = 2; i <= N; i++)
	{
		cout << result[i].second << "\n";
	}
	return 0;
}

Measured memory_bytes: 12764
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
int n,K,S;
int main(){
	scanf("%d%d%d",&n,&K,&S);
	For(i,1,K) cout<<S<<' ';
	For(i,K+1,n) cout<<(S==1000000000?S-1:S+1)<<' ';
} 

Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=1e5+5;
ll n,l,a[maxn];

inline ll rd(){
	ll ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

int main(){
	n=rd(); l=rd();
	go(i,n+1,1) a[i]=rd();
	int pos=0;
	go(i,n,1)
		if(a[i]+a[i+1] >= l){
			pos=i; break;
		}
	if(pos == 0) puts("Impossible");
	else{
		puts("Possible");
		go(i,pos,1) printf("%d\n",i);
		for(rg int i=n-1;i>=pos;i--) printf("%d\n",i);
	}
	return 0;
}//Faze


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

int main(){
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;

	if(u == s) a--;
	else b--;

	cout << a << " " << b << endl;

	return 0;
}


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

struct edge{int to,cost;};
vector<edge> G[100000];
int n,m,d[100000];
bool visited[100000];
string ans = "Yes";

void bfs(int r){
    queue<int> que;
    que.push(r);
    d[r] = 0;
    visited[r] = 1;
    while(!que.empty()){
        int p = que.front();que.pop();
        for(int i = 0;i < G[p].size();i ++){
            edge x = G[p][i];
            if(visited[x.to]){
                if(d[x.to]-d[p]!=x.cost) {ans="No";return ;}
            }else{
                d[x.to] = d[p]+x.cost;
                que.push(x.to);
            }
            visited[x.to] = 1;
        }
    }
    return ;
}

int main(){
    cin >> n >> m;
    for(int i = 0;i < m;i ++){
        int l,r,d;
        cin >> l >> r >> d;
        l --;r --;
        G[l].push_back({r,d});
        G[r].push_back({l,-d});
    }
    for(int i = 0;i < n;i ++){
        if(visited[i]) continue;
        bfs(i);
        if(ans=="No") break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
         
typedef long long ll;
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);}
          

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    string s,s1;
    int a ,b;
    cin >> a >> b;
    char c[a + 2][b + 2];
    memset(c,'#',sizeof(c));
    for(int i = 1; i < a + 1; ++i){
        for(int j = 1; j < b + 1; ++j){
                cin >> c[i][j];
        }
    }
   for(int i = 0; i < a + 2; ++i){
        for(int j = 0; j < b + 2; ++j){
            cout << c[i][j];
        }
        cout << '\n';
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
ll N;
ll v[312345];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  for (int i = 0; i < 3 * N; ++i) cin >> v[i];

  multiset<ll> st1;
  multiset<ll, greater<ll>> st2;

  ll sum1 = 0;
  ll sum2 = 0;
  for (int i = 0; i < N; ++i) {
    sum1 += v[i];
    st1.insert(v[i]);
  }

  for (int i = 2 * N; i < 3 * N; ++i) {
    sum2 += v[i];
    st2.insert(v[i]);
  }

  ll ret = sum1 - sum2;
  ll ss1[N + 1];
  ll ss2[N + 1];

  ss1[0] = sum1;
  for (int i = 0; i < N; ++i) {
    st1.insert(v[N + i]);
    ll psum = ss1[i];

    psum += v[N + i];
    psum -= *st1.begin();
    st1.erase(st1.begin());
    ss1[i + 1] = psum;
  }


  ss2[N] = sum2;
  for (int i = N - 1; i >= 0; --i) {
    st2.insert(v[N + i]);
    ll psum = ss2[i + 1];

    psum += v[N + i];
    psum -= *st2.begin();
    
    st2.erase(st2.begin());
    ss2[i] = psum;
  }

  for (int i = 0; i <= N; ++i) {
    ret = max(ret, ss1[i] - ss2[i]);
  }
  cout << ret << endl;
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;

const ll INF = (1LL<<60);

int main(){

    ll a, b; cin >> a >> b;

    if(0<a && a<10 && 0<b && b<10){
        cout << a*b << endl;
        return 0;
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3544
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()
	if n == m {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>

int main(){
  
  int a,b,n;
  
  scanf("%d%d",&a,&b);
  
  if(a>=b){
    
    n=a%b;
    
    while(n!=0){
      
      a=b;
      
      b=n;
      
      n=a%b;
      
    }
    
    printf("%d\n",b);
    
  }
  
  else{
    
    n=b%a;
    
    while(n!=0){
      
      b=a;
      
      a=n;
      
      n=b%a;
      
    }
    printf("%d\n",a);
  }
  return 0;
}




Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
vll A(2 * (1e5) + 1), F(2 * (1e5) + 1);
ll N, K;
bool can(ll X)
{
    ll Min = INF, cnt = 0;
    rep(i, N)
    {
        if (A[i] * F[i] > X)
        {
            cnt += A[i] - X / F[i];
        }
    }
    return (cnt <= K);
}
int main()
{

    cin >> N >> K;
    A.resize(N);
    F.resize(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> F[i];
    sort(all(A));
    sort(all(F), greater<ll>());
    ll ok = INF / 2, ng = -1;
    while (abs(ok - ng) > 1)
    {
        ll mid = (ok + ng) / 2;
        if (can(mid))
        {
            ok = mid;
        }
        else
        {
            ng = mid;
        }
    }
    cout << ok;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main(){
ll N, Ans = pow(10, 6);cin >> N;
string S;cin >> S;
vector<pair<ll, ll>> A(N);
pair<ll, ll> total{0, 0};

rep(i, 0, N){
if(i != 0){A[i].first = A[i - 1].first;A[i].second = A[i - 1].second;}

if(S[i] == 'W')A[i].first++;
else A[i].second++;
}

rep(i, 0, N){
if(S[i] == 'W')total.first++;
else total.second++;
}

//rep(i, 0, N)cout << A[i].first << " " << A[i].second << endl;

rep(i, 0, N){

if(S[i] == 'W'){
Ans = min(A[i].first - 1 + total.second - A[i].second, Ans);
}

if(S[i] == 'E'){
Ans = min(A[i].first + total.second - A[i].second, Ans);
}
}
cout << Ans;
}

Measured memory_bytes: 8196
/*
     Contest  :
     Task    :
*/
 
#include <bits/stdc++.h>
using namespace std;
 
#define pb  push_back
#define mp  make_pair
#define ll  long long
#define int long long
#define F_  first
#define S_  second
#define itr ::iterator 
 
typedef pair<int,int> pii;
 
const int MAX=3e5+99;
const int mod=1e9+7;
const int INF=1e16;
 
vector<pii> vec[MAX];
 
int N,M,S,T,X,Y,Z,dp[MAX][2],dis[MAX][2];
 
void dijkstra(int node,int K)
{
	pair<int,int> cur;
	priority_queue<pii,vector<pii>,greater<pii>> pq;
	for(int A=1;A<=N;A++)
	dis[A][K]=INF,dp[A][K]=0;
	dp[node][K]=1;
	dis[node][K]=0;
	pq.push(mp(0,node));
	while(! pq.empty())
	{
		cur=pq.top();
		pq.pop();
		if(cur.first > dis[cur.second][K])
		continue;
		for(auto A:vec[cur.second])
		{
			if(cur.first+A.second < dis[A.first][K])
			{
				dis[A.first][K]=cur.first+A.second;
				dp[A.first][K]=dp[cur.second][K];
				pq.push(mp(dis[A.first][K],A.first));
			}
			else if(cur.first+A.second == dis[A.first][K])
{
			dp[A.first][K]+=dp[cur.second][K];
			dp[A.first][K]%=mod;
}
		}
	}
	return ;
}
 
int solve()
{
	int D,cnt=0;
	dijkstra(S,0);
	dijkstra(T,1);
	D=dis[T][0];
	for(int A=1;A<=N;A++)
	if(dis[A][0]==dis[A][1] and dis[A][0]+dis[A][1]==D)
	{
		cnt+=(((dp[A][0]*dp[A][1])%mod) * ((dp[A][0]*dp[A][1])%mod))%mod;
		cnt%=mod;
	}
	for(int A=1;A<=N;A++)
	for(auto B:vec[A])
	if(dis[A][0]<D/2+D%2 and dis[B.first][1]<D/2+D%2 and dis[A][0]+B.second+dis[B.first][1]==D)
	{
		cnt+=(((dp[A][0]*dp[B.first][1])%mod)* ((dp[A][0]*dp[B.first][1])%mod))%mod;
		cnt%=mod;
	}
	cnt=(dp[T][0]*dp[S][1])%mod-cnt;
	cnt%=mod;
	while(cnt<0)
	cnt+=mod;
	return cnt;
}
 
signed main()
{
	ios_base::sync_with_stdio(false);
	/*cin.tie(0);
	cout.tie(0);*/
	
	cin>>N>>M;
	cin>>S>>T;
	for(int A=1;A<=M;A++)
	{
		cin>>X>>Y>>Z;
		vec[X].pb(mp(Y,Z));
		vec[Y].pb(mp(X,Z));
	}
	cout<<solve();
    return 0;
}

Measured memory_bytes: 27220
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    cout<<(1000-(n%1000))%1000;
}


Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	string s;
	int ans = 0;
	
	cin>>N;
	cin>>s;
	
	for(int i = 1; i < N-1; i++){
		string X = s.substr(0,i);
		string Y = s.substr(i,N-i);
		
		int con[26] = {}, Z = 0;
		int con2[26] = {};
		
		for(int j = 0; j < X.size(); j++){
			con[X[j] - 'a']++;
		}
		for(int j = 0; j < Y.size(); j++){
			con2[Y[j] - 'a']++;
		}
		
		for(int i = 0; i < 26; i++){
			if(con[i] && con2[i]) Z++;
		}
		ans = max(ans, Z);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    vector<int> num(n);
    int a, b;
    rep(i, n) {
        cin >> p.at(i);
        num.at(i) = p.at(i);
    }
    sort(num.begin(), num.end());
    rep(i, n) {
        cin >> q.at(i);
    }
    int aa = 0, bb = 0;
    do {
        int i = 0;
        for (int x : num) {
            if (p.at(i) != x) goto nexta;
            i++;
        }
        a = aa;
        nexta:
        int j = 0;
        for (int x : num) {
            if (q.at(j) != x) goto nextb;
            j++;
        }
        b = bb;
        nextb:;
        aa++;
        bb++;
    } while (next_permutation(num.begin(), num.end()));
    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  int l;
  cin>>n;
  int max=0,sum=0;
  for(int i=0;i<n;i++){
    cin>>l;
    if(max<l)max=l;
    sum+=l;
  }
  sum-=max;
  if(max<sum){
    cout<<"Yes\n";
  }else{
    cout<<"No\n";
  }
  return 0;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
long long ans[200000] = {};
long long woa[200000] = {};
int main() {
	long long n;
	cin >> n;
	vector<int> changed;
	changed.push_back(0);
	vector<long long> a;
	vector<pair<long long,long long>> b;
	a.push_back(0);
	b.push_back(make_pair(0,0));
	REP(i, n) {
		long long tmp;
		cin >> tmp;
		if (a[changed[changed.size() - 1]] < tmp) changed.push_back(i + 1);
		a.push_back(tmp);
		b.push_back(make_pair(tmp,i+1));
	}
	sort(b.begin(), b.end());
	for (int i = 0;i < b.size();++i) {
		woa[b[i].second] = i;
	}
	priority_queue<long long> unsolved;//場所を持っておく
	long long max_it = changed.size()-1;
	long long cnt = 0;
	//最大化
	for (int i = changed[max_it] + 1;i < a.size();++i) {
		unsolved.push(woa[i]);
	}
	for (int t = 0;t >= 0;++t) {
		long long next_max = changed[max_it - 1];
		for (int i = next_max + 1;i <= changed[max_it];++i) {
			unsolved.push(woa[i]);
		}
		ans[changed[max_it]] += cnt * (a[changed[max_it]] - a[next_max]);
		while (unsolved.empty() == false) {
			int aaa = unsolved.top();
			if (aaa < woa[next_max]) break;
			unsolved.pop();
			cnt++;
			ans[changed[max_it]] += b[aaa].first - b[woa[next_max]].first;
		}
		max_it--;
		if (max_it == 0) break;
	}
	for (int i = 1;i <= n;++i) {
		cout << ans[i] << " ";
	}
	cout << endl;
}

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

int n, m, len[300000], i, ind;

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

	cin >> n >> m;
	for (i=1; i<=n; i++) {
		cin >> len[i];
	}
	for (i=1; i<n; i++) {
		if (len[i]+len[i+1]>=m) {
			ind=i;
			break;
		}
	}
	if (ind==0) {
		cout << "Impossible";
	}
	else {
		cout << "Possible" << endl;
		for (i=1; i<ind; i++) {
			cout << i << endl;
		}
		for (i=n-1; i>=ind; i--) {
			cout << i << endl;
		}
	}

}

Measured memory_bytes: 1280
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
op=[LI() for i in range(n)]
pro=[LI() for i in range(n)]
vals=[]
for j in range(1,2**10):
    ans=0
    common=[0 for i in range(n)]
    for k in range(n):
        for i in range(10):
            x=(j>>i) %2
            common[k]+=x*op[k][i]
        ans+=pro[k][common[k]]
    vals.append(ans)
print(max(vals))

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

using namespace std;

using ll = long long;

struct State {
    int at;
    ll cost;
    //int prev;
    State(int at, ll cost/*, int prev*/) : at(at), cost(cost)/*, prev(prev)*/ {}
    bool operator>(const State& s) const {
        //if (cost != s.cost) return cost > s.cost;
        //if (prev != s.prev) return prev > s.prev; //最短経路を辞書順最小にする(省略可)
        //return at > s.at;
        return cost > s.cost;
    }
};

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

using Graph = vector<vector<Edge> >; //隣接リスト

const ll INF = 1e15;
//const int NONE = -1;

//sは始点、mincは最短経路のコスト、prevsは最短経路をたどる際の前の頂点
void dijkstra(int s, const Graph& graph, vector<ll>& minc/*, vector<int>& prevs*/){
    minc.assign(graph.size(), INF);
    //prevs.assign(graph.size(), NONE);

    priority_queue<State, vector<State>, greater<State> > pq;
    pq.emplace(s, 0/*, NONE*/);
    minc[s] = 0;

    while(!pq.empty()) {
        State cur = pq.top();
        pq.pop();
        if (minc[cur.at] < cur.cost) continue; 

        for(const Edge& e : graph[cur.at]) {
            ll cost = cur.cost + e.cost;
            if (minc[e.to] <= cost) continue;
            minc[e.to] = cost;
            //prevs[e.to] = cur.at;
            pq.emplace(e.to, cost/*, cur.at*/);
        }
    }
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    Graph g1(n), g2(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        ll a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        g1[u].emplace_back(v, a);
        g1[v].emplace_back(u, a);
        g2[u].emplace_back(v, b);
        g2[v].emplace_back(u, b);
    }
 
    vector<ll> minc1(n, INF), minc2(n, INF);
    dijkstra(s, g1, minc1);
    dijkstra(t, g2, minc2);
 
    vector<ll> ans(n, INF);
    for (int i = n - 1; i >= 0; i--) {
        ans[i] = min(ans[i], minc1[i] + minc2[i]);
        if (i < n - 1) ans[i] = min(ans[i], ans[i + 1]);
    }
 
    for (int i = 0; i < n; i++) {
        cout << INF - ans[i] << endl;
    }
    return 0;
}


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

int n, m;
bool know[110][110];
int check[110];
int ans;

int main(void){
	int i, j, id;
	while(cin >> n, n){
		memset(know, 0, sizeof(know));
		memset(check, 0, sizeof(check));
		ans = -1;
		for(i = 1; i <= n; i++){
			cin >> j;
			while(j--){
				cin >> id;
				know[i][id] = true;
			}
		}
		cin >> j;
		while(j--){
			cin >> id;
			check[id] = true;
		}
		for(i = 1; i <= n; i++){
			for(j = 1; j <= n; j++){
				if(check[j] && !know[i][j]) break;
			}
			if(j == n+ 1){
				if(ans != -1){ ans = -1; break;}
				ans = i;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#include <stdio.h>
 
int main(void){
     
    int num1 = 0;    // 1つ目の数値
    int num2 = 0;    // 2つ目の数値
    int answer = 0;  // 算出した最大公約数を入力
     
     
    // 数値取得（空白区切りで2個入力されると、私は信じている。）
    scanf("%d%d", &num1, &num2);
     
    // 最大公約数の算出
    while(1)
    {
        // "大きい値"を"小さい値"で割って余りを取得する。余りがゼロの場合、終了。
        // そうでないなら、"余り"と"小さい値"を使って、次回ループで再度計算する。
        if (num2>=num1)
        {
            num2 = num2%num1;
            if(num2 == 0)
            {
                answer = num1;
                break;
            }
        }
        else
        {
            num1 = num1%num2;
            if(num1 == 0)
            {
                answer = num2;
                break;
            }
        }
    }
     
    // 回答表示
    printf("%d\n",answer);
     
    return 0;
}


Measured memory_bytes: 2076
n = int(input())
count = 0

for i in range(n):
    al, be = map(int, input().split())
    if al == be:
        count += 1
        if count >= 3:
            print("Yes")
            break
    else:
        count = 0
else:
    print("No") if count < 3 else print("Yes")


Measured memory_bytes: 9164
#include <cstdio>
char s[5];
int main ()
{
scanf ("%s", &s);
int a = s[0] - '0', b = s[1] - '0',c=s[2] - '0', d = s[3] - '0';
if (a -b -c - d ==7)
  printf ("%d-%d-%d-%d=7\n " ,a ,b ,c , d );
else if (a -b - c + d ==7)
  printf ("%d-%d-%d+%d=7\n " ,a ,b ,c , d );
else if (a - b +c - d ==7)
  printf ("%d-%d+%d-%d=7\n " ,a ,b ,c , d );
else if (a - b + c + d ==7)
  printf ("%d-%d+%d+%d=7\n " ,a ,b ,c , d );
else if ( a +b -c - d ==7)
  printf ("%d+%d-%d-%d=7\n " ,a ,b ,c , d );
else if ( a +b- c + d ==7)
  printf ("%d+%d-%d+%d=7\n " ,a ,b ,c , d );
else if ( a + b +c - d ==7)
  printf ("%d+%d+%d-%d=7\n " ,a ,b ,c , d );
else if ( a + b + c + d ==7)
  printf ("%d+%d+%d+%d=7\n " ,a ,b ,c , d );
}


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



int main() {
  vector<vector<int>> A(3, vector<int>(3, 0));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A[i][j];
    }
  }
  vector<vector<int>> R(3, vector<int>(3, false));
  int N; cin >> N;
  rep(i,N) {
    int B; cin >> B;
    rep(j,3) {
      rep(k,3) {
        if (A[j][k] == B) {
          R[j][k] = true;
        }
      }
    }
  }

  string result = "No";
  rep(i,3) {
    if (R[0][i] && R[1][i] && R[2][i]) result = "Yes";
    if (R[i][0] && R[i][1] && R[i][2]) result = "Yes";
  }
  if (R[0][0] && R[1][1] && R[2][2]) result = "Yes";
  if (R[0][2] && R[1][1] && R[2][0]) result = "Yes";

  cout << result << endl;
  return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	REP(i,9){
		REP(j,9){
			cout << i+1 << 'x' << j+1 << '=' << (i+1)*(j+1) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3108