akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int n, k;
vector<vector<int>> tree;
vector<pair<int, int>> edges;
queue<int> que;
vector<int> dist;

void bfs(){
    while(que.size()){
        int v = que.front(); que.pop();
        for(int u : tree[v]){
            if(chmin(dist[u], dist[v] + 1)){
                que.push(u);
            }
        }
    }
}

int solve_even(){
    int res = n;
    rep(i, n){
        fill(all(dist), n); dist[i] = 0;
        que.push(i); bfs();
        int tmp = 0;
        for(int d : dist){
            if(d > k / 2)tmp++;
        }
        chmin(res, tmp);
    }
    return res;
}

int solve_odd(){
    int res = n;
    for(pair<int, int> e : edges){
        fill(all(dist), n); dist[e.first] = dist[e.second] = 0;
        que.push(e.first); que.push(e.second); bfs();
        int tmp = 0;
        for(int d : dist){
            if(d > k / 2)tmp++;
        }
        chmin(res, tmp);
    }
    return res;
}

int main(){

    cin >> n >> k;
    tree.resize(n);
    dist.resize(n);
    edges.resize(n - 1);

    rep(i, n - 1){
        int a, b; cin >> a >> b; a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
        edges[i] = make_pair(a, b);
    }

    if(k % 2 == 0)cout << solve_even() << endl;
    else cout << solve_odd() << endl;
    return 0;

}

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

template <typename _tp> inline void read(_tp&x){
	char ch=getchar();x=0;while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
}

const int N = 601000;
int sg[N], tag[N];

vector <int> vec[N];
vector <int> :: iterator itr;

void build(int l, int r, int x) {
	sg[x] = -l;
	if(l == r) return ;
	int mid = l + r >> 1;
	build(l, mid, x<<1);
	build(mid+1, r, x<<1|1);
}

inline void down(int x) {
	int&v = tag[x];
	sg[x<<1] += v, tag[x<<1|1] += v,
	sg[x<<1|1] += v, tag[x<<1] += v,
	v = 0;
}

void upd(int l, int r, int x, int L) {
	if(L <= l) return ++sg[x], ++tag[x], void();
	int mid = l + r >> 1; if(tag[x]) down(x);
	if(L <= mid) upd(l, mid, x<<1, L);
	upd(mid+1, r, x<<1|1, L);
	sg[x] = max(sg[x<<1], sg[x<<1|1]);
}

int qry(int l, int r, int x, int R) {
	if(r <= R) return sg[x];
	if(tag[x]) down(x);
	int mid = l + r >> 1, res = qry(l, mid, x<<1, R);
	if(mid < R) res = max(res, qry(mid+1, r, x<<1|1, R));
	return res;
}

int n, m;

int main() {
	read(n), read(m);
	for(int i=1,l,r;i<=n;++i) {
		read(l), read(r);
		vec[r].push_back(l);
	}
	
	build(0, m, 1);
	
	int Ans = m;
	for(int r=m+1;r>1;--r) {
		for(itr = vec[r].begin(); itr != vec[r].end(); ++ itr)
			upd(0, m, 1, *itr);
		Ans = max(Ans, qry(0,m,1,r-1) + r - 1);
	}
	Ans = max(Ans, n);
	printf("%d\n", Ans-m);
	return 0;
}

Measured memory_bytes: 22272
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<vector>
#include<algorithm>
#include<stack>
#include<tuple>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define OREP(i,n) FOR(i,1,n)
#define GREY 2
#define WHITE 1
#define BLACK 0
#define dis first
#define num second
#define MAX 922337206854775807
tuple<ll, ll, ll> xynum[100000];//distance,first,second
vector<tuple<ll, ll, ll>> lengthpoints;
ll n,xx[100000],yy[100000],money=0;
bool flag[200000] = { false };
ll par[100000] = { 0 }, depth[100000] = { 0 };

ll init(ll n) {
	REP(i, n) {
		par[i] = i;
		depth[i] = 0;
	}
	return 0;
}

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

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

bool same(ll x, ll y) {
	if (find(x) == find(y)) { return false; }
	else { return true; }
}

bool klaskal(ll i){
	if (same(get<1>(lengthpoints[i]),get<2>(lengthpoints[i]))) {//もし両方既にいったことのある点ならskipする
		money += get<0>(lengthpoints[i]);
		unite(get<1>(lengthpoints[i]), get<2>(lengthpoints[i])); return true;
	}
	return false;
}

ll sortandput() {
	sort(xynum, xynum + n);//xの順番でソートする、二回目はy
	FOR(i,0, n-1) {
		//cout << get<0>(xynum[i + 1]) << " " << get<0>(xynum[i]) << "a"<<i<<endl;
		lengthpoints.push_back(make_tuple(get<0>(xynum[i+1])-get<0>(xynum[i]),get<2>(xynum[i+1]),get<2>(xynum[i])));//長さ、一個目の頂点、二個目の頂点でtupleに入れる
	}
	return 0;
}

