akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cctype>
#include <iostream>
using namespace std;

int n;
set<string> st;
vector<vector<string> > group;
map<string,int> gindex;
vector<bool> flag;


void func(int index){
	flag[index] = true;
	map<string,int>::iterator it;

	for(int i = 0; i < group[index].size(); ++i){
		it = gindex.find(group[index][i]);

		if( it == gindex.end() ){
			st.insert(group[index][i]);
		}
		else if( !flag[it->second] ){
			func(it->second);
		}
	}
}


void check_name(string s){
	if(s.empty() || s.size() > 15){
		throw 0;
	}
	for(int i = 0; i < s.size(); ++i){
		if(!islower(s[i])){
			throw 0;
		}
	}
}


int main(){
	char str[64] = "";
	int n;

	string ln;
	while(1){
		getline(cin, ln);
		int d0 = -9, d1 = -9;
		char cc = 0;
		sscanf(ln.c_str(), " %n%d%c", &d0, &n, &cc);
		if(d0 != 0 || cc != 0){
			throw 0;
		}
		if(n == 0){ break; }
		
		if(n > 100){ throw 0; }
		
		group.assign(n, vector<string>());
		flag.assign(n, false);
		st.clear();
		gindex.clear();

		for(int i = 0; i < n; ++i){
			getline(cin, ln);
			for(int j = 0; j < ln.size(); ++j){
				if(!islower(ln[j]) && ln[j] != ':' && ln[j] != '.' && ln[j] != ','){
					throw 0;
				}
			}
			
			const char *ptr = ln.c_str();

			d0 = d1 = -9;
			sscanf(ptr, " %n%[^:]:%n", &d0, str, &d1);
			if(d0 != 0 || d1 == -9){ throw 0; }
			gindex[str] = i;
			ptr += d1;
			
			check_name(str);

			char ch = ',';
			while(ch != '.'){
				d0 = d1 = -9;
				ch = 0;
				sscanf(ptr, " %n%[^,.]%c%n", &d0, str, &ch, &d1);
				if(d0 != 0 || d1 == -9 || (ch != '.' && ch != ',')){
					throw 0;
				}
				group[i].push_back(str);
				ptr += d1;
				check_name(str);
			}
			if(*ptr){
				throw 0;
			}
			
			if(group[i].empty() || group[i].size() > 10){
				throw 0;
			}
		}

		func(0);
		cout << st.size() << endl;
	}
	
	if(!cin.good()){
		throw 0;
	}
	cin.peek();
	if(cin.good()){
		throw 0;
	}
	
	for(volatile int i = 0; i < 100000000; ++i);
}

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

int main()
{
    string M;

    cin>>M;

    if(M=="RRR")
        cout<<"3"<<endl;
    else{
        if(M=="RRS" || M=="SRR")
            cout<<"2"<<endl;
        else{
            if(M=="RSR" || M=="SSR" || M=="SRS" || M=="RSS")
                cout<<"1"<<endl;
            else
                cout<<"0"<<endl;
        }
    }
}


Measured memory_bytes: 3104
h, w = map(int, input().split())
a = []
colrow = []

for i in range(h):
    b = list(input())
    if set(b) == {"."}:
            continue
    a.append(b)

for x in zip(*a): #各リストの1番目から順番に出力
    if set(x) == {"."}:
        continue
    colrow.append(x)

for x in zip(*colrow):
    print(*x, sep="")

Measured memory_bytes: 4596
/*hello guys！~*/ 
#include<bits/stdc++.h>
using  namespace std;
int main()
{
	int a,b;
	int c[1001];
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)
	scanf("%d",&c[i]);
	sort(c,c+a);
	int sum=0;
	for(int i=0;i<b;i++)
	sum+=c[i];
	printf("%d",sum);
	return 0;
} 

Measured memory_bytes: 3832
from itertools import product

N, K = [int(_) for _ in input().split()]
D = set([int(_) for _ in input().split()])
valid = list(set(range(10)) - D)

x = set()
for r in range(1,6):
    for p in product(valid, repeat=r):
        x.add(int(''.join([str(i) for i in p])))

for n in sorted(x):
    if n >= N:
        print(n)
        break

Measured memory_bytes: 7760
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;


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

    cout << (K / 2) * ((K + 1) / 2) << endl;
}

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

using namespace std;

