akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll d,g;
	cin>>d>>g;
	vector<ll> p(d);
	vector<ll> c(d);
	REP(i,d) cin>>p[i]>>c[i];
	ll ans=INF;
	REP(bit,(1<<d)) {
		bitset<10> bi(bit);
		ll pt=0;
		ll sum=0;
		REP(i,d) {
			if(bi[i]) {
				pt+=c[i]+p[i]*(100*(i+1));
				sum+=p[i];
			}
		}
		if(pt>=g) {
			ans=min(ans,sum);
			continue;
		}
		queue<ll> q;
		for(ll i=d-1; i>=0; i--) {
			if(bi[i]) continue;
			REP(j,p[i]) q.push((i+1)*100);
		}
		while(pt<g&&!q.empty()) {
			pt+=q.front();
			q.pop();
			sum++;
		}
		if(pt>=g) ans=min(ans,sum);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

A, B = read_int()

def solve():
    if (A + B) % 2 == 0:
        return (A + B) // 2
    return 'IMPOSSIBLE'

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

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, k;
    cin >> n >> k;
    multiset<int> h;
    rep(i, n) {
        int a;
        cin >> a;
        h.insert(a);
    }
    ll ans = 0;
    multiset<int>::iterator it = h.begin();
    rep(i, n-k) {
        ans += *it;
        it++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 9600
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int h, w, a, b;
    cin >> h >> w >> a >> b;

    char mat[1010][1010];
    rep(i, 1010) rep(j, 1010) mat[i][j] = '0';

    if (2*a < w) a = w - a;
    if (2*b < h) b = h - b;

    rep(hi, b) {
        rep(wi, a) mat[hi][wi] = '1';
    }

    for (int hi = b; hi < h; hi++) {
        for (int wi = a; wi < w; wi++) {
            mat[hi][wi] = '1';
        }
    }

    rep(hi, h) {
        rep(wi, w) cout << mat[hi][wi];
        cout << '\n';
    }




    return 0;
}



Measured memory_bytes: 2176
#include <limits.h>
#include<iostream>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
using namespace std;

int main(void){
    string s;cin >> s;
    int ans = 7;
    for(int i = 0;i < 3;i++)if(s[i] == 'o')ans++;
    cout << ans*100 << '\n';

    return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

class DisjointSet{
public:
	vector<int> rank, par;

	DisjointSet(){}
	DisjointSet(int size){
		rank.resize(size, 0);
		par.resize(size, 0);
		for(int i=0; i<size; i++){
			par[i]=i;
			rank[i]=0;
		}
	}

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

	void unite(int x, int y){
		x=find(x), y=find(y);
		if(x==y) return;

		if(rank[x]<rank[y]){
			par[x]=y;
		}else{
			par[y]=x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}

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

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

	DisjointSet ds(n+1);
	int p[n+1];
	for(int i=1; i<=n; i++) cin >> p[i];
	for(int i=0; i<m; i++){
		int x, y;
		cin >> x >> y;
		ds.unite(x, y);
	}

	int ans=0;
	for(int i=1; i<=n; i++){
		if(ds.find(i)==ds.find(p[i])) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
n=int(input())
t=list(map(int,input().split()))
m=int(input())
p=[0]*m 
x=[0]*m 
for i in range(m):
    p[i],x[i]= map(int,input().split())
for i in range(m):
    print(sum(t)-t[p[i]-1]+x[i])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
//gcd(x, y) -> xとyの最大公約数
ll gcd(ll x, ll y){
    return y ? gcd(y, x % y) : x;
}
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   ll N, M; cin >> N >> M;
   vector<ll> A(N);
   rep(i,N) cin >> A[i];
   ll lca = A[0];
   for (int i=1; i < N; ++i){
      lca /= gcd(lca, A[i]);
      lca *= A[i];
      if (lca > 2 * M) break;
   }
   int div2 = 1;
   while(A[0]%2 == 0){
      div2 <<= 1;
      A[0]/=2;
   }
   for (int i=1; i < N; ++i){
      if (!((A[i]%div2==0) && (A[i]%(div2<<1)!=0))){
         cout << 0 << endl;
         return 0;
      }
   }
   cout << ((M+lca/2)/lca) << endl;
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll h, w;
    cin >> h >> w;
    vvll c(10, vll(10));
    rep(i, 10)rep(j, 10){
        cin >> c[i][j];
    }
    vvll a(h, vll(w));
    rep(i, h)rep(j, w){
        cin >> a[i][j];
    }
    for(int k = 0; k < 10; k++)
        for(int i = 0; i < 10; i++)
            for(int j = 0; j < 10; j++)
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    ll ans = 0;
    rep(i, h)rep(j, w){
        if(a[i][j] != -1) ans += c[a[i][j]][1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define M_PI 3.1415926535
#define ll long long
#define ld long double
#define all(a) (a.begin(),a.end())
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 1e9 + 7;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
 int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin ) ;
  ll t = 1 ;
  //cin>>t ;
  while(t--)
  {
   ll x;
  cin>>x;
  ll ans =  lcm(x,360ll);
  cout<<ans/x;
  }
  return 0;

}


Measured memory_bytes: 3640
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		if ( C>=A && C<=B) System.out.println("Yes");
		else System.out.println("No");
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<list>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<deque>
#include<string.h>
#include<ctype.h>
using namespace std;

int main(){
  int n, k;
  long long ans = 0;
  cin >> n >> k;
  for (int b = k+1; b <= n; b++){
    ans += ((n+1)/b)*(b-k)+max(0, n-((n+1)/b)*b-k+1);
  }
  if (k == 0){
    ans -= n-k;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
int n,h[10000000],F[10000000];
int main()
{
    //freopen("FROG1.INP","r",stdin);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>h[i];
    F[2]=abs(h[2]-h[1]);
    for (int i=3;i<=n;i++)
        F[i]=min(F[i-1]+abs(h[i]-h[i-1]),F[i-2]+abs(h[i]-h[i-2]));
    cout<<F[n];
    return 0;
}


Measured memory_bytes: 2688
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int 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;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

// index が条件を満たすかどうか

int main() {
	int n;
	cin >> n;
	vector<int> v;
	string p, q;
	int p1, q1;
	for (int i = 0; i < n; i++) {
		string k;
		cin >> k;
		p = p + k;
	}
	for (int i = 0; i < n; i++) {
		string k;
		cin >> k;
		q = q + k;
	}
	for (int i = 1; i <= n; i++) {
		v.push_back(i);
	}
	vector<string>ans;
	do
	{	
		string a;
		for (int i = 0; i < v.size(); i++) {
			a = a + to_string(v[i]);
		}
		ans.push_back(a);
	} while (next_permutation(v.begin(), v.end()));

	for (int i = 0; i < ans.size(); i++) {
		if (q == ans[i]) {
			q1 = i;
		}
		if (p == ans[i]) {
			p1 = i;
		}
	}
	cout << abs(p1 - q1);
}

Measured memory_bytes: 2424
/*#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(class vector<T>::size_type h,class vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
}*/

#include<iostream>
#include<vector>
using namespace std;
class union_find{
private:
    vector<int>parent;
    vector<int>rank;
    int cnt;
public:
    union_find(int vertex_num)
    {
        parent.resize(vertex_num);
        rank.resize(vertex_num);
        for(int i = 0; i < vertex_num; ++i){
            parent[i] = i;
            rank[i] = 0;
        }
        cnt = vertex_num;
    }
    int get_root(int n)
    {
        if(parent[n] == n){
            return n;
        }else{
            return get_root(parent[n]);
        }
    }
    bool is_same(int a, int b)
    {
        return get_root(a) == get_root(b);
    }
    void unite(int a, int b)
    {
        int root_a=get_root(a),root_b=get_root(b);
        if(root_a == root_b)return;
        if(rank[root_a] < rank[root_b]){
            parent[root_a] = root_b;
            --cnt;
        }else if(rank[root_a] > rank[root_b]){
            parent[root_b] = root_a;
            --cnt;
        }else{
            parent[root_a] = get_root(root_b);
            ++rank[root_b];
            --cnt;
        }
    }
    bool is_all_connected()
    {
        return cnt == 1;
    }
};
int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>>ab(m);
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        ab[i] = make_pair(a, b);
    }

    int ans = 0;
    for(int i = 0; i < m; ++i){
        union_find uf(n);
        for(int j = 0; j < m; ++j){
            if(i == j)continue;
            uf.unite(ab[j].first, ab[j].second);
        }
        if(!uf.is_all_connected()){
            ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>

int isPrime(int x);

int main() {
  int i,j,n,m,count=0,num,c;
  scanf("%d",&num);
  for(i = 0;i < num;i++) {
    scanf("%d",&n);
    c = isPrime(n);
    count += c;
    }
  printf("%d\n",count);
  return 0;
  }

int isPrime(int x) {
  int i;
  if(x == 2) return 1;
  if(x < 2 || x % 2 == 0) return 0;
  i = 3;
  while(i <= sqrt(x)) {
    if(x % i == 0) return 0;
    i = i + 2;
  }

  return 1;
}

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

    int my_gcd(int x,int y) {
        if (x%y==0) {
            return y;
        }
        return my_gcd(y,x%y);
    }

int main(void){
    long double K;
    cin >> K;
    

    int64_t sum=0;
    
    for (int i=1;i<K+1;i++) {
        for (int j=1;j<K+1;j++) {
            int gcd1=my_gcd(i,j);
            for (int k=1;k<K+1;k++) {
                int gcd2=my_gcd(gcd1,k);
                sum+=gcd2;
            }
        }
    }
    cout << sum << endl;
    
}




Measured memory_bytes: 3740
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define EPS 1e-8
using namespace std;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
const double pi = acos(-1.0);
int read()
{
	int ret=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret;
}
int n,l,r,ans;
int main()
{
 	#ifdef TEST
	 	freopen("input.txt","r",stdin);
	#endif
	cin>>n;
	ans=0;
	while(n--)
	{
		cin>>l>>r;
		ans+=(r-l+1);
	}
	cout<<ans<<endl;
	return 0;
}



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

using namespace std;

int main() {
  int n, x;
  scanf("%d %d", &n, &x);
  int res = 1;
  vector <int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    if (i != 0)
      a[i] += a[i - 1];
    if (a[i] <= x)
      ++res;
  }
  printf("%d", res);
  return 0;
}


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

int N;
int P[100], Q[100], R[100], B[100];
int T[100];

long long gcd(long long a, long long b) {
  if (a > b) swap(a, b);
  if (a == 0) return b;
  return gcd(b%a, a);
}

long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  if (g == 0) return max(a, b);
  cout << "lcm("<<a<<", "<<b<<") = " << a/g*b<<"\n";
  return a / g * b;
}

long long f(int x) {
  if (x == -1) return 1;
  long long l = f(R[x]), r = f(B[x]);
  long long g = gcd(l*P[x], r*Q[x]);
  return l * r * (P[x] + Q[x]) / g;
}

int main() {
  while (cin >> N) {
    if (N == 0) break;
    for (int i=0; i<N; i++) T[i] = 0;
    for (int i=0; i<N; i++) {
      int r, b;
      cin >> P[i] >> Q[i] >> R[i] >> B[i];
      int g = gcd(P[i], Q[i]);
      P[i] /= g, Q[i] /= g;
      R[i]--, B[i]--;
      if (R[i] >= 0) T[R[i]]++;
      if (B[i] >= 0) T[B[i]]++;
    }
    int root = -1;
    for (int i=0; i<N; i++) {
      if (T[i] == 0) root = i;
    }
    cout << f(root) << "\n";
  }
  return 0;
}

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

int main() {
  int K;
  string S;
  cin >> K >> S;
  if (S.size() <= K) cout << S << endl;
  else {
    for (int i=0; i<K; i++) cout << S.at(i);
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int check(string s){
  if(s=="Vacant") return 0;
  if(s=="Male") return 1;
  return 2;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

vll flag;

void search(ll start, ll end){
  ll mid = (start+end)/2;
  string s;
  cout << mid << endl;
  cin >> s;
  if(check(s)==0) return;
  flag[mid] = check(s);
  if((start+flag[start])%2 == (mid+flag[mid])%2){
    return search(mid, end);
  }else{
    return search(start, mid);
  }
}

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

  flag.resize(N, -1);

  string s;

  cout << "0" << endl;
  cin >> s;

  if(check(s)==0) return 0;
  flag[0] = check(s);

  cout << N/2 << endl;
  cin >> s;
  if(check(s)==0) return 0;
  flag[N/2] = check(s);

  if((N/2+flag[N/2])%2 != (0+flag[0])%2){
    search(0, N/2);
  }else{
    cout << N-1 << endl;
    cin >> s;
    if(check(s)==0) return 0;
    flag[N-1] = check(s);
    search(N/2, N-1);
  }

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
    int n;
    cin>>n;
    vi a(n),b(n),c(n);
    REP(i,n){cin>>a[i];}
    REP(i,n){cin>>b[i];}
    REP(i,n){cin>>c[i];}

    sort(all(a));
    sort(all(c));

    ll ans=0;
    REP(i,n){
        ll ai=lower_bound(all(a),b[i]) - a.begin();
        ll ci=n-(upper_bound(all(c),b[i]) - c.begin());

        ans+=ai*ci;
        //cout<<"  "<<bi<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

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

    vector<vector<ll>> cost_graph(n, vector<ll>(n,0));

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cost_graph[i][j] = i==j ? 0 : 1LL<<60;
        }
    }

    for(int i=0;i<m;i++){
        int src, dst, cost;
        cin >> src >> dst >> cost;
        src--; dst--;
        if(cost>l){continue;}
        cost_graph[src][dst] = cost;
        cost_graph[dst][src] = cost;
    }


    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(cost_graph[i][k] + cost_graph[k][j] < cost_graph[i][j]){
                    cost_graph[i][j] = cost_graph[i][k] + cost_graph[k][j];
                }
            }
        }
    }



    vector<vector<ll>> cost_graph2(n, vector<ll>(n,0));
    vector<vector<ll>> path2(n, vector<ll>(n,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cost_graph2[i][j] = i==j ? 0 : 1LL<<60;
            path2[i][j] = j;
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(cost_graph[i][j] <= l){
                cost_graph2[i][j] = 1;
            }
        }
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(cost_graph2[i][k] + cost_graph2[k][j] < cost_graph2[i][j]){
                    cost_graph2[i][j] = cost_graph2[i][k] + cost_graph2[k][j];
                }
            }
        }
    }



    ll q;
    cin >> q;
    for(int i = 0; i < q; i++){
        ll s, t;
        cin >> s >> t;
        s--; t--;

        ll ans = cost_graph2[s][t]-1;
        if(cost_graph2[s][t] == 1LL<<60){ans = -1;}
        cout << ans << endl;
    }

    return 0;

}


Measured memory_bytes: 2688
N, M = map(int, input().strip().split())

s_list = list()
e_list = list()

for m in range(M):
    s, e = map(int, input().strip().split())
    s_list.append(s)
    e_list.append(e)

s_max = max(s_list)
e_min = min(e_list)

if s_max > e_min:
    print(0)
else:
    print(e_min-s_max+1)


Measured memory_bytes: 11052
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>

using namespace std;

int main(){
    int  n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a.at(i);
    for(int j=n-1;j>=0;j--){
        cout<<a.at(j);
        if(j!=0)cout<<" ";

    }
    cout<<endl;
}


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

// template {{{
/* vim: set foldmethod=marker: */

// constant
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const double PI = acos(-1);
#define EPS 1e-14

// typedef
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

// input
template <class T> inline T in_(){ T x; cin >> x; return x; }

// short
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define REPit(type, i, obj) for (type::iterator i = (obj).begin(); i != (obj).end(); i++)
#define RREPit(type, i, obj) for (type::iterator i = (obj).rbegin(); i != (obj).rend(); i++)

// container util
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define sz(obj) obj.size()
#define sza(ary) (sizeof(ary) / sizeof(*ary))
#define sort(obj) sort(all(obj))
#define exist(obj, key) ((obj).find(key) != (obj).end())
#define cleAR(ary) memset((ary), 0, sizeof(ary))

// print util
#define print(x) cout << (x) << endl
#define printd(x, d) cout << fixed << setprecision(d) << (x) << endl
#define printv(v) REP(i, sz(v)) cout << v[i] << "\n "[i < sz(v) - 1]
#define printa(ary) REP(i, sza(ary)) cout << ary[i] << "\n "[i < sza(ary) - 1]
#define dump(x) cerr << #x << ": " << (x) << endl
#define debug(x) cerr << #x << ": " << (x) << " (" << __LINE__ << ")" << endl

//template }}}

#define in in_<int>

signed main()
{
    int n = in();
    vi l;
    REP(i, n * 2){
        l.push_back(in());
    }

    sort(l);
    int cnt = 0;
    for (int i = 0; i < n * 2; i += 2) cnt += l[i];
    print(cnt);

    return 0;
}


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

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

    set<string> lottery;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        lottery.insert(s);
    }
    cout<<lottery.size();
}


