akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
int max(int a , int  b){
  if(a > b) return a;
  else return b;

}
int min(int a , int b){
  if(a < b) return a;
  else return b;
}
bool cmp(pair < int , string >   a , pair < int , string >   b){
  if(a.first < b.first ) return true;
  else return false;
}
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int dp[105][100005];
const int INF=1e9+7;
int32_t main(){  
  fast;
  int n,ww;
  cin >> n >> ww;
  vector < int > w(n) , v(n);
  for(int i  = 0 ; i < n ; i++) cin >> w[i] >> v[i];
    //cout << "ok\n";
  for(int i = 0 ; i < n ; i++){
    for(int j = 0; j < 100005; j++) dp[i][j]=INF;
  }
      dp[0][v[0]] = w[0];
      dp[0][0] = 0;
  //cout << "ok\n";
 for(int i = 1 ; i < n ; i++){
    for(int j = 0 ; j < 100005 ; j++){
        if(j>= v[i]){
            if(w[i] + dp[i-1][j-v[i]]  <= ww) dp[i][j] = min(dp[i-1][j] , dp[i-1][j-v[i]] + w[i]);
            else dp[i][j]= dp[i-1][j];
        }
        else dp[i][j] = dp[i-1][j];
    }
  }
  int ans = 0;
  for(int i = 0  ; i < n ; i++){
    for(int j = 0 ; j < 100005 ; j++){
      if(dp[i][j] !=INF) ans= max(ans,j);
    }
  }
  cout << ans << "\n";
  return 0;
} 

/*
1 -- 0
2 -- 

...
30 -- 3
..
49- --3
50 -- 4
60 -- 5
--
69 - 
70 -- 

subset sum = 100
100
100 - 

x  <=ww

*/

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;



bool solve(ll a, ll b, ll c, ll d, string s){
  if(s.substr(a+1, max(c, d)-a-1).find("##") != string::npos) return false;  
  return true;
}