int main() {
  std::cout << setprecision(20) << fixed;
  int n;
  cin >> n;
  vector<double> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }

  vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
  dp[0][0] = 1.0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i + 1; j++) {
      dp[i + 1][j] += dp[i][j] * (1 - p[i]);
      if (j - 1 >= 0) {
        dp[i + 1][j] += dp[i][j - 1] * p[i];
      }
    }
  }
  double ans = 0;
  for (int i = n / 2 + 1; i <= n; i++) {
    ans += dp[n][i];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,D,E;
    cin>>A>>B>>C>>D>>E;
    int T=A;
    int ans=0;
    int c=1;
    if(A<0)c=0;
    while(1){
        if(T==B)break;
        if(T<0)ans=ans+C;
        if(c==0){ans=ans+D;c=1;}
        if(T>=0)ans=ans+E;
        T++;
    }
    cout<<ans<<endl;
    return 0;
}


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

book = [[None]*(m+1)]*n

for i in range(n):
    c = list(map(int, input().split()))
    book[i] = c
        

min_ans = float('inf')
for i in range(2 ** n):
    ans = 0
    rikai = [0]*m
    cost = 0

    for j in range(n):
        if((i >> j) & 1):
            p = book[j]
            for t in range(1,m+1):
                rikai[t-1] += p[t]
            cost += p[0]

    for j in range(m):
        if rikai[j] < x:
            ans = 1

    if ans == 0:
        min_ans = min(min_ans, cost)

if min_ans != float('inf'):
    print(min_ans)
else:
    print(-1)

Measured memory_bytes: 9248
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
#define Endl endl
const int INF=100000000;

int Ceil(int a,int b){
	return ((a%b==0)?a/b:a/b+1);
}

