akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int d[310][310];

void warshall_floyd(int n){
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++)
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

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

	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			d[i][j] = INF;
		}
		d[i][i] = 0;
	}

	for(int i = 0; i < M; i++){
		long long int A, B, C;
		cin >> A >> B >> C;
		d[A - 1][B - 1] = C;
		d[B - 1][A - 1] = C;
	}

	warshall_floyd(N);
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(d[i][j] <= L){
				d[i][j] = 1;
			}else{
				d[i][j] = INF;
			}
		}
	}

	warshall_floyd(N);
	
	int Q;
	cin >> Q;

	for(int i = 0; i < Q; i++){
		int s, t;
		cin >> s >> t;
		s -= 1;
		t -= 1;
		if(d[s][t] == INF){
			cout << -1 << endl;
		}else{
			cout << d[s][t] - 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1280
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    def COMinit(n,MOD):
        fac,finv,inv=[0]*max(2,n+1),[0]*max(2,n+1),[0]*max(2,n+1)
        fac[0]=fac[1]=1
        finv[0]=finv[1]=1
        inv[1]=1
        for i in range(2,(n+1)):
            fac[i]=fac[i-1]*i%MOD
            inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
            finv[i]=finv[i-1]*inv[i]%MOD
        return fac,finv,inv
    
    fac,finv,inv=COMinit(10**5,MOD)
    
    def COM(n, k, MOD=MOD):
        if n<k or n<0 or k<0:
            return 0
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
    
    
    N,M=map(int,input().split())
    if abs(N-M)==0:
        print(fac[N]*fac[M]*2%MOD)
    elif abs(N-M)==1:
        print(fac[N]*fac[M]%MOD)
    else:
        print(0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 41072
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 3005;
const int mo = 1e+9+7;

int n,m;
int a[N],R[N];
int pre[N],ps[N];
int f[N][N];

int add(int x,int y){return x+y>=mo?x+y-mo:x+y;}

int main(){
	n=get();m=get();
	fo(i,1,n){
		char ch;
		while(ch=getchar(),ch<'0'||ch>'1');
		a[i]=ch-'0';
	}
	fo(i,1,m){
		int l=get(),r=get();
		R[l]=max(R[l],r);
	}
	fo(i,1,n){
		if (R[i]>pre[i-1])pre[i]=R[i];
		else R[i]=0,pre[i]=pre[i-1];
	}
	fo(i,1,n)ps[i]=ps[i-1]+a[i];
	f[0][0]=1;
	fo(i,0,n-1){
		int cnt,ad;
		if (!R[i+1]&&pre[i+1]<i+1)cnt=1,ad=a[i+1];
		if (!R[i+1]&&pre[i+1]>=i+1)cnt=pre[i]-i,ad=0;
		if (R[i+1])cnt=R[i+1]-i,ad=ps[R[i+1]]-ps[max(i,pre[i])];
		fo(j,0,n){
			if (j+ad)f[i+1][j+ad-1]=add(f[i+1][j+ad-1],f[i][j]);
			if (cnt-(j+ad))f[i+1][j+ad]=add(f[i+1][j+ad],f[i][j]);
		}
	}
	printf("%d\n",f[n][0]);
	return 0;
}

Measured memory_bytes: 35456
#include <stdio.h>
int main(void){
  int N;
  int s;
  int i;
  int o;
  scanf("%d",&N);
  o=N;
  for(i=0;i<10;i++){
    int a;
    if(o==0){
      break;
    }
    else{
      a=o%10;
      s=s+a;
      o=o/10;
    }
  }
  if(N%s==0){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 1632
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,d,e,k;
  cin>>a;
  cin>>b;
  cin>>c;
  cin>>d;
  cin>>e;
  cin>>k;
  if((e-a) > k)
  {
    cout<<":(";
  }
  else
  {
    cout<<"Yay!";
  }
  return 0;
}


Measured memory_bytes: 256
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
P x[300005];int n;
bool ok(int num)
{
	priority_queue<int>que;
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		int border=x[i].f;
		ll lim=1LL*border*num;
		que.push(x[i].s);
		sum+=x[i].s;
		while(sum>lim)
		{
			sum-=que.top(); que.pop();
		}
		if(que.size()>=num) return 1;
	}
	return 0;
}
int main()
{
	srand((unsigned int)time(NULL));
	scanf("%d",&n);
	for(int i=0,a,b;i<n;i++)
	{
		scanf("%d %d",&a,&b);
		x[i]=mp(b,a);
	}
	sort(x,x+n,greater<P>());
	int lb=0,ub=n+5;
	while(ub-lb>1)
	{
		int mid=(lb+ub)>>1;
		if(ok(mid)) lb=mid;
		else ub=mid;
	}
	printf("%d\n",lb);
}

Measured memory_bytes: 7512
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> v(N,0);
  REP(k,K){
    int d;
    cin>>d;
    REP(i,d){
      int A;
      cin>>A;
      A--;
      v[A]++;
    }
  }
  int ans=0;
  for(auto e:v)if(e==0)ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>k>>n;
    int arr[n];
    for(int &x:arr)
        cin>>x;
    sort(arr,arr+n);
    int max=k-arr[n-1]+arr[0];
    for(int i=0;i<n-1;i++)
    { if(abs(arr[i]-arr[i+1])>max)
        max=abs(arr[i]-arr[i+1]);}
    cout<<k-max;

}

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

using namespace std;


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

    int type = -1;
    int ans = 1;
    for (int i = 1; i < N; i++) {
        int inc = a[i - 1] < a[i];
        if (a[i - 1] != a[i] && type != -1 && type != inc) {
            type = -1;
            ans++;
        }else if (a[i - 1] != a[i]) {
            type = inc;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n;
  double sum=0,t1,t2,ans;
  cin >> n;
  vvd xy(n, vd(2, 0));
  rep(i,0,n){
    cin >> xy[i][0] >> xy[i][1];
  }
  
  rep(i,0,n){
    rep(j,0,n){
      sum+= sqrt(pow(xy[i][0]-xy[j][0],2)+pow(xy[i][1]-xy[j][1],2));
    }
  }
  ans= sum/n;
  cout << setprecision(11) << ans << endl;
}


Measured memory_bytes: 256
import numpy as np

N, M, C = map(int, input().split()) # 横に2個
B = np.array(list(map(int, input().split()))) # 横に2個

c = 0
for i in range(N):
    Ai = np.array(list(map(int, input().split())))
    if Ai.dot(B) + C > 0:
        c += 1

print(c)


Measured memory_bytes: 12504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		ll h,w;
		cin>>h>>w;
		if(h==1 ||  w==1) {
		cout<<1;
		return 0;}
		if((h*w)%2==0) cout<<(h*w)/2;
		else cout<<((h*w)/2+1);
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char s[101];
	int countChar = 0, countHug = 0;
	int i = 0;

	scanf("%s", s);

	while (s[i])
	{
		countChar++;
		i++;
	}

	for (i = 0; i < countChar / 2; i++)
	{
		if (s[i] != s[countChar - 1 - i])
		{
			countHug++;
		}
	}

	printf("%d\n", countHug);

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

vector<long long> deep;
vector<vector<int> > to;
vector<bool> done;
vector<vector<int> > dis;

void dfs(int id,int d)
{
	deep[id]=d;
	done[id]=true;
	for(int i=0;i<to[id].size();i++)
	{
		int nxid=to[id][i];
		if(done[nxid]!=true)dfs(nxid,(deep[id]+dis[id][i])%2);
	}
}

int main()
{
	int n;
	cin >> n;
	deep=vector<long long>(n,0);
	to=vector<vector<int> >(n);
	done=vector<bool>(n,false);
	dis=vector<vector<int> >(n);

	for(int i=0;i<n-1;i++)
	{
		int u,v,w;
		cin >> u >> v >> w;
		u--;v--;w%=2;
		to[u].push_back(v);
		to[v].push_back(u);
		dis[u].push_back(w);
		dis[v].push_back(w);
	}

	deep[0]=0;

	dfs(0,0);


	for(int i=0;i<n;i++)
		cout << deep[i] << endl;


}

Measured memory_bytes: 13696
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	int ans=0,n=s.size();
	for(int i=0;i<n;i++){
		if(s[i]!=t[i]) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3912
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
#define in(n) for (int i=0; i<n;i++)
#define inj(n)for (int j=0; j<n;j++)
using namespace std;
using ll=long long;
using pii=pair<int, int>;

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;

ll f(ll n) {
	return (n * (n + 1)) / 2;
}

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

	for (int i = K; i <= N +1; i++) {
		ans += (f(N) - f(N - i)) - f(i - 1) + 1;
		ans %= MOD;
	}

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

Measured memory_bytes: 3632
from itertools import combinations
n=int(input())
l=list(map(int, input().split()))
base = list(combinations(l,3))
c = len(base)
ans=0
for i in range(c):
  if base[i][0]==base[i][1] or base[i][0]==base[i][2] or base[i][1]==base[i][2]:
    continue
  ct1 = base[i][0]+base[i][1]
  ct2 = base[i][0]+base[i][2]
  ct3 = base[i][1]+base[i][2]
  if ct1>base[i][2] and ct2>base[i][1] and ct3>base[i][0]:
    ans+=1
    #print(base[i])
print(ans)
#print(ct1)

Measured memory_bytes: 20548
n, m = map(int, input().split())
ps = []
for _ in range(m):
    p, s = input().split()
    ps.append((int(p), s))
was = [0]*(n+1)
total_ac = 0
total_wa = 0
for p, s in ps:
    if was[p]<0:
        continue
    if s=='AC':
        total_wa += was[p]
        total_ac += 1
        was[p] = -1
    else:
        was[p] += 1
print(total_ac, total_wa)

Measured memory_bytes: 19732
import bisect
N = int(input())
A = list(map(int,input().split()))
left = [A[i] + i for i in range(N)]
right = [j - A[j] for j in range(N)]
right.sort()

ans = 0
for i in range(N):
	x = left[i]
	ans += bisect.bisect_right(right, x) - bisect.bisect_left(right, x)
print(ans)

Measured memory_bytes: 33916
n=gets.to_i
 
arr=gets.split.map(&:to_i)
 
arr2=[]
 
i=0
n.times{
    arr2<<arr[i]-i
    
    i+=1
}
 
 
arr3=arr2.sort
 
 
 
key=arr3[n/2]
   
ans=0
j=0
n.times{
   ans+=(arr[j]-key-j).abs
    
   j+=1 
}
  
puts ans


Measured memory_bytes: 20736
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <functional>

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>

using namespace std;
using ll = long long;

int main() {
	int N;
	cin >> N;
	vector<ll> a(N);
	ll amax = -1000000 - 1;
	ll amin = 1000000 + 1;
	int amax_ele, amin_ele;
	REP(i, N) {
		cin >> a[i];
		amax = max(amax, a[i]);
		if (amax == a[i]) amax_ele = i;		
		amin = min(amin, a[i]);
		if (amin == a[i]) amin_ele = i;
	}
	if (amax == amin) {
		cout << 0 << endl;
		return 0;
	}

	VI x, y;

	if (abs(amax) >= abs(amin)) {
		REP(i, N) {
			if (a[i] < 0) {
				a[i] += amax;
				x.push_back(amax_ele);
				y.push_back(i);
			}
		}
		REP(i, N-1) {
			if (a[i] > a[i + 1]) {
				a[i + 1] += a[i];
				x.push_back(i);
				y.push_back(i + 1);
			}
		}	
	}

	if (abs(amax) < abs(amin)) {
		REP(i, N) {
			if (a[i] > 0) {
				a[i] += amin;
				x.push_back(amin_ele);
				y.push_back(i);
			}
		}
		REP(i, N - 1) {
			if (a[N - 1 - i]  < a[N - 1 - (i + 1)]) {
				a[N - 1 - (i + 1)] += a[N - 1 - i];
				x.push_back(N - 1 - i);
				y.push_back(N - 1 - (i + 1));
			}
		}
	}
	cout << x.size() << endl;
	REP(i, x.size()) cout << x[i] + 1 << " " << y[i] + 1 << endl;
	return 0;
}

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

using namespace std;

typedef long long int LL;
typedef unsigned long long uLL;
const int inf = (int)1e9;
const LL INF = (LL)2e18;
const int N = 100005;
const int mod = 1000000007;
const double eps = 1e-8;
const double pi = acos( -1.0 );

int ara[ 10 ];

int main( int argc, char const *argv[] ) {
    cin >> ara[1] >> ara[2] >> ara[3];
    int k;
    cin >> k;
    sort( ara+1 , ara+3+1 );
    while( k-- ) {
        ara[3] *= 2;
    }
    cout << ara[1]+ara[2]+ara[3] << endl;
    return 0;
}








Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] n = sc.next().toCharArray();
    int sum = 0;
    for (char nn : n) {
      sum += Character.getNumericValue(nn);
    }
    String ans = sum % 9 == 0 ? "Yes" : "No";
    System.out.println(ans);
    sc.close();
  }
}


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

using namespace std;

int n, k, q;

int main()
{
    cin >> n >> k >> q;

    vector<int> a(n, k-q);

    for (int i = 0; i < q; i++) {
        int x;
        cin >> x;
        a[x-1]++;
    }

    for (auto i : a) {
        if (i > 0) cout << "Yes\n";
        else cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
v = [int(x) for x in input().split()]
v_1 = {}
v_2 = {}
k = 1
for i in v:
    if k == 1:
        if i in v_1:
            v_1[i] = v_1[i]+1
        else:
            v_1[i] = 1
    else:
        if i in v_2:
            v_2[i] = v_2[i]+1
        else:
            v_2[i] = 1
    k = -k

v_11 = sorted(v_1.items(), key=lambda x:x[1], reverse=True)
v_12 = sorted(v_2.items(), key=lambda x:x[1], reverse=True)

a1, b1 = v_11[0][1], v_12[0][1]
if len(v_11) == 1:
    a2 = -1
else:
    a2 = v_11[1][1]
if len(v_12) == 1:
    b2 = -1
else:
    b2 = v_12[1][1]
if v_11[0][0] != v_12[0][0]:
    ans = n-a1-b1
elif a2 == -1:
    if b2 == -1:
        ans = n-n//2
    else:
        ans = n-a1-b2
else:
    if b2 == -1:
        ans = n-a2-b1
    else:
        ans = min(n-a2-b1,n-a1-b2)
print(ans)

Measured memory_bytes: 22368
N = int(input())
A_lst = [[int(x) for x in input().split()] for i in range(2)]
c_lst = []
for i in range(N):
    cnt = 0
    for j in range(i + 1):
        cnt += A_lst[0][j]
    for j in range(i, N):
        cnt += A_lst[1][j]
    c_lst.append(cnt)
print(max(c_lst))


Measured memory_bytes: 3060
#include<stdio.h>

int main(){
        int H,W,i,j;

        while(1){
                scanf("%d %d",&H,&W);
                if(H==0 && W==0)break;

                for(i=0;i<H;i++){
                        for(j=0;j<W;j++){
                                printf("#");
                        }
                        printf("\n");
                }
                printf("\n");
        }

        return 0;
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 2005;

ll dp[MAX_N][MAX_N];

ll add(ll x,ll y)
{
    return (x + y)%MOD;
}

ll sub(ll x,ll y)
{
    return (x+MOD-y)%MOD;
}

ll mul(ll x,ll y)
{
    return x*y%MOD;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<char> vec(n);
    rep(i,n){
        cin >> vec[i];
    }
    // svec(vec);
    dp[0][0] = 1;
    rep(i,n){
        rep(j,i+1){
            if(vec[i] == '-'){
                dp[i+1][j] = add(dp[i+1][j],dp[i][j]);
            }else if(vec[i] == 'D'){
                dp[i+1][j] = add(dp[i+1][j],mul(j,dp[i][j]));
                if(j != 0){
                    dp[i+1][j-1] = add(dp[i+1][j-1],mul(j*j,dp[i][j]));
                }
            }else{
                dp[i+1][j] = add(dp[i+1][j],mul(j,dp[i][j]));
                dp[i+1][j+1] = add(dp[i+1][j+1],dp[i][j]);
            }
        }
    }
    // rep(i,n+1){
    //     rep(j,i+1){
    //         cout << i << " " << j << " " << dp[i][j] << "\n";
    //     }
    // }
    cout << dp[n][0] << "\n";
    return 0;
}

Measured memory_bytes: 4148
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define true 1
#define false 0
int solve(int,int);
int A[20];
int n;
int main(){
  int q,key;
  int i,j,sol;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    j=0;
    sol=solve(j,key);
    if(sol==true)printf("yes\n");
    if(sol==false)printf("no\n");
  }
  return 0;
}
int solve(int i,int key){
  int res;
  if(key==0)return true;
  if(i>=n)return false;
  res = solve(i + 1, key) || solve(i + 1, key - A[i]);
  return res;
}




Measured memory_bytes: 2108
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
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;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    int x;
    cin >> x;
    if (x >= 30) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>

#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

int main() {
    int n, k, d[10];
    cin >> n >> k;
    for (int i = 0; i < k; i++)cin >> d[i];
    while (1) {
        int t = n;
        bool ans = true;
        while (t > 0) {
            int digit = t % 10;
            t /= 10;
            for (int i = 0; i < k; i++) {
                if (d[i] == digit) {
                    ans = false;
                    break;
                }
            }
            if (!ans)break;
        }
        if (ans) {
            cout << n << endl;
            return 0;
        }
        n++;
    }
    return 0;
}


Measured memory_bytes: 256
import itertools

n=int(input())
l=[i+1 for i in range(n)]
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
cnt=0
P=0;Q=0
for i in itertools.permutations(l):
  cnt+=1
  if p==i:P=cnt
  if q==i:Q=cnt
print(abs(P-Q))

Measured memory_bytes: 39280
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1

using namespace std;

const int INF = 1e18;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int n, q;
vector<vector<int>> G;
map<int, int> mp;
int counter[300000];
int seen[300000];
void culc(int cur, int score)
{
    seen[cur] = true;
    int curScore = score + mp[cur];
    counter[cur] = curScore;
    for (auto nv : G[cur])
    {
        if (seen[nv])
            continue;
        culc(nv, curScore);
    }
}

void solve()
{
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("./sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n >> q;
    G.resize(n);
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    rep(i, q)
    {
        int q, x;
        cin >> q >> x;
        q--;
        mp[q] += x;
    }
    memset(seen, 0, sizeof(seen));
    memset(counter, 0, sizeof(counter));

    culc(0, 0);

    rep(i, n) cout << counter[i] << " ";
    cout << endl;
}

signed main()
{
    solve();
    return 0;
}


Measured memory_bytes: 46208
/* B Depth First Search */

#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
int time;
int A[101][101]; /* 1<= n <= 100 */
int color[101];
int d[101],f[101];

void DFS();
void DFS_Visit(int u);

int main(){
  int i,j;
  int u,k,v;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    d[i]=0;
    f[i]=0;
    for(j=1;j<=n;j++){
      A[i][j]=0;
    }
  }
  

  for(i=1;i<=n;i++){
    scanf("%d %d",&u,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&v);
      A[u][v]=1;
    }
  }
  
  DFS();

  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  

  return 0;
}

void DFS(){
  int i;

  for(i=1;i<=n;i++){
    color[i]=WHITE;
  }
  
  time = 0;
  
  for(i=1;i<=n;i++){
    if(color[i]==WHITE){
      DFS_Visit(i);
    }
  }
}

void DFS_Visit(int u){
  int i;
  color[u]=GRAY;
  time=time+1;
  d[u]=time;
  for(i=1;i<=n;i++){
    if(A[u][i]==1){ /* check array element */
      if(color[i]==WHITE){
	DFS_Visit(i);
      }
    }
  }
  color[u]=BLACK;
  time=time+1;
  f[u]=time;
}
    

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

const int maxn = 1e5+5;
int N;
int x[maxn], y[maxn];
    
int parent[maxn]; //memset to -1
int Find(int x) {
    return parent[x] < 0 ? x : parent[x] = Find(parent[x]);
}

void Union(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y) return;
    if (parent[x] > parent[y]) swap(x,y);
    parent[x] += parent[y];
    parent[y] = x;
}

struct Point
{
    int x, y, id;
};

struct Edge
{
    int u, v, wt;
};

int main()
{
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    memset(parent,-1,sizeof parent);
    vector<Point> xs, ys;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
        xs.push_back({x[i],y[i],i});
        ys.push_back({x[i],y[i],i});
    }
    vector<Edge> edges;
    sort(xs.begin(),xs.end(),[](auto a, auto b) {
            return a.x < b.x; });
    sort(ys.begin(),ys.end(),[](auto a, auto b) {
            return a.y < b.y; });
    for (int i = 0; i < N-1; i++) {
        edges.push_back({xs[i].id,xs[i+1].id,xs[i+1].x-xs[i].x});
    }
    for (int i = 0; i < N-1; i++) {
        edges.push_back({ys[i].id,ys[i+1].id,ys[i+1].y-ys[i].y});
    }
    sort(edges.begin(),edges.end(),[](auto a, auto b) { return a.wt < b.wt; });
    ll ans = 0;
    for (Edge e: edges) {
        if (Find(e.u) == Find(e.v)) continue;
        else {
            ans += e.wt;
            Union(e.u,e.v);
        }
    }
    cout << ans << '\n';
}



