akhauriyash/Code-Regression huggingface dataset:
#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;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 3e3 + 12;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
ll a[N][N];
ll dp[N][N][4];
int n, m, k;
 
void maxself(ll &a, ll c) {
    a = max(a, c);
}
ll get(int x, int y, int t) {
    if(t < 0)
        return -LINF;
    if(x < 0 || x > n || y > m || y < 0)
        return -LINF;
    if(dp[x][y][t] != -1)
        return dp[x][y][t];
    if(t == 0) {
        ll fromUp = get(x - 1, y, 0);
        maxself(fromUp, get(x - 1, y, 1));
        maxself(fromUp, get(x - 1, y, 2));
        maxself(fromUp, get(x - 1, y, 3));
        ll fromLeft = get(x, y - 1, 0);
        return dp[x][y][t] = max(fromLeft, fromUp);
    }
    ll fromUp = 0;
    if(a[x][y] && t == 1) {
        fromUp = get(x - 1, y, 0);
        maxself(fromUp, get(x - 1, y, 1));
        maxself(fromUp, get(x - 1, y, 2));
        maxself(fromUp, get(x - 1, y, 3));
        fromUp += a[x][y];
    }
    // dont take
    ll fromLeft = get(x, y - 1, t);
    maxself(fromLeft, get(x, y - 1, t - 1) + a[x][y]);
 
    return dp[x][y][t] = max(fromLeft, fromUp);
 
} 
void solve(){
    cin >> n >> m >> k;
    while(k --) {
        int x, y, v;
        cin >> x >> y >> v;
        a[x][y] = v;
    }
    for(int i = 0; i <= n; ++i)
        for(int j = 0; j <= m; ++j)
            for(int k = 0; k <= 3; ++k)
                dp[i][j][k] = -1;
    ll mx = 0;
    for(int i = 0; i <= 3; ++i){
        mx = max(mx, get(n, m, i));
    }
    cout << mx;
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 357336
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define INF (2000000000)
#define MAX (2000)
using namespace std;

typedef vector<int> VI;
typedef vector<int>::iterator VII;
typedef vector<double> VD;
typedef vector<double>::iterator VDI;


typedef struct
{
	int id;
	int ac;
	int wa[10];
	int pe;
} TEAM;
TEAM team[50];

bool cmp(TEAM A, TEAM B)
{
	if (A.ac == B.ac){
		if (A.pe == B.pe){
			return (A.id < B.id);
		}
		return (A.pe < B.pe);
	}
	return (A.ac > B.ac);
}

int main()
{
	int T, P, R;
	while (scanf(" %d %d %d", &T, &P, &R), T + P + R){
		memset(team, 0, sizeof(team));
		for (int i = 0; i < T; i++){
			team[i].id = i + 1;
		}
		
		for (int i = 0; i < R; i++){
			int tID, pID, time;
			char mes[16];
			
			scanf("%d %d %d", &tID, &pID, &time);
			tID--; pID--;
			scanf("%s", mes);
			
			if (!strcmp(mes, "CORRECT")){
				team[tID].ac++;
				team[tID].pe += team[tID].wa[pID] * 1200 + time;
			}
			else {
				team[tID].wa[pID]++;
			}
		}
		
		sort(team, team + T, cmp);
		
		for (int i = 0; i < T; i++){
			printf("%d %d %d\n", team[i].id, team[i].ac, team[i].pe);
		}
	}
	
	return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
int dp[3003][3003];
string sa,sb;
int rec(int a,int b){
    if(a==sa.size() or b==sb.size())return 0;
    if(dp[a][b]!=-1)return dp[a][b];
//    dp[a][b]=0;
    if(sa[a]==sb[b]){
        dp[a][b] = rec(a+1,b+1)+1;
    }
    else  dp[a][b] = max(rec(a+1,b),rec(a,b+1));
    return dp[a][b];
}
void recons(int a,int b){
    if(a==sa.size() or b==sb.size())return;
    else if(dp[a][b] == rec(a+1,b+1)+1 and sa[a]==sb[b]){cout<<sb[b];recons(a+1,b+1);}
    else{
        if(dp[a][b]==rec(a+1,b))recons(a+1,b);
        else if(dp[a][b]==rec(a,b+1))recons(a,b+1);
    }
}

int main(){
//    freopen("entra.in","r",stdin);
//    freopen("sale.out","w",stdout);
 //   cin>>sa>>sb;
    while(getline(cin,sa)){
        getline(cin,sb);
        memset(dp,-1,sizeof dp);
        rec(0,0);
        recons(0,0);
        cout<<"\n";

    }
}


Measured memory_bytes: 35968
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,t;
    cin>>a>>b>>t;
    int c=0;
    int x=2;
    int val=a;
    while(val<=t){
        c+=b;
        val=a*x;
        x++;
    }
    cout<<c<<endl;
    
    return 0;
    
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  ll N;
  cin >> N;
  ll M = abs(N);
  string ans;
  if(N == 0){
    ans = "0";
  } else {
    if(N > 0){
      if(M % 2 == 1)
	ans = "1";
      else
	ans = "0";
      M /= 2;
    }

    while(M > 0){
      if(M % 4 == 3){
	ans = "01" + ans;
	M -= -1;
      } else if(M % 4 == 2){
	ans = "10" + ans;
	M -= 2;
      } else if(M % 4 == 1){
	ans = "11" + ans;
	M -= 1;
      } else if(M % 4 == 0){
	ans = "00" + ans;
	M += 0;
      }
      M /= 4;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
using namespace std;
#define ll long long

int main() {
	string S; cin >> S;
	vector<string> ans{"NA", "MMYY", "YYMM", "AMBIGUOUS"};
	int mmyy=0, yymm=0;
	if((S[0]=='1' && S[1]<'3') || (S[0]=='0' && S[1]!='0')) mmyy=1;
	if((S[2]=='1' && S[3]<'3') || (S[2]=='0' && S[3]!='0')) yymm=2;
	cout << ans[mmyy+yymm] << endl;
	return 0;
}


Measured memory_bytes: 256
program ABC092B
	integer(8)::N,D,X,i,result,day
	integer(8),allocatable,dimension(:)::A
	read(5,*)N
	read(5,*)D,X
	allocate(A(N))
	read(5,*)(A(i),i=1,N)
	result=X
	
	do i=1,N
		day=1
		result=result+1
		do
			day=day+A(i)
			if(day>D)then
				exit
			end if
			result=result+1
		end do
	end do
	
	print'(i0)',result
end program ABC092B


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

using namespace std;

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

    int cnt = 0;
    for (int i = 0; i < static_cast<int>(s.size()); i++) {
        if (s[i] == 'p') {
            cnt++;
        }
    }

    cout << (s.size() / 2) - cnt << endl;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=110;
int n,k,a;
int main(){
	int i,j,ans=0;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		j=min(a,k-a);
		ans+=2*j;	
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
Ans = [0] * N
def how_many_times_divisible(n):
    count = 0
    while n % 2 == 0:
        n = n // 2
        count += 1
    return count

flag = 0
ans = 1
for i in range(N):
    Ans[i] = how_many_times_divisible(i+1)
    if flag < Ans[i]:
        flag = Ans[i]
        ans = i+1



print(ans)


Measured memory_bytes: 3060
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("io error");
    let bytes = s.as_bytes();
    println!("{}",
    if bytes[2] == bytes[3] && bytes[4] == bytes[5] {
        "Yes"
    }else{
        "No"
    }
    );
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}


int main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  multiset< string > t;
  for(int i = 0; i < X; i++) t.emplace("a");
  for(int i = 0; i < Y; i++) t.emplace("b");
  for(int i = 0; i < Z; i++) t.emplace("c");
  while(t.size() > 1) {
    string q = *t.begin() + *prev(t.end());
    t.erase(t.begin());
    t.erase(prev(t.end()));
    t.emplace(q);
  }
  cout << *t.begin() << endl;
}







Measured memory_bytes: 256
from networkx import*
(N,),*t=map(str.split,open(0))
G=Graph(t)
s=shortest_path_length
x=s(G,'1')
y=s(G,N)
print('FSennunkeec'[sum(x[k]>y[k]for k in x)*2>=int(N)::2])

Measured memory_bytes: 188928
#include <stdio.h>

void maxHeapify(int [],int ,int );

int main()
{
  int i,n,m,ori[2000000];
  
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&m);
    ori[i]=m;
  }
  
  for(i=n/2;i>=1;i--) maxHeapify(ori,i,n);

  for(i=1;i<=n;i++) printf(" %d",ori[i]);

  printf("\n");

  return 0;
}

void maxHeapify(int ori[],int i,int n)
{
  int left,right,max,kawari;

  left=2*i;
  right=2*i+1;

  if(left<=n && ori[left]>ori[i]) max=left;
  else max=i;

  if(right<=n && ori[right]>ori[max]) max=right;

  if(max!=i){
    kawari=ori[i];
    ori[i]=ori[max];
    ori[max]=kawari;

    maxHeapify(ori,max,n);
  }
}


Measured memory_bytes: 3656
from numpy import *
from scipy.sparse.csgraph import *
H,W = map(int,input().split())
G = array([list(map(int,input().split())) for n in range(10)])
A = [list(map(int,input().split())) for h in range(H)]
F = shortest_path(G)
ans = 0

for h in range(H):
  for w in range(W):
    if A[h][w]!=-1:
      ans+=F[A[h][w]][1]

print(int(ans))

Measured memory_bytes: 38200
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b, c = rs()
print((a[0] + b[0] + c[0]).upper())










Measured memory_bytes: 27148
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int sum = accumulate(a.begin(), a.end(), 0);
  int m;
  cin >> m;
  while (m--) {
    int x, y;
    cin >> x >> y;
    --x;
    cout << sum + y - a[x] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
def solve(string):
    s, t = string.split()

    c_s = sorted([s.count(_c) for _c in set(s)])
    c_t = sorted([t.count(_c) for _c in set(t)])

    if c_s == c_t:
        return "Yes"
    else:
        return "No"


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 63804
NK = list(map(int,input().split()))

N = NK[0]
K = NK[1]

Ad = [list(map(int,input().split())) for l in range(K*2)]

A = []

for i in range(1,len(Ad)+1,2):
    A.extend(Ad[i])
    
set_A = set(A)

members = []

for i in range(1,N+1):
    members.append(i)

set_M = set(members)

print(len(set_M - set_A))

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

int main() {
  int N; cin >> N;
  vector<int> C(100000);
  rep(i, 0, N) {
    int a; cin >> a; a--;
    C[a]++;
  }
  int ans = 0;
  int sum = 0;
  rep(i, 0, 100000) {
    if(C[i]) {
      ans++;
      sum += C[i] - 1;
    }
  }
  if(sum % 2) ans--;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    string s; cin >>s;
    int n = s.length();

    vector<int> place;
    vector<int> nums;
    for (int i = 0; i < (int)s.length();) {
        int j = i;
        while (j < (int)s.length() && s[i] == s[j]) {
            j++;
        }
        place.push_back(j);
        nums.push_back(j-i);
        i = j;
    }

    vector<int> a(n, 0);
    for (int i = 0; i < nums.size(); i++) {
        if (i % 2 == 0) {
            if (nums[i] % 2 == 0) {
                a[place[i]-1] += nums[i]/2;
                a[place[i]] += nums[i]/2;
            } else {
                a[place[i]-1] += nums[i]/2 + 1;
                a[place[i]] += nums[i]/2;
            } 
        } else {
            if (nums[i] % 2 == 0) {
                a[place[i-1]-1] += nums[i]/2;
                a[place[i-1]] += nums[i]/2;
            } else {
                a[place[i-1]-1] += nums[i]/2;
                a[place[i-1]] += nums[i]/2 + 1;
            }
        } 
    }

    for (int i = 0; i < n; i++) {
        cout << a[i];
        if (i < n-1) {
            cout << " ";
        } 
    }
    cout << endl;

    return 0;
}





Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
int N,T;
int A[111111];
int mi[111111];
int ma[111111];
int sm;
set<int>s;
int main()
{
	scanf("%d%d",&N,&T);
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	mi[0]=A[0];
	for(int i=1;i<N;i++){
		mi[i]=min(mi[i-1],A[i]);
	}
	ma[N-1]=A[N-1];
	for(int i=N-2;i>=0;i--){
		ma[i]=max(A[i+1],ma[i+1]);
	}
	for(int i=0;i<N;i++){
		sm=max(sm,ma[i]-mi[i]);
	}
	for(int i=0;i<N;i++){
		if(sm==ma[i]-mi[i]){
			s.insert(ma[i]);
		}
	}
	printf("%d\n",(int)s.size());
	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define ll long long
using namespace std;
const ll N = 1e5 +200;
const ll mod = 1e9+7;

int main(){
	ll n;
	cin>>n;
	ll y = n/100;
	ll x = n%100;
	ll sum = 0;
	while(x > 0){
		for(int i = 5; i >= 0; i--){
			if(x >= i){
				x -= i;
				sum++;
				break;
			}
		}
	}
	if(sum <= y){
		cout<<1<<endl;
	}else{
		cout<<0<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 100 * 1000 + 10;

vector <int> adj[MAXN];
vector <int> ennemis[MAXN];
int appartient[MAXN];
int taille[MAXN];

void remplir(int noeud , int c)
{
	if (appartient[noeud] == 0)
	{
		appartient[noeud] = c;
		taille[c]++;
	}
	else
	{
		return;
	}
	for (auto voisin : adj[noeud])
	{
		remplir(voisin , c);
	}
}
int main()
{
	int nbNoeuds , nbAmis , nbEnnemis;
	cin >> nbNoeuds >> nbAmis >> nbEnnemis;
	for (int i = 0 ; i < nbAmis ; i++)
	{
		int a,b;
		cin >> a >> b; a--; b--;
		adj[a].push_back(b); adj[b].push_back(a);
	}
	for (int i = 0 ; i < nbEnnemis ; i++ )
	{
		int a,b;
		cin >> a >> b; a--; b--;
		ennemis[a].push_back(b);
		ennemis[b].push_back(a);
	}
	int nbC = 0;
	for (int i = 0 ; i < nbNoeuds ; i++)
	{
		if (appartient[i] == 0)
		{
			nbC++;
			remplir(i , nbC);
		}
	}
	for (int i = 0 ; i < nbNoeuds ; i++)
	{
		int tailleActu = taille[appartient[i]];

		tailleActu -= adj[i].size();
		tailleActu--;
		for (auto voisin : ennemis[i]) if (appartient[i] == appartient[voisin]) tailleActu--;
		cout<<tailleActu<<" ";
	}
	cout<<endl;
}

Measured memory_bytes: 17024
from collections import Counter
import math


def c_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = int(input())
a = list(map(int, input().split()))
a_cnt = Counter(a).most_common()
a_cnt_dict = dict(a_cnt)
ans = 0
for i in range(len(a_cnt)):
    if a_cnt[i][1] > 1:
        ans += c_count(a_cnt[i][1], 2)
for i in range(n):
    print(ans - (a_cnt_dict[a[i]] - 1))


Measured memory_bytes: 34100
#include <iostream>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <cstdio>
#include <math.h>
#include <map>
#include <algorithm>
#include <deque>
#include <stack>
#include<set>
//#include <bits/stdc++.h>
#define lson l,mid,rt<<1

#define rson mid+1,r,rt<<1|1

const int N=1e5+100;
using namespace std;

typedef long long ll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(1){
        c-=b;
        if(c<=0) {
            cout<<"Yes"<<endl;
            return 0;
        }
        a-=d;
        if(a<=0){
              cout<<"No"<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3100
import sys
N,X,M=map(int, sys.stdin.readline().split())

A=[]
A.append(X)
visit={}
for i in range(M+1):
    X=pow(X,2,M)
    if X not in visit:
        visit[X]=1
        A.append(X)
    else:
        break
loop_point=A.index(X)
notloop=A[:loop_point]
loop=A[loop_point:]

len_notloop=len(notloop)
len_loop=len(loop)


SUM_notloop=[0]
for x in notloop:
    SUM_notloop.append(SUM_notloop[-1]+x)


SUM_loop=[0]
for x in loop:
    SUM_loop.append(SUM_loop[-1]+x)

ans=0
if len_notloop<N:
    ans+=SUM_notloop[-1]
    N-=len_notloop
    sho,amari=N/len_loop,N%len_loop
    ans+=SUM_loop[-1]*sho
    ans+=SUM_loop[amari]
elif N<=len_notloop:
    ans=SUM_notloop[N]
print ans


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

def main():
    N=int(input())
    print(2**(N.bit_length()-1))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int C[3][3];
    REP(i,3){
        REP(k,3){
            cin >> C[i][k];
        }
    }
    vector <int> a(3,0), b(3,0);
    //if(C[0][0] == 0) a[0] = 0, b[0] = 0;
    REP(i,C[0][0]+1){
        a[0] = i , b[0] = C[0][0] - i;
        b[1] = C[0][1] - a[0];
        b[2] = C[0][2] - a[0];
        a[1] = C[1][0] - b[0];
        a[2] = C[2][0] - b[0];
        bool flag = true;
        for(int k = 1; k<= 2; k++){
            for(int j = 1; j <= 2; j++){
                if(a[k] + b[j] != C[k][j]) flag = false;
            }
        }
        if(flag){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <time.h>
#include <complex>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;
using std::complex;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;
typedef complex<double> cd;

inline ll max(ll a, ll b)
{
    if (a > b)
        return a;
    return b;
}

inline ll min(ll a, ll b)
{
    if (a < b)
        return a;
    return b;
}

namespace MySpace{
    struct Small_Segment_Tree{
        vector<int> a;
        int l, r;

        private:
        int __summ(int L, int R, int l, int r, int v)
        {
            if (L <= l && r <= R)
                return a[v];
            if (R <= l || r <= L)
                return 0;
            int m = (l + r) / 2;
            return __summ(L, R, l, m, 2 * v + 1) + __summ(L, R, m, r, 2 * v + 2);
        }

        void __set(int P, int l, int r, int v, int V)
        {
            if (l + 1 == r)
            {
                a[v] = V;
                return;
            }
            int m = (l + r) / 2;
            if (P < m)
            {
                __set(P, l, m, 2 * v + 1, V);
                a[v] = a[2 * v + 1] + a[2 * v + 2];
            }
            else
            {
                __set(P, m, r, 2 * v + 2, V);
                a[v] = a[2 * v + 1] + a[2 * v + 2];
            }
        }

        public:
        int Summ(int L, int R)
        {
            if (R < L)
                return 0;
            return __summ(L, R + 1, l, r, 0);
        }

        void Set(int P, int V)
        {
            __set(P, l, r, 0, V);
        }

        Small_Segment_Tree(int _n)
        {
            a.resize(4 * _n);
            l = 0, r = _n;
        }
    };
    long long inq(long long x, long long q, long long MOD)
    {
        if (q == 0)
            return 1;
        long long l = inq(x, q / 2, MOD);
        if (q % 2)
            return l * l % MOD * x % MOD;
        return l * l % MOD;
    }
};


using namespace MySpace;

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

const ll MOD = 1e9 + 7;
const ll K = 320;

ll x;

int main()
{
    ios_base::sync_with_stdio();
    cin.tie(0);
    cout.tie(0);
    cin >> x;
    ll ans = x / 11;
    ans += ans;
    x %= 11;
    if (x == 0)
        cout << ans;
    else
        if (x <= 6)
            cout << ans + 1;
        else
            cout << ans + 2;
}


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

using namespace std;
int main(){
	int count = 0;
	string w;
	string t;


	cin >>w;

	while (1)
	{
		cin >> t;
		
		

		if (t == "END_OF_TEXT")
		{
			break;
		}
		for (int i = 0; i < t.size(); i++)
		{
			t[i] = tolower(t[i]);
		}
		if (w==t)
		{
			count += 1;
		}

	}

	cout << count << endl;

	return 0;
}

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

int main()
{
	int N;
	cin >> N;
	int c = 0;
	int w = 1;
	for(int n=0; n<N; n++){
		int a;
		cin >> a;
		if(a == w){
			w++;
		} else {
			c++;
		}
	}
	if(c == N){
		cout << -1;
	} else {
		cout << c;
	}
}


Measured memory_bytes: 256
from math import sqrt


def dist(l, m):
    temp = 0
    for i in range(len(l)):
        temp += (l[i] - m[i]) ** 2
    return sqrt(temp).is_integer()


n, d = list(map(int, input().split()))
res = 0
l = []
for _ in range(n):
    l.append(list(map(int, input().split())))
for i in range(n - 1):
    for j in range(i + 1, n):
        res += dist(l[i], l[j])
print(res)


Measured memory_bytes: 9172
from sys import stdin


def main():
    readline = stdin.readline
    readline()
    *A, = map(int, readline().split())
    *B, = map(int, readline().split())
    B.append(0)
    ans = 0
    pre = 0
    for a, b in zip(A, B):
        brave = pre + b
        if brave < a:
            ans += brave
            pre = 0
        elif a < pre:
            ans += a
            pre = b
        else:
            ans += a
            pre = brave - a
    print(ans)
    return


main()


Measured memory_bytes: 19228
from collections import Counter
n = int(input())
v = list(map(int, input().split()))

k = n // 2
half = [Counter(), Counter()]
for i in range(k):
    for par in range(2):
        half[par][v[2*i+par]] += 1

cmn = [0, 0]
for par in range(2):
    cmn[par] = half[par].most_common(2)
    if len(cmn[par]) == 1:
        cmn[par].append(('ghost', 0))
if cmn[0][0][0] != cmn[1][0][0]:
    ret = n - cmn[0][0][1] - cmn[1][0][1]
else:
    ret = n - max(cmn[0][0][1] + cmn[1][1][1], cmn[0][1][1] + cmn[1][0][1])
print(ret)

Measured memory_bytes: 17312
n = int(input())
A = list(input().split())

even = [A[i] for i in range(n) if i % 2 == 0]
odd = [A[i] for i in range(n) if i % 2 == 1]

if n % 2 == 0:
    print(' '.join(list(reversed(odd)) + even))
else:
    print(' '.join(list(reversed(even)) + odd))

Measured memory_bytes: 27204
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int inf=0x3f3f3f3f;
int val[15][15],sum[1<<15],dp[15][1<<15],f[15];
int main(){
	int n=read(),m=read();
	while(m--){
		int x=read()-1,y=read()-1,z=read();
		val[x][y]=z,val[y][x]=z;
		sum[(1<<x)|(1<<y)]=z;
	}
	REP(i,0,n-1) REP(j,0,(1<<n)-1) if((1<<i)&j) sum[j]+=sum[j^(1<<i)];
	REP(i,0,n-1) REP(j,0,(1<<n)-1) dp[i][j]=-inf;
	REP(j,1,(1<<n)-1) if(j&1) dp[0][j]=sum[j];
	REP(i,1,(1<<n)-1){
		REP(j,0,n-1) f[j]=-inf;
		REP(j,0,n-1) if(i&(1<<j)) REP(k,0,n-1) if(val[j][k] && (i&(1<<k))==0) chkmax(f[k],dp[j][i]+val[j][k]);
		REP(j,0,n-1) if((i&(1<<j))==0)
			for(int cur=i|(1<<j),k=cur;k<=iend;k=(k+1)|cur)
				chkmax(dp[j][k],f[j]+sum[k^i]);
	}
	printf("%d\n",sum[(1<<n)-1]-dp[n-1][(1<<n)-1]);
	return 0;
}


Measured memory_bytes: 2304
using System;
using System.Collections.Generic;

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] strs = line.Split(' ');
            int N = int.Parse(strs[0]);
            int K = int.Parse(strs[1]);
            int C = int.Parse(strs[2]);
            line = Console.ReadLine();
            List<int> day = new List<int>();
            for(int i = 0; i < line.Length; i++)
            {
                if (line[i] == 'x') continue;
                day.Add(i + 1);
            }
            // K日選ぶ　C日休む
            int[] L = new int[K];
            int[] R = new int[K];
            int now = day[0];
            L[0] = day[0];
            int count = 1;
            for (int i = 1; i < day.Count && count < K; i++)
            {
                if (day[i] > now + C)
                {
                    L[count] = day[i];
                    now = day[i];
                    count++;
                }
            }
            now = day[day.Count - 1];
            R[K - 1] = day[day.Count - 1];
            count = K - 2;
            for (int i = day.Count - 2; i >= 0 && count >= 0; i--)
            {
                if (day[i] < now - C)
                {
                    R[count] = day[i];
                    now = day[i];
                    count--;
                }
            }
            for(int i = 0; i < K; i++)
            {
                if (L[i] == R[i]) Console.WriteLine(L[i]);
            }
        }
    }
}


Measured memory_bytes: 20444
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

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

int main(void) {
    int h,a;

    cin>>h>>a;

    if(h%a==0){
        cout<<h/a<<endl;
    }else{
        cout<<(h/a)+1<<endl;
    }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}
#define bit(n,k) ( (n>>k)&1 )

//デバッグ
template<class T>
void Vout(vector<T> &V){
    cout<<"\nstart\n";
    const int sz=V.size();
    for(int i=0;i<sz;i++){
        cout<<i<<" "<<V[i]<<'\n';
    }
    cout<<"end\n"<<endl;
}

template<class T>
void VPout(vector<T> &V){
    cout<<"\nstart\n";
    const int sz=V.size();
    for(int i=0;i<sz;i++){
        cout<<i<<" "<<V[i].first<<" "<<V[i].second<<'\n';
    }
    cout<<"end\n"<<endl;
}


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


constexpr int MAX=1<<30;
constexpr ll INF=1LL<<62;
constexpr int MOD=1e9+7;
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

//__builtin_popcount(S);
//#define int ll
//vector<vector<int>> data(3, vector<int>(4));
//vector.resize(a,vector<int>(b,-1));
//vector<vector<vector<要素の型>>> 変数名(要素数1, vector<vector<要素の型>>(要素数2, vector<要素の型>(要素数3, 初期値)));




signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); 
    cout<<fixed<<setprecision(10);

    int N;
    ll K;
    cin>>N>>K;
    vector<ll> A(N),B(N);
    for(int i=0;i<N;i++) cin>>A[i]>>B[i];
    ll ans=0;
    for(int i=29;i>=-1;i--){
        if(i!=-1 && !bit(K,i)) continue;
        ll temp=0;
        for(int j=0;j<N;j++){
            bool flag=true;
            ll x=A[j];
            for(int k=29;k>i;k--){
                if(!bit(K,k) && bit(x,k)) flag=false;
            }
            if(i!=-1 && bit(x,i)) flag=false;
            if(flag) temp+=B[j];
        }
        chmax(ans,temp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
     int a,b,c,k;
     cin >> a >> b >> c >> k;
     int n= max(max(a,b),c);
     int m = n;
     for(int i = 1; i <= k; i++){
          m *= 2;
     }
     cout << a + b + c - n + m << endl;
}

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

int main () {
    int n;
    while (cin >> n, n) {
        vector<string> v;
        vector<int> h;
        int hmax = 0;
        for (int i = 0; i < n; i++) {
            string str;
            cin >> str;

            int count  = 0;
            while (str[count] == '.') count++;
            // count--;
            if (count > 0) str[--count] = '+';
            v.push_back(str);
            h.push_back(count);
            hmax = max(hmax, count);
        }


        for (int i = 0; i < hmax; i++) {
            for (int j = n - 1; j > 0; j--) {
                if (h[j] < i) continue;
                if (v[j][i] == '+' && v[j-1][i] == '.') {
                    j--;
                    while (v[j][i] == '.') {
                        v[j][i] = '|';
                        j--;
                    }
                    j++;
                } else if (v[j][i] == '.') {
                    v[j][i] = ' ';
                }
            }
        }

        for (int i = 0; i < n; i++) {
            cout << v[i] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1788
s = input()
if s=='MON':
  print(6)
elif s=='TUE':
  print(5)
elif s=='WED':
  print(4)
elif s=='THU':
  print(3)
elif s=='FRI':
  print(2)
elif s=='SAT':
  print(1)
elif s=='SUN':
  print(7)

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long n;
  scanf("%lld", &n);
  std::vector<long long> p(n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &p[i]);
  }

  ll ans = 0;
  rep(i, 1, n - 1) {
    if (p[i - 1] < p[i] && p[i] < p[i + 1]) {
      ans++;
      continue;
    }

    if (p[i - 1] > p[i] && p[i] > p[i + 1]) {
      ans++;
      continue;
    }
  }

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

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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 A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


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

int a;
int n;

int dfs(int nowlen, int nowmul, int last, int p, int q)
{

    // cerr << nowlen << "," << nowmul << endl;
    if (p < 0)
    {
        return 0;
    }
    if (nowmul > a)
    {
        return 0;
    }

    if (p == 0)
    {
        //cerr << s << 1 << "/" << q / p << endl;
        return 1;
    }

    if (nowlen == n)
    {
        return 0;
    }

    int ret = 0;
    while (nowmul * last <= a)
    {
        int nextp = last * p - q;
        int nextq = q * last;
        //if (nextq % nextp == 0)
        //{
        //   nextq /= nextp;
        //  nextp = 1;
        // }
        ret += dfs(nowlen + 1, nowmul * last, last, nextp, nextq);
            last++;
    }
    return ret;
}

int main()
{
    while (true)
    {
        int q, p;
        cin >> p >> q >> a >> n;
        if (q == 0)
            break;
        cout << dfs(0, 1, 1, p, q) << endl;
    }
    return 0;
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#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 _GLIBCXX_DEBUG
#define V vector<int>
#define ll long long
using namespace std;


int main() {

    string S;
    cin >> S;

    int n = S.size();

    //n = 1 のとき
    if(n == 1) {
        cout << "1\n";
        return 0;
    }

    //n = 2 のとき
    if(n == 2) {
        if(S[0] == S[1]) cout << "1\n";
        else cout << "2\n";
        return 0;
    }

    //n = 3 のとき
    if(n == 3) {
        if(S[0] != S[1] && S[1] != S[2]) cout << "3\n";
        else cout << "2\n";
        return 0;
    }

    int dp[n];

    //n = 1
    dp[0] = 1;

    //n = 2
    if(S[0] == S[1]) dp[1] = 1;
    else dp[1] = 2;

    //n = 3
    if(S[0] != S[1] && S[1] != S[2]) dp[2] = 3;
    else dp[2] = 2;

    rep(i, 3, n){
        if(S[i] == S[i-1]) dp[i] = dp[i-3] + 2;
        else dp[i] = dp[i-1] + 1;
    }

    cout << dp[n-1] << "\n";
} 


Measured memory_bytes: 1284
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

typedef complex<double> Point;

const double EPS = 1e-10;

int sign(double x){
    if(x > EPS) return 1;
    if(x < -EPS) return -1;
    return 0;
}
struct Line : public vector<Point> {
    Line(const Point& a, const Point& b) {
        push_back(a); push_back(b);
    }
    Point vector() const {
        return back() - front();
    }
};

double cross(Point a, Point b){
    return imag(conj(a) * b);
}

bool paralell(Line l, Line m){
    return sign(cross(l.vector(), m.vector())) == 0;
}

int main(){
    int N;
    cin >> N;
    while(N--){
        Point p[4];
        REP(i, 4){
            double x, y;
            cin >> x >> y;
            p[i] = Point(x, y);
        }
        Line l1(p[0], p[1]);
        Line l2(p[2], p[3]);
        if(paralell(l1, l2)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1232
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        String s=sc.next();
  		String[] a=s.split("");
        Long b=sc.nextLong();
		int ans=1;
		
		for(int c=0;c<a.length;c++){
    		if(b>0){
             if(a[c].equals("1")){
             	b--;
             }else{
                ans=Integer.parseInt(a[c]);
                break;
             }
            }else{
            ans=1;
            }
    	}
    

    	System.out.println(ans);
    }
}


Measured memory_bytes: 35544
N = int(input())
S = list(input())

al = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

for i in range(len(S)):
    for j in range(26):
        if S[i] == al[j]:
            if j + N < 25:
                S[i] = al[j+N]
            else:
                S[i] = al[j+N-26]
            break

mojiretsu = ','.join(S)
print(str(mojiretsu).replace(',', ''))

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	const ll INF = 1LL << 60;
	ll cost[301][301];
	ll tank[301][301];

	ll n, m, l;
	cin >> n >> m >> l;
	for(int i = 0; i < n; ++i)
	{
		for(int j = 0; j < n; ++j)
		{
			cost[i][j] = INF;
		}
		cost[i][i] = 0;
	}

	ll a, b, c;
	for(int i = 0; i < m; ++i)
	{
		cin >> a >> b >> c;
		a--; b--;
		cost[a][b] = cost[b][a] = c;
	}

	for (int k = 0; k < n; k++){			// 経由する頂点
		for (int i = 0; i < n; i++) {		// 始点
			for (int j = 0; j < n; j++) {	// 終点
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}

	for(int i = 0; i < n; ++i)
	{
		for(int j = 0; j < n; ++j)
		{
			tank[i][j] = (cost[i][j] <= l) ? 1 : INF;
		}
	}

	for (int k = 0; k < n; k++){			// 経由する頂点
		for (int i = 0; i < n; i++) {		// 始点
			for (int j = 0; j < n; j++) {	// 終点
				tank[i][j] = min(tank[i][j], tank[i][k] + tank[k][j]);
			}
		}
	}

	int q;
	cin >> q;
	int s, t;
	for(int i = 0; i < q; ++i)
	{
		cin >> s >> t;
		s--; t--;
		cout << (tank[s][t] == INF ? -1 : tank[s][t] - 1) << endl;
	}




}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 1920
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT=mp::cpp_int;
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
INT LCM(INT x,INT y){
  INT z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
INT modinv(INT a, INT m) {
    INT b = m, u = 1, v = 0;
    while (b) {
        INT t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
  cout << fixed << setprecision(30);
  ll n,k;
  cin>>n>>k;
  vec x(n);
  ll maxx=0;
  loop(i,n){
    cin>>x[i];
    maxx=max(maxx,x[i]);
  }
  if(n==1){
   if(x[0]==k)putout("POSSIBLE"); 
   else putout("IMPOSSIBLE");
  }
  else{
  ll GCD=gcd(x[0],x[1]);
  loop(i,n)GCD=gcd(GCD,x[i]);
  if(GCD==1){
    if(k<maxx)putout("POSSIBLE");
    else putout("IMPOSSIBLE");
  }
  else{
    if(k>maxx)putout("IMPOSSIBLE");
    else{
      if(k%GCD==0)putout("POSSIBLE");
      else putout("IMPOSSIBLE");
    }
  }
  }
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*float n乗*/ll floatpow(float x,ll n){ll i;float ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
double ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll n;sc(n);
 bool my=false,ym=false;
 if(n/100<=12&&n/100>0)my=true;
 if(n%100<=12&&n%100>0)ym=true;
// pr(n/100);pr(n%100);
 if(my&&!ym)puts("MMYY");
 if(!my&&ym)puts("YYMM");
 if(my&&ym)puts("AMBIGUOUS");
 if(!my&&!ym)puts("NA");
return 0;}

Measured memory_bytes: 3608
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<limits.h>
#include<float.h>

#define MAX_NUM 29

void dfs(int i, bool adj[MAX_NUM][MAX_NUM], bool *visited, int n, int *ans){
	bool allVisited = true;
	for(int j=1; j<n+1; j++){
		if(!visited[j]) allVisited = false;
	}
	if(allVisited) {
		(*ans)++;
		return;
	}
	for(int j=1; j<n+1; j++){
		if((adj[i][j] || adj[j][i]) && !visited[j]) {
			visited[j] = true;
			dfs(j, adj, visited, n, ans);
			visited[j] = false;
		}
	}
}

void count(bool adj[MAX_NUM][MAX_NUM], int n, int *ans){
	bool visited[MAX_NUM];
	visited[1] = true;
	for(int i=2; i<n+1; i++){
		visited[i] = false;
	}
	dfs(1, adj, visited, n, ans);
}

int main(){
	int n, m, a, b, ans = 0;
	bool adj[MAX_NUM][MAX_NUM];
	scanf("%d%d\n", &n, &m);
	for(int i=1; i<n+1; i++){
		for(int j=1; j<n+1; j++){
			adj[i][j] = false;
		}
	}
	for(int i=0; i<m; i++){
		scanf("%d%d\n", &a, &b);
		adj[a][b] = true;
	}
	count(adj, n, &ans);
	printf("%d\n", ans);
	return 0;
}




Measured memory_bytes: 128