Measured memory_bytes: 19268
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int a;
    cin >> a;
    cout << a * a * a << endl;
}


Measured memory_bytes: 3056
s = gets.strip.split('')
t = gets.strip.split('')

if t.length > s.length
  puts 'UNRESTORABLE'
  exit
end

target_indice = []
(s.length-t.length+1).times do |index|
  target_indice.push(index) if s.slice(index, t.length).zip(t).all? {|c_s, c_t| c_s==c_t || c_s=='?' }
end

if target_indice.empty?
  puts 'UNRESTORABLE'
  exit
end

result = target_indice.map {|i|
  tmp = s.dup
  tmp[i..i+t.length-1]=t
  tmp.map {|c| c=='?' ? 'a' : c }.join('')
}.sort.first
puts result


Measured memory_bytes: 1916
n, m = [int(x) for x in input().split()]
img_a = [input() for _ in range(n)]
img_b = [input() for _ in range(m)]

flag = False
for a in range(n - m + 1):
    border = 0
    isok = True
    while isok and not flag:
        for b in range(m):
            if img_b[b] in img_a[b+a][border:]:
                if b == 0:
                    index = img_a[a].index(img_b[0], border)
                current_index = img_a[b+a].index(img_b[b], border)
                if current_index == index:
                    continue
                elif current_index > index:
                    border = current_index
                    break
                else:
                    border = index
                    break
            else:   # if not substring in string.
                isok = False
                break

        else: # if not loop broken.
            ans = "Yes"
            flag = True
            break
    if flag:
        break