Measured memory_bytes: 8364
#include<stdio.h>
int main(){
    int N,i,j;
    int A[100001];
    int B[100001];
    scanf("%d",&N);
    for(i = 1 ; i <= N ; i++){
        scanf("%d",&A[i]);
    }
    for(i = 1 ; i <= N ; i++){ //出席番号
        B[A[i]] = i;
    }
    for(j = 1 ; j <= N ; j++){
        printf("%d ",B[j]);
    }
    return 0;
}


Measured memory_bytes: 1536
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))
ans = 0
flag = 0
for i in range(n-1):
    if flag:
        flag = 0
        continue
    if lst1[i] == lst1[i+1]:
        ans += 1
        flag = 1

print(ans)

Measured memory_bytes: 61832
#include<bits/stdc++.h>
using namespace std;
using LL = long long;

int main(){
    string s;
    int k;
    cin >> s >> k;
    int l = s.size();
    for(int i = 0;i < l-1;i++){
        int d = 'z'-s[i]+1;
        if(d < 26 && k >= d){
            k -= d;
            cout << 'a';
        }else{
            cout << s[i];
        }
    }
    if(k > 0){
        cout << char((s[l-1]-'a'+k%26)%26+'a');
    }else{
        cout << s[l-1];
    }
    cout << endl;
}

