akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
 
//ITPC dice4
 
class dice{
public:
    int top, bottom, right, left, front, back;
    void North();
    void East();
    void South();
    void West();
    void clockRotate();
};
void dice:: North(){
    int tmp = top;
    top = front;
    front = bottom;
    bottom = back;
    back = tmp;
}
void dice:: East(){
    int tmp = top;
    top = left;
    left = bottom;
    bottom = right;
    right = tmp;
}
void dice:: South(){
    int tmp = top;
    top = back;
    back = bottom;
    bottom = front;
    front = tmp;
}
void dice:: West(){
    int tmp = top;
    top = right;
    right = bottom;
    bottom = left;
    left = tmp;
}
void dice:: clockRotate(){
    int tmp = front;
    front = right;
    right = back;
    back = left;
    left = tmp;
}
 
bool sameDice(dice d1, dice d2){
    string s = "NRRRRNRRRRNRRRRNRRRRERRRRLLRRRR";
    rep(i, 0, s.size()){
        if(d1.top == d2.top && d1.front == d2.front && d1.right == d2.right && d1.back == d2.back && d1.left == d2.left && d1.bottom == d2.bottom){
            return true;
        }
        if(s[i] == 'N') d1.North();
        else if(s[i] == 'E') d1.East();
        else if(s[i] == 'S') d1.South();
        else if(s[i] == 'W') d1.West();
        else if(s[i] == 'R') d1.clockRotate();
    }
    return false;
}
 