int main() {
	 cin >> n;//ｎを代入
	 init(n);
	 REP(i, n) {
		 ll gomi,gomi2;
		 cin >> gomi>> gomi2;//x,y座標を代入
		 xynum[i] = make_tuple(gomi, gomi2, i);//x,y座標、番号をxynumに入れる
	 }
	 sortandput();//x座標でソート、lengthpointsに代入
	 REP(i, n) {
		 swap(get<0>(xynum[i]), get<1>(xynum[i]));//x,y座標をswap
	 }
	 sortandput();//y座標でソート、lengthpointsに代入　　nとあるのはlengthpointsにn個目から代入するため
	 sort(lengthpoints.begin(),lengthpoints.end());//lengthpointsを長さでソート
	 ll count = 0;
	 REP(i, 2 * n-2) {
		 if (klaskal(i)) { count++; }//もしクラスカル法で橋を作ったならば、count++
		 if (count == n-1) {//森と木の関係で、一つの集合になったら終了
			 break;
		 }
	 }
	 cout << money << endl;//加算されたお金を出力
	 return 0;
}

Measured memory_bytes: 13424
import sys
import numpy as np
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    a = np.array(sorted(list(map(int, input().split()))))
    f = np.array(sorted(list(map(int, input().split())), reverse=True))

    Asum = a.sum()

    l, r = 0, int(1e13)
    while l != r:
        p = (l + r) // 2
        tmp = Asum - np.minimum(a, p//f).sum() <= K
        # print(p, tmp)
        if tmp:
            r = p
        else:
            l = p + 1
    
    print(l)


if __name__ == "__main__":
    main()

Measured memory_bytes: 37304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
int L;
int main(){
    cin>>L;
    double x,y,z;
    x=y=z=L/3.0;
    //cout<<x*y*z;
    cout << fixed << setprecision(15) << x*y*z << endl;
    return 0;
}

Measured memory_bytes: 256
program sample
	implicit none
    real(8) :: N
    
    read(*,*) N
    
	if (mod(int(N,8),2)==0) then
    	write(*,*) real(1,8)/2_8
	else
    	write(*,*) (N+1)/(2*N)
    end if

	stop
end program sample



Measured memory_bytes: 3032
i=gets
a=i.split[0].to_i
b=i.split[1].to_i
c=i.split[2].to_i
if (a > b) 
    a, b = b, a
end
if (b > c)
    b, c = c, b
end
if (a > b) 
    a, b = b, a
end
print a," ",b," ",c,"\n"


Measured memory_bytes: 6852
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    if(a == b && a == c){
      System.out.println(1);
    }
    else if (a != b && a!= c && b != c){
      System.out.println(3);
    }
    else
      System.out.println(2);
  }
}


Measured memory_bytes: 21332
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	int n,m;
	cin >> n >> m;
	
	vector<int> x(m);
	for(int i=0;i<m;i++)
		cin >> x[i];
	if(n>=m)
	{
		cout << 0 << endl;
		return 0;
	}
	
	sort(x.begin(),x.end());
	
	vector<long long> y(m-1);
	for(int i=0;i<m-1;i++)
		y[i]=x[i+1]-x[i];
	sort(y.begin(),y.end());

	int ans=0;

	for(int i=0;i<m-n;i++)
		ans+=y[i];
	
	cout << ans << endl;
}


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