int main(){
	int n,t=0,c[100010],s[100010],f[100010];
	cin>>n;
	REP(i,n-1){
		cin>>c[i]>>s[i]>>f[i];
	}
	for(int i=0;i<n;i++){
		t=0;
		for(int j=i;j<n-1;j++){
			if(t<s[j]){
				t=s[j];
			}
			else if(t%s[j]==0){
				t+=c[j];
				continue;
			}
			else{
				t=Ceil(t-s[j],f[j])*f[j]+s[j];
			}
			t+=c[j];
		}
		cout<<t<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    if 0 in A:
        ans = 0
    else:
        for i in range(N):
            ans = ans * A[i]
            if ans > 10**18:
                ans = -1
                break
    print(ans)
resolve()

Measured memory_bytes: 21788
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

const int mod = 1000000007;
int add(int a, int b) { return (a += b) < mod? a : a - mod; }
int sub(int a, int b) { return (a -= b) >=  0? a : a + mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
void adds(int& a, int b) { a = add(a, b); }
void subs(int& a, int b) { a = sub(a, b); }
void muls(int& a, int b) { a = mul(a, b); }
void maxs(int& a, int b) { a = max(a, b); }
void mins(int& a, int b) { a = min(a, b); }
int pwr(int a, ll p) {
    if (p == 0) return 1;
    if (p & 1) return mul(a, pwr(a, p - 1));
    return pwr(mul(a, a), p / 2);
}
int inv(int a) { return pwr(a, mod - 2); }
const int maxn = 1000000;
int f[maxn + 1], fi[maxn + 1];
int ncr(int n, int r) { if (r > n) return 0; return mul(f[n], mul(fi[r], fi[n - r])); }

void precompute()
{
    f[0] = 1;
    for (int i = 1; i <= maxn; ++i)
        f[i] = mul(f[i - 1], i);

    fi[maxn] = inv(f[maxn]);
    for (int i = maxn - 1; i >= 0; --i)
        fi[i] = mul(fi[i + 1], i + 1);
}

int dp[200005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    precompute();
    int sol = 0;
    for (int i = 0; i <= min(k, n - 1); ++i)
    {
        int m = n - i;
        adds(sol, mul(ncr(n, i), ncr(n - 1, m - 1)));
    }
    cout << sol;
}


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

using namespace std;

int main(){
	
	char c;cin >> c;
	switch((int)c){
		case (int)'A':cout << 'T' << endl;break;
		case (int)'T':cout << 'A' << endl;break;
		case (int)'C':cout << 'G' << endl;break;
		case (int)'G':cout << 'C' << endl;break;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(a,j,k) for(int i = a ; i < j ; i += k)
#define f1(a,j,k) for(int i = a ; i > j ; i -= k)
using namespace std;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<int> vi;
typedef pair<int,int> pri;
typedef pair<long long,long long> prl;
int main() {
	std::ios::sync_with_stdio(false);
  ll a , b , c;
	cin >> a >> b >> c;
	ll d = c - a - b;
	if(d > 0 && 4 * a * b < d * d) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    unordered_map<string,int> map;
    rep(i,n){
        string s;
        cin>>s;
        SORT(s);
        map[s]++;
    }
    int ans=0;
    for(auto i:map)ans+=i.se*(i.se-1)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 10660
/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < ll >
#define vll vector < ll > 
#define dt cout<<"HERE\n";
#define pii pair < ll , ll >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define fi first
#define se second 
#define sz size 
#define len length 

const ll inf=1e18+1e17;
const ll mod =1e9+7;
using cd= complex < double > ;
//const ll mod = 998244353;
ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=	(a*a)%mod;b>>=1;}return (res%mod);}
const ll N = 1e6 +5;


int arr[N];
void solve(){
	int n;
	cin>>n;
	for ( int i=0;i<n;i++)
		cin>>arr[i];
	int aa=arr[0];
	ll ans=0;
	for ( int i=1;i<n;i++){
		if ( arr[i]<aa){
			ans=ans+arr[i]-aa;
		}
		else
			aa=arr[i];
	}
	cout<<-ans<<'\n';
}






int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt", "w" , stdout);
	#endif
	ll t=1;
	//cin>>t;
	for ( ll i=1;i<=t;i++){

    	solve();
    }
}


Measured memory_bytes: 4432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//下ごしらえ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l = sc.nextInt();
		int[][] A = new int[n][m];
		int[][] B = new int[m][l];
		long[][] C = new long[n][l];
		for(int i=0;i<n;i++) {
			for(int k=0;k<m;k++) A[i][k]=sc.nextInt();
		}
		for(int k=0;k<m;k++) {
			for(int j=0;j<l;j++) B[k][j]=sc.nextInt();
		}

		//計算
		for(int i=0;i<n;i++) {
			for(int j=0;j<l;j++) {
				for(int k=0;k<m;k++) {
					C[i][j] += A[i][k] * B[k][j];
				}
				System.out.print(C[i][j]);
				if(!(j+1==l)) System.out.print(" ");
			}
			System.out.println();
		}
	}

}



Measured memory_bytes: 56132
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  if(c<=a-b){
    cout << 0 << endl;
  }
  else{
  cout << c - a + b << endl;
  }
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    int h, w; cin >> h >> w;
    rep(i, h) {
        string s; cin >> s;
        rep(_, 2) cout << s << endl;
    }
    return 0;
}

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

typedef long long ll;
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define rerepi(i, a, b) for(int i = int(a)-1; i >= b; --i)
#define rerep(i, n) rerepi(i, n, 0)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const long long INF = 1LL << 60;

// ここから開始だよ！
double T, X;

