akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public final class Main {

    public static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        final int[] arr = fs.readArray(n);
        int max = (int) 1e6;
        final boolean[] seen = new boolean[max + 1];
        boolean pairwiseCoprime = true;
        outer:
        for (int num : arr) {
            final int limit = num;
            for (int p = 2; p * p <= limit; p++) {
                if (num % p == 0) {
                    if (seen[p]) {
                        pairwiseCoprime = false;
                        break outer;
                    }
                    seen[p] = true;
                    while (num % p == 0) {
                        num /= p;
                    }
                }
            }
            if (num > 1) {
                if (seen[num]) {
                    pairwiseCoprime = false;
                    break;
                }
                seen[num] = true;
            }
        }
        if (pairwiseCoprime) {
            System.out.println("pairwise coprime");
            return;
        }
        int gcd = arr[0];
        for (int num : arr) {
            gcd = gcd(gcd, num);
        }
        System.out.println(gcd == 1 ? "setwise coprime" : "not coprime");
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


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

int main() {
    int N;
    cin >> N;
    vector<int>a(N);
    for (int i=0; i<N; i++)cin >> a[i];
    int nax,nin;
    nax = 0;
    nin = 100000000;

    for (int i=0; i<N; i++){
        chmax(nax,a[i]);
        chmin(nin,a[i]);
    }

    cout << nax-nin << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  string S;
  string Q;
  getline(cin, S);
  getline(cin, Q);
  bool rvs = false;
  deque<char> T;
  each(x, S) T.push_back(x);
  rep(i, 0, stoi(Q)) {
    string q;
    getline(cin, q);

    if (q[0] == '1') {
      rvs = !rvs;
    } else {
      if (rvs) {
        q[2] = '1' + !(q[2] - '1');
      }
      if (q[2] == '1') {
        T.push_front(q[4]);
      } else {
        T.push_back(q[4]);
      }
    }
  }
  if (rvs) reverse(all(T));
  each(x, T) {
    cout << x;
  }
}


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

using namespace std;

#define N 5050
#define LL long long

const LL mod=1000000007;
LL n,x,y,sz[N],f[N][N][2],head[N],tot;
struct edge{LL v,nxt;}e[N*2];

void upd(LL &x,LL y){x=(x+y)%mod;}

void add(LL x,LL y){
	e[++tot].v=y; e[tot].nxt=head[x]; head[x]=tot;
}

void dfs(LL u,LL fa){
	sz[u]=1; f[u][1][0]=1;
	for (LL i=head[u],v;i;i=e[i].nxt)
		if ((v=e[i].v)!=fa){
			dfs(v,u);
			for (LL j=sz[u]+sz[v];j>=0;--j){
				int x=f[u][j][0],y=f[u][j][1];
				f[u][j][0]=(f[v][0][0]*x+f[v][0][1]*y)%mod;
				f[u][j][1]=(f[v][0][0]*y+f[v][0][1]*x)%mod;
				for (LL k=max(1LL,j-sz[u]);k<=sz[v]&&k<=j;++k){
					upd(f[u][j][0],f[v][k][0]*f[u][j-k][0]%mod+f[v][k][1]*f[u][j-k][1]%mod);
					upd(f[u][j][1],f[v][k][0]*f[u][j-k][1]%mod+f[v][k][1]*f[u][j-k][0]%mod);
				}
			}
			sz[u]+=sz[v];
		}
	for (LL i=2,t=1;i<=sz[u];i+=2,t=t*(i-1)%mod){
		upd(f[u][0][0],f[u][i][1]*t);
		upd(f[u][0][1],f[u][i][0]*t);
	}
}

int main(){
	scanf("%lld",&n);
	for (LL i=1;i<n;++i){
		scanf("%lld%lld",&x,&y);
		add(x,y); add(y,x);
	}
	dfs(1,0);
	printf("%lld\n",(f[1][0][1]-f[1][0][0]+mod)%mod);
	
	return 0;
}
			

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

using namespace std;

int main(){
    vector<int> a(12);
    for (int i = 0; i < 12; ++i) {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    for (int i = 0; i < 3; ++i) {
        for (int j = 1; j < 4; ++j) {
            if(a[4*i+j]!=a[4*i+j-1]){
                cout<<"no"<<endl;
                return 0;
            }
        }
    }
    cout<<"yes"<<endl;

    return 0;
}


Measured memory_bytes: 3152
#include <iostream>
#include <set>
#include <vector>
#include <iomanip>
#include <deque>

#include <algorithm>

#include <cfenv>
#include <cmath>
typedef long long int ll;

using namespace std;
#include <string>




int main(){


    ll X;

    cin >>X;


    for(int j=-1000;j<=1000;j++){


        for(int i=-1000;i<=1000;i++){



            ll kasu =pow(j,5);
            ll kuzu = pow(i,5);


            if(kasu -kuzu ==X){



                cout << j << ' ' << i << endl;


                return 0;
            }



        }
    }


    return 0;
}

Measured memory_bytes: 4104
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>
#include <cstring>


int main() {
    int x, n; std::cin >> x >> n;
    std::set<int> s;
    for (int i = 0; i < n; i++) {
        int a; std::cin >> a;
        s.insert(a);
    }
    int i = 0;
    while (true) {
        if (!s.count(x - i)) {
            std::cout << x - i << std::endl;
            return 0;
        }
        if (!s.count(x + i)) {
            std::cout << x + i << std::endl;
            return 0;
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<int um> class UF {
	public:
	vector<int> par,rank;
	UF() {rank=vector<int>(um,0); for(int i=0;i<um;i++) par.push_back(i);}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<500000> uf;

int H,W;
string S[404];
int C[404*404][2];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) {
		cin>>S[y];
		FOR(x,W) {
			if((y+x)%2==1) {
				if(S[y][x]=='#') S[y][x]='.';
				else S[y][x]='#';
			}
		}
	}
	
	
	FOR(y,H) FOR(x,W) {
		if(y<H-1 && S[y][x]==S[y+1][x]) uf(y*W+x,(y+1)*W+x);
		if(x<W-1 && S[y][x]==S[y][x+1]) uf(y*W+x,(y+0)*W+x+1);
	}
	
	FOR(y,H) FOR(x,W) C[uf[y*W+x]][(y+x)%2]++;
	
	
	ll ret=0;
	FOR(i,H*W) ret+=1LL*C[i][0]*C[i][1];
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 5744
#include<iostream>
#include<map>
#include<iterator>
#define ll long long int
using namespace std;
int main()
{ll n;
cin>>n;
map<string,ll>a;
for(ll i=0;i<n;i++)
  {string s;
  cin>>s;
  a[s]++;
  }
        cout<<"AC x "<<a["AC"]<<"\n";
		cout<<"WA x "<<a["WA"]<<"\n";
		cout<<"TLE x "<<a["TLE"]<<"\n";
		cout<<"RE x "<<a["RE"]<<"\n";

}

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

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define M 302

int main() {
  int m, a[M], s, g;
  scanf("%d", &m);
  rep(i, 6) scanf("%d", a+i);
  scanf("%d %d", &s, &g); --s; --g;
  int n[M];
  rep(i, m) scanf("%d", &n[i]);

  int prev[M];
  int tod[M];
  int sign[M];

  queue<int> que;
  que.push(s);
  rep(i, m) prev[i] = -1;
  while(!que.empty()) {
    int p = que.front(); que.pop();
    if(p == g) break;
    rep(i, 6) {
      if(0 <= p-a[i]) {
        int nxt = p-a[i];
        nxt += n[nxt];
        if(prev[nxt] == -1) {
          prev[nxt] = p;
          tod[nxt] = i;
          sign[nxt] = -1;
          que.push(nxt);
        }
      }
      if(p+a[i] < m) {
        int nxt = p+a[i];
        nxt += n[nxt];
        if(prev[nxt] == -1) {
          prev[nxt] = p;
          tod[nxt] = i;
          sign[nxt] = 1;
          que.push(nxt);
        }
      }
    }
  }
  vector<int> ss, ds;
  int v = g;
  while(v != s) {
    ds.push_back(tod[v]);
    ss.push_back(sign[v]);
    v = prev[v];
  }
  int c = ds.size() - 1;
  while(c >= 0) {
    int dice;
    scanf("%d", &dice);
    if(dice-1 == ds[c]) {
      printf("%d\n", ss[c]);
      --c;
    } else {
      printf("0\n");
    }
    fflush(stdout);
  }

  return 0;
}

Measured memory_bytes: 1312
import sys
sys.setrecursionlimit(10 ** 6)
ans = []

def dfs(i):
    if 10 < len(i):
        return

    ans.append(int(i))
    if 0 < int(i[-1]):
        dfs(i + chr(ord(i[-1]) - 1))
    if int(i[-1]) < 9:
        dfs(i + chr(ord(i[-1]) + 1))
    dfs(i + i[-1])


K = int(input())
for i in range(1, 10):
    dfs(str(i))
ans.sort()
#print(ans.sort())
# print(ans)
print(ans[K-1])

Measured memory_bytes: 68440
from collections import defaultdict
N = int(input())
Ss = [input() for _ in range(N) ]
di  ={}
for s in Ss:
    if s not in di:
        di[s] = 1
    else:
        di[s] += 1

di = sorted(di.items(),key= lambda x:(-x[1],x[0]) )
# print(di)
key = di[0][1]
for temp in di:
    k,v = temp
    if key == v:
        print(k)

Measured memory_bytes: 59380
from collections import deque

h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]

root = [[float("inf") for _ in range(w)] for _ in range(h)]
root[0][0] = 1
D = deque([[0, 0]])
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

while D:
    p = D.popleft()

    if p == [h-1, w-1]:
        break

    for i in range(4):
        x = p[0]+dx[i]
        y = p[1]+dy[i]
        if 0<=x<=h-1 and 0<=y<=w-1 and root[x][y]==float("inf") and maze[x][y]==".":
            root[x][y] = root[p[0]][p[1]] + 1
            D.append([x, y])

white = 0
for i in range(h):
    for j in range(w):
        if maze[i][j]==".":
            white += 1

if root[h-1][w-1] ==float("inf"):
    print(-1)
else:
    print(white - root[h-1][w-1])

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

int main() {
    long long X, Y, Z;
    cin >> X >> Y >> Z;
    for (int i = 50000; i >= 0; i--) {
        if (X >= Y * i + Z * (i + 1)) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n= int(sys.stdin.readline())
    S= list(map(int, sys.stdin.readline().split()))
    q= int(sys.stdin.readline())
    T= list(map(int, sys.stdin.readline().split()))
    c=0
    for i in T:#リストTの値をターゲットにする
        left = 0#左端のindex
        right =len(S)-1#右端のindex
        while left <= right:#探索範囲が存在する限り
            center = (left+right)//2#切り捨て
            if i == S[center]:
                c+=1
                break
            elif i > S[center]:#中心よりターゲットが大きい時
                left = center+1#中心以下を切り捨て
            elif i < S[center]:
                right = center -1#
    print(c)





Measured memory_bytes: 17900
input_lines = readlines.map(&:chomp)
N, A, B = input_lines.shift.split(' ').map(&:to_i)
SS = input_lines.shift.split('')

#
passed = []
foreigner_passed = []
results = SS.map.with_index(1) do |s, index|
  case s
    when 'a'
      # 国内の学生は、現在予選の通過が確定した参加者がA+B人に満たなければ、予選を通過する
      if passed.size < A + B
        passed << index
        "Yes"
      else
        "No"
      end
    when 'b'
      # 海外の学生は、現在予選の通過が確定した参加者がA+B人に満たず、
      # さらに海外の学生の中での順位がB位以内なら、予選を通過する
       if passed.size < A + B && foreigner_passed.size < B
        passed << index
         foreigner_passed << index
        "Yes"
      else
        "No"
      end
    when 'c'
      "No"
    else
      rais "#{s}は存在しない"
  end
end

puts results

Measured memory_bytes: 17532
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int k,x;
  cin>>k>>x;
  for(int i=x-k+1;i<=x+k-1;i++) {
    cout << i << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
#define _GLIBCXX_DEBUG

using namespace std;


int main() {
    int n,a;
    cin >> n;
    map<int,int> m;
    bool ans = false;
    rep(i, n) {
        cin >> a;
        m[a] += 1;
    }
    for (auto itr = m.begin(); itr != m.end(); itr++) {
        if (itr->second >= 2) {
            ans = true;
        }
    }
    if (ans == true) {
        cout << "NO"<<endl;
    }
    else {
        cout << "YES" << endl;
    }
}


Measured memory_bytes: 9600
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=2005;

int gcd(int a,int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}

int n,A[MAXN];
bool vis[MAXN];
vector<int> adj[MAXN],adj2[MAXN];
int deg[MAXN],ans[MAXN];
priority_queue<int> Q;

void dfs(int u)
{
	vis[u]=true;
	for(int i=0;i<(int)adj[u].size();i++)
	{
		int v=adj[u][i];
		if(vis[v])
			continue;
		adj2[u].push_back(v);
		deg[v]++;
		dfs(v);
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&A[i]);
	sort(A+1,A+n+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i!=j&&gcd(A[i],A[j])>1)
				adj[i].push_back(j);
	for(int i=1;i<=n;i++)
		if(!vis[i])
			dfs(i);
	
	for(int i=1;i<=n;i++)
		if(deg[i]==0)
			Q.push(i);
	int it=0;
	while(!Q.empty())
	{
		int u=Q.top();
		ans[++it]=A[u];
		Q.pop();
		for(int i=0;i<(int)adj2[u].size();i++)
		{
			int v=adj2[u][i];
			deg[v]--;
			if(deg[v]==0)
				Q.push(v);
		}
	}
	
	for(int i=1;i<n;i++)
		printf("%d ",ans[i]);
	printf("%d\n",ans[n]);
	
	return 0;
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct UF{
    int n;
    //正だったらその頂点の親,負だったら根で連結成分の個数
    vector<int> d;
    UF() {}
    UF(int N):n(N), d(N,-1){}
    int root(int v){
        if(d[v]<0) return v;
        return d[v]=root(d[v]);
    }
    bool unite(int X,int Y){
        X=root(X); Y=root(Y);
        if(X==Y) return false;
        if(size(X) < size(Y)) swap(X,Y);
        d[X]+=d[Y];
        d[Y]=X;
        return true;
    }
    int size(int v){ return -d[root(v)]; }
    bool same(int X,int Y){ return root(X)==root(Y); }
};

int main()
{
    int n;
    cin >>n;
    vector<int> x(n),y(n);
    rep(i,n) cin >>x[i] >>y[i];

    vector<int> sx,sy;
    map<int,vector<int>> mx,my;

    rep(i,n)
    {
        sx.pb(x[i]);
        mx[x[i]].pb(i);
        sy.pb(y[i]);
        my[y[i]].pb(i);
    }

    sort(all(sx));
    sx.erase(unique(all(sx)),sx.end());
    sort(all(sy));
    sy.erase(unique(all(sy)),sy.end());
    int SX = sx.size(), SY = sy.size();

    ll ans = 0;
    UF uf(n);
    rep(i,SX)
    {
        vector<int> v = mx[sx[i]];
        int V = v.size();
        rep(j,V-1) uf.unite(v[j],v[j+1]);
    }
    rep(i,SY)
    {
        vector<int> v = my[sy[i]];
        int V = v.size();
        rep(j,V-1) uf.unite(v[j],v[j+1]);
    }

    using P = pair<int,pair<int,int>>;
    vector<P> d;
    rep(i,SX-1) d.pb({sx[i+1]-sx[i],{sx[i],sx[i+1]}});
    rep(i,SY-1) d.pb({sy[i+1]-sy[i],{-sy[i],-sy[i+1]}});
    sort(all(d));
    rep(i,d.size())
    {
        pair<int,int> p=d[i].se;

        int v,u;
        if(p.fi+p.se>=0)
        {
            v=mx[p.fi][0];
            u=mx[p.se][0];
        }
        else
        {
            v=my[-p.fi][0];
            u=my[-p.se][0];
        }

        if(!uf.same(v,u))
        {
            uf.unite(v,u);
            ans += d[i].fi;
        }
    }

    assert(uf.size(0)==n);
    cout << ans << endl;
    return 0;
}


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

int arr[305][305], N, M, cnt[305], ans; 
bool del[305];

int main() {
	cin >> N >> M; ans = N;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= M; ++j) cin >> arr[i][j];
		++cnt[arr[i][1]];
	}
	for (int i = 1; i <= M; ++i) {
		int mx = 0;
		for (int j = 1; j <= M; ++j) mx = max(mx, cnt[j]);
		ans = min(ans, mx);
		
		for (int j = 1; j <= M; ++j) if (mx == cnt[j]) { del[j] = 1; break; }
		
		memset(cnt, 0, sizeof(cnt));
		for (int j = 1; j <= N; ++j) for (int k = 1; k <= M; ++k) if (!del[arr[j][k]]) { ++cnt[arr[j][k]]; break; }
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int main(){
	string s;
	cin >> s;
	if(s[5]-'0'>0||s[6]-'0'>4)cout << "TBD" << endl;
	else cout << "Heisei" << endl;
	return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    string ls, ms, rs;
    int left = 0, right = n-1;
    cout << left << endl;
    cin >> ls;
    cout << right << endl;
    cin >> rs;

    rep(hoge, 20) {
        int mid = (right + left) / 2;
        //cout << left << " " << mid << " " << right << endl;
        //cout << ls << " " << ms << " " << rs << endl;
        cout << mid << endl;
        cin >> ms;
        if ((mid - left + 1) % 2) {
            if (ls == ms) {
                ls = ms;
                left = mid;
            } else {
                rs = ms;
                right = mid;
            }
        } else {
            if (ls == ms) {
                rs = ms;
                right = mid;
            } else {
                ls = ms;
                left = mid;
            }
        }
    }

    return 0;
}







Measured memory_bytes: 852
//
// Noszály Áron 9a Debreceni Fazekas Mihály Gimnázium
//
#include<bits/stdc++.h>
#include<cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;

#define all(s) (s).begin(),(s).end()
#define pb push_back
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define INF std::numeric_limits<int>::max()
#define MINF std::numeric_limits<int>::min()
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define mp make_pair
#define xx first
#define yy second
#define sz(x) (int)(x).size()

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

const long double PI = acos(-1);

int d1[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int d2[8][2]={{1,0},{0,1},{0,-1},{-1,0},{1,1},{-1,1},{1,-1},{-1,-1}};

int main()
{
	IO;
	int n;cin>>n;
	int a[n];
	for(int i=0;i<n;++i)
	{
		cin>>a[i];
	}
	
	int ans=INF;
	for(int e=-100;e<=100;++e)
	{
		int cost=0;
		for(int i=0;i<n;++i)
		{
			cost+=(a[i]-e)*(a[i]-e);
		}
		ans=min(ans,cost);
	}
	cout<<ans<<"\n";
	return 0;
	
}



Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    ll n;
    cin >> n;
    string ans;
    ll kai = 0;
    while(n){
      kai++;
        n--;	
        ans+='a'+n%26;
        n/=26;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}
    



Measured memory_bytes: 3628
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int N, M, S, T, U, V;
vector<pair<int, LL>> edge[100000];
LL C[200000];

LL cost[100000][3]; //from S, U, V

void dijkstra(){
	for(int i=0; i<N; i++){
		for(int j=0; j<3; j++){
			cost[i][j] = LLONG_MAX;
		}
	}
	priority_queue<pair<LL,pair<int,int>>> que;
	cost[S][0] = 0;
	cost[U][1] = 0;
	cost[V][2] = 0;
	que.push({ 0,{S,0} });
	que.push({ 0,{U,1} });
	que.push({ 0,{V,2} });
	while(!que.empty()){
		LL c = -que.top().first;
		int v = que.top().second.first;
		int s = que.top().second.second;
		que.pop();
		for(int i=0; i<edge[v].size(); i++){
			int n = edge[v][i].first;
			LL w = edge[v][i].second;
			if(cost[n][s] > c + w){
				cost[n][s] = c + w;
				que.push({ -cost[n][s],{n,s} });
			}
		}
	}
}
/*
vector<pair<LL, int>> vec;
void bfs(){
	bool visited[100000] ={};
	priority_queue<pair<LL, int>> que;
	que.push({ cost[T][0],T });
	visited[T] = true;
	while(!que.empty()){
		LL c = -que.top().first;
		int v = que.top().second;
		que.pop();
		vec.PB({ c,v });
		for(int i=0; i<edge[v].size(); i++){
			int n = edge[v][i].first;
			LL w = edge[v][i].second;
			if(visited[n]) continue;
			if(cost[n][0] + w == c){
				visited[n] = true;
				que.push({ cost[n][0],n });
			}
		}
	}
	sort(vec.begin(), vec.end());
}*/

LL dp[100000][3];
bool visited[100000] = {};
void solve(int v){
	if(visited[v]) return;
	visited[v] = true;
	LL c = cost[v][0];
	dp[v][0] = cost[v][1];
	dp[v][1] = cost[v][2];
	dp[v][2] = cost[v][1] + cost[v][2];
	for(int i=0; i<edge[v].size(); i++){
		int n = edge[v][i].first;
		LL w = edge[v][i].second;
		if(cost[n][0] + w == c){
			solve(n);
			dp[v][0] = min(dp[v][0], dp[n][0]);
			dp[v][1] = min(dp[v][1], dp[n][1]);
			dp[v][2] = min(dp[v][2], dp[n][2]);
			dp[v][2] = min(dp[v][2], dp[n][0] + cost[v][2]);
			dp[v][2] = min(dp[v][2], dp[n][1] + cost[v][1]);
		}
	}
}

int main(){
	cin >> N >> M >> S >> T >> U >> V;
	S--; T--; U--; V--;
	for(int i=0; i<M; i++){
		int A, B;
		LL C;
		cin >> A >> B >> C;
		A--; B--;
		edge[A].PB({ B,C });
		edge[B].PB({ A,C });
	}

	dijkstra();

	solve(T);
	cout << min(cost[V][1], dp[T][2]) << endl;
}


Measured memory_bytes: 25840
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define sz size()
#define vec vector<int>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, bool isFront) {
	if (first_itr < 0 || first_itr > str.size()) {
		return str;
	}
	else {
		if (isFront) {
			std::string tmp;
			for (size_t i = 0; i < first_itr; i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
		else {
			std::string tmp;
			for (size_t i = first_itr; i < str.size(); i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
	}
}


bool dfs(int depth, int now) {
	/*if (depth == n)return !now;
	for (int i = 0; i < k; i++) {
		if (dfs(depth + 1, now ^ t[depth][i]))return true;
	}
	/**/
	return false;
}



int main() {
	str s, t; cin >> s >> t;
	cout << t << s << endl;




	return 0;
}

Measured memory_bytes: 764
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;



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

	cin >> H >> W;
	vector<string>s(H);
	for (auto &i : s)cin >> i;
	vector<vector<int>>adis(H, vector<int>(W, MOD));
	vector<vector<int>>bdis(H, vector<int>(W, MOD));
	vector<vector<int>>cdis(H, vector<int>(W, MOD));
	queue<pair<int, int>>Q;
	int dir[] = { 1,0,-1,0,1 };
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '@') {
				Q.emplace(i, j);
				adis[i][j] = 0;
			}
		}
	}
	while (!Q.empty()) {
		int cy, cx;
		tie(cy, cx) = Q.front();
		Q.pop();
		for (int i = 0; i < 4; i++) {
			int ny = cy + dir[i];
			int nx = cx + dir[i + 1];
			if (ny < 0 || nx < 0 || ny >= H || nx >= W)continue;
			if (s[ny][nx] == '#')continue;
			if (adis[ny][nx] > adis[cy][cx] + 1) {
				adis[ny][nx] = adis[cy][cx] + 1;
				Q.emplace(ny, nx);
			}
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '$') {
				Q.emplace(i, j);
				bdis[i][j] = 0;
			}
		}
	}
	while (!Q.empty()) {
		int cy, cx;
		tie(cy, cx) = Q.front();
		Q.pop();
		for (int i = 0; i < 4; i++) {
			int ny = cy + dir[i];
			int nx = cx + dir[i + 1];
			if (ny < 0 || nx < 0 || ny >= H || nx >= W)continue;
			if (s[ny][nx] == '#')continue;
			if (bdis[ny][nx] > bdis[cy][cx] + 1) {
				bdis[ny][nx] = bdis[cy][cx] + 1;
				Q.emplace(ny, nx);
			}
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '@') {
				Q.emplace(i, j);
				cdis[i][j] = 0;
			}
		}
	}
	while (!Q.empty()) {
		int cy, cx;
		tie(cy, cx) = Q.front();
		Q.pop();
		for (int i = 0; i < 4; i++) {
			int ny = cy + dir[i];
			int nx = cx + dir[i + 1];
			if (ny < 0 || nx < 0 || ny >= H || nx >= W)continue;
			if (s[ny][nx] == '#')continue;
			if (adis[ny][nx] >= bdis[ny][nx])continue;
			if (cdis[ny][nx] > cdis[cy][cx] + 1) {
				cdis[ny][nx] = cdis[cy][cx] + 1;
				Q.emplace(ny, nx);
			}
		}
	}
	int ans = MOD;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '%') {
				ans = cdis[i][j];
			}
		}
	}
	if (ans == MOD)cout << "No\n";
	else cout << "Yes\n";
}


Measured memory_bytes: 3940
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

vector<int> cnt[26];

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

	string s, t;
	cin >> s >> t;

	int n = s.size();
	for (int i = 0; i < n; i++) {
		int k = s[i] - 'a';
		cnt[k].push_back(i);
	}

	int pos = -1;
	long long ans = 0;
	for (char c : t) {
		int k = c - 'a';
		if (cnt[k].size() == 0) {
			cout << "-1\n";
			return 0;
		}
		auto it = upper_bound(cnt[k].begin(), cnt[k].end(), pos);
		if (it == cnt[k].end()) {
			it = cnt[k].begin();
			ans += n;
		}
		ans += *it - pos;
		pos = *it;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1216
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>

#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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



int main(void) {
	ll i, j, k, ans = 0, cnt = 0, N, tmp, at;
	ll ma = 0;
	
	scanf("%lld", &N);
	scanf("%lld", &tmp);
	for (i = 0; i < N - 1; i++) {
		scanf("%lld", &at);
		if (tmp >= at) {
			cnt++;
			tmp = at;
			ma = max(ma, cnt);
		}
		else {
			tmp = at;
			cnt = 0;
		}
	}
	printf("%lld", ma);

	return 0;
}

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

const int m = 2019;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  reverse(s.begin(), s.end());
  int x = 1, tot = 0;
  vector<int> cnt(m);
  ll ans = 0;
  rep(i, n) {
    cnt[tot]++;
    tot += (s[i] - '0') * x;
    tot %= m;
    ans += cnt[tot];
    x = x * 10 % m;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3704
n = int(input())

x = list(map(int, input().split()))

min_hp = 0
sum_hp = 0

for i in range(n):
    sum_hp += (x[i]-1)**2
min_hp = sum_hp

sum_hp = 0
for i in range(2,max(x)+1):
    for j in range(n):
        sum_hp += (x[j]-i)**2
    if min_hp > sum_hp:
        min_hp = sum_hp
    sum_hp = 0
 
print(min_hp)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    ll ar[n+1];
    ar[n]=10000000007;
    for(ll i=0;i<n;i++)
    cin>>ar[i];
    ll maxi=0,l=0;
    for(ll i=0;i<n;i++)
    {
        if(ar[i]>=ar[i+1])
        l++;
        else
        {
            if(l>maxi)
            maxi=l;
            l=0;
        }
    }
    cout<<maxi<<endl;
}

Measured memory_bytes: 1024
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

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

    
}
  
  
sort(a, a + n, greater<int>()); 
int sum = 0;
  
for(int i = 0;i<n;i++){
     
  if(i==0){
    
    sum = a[i]/2;
  }else{
    
    sum = sum+a[i];
  }
  // cin >> a[n];
   
  
}
  cout << sum << endl;
  return 0;
}

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

using namespace std;

#define ll long long int
#define fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)




void solve(){
	ll n;
	cin>>n;
	ll p[n],q[n];
	for(ll i=0;i<n;i++){
		cin>>p[i];
	}
	for(ll i=0;i<n;i++){
		cin>>q[i];
	}
	ll arr[n];
	for(ll i=1;i<=n;i++){
		arr[i-1]=i;
	}
	ll a=0,b=0;
	ll cc=1;
	do{
		bool flag=true;
		for(ll i=0;i<n;i++){
			if(arr[i]!=p[i]){
				flag=false;
				break;
			}
		}
		if(flag){
			a=cc;
		}
		flag=true;
		for(ll i=0;i<n;i++){
			if(arr[i]!=q[i]){
				flag=false;
				break;
			}
		}
		if(flag){
			b=cc;
		}
		cc+=1;
	}while(next_permutation(arr,arr+n));
	ll ans=abs(a-b);
	cout<<ans<<"\n";
}
int main(){
	fast;
	int t=1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) cin >> s.at(i);
  int M;
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++) cin >> t.at(i);
  int score = 0;
  for (int i = 0; i < N; i++) {
    string target = s.at(i);
    int count = 0;
    for (int j = 0; j < N; j++) {
      if (target == s.at(j)) count++;
    }
    for (int j = 0; j < M; j++) {
      if (target == t.at(j)) count--;
    }
    if (count > score) score = count;
  }
  cout << score;
}


