akhauriyash/Code-Regression huggingface dataset:
n,m = map(int,input().split())
sss = [list(map(int, input().split())) for i in range(m)]
pp = list(map(int, input().split()))

ans = 0
for i in range(2**n):
    chk = (bin(i)[2:]).zfill(10)
    all_tentou = True
    for i,ss in enumerate(sss):
        cnt = 0
        for s in ss[1:]:
            if chk[-s] == '1':
                cnt += 1
                
        if cnt % 2 != pp[i]:
            all_tentou = False
            break
    
    if all_tentou:

        ans += 1
    
print(ans)

Measured memory_bytes: 3064
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, stdout, BufWriter, Write};

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>,
}

impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn main() {
    let mut scan = Scanner::default();
    let out = &mut BufWriter::new(stdout());
    loop {
        let h:i32 = scan.next();
        let w:i32 = scan.next();
        if h == 0 && w == 0 { break; }
        for _ in 0..h {
            for _ in 0..w {
                write!(out, "#").ok();
            }
            writeln!(out).ok();
        }
        writeln!(out).ok();
    }
}


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

int num[1001][1001][3];

int main() {
    int M, N, K;
    cin >> M >> N >> K;
    for (int i = 1; i <= M; i++) {
            char c[1000];
            cin >> c;
        for (int j = 1; j <= N; j++) {
            for (int k = 0; k < 3; k++) {
                num[i][j][k] = num[i - 1][j][k] + num[i][j - 1][k] - num[i - 1][j - 1][k];
            }
            switch(c[j -1]) {
                case 'J':
                    num[i][j][0]++;
                break;
                case 'O':
                    num[i][j][1]++;
                break;
                case 'I':
                    num[i][j][2]++;
                break;
            }
        }
    }
    for (int i = 0; i < K; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        for (int j = 0; j < 3; j++) {
            cout << num[x2][y2][j] - num[x2][y1 - 1][j] - num[x1 - 1][y2][j] + num[x1 - 1][y1 - 1][j] << (j < 2 ? " " : "\n");
        }
    }
}


Measured memory_bytes: 14696
n = int(input())

def dfs(s):
    if int(s) > n:
        return 0
    ret = 0
    is753 = True
    for c in '753':
        if s.count(c) == 0:
            is753 = False
    if is753:
        ret+=1
    for c in '753':
        ret += dfs(s+c)
    return ret
print(dfs('0'))

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

using namespace std;

struct Restaurant
{
    int ID;
    char city[11];
    int scale;
}v[101];

bool compare(Restaurant stg, Restaurant dr)
{
    if (strcmp(stg.city, dr.city)==0)
    {
       return stg.scale>dr.scale;
    }
    else return strcmp(stg.city, dr.city)<0;
}

int n;
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        v[i].ID=i;
        cin>>v[i].city;
        cin>>v[i].scale;
    }

    sort(v+1, v+n+1, compare);

    for (int i=1; i<=n; i++)
        cout<<v[i].ID<<"\n";

    return 0;
}


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

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

    int h[N+K];
    int dp[N+K];
    for (int i=0; i<N;i++) {
        cin >> h[i];
        dp[i]=INT_MAX;
    }

    dp[0]=0;

    for (int i=0; i<N;i++) {
        for (int k=1; k<=K; k++) {
            if (dp[i + k] > dp[i] + abs(h[i] - h[i + k]))
            {
                dp[i + k] = dp[i] + abs(h[i] - h[i + k]);
            }
        }
    }

    cout << dp[N-1]<< endl;
} 


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <bitset>

#pragma comment(linker, "/STACK:36777216")
using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

typedef long double ptype;

long long mod = /*27449*//*998244353*/ 1e9 + 7 /*1e9 + 9*/;
int inf = 1e9;
double eps = 1e-8;
long double pi = acosl(-1);
ifstream in("input.txt");
ofstream out("output.txt");

int trymerge(string left, string right, string& res)
{
	if (left.size() < right.size())
	{
		int p = 0;
		int q = right.size() - 1;
		while (p < left.size() && left[p] == right[q])
		{
			p++;
			q--;
		}
		if (p == left.size())
		{
			res = right.substr(0, q + 1);
			return 2; // suffix part; 
		}
		return 0; // can't match
	}
	else
	{
		int p = 0;
		int q = right.size() - 1;
		while (q >= 0 && left[p] == right[q])
		{
			p++;
			q--;
		}
		if (q == -1)
		{
			res = left.substr(p, left.size() - p);
			return 1; // prefix part; 
		}
		return 0; // can't match
	}
}

bool isPalindrome(string s)
{
	string t = s;
	reverse(t.begin(), t.end());
	return s == t;
}