int main() {
	// 呪文エリア
	cin.tie(0);
	ios::sync_with_stdio(false);
	// 詠唱完了
  
  cin >> T >> X;
  cout << T / X << endl;
  
	return 0;
}


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

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

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

  return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x /gcd(x, y) * y );
}

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}


ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
char c[2010][2010];
ll a[20][20];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll a, b;
	cin >> a >> b;
	if (abs(a + b) % 2 == 0) {
		cout << abs(a + b) / 2 << endl;
	}
	else puts("IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 3608
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 5e3 + 5;
const ll linf = 0x3f3f3f3f3f3f3f3f;

int p[MAXN], c[MAXN];

int main(void)
{
	int n,d;
	scanf("%d%d",&n,&d);
	for(int i=1; i<=n; ++i) scanf("%d",&p[i]);
	for(int i=1; i<=n; ++i) scanf("%d",&c[i]);
	
	ll ans = -linf;
	for(int i=1; i<=n; ++i)
		ans = max(ans, (ll)c[i]);
	
	static bool vis[MAXN];
	for(int k=1; k<=n; ++k) if(!vis[k])
	{
		int tmp = k;
		vector<int> a;
		while(!vis[tmp])
		{
			vis[tmp] = 1;
			a.push_back(c[tmp]);
			tmp = p[tmp];
		}
		
		ll sum = 0;
		for(int i=0; i<(int)a.size(); ++i)
			sum += a[i];
		
		ll res = 0;
		int lim;
		
		if(d >= (int)a.size())
		{
			ans = max(ans, d/(int)a.size() * sum);
			
			if(sum > 0) res = (d/(int)a.size() - 1) * sum;
			lim = d % (int)a.size() + a.size();
		}
		else lim = d;
		
		for(int i=0; i<(int)a.size(); ++i)
		{
			ll now = 0;
			for(int j=1; j<=lim; ++j)
				now += a[(i+j)%(int)a.size()],
				ans = max(ans, res + now);
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3292
#include <iostream>
#include <cstdio>
using namespace std;
 
int main(){
 
  int i,j;
  char g[3][3];
  char win;
   
  while(1){
     
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
    cin >> g[i][j];
    if(g[0][0]=='0') return 0;
    if(g[i][j]=='+') g[i][j]=(j+1)*(i+1);
      }
    }
   
    for(i=0;i<3;i++){
      if(g[i][0]==g[i][1] && g[i][0]==g[i][2]){
    win = g[i][0];
    break;
      }else if(g[0][i]==g[1][i] && g[0][i]==g[2][i]){
    win = g[0][i];
    break;
      }else if(g[0][0]==g[1][1] && g[0][0]==g[2][2]){
    win = g[0][0];
    break;
      }else if(g[0][2]==g[1][1] && g[0][2]==g[2][0]){
    win = g[0][2];
    break;
      }
       
    }
     
    if(i!=3) printf("%c\n",win);
    else puts("NA");
 
  }
 
    return 0;
} 

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

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

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

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

  cout << (s[0]==t[0])+(s[1]==t[1])+(s[2]==t[2]) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		double n1 = sc.nextInt();
		double n2 = sc.nextInt();
		double big = Math.max(n1, n2);
		double small = Math.min(n1, n2);
		double ans;
		if (big - small >= 180) {
		    ans = (big - 360 + small) / 2;
		    if (ans < 0) {
		        ans += 360;
		    }
		} else {
		    ans = (big + small) / 2;
		}
		System.out.println(ans);
	}
}



Measured memory_bytes: 26480
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    H, W = map(int, input().split())
    Ch, Cw = map(lambda x: int(x)-1, input().split())
    Dh, Dw = map(lambda x: int(x)-1, input().split())
    S = [input() for _ in range(H)]

    adj = [[] for _ in range(W*H)]
    dx = [1,-1,0,0]
    dy = [0,0,1,-1]
    
    for i in range(H):
        for j in range(W):
            if S[i][j] == '#': continue
            for k in range(4):
                y = i + dy[k]
                x = j + dx[k]
                if 0 <= y < H and 0 <= x < W:
                    if S[y][x] == '.':
                        adj[W*i + j].append(W*y + x)

    # ワープ可能な場所もadjに加える
    worp = [[] for _ in range(W*H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == '#': continue
            for kx in [-2,-1,0,1,2]:
                for ky in [-2,-1,0,1,2]:
                    if kx == ky == 0: continue
                    y = i + ky
                    x = j + kx
                    if W*y + x in adj[W*i + j]: continue
                    if 0 <= y < H and 0 <= x < W:
                        if S[y][x] == '.':
                            worp[W*i + j].append(W*y + x)
    
    start = W*Ch + Cw
    goal = W*Dh + Dw
    queue = deque([start])
    visit = [-1] * (W*H)
    visit[start] = 0
    
    while queue:
        nextq = queue.copy()
        while queue:
            now = queue.popleft()
            for u in adj[now]:
                if visit[u] < 0:
                    queue.append(u)
                    nextq.append(u)
                    visit[u] = visit[now]
        # print(nextq)
        while nextq:
            now = nextq.popleft()
            for u in worp[now]:
                if visit[u] < 0:
                    queue.append(u)
                    visit[u] = visit[now]+1
    
    print(visit[goal])

if __name__ == "__main__":
    main()


Measured memory_bytes: 264400
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vs = vector<string>;
template <typename T>
using ost = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
#define forn(i,n) for(int i=0; i<int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss second

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    for (char c='a'; c<='z'; c++)
        if (s.find(c)==s.npos)
            return cout << s << c << '\n', 0;
    string t=s;
    if (!next_permutation(all(t)))
        return cout << "-1\n", 0;
    for (int i=0; i<(int)t.size(); i++)
        if (s[i]!=t[i])
            return cout << t.substr(0, i+1) << '\n', 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int A[4];
    for (auto &a : A) cin >> a;
    sort(begin(A), end(A));
    int ans = 1e9;
    do {
        int t = abs(A[0] + A[1] - A[2] - A[3]);
        ans = min(ans, t);
    } while (next_permutation(begin(A), end(A)));
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int b[13] = {0};
  
  int a[N];
  int rednum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    b[a[i] / 400] = 1;
    if (a[i] >= 3200) rednum++;
  }
  
  int colornum = 0;
  for (int i = 0; i < 8; i++) {
    if (b[i]) colornum++;
  }
  if (colornum == 0) {
    cout << 1 << " " << rednum << endl;
  } else {
    cout << colornum << " " << colornum + rednum << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	cout << a[k - 1];
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		
		if(n.equals("A")){
			System.out.println("T");
		}
		if(n.equals("T")){
			System.out.println("A");
		}
		if(n.equals("C")){
			System.out.println("G");
		}
		if(n.equals("G")){
			System.out.println("C");
		}
		
	}
}


