akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()

struct str{
	ll L1, L2, L3;
};

char A[15];
ll d1[15][150];
map <ll, str> M1[15][150];
int n;
ll powten[15];

void solve(int tc){
	scanf("%s", A);
	n = (int)strlen(A);
	int s = 0;
	for(int i=0;A[i];i++)s += A[i] - '0';
	ll mul = 1;
	for(int i=0;A[i];i++)mul *= (A[i] - '0' + 1);
	
	d1[0][0] = 1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<10;j++){
			for(int k=0;k<=s-j;k++){
				d1[i][k+j] += d1[i-1][k];
			}
		}
	}
	ll ans = 0;
	for(int i=0;i<s;i++)ans += d1[n][i];
	
	for(int i=0;i<A[0]-'0';i++)M1[1][i][i+1] = str{1, 0, 0};
	M1[1][A[0]-'0'][A[0]-'0'+1] = str{0, 1, 0};
	for(int i=A[0]-'0'+1;i<10;i++)M1[1][i][i+1] = str{0, 0, 1};
	powten[0] = 1;
	for(int i=1;i<=14;i++)powten[i] = powten[i-1] * 10;
	
	for(int i=2;i<=n;i++){
		for(int j=0;j<10;j++){
			for(int u=0;u<=s-j;u++){
				for(map<ll, str>::iterator k=M1[i-1][u].begin(); k!=M1[i-1][u].end(); ++k){
					if(k->Fi * (j+1) > mul)break;
					if(k->Fi * (j+1) * powten[n-i] < mul){
						ans += (k->Se.L1 + k->Se.L2 + k->Se.L3) * d1[n-i][s-u-j];
						continue;
					}
					
					str x = M1[i-1][u][k->Fi];
					M1[i][u+j][(j+1)*k->Fi].L1 += x.L1;
					M1[i][u+j][(j+1)*k->Fi].L3 += x.L3;
					if(j < A[i-1]-'0')M1[i][u+j][(j+1)*k->Fi].L1 += x.L2;
					else if(j == A[i-1]-'0')M1[i][u+j][(j+1)*k->Fi].L2 += x.L2;
					else M1[i][u+j][(j+1)*k->Fi].L3 += x.L2;
				}
			}
		}
		for(int j=0;j<=s;j++)M1[i-1][j].clear();
	}
	ans += M1[n][s][mul].L1;
	printf("%lld\n", ans);
}

int main(){
	int Tc = 1;// scanf("%d",&Tc);
	for(int i=1;i<=Tc;i++){
		solve(i);
	}
	return 0;
}

