akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

/**
 * Who Says a Pun?
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            String S = sc.next();

            int max = 0;
            for (int i = 0; i < N; i++) {
                int[] prefix = zAlgorithm(S.substring(i));
                for (int j = 1; j < prefix.length; j++) {
                    if (max < prefix[j]) {
                        if (prefix[j] < j) {
                            max = prefix[j];
                        } else if (max < j) {
                            max = j;
                        }
                    }
                }
            }

            System.out.println(max);
        }
    }

    public static int[] zAlgorithm(String S) {
        int[] prefix = new int[S.length()];

        for (int i = 1, j = 0; i < S.length(); i++) {
            if (i + prefix[i - j] < j + prefix[j]) {
                prefix[i] = prefix[i - j];
            } else {
                int k = Math.max(0, j + prefix[j] - i);
                while (i + k < S.length() && S.charAt(k) == S.charAt(i + k)) {
                    k++;
                }
                prefix[i] = k;
                j = i;
            }
        }

        prefix[0] = S.length();

        return prefix;
    }

}


Measured memory_bytes: 48928
from collections import deque
S=deque(input())
Q=int(input())
re=True
cnt=0
for i in range(Q):
    q=list(map(str,input().split()))
    if q[0]=='1':
        cnt+=1
        if re==True:
            re=False
        else:
            re=True
    else:
        if re==True:
            if q[1]=='1':
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if q[1]=='2':
                S.appendleft(q[2])
            else:
                S.append(q[2])
if cnt%2==1:
    S.reverse()
print(*S,sep='')

Measured memory_bytes: 16696
//abc127_c.cpp
//Thu Jun 27 22:32:29 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int l[m],r[m];
	int lborder,rborder;
	lborder = 0;
	rborder = n-1;
	for (int i=0;i<m;i++){
		cin >> l[i] >> r[i];
		l[i]--;
		r[i]--;
		if (l[i]>lborder){
			lborder = l[i];
		}
		if (r[i]<rborder){
			rborder = r[i];
		}
	}

	cout << max(rborder-lborder+1,0) << endl;
}

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

int main(){
	int n;
	cin >> n;
	long long int ans =0;
	for(int i=1;i<=n;i++){
		if(i%3!=0&&i%5!=0){
			ans = ans+i;
		}
	}
	cout << ans << endl;;
}


Measured memory_bytes: 3632
N = int(input())
d = [int(input()) for _ in range(N)]

# 重複を除いた要素数を数えるために、setを使う以外にバケット法による方法がある
l = [0]*100
for i in range(N):
  l[d[i]-1] = 1
  
print(sum(l))

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;

int main(int argc, char * * argv) {
	int N, K, x, ans = 0;
	scanf("%d%d", &N, &K);
	vector<int> mp(10);
	rep(i, 0, K) {
	    scanf("%d", &x);
	    mp[x] = 1;
	}
	bool ok;
	int n = N;
	while(!ans) {
	    ok = true;
	    N = n;
	    while(N) {
	        if(mp[N%10]) ok = false;
	        N /= 10;
	    }
	    if(ok) ans = n;
	    ++n;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;

    for(int i=0; i<s.size(); i++){
	cout << s[i];
	if(i==t.size())
	    break;
	cout << t[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#define N 505
using namespace std;
typedef long long ll;
int c[505]; //到一个车站的花费时间
int s[505]; //一个车站出发的等待时间
int f[505];  //一个车站每f秒出发一个车
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d%d",&c[i],&s[i],&f[i]);
    for(int i=1;i<=n;i++){
        int ans=0;
        for(int j=i;j<n;j++){
            if(ans<s[j])   //小于等待时间重新赋值
                ans=s[j];
            if(ans%f[j]!=0)    //是否处于间隔时间
                ans=ans+f[j]-ans%f[j];
            ans+=c[j];
        }
        printf("%d\n",ans);
    }
}



Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] H = new long[N];
        H[0] = sc.nextLong();
        int max = 0;
        int count = 0;
        for(int i = 1; i < N; i++) {
            H[i] = sc.nextLong();
            if(H[i-1] >= H[i]) {
                count++;
            }else {
                if(max < count) {
                    max = count;
                }
                count = 0;
            }
        }
        
        if(count > max) {
            max = count;
        }
        
        System.out.println(max);
        
        
    }
}

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a; cin >> a;
	string s; cin >> s;
	cout<<(a>=3200 ? s : "red") << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

int main() {
	int a, b, c; cin >> a >> b >> c;
	int cnt = 0;
	for (; a <= b; a++)
		if (c % a == 0) cnt++;
	cout << cnt << endl;
}

Measured memory_bytes: 1160
import java.io.*;
import java.util.*;
import java.math.*;
public class Main{

    static long M=(long)1e9+7;
    
    public static void main(String[] args) {
        FastReader fs=new FastReader();
        String s=fs.next();
        char[] ss=s.toCharArray();
        if (ss[2]==ss[3] && ss[4]==ss[5]){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
    
    public static long min(long a, long mod){
        return pow(a, mod-2,mod);
    }
    public static long mul(long a,long b,long mod){
        long res=0;
        while(b!=0){
            if ((b & 1) == 1){ res = (res + a) % mod;}
            a = (a + a) % mod;
            b >>= 1;
        }
        return res;
    }
    
    public static long pow(long a, long n, long mod){
        long res=1;
        while(n != 0){
            if ((n & 1) == 1) res = mul(res, a, mod)%mod;
            a = mul(a , a, mod)%mod;
            n >>= 1;
        }
        return res;
    }
    
    public static long gcd(long a, long b){
        if(a == 0) return b;
        return b == 0 ? a: gcd(b, a % b);
    }

    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
}

Measured memory_bytes: 22996
import collections
N,K,Q = map(int,input().split())
A = []

for i in range(Q):
  a = int(input())
  A.append(a)

for i in range(N):
  A.append(i+1)

counter = collections.Counter(A)
counter = [list(e) for e in counter.items()]
for i in range(N):
  counter[i][1] = counter[i][1]-1
  counter[i][1] = Q-counter[i][1]

for i in range(N):
  point = K - counter[i][1]
  
  if(point <= 0): 
    print('No')
  else: 
    print('Yes')

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2000 + 5;
const ll INF = 1e17 + 7 , mod = 1e9 + 7;
const double eps = 1e-9 , PI = acos(-1);



int S;
ll mem[N];

ll add(ll a , ll b) {
    return (a%mod + b%mod) % mod;
}

ll dp(int sum) {
    if(sum > S) return 0;
    if(sum == S) return 1ll;

    ll &ret = mem[sum];
    if(ret != -1) return ret;

    ret = 0;

    for(int i = 3 ; i + sum <= S ; i ++) ret = add(ret , dp(i + sum));

    return ret;

}

void solve(int testCase){

    scanf("%d" , &S);

    memset(mem , -1 , sizeof mem);

    printf("%lld\n" , dp(0));

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


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

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    int h, w;
    cin >> h >> w;
    vector<char> c(w, 0);
    for (size_t i = 0; i < h; i++)
    {
        for (size_t j = 0; j < w; j++)
        {
            cin >> c[j];
            /* code */
        }
        for (size_t k = 0; k < 2; k++)
        {
            for (size_t l = 0; l < w; l++)
            {
                cout << c[l];
            }
            cout << endl;
        }
    }

    return 0;
}

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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