int main()
{
    int N,X;
    cin >> N>>X;
    vector<int> L(N);
    for (int i = 0; i < N; i++)
        cin >> L[i];

    int d=0;
    int ans = 1;
    for (int i = 0; i < N; i++)
    {
        d+=L[i];
        if(d<=X)ans++;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  ll a;
  ll eo = 0;
  for (int i = 0; i < n; i++){
    cin >> a;
    if (a % 2){
      eo++;
    }
  }

  if (eo % 2){
    cout << "NO" << endl;
  }
  else
    cout << "YES" << endl;
    

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s,t;
	int cnt=0;
	cin >> s;
	int n=s.size();
	for(int i=0;i<n;i++)
	{
		if(i%2==0)
		{
			if(s[i]=='p')
			cnt--;
		}
		else if(i%2==1)
		{
			if(s[i]=='g')
			cnt++;
		}
	}
	cout << cnt;
}

Measured memory_bytes: 512
N, M = [int(n) for n in input().split()]
edges = []
for m in range(M):
  a, b, c = [int(w) for w in input().split()]
  a -= 1
  b -= 1
  edges.append((a, b, c * (-1)))

inf = 10000000000000000
dist =[inf]*N
dist[0] = 0

for i in range(N-1):
  for a, b, c in edges:
    dist[b] = min(dist[b], dist[a] + c)

ans = dist[N-1]

negative = [inf] * N
negative[0] = 0
for i in range(N):
  for a, b, c in edges:
    negative[b] = min(negative[b], negative[a] + c)

if negative[N-1] < dist[N-1]:
  print("inf")
else:
  print(-1*dist[N-1])

Measured memory_bytes: 3436
#include <iostream>
#include <stdio.h>
#include <cstring>
#define ll long long
#define maxn 100005
using namespace std;

pair<char, int> query[maxn];

int par[maxn], flag[maxn], n, q;

int getfa(int x) {
    if (flag[x])
        return x;
    else {
        par[x] = getfa(par[x]);
        return par[x];
    }
}

int main() {
    while (scanf("%d %d", &n, &q) == 2 && n && q) {
        memset(flag, 0, sizeof flag);
        flag[0] = 1; par[0] = 0;
        for (int i = 1; i < n; i++) {
            int p; scanf("%d", &p);
            par[i] = p - 1;
        }
        for (int i = 0; i < q; i++) {
            scanf(" %c %d", &query[i].first, &query[i].second);
            query[i].second--;
            if (query[i].first == 'M')
                flag[query[i].second]++;
        }
        ll ans = 0;
        for (int i = q - 1; ~i; i--)
            if (query[i].first == 'M')
                flag[query[i].second]--;
            else
                ans += getfa(query[i].second) + 1;
        printf("%lld\n", ans);
    }
    return 0;
}



Measured memory_bytes: 4916
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
const int INF = 1e9 + 5;

void min_self(int &a, int b){
	a = min(a,b);
	}
int main(){
	int n;
	scanf("%d",&n);
	vector<int> h(n);
	for(int& x: h){
		scanf("%d",&x);
		}
	vector<int> dp(n, INF);
	dp[0] = 0;
	for(int i = 0 ; i < n; ++i){
		for(int j : {i + 1, i + 2}){
			if(j < n){
				min_self(dp[j], dp[i] + abs(h[i] - h[j]));
				}
			}
		}
	printf("%d",dp[n - 1]);
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        sc.nextLine();
        
        String[] s = new String[n];
        for(int i=0; i<n; i++) {
            s[i] = sc.nextLine();
        }
        sc.close();

        Arrays.sort(s);

        StringBuilder sb = new StringBuilder();
        for(int i=0; i<n; i++) {
            sb.append(s[i]);
        }

        System.out.println(sb);
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	string s, ss;
	cin >> s;
	int n = s.length(), i, j, k, ans = n, c, ct;
	for (auto ch = 'a'; ch <= 'z'; ch++) {
		ss = ch + s + ch;
		c = 0; 
		for (i = 0; i <= n; i++) {
			if (ss[i] == ch) {
				for (j = i + 1; (j <= n) && (ss[j] != ss[i]); j++);
				c = max(c, j - i - 1);
			}
		}
		ans = min(ans, c);
	}

	cout << ans << "\n";
	return 0;
}



Measured memory_bytes: 504
// Great Ocean View

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

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

    int highest = h[0];
    int count = 0;

    for (int i = 1; i < n; i++) {
        if (h[i] == highest) {
            count++;
        } else if (h[i] > highest) {
            highest = h[i];
            count++;
        }
    }

    cout << count + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, X, Y;
vector<P> G[200000];
int C[200000], W[200000];
int U[200000], R[200000];
int fact[200001], factinv[200001];
int ctr[200000];

int modpow(int x, int k) {
  int a = 1;
  while (k > 0) {
    if (k & 1) a = (1LL*a*x) % MOD;
    x = (1LL*x*x) % MOD;
    k >>= 1;
  }
  return a;
}

int inv(int x) {
  return modpow(x, MOD-2);
}

int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}

void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (R[x] < R[y]) swap(x, y);
  U[y] = x;
  R[x] += R[y];
  R[y] = 0;
}

bool same(int x, int y) {
  return find(x) == find(y);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> X >> Y;
  fact[0] = 1;
  factinv[0] = 1;
  for (int i=1; i<=N; i++) {
    fact[i] = (1LL*i*fact[i-1]) % MOD;
    factinv[i] = inv(fact[i]);
  }

  rep(i, N) {
    cin >> C[i] >> W[i];
    C[i]--;
    G[C[i]].pb(P(W[i], i));
  }
  vector<P> vs;
  rep(i, N) {
    sort(all(G[i]));
    if (!G[i].empty()) {
      vs.pb(G[i][0]);
    }
  }
  sort(all(vs));
  for (int i=0; i<N; i++) U[i] = i, R[i] = 1;
  rep(i, N) {
    int m = 0;
    if (C[vs[0]._2] == C[i]) {
      if (vs.size() <= 1) continue;
      m = 1;
    }
    if (vs[m]._1 + W[i] <= Y) unite(i, vs[m]._2);
  }
  rep(i, N) {
    if (G[i].size() <= 1) continue;
    int lim = X - G[i][0]._1;
    for (int j=1; j<G[i].size(); j++) {
      if (G[i][j]._1 > lim) break;
      unite(G[i][0]._2, G[i][j]._2);
    }
  }

  int rt = find(vs[0]._2);
  int ans = fact[R[rt]];
  rep(i, N) {
    if (find(i) == rt) ctr[C[i]]++;
  }
  rep(i, N) {
    ans = (1LL*ans*factinv[ctr[i]]) % MOD;
  }
  cout << ans << "\n";
  return 0;
}


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

int main() {
    double n, a[100], ans;
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        a[i] = 1/a[i];
        ans += a[i];
    }
    ans = 1/ans;
    cout << fixed << setprecision(5);
    cout << ans;
    
    
}

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

int main(){
  int i=0;
  while(true){
    int X;
    cin >> X;
    if(X==0){
      break;
    }
    else{
      cout << "Case" << " " << i+1 << ":" << " " << X << endl;
      i++;
    }
  }
}
      
    