Measured memory_bytes: 20688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,D,b,ans=0;
int main(){
	cin>>n>>D;
	for(int i=1;i<=n;i++){
		ll x,y;cin>>x>>y;
		if(x*x+y*y<=D*D)ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3596
#include<iostream>
#include<set>
#include<math.h>
#include<limits.h>
#include<vector>
using namespace std;

int main()
{
	register int i, test;

	int n, ans = 0;

	cin >> n;

	int arr[n];

	for (i = 0; i < n; i++)
	{
		cin >> arr[i];

		ans ^= arr[i];
	}

	for (i = 0; i < n; i++)
	{
		cout << (arr[i] ^ ans ) << " ";
	}




	return 0;
}

Measured memory_bytes: 4372
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> xs(n);
  for(Int i=0;i<n;i++) cin>>xs[i];

  vector<Int> grp(m,0);
  for(Int x:xs) grp[x%m]++;

  map<Int, Int> cnt;
  for(Int x:xs) cnt[x]++;
  vector<Int> prs(m,0);
  for(auto p:cnt)
    prs[p.first%m]+=p.second/2;

  Int ans=grp[0]/2;
  if(m%2==0) ans+=grp[m/2]/2;

  for(Int i=1;i<m-i;i++){
    Int j=m-i;
    Int res=min(grp[i],grp[j]);
    ans+=res;
    grp[i]-=res;
    grp[j]-=res;
    //cout<<res<<":"<<grp[i]<<" "<<prs[i]<<" "<<grp[j]<<" "<<prs[j]<<endl;
    ans+=min(grp[i]/2,prs[i]);
    ans+=min(grp[j]/2,prs[j]);
  }

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


Measured memory_bytes: 8832
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <iterator>

using namespace std;

typedef long long ll;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define mod 1000000007

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

int n,m,broken[100010],store[100010];

int dp(int step){
	if (step==n || step==n-1) return 1;
	if (store[step]!=-1) {
		//cout<<"a";
		return store[step];
	}
	int one = broken[step+1];
	int two = broken[step+2];
	//cout<<"call";
	//int ans;
	//if (one||two) cout<<"CALL";
	if (one && two) {
		store[step]=(dp(step+1)%mod+dp(step+2)%mod)%mod;
		return store[step];
	}
	if (one) {
		store[step]=dp(step+1)%mod;
		return store[step];
	}
	if (two) {
		store[step]=dp(step+2)%mod;
		return store[step];
	}
	return store[step]=0;
}

int main(){
	cin>>n>>m;
	int temp;
	mems(broken);
	mems(store);
	for (int i = 0; i < m; ++i)
	{
		cin>>temp;
		broken[temp]=0;
	}
	cout<<dp(0)<<endl;
	/*for (int i = 0; i < n; ++i)
	{
		cout<<store[i]<<'\n';
	}*/
}

Measured memory_bytes: 4224
import sys
import itertools
a = [list(map(int, input().split())) for _ in range(3)]

for x in itertools.permutations([1,2,3,4]):
  for i in range(3):
    f = False
    for y in a:
      if y[0]==x[i]and y[1]==x[i+1]:
        f = True
        break
      elif y[1]==x[i]and y[0]==x[i+1]:
        f = True
        break
    if not f: break
    if i==2:
      print("YES")
      sys.exit()
print("NO")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int x, y, t;
int main(){
	scanf("%d%d", &x, &y);
	y = -y + 4 * x;
	if(y < 0 || x*2 < y || y % 2 == 1) puts("No");
	else puts("Yes");
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
int dp[1001][1001];
const int MOD=1000000007;

int main(){
  int h,w;
  char a[1001][1001];

  cin >> h >> w;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin >> a[i][j];
    }
  }
  
  dp[1][1]=1;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(a[i][j]!='#'){
	dp[i][j]+=dp[i-1][j]%MOD+dp[i][j-1]%MOD;
      }
    }
  }

  cout << dp[h][w]%MOD << '\n';
  return 0;
}


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	string s;
	cin >> s;
	deque<char> d;
	for (auto i : s)
		d.push_back(i);

	bool r = false;
	int q;
	cin >> q;
	char x;
	for (int t, f; q--; )
	{
		cin >> t;
		if (t == 1)
		{
			r ^= true;
			continue;
		}
		cin >> f >> x;
		if (f == 1 && !r) d.push_front(x);
		if (f == 1 && r) d.push_back(x);
		if (f == 2 && r) d.push_front(x);
		if (f == 2 && !r) d.push_back(x);
	}

	string ans = "";
	while (!d.empty())
	{
		if (r) ans += d.back(), d.pop_back();
		if (!r) ans += d.front(), d.pop_front();
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1368
a=[[[0 for i in range(10)]for j in range(3)]for k in range(4)]
n=int(input())
for i in range(n):
    b,f,r,v=map(int,input().split())
    a[b-1][f-1][r-1]+=v
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(" "+str(a[i][j][k]),end="")
        print()
    if (i!=3):
        print("####################")


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

int main() {
  string a; cin >> a;
  int sum = 0;
  for(int i = 0; i<3; i++){
    if(a[i]=='o') sum++;
  }
  cout << 700+100*sum << endl;
 
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int s = sc.NextInt();
        int w = sc.NextInt();
        Console.WriteLine(w >= s ? "unsafe" : "safe");
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 27552
/**
                 MD.Faysal Hasan
                Comilla Univesity               **/

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

#define         rep(i,n)       for ( i=0 ; i<n ; ++i )
#define         rep1(i,n)      for ( i=1 ; i<=n ; ++i )
#define         sajo(str)      sort(str.begin(),str.end())
#define         rev(str)       reverse(str.begin(),str.end())
#define         usajo(str)     sort(str.rbegin(),str.rend())
#define         input(a)       for(auto &it : a) cin>>it
#define         pi             2*acos(0.0)
#define         nel            printf("\n")
#define         longmx         92233720368547758
#define         gcd(a,b)       __gcd(a,b)
#define         lcm(a,b)       (a/gcd(a,b))*b
#define         yes            cout<<"YES"<<"\n"
#define         no             cout<<"NO"<<"\n"
#define         vcl            vector<ll>
#define         vpl            vector<pair<ll,ll>>
#define         pb             push_back
#define         mkp(x,y)       make_pair(x,y)
#define         ff             first
#define         sc             second
#define         spc            ' '
#define         nn             '\n'
#define         ikarus_101     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef         long long int  lli;
typedef         long long      ll;

int main(){ikarus_101

    ll tc,n,m,a,b,c,d,x,y,i,j,l,r,k,ans,sum,tot,cnt,mx,mn,idx,tmp;

    cin>>a>>b;
    cout<<a*b<<nn;
    return 0;
}


Measured memory_bytes: 3640
import java.util.*;
 
public class Main {
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int sum = 0;
		List<Integer> point = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			int p = sc.nextInt();
			sum += p;
			if (p%10 != 0) {
				point.add(p);
			}
		}
		if (point.size() == 0) {
			System.out.println(0);
		} else {
			Collections.sort(point);
			System.out.println(sum%10 == 0 ? sum - point.get(0) : sum);
		}
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N; cin >> N;
  vector<ll> C(N); rep(i,N) cin >> C[i];
  sort(rall(C));
  ll ans = 0;
  if(N==1){
    cout << 2*C[0]%mod << endl;
    return 0;
  }
  vector<ll> mpow(200020,1);
  mpow[1] = 2;
  for(int i=2; i<=200000; i++){
    mpow[i] = mpow[i-1]*2%mod;
  }
  rep(i,N){
    ans += (2+i)*C[i]%mod;
    ans %= mod;
  }
  cerr << ans << endl;
  ans = ans * mpow[N-2] % mod;
  cout << ans*mpow[N]%mod << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    ll a, b;
    cin >> a >> b;
    for(ll i = 0; i <= 1000000000; i++){
        if(abs(a-i) == abs(b-i)){
            cout << i;
            return 0;
        }
    }
    cout << "IMPOSSIBLE";
    return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int numA = scan.nextInt();
		int numB = scan.nextInt();
		int numC = scan.nextInt();
		int numD = scan.nextInt();

		int start = Math.max(numA, numC);
		int end = Math.min(numB, numD);

		int delta = 0;

		if (start < end) {
			delta = end - start;
		}
		System.out.println(delta);
	}
}