void solve()
{
	int n;
	cin >> n;
	vector<pair<string, int>> a(n);
	set<pair<long long, pair<int, string>>> q;
	map<pair<int, string>, long long> d;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first >> a[i].second;
		q.insert({ a[i].second, {0, a[i].first} });
	//	q.insert({ a[i].second, {1, a[i].first} });
		d[{0, a[i].first}] = a[i].second;
	//	d[{1, a[i].first}] = a[i].second;
	}
	while (q.size())
	{
		auto v = *(q.begin());
		q.erase(q.begin());
		long long dist = v.first;
		string cur = v.second.second;
		int orient = v.second.first;

		if (isPalindrome(cur))
		{
			cout << dist;
			return;
		}
		for (int i = 0; i < n; i++)
		{
			string r1;
			int res;
			if (orient)
			{
				res = trymerge(a[i].first, cur, r1);
			}
			else
			{
				res = trymerge(cur, a[i].first, r1);
			}
			if (res)
			{
				int or1 = res - 1;
				if (!d.count({ or1, r1 }))
				{
					d[{or1, r1}] = dist + a[i].second;
					q.insert({ d[{or1, r1}], {or1, r1} });
				}
				else if (d[{or1, r1}] > dist + a[i].second)
				{
					q.erase({ d[{or1, r1}], {or1, r1} });
					d[{or1, r1}] = dist + a[i].second;
					q.insert({ d[{or1, r1}], {or1, r1} });
				}
			}
		}

	}
	cout << -1;
}

int main()
{
	cout << setprecision(2) << fixed;
	cin.tie();
	cout.tie();
	clock_t t1 = clock();
	int t;
	//cin >> t;
	t = 1;
	while (t--) {
		solve();
	}
	//cout << (clock() - t1) * 1.0 / CLOCKS_PER_SEC;
	gg;
}

Measured memory_bytes: 3748
import sys

n, *W = map(int, sys.stdin.read().split())

def main():
    s1 = 0
    s2 = sum(W)
    res = s2
    for w in W:
        s1 += w
        s2 -= w
        res = min(res, abs(s2 - s1))
    
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

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

int main(void){
    string S;
    cin>>S;

    vector<char> s;

    for(int i=0;i<S.length();i++){
        if((i+1)%2==1)
            s.push_back(S[i]);
    }

    for(int i=0;i<s.size();i++)
        cout<<s[i];

    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int visited[10];
int ans, n, num[10], check[4];

int checkValue()
{
	int ret = 0;
	int cnt[4] = { 0, 0, 0, 0 };
	int arr[4] = { 0, 0, 0, 0 };
	for(int i = 0; i < n; i++)
	{
		arr[visited[i]] += num[i];
		cnt[visited[i]]++;
	}

	for(int i = 1; i < 4; i++)
	{
		if(arr[i] == 0) return 100000;
		ret += abs(arr[i] - check[i]) + 10 * (cnt[i] - 1);
	}

	return ret;
}

void dfs(int depth)
{
	if(depth == n)
	{
		int val = checkValue();
		
		ans = min(ans, val);
	}
	else
	{
		visited[depth] = 0;
		dfs(depth + 1);
		visited[depth] = 1;
		dfs(depth + 1);
		visited[depth] = 2;
		dfs(depth + 1);
		visited[depth] = 3;
		dfs(depth + 1);
	}
}

int main()
{
	cin >> n;
	for(int i = 1; i <= 3; i++) cin >> check[i];
	for(int i = 0; i < n; i++) cin >> num[i];

	ans = 100000;
	dfs(0);
	cout << ans << '\n';
}

Measured memory_bytes: 256
#include<iostream>	// 入出力
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか


using namespace std;


int main()
{
	int x, y;

	cin >> x >> y;

	int check[12] = { 1,3,1,2,1,2,1,1,2,1,2,1 };

	if (check[x - 1] == check[y - 1]) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  
  bool b=false;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(i*j==n) b=true;
    }
  }
  
  if(b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 3600
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]

x,y = map(int,input().split())

if (x in a) and (y in a):
  print("Yes")
elif (x in b) and (y in b):
  print("Yes")
elif (x in c) and (y in c):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);
struct edge{ll to,cost,num;};

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

const ll MAX_N=100010;

vector<ll> X(MAX_N);

struct UnionFind {
    private:
    vector<int> par,rank;
    vector<ll> Size;
    public:
    UnionFind(int n){
        par.resize(n);
        rank.resize(n,0);
        Size.resize(n);
        rep(i,n) par[i]=i;
        rep(i,n) Size[i]=X[i];
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    bool merge(int x, int y){
        x=root(x);
        y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y);
        if (rank[x]==rank[y]) ++rank[x];
        par[y]=x;
        Size[x]+=Size[y];
        return true;
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    ll size(int x){
        return Size[root(x)];
    }
};

int main(){
    ll N,M;
    cin >> N >> M;
    rep(i,N) cin >> X[i];
    vector<vector<ll>> G(M,vector<ll>(3));
    rep(i,M){
        cin >> G[i][1] >> G[i][2] >> G[i][0];
        --G[i][1],--G[i][2];
    }
    sort(G.begin(),G.end());
    UnionFind uf(N);
    vector<ll> candidate;
    rep(i,M){
        ll a=G[i][1],b=G[i][2];
        uf.merge(a,b);
        if (uf.size(a)>=G[i][0]) candidate.push_back(i);
    }
    reverse(candidate.begin(),candidate.end());
    vector<vector<edge>> es(N);
    rep(i,M){
        ll a=G[i][1],b=G[i][2],y=G[i][0];
        es[a].push_back(edge{b,y,i});
        es[b].push_back(edge{a,y,i});
    }
    vector<bool> ok(M,false);
    for (auto i:candidate){
        ll a=G[i][1],b=G[i][2],y=G[i][0];
        queue<Pll> que;
        que.push(Pll(i,a));
        que.push(Pll(i,b));
        ok[i]=true;
        while(!que.empty()){
            Pll p=que.front();
            que.pop();
            ll n=p.first,v=p.second;
            for (auto e:es[v]){
                if (e.num==n) continue;
                if (ok[e.num]||e.cost>y) continue;
                ok[e.num]=true;
                que.push(Pll(e.num,e.to));
            }
        }
    }
    ll ans=0;
    rep(i,M) if (!ok[i]) ++ans;
    cout << ans << endl;
}

Measured memory_bytes: 17908
def binary_search(a, tgt):
    low = 0
    high = len(a) - 1
    while low <= high:
        mid = (low + high) // 2
        cand = a[mid]
        