signed main(){
    int n;
    vector<dice> dices;
    dice d;
    cin >> n;
    rep(i, 0, n){
        cin >> d.top >> d.front >> d.right >> d.left >> d.back >> d.bottom;
        dices. push_back(d);
    }
    rep(i, 0, n){
        rep(j, i + 1, n){
            if(sameDice(dices[i], dices[j])){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1232
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int a, i, j, k, n;
	long long max, sum;
	vector<int> s;
	while (cin >> n) {
		if (n == 0)break;
		s.clear();
		max = -100000;
		for (i = 0; i < n; i++) {
			cin >> a;
			s.push_back(a);
		}
		for (j = 0; j < n; j++) {
			sum = 0;
			for (k = j; k < n; k++) {
				sum += s[k];
				if (sum > max)max = sum;
			}
		}
		cout << max << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )
#define MAX 100000
#define M 10007

class Edge{
public:
  int target, cost;
  Edge(int target, int cost):target(target), cost(cost){}
};

vector<Edge> G[MAX];
bool V[MAX];
int n;
int ncomp;

void dfs(int u, vector<int> &maxv){
  V[u] = true;
  ncomp++;

  rep(i, G[u].size()){
    int c = G[u][i].cost;
    if ( maxv[0] < c ){ maxv.clear(); maxv.push_back(c); }
    else if ( maxv[0] == c ) maxv.push_back(c);
  }

  rep(i, G[u].size()){
    int v = G[u][i].target;
    if ( V[v] ) continue;
    dfs(v, maxv);
  }
}

int component(int u){
  vector<int> maxv;
  maxv.push_back(-1);
  ncomp = 0;
  dfs(u, maxv);
  assert( ncomp >= 3 );
  assert( maxv.size()%2 == 0 );
  return maxv.size()/2;
}

void compute(){
  rep(i, n) V[i] = false;
  int p = 1;
  rep(u, n){
    if ( !V[u] ){
      p = (p*component(u))%M;
    }
  }
  cout << p << endl;
}


main(){
  int m, s, t1, t2, b1, b2, c;
  while(1){
    cin >> n;
    if ( n == 0 ) break;
    assert( 3 <= n && n <= 100000);

    rep(i, n) G[i].clear();
    rep(i, n){
      cin >> t1 >> b1 >> t2 >> b2;
      G[i].push_back(Edge(t1, b1));
      G[i].push_back(Edge(t2, b2));
      assert( 0 < b1 );
      assert( 0 < b2 );
    }

    rep(i, n) assert( G[i].size() == 2 );
    rep(i, n) assert( G[i][0].target != G[i][1].target );

    rep(i, n){
      t1 = G[i][0].target;
      t2 = G[i][1].target;
      int c1 = G[i][0].cost;
      int c2 = G[i][1].cost;

      assert( G[t1][0].target == i || G[t1][1].target == i );
      assert( G[t2][0].target == i || G[t2][1].target == i );

      if ( G[t1][0].target == i ) assert( G[t1][0].cost == c1 );
      if ( G[t1][1].target == i ) assert( G[t1][1].cost == c1 );

      if ( G[t2][0].target == i ) assert( G[t2][0].cost == c2 );
      if ( G[t2][1].target == i ) assert( G[t2][1].cost == c2 );
    }



    compute();
  }
}

Measured memory_bytes: 0
prize = [300000, 200000, 100000, 0]
X, Y = map(int, input().split())
if X > 4:
    X = 4
if Y > 4:
    Y = 4
ans = prize[X-1] + prize[Y-1]
if X == 1 and Y == 1:
    ans += 400000
print(ans)


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

int main() {
  int N,A;
  cin >> N >> A;
  int five_hundred_number = N / 500;
  int need_one_number = N - five_hundred_number * 500;
  if(need_one_number > A){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
   
    

}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
typedef unsigned long long ull;
const ull INF = 1e18;
using namespace std;

int main(){
    int x,y;
    cin>>x>>y;
    rep(i,0,x+1){
        if((2*i+4*(x-i))==y){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3620
import sys
def input():
    return sys.stdin.readline()[:-1]
s=input()
t=input()

dp=[[0]*(len(t)+1) for i in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
            dp[i+1][j+1]=max(dp[i+1][j+1], dp[i][j]+1)
        dp[i+1][j+1]=max(dp[i+1][j+1], dp[i+1][j])
        dp[i+1][j+1]=max(dp[i+1][j+1], dp[i][j+1])

i,j=len(s),len(t)
ans=[]
while i>0 and j>0:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    else:
        i-=1
        j-=1
        ans.append(s[i])
ans.reverse()
print("".join(ans))

Measured memory_bytes: 113756
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
var a=Console.ReadLine().Split().Select(long.Parse).ToArray();
  Console.WriteLine(lcm (a[0],a[1])*lcm(a[0],a[1])/(a[0]*a[1])*a[2]);
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        for (long i = 2; i < n; i++) { if (n % i == 0) return false; }
        return true;
    }
}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long() { return long.Parse(Console.ReadLine()); }
    public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); }
    public static int Int() { return int.Parse(Console.ReadLine()); }
    public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 9600
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	hill := make(map[int]int, n)
	for a:=0; a<n; a++ {
		var t int
		fmt.Scan(&t)
		hill[a] = t
	}

	load := make(map[int][]int, n+10)
	for i:=0; i<m; i++ {
		var from, to int
		fmt.Scan(&from, &to)
		load[from-1] = append(load[from-1], to-1)
		load[to-1] = append(load[to-1], from-1)
	}

	goodHill := 0
	for h:=0; h<n; h++ {
		//v := unique(load[h])
		flag := true
		myH := hill[h]
		for _, i := range load[h] {
			if myH <= hill[i] {
				flag = false
				break
			}
		}
		if flag == true {
			goodHill += 1
		}
	}

	fmt.Println(goodHill)
}

func unique(a []int) []int {
	var u []int
	tmp := make(map[int]bool, len(a))
	for _, i := range a {
		if tmp[i] == false {
			u = append(u, i)
			
		}
		tmp[i] = true
	}
	return u
}


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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    string str;
    getline(cin, str);

    rep(i, str.length()) {
        if (islower(str[i])) {
            str[i] = toupper(str[i]);
        } else {
            str[i] = tolower(str[i]);
        }
    }

    cout << str << "\n";

    return 0;
}



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

void pf(int n, vector<int> &v) {
	int p = 2;
	while (p*p <= n) {
		if (n%p != 0) {
			p++;
			continue;
		}
		v.push_back(p);
		while (n%p == 0) n /= p;
	}
	if(n != 1) v.push_back(n);
}

int main(void){
	int N;
	cin >> N;

	vector<int> c(1'000'000);

	rep(i,N) {
		int a;
		cin >> a;
		vector<int> v;
		pf(a, v);
		for (int p : v) c[p]++;
	}
	
	bool pc = true;
	bool sc = true;
	rep(i,1'000'000) {
		if (c[i] < 2) continue;
		pc = false;
		if (c[i] == N) {
			sc = false;
			break;
		}
	}

	if (pc) cout << "pairwise coprime" << endl;
	else if (sc) cout << "setwise coprime" << endl;
	else cout << "not coprime" << endl;
	
return 0;
}


Measured memory_bytes: 7224
#include <iostream>
#include <complex>

using namespace std;

typedef complex<double> P;

double cross(P a, P b){
  return a.real() * b.imag() - a.imag() * b.real();
}

double dot(P a, P b){
  return a.real() * b.real() + a.imag() * b.imag();
}

int ccw(P a, P b, P c){
  b -= a; c -= a;
  if(cross(b, c) > 0) return 1;
  if(cross(b, c) < 0) return -1;
  if(dot(b, c) < 0) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

int main()
{
  char j;
  double a,b,c,d,e,f,g,h;
  for(;cin>>a>>j>>b>>j>>c>>j>>d>>j>>e>>j>>f>>j>>g>>j>>h;)
    {
      P x(a,b),y(c,d),z(e,f),p(g,h);
      if(ccw(x,y,z)==ccw(y,z,p) && ccw(y,z,p) == ccw(z,p,x)
	 && ccw(z,p,x) == ccw(p,x,y))
	cout<<"YES"<<endl;
      else
	cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 1216
function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	let lVl = parseInt(input[0][0], 10);
	let lEl = parseInt(input[0][1], 10);
	let graph = [];
	for (let i = 0; i < lEl; i++){
		graph.push(input[i + 1].map(e => parseInt(e, 10)));
	}
	graph.sort((a, b) => a[2] - b [2]);

	let uf = new UnionFind(lVl);
	let ans = 0;
	for (let i = 0; i < graph.length; i++){
		if (uf.find(graph[i][0]) !== uf.find(graph[i][1])) {
			uf.union(graph[i][0], graph[i][1])
			ans += graph[i][2];
		}
	}

	console.log(ans);

}

function UnionFind (n) {
    this.parents = [];
    for (let i = 0; i < n; i++) {
        this.parents.push(-1);
    }
}

UnionFind.prototype.find = function (x) {
    if (this.parents[x] < 0) return x;
    return this.parents[x] = this.find(this.parents[x]);    
}


UnionFind.prototype.union = function (x, y) {
    x = this.find(x);
    y = this.find(y);
    if (x === y) return;
    if (this.parents[x] > this.parents[y]) [x, y] = [y, x];
    
    this.parents[x] += this.parents[y];
    this.parents[y] = x;
}


UnionFind.prototype.size = function (x) {
    x = this.find(x);
    while (x >= 0) {
        x = this.parents[x];
    }
    return x * -1;
}

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



Measured memory_bytes: 77204
package main

import (
	"fmt"
	"strconv"
)

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

func main() {
	var s string
	fmt.Scan(&s)

	ans := 1000
	l := len(s)
	for i := 0; i+3 <= l; i++ {
		n, _ := strconv.Atoi(s[i : i+3])
		tmp := abs(753 - n)
		if tmp < ans {
			ans = tmp
		}
	}
	fmt.Println(ans)
}


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

int main() {
  
  int N, K, d, h = 0;
  cin >> N >> K;  
  vector<int> X(N);
  
  for(int i = 0; i < K; i++) {
    cin >> d;
    for(int j = 0; j < d; j++) {
      vector<int> A(d);
      cin >> A.at(j);
      for(int l = 0; l < N; l++) {
        if(A.at(j) == l+1) X.at(l) = 1;
      }
    }
  }
   
  for(int i = 0; i < N; i++) h += X.at(i);  
  cout << N - h << endl;

}

Measured memory_bytes: 3604
#include<iostream>
using namespace std;
typedef long long ll;
ll mod=100000;
int N,M,S;

ll dp[50][3001];

void init(){
  for(int i=0;i<50;i++)
    for(int j=0;j<3001;j++)
      dp[i][j]=0;
  dp[0][0]=1;
}

int main(){
  while(1){
    cin>>N>>M>>S;
    if(N==0&&M==0&&S==0)break;
    init();
    for(int i=1;i<=N*N;i++){
      for(int j=0;j<=S;j++){
	if(j-i>=0)dp[i][j]+=dp[i-1][j-i];
	if(j-i>=0)dp[i][j]+=dp[i][j-i];
	if(j-M-1>=0)dp[i][j]+=(mod-dp[i-1][j-M-1]);
	dp[i][j]%=mod;
      }
    }
    cout<<dp[N*N][S]<<endl;
  }
  return 0;
}

Measured memory_bytes: 2328
program answer
  implicit none
  integer :: i, j, N, ans, count
  character(len=10**5) :: S
  read(*,*) S
  N=len_trim(S)
  ans=0
  count=0
  do i = 1, N
     if(S(i:i)=='1') then
        count=count+1
     end if
  end do
  ans=min(count,N-count)

  write(*,*) ans*2
  stop
 end program answer

Measured memory_bytes: 3164
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
template <class... T> void printArr(T&&...){ }
#endif

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a]++;
        v[b]++;
    }
    for(int i = 0; i < n; i++){
        cout << v[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};


const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];


void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(ll i=2; i<MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}


ll nCr(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll nHr(ll n, ll r) { if (n == 0 && r == 0) return 1; else return nCr(n + r - 1, r); }
ll nPr(ll n, ll r) { if (r < 0 || n < r) return 0; else return (fac[n] * finv[n-r]) % MOD; }


int main(){
    COMinit();
    ll s; cin >> s;
    if(s < 3){
        cout << 0 << endl;
        return 0;
    }
    ll ma = s/3, ans = 0;
    Rep(i, 1, ma+1){
        ADD(ans, nHr(i, s-3*i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 15572
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
import heapq
S=[]
D=dict()
for i in range(n):
  s,t,x=map(int,input().split())
  S.append((1,x,max(0,s-x)))
  S.append((-1,x,max(0,t-x)))
  D[x]=False
S.sort(key=lambda x:x[2])
X=[]
cur=0
for i in range(q):
  d=int(input())
  while cur<2*n:
    a,b,c=S[cur]
    if c>d:
      break
    else:
      cur+=1
      if a==1:
        heapq.heappush(X,b)
        D[b]=True
      else:
        D[b]=False
  while X:
    ans=heapq.heappop(X)
    if D[ans]:
      print(ans)
      heapq.heappush(X,ans)
      break
  if not X:
    print(-1)

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

int main(){
  int a, b;
  
  cin >> a;
  cin >> b;
  
  if((a == 1 && b == 2) || (a == 2 && b == 1)){
    cout << 3 << endl;
  }
  else if((a == 1 && b == 3) || (a == 3 && b == 1)){
    cout << 2 << endl;
  }
  else if((a == 2 && b == 3) || (a == 3 && b == 2)){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
N=int(input())
a,b=input().split()
test=lambda x:float(x)
a=test(a)
b=test(b)
h=[int(i) for i in input().split()]
d=1000
c=0
p=0
for i in h:
    c=c+1
    t=a-test(i*0.006)
    if abs(b-t)<d:
        d=abs(float(b)-t)
        p=c

print(p)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int[] x = new int[5];
    int ans = 0;
    for(int i=0;i<5;i++) {
        x[i] = scan.nextInt();
        if(x[i] == 0) {
            ans = i + 1;
        }
    } 

    System.out.println(ans);
    scan.close();

}

};


Measured memory_bytes: 35476
import java.util.Scanner;

class Main {
    public static void main(String str[]) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();

        int count = 0;

        for (int i = a; i <= b; i++) {
            if (c % i == 0) {
                count++;
            }
        }

        System.out.println(count);
    }
}

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

typedef long long ll;
const int MAX_N = 10030;    // Change as necessary
const ll  MODD = 1000000009; //

ll A[2*MAX_N],M[8*MAX_N];

int size;

void constructRMQ(ll A[MAX_N], ll M[4*MAX_N], int n) {
  size = 1; while(size < n) size <<= 1;
  for (int i=0; i < size; i++) M[size-1+i] = (i < n ? A[i] : INT_MAX);
  for (int i=size-2; i>=0; i--) M[i] = min(M[2*i+1],M[2*i+2]);
}

ll getmin(ll M[4*MAX_N], int a, int b, int st=0,int en=size,int ind=0) {
  if (a > b || a >= en || b < st)         return INT_MAX;
  if ((a <= st && en <= b) || st+1 >= en) return M[ind];
  int mid = (st+en)/2;
  return min(getmin(M,a,b,st,mid,2*ind+1), getmin(M,a,b,mid,en,2*ind+2));
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  ll n,x; cin >> n >> x;
  for(int i=0;i<n;i++) cin >> A[i];
  for(int i=0;i<n;i++) A[i+n] = A[i];
  
  constructRMQ(A,M,2*n);
  
  ll best = *min_element(A,A+n)*n+x*(n-1);
  
  for(int gap=0;gap<n;gap++){
    ll curr = 0;
    for(int i=gap;i<gap+n;i++)
      curr += getmin(M,i-gap,i);
    best = min(best,curr+gap*x);
  }
  cout << best << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX>>2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x))
#define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
using namespace std;
void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}}
void solve(){
    ll n,x;
    vt<ll> a;
    cin>>n;
    read(a,n);
    sort(a.begin(),a.end());
    x=unique(a.begin(),a.end())-a.begin();
    cout<<(x-!(x&1))<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 4280
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef pair<int,int> P;
typedef long long int lnt;
lnt n,ans,x;
lnt a[100001];
int main()
{
	cin>>n;
	for(lnt i=0;i<n;i++) cin>>a[i];
	for(lnt i=0;i<n;i++){
		ans+=a[i]/2;
		if(a[i]%2 && a[i+1]){
			ans++;
			a[i+1]--;
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;

#define pll pair<ll,ll>

string s;
int N;
ll dp[100001][13];
int main(){
    cin>>s;
    N = s.size();
    FILL2(dp,100001,13,0LL);
    
    dp[0][0] = 1;
    for(int i=0;i<N;++i){
        int x;
        if(s[i]=='?'){ x = -1;}
        else{ x = ctoi(s[i]); }
        
        if(x<0){
            for(x=0;x<10;++x){
                for(int amari=0;amari<13;++amari){
                    int idx = (amari*10+x)%13;
                    dp[i+1][ idx ] += dp[i][amari];
                    dp[i+1][ idx ] %= MOD;
                }
            }
        }else{
            for(int amari=0;amari<13;++amari){
                int idx = (amari*10+x)%13;
                dp[i+1][ idx ] += dp[i][amari];
                dp[i+1][ idx ] %= MOD;
            }
        }
    }
    cout << dp[N][5] << "\n";
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream& operator<<(ostream &os, unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream& operator<<(ostream &os, multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream& operator<<(ostream &os, unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int N, K;
vector<lint> h;

int main()
{
    cin >> N >> K;
    h.resize(N);
    cin >> h;
    sort(h.begin(), h.end());

    lint ans = 1E9;
    REP(i, N - K + 1) ans = min(ans, h[i + K - 1] - h[i]);

    cout << ans << endl;
}


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

#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<int>

using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 0x3f3f3f3f;
const ll MOD = 1000000007;



signed main(){

#ifndef ONLINE_JUDGE
	//freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);

    int r = 0 , ans = 0;
    string str;
    cin >> str;
    for(auto c : str){
        if(c == 'S') r = 0;
        else r++;
        ans = max(ans , r);
    }
    cout << ans << '\n';

     

    return 0;

}



Measured memory_bytes: 3592
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val xs = (0 until n).map {
        val (s, p) = readLine()!!.split(' ')
        Triple(it + 1, s, p.toInt())
    }
    xs.sortedByDescending { it.third }.sortedBy { it.second }.forEach {
        println(it.first)
    }
}

Measured memory_bytes: 38144
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <string>

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl

using namespace std;
using i64 = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    for (auto &&i : x)
        cin >> i;

    int sum = 0;
    int sqsum = 0;
    for (auto &&i : x)
    {
        sum += i;
        sqsum += i * i;
    }

    float diff = (float)sum / (float)n - sum / n;
    int p = diff * 2 + sum / n;

    int ans;
    ans = n * p * p - 2 * p * sum + sqsum;
    cout << ans << endl;

    return 0;
}

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


int main(){
    int N;
    cin >> N;
    double A;
    double ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A;
        ans += 1/A;
    }
    
    printf("%.10f",1/ans);
    return 0;
}



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

typedef long long ll;

ll dp[20001];
ll inf = 1LL<<50;

int main() {
  ll h, n; cin >> h >> n;
  for (int i = 0; i <= h+10000; ++i) {
    dp[i] = inf;
  }
  dp[0] = 0;
  for (int i = 0; i < n; ++i) { 
    ll a, b; cin >> a >> b;
    // for (int j = h+10000; j >= a; --j) {
    for (int j = a; j <= h+10000; ++j) {
      dp[j] = min(dp[j], dp[j-a]+b);
    }
  }
  ll ans = inf;
  for(int i = h; i <= h+10000; ++i) {
    ans = min(ans, dp[i]);
  }
  cout << ans << endl;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
#define br "\n"
#define MAXIM 100003
ll mod = 1e9 + 7;


void solve(){
	ll n,d;
	cin >> n >> d;
	d = d*d;
	ll ans = 0;
	rep(i,0,n){
		ll x,y;
		cin >> x >> y;
		ll c = ((x*x) + (y*y));
		if(c <= d) ans++;
	}
	cout << ans;
}
 
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif  
	ll t = 1;
	// cin >> t;
	rep(i,0,t){
		solve();
	}
 
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>

using namespace std;

int main(){
	int days[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
	char week2[7][10] = {"Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"};

	int month,day;
	int sum;

	cin >> month >> day;
	while((month != 0) && (day != 0)){
		sum = 0;
		for(int i=0 ;i < month - 1;i++){
			sum += days[i];
		}
		sum += day;

		switch(sum % 7){
			case 1:
				printf("%s\n",week2[0]);
				break;

			case 2:
				printf("%s\n",week2[1]);
				break;

			case 3:
				printf("%s\n",week2[2]);
				break;

			case 4:
				printf("%s\n",week2[3]);
				break;

			case 5:
				printf("%s\n",week2[4]);
				break;

			case 6:
				printf("%s\n",week2[5]);
				break;

			case 0:
				printf("%s\n",week2[6]);
				break;

		}

		cin >> month >> day;
	}
}

Measured memory_bytes: 2984
#inport
import sys
import numpy as np
from collections import deque


#input
N,M = [int(x) for x in sys.stdin.readline().split()]
h = [int(x) for x in sys.stdin.readline().split()]

hills = np.ones(N)

for _ in range(M):
    a, b = [int(x) for x in sys.stdin.readline().split()]
    if h[a-1] > h[b-1] :
        hills[b-1] = 0
    elif h[b-1] > h[a-1]:
        hills[a-1] = 0
    else:
        hills[a-1] = 0
        hills[b-1] = 0

print(int(np.sum(hills)))




Measured memory_bytes: 38868
def solve(n):
    string = []
    while n > 0:
        remainder = n % 26
        if remainder == 0:
            string.append('z')
            n = (n//26)-1
        else:
            a = chr((remainder-1)+ord('a'))
            string.append(a)
            n = n//26
    return ''.join(string[::-1])

if __name__ == '__main__':
    n = int(input())
    print(solve(n))

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> s;
    for (int i=0; i<n; i++) {
        int x;
        cin >> x;
        s.push_back(x);
    }
    int q;
    cin >> q;
    int count = 0;
    for (int i = 0; i < q; i++) {
        int now;
        cin >> now;
        int mid = n / 2;
        int left = 0;
        int right = n - 1;
        // cout << "now: " << now << endl;
        while(1) {
            if (s.at(mid) == now || s.at(left) == now || s.at(right) == now) {
                count++;
                // cout << "found: " << now << endl;
                break;
            } else if (s.at(mid) < now) {
                left = mid + 1;
                mid = (left + right)/2;
                if (s.at(right) < now) break;
            } else {
                right = mid - 1;
                mid = (left + right)/2;
                if (s.at(left) > now) break;
            }
            if (left == right && left != now && right != now) break;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3492
#include <iostream>

using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int a;
  ll b, n;
  std::cin >> a >> b >> n;

  ll x;
  if (n < b - 1)
    x = n;
  else
    x = b - 1;

  std::cout << (a * x) / b + a * (x / b) << '\n';

  return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

 
int main() {
    ll ans = 0;
    ll a, b;
    
    cin >> a >> b;

    cout << max(max(a+b, a-b), a*b) << endl;


    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

signed main() {
    int N;
    cin >> N;
    vector<vector<int>> G(N + 1);
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
        char temp;
        cin >> temp;
        if (temp == '1') {
            G[i + 1].push_back(j + 1);
        }
    }
    int ans = -1;
    for (int i = 1; i <= N; i++) {
        map<int, int> search;
        vector<bool> check(N + 1, false);
        queue<int> next;
        bool update = true;
        next.push(i);
        check[i] = true;
        search[i] = 1;
        while (!next.empty()) {
            int now = next.front();
            next.pop();
            for (auto temp : G[now]) {
                if (search[temp] != 0 && abs(search[now] - search[temp]) != 1) update = false;
                if (check[temp]) continue;
                check[temp] = true;
                next.push(temp);
                search[temp] = search[now] + 1;
            }
        }
        if (update) {
            for (auto temp : search) {
                ans = max(ans, temp.second);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define ARRAY_LEN(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INTINF = 2147483647;
const int MOD = 1000000007;

int main() {
  int X, t; cin >> X >> t;
  int result = max(0, X-t);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


struct mint {
	int x;
	mint(int x = 0) :x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator-=(const mint a) {
		if ((x += MOD - a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator*=(const mint a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint a)const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a)const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
	mint pow(int t)const {
		if (!t)return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1)a *= *this;
		return a;
	}

	//for prime mod
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a)const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint>fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; i++)fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; i--)ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n)return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};

signed main() {
	int X, Y;
	cin >> X >> Y;
	if ((X + Y) % 3) {
		cout << 0;
		return 0;
	}
	int N = (X + Y) / 3;
	X -= N; Y -= N;
	if (X < 0 || Y < 0) {
		cout << 0;
		return 0;
	}
	combination c(X + Y);
	mint ans = c(X + Y, X);
	cout << ans.x << endl;
}

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

using namespace std;

int main()
{
   int n;
   cin>>n;
   vector<int>theval;
   for(int i=0;i<n;i++){
       int a;
       cin>>a;
       theval.push_back(a);
   }
   int maximum=1;
   int sum=1;
   for(int i=1;i<n;i++){
       if(theval[i]<=theval[i-1]){sum++;}
       else{maximum=max(maximum,sum);sum=1;}
   }
   maximum=max(maximum,sum);
   cout<<maximum-1<<endl;
}


Measured memory_bytes: 892
import math


A, B, H, M = map(int, input().split())

m = M * 6
h = H * 30 + M * 0.5
s = min(abs(m-h), abs(h-m))

ans = (A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(s))) ** 0.5

print(ans)

Measured memory_bytes: 9512
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            
            Boolean check = false;
            while (!check)
            {
                check = true;
                for (int i = 2; i < N; i++)
                {
                    if (N % i == 0)
                    {
                        check = false;
                        break;
                    }
                }
                if (check)
                {
                    break;
                }
                N++;
            }
            Console.WriteLine(N);
        }
    }
}


//long n = long.Parse(Console.ReadLine());
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine(cnt);
//Console.ReadKey();


Measured memory_bytes: 13140
# coding=utf-8

if __name__ == '__main__':
    N = int(input())
    S = input()

    if N == 0 or N % 2 == 1:
        print('No')
        exit()

    N = int(N / 2)

    T1 = ''
    T2 = ''

    for i in range(N):
        T1 += S[i]
        T2 += S[i + N]

    if T1 == T2:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
int n;
int a[N],v[N],c[N*2];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline bool check(int k) {
    memset(c,0,sizeof(c));
    int x=0,y=1;c[N]=1;
    long long sum=0;
    for(int i=1;i<=n;i++) {
	if(a[i]>=k) y+=c[++x+N],++c[x+N];
	else y-=c[x+N],++c[--x+N];
	sum+=y++;
    }
    return sum*2>=1LL*n*(n+1)/2;
}
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=v[i]=gi();
    sort(v+1,v+1+n);
    for(int i=1;i<=n;i++) a[i]=lower_bound(v+1,v+1+n,a[i])-v;
    int l=1,r=n;
    while(l<=r) {
	int mid=(l+r)>>1;
	if(check(mid)) l=mid+1;
	else r=mid-1;
    }
    cout<<v[r];
    return 0;
}

Measured memory_bytes: 1792
import math

N,D=map(int,input().split())
X=[]
for i in range(N):
    x=list(map(int,input().split()))
    X.append(x)

def dist(R,L):
    P=0
    for z in range(D):
        P+=(R[z]-L[z])**2
    return math.sqrt(P)

count=0
for j in range(N-1):
    for k in range(j+1,N):
        #print(dist(X[j],X[k]))
        #print(math.floor(dist(X[j],X[k])))
        if dist(X[j],X[k])==math.floor(dist(X[j],X[k])):
            count+=1

print(count)


Measured memory_bytes: 3064
/*
 * 2419.cc: Acrophobia
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_W = 100;
const int MAX_H = 100;
const int MAX_M = 5;
const int MBITS = 1 << MAX_M;

const int dxs[] = {1, 0, -1, 0}, dys[] = {0, -1, 0, 1};

const int INF = 1 << 30;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

struct Stat {
  int d, x, y, b;
  Stat() {}
  Stat(int _d, int _x, int _y, int _b): d(_d), x(_x), y(_y), b(_b) {}
  bool operator<(const Stat &s) const { return d > s.d; }
};

/* global variables */

string flds[MAX_H];
int ds[MAX_H][MAX_W], ms[MAX_H][MAX_W];
int dists[MAX_H][MAX_W][MBITS];

/* subroutines */

/* main */

int main() {
  int w, h;
  cin >> w >> h;

  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      ds[y][x] = 1, ms[y][x] = -1;

  int sx, sy, gx, gy, m = 0;
  
  for (int y = 0; y < h; y++) {
    cin >> flds[y];
    for (int x = 0; x < w; x++) {
      switch (flds[y][x]) {
      case '#': ds[y][x] = 0; break;
      case 'S': sx = x; sy = y; break;
      case 'G': gx = x; gy = y; break;
      case 'M': ms[y][x] = m++; break;
      }
    }
  }

  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      if (ds[y][x] == 0)
	for (int y0 = y - 2; y0 <= y + 2; y0++)
	  for (int x0 = x - 2; x0 <= x + 2; x0++)
	    if (x0 >= 0 && x0 < w && y0 >= 0 && y0 < h && ds[y0][x0] > 0) {
	      int d = 4 - max(abs(x0 - x), abs(y0 - y));
	      if (ds[y0][x0] < d) ds[y0][x0] = d;
	    }

  /*
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) printf("%d", ds[y][x]);
    putchar('\n');
  }
  */
  
  int mbits = 1 << m;

  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      for (int bits = 0; bits < mbits; bits++) dists[y][x][bits] = INF;
  dists[sy][sx][0] = 0;

  priority_queue<Stat> q;
  q.push(Stat(0, sx, sy, 0));

  while (! q.empty()) {
    Stat u = q.top(); q.pop();
    if (dists[u.y][u.x][u.b] != u.d) continue;
    if (u.x == gx && u.y == gy && u.b == mbits - 1) break;

    int vd = u.d + ds[u.y][u.x];

    for (int di = 0; di < 4; di++) {
      int vx = u.x + dxs[di], vy = u.y + dys[di];
      if (vx >= 0 && vx < w && vy >= 0 && vy < h && ds[vy][vx]) {
	int vb = (ms[vy][vx] >= 0) ? u.b | (1 << ms[vy][vx]) : u.b;
	if (dists[vy][vx][vb] > vd) {
	  dists[vy][vx][vb] = vd;
	  q.push(Stat(vd, vx, vy, vb));
	}
      }
    }
  }

  printf("%d\n", dists[gy][gx][mbits - 1]);
  return 0;
}

Measured memory_bytes: 2664
import bisect

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

A = sorted(A)
B = sorted(B)
C = sorted(C)

ans = 0

for b in B:
    ia = bisect.bisect_left(A, b)
    ic = len(C) - bisect.bisect(C, b)
    ans += ia * ic

print(ans)
    

Measured memory_bytes: 105348
def solve(d,w,f):
    ans = 0
#    print("aaa")
    for i in range(d-2):
        for j in range(i+2,d):
            for k in range(w-2):
                for l in range(k+2,w):
                    minOut = 10
                    for m in range(i,j+1):
                        if minOut > f[m][k]:
                            minOut = f[m][k]
                        if minOut > f[m][l]:
                            minOut = f[m][l]
                            
                    for m in range(k,l+1):
                        if minOut > f[i][m]:
                            minOut = f[i][m]
                        if minOut > f[j][m]:
                            minOut = f[j][m]
                    total = 0
                    for m in range(i+1,j):
                        for n in range(k+1,l):
                            total += minOut-f[m][n]
                            if minOut <= f[m][n]:
                                total -= 10**5
    #                print(total,i,j,k,l)
                    if ans < total:
                        ans = total
    return ans


while True:
    d,w = [int(i) for i in input().split()]
    if d==0:
        break
    f = []
    for i in range(d):
        f.append([int(i) for i in input().split()])
    print(solve(d,w,f))




Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(15);
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  int one = 0;
  int two = 0;
  int three = 0;
  for (int i = 0; i < N; i++){
    if (a[i] == 1){
      one++;
    }
    if (a[i] == 2){
      two++;
    }
    if (a[i] == 3){
      three++;
    }
  }
  vector<vector<vector<double>>> dp(N + 1, vector<vector<double>>(N + 1, vector<double>(N + 1, 1)));
  dp[0][0][0] = 0;
  for (int k = 0; k <= N; k++){
    for (int j = 0; j <= N; j++){
      for (int i = 0; i <= N; i++){
        if (i + j + k > 0 && i + j + k <= N){
          if (i > 0){
            dp[i][j][k] += dp[i - 1][j][k] * i / N;
          }
          if (j > 0){
            dp[i][j][k] += dp[i + 1][j - 1][k] * j / N;
          }
          if (k > 0){
            dp[i][j][k] += dp[i][j + 1][k - 1] * k / N;
          }
          dp[i][j][k] *= (double) N / (i + j + k);
        }
      }
    }
  }
  cout << dp[one][two][three] << endl;
}

Measured memory_bytes: 216832
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        int A = sc.nextInt();
        int B = sc.nextInt();

        if (B % A == 0) {
            WriteLine(A + B);
        } else {
            WriteLine(B - A);
        }
    }
}


class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 11220