Measured memory_bytes: 21844
# N人
# M個のチェックポイント
N, M = map(int, input().split())

# 学生の初期値
student = []
for _ in range(N):
    student.append(list(map(int, input().split())))
    
# チェックポイントの座標
cp = []
for _ in range(M):
    cp.append(list(map(int, input().split())))
    
# ゴールまでの距離を格納する配列
goal = [10**9 for _ in range(N)]
# 学生が進むチェックポイント
ans = [0 for _ in range(N)]


for n in range(N):
    for m in range(M):
        # マンハッタン距離を測る
        x = abs(student[n][0] - cp[m][0])
        y = abs(student[n][1] - cp[m][1])
        #print(student[n], cp[m])
        #print("abs(x-y)", x, y, x+y)
        # 最短の場合は目標チェックポイントを更新
        if goal[n] > x+y:
            goal[n] = x+y
            ans[n] = m +1
            #print(goal[n], ans[n])


for n in range(N):
    print(ans[n])

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#define inf 1e9+7
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl;
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;

bool kaibun(string s){
    bool ans=true;
    ll n=s.size();
    for(ll i=0;i<s.size();i++){
        if(s[i]!=s[n-1-i]) ans=false;
    }
    return ans;
}

int main() {
    ll n,m;
    cin >> n >> m;
    ll ans=n*(n-1)/2+m*(m-1)/2;
    kaku(ans);
}
 



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

