akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int N;
int main()
{
	while(true){
		scanf("%d",&N);
		if(N==0)return 0;
		int X[30][6];
		for(int i=0;i<N;i++){
			for(int j=0;j<6;j++){
				string SS;
				cin >> SS;
				if(SS=="Cyan")X[i][j]=0;
				if(SS=="Yellow")X[i][j]=1;
				if(SS=="Red")X[i][j]=2;
				if(SS=="Magenta")X[i][j]=3;
				if(SS=="Green")X[i][j]=4;
				if(SS=="Blue")X[i][j]=5;
			}
		}
		int cou=0;
		for(int i=0;i<N;i++){
			bool F=true;
			for(int j=i+1;j<N;j++){
				//equal->false
				for(int k=0;k<6;k++){
					for(int l=0;l<4;l++){
						bool FF=false;
						for(int m=0;m<6;m++){
							//if(i==0&&j==1)printf("%d ",X[i][m]);
							if(X[i][m]!=X[j][m])FF=true;
						}
						//if(i==0&&j==1)printf("\n");
						if(!FF)F=false;
						int t=X[i][1];
						X[i][1]=X[i][2];
						X[i][2]=X[i][4];
						X[i][4]=X[i][3];
						X[i][3]=t;
					}
					if(k==0){
						int t=X[i][0];
						X[i][0]=X[i][1];
						X[i][1]=X[i][5];
						X[i][5]=X[i][4];
						X[i][4]=t;
					}
					if(k==1){
						int t=X[i][0];
						X[i][0]=X[i][2];
						X[i][2]=X[i][5];
						X[i][5]=X[i][3];
						X[i][3]=t;
					}
					if(k==2){
						int t=X[i][2];
						X[i][2]=X[i][3];
						X[i][3]=t;
						t=X[i][5];
						X[i][5]=X[i][0];
						X[i][0]=t;
					}
					if(k==3){
						int t=X[i][0];
						X[i][0]=X[i][3];
						X[i][3]=X[i][5];
						X[i][5]=X[i][2];
						X[i][2]=t;
					}
					if(k==4){
						int t=X[i][0];
						X[i][0]=X[i][1];
						X[i][1]=X[i][5];
						X[i][5]=X[i][4];
						X[i][4]=t;
					}
					
				}
			}
			if(F)cou++;
		}
		printf("%d\n",N-cou);
	}
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

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

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

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

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }
#define dump(...) cout<<#__VA_ARGS__<<": [L_"<<__LINE__<<"]"<<'\n'; print(__VA_ARGS__);cout<<'\n';

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

inline bool is_prime(long long x) {
  if (x <= 1) return false;
  for (long long i = 2; i*i <= x; ++i) if (x % i == 0) return false;
  return true;
}