Measured memory_bytes: 8668
#include <bits/stdc++.h>
using namespace std;
bool cmp(int x, int y)
{
	return x>y;
}
int main()
{
	int n, m;
	cin >> n >> m;
	int a[n+1];
	for (int i=1; i<=n; i++) cin >> a[i];
	sort (a+1, a+n+1, cmp);
	double t=0;
	for (int i=1; i<=n; i++) t+=a[i];
	if (a[m]<(t*1.0/(4.0*m))) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 384
n,x,y=map(int,input().split())

result={}
for i in range(1,n):
    result[i]=0

for i in range(1,n):
    for j in range(i+1,n+1):
        #print(i,j)
        if j-i==1:
            result[1]+=1
        else:
            temp=min(j-i,abs(x-i)+1+abs(j-y))
            result[temp]+=1
for i in range(1,n):
    print(result[i])



Measured memory_bytes: 46556
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 505


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

	ll x, y, z, k;
	cin >> x >> y >> z >> k;
	ll a[x], b[y], c[z];
	for (int i = 0; i < x; ++i)
	{
		cin >> a[i];
	}
	for (int i = 0; i < y; ++i)
	{
		cin >> b[i];
	}
	for (int i = 0; i < z; ++i)
	{
		cin >> c[i];
	}
	sort(a, a + x, greater<ll>());
	sort(b, b + y, greater<ll>());	
	sort(c, c + z, greater<ll>());
	
	// int ia = 0, ic = 0;
	vector<ll> ans;
	// x = min(x, (ll)100);
	// y = min(y, (ll)100);
	// z = min(z, (ll)100);
	// for (int i = 0; i < x; ++i)
	// {
	// 	for (int j = 0; j < y; ++j)
	// 	{
	// 		for (int k = 0; k < z; ++k)
	// 		{
	// 			ans.pb(a[i] + b[j] + c[k]);
	// 		}
	// 	}
	// }
	for (int i = 0; i < x; ++i)
	{
		if((i + 1) > k)
			break;
		for (int j = 0; j < y; ++j)
		{
			if((i + 1) * (j + 1) > k)
				break;
			for (int l = 0; l < z; ++l)
			{
				if((i + 1) * (j + 1) * (l + 1) > k)
					break;
				else
					ans.pb(a[i] + b[j] + c[l]);
			}
		}
	}
	sort(ans.begin(), ans.end(), greater<ll>());
	// x = min(x * y * z, (ll)3000);
	for (int i = 0; i < k; ++i)
	{
		cout << ans[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int a,b,c,i;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    cin>>a>>b>>c;
    for(i=1;i<=1000002;i++)
    {
    	if(a*i%b==c)
    	{
    		cout<<"YES";
    		return 0;
		}
	}
	cout<<"NO";
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, M = map(int, input().split())
G = [[] for _ in [0]*N]
E = []
for _ in [0]*M:
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
    E.append((a, b))


def dfs(v, s, g):
    if v == g:
        return True

    visited[v] = True

    for u in G[v]:
        if visited[u] or v == s and u == g:
            continue
        if dfs(u, s, g):
            return True

    return False


visited = [False]*N

cnt = 0
for a, b in E:
    visited = [False]*N
    visited[a] = True
    if not dfs(a, a, b):
        cnt += 1

print(cnt)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#define rep(i, x, y) for (int i = x; i <= y; i ++)
using namespace std;

const int N = 505;

char G[N][N];
bool cho[N][N];

int main() {
  int n, m, t = 0;
  scanf("%d%d", &n, &m);
  rep(i, 1, n) scanf("%s", G[i] + 1);
  rep(i, 1, n) cho[i][1] = 1;
  for (int i = 1; i <= n; i += 2)
    rep(j, 1, m - 1) cho[i][j] = 1;
  rep(i, 1, n) {
    rep(j, 1, m) {
      if (G[i][j] == '#' || cho[i][j]) putchar('#');
      else putchar('.');
    }
    putchar('\n');
  }
  putchar('\n');
  rep(i, 1, n) {
    rep(j, 1, m) {
      if (G[i][j] == '#' || !cho[i][j]) putchar('#');
      else putchar('.');
    }
    putchar('\n');
  }
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
#define vi vector<int>
#define pb push_back
typedef long long ll;

int main(){
    int n;
    vi a;
    int tmp;
    cin >> n;
    rep(i,n){
        cin >> tmp;
        a.pb(tmp - (i + 1));
    }
    sort(a.begin(),a.end());
    ll sad;
    rep(i,n){
        sad += abs(a[i] - a[n / 2]);
    }
    cout << sad << endl;

    return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
using namespace std;
struct Info
{
	long long int a;
	long long int b;
	long long int c;

	Info(long long int ax, long long int bx, long long int cx)
	{
		a = ax;
		b = bx;
		c = cx;
	}
};

bool cmp(const Info &x, const Info &y)
{
	return x.c > y.c;
}



int main() {
	long long int a[200005] = {}, b[200005] = {}, c[200005] = {}, d, n, m = 0;
	vector<Info> info;
	string str, str2, str3;
	map<int, long long int > mp;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		c[i] = b[i] + a[i];
		info.push_back(Info(a[i], b[i], c[i]));
	}
	sort(info.begin(), info.end(), cmp);

	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			m += info[i].a;
		}
		else {
			m -= info[i].b;
		}
	}



	cout << m;
}

Measured memory_bytes: 7540
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n, m; ll k;
    cin >> n >> m >> k;
    vector<ll> a(n+1), b(m+1);
    rep(i, n) {
        cin >> a[i+1];
        a[i+1] += a[i];
    }
    rep(i, m) {
        cin >> b[i+1];
        b[i+1] += b[i];
    }
    int ans = 0;
    rep(i, n+1) {
        if (a[i] > k) break;
        ll l=0, r=m+1;
        while (r-l > 1){
            ll mid = (l+r)/2;
            if (a[i]+b[mid] <= k) l = mid;
            else r = mid;
        }
        int res = i + l;
        ans = max(ans, res);
    }
    cout << ans;
}


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

long long int compare(long long int* x, long long int* y) {
  return *y-*x;
}

int main() {
  int i;
  int N;
  long long int result;
  long long int* arr;
  scanf("%d\n", &N);
  arr = (long long int*)malloc(sizeof(long long int)*N);
  for ( i = 0; i < N; i++ ) {
    scanf("%lld", &(arr[i]));
  }
  qsort(arr,N,sizeof(long long int),compare);
  result = 0;
  for ( i = 0; i < N-1; i++ ) {
    result += arr[(i+1)/2];
  }
  printf("%lld\n", result);
  free(arr);
  return 0;
}


Measured memory_bytes: 5016
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
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;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  int n,m; cin >> n >> m;
  vector<vector<int>> job(m);
  rep(i,n){
    int a,b; cin >> a >> b;
    if(a > m) continue;
    job[m-a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  for(int i = m-1; i >= 0; i--){
    for(auto j1:job[i]){
      q.push(j1);
    }
    if(!q.empty()){
      ans += q.top(); q.pop();
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

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

const string YES = "Yes";
const string NO = "No";

int main() {
    int N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;

    S = "#" + S + "#";

    auto can_reach = [&](int start, int end) {
        for (int i = start; i + 1 <= end; i++) {
            if (S[i] == '#' && S[i + 1] == '#') return false;
        }
        return true;
    };

    if (!can_reach(A, C) || !can_reach(B, D)) {
        cout << NO << endl;
        return 0;
    }

    if (C > D) {
        bool snuke_can_over = false;
        for (int i = B; i <= D; i++) {
            if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') {
                snuke_can_over = true;
            }
        }
        if (!snuke_can_over) {
            cout << NO << endl;
            return 0;
        }
    }

    cout << YES << endl;
    return 0;
}


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

int divid10 (int n) {
  int sum = 0;
  while(true){
    if (n/10 == 0){
      sum+=n;
      break;
    }
    sum += n%10;
    n /=10;
  }
  return sum;
}

int main(){

  int n,a,b;
  cin >> n >> a >> b;
  int cnt = 0;
  int sum;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    sum = divid10(i);
    if (sum >= a && sum <= b) ans = ans + i;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

vi res(100100,-1);
vector<bool> checked(100100,false);
map<ll, vi> mp;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n,m;
    cin >> n >> m;
    vi a(m), b(m);
    rep(i,m) cin >> a.at(i) >> b.at(i);
    vector<P> v(2*m);
    rep(i,m){
        v.at(i) = make_pair(a.at(i), b.at(i));
        v.at(m+i) = make_pair(b.at(i), a.at(i));
    }

    sort(v.begin(), v.end());
    ll num = 0;
    vi tempv;
    rep(i,2*m){
        if(num!=v.at(i).first){
            mp[num] = tempv;
            tempv.clear();
            num=v.at(i).first;
        }
        tempv.push_back(v.at(i).second);
    }
    mp[num] = tempv;

    // rep(i,n+1){
    //     if(mp.count(i)==0) continue;
    //     for(ll j:mp.at(i)){
    //         cout << "i:" << i << " j:" << j << endl;
    //     }
    // }
    res.at(0) = 1;
    // 1から順に進める
    queue<ll> st;
    st.push(1);
    while(!st.empty()){
        ll j = st.front();
        st.pop();
        if(mp.count(j)==0) continue;
        if(checked.at(j)) continue;
        checked.at(j) = true;
        for(ll i:mp.at(j)){
            if(res.at(i)==-1){
                res.at(i) = j;
            }
            st.push(i);
        };
    }

    string resstr = "Yes";
    for(ll i=2; i<=n; i++){
        if(res.at(i)==-1) resstr = "No";
    }
    if(resstr=="Yes"){
        cout << resstr << endl;
        for(ll i=2; i<=n; i++){
            cout << res.at(i) << endl;
        }
    }else{
        cout << resstr << endl;
    }
}



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

#define PI 3.1415926535
#define X real()
#define Y imag()

typedef complex<double> point;
typedef point vec;

vec rotate(vec v, double r) {
	return v*vec(cos(r), sin(r));
}

void f(int n,point p,point q){
	if(n--==0){
		cout<<setprecision(6)<<fixed<<p.X<<" "<<p.Y<<endl;
		return;
	}
	vec v=(q-p)/(point)3;
	point r=p+v;
	point s=r+rotate(v,PI/3);
	point t=q-v;
	f(n,p,r);
	f(n,r,s);
	f(n,s,t);
	f(n,t,q);
	return;
}

int main(){
	int n;
	cin>>n;
	f(n,(point)0,(point)(100));
	cout<<100<<" "<<0<<endl;
}

Measured memory_bytes: 3228
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		long a = in.nextLong();
		long b = in.nextLong();
		long k = in.nextLong();
		if (a > k)
			System.out.println((a - k) + " " + b);
		else if (b > k - a)
			System.out.println(0 + " " + (b - k + a));
		else
			System.out.println(0 + " " + 0);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    ll n,k;
    cin >> n >> k;
    vector<int> a(n),b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    vector<pair<int,int>> ab;
    rep(i,n){
        ab.emplace_back(a[i], b[i]);
    }
    sort(ab.begin(), ab.end());
    ll cnt = 0;
    rep(i, n)
    {      
        if(cnt + ab[i].second >= k){
            cout << ab[i].first;
            return 0;
        }else{
            cnt += ab[i].second;
        }
    }

}

Measured memory_bytes: 2168
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	ret := a + b

	if ret < (a - b) {
		ret = a - b
	}
	if ret < (a * b) {
		ret = a * b
	}

	fmt.Println(ret)
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;

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

int main() {

    string S,T;
    cin >> S >> T;
    bool isExist = false;
    rep(i,S.length()-T.length()+1){
        if(S[S.length()-1-i]==T[T.length()-1]||S[S.length()-1-i]=='?'){
            ll cnt = 0;
            rep(j,T.length()){
                if(S[S.length()-1-i-j]==T[T.length()-1-j]||S[S.length()-1-i-j]=='?') cnt++;
                else{
                    break;
                }
            }
            if(cnt==T.length()){
                rep(j,T.length()){
                    S[S.length()-1-i-j] = T[T.length()-1-j];
                }
                isExist = true;
                break;
            }
        }
    }
    if(isExist){
        rep(i,S.length()){
            if(S[i]=='?') S[i] = 'a';
        }
        cout << S << endl;
    }else cout << "UNRESTORABLE" << endl;
    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>

#define int long long
#define double long double
#define incin(n) int (n); cin >> (n)
#define uniq(v) sort((v).begin(),(v).end()); (v).erase(unique((v).begin(),(v).end()),(v).end());
using namespace std;
namespace math
{
	double PI = 3.14159265359;
	int step(int n);
	int ncr(int n,int r);
	int npr(int n,int r);
	int gcm(int a,int b);
	int lcm(int a,int b);

	int step(int n){
		if(n<=1){
			return 1;
		}else{
			return n * step(n-1);
		}
	}
	int ncr(int n,int r){
		for(int i=1;i<r;i++){
			n *= n-i;
		}
		for(int i=1;i<r;i++){
			r *= r-1;
		}
		return n/r;
	}
	int npr(int n,int r){
		for (int i = 1; i < r; ++i)
		{
			n *= n-1;
		}
		return n;
	}
	int gcm(int a,int b){
		int p=max(a,b);
		int q=min(a,b);
		int r;
		while(true){
			if(p%q==0){
				return q;
			}
			r = p%q;
			p=q;
			q=r;
		}
	}
}


using namespace std;

signed main (){
	incin(n);
	cout<<(n+1)/2<<endl;
	return 0;
}


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

const int INF = (1 << 30) - 1;
const ll LLINF = 1LL << 60;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int mod = 1000000007;
int N;
int A[200005], B[200005];
int main()
{
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    int ans = 0;
    for(int p = 0; p < 29; p++) {
        int tempa[200005], tempb[200005];
        for(int i = 0; i < N; i++) {
            tempa[i] = A[i] % (1 << (p + 1));
            tempb[i] = B[i] % (1 << (p + 1));
        }
        sort(tempb, tempb + N);
        long long cnt = N;
        for(int i = 0; i < N; i++) {
            cnt -= lower_bound(tempb, tempb + N, (1 << p) * 3 - tempa[i]) - tempb;
            cnt += lower_bound(tempb, tempb + N, (1 << p) * 2 - tempa[i]) - tempb;
            cnt -= lower_bound(tempb, tempb + N, (1 << p) - tempa[i]) - tempb;
        }
        ans |= (cnt & 1) << p;
    }
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 3328
class UnionFindNode(object):

    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.rank_ = 1

    def __str__(self):
        template = "UnionFindNode(group_id: {}, \n\tparent: {}, value: {}, size: {})"
        return template.format(self.group_id_, self.parent_, self.value, self.rank_)

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        root = self.root()
        return root.group_id_

    def rank(self):
        root = self.root()
        return root.rank_

    def unite(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()

        if root.group_id_ != unite_root.group_id_:
            if root.rank() > unite_root.rank():
                unite_root.parent_ = root
                root.rank_ = max(root.rank_, unite_root.rank_ + 1)
            else:
                root.parent_ = unite_root
                unite_root.rank_ = max(root.rank_ + 1, unite_root.rank_)
                
if __name__ == "__main__":
    P,Q=map(int,input().split())
    node_list = [UnionFindNode(i) for i in range(1,P+1)]
    root_num=P
    for i in range(Q):
        a,b,c=map(int,input().split())
        if node_list[a-1].root()!= node_list[b-1].root():
            node_list[a-1].unite(node_list[b-1])
            root_num=root_num-1
    print(root_num)

Measured memory_bytes: 34932
#include <iostream>

using namespace std;

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

    int a;
    cin >> a;
    int min = a;
    int max = a;
    for (int i = 1; i < n; i++) {
         cin >> a;
         if (a < min) {
             min = a;
         }
         if (a > max) {
             max = a;
         }
    }

    cout << max - min << endl;

    return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())

s = list()
offsets = list()

for i in range(-2, 3):
    for j in range(-2, 3):
        offsets.append((i, j))


def print_map(m):
    for mm in m:
        print(mm)


def label(num, x, y):
    res = list()
    if not (0 <= x < h and 0 <= y < w):
        return res
    if s[x][y] != ".":
        return res
    s[x][y] = num

    res += label(num, x - 1, y)
    res += label(num, x + 1, y)
    res += label(num, x, y - 1)
    res += label(num, x, y + 1)

    res.append((x, y))

    return res


def find_next(x, y):
    res = list()

    for offset in offsets:
        xx, yy = x + offset[0], y + offset[1]
        if not (0 <= xx < h and 0 <= yy < w):
            continue

        if s[xx][yy] == ".":
            res.append((xx, yy))

    return res


for i in range(h):
    s.append(list(input()))

stage = 0
labeled = label(stage, dh - 1, dw - 1)

stage += 1

while len(labeled) > 0:
    new_labeled = list()
    for l in labeled:
        nexts = find_next(l[0], l[1])
        for n in nexts:
            new_labeled += label(stage, n[0], n[1])

    labeled = new_labeled
    stage += 1

if s[ch - 1][cw - 1] != ".":
    print(s[ch - 1][cw - 1])
else:
    print(-1)


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

int main() {
	int n;
	cin>>n;
	
	int a[26]={0};
	string s;
	while(n--)
	{
		cin>>s;
		a[s[0]%65]++;
	}
    cout<<"AC x "<<a['A'%65]<<endl;
    cout<<"WA x "<<a['W'%65]<<endl;
    cout<<"TLE x "<<a['T'%65]<<endl;
    cout<<"RE x "<<a['R'%65]<<endl;
	return 0;
}

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

#define    Boost      ios_base::sync_with_stdio(false);cin.tie(NULL);
#define    end        '\n'
#define PI 3.14159

typedef   long long   ll ;

using namespace std;
int main()
{
    Boost;
    int m,n,d;
    cin>>m;
    cin>>n;
    int sum=0;
    for(int i=1; i<=n; i++)
    {
        cin>>d;
        m-=d;
    }

    if(m<0)
        cout<<"-1"<<end;
    else
        cout<<m<<end;

    return 0;

}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for (int i=0;i<N;i++)
    cin >> vec.at(i);
  
  int p = vec.at(0);
  int t=0;
  int j;
  
  for(j=0;j<N;j++){
    t++;
    if(p==2)
      break;
    else
      p=vec.at(p-1);
  }

  if (j==N)
    cout << -1 << endl;
  else
    cout << t << endl;
}


Measured memory_bytes: 640
a=[]
for _ in 1..5
  a << gets.to_i
end
tot = 0
ma = 0
for i in 0..4
  tot += (a[i] + 9) / 10 * 10
  ma = [ma, (a[i] + 9) / 10 * 10 - a[i]].max
end
puts tot-ma

Measured memory_bytes: 3836
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1000000007
#define double long double
using namespace std;
typedef pair<double, double>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll mod_pow(ll x, ll n, ll mod) {
	ll bit = 1;
	while (n) {
		if (n & 1)bit = bit * x % mod;
		x = x * x % mod;
		n /= 2;
	}
	return bit;
}
ll C(ll a, ll b) {
	ll x = 1, y = 1;
	rep(i, b) {
		x = x * (a - i) % inf;
		y = y * (b - i) % inf;
	}
	rep(i, inf) {
		if (x == y * i % inf) {
			return i;
		}
	}
}
ll n;
P a[8];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i].first >> a[i].second;
	sort(a, a + n);
	double mod = 1;
	rep(i, n)mod *= i + 1;
	double ans = 0;
	do {
		double memo = 0;
		rep(i, n - 1) {
			memo += sqrt(pow((a[i + 1].first - a[i].first), 2) + pow((a[i + 1].second - a[i].second), 2));
		}
		ans += memo;
	} while (next_permutation(a, a + n));
	cout << setprecision(8) << ans / mod << endl;
	ggr
}


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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    string s,ans="Good";
    cin >> s;
    if(s[0]==s[1]) ans="Bad";
    if(s[1]==s[2]) ans="Bad";
    if(s[2]==s[3]) ans="Bad";
    
    cout << ans << endl;

    return 0;
}











Measured memory_bytes: 256
#入力
n = int(input())
p = []
for _ in range(n):
    p.append(list(map(int,input().split())))


t = 0
gx = 0
gy = 0
x = 0
y = 0
can = True
for i in range(n):
    gt = p[i][0]
    gx = p[i][1]
    gy = p[i][2]
    flag = False
    while True:
        if gx>x:
            x+=1
            t+=1
        elif gx<x:
            x-=1
            t+=1
        else:
            if gy>y:
                y+=1
                t+=1
            elif gy<y:
                y-=1
                t+=1
            else:
                if t>gt:
                    break
                elif t==gt:
                    flag = True
                    break
                else:
                    x+=1
                    t+=1
    if flag==False:
        can = False
        break

if can:
    print("Yes")
else:
    print("No")


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N,K; cin >> N >> K;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    REP(i,N-K){
        if(A[i] < A[i+K])cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4836
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>

using namespace std;

typedef long long ll;

ll T,A,B,C,D;

int main()
{
	cin >> T;
	while (T--)
	{
		cin >> A >> B >> C >> D;
		if (A < B || D < B)
		{
			puts("No");
			continue;
		}
		ll g = __gcd(B,D);
		if (B / g > (C - A % g) / g + 1 || C < A % g)
		{
			puts("No");
			continue;
		}
		puts("Yes");
	}
	return 0;
} 

Measured memory_bytes: 256
C = [0]*3
for i in range(3):
    l = input().split()
    C[i] = [int(x) for x in l]

# print(C)

A = [0*3]*3
B = [0]*3
B[0] = C[0][0]
B[1] = C[0][1]
B[2] = C[0][2]
A[1] = C[1][0] - B[0]
A[2] = C[2][0] - B[0]

for i in range(3):
    for j in range(3):
        if A[i] + B[j] != C[i][j]:
            print('No')
            exit()

print('Yes')


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int INF = 1001001001;
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 (a>b) { a=b; return 1; } return 0; }

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<P, vector<P>, greater<P>> p;
    rep (i, n) {
        int a, b;
        cin >> a >> b;
        p.emplace(a, b);
    }
    
    ll ans = 0;
    priority_queue<int> q;
    rep (i, 1, m+1) {
        while(!p.empty()) {
            auto r = p.top();
            if (r.first == i) {
                q.push(r.second);
                p.pop();
            }
            else
                break;
        }
        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4824
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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;}

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

using Graph = vector<vector<int>>;
int main(){
  int N, M; cin >> N >> M;
  Graph G(N);
  rep(i, M){
    int a, b; cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> dist(N, -1);
  vector<vector<int>> memo(N);
  queue<int> que;
  dist[0] = 0;
  que.push(0);

  while (!que.empty()){
    int v = que.front(); que.pop();
    for (auto nv: G[v]){
      if (dist[nv] != -1) continue;
      dist[nv] = dist[v] + 1;
      que.push(nv);
      memo[nv].push_back(v);
    }
  }
  bool flag = true;
  rep(i, N) {
    if (dist[i] == -1) flag = false;
  }
  if (flag){
    cout << "Yes" << endl;
    rep(i, N){
      for (auto v: memo[i]){
        cout << v + 1 << endl;
      }
    }
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 15588
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int a,b;
	cin >> a >> b;
	cout << a - b + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
//繝・Φ繝励Ξ
#include <bits/stdc++.h>
//#define int long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,a,b)  for(int i = (a); i <= (b); ++i)
#define ALL(v) (v).begin(),(v).end()
#define PAIR pair<int,int>
using namespace std;
//constexpr int MOD = 10e9+7;
//constexpr int INF = 1LL << 60;
template <class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}  
template <class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}  
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
//



signed main (){
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   string S;
   int A,B;
   cin >> A >> B;
   cin >> S;
   
   if(S[A] != '-') {cout << "No" << endl;return 0;}
   auto l = S.length();
   REP(i,l)
   {
      if(S[i]=='-' && i != A)
      {
         cout << "No" << endl;
         return 0;
      }
   }
   if(l == A+B+1) {cout << "Yes" << endl;}
}



//驛ｨ蛻・・譛蟆丞､
//譖ｴ譁ｰ縺励↑縺・ｴ蜷遺・邏ｯ遨阪ｏ
//莠梧ｬ｡蜈・↓縺励◆縺・・縺・ｂ縺呎ｳ・
//荳邂・園繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Segment Tree(縺溘□縺怜叙蠕涌(logN))
//遽・峇繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Lazy Segment Tree


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  char s[3];
  char t[0];
  while(cin>>s){
    if(s[0]!=s[1]||s[1]!=s[2]){
      cout << "Yes" << "\n";
    }else{
      cout << "No" << "\n";
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll i,j;
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	for(i=k;i<=n+1;i++){
		ll su=1+mod+((2*n+1-i)*i/2)%mod-(i*(i-1)/2)%mod;
		su%=mod;
		//cout<<su<<endl;
		ans+=su;
		ans%=mod;
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 3648
import sys
input=sys.stdin.readline
n, m = map(int, input().split())
A = [0] * m
B = [0] * m
C = [[] for _ in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
    c = list(map(int, input().split()))
    C[i] = c
D = [0] * m
for i in range(m):
    d = 0
    for j in C[i]:
        d |= 1 << (j - 1)
    D[i] = d
# dp[i][s], i番目までの鍵を使ってSを作る最小コスト
infi = 10 ** 20
dp = [[infi for i in range(2 ** n + 1)] for _ in range(m + 1)]
dp[0][0] = 0
for i in range(m):
    for s in range(2 ** n):
        ni = i + 1
        ns = s
        # 使わないとき
        dp[ni][ns] = min(dp[i][s], dp[ni][ns])
        # 使うとき
        ns = s | D[i]
        dp[ni][ns] = min(dp[ni][ns], dp[i][s] + A[i])
ans = dp[m][2 ** n - 1]
print(ans if ans < infi else -1)


Measured memory_bytes: 82780
ans = 0
c = 1
li = ["A","C","G","T"]
s = input()
lens = len(s)
for i in range(lens):
    for j in range(lens-(i)):
        a = s[j:j+i+1]
        for k in range(i+1):
            if a[k] not in li:
                c = 1
                break
            else:
                c = 0
                continue
        if c == 0:
            ans = i+1
        else:
            c = 1
print(ans)

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

using namespace std;

int main(){

       string c;
        cin>>c;

        if(c=="Sunny"){
            cout<<"Cloudy"<<endl;
        }
        else if(c=="Cloudy"){
            cout<<"Rainy"<<endl;
        }
        else if(c=="Rainy"){
            cout<<"Sunny"<<endl;
        }


}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i + 100*j + 50*k == X:
                count += 1


print(count)

Measured memory_bytes: 3060
S = gets.chomp.to_s
 
array = 'a'.upto('z').to_a
 
flag = 0
(0..25).each do |i|
  if array[i] == S
    flag = 1
  elsif flag == 1 and i != 25
    puts array[i]
    break
  elsif i == 25
    puts array[i]
  end
end

Measured memory_bytes: 1788
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <stack>
#include <cmath>
#include <cstring>
#include <climits>
#include <iomanip>
using namespace std;

#define FORN(i, j, k) for(int i=j;i<k;i++)
#define FORR(i, j, k) for(int i=j;i>=k;i--)
#define REP(i, n) FORN(i, 0, n)
#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl '\n'

const int MODO = 1e+9 + 7;
const int INF = 1e18L;
const int MAX = 1e+5 + 5;
const int nax = 3e+3 + 5;

int n;
vector<int> adj[MAX];
int dp[MAX][2];

int dfs(int node, int isBlack, int par){
	if(dp[node][isBlack]!=-1){
		return dp[node][isBlack];
	}
	
	int white = 1;
	int black = isBlack ? 0 : 1;
	int res=1;
	for(int child:adj[node]){
		if(par == child){
			continue;
		}
		white = dfs(child, false, node);
		if(!isBlack){
			black = dfs(child, true, node);
		}
		res = (res*(white+black)%MODO)%MODO;
	}
	
	return dp[node][isBlack] = res;
}


void solve(){
	int x,y;
	REP(i,n-1){
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	memset(dp,-1,sizeof(dp));
	cout << (dfs(1, 0, -1) + dfs(1, 1, -1))%MODO << endl;
	return;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	solve();
	return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  string s;
  cin >> s;
  ll ans = 700;
  REP(i,3) if(s[i]=='o') ans += 100;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            ReadString();
            string s = ReadString();
            bool ans = s.Length % 2 == 0 && s.Substring(0, s.Length / 2) == s.Substring(s.Length / 2);
            Console.WriteLine(ans ? "Yes" : "No");
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 11092
S = input()
S = (S.replace('LR','L R')).split()
def subans(SR):
  rl =len(SR) 
  r = SR.count('R')
  l = rl-r
  r1 = rl//2
  r2 = rl-r1
  ret = [0]*rl
  if r%2==0:
    ret[r-1],ret[r] = r1,r2
  else:
    ret[r-1],ret[r] = r2,r1
  return ret
ans = []
for _ in S:
  ans += subans(_)
print(*ans)

Measured memory_bytes: 9436
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<cmath>
#include<algorithm>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=3e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
ll n,a[maxn],k,fs,zs,zero;
bool check(ll x)//小于等于x的个数 
{
	ll sum=0;
	if(x>=0)
	{
		sum=fs*zs+zero*(fs+zs)+zero*(zero-1)/2;//<=0
		for(ll i=1;i<=n;i++)
		{
			if(a[i]<0)
			{
				ll kk=lower_bound(a+1,a+1+n,x/a[i])-a;
				sum+=(fs-max(i,kk-1));
//				cout<<"!"<<i<<' '<<fs-max(i,kk-1)<<endl;
			}
			if(a[i]>0)
			{
				ll kk=upper_bound(a+1,a+1+n,x/a[i])-a;
				sum+=(max(kk-1,i)-i);
//				cout<<"?!"<<i<<' '<<max(kk-1,i)-i<<endl;
			}
		}
	}
	else
	{
		for(ll i=1;a[i]<0&&i<=n;i++)
		{
			ll kk=lower_bound(a+1,a+1+n,(-x-a[i]-1)/(-a[i]))-a;
			sum+=(n-kk+1);
		}
	}
//	cout<<"?"<<sum<<' '<<x<<endl;
	if(sum>=k)return 1;
	return 0;
}
int main()
{
	scanf("%lld%lld",&n,&k);
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(a[i]<0)fs++;
		else if(a[i]>0)zs++;
		else zero++;
	}
	sort(a+1,a+1+n);
	ll l=-1e18,r=1e18,ans=0;
	while(r-l>1)
	{
		ll mid=(l+r)>>1;
		if(check(mid))r=mid,ans=mid;
		else l=mid;
	//		cout<<l<<' '<<r<<endl;
	}
	printf("%lld",ans);	
}

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

int main(){
    ll l,r,q1,q2,mi,pq;
    cin >> l >> r;
    mi = 2018;
    for(ll i = l; i < r; i++){
        for(ll k = i + 1; k <= r; k++){
            q1 = i % 2019;
            q2 = k % 2019;
            pq = (q1 * q2) % 2019;
            mi = min(mi,pq);
            if(mi == 0){
                break;
            }
        }
        if(mi == 0){
            break;
        }
    }
    cout << mi << endl;
}


Measured memory_bytes: 256
function Main(input) {
  lines = input.split("\n")
  N = lines[0] * 1
  s = lines[1].split(" ").map(function(i){ return i * 1 })

  cnt = 0
  s = s.sort(function(a, b){ return a - b })
  c = s.length / 2 
  ans = s[c] - s[c-1]
  console.log(ans)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}


/**
 * @brief
 * 範囲加算と範囲最大値を求めるセグツリー
 */
template<class T, int MAX_SIZE>
class range_max_add_tree{
private:
    std::size_t size_;
    T unif_adds_[MAX_SIZE];
    T max_des_[MAX_SIZE];
    const T MIN_INF = numeric_limits<T>::min();
  
public:
    range_max_add_tree(){}

    size_t size()
    {
        return size_;
    }
    void init(size_t size)
    {
        // size_は2の倍数に調整する
        size_ = 1;
        while(size_ < size)
            size_ *= 2;
        for(size_t i=0;i<2*size_-1;i++)
            unif_adds_[i] = max_des_[i] = 0;
    }

    // [a,b)に対して+=vする
    void update(size_t a, size_t b, T v)
    {
        update_impl(a, b, 0, 0, size_, v);
    }
  
    // [a,b)の最大値を求める
    T max(size_t a, size_t b)
    {
        return max_impl(a, b, 0, 0, size_);
    }
  
private:  
    void update_impl(size_t a, size_t b, std::size_t k, size_t l, size_t r, T v)
    {
        // 範囲から外れた場合
        if(r<=a||l>=b)return;
        // 完全に含まれる
        else if(a<=l&&b>=r){
            unif_adds_[k] += v;
            max_des_[k] += v;
        }
        else{
            // この範囲に値を加算しておく
            // それ以外は,クエリを分割
            // max_des_[k] += v;
            update_impl(a, b, k * 2 + 1, l, (l + r) /2, v);
            update_impl(a, b, k * 2 + 2, (l + r) / 2, r, v);
            // std::を付けないとこのクラスのpublicメソッドmax が呼ばれる
            max_des_[k] = std::max(max_des_[k * 2 + 1], max_des_[k * 2 + 2]) + unif_adds_[k];
        }
    }
    T max_impl(size_t a, size_t b, std::size_t k, size_t l, size_t r)
    {
        // 完全に含まれる
        if(a<=l&&b>=r){
            return max_des_[k];
        }
        // 範囲から外れた場合
        else if(r<=a||l>=b) return MIN_INF;
        // それ以外は,クエリを分割
        // std::を付けないとこのクラスのpublicメソッドmax が呼ばれる
        return std::max(max_impl(a, b, k * 2 + 1, l, (l + r) /2), 
                        max_impl(a, b, k * 2 + 2, (l + r) / 2, r)) + unif_adds_[k];
    }
};

range_max_add_tree<ll, 1000000> st;
int N, M;
int L[200010];
int R[200010];
int A[200010];
vector<pii> es[200010];

int main(){    

    cin >> N >> M;
    st.init(N + 2);
    for(int i = 0; i < M; i++){
        cin >> L[i] >> R[i] >> A[i];
    }
    for(int i = 0; i < M; i++){
        es[L[i]].push_back(pii(i, 0));
        es[R[i] + 1].push_back(pii(i, 1));
    }

    /*
      dp[i] = max(dp[m] + sum(A[k]))
      を計算する
      mは最後に1にした場所
      k は m < L[k] <= i <= R[k] を満たすもの
     */
    ll ans = 0;
    for(int i = 0; i <= N; i++){
        for(pii p : es[i]){
            int e_id = p.first;
            int is_out = p.second;
            if(!is_out){
                // in
                st.update(0, i, A[e_id]);
            }
            else{
                // out
                st.update(0, L[e_id], -A[e_id]);
            }
        }
        if(i - 1 >= 0) {
            st.update(i, i + 1, st.max(0, i));
            ans = max(ans, st.max(i, i + 1));
        }
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

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

const int MOD = 1e9 + 7;

typedef long long li;

int n, m;
vector<vector<int>> a;

bool can(int k)
{
    vector<char> enabled(m, true);
    vector<int> pos(n, 0);
    
    while (true)
    {
        vector<int> count(m, 0);
        
        for (int i = 0; i < n; i++)
        {
            while (!enabled[a[i][pos[i]]])
            {
                pos[i]++;
                if (pos[i] >= m) return false;
            }
            count[a[i][pos[i]]]++;
        }
        
        bool ok = true;
        for (int i = 0; i < m; i++)
            if (count[i] > k)
            {
                enabled[i] = false;
                ok = false;
            }
            
        if (ok)
            return true;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> m;
    
    a.resize(n, vector<int>(m));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
            a[i][j]--;
        }
        
    // low can't, high can
    int low = 0, high = n;
    
    while (low + 1 != high)
    {
        int m = (low + high) / 2;
        if (can(m))
            high = m;
        else
            low = m;
    }
    
    cout << high << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
using namespace std;
#define max(a, b) ((a>b)?a:b)
const int N = 1e5+1;
int A[N], B[N], C[N];
int n;

int main(){
	int aa, bb, cc;
	scanf("%d", &n);
	A[0] = B[0] = C[0] = 0;
	for(int i=1; i<=n; ++i){
		scanf("%d%d%d", &aa, &bb, &cc);
		A[i] = aa + max(B[i-1], C[i-1]);
		B[i] = bb + max(A[i-1], C[i-1]);
		C[i] = cc + max(A[i-1], B[i-1]);
	}
	printf("%d\n", max(max(A[n], B[n]), C[n]));
}

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

#define pb(a) push_back(a)

typedef long long ll;
const ll inf = 1e9+7;
const int dsize = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;
set<ll> Prime;

ll inv[dsize],fac[dsize];

inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%inf;}a=a*a%inf;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<dsize;i++){fac[i]=fac[i-1]*i%inf;}for(int i=0;i<dsize;i++){inv[i]=POW(fac[i],inf-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%inf)*inv[n-r]%inf;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);Prime.insert(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

int main() {
	int a;
	cin>>a;
	pair<ll,ll> q[a];
	int dif[100005];
	int sum[100005];
	for(int i=0;i<100005;i++){
		dif[0]=0;
		sum[0]=0;
	}
	for(int i=0;i<a;i++){
		cin>>q[i].first>>q[i].second;
	}
	PRI(100000);
	for(int i=1;i<prime.size();i++){
		if(Prime.find((prime[i]+1)/2)!=Prime.end()){
			dif[prime[i]]++;
		}
	}
	for(int i=1;i<100005;i++){
        sum[i] = sum[i-1]+dif[i];
    }
    for (int i = 0;i < a;i++) {
    	cout << sum[q[i].second]-sum[q[i].first-1] << endl;
    }
}

Measured memory_bytes: 3584