Measured memory_bytes: 3620
def bin_search(x,v):
    if x<=v[0]:
        return v[0]
    elif x>=v[-1]: return v[-1]
    l = 0
    r = len(v)
    while l+1<=r:
        i = (l+r)//2
        if v[i]<=x and x<=v[i+1]:
            if x-v[i] >= v[i+1]-x:
                return v[i+1]
            else: return v[i]
        elif v[i]>x: r=i
        else: l=i
    return False

n = int(input())
v = list(map(int,input().split()))
v.sort()

print(v[-1],bin_search(v[-1]/2,v[:-1]))

Measured memory_bytes: 14428
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())
pf = factorization(n)
cnt = 0
for p in pf:
    i = 1
    while True:
        if p[0] == 1:
            break
        n /= p[0]**i
        p[1] -= i
        cnt += 1
        i += 1
        if p[1] < i:
            break

print(cnt)

Measured memory_bytes: 9500
N = int(input())
cities = {}
citylist = []
for i in range(1,N+1):
    s,p = map(str,input().split())
    if s in cities:
        cities[s].append([int(p),i])
    else:
        cities[s] = [[int(p),i]]
        citylist.append(s)

citylist.sort()
for city in citylist:
    cities[city].sort(reverse = True)
    for j in range(len(cities[city])):
        print(cities[city][j][1])
    