Measured memory_bytes: 3048
#include <cstdio>
int main() {
	int N, M; scanf("%d", &N);
	for(M = 0; (M << 1 | 1) <= N; M = (M << 1 | 1));
	if( N == 1 || M + 1 == N )
		puts("No");
	else {
		puts("Yes");
		int P = (M + 1) >> 1;
		for(int i=1;i<P;i++) {
			printf("%d %d\n", i + N + P, i);
			printf("%d %d\n", i, P);
			printf("%d %d\n", P, i + P);
			printf("%d %d\n", i + P, i + N);
		}
		printf("%d %d\n", P + N, N + 1);
		if( M != N ) {
			printf("%d %d\n", P, M + 1);
			printf("%d %d\n", M + 1 + N, M + 2 + N);
			for(int i=M+2;i<=N;i++) {
				int x = i - (M + 1);
				if( x < P ) printf("%d %d\n", i + N, x + P);
				else if( x == P ) printf("%d %d\n", i + N, x);
				else printf("%d %d\n", i + N, x - P);
				printf("%d %d\n", M + 1, i);
			}
		}
	}
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int money = Integer.parseInt(sc.nextLine());
      	int work = money;
      	int i = 0;
      
      	while (work >= 500){
        	work = work - 500;
          	i++;
        }
      	
      	int j = 0;
      	while(work >= 5){
        	work = work - 5;
          	j++;
        }
      	
      	System.out.println(i*1000 + j * 5);
	}
}

Measured memory_bytes: 23764
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,VI(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)
     
int main() {
  ll n, m, k, x=0, y=0 , z = 0, h,w, sum = 1, Max = -1, Min = 3e9+1;
  string u;
  bool ok=true;
  cin >> n;
  VL a(n);
  rep(i,n) {
    cin >> a[i];
    if(a[i]==0){
      pri(0); return 0;
    }
  }

  rep(i,n){
    if(a[i] <= 1000000000000000000/sum){
      sum *= a[i];
    }
    else{
      pri(-1); return 0;
    }
  }
  pri(sum);
  return 0;
}


Measured memory_bytes: 3960
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def eratosthenes(n):
    p = []
    t = [0] * n

    for i in range(2, int(math.ceil(math.sqrt(n)))):
        if t[i] == 0:
            p.append(i)
            t[i] = i
            for j in range(2*i, n, i):
                if t[j] == 0:
                    t[j] = i

    for j in range(i+1, n):
        if t[j] == j or t[j] == 0:
            p.append(j)
            t[j] = j

    return p, t


@mt
def slv(N, A):
    _, T = eratosthenes(10**6+1)

    used = set()
    for a in A:
        while a != 1:
            p = T[a]
            if p in used:
                break
            while a % p == 0:
                a //= p
            used.add(p)
        if a != 1:
            break

    else:
        return 'pairwise coprime'

    g = 0
    for a in A:
        g = math.gcd(a, g)
    return 'setwise coprime' if g == 1 else 'not coprime'


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


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