bool my_compare(pair<ll, ll> x, pair<ll, ll> y) {
  return x.second > y.second;
}

ll N = 0;
ll M = 0;
ll ret = 0;
priority_queue< ll, vector<ll>, greater<ll> > cards;
vector<pair<ll, ll>> man;

void input() {
  IN(N);
  IN(M);
  ll a;
  REP(i, N) {
    IN(a);
    cards.push(a);
  }
  ll b, c;
  REP(i, M) {
    IN(b);
    IN(c);
    man.pb(mp(b, c));
  }
  sort(ALL(man), my_compare);
}

void solve() {
  REP(i, M) {
    if (man[i].second <= cards.top()) {
      break;
    }
    REP(j, man[i].first) {
      if (man[i].second > cards.top()) {
        cards.pop();
        cards.push(man[i].second);
      } else {
        break;
      }
    }
  }
  while(!cards.empty()) {
    ret += cards.top();
    cards.pop();
  }
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


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

l_count = [0]*n

for i in range(1, n):
    for j in range(i+1, n+1):
        if i <= x:
            if j <= x:
                l_count[j-i] += 1
            elif x < j < y:
                l_count[min(j-i, x-i + y-j + 1)] += 1
            elif y <= j:
                l_count[x-i + j-y + 1] += 1
        elif x < i < y:
            l_count[min(j-i, i-x + abs(y-j) + 1)] += 1
        else:
            l_count[j-i] += 1
for i in range(1, n):
            print(l_count[i])

Measured memory_bytes: 3444
#include<stdio.h>
static int N=1000;
void irekae(int A[],int n){
   int i;
    for(i=0;i<n;i++){
      if(i>0) printf(" ");
      printf("%d",A[i]);
    }
    printf("\n");
 }
int main(){
  int a,n,i,j,A[N];
 scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  irekae(A,n);
  for(j=1;j<n;j++){
     a=A[j];
     i=j-1;
    while(i>=0&&A[i]>a){
      A[i+1]=A[i];
      i=i-1;
    }
    A[i+1]=a;
    irekae(A,n);
  }
  return 0;
}



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

unordered_map<int,unordered_map<int,int>> mp;

int main(){
	int h,w,m,a,b;
	cin >> h >> w >> m;
	pair<int,int> row[h],col[w];
	for(int i = 0;i < h;i++) row[i].first = 0,row[i].second = i;
	for(int i = 0;i < w;i++) col[i].first = 0,col[i].second = i;
	while(m--){
		cin >> a >> b;
		a--,b--;
		row[a].first++;
		col[b].first++;
		mp[a][b] = 1;
	}
	sort(row,row+h,greater<>());
	sort(col,col+w,greater<>());
	int maxm = INT_MIN;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			int curr = row[i].first + col[j].first;
			if(!(mp.find(row[i].second) != mp.end() && mp[row[i].second].find(col[j].second) != mp[i].end())){
				maxm = max(maxm,curr);
				break;
			}
			else{
				curr--;
				maxm = max(maxm,curr);
			}
		}
	}
	cout<<maxm;
}