else:
    ans = "No"
        
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int k = s.nextInt();
		int i = 0;
		long ans = 1;

		for (i = 0; i < n-1; i++) {

			if (n == 1) {

			} else if (1 < n) {
				ans = ans * (k - 1);
			}

		}
		System.out.println(ans * k);

	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define RANGE(i,n) for(int i=0;i<n;i++)
typedef long long ll;

using namespace std;

signed main() {
    int N, K;
    cin >> N >> K;
    int ans = 0;
    vector<char> S(N);
    RANGE(i, N) cin >> S[i];
    int index = 0;
    queue<int> q;
    int now_sak = 0;
    while(index < N){
        int ren_one = 0;
        while( index < N && S[index] == '1'){
            ren_one++;
            index++;
        }

        ans = max(ans, now_sak + ren_one); 

        int ren_zero = 0;
        while( index < N && S[index] == '0'){
            ren_zero++;
            index++;
        }
        if(q.size() == K){
            now_sak -= q.front();
            q.pop();
        }
        q.push(ren_one + ren_zero);
        now_sak += ren_one + ren_zero;

        ans = max(ans, now_sak); 
    }
    cout << ans << endl;
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ll A,B,C;
  cin >> A >> B >> C;
  ll ans = B;
  ans += min(A+B+1,C);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner scan=new Scanner(System.in);
		String str=scan.next();
		int c1=0;
		int c2=0;
		for(int i=0;i<str.length();i++) {
			if(i%2==0) {
				if(str.charAt(i)=='0') {
					c1++;
				}
				else {
					c2++;
				}
			}
			if(i%2==1) {
				if(str.charAt(i)=='1') {
					c1++;
				}
				else {
					c2++;
				}
			}
		}
		System.out.println(Math.min(c1, c2));
	}
}