int main(){
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  string s;
  cin >> s;
  a--; b--; c--; d--;

  if(s.substr(a+1, max(c, d)-a-1).find("##") != string::npos){
    cout << "No" << endl;
    return 0;
  }

  if(c < d){
    cout << "Yes" << endl;
    return 0;
  }
    
  for(ll m = b; m <= d; m++){
    if(s.substr(m-1, 3) != "...") continue;
    if(solve(m, m+1, d, c, s)){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 720
/**
*    author:  boutarou
*    created: 25.07.2020 21:02:00
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
    int a[3], k;
    cin >> a[0] >> a[1] >> a[2];
    cin >> k;
    vector<int>x;
    rep(i, 2) x.push_back(0);
    rep(i, k) x.push_back(1);
    do{
        int b[3];
        int now = 0;
        rep(i, 3) b[i] = a[i];
        rep(i, x.size()) {
            if (x[i] == 0) now++;
            else b[now] *= 2;
        }
        if (b[0] < b[1] && b[1] < b[2]) {
            cout << "Yes" << endl;
            return 0;
        }
    } while (next_permutation(x.begin(), x.end()));
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    map<long,int> mp;
    for(int i = 0; i < n; i++){
        long t;
        cin>>t;
        if(mp.find(t) == mp.end())
            mp[t]=1;
        else
            mp[t]++;
    }
    long max=0;
    for(auto x:mp){
        if(x.second>1&&x.first>max)
            max = x.first;
    }
    if(mp[max] >= 4){
        cout<<max*max;
        return 0;
    }
    mp.erase(max);
    long pmax=0;
    for(auto x:mp){
        if(x.second>1&&x.first>pmax)
            pmax = x.first;
    }
    cout<<max*pmax;
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

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

//int ()



int main()
{
  int a ,b, c, d, e, X, Y;
  double d_a,d_b, d_temp, d_count;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
//  int  A[200003]={};
  long long  A[100003]={};
  long long  B[100003]={};
  int  C[100003][11]={};

  int  flg=0;

//  long long  a, b, c, d, X, Y;
  char s[101][101]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans=0;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
  long long  tmp=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d", &a);
  scanf("%lf", &d_a);
  d_count=1;
  for(i=1;i<a;i++){
    scanf("%lf", &d_b);
    d_count=d_count*d_b+d_a;
    d_a=d_a*d_b;
//    printf("d_a=%lf d_count=%lf\n",d_a,d_count);
  }

  
//  if(a<3200)  printf("red\n");
//  else   printf("%s\n",t);
  printf("%lf\n",d_a/d_count);
 

return 0;
}


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

n=int(input())
A=list(map(int,input().split()))
for ai in A:
    if ai % 2 == 0:
        pro*=2
print(3**n-pro)

Measured memory_bytes: 3316
import bisect

N = int(input())
L = list(map(int,input().split()))

ans = 0
L = sorted(L)

for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        a = L[i]
        b = L[j]
        c = bisect.bisect_left(L,a+b)
        ans += c - j - 1

print(ans)

Measured memory_bytes: 9372
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n, m,k; string s; string sp;
char maze[60][60];
int dis[60][60];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main() {
	/*cin >> n >> s >> k; char key='a';
	for (int i = 0; i < n; i++) {
		if (i == k - 1) {
			key = s[i];
		}
	}
	string res;
	for (int i = 0; i < n; i++) {
		if (s[i] != key) {
			res += '*';
		}
		else {
			res += key;
		}
	}
	cout << res << endl;*/
	int a, b, c;
	cin >> a >> b >> c;
	if (a > b) {
		if (b < c && c < a) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else if (b > a) {
		if (a < c && c < b) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import Counter

def read():
    N = int(input().strip())
    return N,


def sieve(n):
    """
    n以下の素数を昇順に列挙する
    """
    is_prime = [True for i in range(n+1)]
    primes = []
    for i in range(2, n+1):
        if is_prime[i]:
            primes.append(i)
            for j in range(i+i, n+1, i):
                is_prime[j] = False
    return primes


def prime_factorization(n, primes):
    """
    nの素因数分解を求める
    """
    prime_factors = Counter()
    if n < 2:
        return prime_factors
    for p in primes:
        if p * p > n:
            break
        while n % p == 0:
            prime_factors[p] += 1
            n //= p
    if n > 1:
        prime_factors[n] = 1
    return prime_factors


def solve(N, p=10**9+7):
    primes = sieve(N)
    factors = Counter()
    for i in range(1, N+1):
        f = prime_factorization(i, primes)
        factors += f
    ans = 1
    for v in factors.values():
        ans *= (v+1)
        ans %= p
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 9416
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
using namespace std;


int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int X;
	cin >> X;
	if(X < 100) {
		cout << 0;
		return 0;
	}
	int divH = X / 100;
	int modH = X % 100;

	if(divH * 5 < modH) {
		cout << 0;

	} else {
		cout << 1;

	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    string s;
    cin >> s;
    ll c = 0;
    ll ans = 0;
    REP(i,s.size()){
        if(s[i]=='A' || s[i]=='G' || s[i]=='C' || s[i]=='T'){
            c++;
            ans = max(c,ans);
        }
        else{
            c = 0;
        }
        // cout << c << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[100000],tmp;
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1])tmp++;
    }
    cout<<n-tmp-tmp%2<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
string s;
string kupc = "KUPC";

bool input(){
  if(cin>>s)return true;
  return false;
}

int solve(){
  int k=0,u=0,p=0,c=0;
  for(int i=0;i<s.size();i++){
    switch(s[i]){
      case 'K':
        k++;
        break;
      case 'U':
        u++;
        break;
      case 'P':
        p++;
        break;
      case 'C':
        c++;
        break;
    }
  }
  return min(min(k,u),min(p,c));
}

int main(){
  while(input()){
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 1200
#!/usr/bin/ruby
#encoding: utf-8

n = gets.to_i
w = gets.split.map(&:to_i)

s1 = Array.new(n+1,0)
s2 = Array.new(n+1,0)

sum = w.inject(:+)
ans = 100000
tmpans = 0

(0..n-1).each do |i|
  (0..i).each do |j|
    #puts "i=#{i},j=#{j}"
    s1[i] += w[j]
  end

  s2[i] = sum - s1[i]
  tmpans = (s2[i] - s1[i]).abs

  if ans >= tmpans then
    ans = tmpans
  end
end

puts ans


Measured memory_bytes: 1916
//============================================================================
// Name        : template.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <vector>
#include <string.h> // for memset in CF judge.
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE // suppress some compilation warning messages (for VC++ users)
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define forn(i,n) \
for (int i =0; i<(n); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

int main() {
	ios::sync_with_stdio(false);
 cin.tie(0);
 string s,t;
 cin >> s >> t;
 ll ans = 0;
 forn(i, s.length()) {
 	if(s[i] != t[i]) ans++;
 }
 cout << ans << endl;
return 0;
}


Measured memory_bytes: 3808
open Batteries
let explode s = List.init (String.length s) (String.get s)
let string_of_chars chars = 
  let buf = Buffer.create 16 in
  List.iter (Buffer.add_char buf) chars;
  Buffer.contents buf
let n = read_line () |> explode
let rec ans lst = 
  match lst with
  | [] -> []
  | first :: rest -> if first = '9' then '1' :: ans rest else '9' :: ans rest

let _ = print_endline (string_of_chars (ans n))

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

using namespace std;

int main(int argc, const char *argv[]) {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int d1, d2;
  d1 = x2 - x1;
  d2 = y1 - y2;
  cout << x2 + d2 << ' ' << y2 + d1 << ' ' << x1 + d2 << ' ' << y1 + d1 << '\n';
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	int k;
	for (int i = 2; ; i++) {
		int t = i * (i - 1) / 2;
		if (t == n) {
			k = i;
			break;
		}
		if (n < t) {
			cout << "No" << endl;
			return 0;
		}
	}
	vector<vector<int>> v(k);
	int c = 1;
	for (int i = 0; i < k - 1; i++) {
		for (int j = i + 1; j < k; j++) {
			v[i].push_back(c);
			v[j].push_back(c);
			c++;
		}
	}
	cout << "Yes" << endl;
	cout << k << endl;
	rep(i, k) {
		cout << k - 1 << " ";
		rep(j, k - 1) {
			cout << v[i][j];
			if (j == k - 2) cout << endl;
			else cout << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 4532
#include <stdio.h>
int main(){
    int N;
    int CX['z'+1];
    int CY['z'+1];
    int anw=0,ANW=0;
    char S[110];
    char X[110],Y[110];
    scanf("%d",&N);
    scanf("%s",S);
    for(int i=0;i<N-1;i++){
        anw=0;
        for(int j='a';j<='z';j++) {
            CX[j]=0;
            CY[j]=0;
        }
        X[i]=S[i];
        for(int j=0;j<N-i-1;j++) Y[j]=S[j+i+1];
        for(int j=0;j<=i;j++) CX[X[j]]++;
        for(int j=0;j<N-i-1;j++) CY[Y[j]]++;
        for(int j='a';j<='z';j++){
            if(CX[j]!=0&&CY[j]!=0) anw++;
        }
        if(i==0) ANW=anw;
        if(anw>ANW) ANW=anw;
    }
    printf("%d",ANW);
}



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

using namespace std;

int n, k, d[10];

int main(){
	cin >> n >> k;
	for(int i = 0, tmp; i < k; ++i){
		cin >> tmp;
		d[tmp] = 1;
		}
	for(int i = n, tmp; ; ++i){
		tmp = i;
		while(tmp > 0){
			if(d[tmp % 10]){
				break;
				}
			tmp /= 10;
			if(tmp == 0){
				cout << i;
				return 0;
				}	
			}
		}
	}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n;
  cin>>n;
  vll a(n);
  REP(i,n)cin>>a[i];
  
  ll sum=0;
  REP(i,n)sum+=a[i];
  ld ave=sum*1.0/n;
  
  ll ans=-1;
  ld value = LLINF;
  REP(i,n){
    if(abs(a[i]-ave)<value){
      value=abs(a[i]-ave);
      ans=i;
    }
  }
    

  cout<<ans<<endl;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    COIN = (500, 100, 50)

    v = []
    for i in range(4):
        v.append( int(input()) )
    # v[0]:a, v[1]:b, v[2]:c, v[3]:X
    i, j, count = 0, 0, 0

    while i <= v[0] and i*COIN[0] <= v[3]:
        while j <= v[1] and j*COIN[1] <= (v[3]-i*COIN[0]):
            if v[2]*COIN[2] >= (v[3]-i*COIN[0]-j*COIN[1]):
                count += 1
            j += 1
        j = 0
        i += 1

    print(count)


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    for(int i = 0; i < k; i++){
        if(a < b){
            if(b < c) c *= 2;
            else b *= 2;
        }
        else{
            if(a < c) c *= 2;
            else a *= 2;
        }
    }
    cout << a + b + c << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;

//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
    
    int n,i,w=0,r=0,ans=0;
    cin>>n;
    string s;
    cin>>s;
    for(i=0;i<n;i++)
    {
    	if(s[i]=='R')
    	r++;
    	else
    	w++;
	}
    for(i=0;i<r;i++)
    {
    	if(s[i]=='W')
    	ans++;
	}
	cout<<ans<<endl;
	return 0;
}


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

int main()
   {
     ll n,a,b,i,cnt=0,x,y,aa,bb,cc,dd;
     cin >> a >> b;
     for(i=1;i<=100*(a+b)/8;i++)
     {
         if((i*8)/100==a && (i*10)/100==b)
         {
             cout << i;
             return 0;
         }
     }
     cout << "-1";
     return 0;
   }


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

int main(){
    int n, m, p, a, b;
    while(cin >> n >> m >> p >> a >> b, n+m+p+a+b){
        a--, b--;
        vector<int> t(n);
        for(int i = 0; i < n; i++)  cin >> t[i];
        vector<pair<int,int>> v[m];
        int x, y, z;
        for(int i = 0; i < p; i++){
            cin >> x >> y >> z;
            x--, y--;
            v[x].push_back({y,z});
            v[y].push_back({x,z});
        }
        vector<vector<double>> d(1<<n, vector<double>(m, DBL_MAX));
        // dist, pos, bit
        priority_queue<pair<double, pair<int, int>>> q;
        q.push({-0, {a, 0}});
        double res = DBL_MAX;
        while(!q.empty()){
            auto p = q.top(); q.pop();
            double cost = -p.first;
            int pos = p.second.first, bit = p.second.second;
            if(d[bit][pos] <= cost) continue;
            d[bit][pos] = cost;
            if(pos == b){
                res = cost;
                break;
            }
            for(pair<int,int> next : v[pos]){
                int tmp = next.first;
                double tmpd = next.second;
                for(int j = 0; j < n; j++){
                    if((bit>>j) & 1)    continue;
                    if(d[bit|(1<<j)][tmp] > cost + tmpd/t[j]){
                        q.push({-(cost+tmpd/t[j]), {tmp, bit|(1<<j)}});
                    }
                }
            }
        }
        if(res == DBL_MAX)  cout << "Impossible" << endl;
        else                cout << fixed << setprecision(12) << res << endl;
    }
    return 0;
}


Measured memory_bytes: 15420
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main(){
    char a[1005];
    int k = 0,len;
    while(~scanf("%s",a)){
        printf("%c",a[0]);
    	memset(a,0,sizeof(a));
	}
    return 0;
    }

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,coun=0;
    cin>>n;

    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(i%2==1 && x%2==1)
            coun++;
    }
    cout<<coun<<endl;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

struct UnionFind {
  vector<int> par;
  
  UnionFind(int n) : par(n, -1) { }

  int root(int x) {
      if (par[x] < 0) return x;
      else return par[x] = root(par[x]);
  }
  
  bool issame(int x, int y) {
      return root(x) == root(y);
  }
  
  bool merge(int x, int y) {
      x = root(x); y = root(y);
      if (x == y) return false;
      if (par[x] > par[y]) swap(x, y); // merge technique
      par[x] += par[y];
      par[y] = x;
      return true;
  }
  
  int size(int x) {
      return -par[root(x)];
  }
};

int main() {
  ll N, M; cin >> N >> M;
  vector<ll> A(M), B(M);
  REP(i, M) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
  }
  UnionFind uf(N);
  REP(i, M) {
    uf.merge(A[i], B[i]);
  }
  ll ans = 0;
  REP(i, N) {
    ll res = uf.size(i);
    if(ans < res) ans = res;
  }
  cout << ans << endl;
}

Measured memory_bytes: 7204
import java.util.*;
import java.math.*;
class Main {
    //
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ary = new int[n];
        for(int i = 0;i < n;i++){
            ary[i] = sc.nextInt();
        }
        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(ary[1] - ary[0]);
        for(int i = 2;i < n;i++){
            dp[i] = Math.min(Math.abs(ary[i]-ary[i-1])+dp[i-1], Math.abs(ary[i]-ary[i-2])+dp[i-2]);
        }
        System.out.println(dp[n-1]);
        
    }
}


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

int main(){
    int N;
    cin>>N;
    double value;
    vector<int>V(N);
    for(int i=0;i<N;i++){
        cin>>V[i];
    }
    sort(V.begin(),V.end());
    value=V[0];
    for(int i=1;i<N;i++){
        value=(value+V[i])/2;
    }
    cout<<value<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF 1000000000000000007

typedef long long i64;
typedef pair<i64,i64> P;


int n,m;
P p[101010];

int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		int a,b;
		cin >> a >> b;
		p[i].first = a;
		p[i].second = b;
	}
	sort(p, p+n);
	
	priority_queue<int> pq;
	int ans = 0;
	int j = 0;
	for(int i = 1; i <= m; i++){
		while(j < n && p[j].first <= i){
			pq.push(p[j].second);
			j++;
		}
		if(pq.empty()) continue;
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;
	
	return 0;
}

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

int F[50];

int main(){
  int n;
  cin>>n;
  F[0] = F[1] = 1;
  for(int i=2;i<=44;i++) F[i] = F[i-1]+F[i-2];
  cout<<F[n]<<endl;
  return 0;
}

Measured memory_bytes: 3124
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

using namespace std;
using ll = long long;

#define nextline() (std::cerr << "\n")
#define debug(x) (#x " : " + (x))
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabCout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headCout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabHeadCout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
//#define int long long
constexpr int INF = 2000000100;
constexpr ll DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divUp(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }

/*****/

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

	int cnt = 0;
	for (int i = 1; i <= N; i++)
	{
		if (i % 2 == 1)
		cnt++;
	}

	cout << (double(cnt) / N);

	return 0;
}

/*****/

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

	std::cout << std::fixed << std::setprecision(10);

	Main();

	return 0;
}


Measured memory_bytes: 256
def GaussJordan_mod2(A):
    row=len(A)
    col=len(bin(max(A))[2::])
    rank=0
    for c in reversed(range(col)):
        pivot=-1
        for r in range(rank,row):
            if A[r]&(1<<c):
                pivot=r
                break
        if pivot==-1:
            continue
        A[pivot],A[rank]=A[rank],A[pivot]
        A_rank=A[rank]
        for r in range(row):
            if r!=rank and A[r]&(1<<c):
                A[r]^=A[rank]
        rank+=1
    return A

n=int(input())
A=list(map(int, input().split()))
d=len(bin(max(A)))-2
ans=0
xor_sum=0
for i in range(n):
    xor_sum^=A[i]
for i in range(d):
    bit=xor_sum&(1<<i)
    if bit:
        ans+=bit
        for i in range(n):
            A[i]-=bit&A[i]
J=GaussJordan_mod2(A)
xor=0
for i in range(n):
    xor^=J[i]
print(ans+2*xor)

Measured memory_bytes: 76832
x=input()
x=list(x)
p=0
for i in range(len(x)):
	if x[len(x)-i-1]!=x[i]:
		p=1
if p==0:
	for i in range(((len(x)-1)//2)-1):
		if x[i]!=x[((len(x)-1)//2)-1-i]:
			p=1

if p==0:
	for i in range((len(x)+3),len(x)):
		if x[i]!=x[len(x)-i-1]:
			p=1

if p==0:
	print('Yes')
else:
	print('No')

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

int main() {
	int n, a, p1 = 0, p2 = 0, p4 = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
      	cin >> a;
	    if (a % 4 == 0) p4++;
	    else if (a % 2 == 0) p2++;
	    else p1++;
	}
	if (p4 >= p1) cout << "Yes";
	else if (p1 - p4 == 1 && p2 == 0) cout << "Yes";
	else cout << "No";
	return 0;
}


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

using namespace std;

#define pb push_back

const int maxi = 1e6+10;
string s;
vector<int> v[maxi];
int n;
long long a[maxi];


void dfs(int x, int pred)
{
    a[x]+=a[pred];

    for (int i:v[x])
        if (i!=pred) dfs(i,x);
}
int main()
{
     cin>>n;

     for (int i=1;i<=n;i++)
        scanf("%lld",&a[i]);


    sort(a+1,a+n+1);

    double sum = a[1];
    for (int i=2;i<=n;i++)
      {
          sum += a[i];
          sum/=2.00;
      }

    printf("%.6f",sum);

    return 0;
}
//pisacu joj pisma duga
//iz Zagore iz Drnisa
//razglednice tople s juga
//z Banata poslije Nisa

//ti si sunce moga neba
//tebi mogu reci
//ti si jedina od svih
//koja tajne moje cuva
//ti si moja ljubav prva <3


Measured memory_bytes: 25344
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main()
{
    int N; cin >> N;
    string S; cin >> S;
    int count[26] = {};
    for (char c : S) count[c-'a']++;
    long long ans = 1;
    for (int c : count) {
        ans = ans * (c + 1) % MOD;
    }
    ans = (ans + MOD - 1) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int a[5];
  REP(i,5){
    cin>>a[i];
  }
  int min1 = 10;
  REP(i,5){
    if(a[i]%10!=0){
      min1 = min(min1,a[i]%10);
    }
  }
  int ans = 0;
  REP(i,5){
    ans += (a[i]+9)/10*10;
  }
  ans = ans - 10 + min1;

  cout<<ans<<endl;

 

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	vi v(26);
	REP(i, 26)v[i] = i;
	REP(i, s.size()) {
		if (v[s[i] - 'a'] != t[i] - 'a') {
			REP(j, 26) {
				if (v[j] == t[i] - 'a') {
					swap(v[s[i] - 'a'], v[j]);
				}
			}
		}
	}
	REP(i, s.size())s[i] = v[s[i] - 'a'] + 'a';
	if (s == t)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 916
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
#define int long long
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int N;
  cin>>N;
  int ans=N*(N+1)/2;
  rep(i,N+1)if(i%3==0||i%5==0)ans-=i;
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

ll d[30];

int main() {
    cin >> s;
    string t = "zyxwvutsrqponmlkjihgfedcba";
    if(s==t){
        cout << -1 << endl;
        return 0;
    }
    if(s.size()==26){
        RREP(i,25){
            if(s[i]>s[i+1]){
                continue;
            }else{
                n = i;
                break;
            }
        }
        REP(i,n) {
            d[s[i] - 'a'] = 1;
        }
        REP(i,26) {
            if(d[i]==0&&(s[n]-'a')<i){
                c = i + 'a';
                break;
            }
        }
        cout << s.substr(0, n) << c << endl;
    }else{
        REP(i,s.size()) {
            d[s[i] - 'a'] = 1;
        }
        REP(i,26) {
            if(d[i]==0){
                c = i + 'a';
                break;
            }
        }
        cout << s << c << endl;
    }
}

Measured memory_bytes: 256
# ABC103D_IslandsWar.py

import operator

"""
区画スケジューリング
まず、(ai, bi) の組を bi について昇順にソートし、以下を行う
• 既にその要望を満たしている場合、何もしない
• 要望を満たしていない場合、bi − 1 番目と bi 番目を接続する橋を取り除く

TLE に注意
bridges[-1] == max(bridges), ms[i][0] == min(ms) という事実を使う
ジェネレータ表記は必ずしも使わなくてもよい
"""

n, m = map(int, input().split())
bridges = [0]
ms1 = (tuple(map(int, input().split())) for i in range(m))
ms2 = sorted(ms1, key=operator.itemgetter(1))

for i in range(m):
    if ms2[i][0] <= bridges[-1]:
        pass
    else:
        bridges.append(ms2[i][1] - 1)

if __name__ == "__main__":
    print(len(bridges)-1)    # 0 の分を除く


Measured memory_bytes: 18220
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    long long N; cin >> N;
    map<long long, long long> mp;

    long long sum = 0;
    for (int i = 0; i < N; i++) {
        long long a; cin >> a;
        mp[a]++;
        sum += a;
    }
    int Q; cin >> Q;

    for (int q = 0; q < Q; q++) {
        long long B, C; cin >> B >> C;
        sum -= mp[B] * B;
        sum += mp[B] * C;

        mp[C] += mp[B];

        mp[B] = 0;

        cout << sum << endl;
    }
}


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

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

#define ll long long
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define int long long
#define INF 1e9
#define pii pair<int, int>
#define pt(xx) cout << "\n" \
                    << xx << "\n"
#define debugv(x, n)               \
    cout << "\n"                   \
         << #x << ": ";            \
    rep(i, n) cout << x[i] << " "; \
    cout << endl
#define debug2d(x, m, n)            \
    cout << "\n"                    \
         << #x << " is: \n";        \
    for (int i = 0; i < m; ++i)     \
    {                               \
        for (int j = 0; j < n; ++j) \
        {                           \
            cout << x[i][j] << " "; \
        }                           \
        cout << endl;               \
    }
#define nl cout << endl

#define MOD 1000000007

int N, K,L;
int ans;

/* 
int gcd(int m, int n){
    int tmp;
    while (m%n !)
}
*/
int gcd(int a, int b) {
  if(a < b) return gcd(b, a);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int lcm(int m, int n){
    return (m*n)/gcd(m,n);
}

int cnt(int n, int c, int d, int l){
    int rt = 0;
    rt += n/c;
    rt += n/d;
    rt -= n/l;
    return (n-rt);
}

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

    int A,B,C,D;
    cin>>A>>B>>C>>D;

    int lc = lcm(C,D);


 
    //cout<<cnt(B,C,D,lc)<<endl;
    //cout<<cnt(A,C,D,lc)<<endl;


    if (lc == 1){
        ans = 0;
    }
    else {
    ans = (cnt(B,C,D,lc)-cnt(A-1,C,D,lc) );
    }

    cout<<ans<<endl;


    //cout<<ans<<endl;

    


    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()

def divisors(n):
    S,T=[],[]
    for i in range(1,int(n**.5)+1):
        if(n%i==0):
            S.append(i)
            T.append(n//i)
    T.reverse()
    return S+T if(S[-1]!=T[0]) else S+T[1:]

def resolve():
    n, k = map(int,input().split())
    C = [0] * (k + 1)
    for i in range(1, k + 1):
        C[i] = pow((k // i), n, MOD)

    for i in range(k, 1, -1):
        for d in divisors(i):
            if i == d:
                continue
            C[d] -= C[i]

    res = 0
    for i in range(1, k + 1):
        res += i * C[i]
        res %= MOD

    print(res)
resolve()

Measured memory_bytes: 69956
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int max=0;
    int count=0;
    for(int i=0;i<N;i++){
        int h;
        cin>>h;
        if(h>=max){
            count++;
            max=h;
        }
    }
    cout<<count<<endl;
}


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

int main(void){
   long long N,D;
   cin>>N>>D;
   vector<long long> x(N),y(N);
   for(int i=0;i<N;i++){
      cin>>x[i]>>y[i];
   }
   int ans=0;
   for(int i=0;i<N;i++){
      if(x[i]*x[i]+y[i]*y[i]<=D*D) ans++;
   }
   cout<<ans<<endl;
   return 0;
}


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

using Weight = int;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src_, int dst_, Weight weight_) :
        src(src_), dst(dst_), weight(weight_) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

vector<int> stronglyConnectedComponents(const Graph &g){
    int n = g.size(), sz = 0; Graph rg(n);
    vector<int> stk(n), cmp(n, -1), added(n), visited(n), ord(n);
    for(const Edges &es : g){
        stk.resize(stk.size() + es.size());
        for(const Edge &e : es) rg[e.dst].eb(e.dst, e.src, e.weight);
    }
    for(int i = 0; i < n; i++) if(!visited[i]){
        int s = 0; stk[s++] = i;
        while(s != 0){
            int v = stk[s-1]; visited[v] = true;
            bool pushed = false;
            for(auto & e : g[v]){
                int dst = e.dst;
                if(!visited[dst]){ stk[s++] = dst; pushed = true; }
            }
            if(pushed) continue;
            int t = stk[s-1];
            if(!added[t]){ added[t] = true; ord[sz++] = t; }
            --s;
        }
    }
    int k = 0;
    for(int i = 0; i < n; i++){
        int u = ord[n-i-1];
        if(cmp[u] != -1) continue;
        int s = 0; stk[s++] = u;
        while(s != 0){
            int v = stk[--s]; cmp[v] = k;
            for(auto & e : rg[v]){
                int d = e.dst;
                if(cmp[d] == -1) stk[s++] = d;
            }
        }
        ++k;
    }
    return cmp;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n,m;
    cin >> n >> m;
    Graph g(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        g[a].eb(a,b,0);
    }
    vector<int> c = stronglyConnectedComponents(g);
    int q; cin >> q;
    rep(i,q){
        int a,b;
        cin >> a >> b;
        cout << (c[a]==c[b]) << '\n';
    }
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const long long inf = 0x3f3f3f3f;
int main(){
	//freopen("in.txt","r",stdin);
	long long n,m,x;
	cin>>n>>m>>x;
	long long ans=inf;
	long long dat[n+1][m+1+1];
	for(long long i=0;i<n;i++){
		cin>>dat[i][0];
		for(long long j=1;j<=m;j++) cin>>dat[i][j];
	}
	for(long long i=0;i<=(1<<n)-1;i++){
		long long e[m+1+1]={0};
		long long foo=0;
		for(long long j=0;j<n;j++){
			if(i>>j&1){
				for(long long k=1;k<=m;k++){
					e[k]+=dat[j][k];
				}
				foo+=dat[j][0];
			}
		}
		bool ok=true;
		for(long long i=1;i<=m;i++) if(e[i]<x) ok=false;
		if(ok) ans=min(ans,foo);
		//for(long long i=1;i<=m;i++) cout<<e[i]<<" "; cout<<endl;
	}
	cout<<(ans==inf?-1:ans)<<endl;
	return 0;
}

Measured memory_bytes: 3548
"""E."""

import sys


def input() -> str:  # noqa: A001
    """Input."""
    return sys.stdin.readline()[:-1]


RESULT_TEXT = {
    1: 'pairwise coprime',
    2: 'setwise coprime',
    3: 'not coprime',
}

n = int(input())

a_list = list(map(int, input().split(' ')))

ans = 0

MAX = 1000000 + 1
counts = [0] * MAX
for a in a_list:
    counts[a] += 1

max_count = 0

for i in range(2, MAX):
    max_count = max(max_count, sum(counts[i::i]))

if max_count == n:
    ans = 3
elif max_count >= 2:
    ans = 2
else:
    ans = 1

print(RESULT_TEXT[ans])


Measured memory_bytes: 126884
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
const long long INF = 1LL << 60;
using namespace std;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i,n){
    cin >> h[i];
  }
  int a, b;
  vector <int> x(n);
  rep(i, n){
    x[i] =1;
  }
  rep(i,m){
    cin >> a >> b;
    // if(a != b)x[min(h(a),h(b))] = 0;
    // else x[a] = 0;x[b]=0;
    if(h[a-1] <= h[b-1]){
      x[a-1] = 0;
    }
    if(h[a-1] >= h[b-1]){
      x[b-1] = 0;
    }
  }
  int cnt = 0;
  rep(i,n){
    if(x[i])cnt++;
  }
  cout << cnt << endl;
return 0;
}

Measured memory_bytes: 4028
from itertools import permutations

N=int(input())
P=tuple(input().split(' '))
Q=tuple(input().split(' '))
l = [str(i) for i in range(1,N+1)]
p = permutations(l,N)
a = 0
b = 0
for n,i in enumerate(p):
    if i == P:
        a = n+1
    if i == Q:
        b = n+1
print(abs(a-b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 1e5 + 20;
vector<int> unq;
lint N = 0, n;
int a[MAXN], b[MAXN];
lint tree[MAXN * 2];
inline void clear() {
	rep (i, 0, N) {
		tree[i] = 0;
	}
}
inline void add(int x, int y) {
	x += n + 1;
	while (x <= N) {
		tree[x] += y;
		x += (x & (-x));
	}
}
inline lint query(int x) {
	x += n + 1;
	lint res = 0;
	while (x) {
		res += tree[x];
		x -= (x & (-x));
	}
	return res;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	cin >> n;
	N = n + n + 1;
	rep (i, 1, n) {
		cin >> a[i];
		unq.pb(a[i]);
	}
	sort(all(unq));
	unq.erase(unique(all(unq)), unq.end());
	int l = 0, r = SZ(unq) - 1;
	while (l <= r) {
		int mid = (l + r) >> 1;
		clear();
		rep (i, 1, n) {
			b[i] = b[i - 1] + (unq[mid] <= a[i] ? 1 : -1);
		}
		lint all = 0;
		rep (i, 1, n) {
			add(b[i - 1], 1);
			all += query(b[i]);
		}
		if (all >= (n * (n + 1) / 2 + 1) / 2) {
			l = mid + 1;
		} else {
			r = mid - 1;
		}
	}
	cout << unq[l - 1] << endl;
	return 0;
}

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc129/tasks/abc129_b
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize,
        w: [i32; n]
    };
    let mut s = vec![0; n+1];
    for i in 0..n {
        s[i+1] = s[i] + w[i];
    }

    let mut min_diff = s[n];
    for i in 0..n {
        min_diff = min(min_diff, (s[n]-2*s[i]).abs());
    }
    println!("{}", min_diff);
}


Measured memory_bytes: 4352