akhauriyash/Code-Regression huggingface dataset:
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<LL> a(n + 1), b(n);
	for (int i = 0; i < n + 1; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
	}
	LL ans = 0;
	for (int i = 0; i < n; ++i) {
		LL x = min(a[i], b[i]);
		ans += x;
		b[i] -= x;
		LL y = min(a[i + 1], b[i]);
		a[i + 1] -= y;
		ans += y;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	ll N, K;
	cin >> N >> K;
	if (2 * K > 1 + N) {
		cout << "-1" << endl;
	}
	else {
		ll N_2 = N / 2;
		rep(i, N) {
			ll a = K;
			ll b = K + N;
			ll c = K + N * 2;
			if (i < N_2) {
				a += N_2 - 1 - i;
				b += 2 * i + 1;
			}
			else {
				a += N + N_2 - 1 - i;
				b += 2 * (i - N_2);
			}
			c += i;
			cout << a << " " << b << " " << c << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 2304
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;

#define INF (1e9)

ll N;
ll MOD = 1e9 + 7;

ll mpow(ll x, ll n) {  //x^n(mod MOD)
    ll ans = 1;
    while (n != 0) {
        if (n & 1) ans = ans * x % MOD;
        x = x * x % MOD;
        n = n >> 1;
    }
    return ans % MOD;
}

int main() {
    cin >> N;

    ll A;
    vi D(70);
    for (int i = 0; i < N; i++) {
        cin >> A;
        for (int i = 0; i < 64; i++) {
            if ((A >> i) & 1) {
                D[i]++;
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < 64; i++) {
        ll x = D[i] * (N - D[i]);
        x %= MOD;
        x *= mpow(2, i);
        x %= MOD;
        ans += x;
        ans %= MOD;
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //__gnu_pbds::gp_hash_table<int, int> table;
//priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;  //min heap

typedef int OwO;
typedef double UwU;

#define int long long
#define double long double
#define INF 1000000000
#define PI 3.14159265358979323846
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vi vector<int>

using namespace std;

OwO main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;
  int oup = 0;
  for(int x = 0; x<S.length()-1; x++){
    if((S[x]=='1' && S[x+1]=='0')||(S[x]=='0' && S[x+1]=='1')){
      S.erase(S.begin()+x, S.begin()+x+2);
      if(x>0)
        x-=2;
      else
        x--;
      oup+=2;
    }
    if(S.size()==0)
      break;
  }
  cout << oup << endl;

  return 0;
}

Measured memory_bytes: 512
#include <cstdio>

int main(void)
{
    int i;

    scanf("%d", &i);

    int h, m, s;

    h = i / 3600;
    i = i % 3600;
    m = i / 60;
    s = i % 60;

    printf("%d:%d:%d\n", h, m, s);

    return 0;
}

Measured memory_bytes: 2740
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    int sum = 0;
    rep(i,n){
        int a;
        cin >> a;
        if(a%2==0) sum++;
        if(a%4==0) sum++;
    }
    if(n%2==1) n--;
    if(n <=sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main()
{
    int m, min, max;
    while (cin >> m >> min >> max && m) {
        vector<int> v;
        loop(m, i) {
            int j; cin >> j;
            v.push_back(j);
        }

        int gap = 0;
        int ans = 0;
        for (int i = min; i <= max; i++) {
            if (gap <= v[i-1] - v[i]) {
                gap = v[i-1] - v[i];
                ans = i;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3088
#include <iostream>
#define MAX 100001
using namespace std;

int a[MAX];
int count[MAX];

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

  for (int i = 0; i < MAX; i++)
    count[i] = 0;

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

  int sum = 0;
  for (int i = 0; i < MAX; i++) {
    if (count[i] == 0) continue;
    sum += count[i] - 1;
  }
  if (sum % 2) cout << n - sum - 1 << endl;
  else cout << n - sum << endl;

  return 0;
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] p = new int[N];
            for (int i = 0; i < N; i++) {
                p[i] = in.nextInt();
            }

            Arrays.sort(p);

            p[N - 1] /= 2;

            int sum = 0;
            for (int i = 0; i < N; i++) {
                sum += p[i];
            }

            System.out.println(sum);
        }
    }
}


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

using namespace std;
const int INF = 1e18;

struct edge
{
    int to;
    int cost;
};
using Graph = vector<vector<edge>>;

#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
Graph G;

int seen[110];
int discover[110];
int finish[110];
int stamp = 0;

void dfs(int cur)
{
    discover[cur] = stamp++;

    seen[cur] = BLACK;
    for (auto ne : G[cur])
    {
        int v = ne.to;
        int vc = ne.cost;
        if (seen[v] == BLACK)
            continue;
        dfs(v);
    }

    finish[cur] = stamp++;
}

void solve()
{

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

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

    int n;
    cin >> n;
    G.resize(n + 1);

    for (int i = 0; i <= n; i++)
    {
        if (i == 0)
        {
            for (int j = 1; j <= n; j++)
            {
                G[0].push_back((edge){j, 1});
            }
        }
        else
        {
            int u, k;
            cin >> u >> k;
            for (int j = 0; j < k; j++)
            {
                int v;
                cin >> v;
                G[u].push_back((edge){v, 1});
            }
        }
    }

    for (int i = 0; i < 110; i++)
    {
        seen[i] = WHITE;
        discover[i] = INF;
        finish[i] = INF;
    }

    dfs(0);

    for (int i = 1; i <= n; i++)
    {
        cout << i << " " << discover[i] << " " << finish[i] << endl;
    }
}

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



Measured memory_bytes: 3228
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>

using namespace std;

int main(){
	
	while(true){
		
		int n, m;
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		long long int wx[200], wy[200], r[200];
		
		for(int i = 0; i < n; i++){
			cin >> wx[i] >> wy[i] >> r[i];
		}
		
		cin >> m;
		
		for(int loop = 0; loop < m; loop++){
			
			bool flag = false;
			
			long long int tx, ty, sx, sy;
			cin >> tx >> ty >> sx >> sy;
			
			for(int i = 0; i < n; i++){
				bool isin1 = false, isin2 = false;
				if((sx - wx[i]) * (sx - wx[i]) + (sy - wy[i]) * (sy - wy[i]) < r[i] * r[i]){
					isin1 = true;
				}
				if((tx - wx[i]) * (tx - wx[i]) + (ty - wy[i]) * (ty - wy[i]) < r[i] * r[i]){
					isin2 = true;
				}
				if(isin1 && isin2){
					continue;
				}else if(isin1 || isin2){
					flag = true;
					break;
				}
				long long int a, b, c;
				a = (ty - sy);
				b = (sx - tx);
				c = sx * (sy - ty) - sy * (sx - tx);
				if((a * wx[i] + b * wy[i] + c) * (a * wx[i] + b * wy[i] + c) > r[i] * r[i] * (a * a + b * b)){
					continue;
				}
				double a1, b1, x_center;
				a1 = (sx - tx) * (sx - tx) + (sy - ty) * (sy - ty);
				b1 = (sx - tx) * (wx[i] * (sx - tx) + wy[i] * (sy - ty)) - (sx * ty - tx * sy) * (sy - ty);
				x_center = b1 / a1;
				if((sx - x_center) * (tx - x_center) <= 0){
					flag = true;
					break;
				}
			}
			if(flag){
				cout << "Safe" << endl;
			}else{
				cout << "Danger" << endl;
			}
		}
		
	}
	return 0;
}

Measured memory_bytes: 3020
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,a[N],c1[N],c2[N];
int main() {
	scanf("%d",&n);memset(c1,0,sizeof(c1));memset(c2,0,sizeof(c2));
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	bool bk=true,bo=true;int d1=1,d2=1;
	for(int i=3;i<=n;i+=2) {
		if(a[i]!=a[i-2])bk=false;	
		d1++;
	}for(int i=1;i<=n;i+=2)++c1[a[i]];
	for(int i=4;i<=n;i+=2) {
		if(a[i]!=a[i-2])bo=false;
		d2++;
	}for(int i=2;i<=n;i+=2)++c2[a[i]];
	if(bk==true && bo==true && a[1]!=a[2]){printf("0\n");return 0;}
	else {
		if(bk==true && bo==true){printf("%d\n",min(d1,d2));return 0;}
		int m11=0,m12=0,t11,t12;
		int m21=0,m22=0,t21,t22;
		if(bk==false && bo==true) {
			for(int i=1;i<=100000;++i) {
				if(m11<c1[i]) {
					swap(m11,m12);swap(t11,t12);
					m11=c1[i];t11=i;
				}
				else if(m12<c1[i])m12=c1[i],t12=i;
			}
			if(a[2]==t11) printf("%d\n",min(d2+d1-m11,d1-m12));
			else printf("%d\n",d1-m11);
		}
		else if(bk==true && bo==false) {
			for(int i=1;i<=100000;++i) {
				if(m11<c2[i]) {
					swap(m11,m12);swap(t11,t12);
					m11=c2[i];t11=i;
				}
				else if(m12<c2[i])m12=c2[i],t12=i;
			}
			if(a[1]==t11) printf("%d\n",min(d1+d2-m11,d2-m12));
			else printf("%d\n",d2-m11);
		}
		else {
			for(int i=1;i<=100000;++i) {
				if(m11<c1[i]) {
					swap(m11,m12);swap(t11,t12);
					m11=c1[i];t11=i;
				}
				else if(m12<c1[i])m12=c1[i],t12=i;
			}
			for(int i=1;i<=100000;++i) {
				if(m21<c2[i]) {
					swap(m21,m22);swap(t21,t22);
					m21=c2[i];t21=i;
				}
				else if(m22<c2[i])m22=c2[i],t22=i;
			}
			if(t11!=t21)printf("%d\n",d1+d2-m11-m21);
			else {
				int mn=(1<<31)-1;
				if(t11!=t22)mn=min(mn,d1+d2-m11-m22);
				if(t21!=t12)mn=min(mn,d1+d2-m21-m12);
				printf("%d\n",mn);
			}
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

ll A, B, C, D;

ll gcd(ll a, ll b)
{
    return (b == 0 ? a : gcd(b, a % b));
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> A >> B >> C >> D; --A;
    ll CD = C * D / gcd(C, D);
    cout << (B - A) - (B / C - A / C) - (B / D - A / D) + (B / CD - A / CD) << endl;  
    return 0;
}


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

int main(void){
    int N, T;
    cin >> N >> T;
    int ans=0;
    int temp=0;
    int t[200005];
    
    for(int i=0; i<N; i++){
        cin >> t[i];
        if(T > (t[i] - temp)) ans += (t[i] - temp);
        else ans += T;
        temp = t[i];
    }
    ans +=T;

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	while(cin>>s){
		int n;
		cin>>n;
		string operate,str;
		int x1,x2;
		for(int i=0;i<n;i++){
			cin>>operate;
			cin>>x1>>x2;
			if(operate=="replace"){
				cin>>str;
				for(int i=x1,j=0;i<=x2;i++,j++){
					s[i]=str[j];
				}
			}else if(operate=="reverse"){
				str=s.substr(x1,x2+1);
				for(int i=x1,j=x2-x1;i<=x2;i++,j--){
					s[i]=str[j];
				}
			}else if(operate=="print"){
				for(int i=x1;i<=x2;i++){
					cout<<s[i];
				}
				cout<<endl;
			}
		}
	}
	return 0;
} 


Measured memory_bytes: 3228
#include <bits/stdc++.h>
     
    using namespace std;
    const long long INF = 1LL <<60;
     
    int main(void){
      int x;
      cin>>x;
      
      if(x>=30){
        cout<<"Yes"<<endl;
      }
      else{
        cout<<"No"<<endl;
      }
      
      return 0;
    }

Measured memory_bytes: 3604
abc = input().split(' ')
W = int(abc[0])
H = int(abc[1])
x = int(abc[2])
y = int(abc[3])
r = int(abc[4])
if (x-r < 0 or x+r > W) or (y-r < 0 or y+r > H):
	print('No')
else:
	print('Yes')


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

int i,j,m,n,t,s,k;

int main() {
	scanf("%d",&n);
	m = n;
	while(m>0){
		k += m % 10;
		m /= 10;
	}
	if(n % k==0)printf("Yes");
	else {
		printf("No");
		
	}	
	return 0;
}

Measured memory_bytes: 256
#include <array>
#include <cstddef>
#include <cstdint>
#include<algorithm>
#include <vector>

using usize = std::size_t;
using u64 = long long;

struct foldable_wavelet_matrix {
	static constexpr usize BitLen = static_cast<usize>(30);

	struct bitvector {
		struct node_type {
			usize count;
			u64 sum;
		};

		std::vector<node_type> vector;

		bitvector() : vector() {}

		void resize(const usize size) { vector.resize(size+1); }
		void set(const usize index) { vector[index+1].count = static_cast<usize>(1); }
		void build(const std::vector<u64> &a) {
			const usize size = a.size();
			for (usize i = static_cast<usize>(0); i != size; ++i) {
				vector[i + static_cast<usize>(1)].count += vector[i].count;
				vector[i + static_cast<usize>(1)].sum = vector[i].sum + a[i];
			}
		}

		usize count(const usize index) const { return vector[index].count; }
		usize zeros() const { return vector.size()-1 - vector.back().count; }
		u64 fold(const usize first, const usize last) const {
			return vector[last].sum - vector[first].sum;
		}
	};

	std::array<bitvector, BitLen> matrix;

	explicit foldable_wavelet_matrix(std::vector<u64> a) {
		const usize size = a.size();
		std::vector<u64> b(size);
		usize bitpos = BitLen;
		while (bitpos != static_cast<usize>(0)) {
			--bitpos;
			bitvector &v = matrix[bitpos];
			v.resize(size);
			auto zero_itr = b.begin(), one_itr = b.end();
			for (usize i = static_cast<usize>(0); i != size; ++i) {
				if ((a[i] >> bitpos & static_cast<u64>(1)) == static_cast<u64>(1)) {
					v.set(i);
					--one_itr;
					*one_itr = a[i];
				}
				else {
					*zero_itr = a[i];
					++zero_itr;
				}
			}
			std::reverse(one_itr, b.end());
			v.build(b);
			std::swap(a, b);
		}
	}

	u64 fold_topk(usize first, usize last, usize k) const {
		u64 ret = static_cast<u64>(0);
		usize bitpos = BitLen;
		while (bitpos != static_cast<usize>(0)) {
			--bitpos;
			const bitvector &v = matrix[bitpos];
			const usize f_cnt = v.count(first), l_cnt = v.count(last),
				zeros = v.zeros();
			if (k < l_cnt - f_cnt) {
				first = zeros + f_cnt;
				last = zeros + l_cnt;
			}
			else {
				k -= l_cnt - f_cnt;
				ret += v.fold(zeros + f_cnt, zeros + l_cnt);
				first -= f_cnt;
				last -= l_cnt;
			}
		}
		return ret + matrix.front().fold(last - k, last);
	}
};

#include<vector>
#include<iostream>
#include<algorithm>

int main() {

	usize n;
	std::cin >> n;
	std::vector<u64> a(3*n );
	for (auto &e : a) {
		std::cin >> e;
	}
	foldable_wavelet_matrix fwm(a);

	u64 max = -1000000000LL * 100000LL;
	for (int i = n;i <= 2 * n;++i) {
		max = std::max(max,
			fwm.fold_topk(0, i, n) 
			- (fwm.fold_topk(i, 3 * n, 3 * n - i) 
				- fwm.fold_topk(i, 3 * n, 3 * n - i - n)));
	}
	std::cout << max << std::endl;

	return 0;
}


Measured memory_bytes: 147968
import java.util.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    static int dx[]={-1,0,1,0};
    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}


        
//        long L=sc.nextLong();
//        int n=sc.nextInt();	
        long w=0, ans=0;
        String s=sc.nextString();
        for (int i = 0; i < s.length(); i++) {
			if(s.charAt(i)=='B')w++;
			else ans+=w;
		}


        out.println(ans);
        out.flush();
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

class P {
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
}

//class P implements Comparable<P>{
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//    public int compareTo(P p){
//        return d-p.d; //des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 25072
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
A.sort()

PLUS = A[int((N+1)//2):]
MINUS = A[:int((N+1)//2)]
#print(PLUS, MINUS)
ans = sum(PLUS)*2 - sum(MINUS)*2
if N%2==0:
    ans += MINUS[-1] - PLUS[0]
else:
    ans += sum(MINUS[-2:])

PLUS = A[int(N//2):]
MINUS = A[:int(N//2)]
#print(PLUS, MINUS)
ans2 = sum(PLUS)*2 - sum(MINUS)*2
if N%2==0:
    ans2 += MINUS[-1] - PLUS[0]
else:
    ans2 -= sum(PLUS[:2])

print(max(ans, ans2))

Measured memory_bytes: 8148
import math
n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
D = [abs(X[i]-Y[i]) for i in range(n)]
for p in [1, 2, 3, -1]:
    if p == -1:
        print(max(D))
    else:
        print(math.pow(sum([math.pow(D[i],p) for i in range(n)]),1/p))



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

using namespace std;

const long long ool = 1e18;

long long fuel[310][310], dist[310][310];
long long a[105000], b[105000], c[105000];
long long s[105000], t[105000];

int main() {
    int n, m, l, q;
    cin >> n >> m >> l;
    for (int i = 1; i <= m; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    cin >> q;
    for (int i = 1; i <= q; i++) {
        cin >> s[i] >> t[i];
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            fuel[i][j] = ool;
            dist[i][j] = ool;
        }
        fuel[i][i] = 0;
        dist[i][i] = 0;
    }
    for (int i = 1; i <= m; i++) {
        fuel[a[i]][b[i]] = min(c[i], fuel[a[i]][b[i]]);
        fuel[b[i]][a[i]] = min(c[i], fuel[b[i]][a[i]]);
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                fuel[j][k] = min(fuel[j][k], fuel[j][i] + fuel[i][k]);
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == j) continue;
            if (fuel[i][j] <= l) dist[i][j] = min(dist[i][j], 1ll);
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }

    for (int i = 1; i <= q; i++) {
        if (dist[t[i]][s[i]] == ool) cout << "-1\n";
        else cout << dist[t[i]][s[i]] - 1 << '\n';
    }
}

Measured memory_bytes: 5632
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;
vector<vec> G(N,vec());
bool is_bi=true;
int visited[N];
void dfs(int x,int color){
    visited[x]=color;
    int next=color%2+1;
    for(auto e:G[x]){
        if(visited[e]&&visited[e]!=next)is_bi=false;
        if(visited[e]==0){
            dfs(e,next);
        }
    }
}
main(){
    ll n=in(),m=in();
    rep(i,m){
        int a=in(),b=in();
        G[a].pb(b);
        G[b].pb(a);
    }
    dfs(1,1);
    ll nn=n*(n-1)/2;
    if(is_bi){
        ll ans=0;
        ll black=0,white=0;
        rep2(i,1,n){
            if(visited[i]==1)black++;
            else white++;
            for(auto e:G[i]){
                if(visited[e]!=visited[i])ans--;
            }
        }
        ans/=2;
        ans+=black*white;
        cout<<ans<<endl;
    }
    else{
        cout<<nn-m<<endl;
    }
    return 0;
}



Measured memory_bytes: 16000
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
int main(){
	int N;
	cin>>N;
	set<pint> tes;
	for(int i=1;i<N;i++){
		if(i!=N-i)
			tes.insert(mp(min(i, N-i), max(i, N-i)));
	}
	cout<<tes.size()<<endl;
	return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define dump(x) cerr << #x << " => " << (x) << endl
#define MIN(vec) *min_element(vec.begin(), vec.end())
#define MAX(vec) *max_element(vec.begin(), vec.end())
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end()) //ソートの必要あり
#define IN(n, m) (!(m.find(n) == m.end()))
#define FINDL(vec, x) (lower_bound(vec.begin(), vec.end(), x) - vec.begin())
#define FINDU(vec, x) (upper_bound(vec.begin(), vec.end(), x) - vec.begin())
#define EQ(a, b) (abs(a - b) < 1e-10)
using namespace std;
typedef long long LL;
constexpr int dx[4] = {0, 1, 0, -1};
constexpr int dy[4] = {1, 0, -1, 0};
constexpr long double pi = M_PI;
constexpr double eps = 1e-10;
constexpr long mod = 1000000007;
// LONG_MAX,LLONG_MAX
template <class T1, class T2>
ostream &operator<<(ostream &s, pair<T1, T2> P)
{
    return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream &operator<<(ostream &s, vector<T> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        if (i > 0)
        {
            s << " ";
        }
        s << P[i];
    }
    return s;
}
template <class T>
ostream &operator<<(ostream &s, vector<vector<T>> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        s << endl
          << P[i];
    }
    return s << endl;
}
template <class Key, class Value>
ostream &operator<<(ostream &s, map<Key, Value> M)
{
    for (auto itr = begin(M); itr != end(M); ++itr)
    {
        s << itr->first << ":" << itr->second;
    }
    return s;
}

vector<int> cnt;
vector<vector<int>> edge;
void dfs(int n, int prev)
{
    for (auto &&e : edge[n])
    {
        if (e == prev)
            continue;
        cnt[e] += cnt[n];
        dfs(e, n);
    }
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    cnt = vector<int>(N, 0);
    edge = vector<vector<int>>(N);
    REP(i, N - 1)
    {
        int a, b;
        cin >> a >> b;
        edge[a - 1].push_back(b - 1);
        edge[b - 1].push_back(a - 1);
    }
    REP(q, Q)
    {
        int p, x;
        cin >> p >> x;
        cnt[p - 1] += x;
    }
    dfs(0, -1);
    for (auto &&e : cnt)
    {
        cout << e << " ";
    }
    cout << endl;
}


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

int x[202020];
int l[202020][20], r[202020][20];
int dpl[1 << 20], dpr[1 << 20];

void solve() {
        int n, v;
        cin >> n >> v;
        for (int i = 0; i < n; i ++) cin >> x[i];
        int p;
        for (int i = 0; ; i ++) if ((1 << i) > v) {
                p = i + 1;
                break;
        }
        for (int i = 0; i < n; i ++) {
                int vv = v;
                for (int j = 0; j < p; j ++) {
                        if (i == 0 || x[i] - x[i - 1] > vv) l[i][j] = i;
                        else l[i][j] = l[i - 1][j];
                        vv /= 2;
                }    
        }
        for (int i = n - 1; i >= 0; i --) {
                int vv = v;
                for (int j = 0; j < p; j ++) {
                        if (i == n - 1 || x[i + 1] - x[i] > vv) r[i][j] = i;
                        else r[i][j] = r[i + 1][j];
                        vv /= 2;
                }
        }
        for (int i = 0; i < (1 << p); i ++) {
                //if (i & 1) continue;
                for (int j = 0; j < p; j ++) {
                        if ((i >> j) & 1) continue;
                        if (dpr[i] == n) dpr[i | (1 << j)] = n;
                        else dpr[i | (1 << j)] = max(dpr[i | (1 << j)], r[dpr[i]][j] + 1);
                }
        }
        for (int i = 0; i < (1 << p); i ++) dpl[i] = n - 1;
        for (int i = 0; i < (1 << p); i ++) {
                //if (i & 1) continue;
                for (int j = 0; j < p; j ++) {
                        if ((i >> j) & 1) continue;
                        if (dpl[i] == -1) dpl[i | (1 << j)] = -1;
                        else dpl[i | (1 << j)] = min(dpl[i | (1 << j)], l[dpl[i]][j] - 1);
                }
        }
        bool ok = false;
        for (int i = 0; i < n; i ++) {
                if (l[i][0] == i) {
                        int c = 0;
                        for (int j = 0; j < (1 << p); j ++) {
                                c ++;
                                if (j & 1) continue; 
                                if (i > 0 && dpr[j] < i) continue;
                                if (r[i][0] < n - 1 && dpl[((1 << p) - 1 - j) - 1] > r[i][0]) continue;
                                break;
                        }
                        if (c < (1 << p)) ok = true;
                        else ok = false;
                }
                if (ok) cout << "Possible" << endl;
                else cout << "Impossible" << endl;
        }
        return;
}

int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        solve();
        return 0;
}


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

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	long long s; cin >> s;
	map<long long, bool> mp; mp[s] = 1;
	int i = 2;
	while (1)
	{
		if (s % 2 == 0)s /= 2;
		else s = 3 * s + 1;

		if (mp[s])
		{
			cout << i << endl;
			return 0;
		}
		mp[s] = 1;
		++i;
	}
}

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

int main() {
  int n;
  cin >> n;
  vector<long long> ans(n,0);

  for (int x = 1;x <= 100;x++){
    for (int y = 1;y <= 100;y++){
      for (int z = 1;z <= 100;z++){
        int r =x*x + y*y + z*z + x*y + y*z + z*x;
        if (r <= n){
          ans[r-1]++;
        }
      }
    }
  }
  
  for (int i = 0;i < n;i++){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 3648
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    vi a(5);
    rep(i,5){
        cin>>a[i];
    }
    lli k;
    bool c=true;
    cin>>k;
    rep(i,5){
        for(lli j=i+1;j<5;j++){ 
            if(abs(a[i]-a[j])>k){ 
                c=false;
                break;
            }
        }
    }
    out((c?"Yay!":":("));

}

Measured memory_bytes: 3584
import java.util.*;

class Main {
  public static float calcStudyTime(int T, int X) {
    return (float) T / X;
  }
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    String line = scanner.nextLine();
    String[] values = line.split(" ", 0);

    int T = Integer.parseInt(values[0]);
    int X = Integer.parseInt(values[1]);
    
    System.out.println(calcStudyTime(T, X));
  }
}

Measured memory_bytes: 22996
#include<iostream>
#include<string>
#include<vector>

using namespace std;

void reverse(string *s){
	for(int i=0;i<s->length()/2;i++){
		char tmp=s->at(i);
		s->at(i)=s->at(s->length()-i-1);
		s->at(s->length()-i-1)=tmp;
	}
}

int main(void){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string s1,s2;
		cin>>s1;
		cin>>s2;
		if(s1.length()>80||s2.length()>80){
			cout<<"overflow"<<endl;
		}else{
			string s3;
			string tmp;
			if(s1.length()<s2.length()){
				tmp=s1;
				s1=s2;
				s2=tmp;
			}
			int c=0;
			for(int j=0;j<s1.length();j++){
				int tmp;
				if(j<s2.length()){
					tmp=s1[s1.length()-j-1]-'0'+s2[s2.length()-j-1]-'0'+c;
				}else{
					tmp=s1[s1.length()-j-1]-'0'+c;
				}
				c=tmp/10;
				s3.append(1,tmp%10+'0');
			}
			if(c!=0){
				s3.append(1,'1');
			}
			if(s3.length()>80){
				cout<<"overflow"<<endl;
			}else{
				reverse(&s3);
				cout<<s3<<endl;
			}
		}
	}
}

Measured memory_bytes: 1212
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 60;

ll C[MAX][MAX];

void com(){
    C[0][0]=1;
    for(ll i=1;i<51;i++){
        for(ll j=0;j<i+1;j++){
            if(j==0||j==i) C[i][j]=1;
            else{
                C[i][j]=C[i-1][j-1]+C[i-1][j];
            }
        }
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, p,a[60],ans=0,l[3]={};
    cin>>n>>p;
    rep(i,n){
        cin>>a[i];
        if(a[i]%2==0) l[0]++;
        else l[1]++;
    }
    com();
    if(p==1)rep2(i,1,n+1){
        for(ll j=1;j<i+1;j+=2){
            if(l[1]>=j && l[0]>=i-j){
                ans+=C[l[1]][j]*C[l[0]][i-j];
            }
        }
    }
    if(p==0){
        rep2(i,1,n+1){
            for(ll j=0;j<i+1;j+=2){
                if(l[1]>=j && l[0]>=i-j){
                    ans+=C[l[1]][j]*C[l[0]][i-j];
                }
            }
        }
        ans++;
    }
    // cout<<l[0]<<" "<<l[1]<<endl;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define lli long long int
#define double long double
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define siz(x) x.size()
#define prs(x,y) x.find(y)!=x.end()
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define forn(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}
inline int level(int n){int ans=0;while(n%2==0){n/=2;ans++;}return ans;}
int main()
{
	fast_io //REMOVE FOR interactive problems
	string s;
	cin>>s;
	lli ans=0;
	forn(i,(int)s.size())
	{
		ans+=(s[i]-'0');
	}
	ans%=9LL;
	if(ans==0)
		cout<<"Yes";
	else
		cout<<"No";
}



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

using namespace std;

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

    int ans = A * X + B * Y;
    int maxLoop = 1 + max(X, Y);
    int attain = 0;
    for (int i = 1; i < maxLoop; ++i) {
        int temp = C * 2 * i + A * max(X - i, 0) + B * max(Y - i, 0);
        if (temp < ans) {
            ans = temp;
            attain = i;
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
#define ll long long
#define ld long double


int main(){

int n;
cin>>n;

vector<vector<int>> red(n,vector<int>(2,0));
vector<vector<int>> blue(n,vector<int>(2,0));

rep(i,n){
    cin>>red[i][0]>>red[i][1];
}
 

rep(i,n){
    cin>>blue[i][0]>>blue[i][1];
}   

sort(red.begin(),red.end());
reverse(red.begin(),red.end());
  int ans=0;
  vector<bool>ch(n);
  rep(i,n){
    int now=1001001001;
    int co=-1;
    rep(j,n){
      if(!ch[j]&&red[i][0]<blue[j][0]&&red[i][1]<blue[j][1]){
        if(now>blue[j][1]){
          now=blue[j][1];
          co=j;
        }
      }
    }
    if(co>=0){
      ans++;
      ch[co]=true;
    }
  }
  
  cout<<ans<<endl;
}

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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)

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

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld EPS = 1e-9;


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

    const int MAX = 300001;
    vi prime(MAX, 1);
    for (int i = 6; i < MAX; ++i) {
        if (i % 7 != 1 and i % 7 != 6) continue;
        for (int j = 6; j * i < MAX; ++j) {
            if (j % 7 != 1 and j % 7 != 6) continue;
            prime[j * i] = 0;
        }
    }

    for (;;) {
        int n; cin >> n;
        if (n == 1) break;
        vi ans;
        for (int i = 6; i <= n; ++i) {
            if (i % 7 != 1 and i % 7 != 6) continue;
            if (prime[i] and n % i == 0) ans.push_back(i);
        }
        cout << n << ":";
        REP(i, SZ(ans)) {
            cout << " " << ans[i];
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3688
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    int ret = 0;
    for(int i = A; i <= B; i++)
    {
        if (i/10000 == i%10 && i%10000/1000 == i/10%10)
            ret++;
    }
    cout << ret << endl;
    
    return 0;
}

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

int main() {
  string a;
  cin >> a;
  
  if(a.at(0) != a.at(1) && a.at(0) != a.at(2) && a.at(0) != a.at(3)){
    cout << "No" << endl;
  }
  
  else if(a.at(1) != a.at(0) && a.at(1) != a.at(2) && a.at(1) != a.at(3)){
    cout << "No" << endl;
  }
  
  else if(a.at(2) != a.at(1) && a.at(2) != a.at(0) && a.at(2) != a.at(3)){
    cout << "No" << endl;
  }
  
  else if(a.at(3) != a.at(0) && a.at(3) != a.at(1) && a.at(3) != a.at(2)){
    cout << "No" << endl;
  }
  
  else if(a.at(0) == a.at(1) && a.at(1) == a.at(2) && a.at(2) == a.at(3)){
    cout << "No" << endl;
  }
  
  else{
    cout << "Yes" << endl;
  }
    
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	ll n;
	cin >> n;
	ll h, m, w;
	for (h = 1; h <= 3500; h++) {
		for (m = 1; m <= 3500; m++) {
			if (4 * h*m - n*m - n*h <= 0) {
				continue;
			}
			else if ((n*h*m) % (4 * h*m - n*m - n*h) == 0) {
				w = (n*h*m) / (4 * h*m - n*m - n*h);
				cout << h << " " << m << " " << w << endl;
				return 0;
			}
		}
	}
}

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

const int N = 100005;
const int INF = 1e8;

int n, m, s, t;

vector<int> G[N];
int dist[N][3];

int main() {
  cin >> n >> m;
  rep(i, m) {
    int u, v;
    cin >> u >> v; u--; v--;
    G[u].push_back(v);
  }
  cin >> s >> t; s--; t--;

  priority_queue<P, vector<P>, greater<P>> que;
  rep(i, n) rep(j, 3) dist[i][j] = INF;
  dist[s][0] = 0;
  que.push(make_pair(0, s));

  while (que.size()) {
    P p = que.top();
    que.pop();
    int d = p.first;
    int pos = p.second;
    rep(i, G[pos].size()) {
      int to = G[pos][i];
      int nd = d + 1;
      if (dist[to][nd % 3] > (nd + 2) / 3) {
        dist[to][nd % 3] = (nd + 2) / 3;
        que.push(make_pair(nd, to));
      }
    }
  }
  
  if (dist[t][0] == INF) cout << -1 << endl;
  else cout << dist[t][0] << endl;
  return 0;
}

Measured memory_bytes: 10244
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){

    int a, b;
    string s;
    
    cin>>a>>b;
    cin>>s;
    
    bool bb=true;
    
    for(int i=0; i<a; i++){
        if(!(s[i]>='0'&&s[i]<='9')){
            bb=false;
        }
    }
    
    if(!(s[a]=='-')){
        bb=false;
    }
    
    for(int i=a+1; i<a+b+1; i++){
        if(!(s[i]>='0'&&s[i]<='9')){
            bb=false;
        }
    }
    
    if(bb){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
from collections import deque
s=list(input())
x,y=map(int,input().split())
#print(s,x,y)
i=0
xflag=1
flag=0
xax=deque()
yax=deque()
cnt=0
while i<len(s):
    if s[i]=="F":
        cnt=cnt+1
    else:
        if cnt!=0:
            if xflag==1:
                xax.append(cnt)
            else:
                yax.append(cnt)
        xflag=(xflag+1)%2
        cnt=0
    i=i+1
if cnt!=0:
    if xflag == 1:
        xax.append(cnt)
    else:
        yax.append(cnt)
#print(xax,yax)
xdeq=deque()
ydeq=deque()
if (len(xax)>0)and(s[0]=="F"):
    x0=xax.popleft()
    xdeq.append(x0)
else:
    xdeq.append(0)
ydeq.append(0)
#print(xdeq,xax)
while len(xax)>0:
    subadd=xax.popleft()
    xdeq2=[]
    while len(xdeq)>0:
        xd=xdeq.popleft()
        xdeq2.append(xd-subadd)
        xdeq2.append(xd+subadd)
    xdeq2=list(set(xdeq2))
    for i in xdeq2:
        xdeq.append(i)
    #print(xdeq)
#print(xdeq)
while len(yax)>0:
    subadd=yax.popleft()
    ydeq2=[]
    while len(ydeq)>0:
        yd=ydeq.popleft()
        ydeq2.append(yd-subadd)
        ydeq2.append(yd+subadd)
    ydeq2=list(set(ydeq2))
    for i in ydeq2:
        ydeq.append(i)
    #print(ydeq)
#print(ydeq)
xlist=list(xdeq)
ylist=list(ydeq)
for i in xlist:
    for j in ylist:
        if (i==x)and(j==y):
            flag=1
            break
    if flag==1:
        break
if flag==1:
    print("Yes")
else:
    print("No")







Measured memory_bytes: 114200
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll fact[200020];
ll powmod(ll x,ll n){
    if(n == 0)return 1;
    ll ans = powmod(x*x%MOD,n/2);
    if(n & 1)ans = ans * x % MOD;
    return ans;
}
ll divmod(ll a,ll b){
    return ((a%MOD) * (powmod(b,MOD-2)%MOD)) % MOD;
}
ll combi(ll n,ll r){
    ll num = 1;
    /*
    for(ll i = 1;i <= r;i++){
        num = divmod((n-i+1)*num,i);
    }
    */
    return divmod(fact[n], fact[r] * fact[n-r] % MOD );
}
main(){
    fact[0] = 1;
    rep(i,1,200020){
        fact[i] = (fact[i-1] * i) % MOD; 
    }
    ll H,W,A,B;
    cin >> H >> W >> A >> B;
    ll ans = 0;
    rep(i,1,H-A+1){
        ll y1 = 1, y2 = i, y3 = H;
        ll x1 = 1, x2 = B, x3 = W;
        //cout << y1 << y2 << y3 << endl;
        //cout <<  combi(y2 - y1 + x2 - x1, x2 - x1) << ",";
        //cout << combi(y3 - y2 + x3 - x2, x3 - x2) << endl;
        ll num = combi(y2 - y1 + x2 - x1, x2 - x1) * combi(y3 - y2 + x3 - x2 - 1, x3 - x2 - 1);
        ans = (ans + num) % MOD;
   }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int x;
  cin>>x;
  if(x) cout<<0<<endl;
  else cout<<1<<endl;

  return 0;
}


Measured memory_bytes: 3604
#include<iostream>
using namespace std;
int main() {
    int a,b,c,tmp;
    cin >> a >> b >> c;
    if(a > b){
        if(a > c){
            if(b > c)cout << c << " " << b << " " << a << endl;
            else cout << b << " " << c << " " << a << endl;
        }
        else {
            cout << b << " " << a << " " << c << endl;
        }
    }
    else {
        if(a >c){
            cout << c << " " << a << " " << b << endl;
        }
        else {
            if(b > c)cout << a << " " << c << " " << b << endl;
            else cout << a << " " << b << " " << c << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3116
S = input()
BW01 = '01' * (len(S) // 2)
if len(S) % 2 == 1:
    BW01 += '0'
WB10 = '10' * (len(S) // 2)
if len(S) % 2 == 1:
    WB10 += '1'

ans1 = ans2 = 0
for i in range(len(S)):
    if i % 2 == 0 and S[i] == '1':
        ans1 += 1
    if i % 2 == 1 and S[i] == '0':
        ans1 += 1
    if i % 2 == 0 and S[i] == '0':
        ans2 += 1
    if i % 2 == 1 and S[i] == '1':
        ans2 += 1
# print(ans1, ans2)
print(min(ans1, ans2))

Measured memory_bytes: 3444
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  int N; cin >> N;
  vector<int> A(N);

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

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int mini = i;
    for (int j = i; j < N; j++) {
      if (A[j] < A[mini]) mini = j;
    }
    swap(A[i], A[mini]);
    if (i != mini)
      cnt++;
  }

  for (int i = 0; i < N; i++) {
    cout << A[i];
    if (i == N-1) cout << endl;
    else cout << ' ';
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1196
using System;
class Program
{
    static void Main()
    {
        var nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var map = new string[nm[0]];
        var temp = new string[nm[1]];
        for (int i = 0; i < nm[0]; i++) map[i] = Console.ReadLine();
        for (int i = 0; i < nm[1]; i++) temp[i] = Console.ReadLine();
        bool yes = true;
        bool ans = false;
        for (int x = 0; x < nm[0] - nm[1] + 1; x++)
        {
            for (int y = 0; y < nm[0] - nm[1] + 1; y++)
            {
                for (int i = 0; i < nm[1]; i++)
                {
                    for (int j = 0; j < nm[1]; j++)
                    {
                        if (map[x + i][y + j] != temp[i][j]) yes = false;
                    }
                }
                if (yes) ans = true;
                else yes = true;
            }
        }
        Console.WriteLine(ans ? "Yes" : "No");
    }
}



Measured memory_bytes: 13140