        if cand == tgt:
            return mid
        if cand > tgt:
            high = mid - 1
        else:
            low = mid + 1
    
    return -1

n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))

cnt = 0
for tgt in t:
    flag = binary_search(s, tgt)
    if flag >= 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 16708
from math import factorial
from functools import lru_cache

@lru_cache(maxsize=None)
def cmbcount(n):
    if n > 1:
        return factorial(n) // (factorial(n - 2) * factorial(2))
    return 0

N = int(input())
A = list(map(int, input().split()))
samecnt = [0] * (N + 1)
for a in A:
    samecnt[a] += 1
cnts = [cmbcount(n) for n in samecnt]
allcnt = sum(cnts)
for i in range(N):
    a = A[i]
    o = cnts[a]
    n = cmbcount(samecnt[a] - 1)
    ans = allcnt - (o - n)
    print(ans)

Measured memory_bytes: 121172
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/

typedef struct dict_num {
  long num;
  long count;
};

int main(void){
  int N;
  cin >> N;
  int a[N];
  //dict_num count_dict[N];
  int max = 1e+5;
  //cout << max << endl;
  int count[max+1];
  //cout <<"hello" << endl;
  vector<int> unique_num;
  int ans = 0;
  rep(i, N){
    cin>> a[i];
    if (a[i] > max) {
      ans ++;
      continue;
    }
    if (count[a[i]] == 0) unique_num.push_back(a[i]);
    count[a[i]]++;
  }
  
  int j;
  rep(i, unique_num.size()){
    j = unique_num[i];
   	if (count[j] < j) ans+= count[j];
    else ans += (count[j]-j);
  }
  cout << ans << endl;
  

}


Measured memory_bytes: 640
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
//#define scanf scanf_s
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<30);
const llint mod=1000000007;

/*printf("? %c %c\n",x,y);
		fflush(stdout);
		char ret;scanf(" %c", &ret);
		*/