Measured memory_bytes: 9044
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;


#[fastout]
fn solve() {
    const MOD: usize = 1_000_000_007;
    const INF: usize = std::usize::MAX;
    
    input!{
        x: isize,
        a: isize,
        b: isize,
    }

    let ans = if b <= a {
        "delicious"
    } else if b - a <= x {
        "safe"
    } else {
        "dangerous"
    };

    println!("{}", ans);
}

fn main() {
    solve()
}

#[cfg(test)]
mod test {
    use super::solve;
}


Measured memory_bytes: 2092
import sys
input = sys.stdin.readline

n = int(input())
robots = [tuple(map(int, input().split())) for _ in range(n)]
robots.sort(key=(lambda robo: robo[0] + robo[1]))

z = -float('inf')
ans = 0
for x, l in robots:
    if z <= x - l:
        ans += 1
        z = x + l

print(ans)


Measured memory_bytes: 26932
#include<bits/stdc++.h>
using namespace std;
long long l,ll,g,gg;
string a,b,s; 
int main()
{
    cin>>a>>b;
    l=a.size();
    ll=b.size();
    for(int i=0;i<l+ll;i++)
    {
    	if(i%2==0)
    	{
    		cout<<a[g++];
    	}
    	else
    	{
    		cout<<b[gg++];
    	}
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
void myInit();
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int MOD = 1000000007;
const int N = 3e5, M = N;
//=========TQR==============
vi g[N];
int a[N];

int main() {
	myInit();
	FIO;
	int x, y;
	float c;
	cin >> x >> y;
	c = floor((4 * x - y) / 2.0);
	if (c >= 0 && (4 * x - y) / 2.0 == c) {
		if (y - 2 * x >= 0)
			cout << "Yes\n";
		else
			cout << "No\n";
	}
	else
		cout << "No\n";
	return 0;
}

void myInit() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int mpow(int base, int exp) {
	base %= MOD;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = ((ll)result * base) % MOD;
		base = ((ll)base * base) % MOD;
		exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m) {
	int i, u, v;
	while (m--) {
		cin >> u >> v;
		g[u - 1].pb(v - 1);
		g[v - 1].pb(u - 1);
	}
}

void dfs(int u, int par) {
	for (int v : g[u]) {
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 10660
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=2e5;
typedef ll fuko[yuzu|10];
fuko a,b;int n;

void merge_sort(ll *a,ll mod){
int pos=n+1,i;
for (i=1;i<=n;++i){
  if (pos>n&&a[i]>=mod) pos=i;
  a[i]&=mod-1;
  }inplace_merge(a+1,a+pos,a+n+1);
}

int get(ll x){
ll ans=0;int i,kp=n;
for (i=1;i<=n;++i){
  for (;kp>0&&a[i]+b[kp]>=x;--kp);
  ans+=n-kp; 
  }return ans&1;
}

int main(){
int i,j;
for (int t=1,zxy=0;t--;){
  n=read();
  for (i=1;i<=n;++i) read(a[i]);
  for (i=1;i<=n;++i) read(b[i]);
  sort(a+1,a+n+1),sort(b+1,b+n+1);
  ll ans=0;
  for (i=61;~i;--i){
    merge_sort(a,2ll<<i),merge_sort(b,2ll<<i);
    ans|=(get(1ll<<i)^get(2ll<<i)^get(3ll<<i))<<i;
    }
  //printf("Case #%d: ",++zxy);
  write(ans),pl;
  }
}

Measured memory_bytes: 4212
#include<stdio.h>
int main(void){
    for(;;){
        int N,i,j,k,A=0,B=0;
        scanf("%d",&N);
        if(N==0){
            break;
        }
        int a[N],b[N];
        for(i=0;i<N;i++){
            scanf("%d%d",&a[i],&b[i]);
        }
        for(i=0;i<N;i++){
            if(a[i]>b[i]){
                A=A+a[i];
                A=A+b[i];
            }
            else if(a[i]<b[i]){
                B=B+a[i];
                B=B+b[i];
            }
            else{
                A=A+a[i];
                B=B+b[i];
            }
        }
        printf("%d %d\n",A,B);
    }
return 0;
}

Measured memory_bytes: 676
#include <stdio.h>

int main(int argc, char* argv[])
{
	int N;
	char A[101];
	char B[101];
	char C[101];
	scanf("%d %s %s %s", &N, A, B, C);
	//printf("%d %s %s %s\n", N, A, B, C);

	int count = 0;
	for (int n = 0; n < N; n++) {
		int a = A[n];
		int b = B[n];
		int c = C[n];
		//printf("%d : %d %d %d\n", n, a, b, c);
		if (a == b) {
			if (a == c) {
				count += 0;
			}
			else {
				count += 1;
			}
		}
		else {
			if (a == c) {
				count += 1;
			}
			else {
				if (b == c) {
					count += 1;
				}
				else {
					count += 2;
				}
			}
		}
	}

	printf("%d\n", count);

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,k;
int a[252];
// pos, xor
int dp[252][830];

int main(){
  scanf("%d%d",&n,&k);
  REP(i,n)scanf("%d",a+i);
  REP(i,n+1)REP(j,256)dp[i][j] = 0;
  dp[0][0] = 1;
  REP(i,n){
    int x = a[i];
    FORR(key,0,n)REP(y,256){
      dp[key+1][x^y] = (dp[key+1][x^y] + dp[key][y]) % MOD;
    }
  }
  ll fact = 1;
  ll ans = 0;
  FOR(key,1,n+1){
    fact = fact*key%MOD;
    ans = (ans + fact*dp[key][k]%MOD)%MOD;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 640