Measured memory_bytes: 25840
// 基本テンプレート
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;


int A[1010];
const int B = 40;

signed main() {
    int N, K; cin >> N >> K;

    vector<int> sum;
    for(int i=0; i<N; i++) {
        cin >> A[i+1];
        A[i+1] += A[i];
    }

    for(int l=0; l<N; l++) {
        for(int r=l+1; r<=N; r++) {
            sum.push_back(A[r] - A[l]);
        }
    }

    int ans = 0;
    for(int i=50; i>=0; i--) {
        int target = ans | (1LL << i);
        int cnt = 0;
        for(auto x : sum) {
            if((target & x) == target) cnt++;
        }
        if(cnt >= K) {
            ans |= (1LL << i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6256
#include <iostream>

using namespace std;

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

int x[50];
long long dp[55][55][3000];

int main() {
  int N, A;
  cin >> N >> A;

  for (int i = 0; i < N; ++i) {
    cin >> x[i];
  }

  dp[0][0][0] = 1;
  for (int i = 1; i <= N; ++i) {
    int _x = x[i - 1];
    for (int k = 0; k <= i; ++k) {
      for (int s = 0; s < 3000; ++s) {
        dp[i][k][s] = dp[i - 1][k][s];
        if (_x <= s && k > 0) dp[i][k][s] += dp[i - 1][k - 1][s - _x];
      }
    }
  }

  long long cnt = 0;
  for (int i = 1; i <= N; ++i) {
    cnt += dp[N][i][i * A];
  }

  cout << cnt << endl;
}


Measured memory_bytes: 34876
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val pw = new java.io.PrintWriter(System.out)
  val n = sc.nextInt()
  val s = for(i <- 0 until n) yield (i+1, sc.next(), sc.nextInt())
  val ans = s.toList.sortBy(x => (x._2, -x._3)).map(x => x._1).toList
  ans.foreach(pw.println(_))
  pw.flush()
}

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

typedef long long int ll;

const int N = 1e5+7;

const ll mod = 1e9 + 7;
vector<int> g[N];
void eadd(int u,int v)
{
  g[u].push_back(v);
  g[v].push_back(u);
}

ll dp[N][2];

void dfs(int u=1, int col = 0, int p=0)
{
  //~ cerr << u << ' ' << col << endl;
  if(~dp[u][col]) return ;
  
  dp[u][col] = 1;
  for(int v: g[u])
  {
    if(v == p) continue;
    if(col == 0)
    {
      dfs(v, 0, u);
      dfs(v, 1, u);
      dp[u][col] = dp[u][col] * (dp[v][0] + dp[v][1]) % mod;
    }else
    {
      dfs(v, 0, 1);
      dp[u][col] = dp[u][col] * dp[v][0] % mod;
    }
  }  
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int n;
  cin >> n;
  
  //~ if(n == 1) return !(cout << "2\n");
  
  for(int i=1;i<n;++i)
  {
    int u, v;
    cin >> u >> v;
    eadd(u, v);
  }
  
  memset(dp, -1, sizeof dp);
  
  dfs();
  dfs(1, 1);
  
  //~ cerr << dp[1][0] << ' ' << dp[1][1] << endl;
  
  cout << (dp[1][0] + dp[1][1]) % mod << endl;
  
  return 0;
}


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

int main()
{
    int N, H;
    cin >> N >> H;
    int a[N];
    int b[N];
    for (int i = 0; i < N; i++)
    {
        cin >> a[i] >> b[i];
    }

    sort(a, a + N);
    reverse(a, a + N);

    sort(b, b + N);
    reverse(b, b + N);

    int ans = 0;
    while (b[ans] >= a[0] && ans < N && H > 0)
    {
        H -= b[ans];
        ans++;
    }

    while (H > 0)
    {
        ans++;
        H -= a[0];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    

    
    int a, b;
    cin >> a >> b;
    int m = max(a + b, a - b);
    m = max(m, a * b);

    cout << m << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

class SegmentTree:
    def __init__(self, N, func, I):
        self.func = func
        self.I = I
        self.N = N
        self.sz = 2**(N-1).bit_length()
        self.seg = [I] * (self.sz * 2)
 
    def assign(self, k, x):
        self.seg[k + self.sz] = x
 
    def build(self):
        for i in reversed(range(1,self.sz)):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])
 
    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k >>= 1
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])

    def query(self, a, b):
        L = self.I
        R = self.I
        a += self.sz
        if b == self.N:
            b = self.sz
        b += self.sz
        while a < b:
            if a & 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b & 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a >>= 1
            b >>= 1
        return self.func(L, R)

def main():
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    N = int(readline())
    L = list(map(int,readline().split()))
    seg = SegmentTree(N , gcd , 0)
    for i,n in enumerate(L):
        seg.assign(i , n)
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
    print(ans)

main()


Measured memory_bytes: 58224
n = int(input())
A = [*map(int, input().split())] + [0]
yen, stock = 1000, 0
nxt = A[0]
for now in A[1:]:
    now, nxt = nxt, now
    if now < nxt:
        stock += yen // now
        yen -= yen // now * now
    else:
        yen += stock * now
        stock = 0
print(yen + stock * nxt)


Measured memory_bytes: 9176
N, K = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)