Measured memory_bytes: 512
import sys
input=sys.stdin.buffer.readline

L=[]
for _ in range(int(input())):
  x,l=map(int,input().split())
  L.append((x-l,x+l))

L.sort(key=lambda x:x[1])
ans=0
cur=-11111111111111111
for a,b in L:
  if a>=cur:
    cur=b
    ans+=1
print(ans)

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

int n, a, b;

int digit_sum(int num) {
  int result = 0;
  rep (i, 5) {
    result += num % 10;
    num /= 10;
  }
  return result;
}

int ans = 0;

int main() {
  cin >> n >> a >> b;
  rep (i, n) {
    if (a <= digit_sum(i) and digit_sum(i) <= b) ans += i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int w = sc.nextInt();
		ArrayList<Long> v1 = new ArrayList<>();
		ArrayList<Long> v2 = new ArrayList<>();
		ArrayList<Long> v3 = new ArrayList<>();
		ArrayList<Long> v4 = new ArrayList<>();
		long firW = sc.nextLong();
		long firV = sc.nextLong();
		v1.add(firV);
		for(int i = 0; i < n-1 ; i++) {
			int sa = (int) (sc.nextLong() - firW);
			switch (sa) {
			case 0:
				v1.add(sc.nextLong());
				break;
			case 1:
				v2.add(sc.nextLong());
				break;
			case 2:
				v3.add(sc.nextLong());
				break;
			case 3:
				v4.add(sc.nextLong());
				break;
			}
		}
		v1.sort(Comparator.reverseOrder());
		v2.sort(Comparator.reverseOrder());
		v3.sort(Comparator.reverseOrder());
		v4.sort(Comparator.reverseOrder());
		for(int i = 1; i < v1.size(); i++) {
			v1.set(i, v1.get(i-1)+v1.get(i));
		}
		for(int i = 1; i < v2.size(); i++) {
			v2.set(i, v2.get(i-1)+v2.get(i));
		}
		for(int i = 1; i < v3.size(); i++) {
			v3.set(i, v3.get(i-1)+v3.get(i));
		}
		for(int i = 1; i < v4.size(); i++) {
			v4.set(i, v4.get(i-1)+v4.get(i));
		}
		v1.add(0, 0L);
		v2.add(0, 0L);
		v3.add(0, 0L);
		v4.add(0, 0L);
		Long ans = 0L;
		for(int $1 = 0; $1 < v1.size(); $1++) {//0～size個まで取る
			for(int $2 = 0; $2 < v2.size(); $2++) {
				for(int $3 = 0; $3 < v3.size(); $3++) {
					for(int $4 = 0; $4 < v4.size(); $4++) {
						if(firW*$1 + (firW+1)*$2 + (firW+2)*$3 + (firW+3)*$4 <= w) {
							ans = Math.max(ans, v1.get($1)+v2.get($2)+v3.get($3)+v4.get($4));
						}
					}
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 28500
n = int(input())
tbl = [[0 for i in range(13)] for j in range(4)]

for n in range(n):
    suit, i = input().split()
    i = int(i)
    if suit == 'S':
        tbl[0][i-1] = i
    elif suit == 'H':
        tbl[1][i-1] = i
    elif suit == 'C':
        tbl[2][i-1] = i
    elif suit == 'D':
        tbl[3][i-1] = i

for y in range(4):
    for x in range(13):
        if tbl[y][x] == 0:
            if y == 0:
                print(f'S {x+1}')
            elif y == 1:
                print(f'H {x+1}')
            elif y == 2:
                print(f'C {x+1}')
            elif y == 3:
                print(f'D {x+1}')


Measured memory_bytes: 5620
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int x[101], y[101], h[101];

int calcCH(int x, int y,int h, int cx, int cy) {
	return h + abs(x - cx) + abs(y - cy);
}
int calcH(int H, int x, int y, int cx, int cy) {
	return max(H - abs(x - cx) - abs(y - cy), 0LL);
}

vector<vector<int>> ansCand;

signed main() {
	int N, x;
	cin >> N >> x;
	int arr[200001];
	bool used[200001];
	for (int i = 1; i <= 2*N-1; i++) {
		arr[i] = 0;
		used[i] = false;
	}
	if (x == 1 || x == 2 * N - 1) { 
		cout << "No\n";
		return 0;
	}
	else if (N == 2) {
		cout << "Yes\n";
		cout << "1\n2\n3";
		return 0;
	}
	else if(x == 2*N - 2){
		arr[N] = x;
		arr[N - 1] = x + 1;
		arr[N + 1] = x - 1;
		arr[N - 2] = x - 2;
		used[x] = used[x + 1] = used[x - 1] = used[x - 2] = true;
	}
	else {
		arr[N] = x;
		arr[N - 1] = x - 1;
		arr[N + 1] = x + 1;
		arr[N - 2] = x + 2;
		used[x] = used[x + 1] = used[x - 1] = used[x + 2] = true;
	}
	int usedInd = 1;
	for (int i = 1; i <= 2 * N - 1; i++) {
		if (arr[i] != 0) continue;
		while (used[usedInd])usedInd++;
		arr[i] = usedInd;
		used[usedInd] = true;
	}
	cout << "Yes\n";
	for (int i = 1; i <= 2 * N - 1; i++) {
		if (i < 2 * N - 1) cout << arr[i] << "\n";
		else cout << arr[i];
	}

	return 0;
}

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

int main()
{
    cout << fixed << setprecision(18);
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
    ll n, k, var, count = 0;
    cin >> n >> k;
    for (ll i = 0; i < n; i++)
    {
        cin >> var;
        if (var >= k)
        {
            count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int ans = 0;
	string str;
	cin>>str;
	int size = str.size();
	for(int i=0;i<size;++i){
		if(str[i]=='+'){
			ans++;
		}else{
			ans--;
		}
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


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

using namespace std;

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

  int count = 0;
  //  int _B = B; 
  while (B <= A) {
    B *= 2;
    count++;
  }

  //int _C = C;
  while (C <= B) {
    C *= 2;
    count++;
  }

  string result = "No";

  if (count <= K) {
    result = "Yes";
  }

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


Measured memory_bytes: 3168
#include<stdio.h>
int main()
{
	int m,n,i,j;
	char a[105][105];
	while(scanf("%d%d\n",&m,&n)!=EOF)
	{
	for(i=0;i<m;i++)
	     {
	     	for(j=0;j<n;j++)
	     	{
	     	scanf("%c",&a[i][j]);
	     	}
	     	getchar();
	     }
	for(j=0;j<n+1;j++)
	{
	printf("#");
	}
	printf("#\n");
	for(i=0;i<m;i++)
	{
		printf("#");
		for(j=0;j<n;j++)
		{
		printf("%c",a[i][j]);
		}
		printf("#\n");
	}
	for(j=0;j<n+1;j++)
	{
	printf("#");
	}
	printf("#\n");
     }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
int n,a[105],i,s,mn=1<<30,id;
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",a+i),s+=a[i];
	for(i=1;i<=n;++i)if(abs(a[i]*n-s)<mn)mn=abs(a[i]*n-s),id=i;
	printf("%d\n",id-1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define all(x) begin(x), end(x)
#define range(x) begin(x), begin(x)
#define what(x) cout << #x << ": " << x << '\n'
#define print(x) for (auto &el: x) cout << el << ' '; cout << '\n'
using namespace std;
 
template<typename S, typename T>
ostream& operator <<(ostream &os, pair<S, T> &m) { 
    os << '[' << m.first << " " << m.second << ']';
    return os;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
 
    ll a;
    int main, frac;
    cin >> a >> main;
    cin.ignore();
    cin >> frac;
    ll b = main * 100 + frac;
    cout << (a * b) / 100 << endl;
 
    return 0;
}

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

bool field[10][6];
int dir = 1;
int dx[] = { 0, 1, 0, -1 }, dy[] = { -1, 0, 1, 0 };
int x = 1, y = 0;
char s[5] = "URDL";

bool safe( int x, int y )
{
	return x >= 0 && x < 9 && y >= 0 && y < 9;
}

char g[9][9];

int main()
{
	for( int i = 0; i != 9; ++i )
	{
		std::string line;
		std::cin >> line;

		bool odd = i & 1;
		for( int j = !odd; j < 9; j += 2 )
		{
			g[i][j] = line[j/2] - '0' ? odd ? '|' : '_' : ' ';
			g[i][j+1] = '.';
		}

		if( !odd )
			g[i][0] = '.';
	}
	
	do
	{
		int fdir = ( 4 + dir - 1 ) % 4;
		int fx = x + dx[dir] + dx[fdir], fy = y + dy[dir] + dy[fdir];

		if( !safe( x, y ) || g[y][x] == ' ' )
		{
			x -= dx[dir], y -= dy[dir], dir = ( dir + 1 ) % 4;
			x += dx[dir], y += dy[dir];
		}
		else if( safe( fx, fy ) && ( g[fy][fx] == '_' || g[fy][fx] == '|' ) )
		{
			std::cout << s[dir];
			x += dx[dir], y += dy[dir], dir = ( 4 + dir - 1 ) % 4;
			x += dx[dir], y += dy[dir];
		}
		else
		{
			x += dx[dir] * 2, y += dy[dir] * 2;
			std::cout << s[dir];
		}

		if( x == 1 && y == 0 )
		{
			std::cout << s[dir];

			break;
		}
	}while( true );

	std::cout << std::endl;
	
	return 0;
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll p[100], q[100], r[100], b[100];
ll memo[100];
ll dfs(int k){
  if(k == 0) return 1;
  k --;
  if(memo[k] != -1) return memo[k];
  ll A = dfs(r[k]);
  ll B = dfs(b[k]);
  A *= p[k];
  B *= q[k];
  ll G = __gcd(A, B);
  ll L = A * B / G;
  return memo[k] = L / p[k] + L / q[k];
}

int main(){
  int n;
  while(cin >> n && n){
    REP(i, n) cin >> p[i] >> q[i] >> r[i] >> b[i];
    ll ans = 0;
    memset(memo, -1, sizeof memo);
    REP(i, n){
      ans = max(ans, dfs(i + 1));
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main()
{
    int n,m;
    cin>>n>>m;
    int a[m];
    int b[m-1];
    int result=0;
    for(int i=0;i<m;i++)
        cin>>a[i];
    sort(a,a+m);
    //for(int i=0;i<m;i++)
        //cout<<a[i]<<endl;
    for(int i=0;i<m-1;i++)
        b[i] = a[i+1]-a[i];
    //for(int i=0;i<m;i++)
        //cout<<a[i]<<endl;
    sort(b,b+m-1);
    result = a[m-1]-a[0];
    //cout<<"result:"<<result<<endl;
    for(int i=0;i<n-1 & i<m-1;i++)
        result -= b[m-2-i];
    cout << result;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int dp[(1<<15)+3],must=3;
int n,m;
int g[20][20],lg[(1<<15)+3];
int num[20][(1<<15)+3];
int pw[200];
const int mod=1e9+7;
int main(){
    //read
    scanf("%d%d",&n,&m);
    for(int i=1,f,t;i<=m;i++)
        scanf("%d%d",&f,&t),g[f-1][t-1]=1;
    //pre
    for(int i=0;i<n;i++) lg[1<<i]=i;
    pw[0]=1;for(int i=1;i<200;i++) pw[i]=pw[i-1]*2%mod;
    for(int i=0;i<n;i++)
        for(int S=1,t;S<(1<<n);S++)
            t=(S)&(-S),
            num[i][S]=num[i][S^t]+g[i][lg[t]];
    //solve
    dp[0]=1;
    for(int i=0;i<(1<<n);i++)
        for(int mask=(1<<n)-1-i,j=mask;j;j=(j-1)&mask)
            if( ( 1^(j&1) ^ ( (j&2) >>1) ) && dp[i]!=0 ){
                long long ways=1;
                for(int k=0;k<n;k++)
                    if(i&(1<<k)) (ways*=pw[num[k][j]]-1)%=mod;
                    else if(j&(1<<k)) (ways<<=num[k][i])%=mod;
                dp[i|j]=(dp[i|j]+dp[i]*ways)%mod;
            }
    
    cout<<((pw[m]-dp[(1<<n)-1])%mod +mod)%mod <<endl;
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long x, y;
    cin >> x >> y;

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

}


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

int main() {
	int N, M; cin >> N >> M;
	vector<int>x(N, 0); stack<int>s;
	vector<vector<pair<int, int>>>L(N), R(N);
	for (int i = 0, lef, rig, d; i < M; i++) {
		cin >> lef >> rig >> d; lef--; rig--;
		L[rig].push_back({ lef,d }); R[lef].push_back({ rig,d });
	}
	for (int i = 0; i < N; i++) {
		if (L[i].size() == 0) {
			x[i] = 1; s.push(i);
		}
	}

	bool ok = true;
	while (!s.empty()) {
		int node = s.top(); s.pop();
		for (int i = 0; i < R[node].size(); i++) {
			int next = R[node][i].first, xd = x[node] + R[node][i].second;
			if (x[next] == 0) {
				x[next] = xd;
				s.push(next);
			}
			else if (x[next] != xd) {
				ok = false; break;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		if (x[i] == 0)ok = false;
	}
	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 12288
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
//#define MOD 998244353

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

using namespace std;

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

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

	ll N, M;


	string S;

	cin >> S;

	ll count = 0;

	rep(i, S.size()) {
		if (S[i] == 'o') count++;
	}

	if (count >= (8 - (15 - (ll)S.size()))) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}


	return 0;



	
}



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

using namespace std;

int main(void) {

	string x, y;

	cin >> x >> y;

	if (x.at(0) == y.at(2)&& x.at(1) == y.at(1) && x.at(2) == y.at(0))cout<<"YES\n";
else cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256
n = gets.chomp!.to_i

ary = []

3.times do |i|
  gets.chomp!.split("").each_with_index do |k, idx|
    ary[idx] = [] if ary[idx].nil?
    ary[idx][i] = k
  end
end

puts ary.map{ |t| t.uniq.size - 1}.inject(:+)


Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>

using namespace std;

int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a%b);
}

int lcm(int a, int b)
{
	return a / gcd(a, b)*b;
}

int main()
{
	int a, b;
	while (cin >> a >> b) {
		cout << gcd(a, b) << " " << lcm(a, b) << endl;
	}
	return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef pair<int, string> PS;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

char color(char s, char l){
	if(s + l == 'r' + 'g') return 'b';
	if(s + l == 'r' + 'b') return 'g';
	if(s + l == 'b' + 'g') return 'r';
	return 0;
}

int main(void){
	
	string S;
	while(cin >> S){
		if(S == "0")break;
		int str_size = S.size();
		string R, G, B;
		rep(i, str_size){
			R += 'r';
			G += 'g';
			B += 'b';
		}
		bool flag = 0;
		queue<PS> que;
		que.push(PS(0, S));
		map<string, bool> state;
		while(que.size()){
			PS p = que.front(); que.pop();
			string str = p.second;
			
			if(str == R || str == G || str == B){
				flag = 1;
				cout << p.first << endl;
				break;
			}

			if(state[str]){
				continue;
			}
			state[str] = 1;

			rep(i, str.size()-1){
				if(str[i] != str[i+1]){
					char L = color(str[i], str[i+1]);
					string SS = str;
					SS[i] = L;
					SS[i+1] = L;
					que.push(PS(p.first+1,SS));
				}
			}
		}
		if(!flag) cout << "NA" << endl;
	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 3352
#include <iostream>
#include <string>
#include <iostream>
using namespace std;
 
int main(){
  string S, T;
  cin >> S >> T;
  int  A, B;
  cin >> A >> B;
  string U;
  cin >> U;
  
  if ( U == S ){
    cout << (A - 1) << " " << B << endl;
  }
  else if ( U == T ){
    cout << A << " " << (B - 1) << endl;
  }
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int               long long
#define ff                first
#define ss                second
#define md                1000000007
#define md1               998244353
#define inf               1000000000000000
#define minf              -1000000000000000
#define pb                push_back
#define in                insert
#define mkp               make_pair
#define mpll              map<ll,ll>
#define len(p)            (ll)p.size()
#define pll               pair<ll,ll>
#define all(v)            v.begin(),v.end()
#define mem(a,t)          memset(a,t,sizeof(a))
#define endl              "\n"
#define ar                array
#define vl                vector<ll>
#define vpll              vector<pair<ll,ll>>
#define f(i,yha,wha)      for(ll i=yha;i<wha;i++)
#define rf(i,wha,yha)     for(ll i=wha;i>=yha;i--)
#define f0(n)             for(ll i=0;i<n;i++)
#define f1(n)             for(ll i=1;i<=n;i++)
#define fg(i,yha,wha,gap) for(ll i=yha;i<wha;i+=gap)


void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


void solve()
{
    ll k, a, b;
    cin >> k >> a >> b;

    ll tim = b / k;

    k = k * tim;

    if (k <= b and k >= a)
        cout << "OK" << endl;
    else
        cout << "NG" << endl;



}

int32_t main()
{
    flash();
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3692
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define EVEL 1

#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;
    ll ans=0,id;
    int N,M;
    ll A,B,C,W;
    int a[100010];
    bool f=false;
    ll sum=0;
    string S;

int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    EREP(i,N)cin>>a[i];
    for(int i=1,j=1;;j++){
        i=a[i];
        if(i==2){
            ans=j;
            break;
        }
        if(j>6000000){
            ans=-1;
            break;
        }
    }



    cout<<ans;

    return 0;
}


Measured memory_bytes: 640
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, k: usize, mut a: [usize; n]);

    a.sort_unstable();

    let mut ans_vec = Vec::new();

    for i in 0..n {
        ans_vec.push(i);
    }
    let mut left = 0;
    let mut right = a[a.len() - 1];

    let func = |t_max| -> bool {
        let mut cat_sum = 0;
        for i in 0..a.len() {
            if a[i] <= t_max {
                continue;
            }
            cat_sum += a[i] / t_max;
        }
        cat_sum > k
    };
    while right - left > 1 {
        let buff = (left + right) / 2;

        if func(buff) {
            left = buff;
        } else {
            right = buff;
        }
    }

    println!("{}", right);
}


Measured memory_bytes: 7168
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A, B, C = LI()

    if A <= C <= B or B <= C <= A:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10020
fun main(args: Array<String>){
    val cards = listOf("S", "H", "C", "D").flatMap { s -> (1..13).map { i -> "$s $i" } }
    val n = readLine()!!.toInt()
    val x = (1..n).map { readLine()!!.split(" ").joinToString(" ") }
    cards.subtract(x).forEach(::println)
}


Measured memory_bytes: 26968