int main(void){
	int i,j,k,N=200,a,b;
	vector<pair<int,int>> kotae;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		for(j=i+1;j<N;j+=10){
			printf("? ");
			for(k=0;k<N;k++){
				if(k==i||(j<=k&&k<j+10)){a=1;} else{a=0;}
				printf("%d",a);
			}
			printf("\n");
			fflush(stdout);
			scanf("%d",&a);
			if(a!=0){
				for(k=j;k<min(j+10,N);k++){
					printf("? ");
					for(int l=0;l<N;l++){
						if(l==i||k==l){b=1;} else{b=0;}
						printf("%d",b);
					}
				printf("\n");
				fflush(stdout);
				scanf("%d",&b);
				if(b!=0){kotae.pub(mp(i,k));}
				}
			}
		}
	}
	printf("!");
	for(i=0;i<kotae.size();i++){
		printf(" (%d,%d)",kotae[i].first,kotae[i].second);
		
	}
	printf("\n");
	fflush(stdout);
	return 0;
}



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

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

    long long int max_so_far = a[0],sum=0;

    for(int i=1;i<n;i++){
        if(a[i]>max_so_far){
            max_so_far = a[i];
        }
        else{
            sum += max_so_far-a[i];
        }
    }
    cout<<sum;

}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N), b(N), c(N), d(N);
    vector<Pll> p(N), q(N);
    rep(i,N){
        cin >> a[i] >> b[i];
        p[i] = Pll(a[i],b[i]);
    }
    rep(i,N){
        cin >> c[i] >> d[i];
        q[i] = Pll(c[i],d[i]);
    }
    sort(p.begin(),p.end());
    sort(q.begin(),q.end());
    vector<ll> memo(N);
    ll ans = 0;
    rep(i,N){
        ll Mb = -1;
        ll id = -1;
        rep(j,N){
            if(q[i].fi > p[j].fi && q[i].se > p[j].se && memo[j] == 0){
                if(Mb < p[j].se){
                    Mb = p[j].se;
                    id = j;
                }
            }
        }
        if(Mb != -1){
            memo[id] = 1;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include<stdio.h> 
#include<stack> 
int main(){
	std::stack<int> s;     
	int n;     
	scanf("%d",&n);     
	s.push(n);
	while(scanf("%d",&n)!=EOF){
		if(n!=0)s.push(n);         
		else{             
			printf("%d\n",s.top());             
			s.pop();         
		}     
	} 
} 

Measured memory_bytes: 1036
#include <iostream>
#include <string>
using namespace std;
int caesar(char s[]);
bool search(string s);

int main(){
	string str;
	unsigned int i;
	while(getline(cin,str)){
		int j=0;
		while(!search(str)){
			for(i=0;i<str.length();i++){
				if(str[i]!=' '&&str[i]!='.') str[i]++;
				if(str[i]>122) str[i]=97;
			}
			j++;
			if(j>25) break;
		}
		cout << str << endl;
	}
	return 0;
}

bool search(string s){
	if(s.find("this")!=string::npos) return true;
	if(s.find("that")!=string::npos) return true;
	if(s.find("the")!=string::npos) return true;
	return false;
}

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

using namespace std;

typedef long long LL;
typedef double db;
#define FAST ios::sync_with_stdio(false);
const int MaxN = 105;
int main()
{
	int a , b , w  ;
	cin >> w >> a >> b;
	if(a == b)cout << "0" << endl;
	else
	{
	int mn = min(a,b);
	int mx = max(a,b);
	int cnt1 = mn + w;
	if(cnt1 >= mx)
		cout << "0" << endl;
	else printf("%d\n",mx - cnt1);
	}
	return 0;
	}

Measured memory_bytes: 768
fun main(args: Array<String>) {
    val S = readLine()!!

    println(
        S.map {
            when (it) {
                'A', 'C', 'G', 'T' -> "A"
                else -> "Z"
            }
        }.joinToString("")
            .split("Z")
            .max()
            ?.length ?: 0
    )
}

Measured memory_bytes: 38344
/*

*/

#include <stdio.h>
#include <math.h>

int main()
{
	int n,i;
	double x[1000];
	double v,ans,sum,average;
	while(1){
		scanf("%d", &n);
		if(!n){
			break;
		}
		sum=0;
		for(i=0; i<n; i++){
			scanf("%lf", &x[i]);
			sum+=x[i];
		}
		average=sum/(double)n;
		sum=0;
		for(i=0; i<n; i++){
			x[i]-=average;
			x[i]*=x[i];
			sum+=x[i];
		}
		v=sum/(double)n;
		ans=sqrt(v);
		printf("%f\n", ans);
	}
	return 0;
}

Measured memory_bytes: 664
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int first = Integer.parseInt(scan.next());
        int second = Integer.parseInt(scan.next());
        //int third = Integer.parseInt(scan.next());
        //String s = scan.next();
        //String second = scan.next();
        //for (int i = 1; i <=input; i++) {
        //}
        if(first>9 || second >9) {
            System.out.println(-1);
        } else {
            System.out.println(first*second);
        }
    }

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 a, b;
  cin >> a >> b;
  set<int> st;
  st.insert(1);
  st.insert(2);
  st.insert(3);
  st.erase(a);
  st.erase(b);
  cout << *st.begin() << endl;
}


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

int main()
{
    string s, t;
    cin >> s >> t;
    int mintime = 1000;
    for (int i = 0; i < s.size() - t.size() + 1; i++)
    {
        int tmp = 0;
        for (int j = 0; j < t.size(); j++)
        {
            if (s.at(i + j) != t.at(j))
                tmp++;
        }
        if (mintime > tmp)
            mintime = tmp;
    }

    cout << mintime << endl;
}

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

using namespace std;
const int MAXN = 100005;

int dp[MAXN][3];