int main() {
	int n;
	cin >> n;
	set<string> l;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		l.insert(s);
	}
	cout << l.size();
	cin >> n;
	return 0;
}

Measured memory_bytes: 19088
#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>;

std::vector<vector<P>> iig(int vn, int en) {
	std::vector<std::vector<P>> res(vn);
	for(int i = 0; i < en; i++) {
		int a, b, c;
		std::cin >> a >> b >> c;
		a--; b--;
		res[a].emplace_back(b, c);
		res[b].emplace_back(a, c);
	}
	return res;
}


int n, m, l;

void show_onesteps(vector<vector<int>>& v) {
	rep(i, n) {
		for(int j: v[i]) cout << j << ' ';
		cout << endl;
	}
}

void show_res(int i, vector<int>& res) {
	cout << i << ": ";
	for(int j: res) cout << j << ' ';
	cout << endl;
}


int main() {
	cin >> n >> m >> l;
	auto graph = iig(n, m);
	vector<vector<int>> v(n, vector<int>());
	rep(i, n) {
		vector<int> mxfuel(n, -1);
		mxfuel[i] = l;
		priority_queue<P> q;
		q.emplace(l, i);
		while(!q.empty()) {
			auto x = q.top(); q.pop();
			int left = x.first, dest = x.second;
//			cout << "xx" << left << ' ' << dest << "with" << graph[dest].size() << endl;
			if (x.first != mxfuel[dest]) continue;
			for(auto y: graph[dest]) {
				int nxt = y.first, nxtcost = y.second;
				int nxtleft = left - nxtcost;
//				cout << "yy" << nxt << nxtcost << endl;
				if (nxtleft < 0) continue;
				if (mxfuel[nxt] < nxtleft) {
					if (mxfuel[nxt] == -1) v[i].push_back(nxt);
					mxfuel[nxt] = nxtleft;
					q.emplace(nxtleft, nxt);
				}
			}
		}
	}
	//show_onesteps(v);
	vector<vector<int>> distance(n, vector<int>(n, -1));
	rep(i, n) {
		vector<bool> visited(n);
		vector<int> st;
		vector<int> res(n, -1);
		st = v[i];
		int cur = 0;
		res[i] = 0;
		while(!st.empty()) {
			vector<int> nxtst;
			for(int j: st) {
				if (res[j] != -1) continue;
				res[j] = cur;
				for(int k: v[j]) {
					nxtst.push_back(k);
				}
			}
			cur++;
			swap(st, nxtst);
		}
	//	show_res(i, res);
		swap(distance[i], res);
	}
	int q;
	cin >> q;
	rep(i, q) {
		int si, ti;
		cin >> si >> ti;
		si--; ti--;
		cout << distance[si][ti] << endl;
	}
}