int main() {
    string S;
    cin >> S;
    int len = int(S.size());

    int res = 754;
    for(int i=0; i<len-2; i++) {
        int temp;
        temp = 100*int(S[i]-'0') + 10*int(S[i+1]-'0') + int(S[i+2]-'0');
        res = min(res, abs(753-temp));
    } 
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


if __name__ == '__main__':
    a, b, c = list(map(int, input().split()))
    a, b = b, a
    a, c = c, a
    print("{} {} {}".format(a, b, c))

    #print('\33[32m' + 'end' + '\033[0m') # debug


Measured memory_bytes: 68688
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define DSORT(c, type) sort(ALL(c), greater<type>())

using namespace std;


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

  string s;
  cin >> s;
  int len = s.size();

  stack<int> st;
  int count = 0;
  for(int i=0; i<len; ++i){
    if(st.empty()){
      st.push(int(s[i]-'0'));
    }
    else{
      int top = st.top();
      if(top != int(s[i]-'0')){
        st.pop();
        count += 2;
      }
      else
        st.push(int(s[i]-'0'));
    }
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 720
import Control.Applicative
import Control.Monad
import Data.List
import Data.Set (Set)
import qualified Data.Set as S

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve <$> replicateM n f >>= print
    main
  where
    f = (\[x, y] -> (x, y)) <$> map read <$> words <$> getLine

solve :: [(Int, Int)] -> Int
solve ps = f 0 ps
  where
    st = S.fromList ps
    f mxa [_] = mxa
    f mxa ((a, b):ps) = let mxa' = foldl' (\ta (c, d) ->
                                          if S.member (b-d+a, c-a+b) st &&
                                             S.member (b-d+c, c-a+d) st
                                          then max ta ((c - a) ^ 2 + (d - b) ^ 2)
                                          else ta
                                        ) mxa ps
                        in f mxa' ps



Measured memory_bytes: 8384
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n; cin >> n;
    if (n % 2 == 0) {
        cout << 0.5 << "\n";
    } else {
        int m = n / 2;
        ld res = m + 1;
        cout << res / (ld) n << "\n";
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
#define int long long
#define f(i,n) for(ll i=0;i<n;i++)
#define fo(i,a,b) for(ll i=a;i<=b;i++)
#define forr(i,a,b) for(ll i=a;i>=b;i--)
#define bp __builtin_popcount
#define all(x) (x).begin(),(x).end()
#define s(x) sort(all(x))
#define r(x) reverse(all(x))
#define vll vector<ll>
#define pll pair<ll,ll>
#define sz size()
#define ln length()
#define pi acos(-1)
#define U 1e9
#define MOD 1000000007
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second 
#define vl vector<ll>
#define pll pair<ll,ll>
#define KHILADI ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
//cout << fixed << showpoint;
//cout << setprecision(7);

ll max(ll a , ll b){ if(a>b) return a; else return b;}
ll min(ll a , ll b){ if(a<b) return a; else return b;}

ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}          
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

signed main()
{
    KHILADI;
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    if((a[0]==a[1] && a[0]!=a[2])|| (a[1]==a[2] && a[0]!=a[2]) )
        cout << "Yes";
    else
        cout << "No";
    return 0;
}




Measured memory_bytes: 256
// ConsoleApplication.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#define _USE_MATH_DEFINES

#include "stdio.h"
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <unordered_set>
#include <functional>
#include <array>

using namespace std;
int INF = 1000000000;
int MAX = 5000001;


struct Card {
	string name;
	int num;
	Card() {}
	Card(const string& name, const int num):name(name),num(num){}
	bool operator==(const Card& rhs)const { return name == rhs.name && num == rhs.num; }
	bool operator<(const Card& rhs)const { return num < rhs.num; }
	bool operator<=(const Card& rhs)const { return num <= rhs.num; }
};

istream& operator>>(istream& is, Card& c) {
	is >> c.name;
	is >> c.num;
	return is;
}

ostream& operator<<(ostream& os, const Card& c) {
	os << c.name << " " << c.num;
	return os;
}

template<typename T>
int partition(vector<T>& A, int p, int r)
{
	T& x = A.at(r);
	for (int j = p; j != r; ++j) if (A.at(j) <= x) swap(A.at(p++), A.at(j));
	swap(A.at(p), x);
	return p;
}

template<typename T>
void quickSort(vector<T>& A, int p, int r) {
	if (p < r) {
		const int q = partition(A, p, r);
		quickSort(A, p, q - 1);
		quickSort(A, q + 1, r);
	}
}

template<typename T>
void quickSort(vector<T>& A) {
	quickSort(A, 0, A.size() - 1);
}
//
//
//void merge(vector<int>& A, const int left, const int mid, const int right, int & cnt, vector<int>& L, vector<int>& R) {
//	L.clear();  L.insert(L.end(), A.begin() + left, A.begin() + mid); L.push_back(INF);
//	R.clear();  R.insert(R.end(), A.begin() + mid, A.begin() + right); R.push_back(INF);
//	int i = 0, j = 0;
//	cnt += right - left;
//	for (int k = left; k != right; ++k) {
//		A.at(k) = L.at(i) <= R.at(j) ? L.at(i++) : R.at(j++);
//	}
//
//}
//
//void mergeSort(vector<int>& A, const int left, const int right, int& cnt, vector<int>& L, vector<int>& R) {
//	if (!(left + 1 < right)) return;
//	const int mid = (left + right) / 2;
//	mergeSort(A, left, mid, cnt, L, R);
//	mergeSort(A, mid, right, cnt, L, R);
//	merge(A, left, mid, right, cnt, L, R);
//}
//
//int mergeSort(vector<int>& A) {
//	int cnt = 0;
//	vector<int> L, R;
//	L.reserve(MAX);
//	R.reserve(MAX);
//	mergeSort(A, 0, A.size(), cnt, L, R);
//	return cnt;
//}

int main()
{
	int n;
	cin >> n;
	vector<Card> A(n);
	for (auto& c : A) cin >> c;
	vector<Card> B(A);
	quickSort(A);
	stable_sort(B.begin(), B.end());
	cout << (A == B ? "Stable" : "Not stable") << endl;
	for (const auto& c : A)cout << c << endl;

	return 0;
}


Measured memory_bytes: 12144
mod = 10 ** 9 + 7

N, M, *AB = map(int, open(0).read().split())
A, B = set(AB[:N]), set(AB[N:])

ma = max(A)

X = Y = 0
ans = 1
for k in reversed(range(1, ma + 1)):
    a, b = k in A, k in B
    if a and b:
        X += 1
        Y += 1
    elif a:
        ans *= Y
        X += 1
    elif b:
        ans *= X
        Y += 1
    else:
        ans *= X * Y + k - ma

    ans %= mod

print(ans)

Measured memory_bytes: 3316
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn main() {
    let n: usize = read();
    if n == 1 {
        println!("Hello World");
    } else {
        let a: usize = read();
        let b: usize = read();
        println!("{}", a + b);
    }
}

Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main()
{
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	
	for(int i = 0; i < tx - sx; i++)
	{
		cout << 'R';
	}
	for(int i = 0; i < ty - sy; i++)
	{
		cout << 'U';
	}
	for(int i = 0; i < tx - sx; i++)
	{
		cout << 'L';
	}
	for(int i = 0; i < ty - sy; i++)
	{
		cout << 'D';
	}
	
	cout << 'D';
	
	for(int i = 0; i < tx - sx + 1; i++)
	{
		cout << 'R';
	}
	for(int i = 0; i < ty - sy + 1; i++)
	{
		cout << 'U';
	}
	
	cout << "LU";
	
	for(int i = 0; i < tx - sx + 1; i++)
	{
		cout << 'L';
	}
	for(int i = 0; i < ty - sy + 1; i++)
	{
		cout << 'D';
	}
	cout << 'R';
	return 0;
}

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

void solve(int n){
	int a[n];
	vector<string> v;
	for(int i=0; i<n; ++i){
		string s;
		cin >> s;
		if(s == "x") a[i] = 1e9+7;
		else a[i] = stoi(s);
	}
	int l = -1e9-7;
	int r = 1e9+7;
	for(int i=0; i<n-1; ++i){
		if((a[i] == 1e9+7 && a[i+1] == 1e9+7)){
			cout << "none\n";
			return;
		}else if(a[i] == 1e9+7){
			if(i % 2 == 0){
				r = min(r, a[i+1]-1);
			}else{
				l = max(l, a[i+1]+1);
			}
		}else if(a[i+1] == 1e9+7){
			if(i % 2 == 0){
				l = max(l, a[i]+1);
			}else{
				r = min(r, a[i]-1);
			}
		}else{
			if(a[i] == a[i+1] || (i % 2 == 0 && a[i] > a[i+1]) || (i % 2 == 1 && a[i] < a[i+1])){
				cout << "none\n";
				return;
			}
		}
	}
	if(l == r) cout << l << "\n";
	else if(l < r) cout << "ambiguous\n";
	else cout << "none\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n;
		cin >> n;
		if(n == 0) return 0;
		solve(n);
	}
}


Measured memory_bytes: 3148
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <deque> 

using namespace std;


struct Range
{
	int l, r;
};
Range ranges[100010];

int n, m;

bool compareL(const Range &a, const Range &b)
{
	return a.l < b.l;
}

int ln, rn;

bool compareR(const Range &a, const Range &b)
{
	return a.r < b.r;
}


int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0 ; i < m ; i++)
		scanf("%d%d", &(ranges[i].l), &(ranges[i].r));
		
	sort(ranges, ranges + m, compareL);
	ln = ranges[m - 1].l;
	
	sort(ranges, ranges + m, compareR);
	rn = ranges[0].r;
	
	int count = rn - ln + 1;
	if (count < 0)
		count = 0;
	
	printf("%d\n", count);
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;


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

    int N, K;
    cin >> N >> K;
    int a;
    vector<int> cnt(200000);
    for (int i = 0; i < N; i++) {
        cin >> a;
        cnt[a]++;
    }

    vector<int> nz;
    for (int c : cnt) {
        if (c != 0)
            nz.push_back(c);
    }

    sort(begin(nz), end(nz));

    int ans = 0;
    for (int i = 0; i < (int)nz.size() - K; i++) {
        ans += nz[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2168
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(true){
            int h = sc.nextInt();
            int w = sc.nextInt();
            int i,j;
        if(h == 0 && w == 0){
           break;
        }
        else{
            for(i = 0; i < h; i++){
                for(j = 0; j < w; j++){
                    System.out.printf("#");
                }
            System.out.printf("\n");    
            }
        System.out.printf("\n");
        }    
        }
    }
}