posi = []
nega = []
zeros = 0
A.each do |ai|
  if ai < 0
    nega << ai
  elsif ai > 0
    posi << ai
  else
    zeros += 1
  end
end

posi.sort!
nega.sort!.reverse!

posi_size = posi.size
nega_size = nega.size

zero_pairs = zeros * (zeros - 1) / 2 + zeros * (N - zeros)

ng = -(10**18 + 1)
ok = 10**18 + 1

while ok - ng > 1
  mid = (ok + ng) / 2
  cnt = 0
  
  cnt += zero_pairs if mid >= 0

  if mid > 0
    cnt += nega_size * posi_size
    [posi, nega].each do |a|
      l = 0
      r = a.size - 1
      while l < r
        r -= 1 while l < r && a[l] * a[r] > mid
        cnt += r - l
        l += 1
      end
    end
  else
    r = nega_size - 1
    posi.size.times do |l|
      r -= 1 while(r >= 0 && posi[l] * nega[r] <= mid)
      cnt += nega_size - r - 1
    end
  end

  cnt >= K ? (ok = mid) : (ng = mid)
end

puts ok

Measured memory_bytes: 22452
#include <string>
#include <iostream>
using namespace std;
int n, a, c; string s;
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &a), s += (char)(a + 48);
	while(true) {
		if(s.find(to_string(c++)) == string::npos) {
			printf("%d\n", --c); break;
		}
	}
	return 0;
}