Measured memory_bytes: 54280
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN 2*int(1e5)+5
#define endl '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
const ll mod = 1e9+7;

int main(){
	ll h, n;
	cin >> h >> n;
	ll sum = 0;
	while(n--) {
		int x;
		cin >> x;
		sum += x;
	}
	cout << (sum >= h ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

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

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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 gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vi c(n-1), s(n-1), f(n-1);
  rep(i, n-1) cin >> c[i] >> s[i] >> f[i];

  vi t(n);
  rep(i, n){
    if(i == n-1) t[i] = 0;
    else t[i] = s[i];
    for (int j = i; j < n-1; j++) {
      if(t[i] < s[j]) t[i] = s[j];
      else{
        int r = (t[i]-s[j])%f[j];
        if(r != 0) t[i] += f[j] - r;
      }
      t[i] += c[j];
    }
  }
  rep(i, n) std::cout << t[i] << '\n';
}


Measured memory_bytes: 256
#include <stdio.h>

int
main(void) {
	int A, B, N;
	scanf("%d %d %d", &N, &A, &B);
	int min;
	if (A * N > B) {
		min = B;
	}else {
		min = A * N;
	}
	
	printf("%d\n", min);
	return 0;
}

Measured memory_bytes: 128
#[warn(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1}
};

#[fastout]
fn main() {
   input! {
      n: usize,
      a: [usize; n]
   }
   let mut dp = vec![0 as usize; n];
   let mut ans: usize = 0;
   for i in 1..=n {
      if a[i-1] <= i {
         ans += dp[i-a[i-1]];
      }
      if a[i-1] + i < n {
         dp[a[i-1]+i] += 1;
      }
   }
   println!("{}", ans);
}


Measured memory_bytes: 6612
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
	int n;
	cin >> n;
	vector<ll> l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
		
	}
	
int ans = 0;
	for (int i = 0; i < n-2; i++) {
			for (int j = i+1; j < n-1; j++) {
				for (int k = j+1; k < n; k++) {
					if (l[i]!=l[j]&& l[j] != l[k] && l[k] != l[i] && l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j]) {
						ans++;
					}
				}
			}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int n, res, tem, a[111];