Measured memory_bytes: 62204
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),m=sc.nextInt(),c=sc.nextInt();
        int[] b = new int[m];
        int ans = 0;
        for(int i = 0;i<m;i++){
            b[i] = sc.nextInt();
        }
        for(int i = 0;i<n;i++){
            int tmp = 0;
            for(int j = 0;j<m;j++){
                tmp += sc.nextInt()*b[j];
            }
            if(tmp+c>0){
                ans ++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using u64 = uint64_t;
int main() {
    u64 N;
    cin >> N;

    vector<u64> A(N), B(N), C(N);
    for (u64 i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (u64 i = 0; i < N; i++) {
        cin >> B[i];
    }
    for (u64 i = 0; i < N; i++) {
        cin >> C[i];
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    vector<u64> sum(N+1);
    u64 cursum = 0;
    for (u64 i = 0; i < N; i++) {
        u64 s = C.end() - upper_bound(C.begin(), C.end(), B[i]);
        cursum += s;
        sum[i+1] = cursum;
    }

    u64 cnt = 0;
    for (u64 a: A) {
        u64 i = upper_bound(B.begin(), B.end(), a) - B.begin();
        cnt += sum[N] - sum[i];
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <cstdio>

using namespace std;
typedef long long LL;

const int N=210;
const LL Inf=1e12+10;

LL n;
int app[N];

void Solve()
{
	int p=0,now=0;
	for (int i=40;i>=0;--i) 
		if ((1ll<<i)<=n) { p=i; break; }
	int tot=p*2+2;now=p+1;
	n-=1ll<<p;
	for (int i=p-1;i>=0;--i)
	{
		if ((1ll<<i)<=n)
		{
			n-=1ll<<i;
			app[i]=++now;
			tot+=2;
		}
	}
	printf("%d\n",tot);
	if (app[0]) printf("%d ",app[0]);
	for (int i=1;i<=p;++i)
	{
		printf("%d ",i);
		if (app[i]) printf("%d ",app[i]);
	}
	for (int i=1;i<=p;++i) printf("%d ",i);
	printf("%d %d ",p+1,p+1);
	for (int i=p;i>=0;--i) if (app[i]) printf("%d ",app[i]);
	putchar('\n');
}

int main()
{
	scanf("%lld",&n);
	Solve();
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#define N 100005
using namespace std;
int head[N],bin[N];
struct pl{int v,nex,flag;}e[2*N];
int n,m,x,y,cnt=1,fil,id1,id2,id3;
void add(int a,int b){cnt++;e[cnt].v=b;e[cnt].nex=head[a];head[a]=cnt;}
void dfs(int a){
	if(a==id1){fil=1;return;}
	if(a==id2) return;
	int i=head[a];
	while(i!=0){
		if(e[i].flag==0){
			e[i].flag=e[i^1].flag=1;
			dfs(e[i].v);
		}
		i=e[i].nex;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x),bin[x]++,bin[y]++;
	int fl1=0,fl2=0;
	for(int i=1;i<=n;i++){
		fl2=max(fl2,bin[i]);
		if(bin[i]&1) fl1=1;
	}
	if(fl1) puts("No");
	else{
		if(fl2<4) puts("No");
		else if(fl2>4) puts("Yes");
		else{
			id1=0,id2=0,id3=0;
			for(int i=1;i<=n;i++){
				if(bin[i]==4){
					if(id1==0) id1=i;
					else if(id2==0) id2=i;
					else id3=i;
				}
			}
			if(id2==0) puts("No");
			else if(id3!=0) puts("Yes");
			else{
				int i=head[id1];
				while(i!=0){
					if(e[i].flag==0){
						e[i].flag=e[i^1].flag=1;dfs(e[i].v);
					}
					i=e[i].nex;
				}
				if(fil) puts("Yes");
				else puts("No");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100010
#define inf 0x7fffffff
/*------------------------------------------------------------*/
int n,m;
ll a[maxn];
int main(){
	in(n);
	ll sum=0; 
	a[n+1]=0;
	FOR(i,1,n)inl(a[i]),sum+=abs(a[i]-a[i-1]);
	sum+=abs(a[n+1]-a[n]);
	FOR(i,1,n){
//		out(a[i+1]-a[i]);
		outl(sum-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]));
	}
}	

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int n,x,ans,tmp=0;
    cin>>n>>x;
    ans=n;
    vector<int> m(n);
    REP(i,n){
        cin>>m.at(i);
        tmp+=m.at(i);
    }
    sort(m.begin(),m.end());
    ans+=abs((x-tmp)/m.at(0));
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int k = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        for (int i = a; i <= b; i++) {
            if (i % k == 0) {
                out.println("OK");
                out.close();
                return;
            }
        }

        out.println("NG");
        out.close();
    }
}


Measured memory_bytes: 27080
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(a,b,c) for(int i=a;i<b;i+=c)  
typedef pair<ll , pair<ll, ll> > pi;
int pow(int x,int y){
    int res=1;
    while(y){
        if(y&1) res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}   
struct Compare {
    constexpr bool operator()(pi const & a,
                              pi const & b) const noexcept
    { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); }
 
};
ll dist[1005][1005];
 
bool vis[1005][1005];
vector<pair<pair<ll,ll>,ll>>adj[1005][1005];
char sura[1005][1005];

void dijkstra(ll x,ll y)
{
   
    dist[x][y]=0;
    priority_queue<pair<ll,pair<ll,ll>>, vector<pair<ll,pair<ll,ll>>>,greater<pair<ll,pair<ll,ll>>>>pq;
    pq.push({0,{x,y}});
    while(!pq.empty())
    {
       pair<ll,pair<ll,ll>> u=pq.top();
        pq.pop();
        vis[u.s.f][u.s.s]=true;
      
        if(dist[u.s.f][u.s.s]<u.f)
        continue;
        for(ll i=0;i<adj[u.s.f][u.s.s].size();i++)
        {
           pair<pair<ll,ll>,ll> v=adj[u.s.f][u.s.s][i];
            if(vis[v.f.f][v.f.s])
            continue;
            ll new_dist=dist[u.s.f][u.s.s]+v.s;
            if(new_dist<dist[v.f.f][v.f.s])
            {
                dist[v.f.f][v.f.s]=new_dist;
              
                pq.push({new_dist,{v.f.f,v.f.s}});
            }
 
        }
    }
 
}

int main()
{
    Fast
    ll h,w;
    ll start1,start2;
    ll end1,end2;
    cin>>h>>w;
    cin>>start1>>start2;
    cin>>end1>>end2;
    for(ll i=0;i<h;i++)
    {
        for(ll j=0;j<w;j++)
        {
            cin>>sura[i][j];
            vis[i][j]=false;
            dist[i][j]=100000000;
            
        }
    }
    for(ll i=0;i<h;i++)
    {
        for(ll j=0;j<w;j++)
        {
            for(ll k=i-2;k<=i+2;k++)
            {
                for(ll r=j-2;r<=j+2;r++)
                {
                    if(k==i && r==j )
                    continue;
                    else if(abs(k-i)+abs(r-j)==1 &&(k>=0 && k<h)&& (r>=0 && r<w) && sura[k][r]!='#')
                    adj[i][j].push_back({{k,r},0});
                    else if((k>=0 && k<h)&& (r>=0 && r<w) && sura[k][r]!='#')
                    {
                        adj[i][j].push_back({{k,r},1});
                    }
                }
                
            }
           // cout<<adj[i][j].size()<<endl;
        }
    }
    dijkstra(start1-1,start2-1);

    
    if(vis[end1-1][end2-1])
    {
        cout<<dist[end1-1][end2-1]<<'\n';
    }
    else
    {
        cout<<-1<<'\n';
    }
    

 

}



   
      
    
        



Measured memory_bytes: 424676
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Char
import Control.Monad

main = do
    [n,k,q] <- map read . words <$> getLine :: IO [Int]
    xs <- VUM.replicate (n+1) 0 :: IO (VUM.IOVector Int)
    replicateM_ q $ do
        a <- readLn :: IO Int
        VUM.modify xs (+1) a
    forM_ [1..n] $ \i -> do
        r <- VUM.read xs i
        if (q-r) < k
            then putStrLn "Yes"
            else putStrLn "No"

Measured memory_bytes: 2172
import sys

i = int(input())
d = [list(map(int, input().split())) for i in range(i)]

c = 0
for i in range(len(d)):
    if (d[i][0] == d[i][1]):
        c += 1
        if (c >= 3):
          print("Yes")
          sys.exit(0)
    else:
      c = 0
print("No")


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

int main(){
  int A,B; cin >> A >> B;
  int M; cin >> M;
  int a[100010],b[100010];
  int mina=10000000, minb=10000000;
  for(int i=0; i<A; i++){
    cin >> a[i];
    mina=min(mina,a[i]);
  }
  for(int i=0; i<B; i++){
    cin >> b[i];
    minb=min(minb,b[i]);
  }
  int mincost=mina+minb;
  for(int i=0; i<M; i++){
    int x,y,c; cin >> x >> y >> c;
    x--; y--;
    mincost=min(mincost,a[x]+b[y]-c);
  }
  cout << mincost << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct UnionFind
{
	std::vector<int> par, cou;
	UnionFind(int N = 0) : par(N), cou(N, 1) {
		iota(par.begin(), par.end(), 0);
	}
	int find(int x) { return (par[x] == x) ? x : (par[x] = find(par[x])); }
	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return false;
		if (cou[x] < cou[y]) std::swap(x, y);
		par[y] = x, cou[x] += cou[y];
		return true;
	}
	int count(int x) { return cou[find(x)]; }
	bool same(int x, int y) { return find(x) == find(y); }
};

void solve() {
	int n; cin >> n;
	int q; cin >> q;
	UnionFind u(n);
	while (q--) {
		int t, a, b; cin >> t >> a >> b;
		if (t == 0)u.unite(a, b);
		else if (t == 1) {
			if (u.same(a, b))cout << 1 << "\n";
			else cout << 0 << '\n';
		}
	}


}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--)
	solve();

}


Measured memory_bytes: 4720
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: i64, x: i64, t: i64,
    }
    puts!("{}\n", (n + x - 1) / x * t);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

ll dis(ll x1, ll y1, ll x2, ll y2){
    return abs(x1 - x2) + abs(y1 - y2);
}

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n), b(n), c(m), d(m);
    rep(i, n){
        cin >> a[i] >> b[i];
    }
    rep(i, m){
        cin >> c[i] >> d[i];
    }

    rep(i, n){
        ll ans_d = LLONG_MAX;
        ll ans = 0;
        for(ll j = m-1; j>=0;j--){
            ll d_ = dis(a[i], b[i], c[j], d[j]);
            if (ans_d >= d_){
                ans_d = d_;
                ans = j+1;
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second

#define pb push_back
#define es erase
#define in insert

#define pii pair<ll, ll>
#define ll long long
#define lb long double

#define ioss                     \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);

#define m_p(i, j) make_pair(i, j)
#define mem(a, x) memset(a, x, sizeof(a))
#define endl "\n"
#define all(x) x.begin(), x.end()

const ll mod = 1e9 + 7;
const ll maxn = 1e7 + 7;

int n, nums[maxn], t;

void split(int x)
{
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0)
            nums[i]++;
        while (x % i == 0)
            x /= i;
    }
    if (x != 1)
        nums[x]++;
}
int gcd(int a, int b)
{
    return __gcd(a, b);
}
int main()
{
    cin >> n;
    int gc = 0;
    for (int i = 1; i <= n; i++) {
        cin >> t;
        split(t);
        if (i == 1)
            gc = t;
        else
            gc = gcd(gc, t);
    }
    if (*max_element(nums + 2, nums + maxn - 10) < 2) {
        cout << "pairwise coprime" << endl;
    } else {
        if (gc == 1) {
            cout << "setwise coprime" << endl;
        } else {
            cout << "not coprime" << endl;
        }
    }
}


Measured memory_bytes: 7492