Measured memory_bytes: 3336
# -*- coding: utf-8 -*-
# A - One Card Poker
# 標準入力の取得
A,B = list(map(int, input().split()))

# 1⇒14と見なしてから、大きさを比較
if A == 1:
    A = 14
if B == 1:
    B = 14

if A == B:
    print("Draw")
elif A > B:
    print("Alice")
else:
    print("Bob")

Measured memory_bytes: 3060
# 169A
# A × B を整数として出力せよ。

# １．入力をプログラムで扱えるように受け取ること
a, b = map(int, input().split())
# print(a, b)


# ２．受け取った入力値を使って、適切に書類（計算）すること
answer = a * b

# ３．計算した結果を出力すること
print(answer)

Measured memory_bytes: 9160
#include <stdio.h>

int main() {
	int N = 0;
	int i = 0;
	int flag = 0, flag1 = 0, flag2 = 0;
	int result1[102] = {};
	int result2[102] = {};
	scanf("%d", &N);
	for (i = 0; i <= N; i++) {
		scanf("%d %d", &result1[i], &result2[i]);
	}
	for (i = 0; i <= N; i++) {
		if (result1[i + 2] == 0) {
			break;
		}

		if (result1[i] == result2[i]) {
			flag = 1;
		}

		if (flag) {
			if (result1[i + 1] == result2[i + 1]) {
				flag1 = 1;
			}
			else {
				flag = 0;
			}
		}

		if (flag1) {
			if (result1[i + 2] == result2[i + 2]) {
				flag2 = 1;
				break;
			}
			else {
				flag = 0;
				flag1 = 0;
			}
		}
	}
	if (flag2) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
			
void solve() {		
	int k;
	cin >> k;
	ll num = 7 % k, i = 0;
	map<int, int> m;
	while(1) {
		m[num]++;
		if(m[num] > 1) {
			cout << -1 << endl;
			return;
			}
			if(!num) {
				cout << i + 1 << endl;
				return;
				}
				num = ((num * 10) + 7) % k;
				i++;
		}
}


	

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	solve();
	return 0;
}