Measured memory_bytes: 3352
#include "bits/stdc++.h"
using namespace std;
int main(){
 int N;
 cin >> N;
 map<int,int> val;
 for(int x = 1; x<N; x++){
 	int z;
 	cin >> z;
 	val[z]++;
 }
 for(int x = 1; x<=N;x++){
 	cout << val[x]<<endl;
 }

}
	


Measured memory_bytes: 13004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int K = A + B + C;
    if (K >= 22)
    {
        cout << "bust" << endl;
        return 0;
    }
    cout << "win" << endl;

    return 0;
    // system("pause");
}

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

void Main() {
  int n;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    s.insert(tmp);
  }
  if ((int)s.size() == n) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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


Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <stack>

int main() {
	std::string s;
	std::cin >> s;

	int ans = 0;

	std::stack<int> stack;
	for (auto&& c : s) {
		if (stack.empty()) {
			stack.push(c);
			continue;
		}

		if (c != stack.top()) {
			stack.pop();
			ans += 2;
		}
		else
			stack.push(c);
	}

	std::cout << ans << std::endl;
}

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


template<typename C>
struct Trie {
    struct Node {
        int exist,len;
        vector<int> accept;
        map<C, int> ch;
        Node() : exist(0), len(0) {}  
    };

    vector<Node> node;

    Trie() {node.emplace_back();}

    template<typename S>
    void add (const S &A, int id) {
        int cur = 0;
        for (int i = 0; i < (int)A.size(); i++) {
            if (!node[cur].ch.count(A[i])) {
                int nex = node.size();
                node.emplace_back();
                node[nex].len = node[cur].len + 1;
                node[cur].ch.emplace(A[i],nex);
            }
            node[cur].exist++;
            cur = node[cur].ch[A[i]];
        }
        node[cur].exist++;
        node[cur].accept.emplace_back(id);
    }

    template<typename S>
    int find(const S &A) {
        int cur = 0;
        for (int i = 0; i < (int)A.size(); i++) {
            if (!node[cur].ch.count(A[i])) return -1;
            cur = node[cur].ch[A[i]];
        }
        return cur;
    }

    int count() const {return node[0].eixst;}

    int size() const {return(int)node.size();}
};

ll underbit(ll x) {
    if (x==0) return 0;
    rep(i,64) {
        if (x&(1LL<<i)) return 1LL<<i;
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,L; cin >> N >> L;
    Trie<char> T;

    ll g = 0;
    rep(_,N) {
        string S; cin >> S;
        int K = S.size();
        int cur = 0, len = 0;
        rep(i,K) {
            if (!T.node[cur].ch.count(S[i])) {
                len = T.node[cur].len;
                break;
            }
            cur = T.node[cur].ch[S[i]];
        }
        ll val = L - len;
        g ^= underbit(val);
        ll l = L - K + 1;
        for (ll i = l; i < val; i++) g ^= underbit(i);
        T.add(S,_);
    }

    cout << (g ? "Alice" : "Bob") << ln;
}


Measured memory_bytes: 16496
from itertools import permutations
def main():
    N=int(input())
    P=tuple(int(_) for _ in input().split())
    Q=tuple(int(_) for _ in input().split())
    if P==Q:
        print(0)
        exit()
    ans=[0,0]
    cnt=1
    using=tuple(map(int,range(1,N+1)))
    for i,a in enumerate(list(permutations(using, N))):
        if a==P:
            ans[0]=cnt
        elif a==Q:
            ans[1]=cnt
        if ans[0]!=0 and ans[1]!=0:
            print(abs(ans[0]-ans[1]))
            exit()
        cnt+=1

main()

Measured memory_bytes: 8052