int main() {
  int n;
  cin >> n;
  
  vector< vector<int> > abc(n);
  for (int i = 0; i < n; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> t{a, b, c};
    abc[i] = t;
  }
  
  for (int i = 0; i < 3; ++i) dp[0][i] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (j == k) continue;
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + abc[i][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 3; ++i) ans = max(dp[n][i], ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6912
import numpy as np

N,M=map(int, input().split())
A=[]
for i in range(N):
    a=list(input())
    A.append(a)
B=[]
for i in range(M):
    b=list(input())
    B.append(b)

A=np.array(A)
B=np.array(B)
ans="No"
for i in range(N):
    for j in range(N):
        if i+M<=N and j+M<=N:
            if (A[i:i+M, j:j+M]==B).all():
                ans="Yes"

print(ans)

Measured memory_bytes: 27196
S = input()

f = False
c = 0
max_c = 0

for k, i in enumerate(S):
    if i == 'A' and f == False:
        f = True
        c += 1
    elif i == 'Z' and f == True:
        c += 1
        max_c = max(c, max_c)
        if S[k] != 'Z':
            f = False
    elif f == True:
        c += 1

print(max_c)

Measured memory_bytes: 3516
# 素因数分解
def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


N = int(input())
if N<=9:
    print(0)
    exit()

from collections import defaultdict
P = defaultdict(int)

for i in range(2, N+1):
    for p in prime_decomposition(i):
        P[p] += 1

c4 = len([k for k, v in P.items() if v >= 4])
c2 = len([k for k, v in P.items() if v >= 2])
c14 = len([k for k, v in P.items() if v >= 14])
c24 = len([k for k, v in P.items() if v >= 24])
c2 = len([k for k, v in P.items() if v >= 2])
c74 = len([k for k, v in P.items() if v >= 74])


print(c4 * (c4-1) // 2 * (c2-2) + c14 * (c4-1) + c24 * (c2-1) + c74)


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




int main() {
	
    string s;
    cin>>s;
  int i;
  if(s[0]=='Y'  && s[1]=='A' && s[2]=='K' && s[3]=='I')
      printf("Yes");
  
  else
     printf("No");
      
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int A1 = scan.nextInt();
		int A2 = scan.nextInt();
		int A3 = scan.nextInt();

		if (22 <= (A1 + A2 + A3)) {
			System.out.print("bust");
		} else {
			System.out.print("win");
		}

	}

}


Measured memory_bytes: 23892
n,a=map(int,input().split())
x=list(map(int,input().split()))
stack=[0]*5001
stack[2500]=1
ans=0
for i in range(len(x)):
  x[i]-=a
for i in x:
  ans+=stack[2500-i]
  stack2=[i for i in stack]
  for j in range(5001):
    if 0<=j+i<=5000:
      stack2[j+i]+=stack[j]
  stack=[i for i in stack2]
print(stack[2500]-1)



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

// Size付きUnion-Find木
struct UnionFind {

    // pos-子 値は親
    // neg-親 値は-size
    vector<int> pr;

    // コンストラクタ 親の初期値は自分(size)
    UnionFind(int n) : pr(n,-1) {};

    // 親を返す
    int root(int x) {
        if (pr[x] < 0) return x;
        return pr[x] = root(pr[x]);
    }

    // 木の統合 すでに同じ木ならfalse
    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (pr[rx] > pr[ry]) swap(rx,ry);
        pr[rx] += pr[ry];
        pr[ry] = rx;
        return true;
    }

    // 同じ木に属しているか
    bool same(int x, int y) { return root(x) == root(y); }

    int size(int x) { return -pr[root(x)]; }
};

int main(void)
{
    IOS
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    REP(i,M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
    }

    int ans = 0;
    REP(i,N) ans = max(ans,uf.size(i));

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3960
// Aizu Vol0 0037: Path on a Grid
// 2017.7.31

#include <stdio.h>

char *gets(char *);

#define MAX  6
#define R 0
#define L 1
#define U 2
#define D 3

char a[MAX][MAX];
int next[4][4] = {
	{1,2,4,8},
	{4,8,1,2},
	{8,1,2,4},
	{2,4,8,1} };

int r, c, last;

void move(int k)
{
//	printf("Move (r,c)=(%d,%d), last %d, next %d\n", r, c, last, k);
	if (k == 1) putchar('U'), r--, last = U;
	else if (k == 2) putchar('R'), c++, last = R;
	else if (k == 4) putchar('D'), r++, last = D;
	else putchar('L'), c--, last = L;
}

int main()
{
	int i;
	char buf[50];

	for (i = 0, r = 0; gets(buf) != NULL; i++) {
		r = i / 2;
		if (i & 1) {
			for (c = 0; c < 5; c++) {
				if (buf[c] == '1') 	a[r][c] |= 4, a[r + 1][c] |= 1;
			}
		} else {
			for (c = 0; c < 4; c++) {
				if (buf[c] == '1') 	a[r][c] |= 2, a[r][c + 1] |= 8;
			}
		}
	}

#if 0
	for (r = 0; r < 5; r++) {
		for (c = 0; c < 5; c++) printf("%d ", a[r][c]);
		printf("\n");
	}
#endif
	r = c = 0, last = R;
	do {
		for (i = 0; i < 4; i++) {
			if (a[r][c] & next[last][i]) {
				move(next[last][i]);
				break;
			}
		}
	} while (r || c);
	putchar('\n');
	return 0;
}

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

int dist(int a, int b) {
  return (a - b) * (a - b);
}

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

  vector<int> X(N);
  for (int i=0; i<N; i++) cin >> X.at(i);
  
  vector<int> distArray(100, 0);
  for (int i=0; i<100; i++){
    for (int j=0; j<X.size(); j++){
      distArray.at(i) += dist(i, X.at(j));
    }
  }
  
  sort(distArray.begin(), distArray.end());

  cout << distArray.at(0) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int check[31];

int main(void){
    int a, x;
    for(x = 1; x <= 30; x++){
        check[x] = 0;
    }
    for(x = 0; x < 28; x++){
        scanf("%d", &a);
        check[a] = 1;
    }
    for(x = 1; x <= 30; x++){
        if(check[x] == 0){
            printf("%d\n", x);
        }
    }
    return 0;
}

Measured memory_bytes: 596
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

s = list(input())
t = list(input())

s.sort()
t.sort(reverse=True)
if "".join(s) < "".join(t):
    print("Yes")
else:
    print("No")
# print("".join(s) < "".join(t))
# print(str("".join(s)) < str("".join(t)))


Measured memory_bytes: 38512
#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 n, k;
	cin >> n >> k;

	int p;
	vector<double> a(n);
	rep(i, n) {
		cin >> p;
		a[i] = (p + 1.0) / 2.0;
	}

	double sum = 0;
	rep(i, k) sum += a[i];

	double ans = sum;
	for (int i = k; i < n; i++) {
		sum = sum - a[i - k] + a[i];
		ans = max(ans, sum);
	}

	cout << to_string(ans) << endl;
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  string s;cin>>s;
  ll n=s.size();
  ll k=n/2;
  rep(i,0,n)if(s[i]!=s[n-i-1])judge=false;
  rep(i,0,k){
    if(s[i]!=s[k-i-1])judge=false;
    if(s[i+k+1]!=s[n-i-1])judge=false;
  }
  ans1(judge);
  return 0;
}

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

int main(){

    string s;
    cin >> s;
    vector<bool> b(26, false);
    for(int i = 0; i < (int)s.size(); i++)
    {
        int a = s[i] - 'a';
        b[a] = true;
    }
    int ans = -1;
    for(int i = 0; i < 26; i++)
    {
        if(!b[i]){
            ans = i;
            break;
        }
    }
    
    if(ans == -1) cout << "None" << endl;
    else cout << (char)(ans + 'a') << endl;
    
    
    return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    int N, P;
    string S;
    cin >> N >> P >> S;
    int L = S.length();
    ll ans = 0;
    if(P == 2 || P == 5){
        REP(i, L){
            if((S[i] - '0') % P == 0) ans += i + 1;
        }
        PRINT(ans);
        return 0;
    }
    reverse(ALL(S));
    ll pow = 1, mod = 0;
    map<int, int> mp;
    mp[0] = 1;
    REP(i, L){
        mod = (mod + (S[i] - '0') * pow) % P;
        pow = (pow * 10) % P;
        ans += mp[mod];
        mp[mod]++;
    }
    PRINT(ans);
    return 0;
}

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

using namespace std;

#define PB push_back
#define MP make_pair
#define X first
#define Y second

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define read(a) freopen(a,"r",stdin)
#define write(a) freopen(a,"w",stdout)
#define forall(i,a,b) for(int i=a;i<b;i++)
#define foreach(v, c) for(typeof((c).begin())v=(c).begin();v!=(c).end();++v)
#define read(a) freopen(a,"r",stdin)
#define write(a) freopen(a,"w",stdout)

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

clock_t start;
void Time(bool timeIt) {
	if (!timeIt) return;
	clock_t end = clock();
	double elapsed_time = ((db)end - (db)start) / (db)CLOCKS_PER_SEC;
	printf("Time elapsed = %0.4lf\n", elapsed_time); 
}

#define LINF (long long)1e18
#define EPS 1e-9
#define INF 1000000007ll
#define SIZE 100010
#define MAX_A 1000010

int main() {
	start = clock();

	ll n, k, ans = 0;
	cin >> n >> k;

	if (k == 0) cout << n * n << endl;
	else {
		for (ll b = k + 1 ; b <= n ; ++b) {
			ans += (b - k) * (n / b) + max(0ll, n % b - k + 1);
		}
		cout << ans << endl;
	}


	Time(false);
	return 0;
}

Measured memory_bytes: 256
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e18) + 1;
const int mod = 479001599;
const int maxn = 1e5 + 111;
        