Measured memory_bytes: 50436
# include <cstdio>
# include <iostream>
# include <vector>
# include <map>
# include <set> 
# include <algorithm> 
# include <string>
# include <cstring>
# include <queue> 
# include <stack> 
# include <cstdlib> 

using namespace std ; 

int main()
{
	string S ; 
	cin >> S ; 
	cout << S[0] << S[1] << S[2] << "\n";
	return 0 ; 
}

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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int x, y;
  cin >> x >> y;

  for(int i=0; i<x+1; ++i){
    int b = x - i;
    if(2 * i + 4 * b == y){
      cout << "Yes";
      return 0;
    }
  }

  cout << "No";
  return 0;
}

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

int main(){
 int N;
 cin>>N;
 vector<int>v(N+1);
 for(int i=1;i<=N;i++){
    cin>>v[i];
 }

 int *dp = new int [N+1]();
 dp[1]=0;
 dp[2]=abs(v[2]-v[1]);

 for(int i=3;i<=N;i++){
  dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
 }
cout<<dp[N]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;
int main() {fio;
	int h, w, n, sx, sy;
	cin >> h >> w >> n >> sx >> sy;
	string s, t;
	cin >> s >> t;
	int left = sy, right = sy, up = sx, down = sx;
	for(int i = 0; i < n; i++) {
		left = min(left, w);
		left = max(left, 1);
		right = min(right, w);
		right = max(right, 1);

		up = min(up, h);
		up = max(up, 1);
		down= min(down, h);
		down= max(down, 1);

		if(s[i] == 'L') left--;
		if(s[i] == 'R') right++;
		if(s[i] == 'U') up--;
		if(s[i] == 'D') down++;
		if(left <= 0 || right > w || up <= 0 || down > h) {
			cout << "NO\n";
			return 0;
		}
		if(t[i] == 'L') right--;
		if(t[i] == 'R') left++;
		if(t[i] == 'U') down--;
		if(t[i] == 'D') up++;
	}
	cout << "YES\n";
    return 0;
}

Measured memory_bytes: 4032
#include <iostream>
#include <iomanip>
#include <set>
#include <algorithm>
using namespace std;

void Main() {
    // input
    int N;
    cin >> N;
    set<int> ans;
    for (int i = 0; i < N; i++) {
        int num;
        cin >> num;
        ans.insert(num);
    }


    // translate



    // output
    cout << ans.size() << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int *h;

int cost(int i, int j) {
	return abs(h[j] - h[i]);
}

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

	h = new int[n];
	int *DP = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	DP[0] = 0;
	DP[1] = cost(0,1);

	for (int i = 2; i < n; i++) {
		if (DP[i - 1] + cost(i - 1, i) < DP[i - 2] + cost(i - 2, i))
			DP[i] = DP[i - 1] + cost(i - 1, i);
		else
			DP[i] = DP[i - 2] + cost(i - 2, i);
	}

	cout << DP[n-1] << endl;

	delete[] DP;
	delete[] h;

	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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


int main() {
	int n, m;
	while (cin >> n >> m, n){
		int ma = 2;
		vector<string> code(n);
		vector<string> spell;
		set<string> ss;
		REP(i, n){
			cin >> code[i];
		}
		REP(i, n){
			REP(j, m){
				REP(k, 8){
					string s = "";
					int y=i;
					int x=j;
					while (1){
						s += code[y][x];
						if (s.length() >= ma){
							if (ss.find(s) == ss.end()){
								ss.insert(s);
							}else{
								if (ma < s.length()){
									ma = s.length();
									spell.clear();
								}
								spell.push_back(s);
								}
						}
						y += dy8[k]+n;
						y%=n;
						x +=dx8[k]+m;
						x%=m;
						if (y==i&&x==j)break;
					}
				}
			}
		}
		
		
		if (spell.empty())
			cout << "0"<<endl;
		else{
			SORT(spell);
			cout << spell[0] << endl;
		}
	}
}

Measured memory_bytes: 34212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
#include <sstream>


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



int main() {

	string S;
	

	cin >> S;

	rep(i, S.size())
	{
		S[i] = 'x';
	}
	cout << S << endl;

	return 0;
}




Measured memory_bytes: 256