int main() {
  int x; cin>>x;
  REP(i, x, 1000000) {
    if (is_prime(i)) {
      print(i);
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ks = []
for i in range(m):
    ks.append(list(map(int, input().split())))
p = list(map(int, input().split()))

ans = 0
for i in range(2**n):
    switch = [int(bin(i+2**n)[j+3]) for j in range(n)]
    condition = []
    for k in range(m):
        num = 0
        for l in range(ks[k][0]):
            if switch[ks[k][l+1]-1]:
                num += 1
        if num % 2 == p[k]:
            condition.append(True)
        else:
            condition.append(False)
    flag = 1
    for x in range(m):
        flag *= condition[x]
    if flag == True:
        ans += 1
print(ans)

Measured memory_bytes: 3188
# ABC142D - Disjoint Set of Common Divisors
def gcd(x: int, y: int) -> int:
    while y:
        x, y = y, x % y
    return x


def prime_factorization(x: int) -> dict:
    max_prime, ret = 0, {}

    # Divide x by 2 as much as possible
    cnt = 0
    while x % 2 == 0:
        x //= 2
        cnt += 1
    if cnt > 0:
        max_prime = 2
        ret[max_prime] = cnt

    # x must be odd -> skip even numbers
    cnt = 0
    for i in range(3, int(x ** 0.5) + 1, 2):
        cnt = 0
        while x % i == 0:
            x //= i
            max_prime = i
            cnt += 1
        if cnt > 0:
            ret[max_prime] = cnt

    if x > 2:  # To handle the case when x is prime greater than 2
        max_prime = x
        ret[max_prime] = 1
    return ret


def main():
    # compute the number of common prime factors
    A, B = map(int, input().split())
    g = gcd(A, B)
    ans = len(prime_factorization(g).keys()) + 1
    print(ans)


if __name__ == "__main__":
    main()

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

long double n, k, ans=0;

int main() {
	cin >> n >> k;

	for (int i = 1; i <= n; ++i)
	{
		ans += 1.0/powl(2.0, ceill(log2l(ceill(k/i))));
	}

	cout << fixed << setprecision(9) <<  ans/n << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int selectionSort(int *a, int n) {
  int counter = 0;
  for (int i = 0; i < n; i++) {
    int minj = i;
    for (int j = i; j < n; j++) {
      if (a[j] < a[minj]) minj = j;
    }
    if (a[i] > a[minj]) {
      swap(a[i], a[minj]);
      counter++;
    }
  }
  return counter;
}

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

  int counter;
  counter = selectionSort(a, n);

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



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

int main(){
  int N;
  long long W;
  cin >> N >> W;
  long long v[110], w[110];
  for(int i=0; i<N; i++)  cin >> w[i] >> v[i];
  
  
  long long dp[110][100010];
  
  for(int i=0; i<N; i++){
    for(int j=0; j<=W; j++){
      if(j-w[i]>=0)  dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
      else  dp[i+1][j] = dp[i][j];
    }
  }
  
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 80384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll INFll = 1LL << 60;
typedef pair<long, long> PL;
struct Edge {
  ll to;
  ll cost;
};
/* dijkstra(G,s,dis)
    入力：グラフ G, 開始点 s, 距離を格納する dis
    計算量：O(|E|log|V|)
    副作用：dis が書き換えられる,負のコストの際利用できない
*/
void dijkstra(const vector<vector<Edge>> &G, int s, vector<ll> &dis) {
  int N = G.size();
  dis.resize(N, INFll);
  priority_queue<PL, vector<PL>, greater<PL>>
      pq;  //「仮の最短距離、頂点」が小さい順にならぶ
  dis[s] = 0;
  pq.emplace(dis[s], s);
  while (!pq.empty()) {
    PL p = pq.top();
    pq.pop();
    int v = p.second;
    if (dis[v] < p.first) continue;  //最短経路でなければ無視
    for (auto &e : G[v]) {
      if (dis[e.to] > dis[v] + e.cost) {  //最短距離候補ならpriority_queueに追加
        dis[e.to] = dis[v] + e.cost;
        pq.emplace(dis[e.to], e.to);
      }
    }
  }
}
/* dijkstra(G,s,dis,prev)
    入力：グラフ G, 開始点 s, 距離を格納する dis, 最短経路の前の点を記録するprev
    計算量：O(|E|log|V|)
    副作用：dis, prevが書き換えられる
*/
void dijkstraRestore(const vector<vector<Edge>> &G, int s, vector<ll> &dis,
                     vector<ll> &prev) {
  int N = G.size();
  dis.resize(N, INFll);
  prev.resize(N, -1);  // 初期化
  priority_queue<PL, vector<PL>, greater<PL>>
      pq;  //「仮の最短距離、頂点」が小さい順にならぶ
  dis[s] = 0;
  pq.emplace(dis[s], s);
  while (!pq.empty()) {
    PL p = pq.top();
    pq.pop();
    int v = p.second;
    if (dis[v] < p.first) continue;  //最短経路でなければ無視
    for (auto &e : G[v]) {
      if (dis[e.to] > dis[v] + e.cost) {  //最短距離候補ならpriority_queueに追加
        dis[e.to] = dis[v] + e.cost;
        prev[e.to] = v;  // 頂点 v を通って e.to にたどり着いた
        pq.emplace(dis[e.to], e.to);
      }
    }
  }
}

/* get_path(prev, t)
    dijkstraRestore で得た prev, ゴール t
    出力： t への最短路のパス
*/
vector<int> get_path(const vector<ll> &prev, int t) {
  vector<int> path;
  for (int cur = t; cur != -1; cur = prev[cur]) {
    path.push_back(cur);
  }
  reverse(path.begin(), path.end());  //逆順なのでひっくり返す
  return path;
}
//参考:https://algo-logic.info/dijkstra/
int main() {
  int N, M;
  cin >> N >> M;
  map<P, int> mp;
  vector<vector<Edge>> edge(N);
  REP(i, M) {
    int a, b, c;
    cin >> a >> b >> c, a--, b--;
    edge[a].push_back(Edge{b, c});
    edge[b].push_back(Edge{a, c});
    mp[P(a, b)] = 1;
  }
  for (int i = 0; i < N - 1; i++) {
    vector<ll> dis(0), prev(0);
    dijkstraRestore(edge, i, dis, prev);
    for (int j = i + 1; j < N; j++) {
      vector<int> _a = get_path(prev, j);
      int tmp = i;
      REP(k, _a.size()) {
        mp[P(tmp, _a[k])] = 0;
        mp[P(_a[k], tmp)] = 0;
        tmp = _a[k];
      }
    }
  }
  ll ans = 0;
  for (auto s : mp) {
    if (s.second != 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3728
///
// File:  alds1_5_a.cpp
// Author: ymiyamoto
//
// Created on Mon Oct  9 09:57:55 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

static vector<uint32_t> A;

bool exhaustive_search(uint32_t m, uint32_t i, uint32_t sum)
{
  if (i >= A.size())
    return m == sum;
  else {
    return exhaustive_search(m, i + 1, sum + A[i]) || exhaustive_search(m, i + 1, sum);
  }
}

int32_t main()
{
  uint32_t n;
  cin >> n;
  for (uint32_t i = 0; i < n; i++) {
    uint32_t val;
    cin >> val;
    A.push_back(val);
  }

  uint32_t q;
  cin >> q;

  for (uint32_t i = 0; i < q; i++) {
    uint32_t m;
    cin >> m;
    if (exhaustive_search(m, 0, 0)) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}

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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353
const int INF = 1 << 28;




int main() {
    int N; cin >> N;
    vll s(N);
    rep(i, N) cin >> s[i];

    ll sum;
    ll ans = 0;

    for (int c = 1; c <= N - 1 ; c++ ) {
        sum = 0;
        int j = 1;
        if ((N - 1) % c != 0 ) {
            while (j * c < N - 1 && N - 1 - j * c > c) {
                sum += s[j * c] + s[N - 1 - j * c];
                chmax(ans, sum);
                j++;
            }
        }
        else {
            while (j * c <  N - 1 - j * c) {
                sum += s[j * c] + s[N - 1 - j * c];
                chmax(ans, sum);
                j++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int a, b;
    cin >> a >> b;
    
    cout << max(a+b, max(a-b, a*b)) << endl;
    
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
 
typedef long long Int;
typedef vector<int> VI;
typedef pair<int, int> PII;
 
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000;
const Int LINF = INF * (Int) INF;
const int MAX = 2007;
const int MOD = 998244353;

Int dp[3 * MAX][MAX];
int m;

int main(int argc, char* argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // mt19937 rng(47);

    
    int n;
    cin >> n >> m;
    dp[0][0] = 1;



    FOR(i,0,3 * n)
        FOR(j,0,n + 1) {
            if (dp[i][j] == 0)
                continue;
            dp[i + 1][j] += dp[i][j];
            dp[i + 1][j] %= m;

            if (i + 2 <= 3 * n && j + 1 <= n) {
                dp[i + 2][j + 1] += dp[i][j] * (i + 1);
                dp[i + 2][j + 1] %= m;
            }

            if (i + 3 <= 3 * n) {
                dp[i + 3][j + 1] += dp[i][j] * ((i + 1) * (i + 2));
                dp[i + 3][j + 1] %= m;
            }
        }
    Int res = 0;
    FOR(j,0,n + 1) {
        res += dp[3 * n][j];
        // cout << j << ' ' << dp[3 * n][j] << endl;
        res %= m;
    }

    cout << res << endl;
    
    cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 93056
from heapq import heappush, heappop
from collections import deque
import re
import math
import functools
import itertools
import fractions

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29


def mk1d(n, val=INF):
    return [val for i in range(n)]

def mk2d(h, w, val=INF):
    return [[val for i in range(w)]for i in range(h)]

DIV = 998244353

def gcd(a, b):
    if(b == 0):
        return a
    return gcd(b, a % b)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm(*numbers):
    return functools.reduce(lcm_base, numbers, 1)


def floyd_warshall(costs):
    N = len(costs)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                costs[i][j] = min(costs[i][j], costs[i][k]+costs[k][j])
    return costs

def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)

def main():
    H,W = isRaw()
    SS = [sRaw() for _ in range(H)]
    costs = mk2d(H*W, H*W, INF)
    for h in range(H):
        for w in range(W):
            cur = h*W+w
            costs[cur][cur] = 0
            if h<H-1 and SS[h][w]=="." and SS[h+1][w]==".":
                costs[cur][cur+W] = 1
                costs[cur+W][cur] = 1
            if w < W-1 and SS[h][w] == "." and SS[h][w+1] == ".":
                costs[cur][cur+1] = 1
                costs[cur+1][cur] = 1                
    costs = floyd_warshall(costs)
    maxCost = 0
    for cur in range(H*W):
        for nxt in range(H*W):
            if(costs[cur][nxt]!=INF) and cur!=nxt:
                maxCost = max(maxCost,costs[cur][nxt])
    return maxCost

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 69228
import java.io.*;

public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] strs = str.split(" ");
		int a = Integer.parseInt(strs[0]);
		int b = Integer.parseInt(strs[1]);
		int c = Integer.parseInt(strs[2]);
		
		int count = 0;
		
		for(int i=1; i<=c; i++) {
			if(a<=i && i<=b) {
				if(c%i==0) {
					count++;
				}
			}
		}
		
		System.out.println(count);
	}
}

Measured memory_bytes: 24304
#include<stdio.h>
#include<stdlib.h>

int main(){
  int i,j,n,u,k,v,c,mincost,*d,*pi,*color,**G;
  scanf("%d",&n);
  G = malloc(n * sizeof(int *));
  d = malloc(n * sizeof(int));
  pi = malloc(n * sizeof(int));
  color = malloc(n * sizeof(int));
  for(i=0;i<n;i++){
    G[i] = malloc(n * sizeof(int));
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j] = -1;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      G[u][v] = c;
    }
  }
  for(i=0;i<n;i++){
    d[i] = 110000;
    pi[i] = -1;
    color[i] = 1;
  }
  d[0] = 0;
  while(1){
    mincost = 110000;
    for(i=0;i<n;i++){
      if(color[i] != -1 && d[i] < mincost){
        mincost = d[i];
        u = i;
      }
    }
    if(mincost == 110000){
      break;
    }
    color[u] = -1;
    for(i=0;i < n;i++){
      if(G[u][i] != -1){
        if(color[i] != -1 && d[u] + G[u][i]< d[i]){
          pi[i] = u;
          d[i] = G[u][i] + d[u];
        }
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
  return 0;
}



Measured memory_bytes: 2048
#include <stdio.h>
int main(){
	int h1,m1,h2,m2,k;
	scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&k);
	int i1,i2,i;
	i1=h1*60+m1;
	i2=h2*60+m2;
	i=i2-i1;
	printf("%d\n",(i-k));
	
	return 0;
}

Measured memory_bytes: 1728
// luogu-judger-enable-o2
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a[55],k,n,ans=0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n,greater<int>());
    for(int i=0;i<k;i++)
    {
    	ans+=a[i];
	}
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int n,m;
    cin >> n >> m;

    vector <int> city(n);
    vector <int> road(2);
    
    for (int i = 0; i < m; i++) {
        cin >> road[0] >> road[1];
        city[road[0]-1]++, city[road[1]-1]++;
    }
   
   
    for (int i = 0; i < n; i++) {
        cout << city[i]<< endl;
    }
   
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  bool fail = false;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x % 2 == 0) {
      if ((x % 3) != 0 && (x % 5) != 0) fail = true;
    }
  }
  if (fail) {
    cout << "DENIED\n";
  } else {
    cout << "APPROVED\n";
  }
  return 0;
}

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

#define MAX 100002

int n;

char buf[MAX];
string s;

vector<pair<int,int> > ed;

string t;

int main(){
	scanf("%s",buf);
	s="0";
	t=buf;
	s+=t;
	int n=s.size()-1;
	for(int i=0;i<s.size();i++){
		if(s[i]!=s[n-i]){
			puts("-1");
			return 0;
		}
	}
	if(s[1]=='0'){
		puts("-1");
		return 0;
	}
	int cur=1;
	int par=0;
	int nex=1;
	for(int i=2;i<s.size();i++){
		if(i>n-i)break;
		if(s[i]=='1'){
			ed.push_back(make_pair(par,nex));
			par=nex;
			nex++;
			cur++;
			while(cur<i){
				cur++;
				ed.push_back(make_pair(par,nex));
				nex++;
			}
		}
	}
	if(nex<n){
		ed.push_back(make_pair(par,nex));
		par=nex;
		nex++;
	}
	while(nex<n){
		ed.push_back(make_pair(par,nex));
		nex++;
	}
	for(int i=0;i<ed.size();i++){
		printf("%d %d\n",ed[i].first+1,ed[i].second+1);
	}
	return 0;
}


Measured memory_bytes: 2548
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>

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-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;


void solve() {
	int N, K; cin >> N >> K;
	vector<int>A(N), F(N);
	ll ans = 0;
	REP(i, N) {
		cin >> A[i];
	}
	REP(i, N)cin >> F[i];
	VSORT(A);
	VSORT(F); VREVERSE(F);
	int ok = 1e18, ng = -1;
	while (ok - ng > 1) {
		int mid = (ok + ng) / 2;
		int rem = K;
		REP(i, N) {
			if (A[i] * F[i] <= mid)continue;
			int need = A[i] - (mid ) / F[i];
			if (rem >= need) {
				rem -= need;
			}
			else {
				ng = mid;
				goto END;
			}
		}
		ok = mid;
	END:;
	}
	print(ok);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 3328
from collections import deque
h, w, k = map(int, input().split())
n = h*w
x1, y1, x2, y2 = map(lambda x: int(x)-1, input().split())
fld = ''.join([input()for _ in range(h)])


def bfs(init_v):
    next_v = deque([init_v])
    dist = [-1]*n
    dist[init_v] = 0
    while next_v:
        v = next_v.popleft()
        i, j = divmod(v, w)
        dirc = [(-1, 0), (0, 1), (1, 0), (0, -1)]
        for di, dj in dirc:
            for a in range(1, k+1):
                x, y = i+di*a, j+dj*a
                if x < 0 or h <= x or y < 0 or w <= y:
                    break
                v2 = x*w+y
                if fld[v2] == '@':
                    break
                if dist[v2] != -1 and dist[v2] <= dist[v]:
                    break
                if dist[v2] != -1:
                    continue
                dist[v2] = dist[v]+1
                next_v.append(v2)
    return dist


dist = bfs(x1*w+y1)
print(dist[x2*w+y2])


Measured memory_bytes: 98184
import sys
K,A,B = map(int,input().split())

if A > B - 2:
    print(K+1)
    sys.exit(0)

if (K+1) <= A:
    ans = K+1
else:
    if (K+1-A) % 2 == 0:
        k = (K+1-A)//2
        ans = B + (B-A)*(k-1) if not k==0 else ans
    else:
        k = (K+1-A-1)//2
        ans = B + (B-A)*(k-1) + 1

# print('{:11d}'.format(ans))
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define db cout<<"db: "
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    string s;
    cin>>s;
    if(s.back()=='s')
    {
        s+="es";
        cout<<s;
    }
    else
    {
        cout<<s<<"s";
    }

    return 0;
}

Measured memory_bytes: 3660
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	am := int(1e10)
	zero := false
	minus := 0
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		t := abs(a[i])
		sum += t
		if t != 0 && t < am {
			am = t
		}
		if a[i] < 0 {
			minus++
		}
		if a[i] == 0 {
			zero = true
		}
	}

	if minus%2 == 0 || zero {
		fmt.Println(sum)
		return
	}

	fmt.Println(sum - am*2)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


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

d = [0 for _ in range(n)]

l = [i for i in input().split()]

for idx,i in enumerate(l[::-1]):
    if idx % 2 == 0:
        d[idx//2] = i
    else:
        d[-1*idx //2] = i
        
print(*d)
 

Measured memory_bytes: 24904
// C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<algorithm>
using namespace std;

long long machi[6];

int main()
{
    long long n;
    long long a[5];
    long long sum = 0;
    long long nokori;


    cin >> n;
   // cin >> a >> b >> c >> d >> e;

    for (int i = 0; i < 5; i++) {
        cin >> a[i];
    }
    //int key = 0;
    //while (key< 5) {
    //    if (n % a[key] == 0) {
    //        sum += n / a[key];
    //        if (key == 4)break;
    //        n = a[key] * (n / a[key] - 1) - a[key + 1] * (n / a[key ] - 1);
    //        if (n < 0)n = 0;
    //        n += a[key];
    //    }
    //    else {
    //        sum += n / a[key] + 1;
    //        long long amari = n % a[key];
    //        if (key == 4)break;
    //        n= a[key] * (n / a[key]) - a[key + 1] * (n / a[key ]);
    //        if (n < 0)n = 0;
    //        n +=amari;
    //    }

    //   // cout << sum << endl;
    //    key++;
    //}

    cout << max(max(max((n-1) / a[0]+1, (n-1) / a[1]+1),max(( n-1) / a[2]+1, (n-1) / a[3]+1)), (n-1) / a[4]+1)+4 << endl;



    return 0;


}


Measured memory_bytes: 3588
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
A.sort()
C.sort()
for b in B:
    ans += bisect.bisect_left(A, b)*(N-bisect.bisect_right(C, b))
print(ans)

Measured memory_bytes: 23180
N,M = map(int,input().split())
Hs = list(map(int,input().split()))
array = [[] for i in range(N)]
array2 = list(range(1,N+1))
for i in range(M):
    a,b = map(int,input().split())
    array[a-1].append(b)
    array[b-1].append(a)
z = list(zip(Hs,array,array2))
z.sort(reverse = True)
a, b, c = zip(*z)
Hs2 = list(a)
array = list(b)
array2 = list(c)
visited = [0]*N
ans = 0
for i in range(N):
    valid = True
    x = array2[i]
    for j in range(len(array[i])):
        visited[array[i][j]-1] = 1
        if Hs[array[i][j]-1] == Hs[x-1]:
            valid = False
    if visited[x-1] == 0 and valid:
        ans += 1

print(ans)


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

int main() {
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        int x, y, b, p, ans;
        cin >> x >> y >> b >> p;
        ans = min(b*x + p*y, (max(b,5)*x+max(p,2)*y)/5*4);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <list>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

class Need{
public:
    int a, b;
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<Need> c(m);
    repi(i, c){
        Need d;
        cin >> d.a >> d.b;
        *i = d;
    }
    sort(c.begin(), c.end(), [](Need s, Need t){ return s.b < t.b; });
    list<int> broken;
    repi(i, c){
        if(find_if(broken.begin(), broken.end(), [i](int b){ return (*i).a <= b && b <= (*i).b; }) == broken.end()){
            broken.push_back((*i).b - 1);
        }
    }
    cout << broken.size() << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	// ?¨??????\???????????????????????????????????????
		Scanner sc = new Scanner(System.in); 
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < values.length; i++) { 
			values[i] = i + 1;
		}
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1; 
			int temp =0;
			temp = values[a];
			values[a] = values[b];
			values[b] = temp;
			// a??¨b????????£???values??????????????????
		}
		for(int i = 0; i < n; i++) {
			System.out.println(values[i]);
		}
	// values??????????????????
	} 
}

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

#define MAX 1000

int c[MAX+1][MAX+1];

int lcs(string A, string B)  {
    int a = A.length();
    int b = B.length();
    int maxl = 0;

    A = ' ' + A;
    B = ' ' + B;
    //配列を作る
    for(int i=0; i<a; i++) {
        c[i][0] = 0;
    }
    for(int j=0; j<b; j++) {
        c[0][j] = 0;
    }
    for(int i=1; i<=a; i++) {
        for(int j=1; j<=b; j++) {
            if(A[i]==B[j]) {
                c[i][j] = c[i-1][j-1] + 1;
            }
            else {
                c[i][j] = max(c[i-1][j], c[i][j-1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }

    return maxl;
}

int main() {
    string s1, s2;
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;

#define abs(a) ((a) < (0)? -(a):(a))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define pb push_back


int c[100010];


int main() {
    int n;
    cin >> n;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        c[a-1]++;
        c[b]--;
    }
    int ans = 0, cur = 0;
    rep(i, 100001) {
        cur += c[i];
        if(cur >= i) ans = i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3480
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	n     int
	m     int
	q     int
	table [][]int
)

func main() {
	n = nextInt()
	m = nextInt()
	q = nextInt()
	table = make([][]int, q)
	for i := 0; i < q; i++ {
		a := nextInt()
		b := nextInt()
		c := nextInt()
		d := nextInt()
		table[i] = []int{a, b, c, d}
	}

	as := []int{}
	fmt.Println(dfs(as))

}

func dfs(as []int) int {
	ans := 0
	if len(as) == n {
		for _, t := range table {
			if as[t[1]-1]-as[t[0]-1] == t[2] {
				ans += t[3]
			}
		}
		return ans
	}

	prev := 1
	if len(as) != 0 {
		prev = as[len(as)-1]
	}
	for i := prev; i < m+1; i++ {
		as = append(as, i)
		ans = Max(ans, dfs(as))
		as = as[:len(as)-1]
	}
	return ans
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func Max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Min(s, v)
	}
	return s
}

func MaxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Max(s, v)
	}
	return s
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  cout << (n * (n - 1) >> 1) - (n >> 1) << '\n';
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < i; ++j) {
      if (i + j != (n | 1)) {
        cout << i << ' ' << j << '\n';
      }
    }
  }
  return 0;
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int a, b, c;
    cin >> a >> b >> c;
    int res = a + b + c;
    if (res < 22)
    {
        c("win");
    }
    else
    {
        c("bust");
    }
    return 0;
}

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

int func(long long a,long long b)
{
	long long x=a,y=b,t;
	if (x<y){
		t=x;
		x=y;
		y=t;
	}
	t=x%y;
	while(t!=0){
		x=y;
		y=t;
		t=x%y;
	}
	return y;
}

int main()
{
	int n;
	cin>>n;
	long long a[n+1],x,d;
	cin>>x;
	for(int i=1;i<=n;i++) cin>>a[i];
	d=abs(x-a[1]);
	for(int i=2;i<=n;i++){
		int k=abs(x-a[i]);
		d=func(d,k);
	}
	cout<<d<<endl;
	return 0;
}

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

int main() {
	int n, a[100];
	cin >> n;
	for (int i = 0; i <= n-1; i++){
		cin >> a[i];
	}
	
	for (int i = 0; i <= n-1; i++){
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
		for (int k = 0; k <= n-1; k++){
			cout << a[k];
			if (k < n-1){
				cout << " ";
			} else {
				cout << endl;
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 3092
function Main(arg)
{
  var A = arg.split("\n")[0].split(" ")[0]-0;
  var B = arg.split("\n")[0].split(" ")[1]-0;

  for (var i = 1; i <= 1000; i++){
    var a = Math.floor(i*0.08);
    var b = Math.floor(i*0.1);
    if (A === a && B === b) {
      console.log(i);
      return;
    }
  }

console.log(-1);
  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
<?php
  $input = trim(fgets(STDIN));

  for($i=0; $i<8; $i++){
      $k = 1;
      $ans = $input[0];
      $op = [];
      for($j=0; $j<3; $j++){
          if($i>>$j & 1){
              $ans += $input[$k];
              $k++;
              $op[] = "+";
          }else{
              $ans -= $input[$k];
              $k++;
              $op[] = "-";
          }
      }
    //   echo $ans."\n";
      $op[] = "=7";
      if($ans == 7){
          for($l=0; $l<4; $l++){
              echo $input[$l].$op[$l];
          }
          exit;
      }
  }
  


Measured memory_bytes: 4604
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]

if K > ((N - 1) * (N - 2)) // 2:
    print(-1)
    exit()

ans = []
for i in range(2, N + 1):
    ans.append((1, i))

E = ((N - 1) * (N - 2)) // 2 - K

for j in range(2, N + 1):
    if E == 0:
        break
    for k in range(j + 1, N + 1):
        ans.append((j, k))
        E -= 1
        if E == 0:
            break

print(N - 1 + ((N - 1) * (N - 2)) // 2 - K)
for a in ans:
    print(*a)


Measured memory_bytes: 42992
/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠺⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⠀⠈⢿⣦⣄⣈⣁⣀⣠⣴⣦⡀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣠⣶⣿⣿⣿⣿⣿⣿⣶⡄⠙⢿⣿⣿⣿⣿⣿⡿⠓⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠙⣿⣿⠿⠛⠛⠛⠛⣿⣿⡄⠀⠈⠉⠉⠉⣁⣀⡀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠈⠁⠀⠀⠀⠀⠀⣸⣿⡇⠀⠀⠀⣴⣿⣿⡿⠿⢷⣄⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠠⣤⣤⣴⣾⣿⡿⠁⠀⢀⣾⣿⣿⠏⠀⠀⠈⣿⣧⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣿⣿⣿⣏⠀⠀⣠⣾⣿⣿⠏⠀⠀⠀⠀⢹⣿⡄⠀⠀
⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠻⣿⣿⡟⠻⠿⠛⠁⠀⠀⠀⠀⠀⣾⣿⡇⠀⠀
⠀⠀⠘⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣿⡄⠀⣄⠀⠀⠀⠀⠀⣰⣿⣿⠇⠀⠀
⠀⠀⠀⢿⡄⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⠇⠀⠹⣷⣤⣤⣤⣾⣿⣿⡟⠀⠀⠀
⠀⠀⠀⠈⢿⣦⣄⣀⠀⠀⣀⣠⣾⣿⣿⡟⠀⠀⠀⠘⠻⣿⣿⣿⠿⠋⠀⠀⠀⠀
⠀⠀⠀⠀⠈⠻⣿⣿⣿⣿⣿⣿⣿⡿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠉⠙⠛⠛⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

           KRISHNA ASHOK⠀
*/

#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds; 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> Tree;
// order_of_key(k), find_by_order(k)


#define dbg(x) cout<<#x<<"="<<x<<'\n'
#define ll long long
#define pr pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define For(i,n) for(int i=0;i<(n);++i)
#define Forr(i,n) for(int i=n-1;i>=0;i--)
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#define fin ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define sz(a) (int)a.size()
#define Fill(a,b) memset(a,b,sizeof(a));
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
const int INF=1e9;
#define endl '\n'
#define fit(i,x) for(auto i:x)
#define gcd(a,b) __gcd(a,b)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
#define vt vector




void solve(){
    int n,m;
    cin>>n>>m;
    vt<set<int>> adj(n+1);
    int x,y;
    for(int i=0;i<m;i++){
    	cin>>x>>y;
    	adj[x].insert(y);
    	adj[y].insert(x);
    }
    int ans=0;
    // for(int i=1;i<=n;i++){
    // 	ans=max(ans,sz(adj[i]));
    // }
    // cout<<ans+1<<endl;
    vt<bool> vis(n+1);
    for(int i=1;i<=n;i++){
    	if(vis[i])continue;
 		queue<int> q;
 		int t=1;
 		q.push(i);
 		vis[i]=true;
 		while(!q.empty()){
 			int u=q.front();
 			q.pop();
 			for(int v:adj[u]){
 				if(vis[v])continue;
 				vis[v]=true;
 				q.push(v);
 				t++;
 			}
 		}
 		ans=max(ans,t);
    }
    cout<<ans<<endl;
}



int main()
{
    fin;
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 31536
N = gets.to_i
sp_list = N.times.map { gets.chomp.split }
group = sp_list.map.with_index do |(s, p), i|
  [s, p, i]
end.group_by { |(s, _, _)| s }
group.keys.sort.each do |s|
  sp_list = group[s]
  sorted = sp_list.sort_by { |(_, p, _)| -(p.to_i) }
  sorted.each do |(_, _, i)|
    puts(i + 1)
  end
end


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

int main(){
  string s;
  bool ok = false;
  cin >> s;
  sort(s.begin(),s.end());
  if(s[0] == s[1] && s[2] == s[3] && s[1] !=s[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int cnt;

void insertionSort(int A[], int n, int g);

void shellSort(int A[], int n);

int main(void)
{
	int n, i;
	
	
	scanf("%d", &n);
	
	int A[n];
	
	for(int i=0; i<n; i++)
	{
		scanf("%d", &A[i]);
	}
	
	shellSort(A,n);
	
	printf("%d\n", cnt);
	
	for(i=0; i<n; i++)
	{
		printf("%d\n", A[i]);
	
	}
	
	return 0;
	
}

void insertionSort(int A[], int n, int g)
{
	int i, j, temp;
	
	for(i = g; i<n; i++)
	{
		temp = A[i];
		j= i-g;
		
		while(j>=0 && A[j] > temp)
		{
			A[j+g] = A[j];
			j = j-g;
			cnt++;
		}
		
		A[j+g] = temp;
	
	}
	

}

void shellSort(int A[], int n)
{
	int m, i, h;
	int G[n];
	
		
	G[0] = 1;
	
	for(m = 1; 3*G[m-1]+1 < n; m++)
	{
		G[m] = 3*G[m-1]+1;
	}
		printf("%d\n", m);
				
		for(i=m-1; i>=0; i--)
		{
			insertionSort(A, n, G[i]);
		}
	
	for(i=m-1; i>=0; i--)
	{
		printf("%d", G[i]);
			
		if(i>0)
		{
			printf(" ");
		}
		
	}
	
	printf("\n");

}


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int  w, h, n, bxr=0, bxl=0, byu=0, byl=0, ans = 0;
  cin >> w >> h >> n ;
  vector<int> vecx(n), vecy(n), op(n);
  for(int i=0; i<n; i++){
    cin >> vecx[i] >> vecy[i] >> op[i];
  }
  bxl = w;
  byu = h;
  for(int i=0;i<n;i++){
    if(op[i] == 1 && bxr<vecx[i]){
      bxr = vecx[i];
    }
    if(op[i] == 2 && vecx[i]<bxl){
      bxl = vecx[i];
    }
    if(op[i] == 3 && byl<vecy[i]){
      byl = vecy[i];
    }
    if(op[i] == 4 && vecy[i]<byu){
      byu = vecy[i];
    }
  }
  if(byu -byl < 0 || bxl -bxr < 0){
    ans = 0;
  }else{
  ans = (byu - byl)*(bxl - bxr);
  }
  cout << ans <<endl;
}


Measured memory_bytes: 256
N = int(raw_input())
W = map(int, raw_input().split())
T = sorted(W)
move = {}
for x in W:
    index = T.index(x)
    if x != W[index]:
        move[x] = W[index]

cycle = []
while len(move) > 0:
    l = []
    k, v = move.popitem()
    l.append(k)
    nk = v
    while nk != k:
        nv = move[nk]
        del move[nk]
        l.append(nk)
        nk = nv
    cycle.append(l)
cost = 0
for l in cycle:
    n = len(l)
    minCost = sum(l) + (n-2) * min(l)
    otherCost = sum(l) + min(l) + (n+1) * min(W)
    cost += minCost if minCost < otherCost else otherCost
print cost

Measured memory_bytes: 4344
M,K = map(int, input().split())

if K >= pow(2, M):
    print(-1)
elif K == 0:
    ans = []
    for i in range(pow(2, M)):
        ans.append(i)
        ans.append(i)
    print(*ans)
else:
    num = 0
    L = []
    for i in range(pow(2, M)):
        if i == K:
            continue
        num ^= i
        L.append(i)
    if num == K:
        L2 = list(reversed(L))
        ans = L + [K] + L2 + [K]
        print(*ans)
    else:
        print(-1)

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

#define mod 1000000007

using namespace std;

using ll = long long;

int dp[1 << 21];
vector<vector<int> > compat; //c[man][woman]

void add(int &a, int b) {
	a += b;
	if (a >= mod)
		a -= mod;
}

void sub(int &a, int b) {
	a -= b;
	if (a < 0)
		a += mod;
}

int main()
{
	int n;
	cin >> n;
	compat.resize(n, vector<int>(n));

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)
			cin >> compat[i][j];
	}
	
	dp[0] = 1;

	for (int mask = 0; mask < (1 << n)-1; ++mask) {
		int a = __builtin_popcount(mask); // if x bits are set, it means x men have been taken care of
		for (int i = 0; i < n; i++) {
			if (compat[a][i] && !(mask & (1 << i)))
				add(dp[mask | (1 << i)], dp[mask]);
		}
	}
	cout << dp[(1 << n) - 1] << "\n";
}

Measured memory_bytes: 8448
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll m, k;
  cin >> m >> k;

  if (m == 0) {
    if (k == 0) {
      cout << "0 0" << endl;
    } else {
      cout << "-1" << endl;
    }
    return 0;
  }

  if (m == 1) {
    if (k == 0) {
      cout << "0 0 1 1" << endl;
    } else {
      cout << "-1" << endl;
    }
    return 0;
  }

  ll tail = (1LL << m) - 1;
  if(k > tail){
    cout << "-1" << endl;
    return 0;
  }

  if(k == 0){
    repLRE(i, 0, tail) cout << i << " " << i << ((i == tail)? "\n" : " ");
    return 0;
  }

  vll ansv;
  ansv.push_back(0);
  ansv.push_back(k);
  ansv.push_back(0);
  repLRE(i, 1, tail) if (i != k) ansv.push_back(i);
  ansv.push_back(k);
  rrepLRE(i, tail, 1) if (i != k) ansv.push_back(i);

  rep(i, (ll)ansv.size()) cout << ansv[i] << ((i == (ll)ansv.size()-1)? "\n" : " ");

  return 0;
}


Measured memory_bytes: 3952
import Data.Bool

main :: IO ()
main = do
  [a, b, c, d] <- map read . words <$> getLine
  putStr $ bool "No" "Yes" $ solve a b c d

solve :: Int -> Int -> Int -> Int -> Bool
solve a b c d
  | abs (a - c) <= d = True
  | abs (a - b) <= d && abs (b - c) <= d = True
  | otherwise = False


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

using namespace std;

#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    int x = 0;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        x ^= a[i];
    }

    for(int i = 0; i < n; ++i){
        cout << (x ^ a[i]) << " ";
    }
    cout << "\n";

    return 0;
}


Measured memory_bytes: 3896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
const ll MAX_N=1e5;
ll N,M,H[MAX_N];
vector<ll> G[MAX_N];
int main(){
	cin.tie(0);
	cin.sync_with_stdio(false);
	cin>>N>>M;
	REP(i,N)cin>>H[i];
	REP(i,M){
		ll a,b;
		cin>>a>>b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	ll ans=0;
	REP(i,N){
		bool f=true;
		for(auto e:G[i]){
			if(H[e]>=H[i])f=false;
		}
		if(f)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 10220
#include <bits/stdc++.h>
#define MAXN 100100
#define pii pair<int, int>
#define pll pair<long long, pair<long long, long long>>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x < n and y >= 0 and y < n)
using namespace std;
const int mod = 1e9 + 7;
const ll oo = 1e17 + 7;


int main()
{
    ios_base::sync_with_stdio(false);
    map<int, int> st;
    int n, aux;

    cin >> n;
    vector<pii> v(MAXN, {0, 0});


    for (int i=0; i<n; i++){
        cin >> aux;
        v[aux].ff--;
        v[aux].ss = aux;
    }

    sort(v.begin(), v.end());

    for (auto& x : v){
        // cout << x.ff << " ";
        while (x.ff <= -3) x.ff+=2;
    }
    // cout << endl;
    sort(v.begin(), v.end());


    int carry = 0;

    for (auto& x : v){
        // cout << x.ff << " ";
        if (x.ff < 0) x.ff += carry, carry = 0;
        else continue;
        if (x.ff == -2)x.ff++, carry = 1;
    }
    // cout << endl;

    int ans = 0;

    for (auto& x : v){
        ans += x.ff;
    }

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

Measured memory_bytes: 4048
package main

import (
	"fmt"
	"os"
)

func ReadInt(f *os.File) int {
	var n int
	fmt.Fscanf(f, "%d", &n)
	return n
}

func main() {
	A := ReadInt(os.Stdin)
	B := ReadInt(os.Stdin)
	if B%A == 0 {
		fmt.Println(A + B)
	} else {
		fmt.Println(B - A)
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int a[N],b[N];
  
  for(int i=0;i<N;i++) {
    cin>>a[i]>>b[i];
  }
  
  int ans=0;
  for(int i=0;i<N;i++) {
    ans+=b[i]-a[i]+1;
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256