using namespace std;          

int n, k, a[maxn];

void solve(){
	cin >> n >> k;

	for (int i = 1; i <= k; i++){
		int m;
		cin >> m;

		for (int j = 1; j <= m; j++){
			int x;
			cin >> x;
			a[x]++;
		}
	}

	int ans = 0;

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

	cout << ans;
}   
      
main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

    boost;
    
    int q = 1;

    //cin >> q;

    while (q--){
        solve();
    }
}

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

// main.cpp

int main() {
  std::string n;
  std::cin >> n;
  std::cout << ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]) ? "Yes" : "No") << std::endl;
  return 0;
}

Measured memory_bytes: 256
import sys
# input = sys.stdin.readline

def main():
    a, b = map(int, input().split())
    p = input().split("-")
    if len(p) != 2:
        print("No")
        return
    else:
        l, r = p
        
    if len(l) == a and len(r) == b:
        print("Yes")
    else:
        print("No")

main()

Measured memory_bytes: 2940
n = int(input())
cl = list(input())

ans = 0
front = 0
back = n-1
while True:

    detected_w = 999999999
    for i in range(front,n):
        if cl[i] == 'W':
            detected_w = i
            break
    else:
        print(ans)
        exit()

    detected_r = -1
    for i in range(back,-1,-1):
        if cl[i] == 'R':
            detected_r = i
            break
    else:
        print(ans)
        exit()

    # print(detected_w, detected_r)
    if detected_w < detected_r:
        ans += 1
        front = detected_w+1
        back = detected_r-1
    else:
        print(ans)
        exit()



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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'

int n;
string s;

signed main()
{
    cin >> n;
    cin >> s;
    
    int cnt = 0;
    REP(i, n-2){
        if (s.substr(i, 3) == "ABC") cnt++;
    }

    cout << cnt << endl;
    return 0;
}

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

using namespace std;