int main()
{
    res=4000010;
    cin>>n;for(int i=0;i<n;++i)cin>>a[i];
    for(int i=-100;i<=100;++i){tem=0;for(int j=0;j<n;++j){
        tem+=(i-a[j])*(i-a[j]);
    }res=min(res,tem);}
    cout<<res;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n,d,x,a,s,i;
    scanf("%d%d%d",&n,&d,&x);
    s=x;
    for(i=0;i<n;i++){
        scanf("%d",&a);
        s+=(d+a-1)/a;
    }
    printf("%d",s);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;

const long long MOD = 1e9 + 7;

int main()
{
    ll a, b, c, n, ans = 0;
    cin >> a >> b >> c >> n;
    for (int i = 0; i <= 3000; i++)
    {
        for (int j = 0; j <= 3000; j++)
        {
            ll g = i * a + j * b;
            if (g <= n && (n - g) % c == 0)
            {
                ans++;
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
import queue

def main():
    n = int(input())
    A = list(map(int,input().split()))
    A = sorted(A,reverse=True)
    q = queue.PriorityQueue()
    q.put([-1*A[0],-1*A[0]])
    ans = 0
    for a in A[1:]:
        _min, _max = map(lambda x:-1*x,q.get())
        ans += _min
        q.put([-1*a,-1*_min])
        q.put([-1*a,-1*_max])
    print(ans)
    return 

if __name__ == "__main__":
    main()

Measured memory_bytes: 138148
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n, l = LI()
	s_list = SR(n)
	s_list.sort()
	ans = ''
	for s in s_list:
		ans += s
	print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 13512
$s = <STDIN>;
my @dat =  split(/ /,$s);
my $N =  $dat[0] ;
my $M =  $dat[1] ;
$s = <STDIN>;
my @dat =  split(/ /,$s);
my $sum=0;
for($i=0;$i<$N;$i++){
  $sum = $sum + $dat[$i];
}
my $min = $sum /(4*$M);
my @h = sort { $b - $a } @dat;
#print "$min  $sum";
if( $min <= $h[$M-1]){
   print "Yes";
}else{
 print "No";
}


Measured memory_bytes: 512
from math import sqrt

n, d = map(int, input().split())
points = []
for i in range(n):
  point = list(map(int, input().split()))
  points.append(point)

def issqrt(k):
  a = int(sqrt(k))
  if (k == a**2) or (k == (a+1)**2):
    return True
  else:
    return False
  
def distance(p1, p2):
  h = 0
  for i in range(d):
    h += (p1[i] - p2[i])**2
  return h
  
def solve():
  ans = 0
  for i in range(n):
    for j in range(i+1, n):
      dis = distance(points[i], points[j])
      ans += issqrt(dis)
  return ans

print(solve())

Measured memory_bytes: 3064
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("board.in");ofstream out("board.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

vec<int> n;

int check(){
    int o=1;
    for(int q=0; q<n.size() && o; q++) o&= n[q]==(n[(q-1+n.size())%n.size()]^n[(q+1)%n.size()]);
    return o;
}

int main() {
    fast;
    int a, nn=1; cin>>a;
    vec<int> m(a);
    set<int> s;
    map<int, int> mp;
    for(int q=0; q<a; q++) cin>>m[q], nn&=m[q]==0, s.insert(m[q]), mp[m[q]]++;
    sort(m.begin(), m.end());
    if(nn){cout<<"Yes"; return 0;}
    if(n.size()%3 || s.size()>3 || s.size()<2){cout<<"No"; return 0;}
    if(s.size()==3){
        int xr=0, d=-1;
        for(pii p : mp){
            xr^=p.F;
            if(d==-1) d = p.S;
            else if(d!=p.S){
                d=-1;
                break;
            }
        }
        if(d==-1 || xr>0) cout<<"No";
        else cout<<"Yes";
    }
    else{
        if(mp[0]==a/3) cout<<"Yes";
        else cout<<"No";
    }
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int MOD = 1e9 + 7;
int mul(int x, int y) {return (x*1ll*y) % MOD;}
int bp(int x, int y) {
	int ans = 1;
	while (y) {
		if (y&1) ans = mul(ans, x);
		x = mul(x, x);
		y >>= 1;
	}
	return ans;
}
int inv(int x) {return bp(x, MOD-2);}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector<ll> pos, neg;
	int nonzero = 0;
	for (int i=0; i<n; i++) {
		int x;
		cin >> x;
		if (x) nonzero++;
		if (x < 0) neg.push_back(-x);
		else pos.push_back(x);
	}
	if (nonzero < k) {
		cout << 0; return 0;
	}
	
	int np = pos.size(), nn = neg.size();
	sort(pos.begin(), pos.end(), greater<int>());
	sort(neg.begin(), neg.end(), greater<int>());
	int idp = 0, idn = 0;
	
	if (n == k) {
		bool negative = (nn&1);
		int ans = 1;
		for (int i=0; i<np; i++) ans = mul(ans, pos[i]);
		for (int i=0; i<nn; i++) ans = mul(ans, neg[i]);
		if (negative) ans = (ans - MOD) % MOD;
		cout << abs(ans) << '\n';
	}
	else if (k%2 == 0) {
		int ans = 1;
		while (idp+idn<k && idp<np && idn<nn) {
			if (pos[idp] >= neg[idn]) {
				ans = mul(ans, pos[idp++]);
			}
			else ans = mul(ans, neg[idn++]);
		}
		while (idp+idn<k && idp<np) {
			ans = mul(ans, pos[idp++]);
		}
		while (idp+idn<k && idn<nn) {
			ans = mul(ans, neg[idn++]);
		}
		if (idn&1) {
			if (idn<nn && 0<idp && idp<np) {
				ll takep = pos[idp-1]*pos[idp];
				ll taken = neg[idn-1]*neg[idn];
				if (takep >= taken) {
					ans = mul(mul(ans, inv(neg[idn-1])), pos[idp]);
				}
				else {
					ans = mul(mul(ans, inv(pos[idp-1])), neg[idn]);
				}
			}
			else if (idn == nn || idp == 0) {
				ans = mul(mul(ans, inv(neg[idn-1])), pos[idp]);
			}
			else {
				ans = mul(mul(ans, inv(pos[idp-1])), neg[idn]);
			}
		}
		cout << ans << '\n';
	}
	else if (np) {
		int ans = 1;
		while (idp+idn<k && idp<np && idn<nn) {
			if (pos[idp] >= neg[idn]) {
				ans = mul(ans, pos[idp++]);
			}
			else ans = mul(ans, neg[idn++]);
		}
		while (idp+idn<k && idp<np) {
			ans = mul(ans, pos[idp++]);
		}
		while (idp+idn<k && idn<nn) {
			ans = mul(ans, neg[idn++]);
		}
		if (idn&1) {
			if (idn<nn && 0<idp && idp<np) {
				ll takep = pos[idp-1]*pos[idp];
				ll taken = neg[idn-1]*neg[idn];
				if (takep >= taken) {
					ans = mul(mul(ans, inv(neg[idn-1])), pos[idp]);
				}
				else {
					ans = mul(mul(ans, inv(pos[idp-1])), neg[idn]);
				}
			}
			else if (idn == nn || idp == 0) {
				ans = mul(mul(ans, inv(neg[idn-1])), pos[idp]);
			}
			else {
				ans = mul(mul(ans, inv(pos[idp-1])), neg[idn]);
			}
		}
		cout << ans << '\n';
	}
	else {
		reverse(neg.begin(), neg.end());
		int ans = 1;
		for (int i=0; i<k; i++) ans = mul(ans, neg[i]);
		ans = (ans - MOD) % MOD;
		cout << abs(ans) << '\n';
	}
}

Measured memory_bytes: 5552
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int n,i;
	cin>>n;
	vector<int> v(n,0);
	rep(i,n)cin>>v[i];
	int b[3]={0};
	rep(i,n){
		if(v[i]%4==0)b[2]++;
		else if(v[i]%2==0)b[1]++;
		else b[0]++;
	}
	if(b[1]==0){
		if(b[2]+1>=b[0])cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	else{
		if(b[0]<=b[2])cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	
	
//////////////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
struct revran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { --i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr revran(const i64 e) noexcept: b(0), e(e) {}
  constexpr revran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(e - 1); }
  constexpr iter end() const noexcept { return iter(b - 1); }
};

struct ran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { ++i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr ran(const i64 e) noexcept: b(0), e(e) {}
  constexpr ran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(b); }
  constexpr iter end() const noexcept { return iter(e); }
  constexpr revran rev() const noexcept { return revran(b, e); }
};

constexpr ran rin(const i64 e) noexcept { return ran(1, e + 1); }
constexpr ran rin(const i64 b, const i64 e) noexcept { return ran(b, e + 1); }

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N);
  for(int i = 0;i < N;i++) cin >> A[i];
  sort(all(A));
  i64 sum = A[N - 1] - A[0];
  int L = 0;
  for(int i = 1;i < N - 1 && A[i] <= 0;i++) {
    sum -= A[i];
    L = i;
  }
  for(int i = L + 1;i < N - 1;i++) {
    sum += A[i];
  }

  i64 mi = L + 1;
  i64 pl = N - mi;

  cout << sum << endl;
  vector<pair<i64, i64>> vec;

  i64 pi = N - 1;
  i64 mii = 0;
  i64 sw = 0;
  while(pl > 1) {
    if(sw == 0) {
      i64 LEFT = A[pi];
      i64 RIGHT = - (sum - LEFT);
      vec.push_back({ LEFT, RIGHT });
      sum = RIGHT;
      pi--;
      pl--;
      swap(pl, mi);
      sw ^= 1;
    }
    else {
      i64 LEFT = A[mii];
      i64 RIGHT = - (sum - LEFT);
      vec.push_back({ LEFT, RIGHT });
      sum = RIGHT;
      mii++;
      pl--;
      swap(pl, mi);
      sw ^= 1;
    }
  }
  for(int j = 0;j < mi;j++) {
    if(sw == 0) {
      i64 RIGHT = A[mii];
      mii++;
      i64 LEFT = sum + RIGHT;
      vec.push_back( { LEFT, RIGHT } );
      sum = LEFT;
    }
    else {
      i64 RIGHT = A[pi];
      pi--;
      i64 LEFT = sum + RIGHT;
      vec.push_back({ LEFT, RIGHT });
      sum = LEFT;
    }
  }
  reverse(all(vec));
  for(auto p: vec) {
    cout << p.first << " " << p.second << endl;
  }
}


Measured memory_bytes: 4336
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = __LONG_LONG_MAX__;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b,c; cin >> a >> b >> c;
    int x; cin >> x;
    ll count = 0;
    rep(i,0,a+1){
        rep(j,0,b+1){
            rep(k,0,c+1){
                int y = 500*i+100*j+50*k;
                if(x==y) count++;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
from typing import Set


class UnionFind:
    """Union Find (Disjoint Set): O(α(N))
    References:
        https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp
        https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html
    """

    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        """Find the group (root) of vertex x in O(α(n)) amortized."""
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def __len__(self) -> int:
        """Count the number of groups (roots)."""
        return len(self.groups)

    @property
    def groups(self) -> Set[int]:
        """Return the set of groups (roots) in O(n)."""
        return {i for i, r in enumerate(self._roots) if r < 0}

    def is_connected(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are connected in O(α(n)) amortized."""
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y in O(α(n)) amortized."""
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x

    def get_size(self, x: int) -> int:
        """Return the size of the group vertex x belongs in O(α(n)) amortized."""
        return -self._roots[self[x]]


def unionfind():
    # https://judge.yosupo.jp/problem/unionfind
    # https://atcoder.jp/contests/practice2/tasks/practice2_a
    N, Q, *TUV = map(int, open(0).read().split())
    tree = UnionFind(N)
    res = []
    for t, u, v in zip(*[iter(TUV)] * 3):
        if t:
            res.append(int(tree.is_connected(u, v)))
        else:
            tree.unite(u, v)
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    unionfind()


Measured memory_bytes: 146396
import math
import heapq
import sys
from collections import Counter

#N,K=map(int, input[].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N=int(input())
H=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

min=1000000000
for i in reversed(range(1,N+1)):
    
    if H[i-1]>min:
        print('No')
        sys.exit()
    if H[i-1]<min:
        min = H[i-1]+1

print('Yes')
      


Measured memory_bytes: 14900
//Problem C
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,aa[N],x[N],y[N],t,l;
int chk(int v){//printf("chk %d\n",v);
	t=l=0;
	for(int i=1;i<=n;i++){
		int a=aa[i];
		if(a<=l){
			while(t&&a<x[t])--t;int k=a;
			while(t&&x[t]==k&&y[t]==v-1)--t,--k;
			if(!k)return 0;
			if(t&&x[t]==k)++y[t];
			else x[++t]=k,y[t]=1;
		}
		l=a;
		//printf("%d %d  %d",i,a,l);for(int i=1;i<=t;i++)printf(" (%d,%d)",x[i],y[i]);printf("\n");
	}
	return 1;
}
int main(){
	scanf("%d",&n);int f=1;
	for(int i=1;i<=n;i++)scanf("%d",&aa[i]);
	for(int i=1;i<n;i++)if(aa[i]>=aa[i+1])f=0;if(f){printf("1");return 0;}
	int l=2,r=n,s=n;
	while(l<=r){
		int mid=(l+r)>>1;
		if(chk(mid))s=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {

    int a,b,c,d;
    scanf("%d%d%d%d", &a, &b,&c,&d);

    if(a+b==c+d){
        printf("Balanced");
    }else if(a+b>c+d){
        printf("Left");
    }else{

        printf("Right");
    }


    return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
long long cal(int n){
	long long ret=1;
	for(int i=1;i<=n;i++)ret*=i;
	if(n)return ret;
	else return 1;
}
int main(){
	string s;cin>>s;
	int d[26]={},kisu=0;
	long long sum=0;
	for(int i=0;i<s.size();i++)d[s[i]-97]++;
	for(int i=0;i<26;i++)kisu+=d[i]%2;
	if(kisu>1)cout<<0<<endl;
	else{
		for(int i=0;i<26;i++)d[i]/=2,sum+=d[i];
		sum=cal(sum);
		for(int i=0;i<26;i++)sum/=cal(d[i]);
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 1180
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<list>
#include<map>
#include<iomanip>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
#include<memory.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	cout<<(n-1)*(m-1) ;
	return 0;
}


Measured memory_bytes: 256
s = gets.strip

words = ['dream', 'dreamer', 'erase', 'eraser']

until s.empty? do
    reduced = false
    words.map do |w|
        if s[-w.size, w.size] == w
            s = s[0..-w.size - 1]
            reduced = true
            break
        end
    end

    unless reduced
        puts 'NO'
        exit 0
    end
end

puts 'YES'

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

int main() {
    int N,K;
    cin >> N >> K;
    set<int>X;
    for(int i = 0; i < K; i++) {
        int d;
        cin >> d;
        for(int j = 0; j < d; j++) {
                int a;
                cin >> a;
                X.insert(a);
        }
    }
   cout << N-X.size() << endl;
}


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

typedef long long ll;
const int maxn=310;
int px[maxn*maxn],py[maxn*maxn],d[maxn*maxn];

int main()
{
    int h,w,D;
    cin >> h >> w >> D;
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
        {
            int a;
            cin >> a;
            px[a]=i;
            py[a]=j;
        }
    for(int i=D+1;i<=h*w;i++)
        d[i]=d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]);
    int q;
    cin >> q;
    while(q--)
    {
        int l,r;
        cin >> l >> r;
        cout << abs(d[r]-d[l]) << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
a[3],b[3],w;main(s){for(;~scanf("%d%d%d",a,a+1,a+2);w++){qsort(a,3,4,"\x8b\7+\6\xc3");if(a[0]+a[1]<=a[2])break;s=a[2]*a[2]-a[0]*a[0]-a[1]*a[1];b[s<0?1:s>0?2:0]++;}w=!printf("%d %d %d %d\n",w,b[0],b[1],b[2]);}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
 
using namespace std;
 
int main() {
  int n;
  cin>>n;
  vector<int> arr;
  int adjacent = 1;
  int result = 0;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin>>tmp;
    if (tmp == i + 1) {arr.push_back(i);}
  }
  int j = 0;
  int N = arr.size();
  while (j < N) {
    if (j + 1 < N && arr[j] + 1 == arr[j + 1]) {
      adjacent++;
      j++;
      continue;
    }
    if (adjacent != 1) {
      result += (adjacent + 1) / 2;
      adjacent = 1;
      j++;
    }
    else {
      result++;
      j++;
    }
  }
  cout<<result;
  
  return 0;
}

Measured memory_bytes: 892
#include <iostream>

// candies.cpp
// author: Seong Yong-ju ( @sei40kr )
// Copyright (c) 2018 Seong Yong-ju

#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)

using namespace std;

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

  int n;
  cin >> n;
  int top[n];
  int bottom[n];
  REP(i, n) { cin >> top[i]; }
  REP(i, n) { cin >> bottom[i]; }

  FOR(i, 1, n) { top[i] += top[i - 1]; }
  RFOR(i, 0, n - 1) { bottom[i] += bottom[i + 1]; }

  int ans = 0;
  REP(i, n) { ans = max(ans, top[i] + bottom[i]); }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
int A[200000],B[200000];long K=0,p=0,m=0,z=0;
int compare(const int*a,const int*b){return *a-*b;}
static inline long IN(void)
{
  long x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline int check(long x)
{
  long count=0;
  if(x>=0)
  {
    int plus=p-1,minus=m-1;count+=z*(p+m)+z*(z-1)/2+p*m;
    rep(i,plus){while(1l*A[i]*A[plus]>x){plus--;}if(i>=plus){break;}count+=plus-i;}
    rep(i,minus){while(1l*B[i]*B[minus]>x){minus--;}if(i>=minus){break;}count+=minus-i;}
  }
  else{x=-x;int low=0;rep(i,m){while(1l*A[low]*B[m-1-i]<x&&low<p){low++;}count+=p-low;}}
  return count>=K;
}
int main(void)
{
  int N=IN(),x;long l=-2e18,r=-l,mid;K=IN();
  while(N--){x=IN();if(x>0)A[p++]=x;else if(x<0)B[m++]=-x;else z++;}
  qsort(A,p,sizeof(int),(int(*)(const void*,const void*))compare);
  qsort(B,m,sizeof(int),(int(*)(const void*,const void*))compare);
  while(l<=r){mid=(l+r)/2;if(check(mid))r=mid-1;else l=mid+1;}
  return OUT(l),0;
}

Measured memory_bytes: 2624
def main():
    a, b = [int(x) for x in input().split()]
    if a > b:
        small = str(b)
        big = a
    else:
        small = str(a)
        big = b
    for _ in range(big):
        print(small, end='')
    print()


if __name__ == "__main__":
    main()


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

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

  vector<vector<int>> tojo(26, vector<int>(n + 1, 0));  // 26個のBIT;
  for (int i = 0; i < s.size(); i++) {
    for (int x = i + 1; x <= n; x += (x & -x)) tojo[s[i] - 'a'][x]++;
  }

  int q;
  cin >> q;

  for (int que = 0; que < q; que++) {
    int type;
    cin >> type;
    if (type == 1) {  // 書き換え (logN回)
      int p;
      char c;
      cin >> p >> c;
      if (s[p - 1] == c) continue;
      for (int x = p; x <= n; x += (x & -x)) tojo[s[p - 1] - 'a'][x]--;
      for (int x = p; x <= n; x += (x & -x)) tojo[c - 'a'][x]++;
      s[p - 1] = c;
    } else {
      int l, r, res = 0;
      cin >> l >> r;
      for (int i = 0; i < 26; i++) {
        int count = 0;
        for (int x = r; x > 0; x -= (x & -x)) count += tojo[i][x];
        for (int x = l - 1; x > 0; x -= (x & -x)) count -= tojo[i][x];
        if (count) res++;
      }
      cout << res << endl;
    }
  }
}


Measured memory_bytes: 53728
local mma = math.max
local n, m, p = io.read("*n", "*n", "*n")
local edge = {}
for i = 1, m do
  local a, b, c = io.read("*n", "*n", "*n")
  table.insert(edge, {a, b, c - p})
end
local len = {}
local inf = 10000000000
for i = 1, n do len[i] = -inf end
len[1] = 0
local lim = n + 4
for i = 1, lim do
  for j = 1, m do
    local src, dst, c = edge[j][1], edge[j][2], edge[j][3]
    if len[src] ~= -inf and len[dst] < len[src] + c then
      len[dst] = len[src] + c
      if i == lim then
        len[dst] = inf
      end
    end
  end
end
for i = 1, lim do
  for j = 1, m do
    local src, dst, c = edge[j][1], edge[j][2], edge[j][3]
    if len[src] == inf then
      len[dst] = inf
    end
  end
end
print(inf <= len[n] and "-1" or mma(0, len[n]))


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;

int main(){
    ll N; std::cin >> N;
    std::vector<ll> t, x, y;
    t.push_back(0); x.push_back(0); y.push_back(0);
    for(int i=0; i<N; i++){
        ll b1, b2, b3; std::cin >> b1 >> b2 >> b3;
        t.push_back(b1); x.push_back(b2); y.push_back(b3);
    }

    bool flag=true;
    for(int i=0; i<t.size()-1; i++){
        ll dt=t[i+1]-t[i], dx=abs(x[i+1]-x[i]), dy=abs(y[i+1]-y[i]);
        if(dt<dx+dy || dt%2!=(dx+dy)%2){
            flag=false;
        }
    }

    if(flag){
        std::cout << "Yes";
    }else{
        std::cout << "No";
    }
    return 0;
}


Measured memory_bytes: 2912
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, combinations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from operator import itemgetter
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

from pprint import pprint

def main():
    import itertools
    a, b, c, d = mis()
    print(max(x*y for x, y in itertools.product((a, b), (c, d))))




main()



Measured memory_bytes: 9988
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();

		System.out.println((a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) ? "Possible" : "Impossible");

		sc.close();


	}

}




Measured memory_bytes: 21204
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
k=sorted([list(map(int,input().split()))for i in range(m)],key=lambda x:-x[1])+[[0,0]]
c,d=0,0
t=0
ans=0
while c<n:
    if a[d]>=k[t][1]:
        ans+=a[d]
        d+=1
        c+=1
    else:
        ans+=k[t][1]*min(n-c,k[t][0])
        c+=k[t][0]
        t+=1
print(ans)

Measured memory_bytes: 36824
#include<bits/stdc++.h>
#define fora(i,a,b) for(int i=a,Wub=b;i<Wub;++i)
#define ford(i,a,b) for(int i=a,Wub=b;i>=Wub;--i)
#define SPEEDIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 1000000
#define MOD 1073741824
using namespace std;
typedef long long ll;

int main(){
    int a,b;
    string x;
    cin>>a>>x>>b;
    if(x=="+")cout<<a+b<<"\n";
    else cout<<a-b<<"\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public Main() {
    }

    public static void main(String[] args) {
        new Main().solve();
    }

    int[][] map;
    int N;

    private void solve() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        map = new int[2][N];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < N; j++) {
                map[i][j] = sc.nextInt();
            }
        }
        System.out.println(rec(0, 0, 0));
    }

    int rec(int x, int y, int sum) {
        if (x < 0 || N <= x || y < 0 || 2 <= y) {
            return 0;
        }

        sum += map[y][x];

        if (x == N - 1 && y == 1) {
            return sum;
        }
        int res = 0;

        res = Math.max(rec(x + 1, y, sum), rec(x, y + 1, sum));
        return res;
    }
}


Measured memory_bytes: 25556