int main(){

int i,j;
int h=0,w=0;

while(1){

cin >> h >> w;            //???????????\???

if(h==0&&w==0) break;    //??????????§£???

for(i=0;i<h;i++){
  for(j=0;j<w;j++){
    if(j == 0 || j == w-1){      //?????¬??????????????¨????????????
           cout << "#";
       }
    else if(i==0 || i==h-1){     //?????¬??????????????????????????????
           cout << "#";
       }
    else{
      cout << ".";                   //??????????????´????????????
     }
    }
    cout << endl;              //??????
   }
cout << endl;                  //??????

}

return 0;

}

Measured memory_bytes: 1152
#include<cstdio>
#include<iostream>
#include<vector>
#define Maxn 100010 
using namespace std;
int n,a,b,c,q,k,xx,yy;
vector<pair<int,int> > tree[Maxn];
long long depth[Maxn];
void dfs(int x,int y)
{
    for (int i = 0; i < tree[x].size(); i++)
    {
        if(tree[x][i].first  == y)
            continue;
        depth[tree[x][i].first] = depth[x] + tree[x][i].second;
        dfs(tree[x][i].first,x); 
    }
}
int main()
{
    cin>>n;
    for (int i = 0; i < n - 1; i++)
    {
        cin>>a>>b>>c;
        tree[a].push_back(make_pair(b,c));
        tree[b].push_back(make_pair(a,c));
    }

    // for (int i = 0; i < tree[0].size(); i++)
    //     cout<<tree[0][i].first<<" "<<tree[0][i].second<<endl;

    cin>>q>>k;
    dfs(k,-1);
    for (int i = 0; i < q; i++)
    {
        cin>>xx>>yy;
        cout<<depth[xx]+depth[yy]<<endl;
    }
    return 0;
}

Measured memory_bytes: 14336
#include<stdio.h>
int main(){
  int k,a,b,i;
  scanf("%d",&k);
  scanf("%d %d",&a,&b);
  
  for(i=a;i<=b;i++){
    
   if(i%k==0){
    printf("OK\n"); 
     return 0;
   }
    
  }
  
  
  
  printf("NG\n");
 return 0; 
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)

using namespace std;

long long dfs(long long X) {
	if(X == 1) {
		return 1;
	}
	return 2 * dfs(X/2) + 1;
}

int main(){
	long long X;
	cin >> X;
	cout << dfs(X) << endl;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> dist(N+1, vector<int>(N+1, 9999999));
    for (int i = 1; i <= N; i++) dist[i][i] = 0;
    vector<int> a(M), b(M), c(M);
    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i] >> c[i];
        dist[a[i]][b[i]] = c[i];
        dist[b[i]][a[i]] = c[i];
    }
    
    for (int k = 1; k <= N; k++) {
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i < M; i++) {
        bool check = true;
        for (int k = 1; k <= N; k++) {
            for (int l = 1; l <= N; l++) {
                if (dist[k][l] == dist[k][a[i]] + c[i] + dist[b[i]][l]
                    || dist[k][l] == dist[l][a[i]] + c[i] + dist[b[i]][k]) {
                    check = false;
                    break;
                }
            }
            if (!check) break;
        }
        if (check) ans++;
    }
    cout << ans << endl;
    
    return 0;
}

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

int main() {

	int x,a,b,xa,xb;
	cin>>x>>a>>b;
  if(x>=a){xa=x-a;}
  else{xa=a-x;}
   if(x>=b){xb=x-b;}
  else{xb=b-x;}
	if(xa>=xb){cout<<'B'<<endl;}
  else{cout<<'A'<<endl;}
	//cout<< <<endl;
}



Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque

def main():
    N = int(readline())
    E = [[] for _ in range(N + 1)]
    edge_order = []
    
    m = map(int,read().split())
    AB = list(zip(m,m))
    for a, b in AB:
        E[a].append(b)
        edge_order.append(b)
    
    # 頂点1から幅優先探索
    queue = deque([1])
    color = [0] * (N+1) 
    while queue:
        V = queue.popleft()
        c = 1
        for i in E[V]:
            if c == color[V]:
                c += 1
            color[i] = c
            c += 1
            queue.append(i)

    print(max(color))
    for i in edge_order:
        print(color[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 33336
#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;


ll a[100000];

bool ok(ll x,ll k,ll n)
{
	ll p(0);
	ll count(1);
	REP(i,n)
	{
				if(a[i] > x){return false;}
		if(p+a[i]>x){	count++;	p = a[i];	}
		else{	p += a[i];	}
	}
	
	if(count>k){	return false;	}
	else{	return true;	}
}

int main() 
{
	ll n,k;
	cin >> n >> k;
	REP(i,n){	cin >> a[i];	}
	
	ll left(0),right(1000000000); //最大積載量
	
	while(left+1<right)
	{		
		ll med = (left + right)/2;
		if(ok(med,k,n)){	right =med;	}
		else {	left = med;	}
	}
	
	if(ok(left,k,n)) cout << left << endl;
	else cout << right << endl;
	
	return 0 ;
}

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

int main() {
 int h,w;
 cin >> h >> w;
 char a[h+2][w+2];
 for(int i=0;i<w+2;i++){
   a[0][i] = a[h+1][i] = '#';
 }
 for(int i=0;i<h+2;i++){
   a[i][0] = a[i][w+1] = '#';
 }
 for(int i=1;i<h+1;i++){
   for(int j=1;j<w+1;j++){
     cin >> a[i][j];
   }
 }
 for(int i = 0; i < h+2; i++)
 {
   for(int j = 0; j < w+2; j++)
   {
     cout << a[i][j];
   }
   cout << endl;
 }
 
}

Measured memory_bytes: 256
# AOJ 0121 Seven Puzzle 
# Python 2017.6.23 bal4u

def swap(state, x, y):
	s = list(state)
	s[x], s[y] = s[y], s[x]
	return tuple(s)
	
from collections import deque
MAGIC = 37
move = ((1,4), (0,2,5), (1,3,6), (2,7), (0,5), (1,4,6), (2,5,7), (3,6))

Q = deque()
Q.append(((0,1,2,3,4,5,6,7), 0))
hash = {}
hash[(0,1,2,3,4,5,6,7)] = 0
while Q:
	state, x = Q.popleft()
	step = hash[state]+1
	if step > MAGIC: continue
	for y in move[x]:
		nstate = swap(state, x, y)
		if nstate not in hash: nstep = 100
		else: nstep = hash[nstate]
		if step < nstep:
			Q.append((nstate, y))
			hash[nstate] = step

while 1:
	try: state = tuple(map(int, input().split()))
	except: break
	print(hash[state])


Measured memory_bytes: 9012
#!/usr/bin/env python3

def main():
    N = int(input())

    def num2alpha(num):
        if num <= 26:
            return chr(64 + num)
        elif num % 26 == 0:
            return num2alpha(num // 26 - 1) + chr(90)
        else:
            return num2alpha(num // 26) + chr(64 + num % 26)
    ans = num2alpha(N)
    print(ans.lower())


if __name__ == "__main__":
    main()


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

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

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

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

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

//#define int long long

/*************** using variables ***************/
string s;
/**********************************************/

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

    cin >> s;

    int min_range = INF;
    REP(i, s.size()){
        int cnt = 0;
        int max_cnt = 0;
        string ss = s + s[i];
        REP(j, ss.size()){
            if(ss[j] == s[i]){
                max_cnt = max(max_cnt, cnt);
                cnt = 0;
            }else{
                cnt++;
            }
        }
        min_range = min(min_range, max_cnt);
    }
    cout << min_range << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s=="a" || s=="i" || s=="u" || s=="e" ){
    cout << "vowel" << endl;
  } else if (s=="o"){
    cout << "vowel" << endl;
  } else {
    cout << "consonant" <<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define min_heap priority_queue<pll,vector<pll>,greater<pll> >
#define pld pair<pll,ll>
ll dx4[]={-1,1,0,0};
ll dy4[]={0,0,-1,1};
ll dx8[]={-1,-1,-1,0,1,1,1,0};
ll dy8[]={-1,0,1,1,1,0,-1,-1};
bool isvalid(ll x,ll y,ll n,ll m)
{
	return (x>=0 and y>=0 and x<n and y<m);
}
bool isprime[1000];
vector<ll> prime;
void sievetoprime(ll n)
{
	mem(isprime,true);
	for(ll p=2;p*p<=n;p++)
	{
		if(isprime[p]==true)
		{
			for(ll i=p*p;i<=n;i+=p)
				isprime[i]=false;
		}
	}
}
ll a[20][20];
ll vis[20][20];
ll n,m;
pld curr;

void init()
{
	rep(i,0,n)
	{
		rep(j,0,m)
		{
			vis[i][j]=0;
		}
	}
}
int dijkstra(pll u,pll v)
{
	if(a[u.x][u.y]==0 or a[v.x][v.y]==0)
		return -1;
	queue<pld> q;
	q.push(mp(u,0));
	while(!q.empty())
	{
		curr=q.front();
		q.pop();
		if(curr.x.x==v.x and curr.x.y==v.y)
		{
			return curr.y;
		}
		for(ll i=0;i<4;i++)
		{
			ll x1=curr.x.x+dx4[i];
			ll y1=curr.x.y+dy4[i];
			if(isvalid(x1,y1,n,m) and vis[x1][y1]==0 and a[x1][y1])
			{
				vis[x1][y1]=1;
				q.push(mp(mp(x1,y1),curr.y+1));
			}
		}

	}
}
void solve()
{	
	
	cin>>n>>m;
	char c;
	rep(i,0,n)
	{
		rep(j,0,m)
		{
			cin>>c;
			if(c=='.')
				a[i][j]=1;
			else
				a[i][j]=0;
		}
	}
	vector<ll> ans;
	rep(i,0,n)
	{
		rep(j,0,m)
		{
			rep(k,0,n)
			{
				rep(l,0,m)
				{
					init();
					pll start={i,j};
					pll end={k,l};
					ans.pb(dijkstra(start,end));
				}
			}
			
		}
	}
	ll mx=LLONG_MIN;
	for(auto i:ans)
	{
		mx=max(i,mx);
	}
	cout<<mx;
}	
int main()
{
	IOS
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 2420