akhauriyash/Code-Regression huggingface dataset:
_N,_M=input().split()
N = int(_N)
M = int(_M)
l = []
for i in range(0,M):
    _p, _q = input().split()
    l.append((int(_p),int(_q)))
_A,_B=zip(*l)

A=_A+_B
B=_B+_A


def gen_get_to(_fr):
    global A
    global B
    global nodes
    global step
    for itr in range(0,len(A)):
        if A[itr]==_fr:
            if not B[itr] in nodes[0:step]:
                yield B[itr]

def move(): #returns whether "move" succeeded or not
    global nodes
    global possible_memo
    global step
    global counter
    global N
    global end_flag
    try:
        _=next(possible_memo[step])
        nodes[step+1]=_
        step+=1
        #print("success move to {}".format(nodes[step]))
        #print("map: {}".format(nodes[0:step+1]))
        #print("I am at {}th node".format(step+1))
        if step==N-1:
            counter+=1
            #print('REACHED GOAL!!!')
        possible_memo[step]=gen_get_to(nodes[step])
    except StopIteration:
        step-=1
        #print("failed to move")
        if not step==-1:
            pass#print("map: {}".format(nodes[0:step+1]))
            #print("I am at {}th node".format(step+1))
        if step==-1:
            #print("I fell from the first node")
            end_flag=True

nodes=[0]*N
possible_memo=[0]*N
counter=0
step=0
nodes[step]=1
possible_memo[step]=gen_get_to(nodes[0])
end_flag=False

while not end_flag:
    move()


print(counter)

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

#define vi vector<int>
#define vii vector<int, int>
#define ll long long
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...) 42
#endif

const int MOD = 1000000007;

int main(){
    IOS;

    int n, x;
    cin >> n >> x;
    int count = 1;
    int l[n];
    l[0] = 0;
    for (int i = 1; i <= n; i++) cin >> l[i];

    for (int i = 1; i <= n; i++){
        l[i] = l[i - 1] + l[i];
        //trace(l[i]);
        if (l[i] <= x){
            count++;
        }else break;
    }

    cout << count << endl;

    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        String line = br.readLine();
        int n = Integer.parseInt(line);
        for(int i = 1; i <= n; i++){
            int x = i;
            if( x % 3 == 0 ){
                sb.append(" ").append(i);
            }else{
                do{
                    if( x % 10 == 3 ){
                        sb.append(" ").append(i);
                                                x = 0;
                    }
                    x /= 10;
                }while( x != 0 );
            }
        }
        sb.append("\n");
        System.out.print(sb);
    }
}

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

int main() {
	int n,l;
	cin>>n>>l;
	vector<string> v(n);
	for(int i=0;i<n;i++) cin>>v[i];
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++)
		cout<<v[i];
	
	return 0;
}

Measured memory_bytes: 256
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy
#import heapq
#import math
#import string

setrecursionlimit(10**6)
input=stdin.readline

def Counting_sort(array,max_value):
    cnt_element=[0]*(max_value+1)
    ans_array=[]
    for i in array: cnt_element[i]+=1
    for i,j in enumerate(cnt_element): ans_array+=[i]*j
    return ans_array

n=int(input().rstrip())
a=[int(i) for i in input().split()]
ans=Counting_sort(a,max(a))
print(*ans)


Measured memory_bytes: 226536
import java.io.*;
class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),x=Integer.parseInt(s[1]),t=Integer.parseInt(s[2]);
        int ans=n/x*t;
        if(n%x==0) n=0;
        else n=1;
        ans+=n*t;
        System.out.print(ans);
    }
}


Measured memory_bytes: 32744
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
using namespace std;
 
int main() {
    int a=0, b=0;
    cin >> a >> b;
    
    if(a >= b) for(int i = 0; i < a; i++)cout << b;
    else  for(int i = 0; i < b; i++)cout << a;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
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の最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



//—————————————UnionFind木   UF uf(n);——————————————————————

struct UF {
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    UF(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void reset(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    bool unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool same(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

//—————————————————————————————————————————————————


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

  int n,m;
  cin>>n>>m;

  UF uf(n);
  int x,y,z;
  rep(i,m){
    cin>>x>>y>>z;
    x--;y--;
    uf.unite(x,y);
  }

  set<int> ans;
  rep(i,n){
    ans.insert(uf.root(i));
  }

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

}


Measured memory_bytes: 9508
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
ll mod = 1000000007;

int main(){
    string s;cin>>s;
    bool f=true;
    rep(i,0,3){
        if (s[i]==s[i+1]) f=false;
    }
    if (f){
        cout<<"Good"<<endl;
    }else{
        cout<<"Bad"<<endl;
    }
}

Measured memory_bytes: 256
//#include "/Users/doomzday/Programming/stdc++.h"

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ldb = long double;

#define forn(i, x, n) for (int i = x; i < n; ++i)
#define forb(i, x, n) for (int i = x; i >= n; --i)
#define mmax(a, b, c) max(a, max(b, c))
#define mmin(a, b, c) min(a, min(b, c))
#define pb push_back
#define mp make_pair

const int N = 100500 * 1;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    while (a != 0 && b != n + 1) {
        if (a + 1 != b) {
            ++a;
        } else {
            --a;
        }
        if (b - 1 != a) {
            --b;
        } else {
            ++b;
        }
    }
    if (a == 0) {
        cout << "Borys\n";
    } else {
        cout << "Alice\n";
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int N=0,T=0,min=0,flag=0,TLE=-1;
    int c[101]={};
    int t[1001]={};
    scanf("%d %d",&N,&T);
    for(int i=0;i<N;i++){
        scanf("%d %d",&c[i],&t[i]);
    }
    min=c[0];
    for(int i=0;i<N;i++){
        if(t[i]<=T && c[flag]>=c[i]){
            flag=i;
            TLE=0;
        }
    }
    if(TLE==-1){
        puts("TLE");
        return 0;
    }
    else{
        printf("%d\n",c[flag]);
        return 0;
    }
    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp> 
boost::math::lcm(10,20) ---> use it to find lcm.*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;

/************ Use when precision need to set to some value **************/
// std::cout << std::setprecision(12);
// std::cout << std::fixed;
/*******************************************/
int max(int a,int b){
	if(a > b)return a;
	else return b;
}

int min(int a, int b){
	if(a < b)return a;
	else return b;
}
/*		0. Go to main function first.
		1. Take all the inputs................................................
		2. Check Once whether the graph given is directed or undirected.......
		3. Tree can also be undirected.
		4. Whenever you do multiplication and division in the same line, beware.
*/
void solve(){
	int n,m;
	cin >> n >> m;
	int ans = 0;
	ans += ((n*(n-1))/2);
	ans += ((m*(m-1))/2);
	cout << ans << endl;
}
/*
	memset() can be used to set all values as 0 or -1 for integer data types.
	It will not work if we use it to set as other values.
	The reason is memset works byte by byte.
*/

int main(){
	IO;

	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif // ONLINE_JUDGE

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


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int A,B;
    cin >> A >> B;
    int ans = 0;
    for (int i = A; i <= B; i++){
        string t;
        t = to_string(i);
        if (t[0] == t[4] &&  t[1] == t[3]){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
T=0
H=0
for i in range(n):
    card_t, card_h = input().split()
    if card_t == card_h:
        T += 1
        H += 1
    else:
        if card_h>card_t:
            H += 3
        else:
            T += 3
print(T, H)



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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  string N;
  cin>>N;
  ll cnt = 0;
  for(auto x:N){
    ll t = x - '0';
    cnt+=t;
  }
  if(cnt%9==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
using namespace std::chrono;

#define ll long long
#define ld long double
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#ifdef LL
const ll inf = 1e9;
#else 
const ll inf = 1e18;
#endif

const int mod = 1e9 + 7;
const int mod2 = 998244353;

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

// lower bound returns first element greater than the value

high_resolution_clock::time_point curTime() { return high_resolution_clock::now(); }
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);} //Just add this as a third argument to sort() while sorting an array of pairs; NO NEED FOR ANY ARGUMENTS;
template <typename T>
T fact(T a, T modulus){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=modulus;} return res; }
template <typename T>
ll powmod(T a,T b,ll m){ ll ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
ll power(T a, T b){ ll ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}
template <typename T>
T gcd(T a,T b){ return (b?__gcd(a,b):a); }
template <typename T>
T lcm(T a, T b){ return (a*(b/gcd(a,b))); }
template <typename T>
T cl(T a, T b){ return (a+b-1)/b; }
template <typename T>
T set_bits(T a)
{ return __builtin_popcount(a); }
template <typename T>
T add_self(T& a, T b, T modulus){ a+=b; if(a>=modulus){ a-=modulus; } }
template <typename T>
T to_upper(T s){ transform(s.begin(), s.end(), s.begin(), ::toupper); return s; }
template <typename T>
T to_lower(T s){ transform(s.begin(), s.end(), s.begin(), ::tolower); return s; }

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



int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    auto startTime = curTime();

    int x;
    cin>>x;
    cout<<(x<=0? 1 : 0)<<endl;

    auto stopTime = curTime();
    auto duration = duration_cast<microseconds>(stopTime - startTime);
    //cout<<"Program ran for "<<(ld)duration.count()/1e6<<" "<<"seconds"<<endl;
}


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

int main(){
	int n, x, count = 1, sum = 0;
	cin >> n >> x;
	rep(i, n){
		int input;
		cin >> input;
		sum += input;
		if(sum <= x)count++;
		else break;
	}
	cout << count << endl;
	return 0;
}

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

using namespace std;


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

    vector<int> A(N);
    int count = 0;
    const int INF = 2000000000;

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

    // 最長減少(等しい場合も含む)部分列の数列の長さがi+1のときの最終要素の最大値dp[i]?
    vector<int> dp;

    // 初期条件
    dp.push_back(A[0]);

    // dp開始
    for(int i = 1; i < N; i++) {
        // dp[i]の右から走査
        auto iter = lower_bound(dp.rbegin(), dp.rend(), A[i]);

        // A[i]が右端の値以下の場合
        if(iter == dp.rbegin()) {
            dp.push_back(A[i]);

        // A[i]より小さい値がdp[i]に存在する場合
        } else {
            *(iter-1) = A[i];            
        }
    }

    // dp[i]の大きさが答え    
    cout << dp.size() << endl;
	return 0;
}

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

int main() {
  int h,w,n,x;
  cin >> h >> w >> n;
  x=0;
  
  if(h<=w){
   for(int i=1;i<=h;i++){
    if(i*w<n)x+=1;
    if(i*w>=n){
      x+=1;
      break;
    }
    //if(i*w==n)break;
   }
  }
  
  if(h>w){
   for(int i=1;i<=w;i++){
    if(i*h<n)x+=1;
    if(i*h>=n){
      x+=1;
      break;
    }
    //if(i*h==n)break;
   }
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
main()
{
    char s[5];
    cin>>s;
    int a=0,i;
    for(i=0;i<3;i++)
    {
        if(s[i]=='R')a++;
    }
    if(a==0 || a==3 || a==1)
    {
        cout<<a<<endl;return 0;
    }
    if(s[0]=='R' && s[2]=='R')
    {
        cout<<1<<endl;
    }
    else
    {
        cout<<2<<endl;
    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 1;
  int count = 0;
  for(int i = 1; i <= N; i++){
    int c = i;
    int cnt = 0;
    while(c > 0){
      if(c % 2 != 0) break;
      c /= 2;
      cnt++;
    }
    if(cnt >= count){
      ans = i;
      count = cnt;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ld PI = 3.1415926535;

char itoc(int x){
  return char('0'+x);
}

int ctoi(char x){
  return int(x-'0');
}

int main(){
  string S;cin >> S;
  reverse(S.begin(),S.end());
  S = S + "0";
  //cout << S << endl;
  ll N = S.size();
  vector<ll> DP0(N,0);//kuriagari kaiketuzumi
  vector<ll> DP1(N,0);//kuriagari mikaiketu
  DP0[0] = ctoi(S[0]);
  DP1[0] = (10-ctoi(S[0]))%10;
  for(int i=1;i<N;i++){
    //move to DP0[i]
    if(S[i]=='9'){
      DP0[i] = DP0[i-1]+9;
    }else{
      DP0[i] = min(DP0[i-1]+ctoi(S[i]),DP1[i-1]+ctoi(S[i])+1);
    }
    //move to DP1[i]
    if(S[i]=='0'){
      DP1[i] = DP1[i-1];
    }else{
      if(S[i-1]=='0'){
        DP1[i] = DP0[i-1] + 10 - ctoi(S[i]);
      }else{
        DP1[i] = min(DP0[i-1]+10-ctoi(S[i]),DP1[i-1]+9-ctoi(S[i]));
      }
    }
  }
  cout << DP0[N-1] << endl;
}

Measured memory_bytes: 16988
//Print a Chessboard

#include <iostream>
#include <cassert>

int main()
{
  while (1) {
    int height, width;
    std::cin >> height >> width;

    assert(height >= 0 && height <= 300);
    assert(width >= 0 && width <= 300);
    if (!height && !width) break;

    char color[] = "#.";
    int  flag = 0;

    for (int h = 0; h < height; ++h) {
      flag = h % 2;
      for (int w = 0; w < width; ++w) {
        std::cout << color[flag];
        flag ^= 1;
      }
      std::cout << std::endl;
    }
    std::cout << std::endl;
  }

  return 0;
}

Measured memory_bytes: 1152
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   :
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define rw freopen("graphs_as_a_service.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (ll i=a;i<=(ll)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define rep(i,a) lp(i,0,a-1)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 2e5 + 3, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
int n, x;
ll sum[N] = { };
set<ll> st;
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	cin >> n;
	lp(i,1,n)
	{
		cin >> x;
		sum[i] += sum[i - 1] + x;
		st.insert(sum[i]);
	}
	ll ans = LONG_MAX;
	lp(i,2,n-2)
	{
		vll q1, q2;
		auto it = st.lower_bound(sum[i] / 2);
		if (it != st.end() && *it != sum[i])
			q1.pb( { *it, sum[i] - *it });
		if (it != st.begin()) {
			--it;
			q1.pb( { *it, sum[i] - *it });
		}
		ll totr = sum[n] - sum[i];
		it = st.lower_bound(sum[i] + totr / 2);
		if (it != st.end() && *it != sum[n])
			q2.pb( { *it - sum[i], totr - (*it - sum[i]) });
		if (it != st.begin()) {
			--it;
			if (*it != sum[i])
				q2.pb( { *it - sum[i], totr - (*it - sum[i]) });
		}
		for (auto u : q1) {
			for (auto w : q2) {
				vl r = { u.F, u.S, w.F, w.S };
				sort(all(r));
				ans = min(ans, r.back() - r[0]);
			}
		}
	}
	f(ans);
	return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
const int N = 633;
const int mod = 1e9 + 7;
int f[N][N][N];
int a[N], n, cnt;
int typ[N], tmp[N];
int main(){
	cin>>n;
	n <<= 1;
	for(int i = 1;i <= n; i++)cin>>a[i];
	for(int i = 1;i <= n; i += 2){
		if(a[i] != -1 && a[i+1] != -1){
			typ[a[i]] = typ[a[i+1]] = 3;
		}
		else{
			if(a[i] != -1)typ[a[i]] = 2;
			else if(a[i+1] != -1)typ[a[i+1]] = 2;
			else cnt++;
		}
	}
	for(int i = 1;i <= n; i++)tmp[n-i+1] = typ[i];
	for(int i = 1;i <= n; i++)typ[i] = tmp[i];
	f[0][0][0] = 1;
	for(int i = 1;i <= n; i++){
//		printf("i=%d tp=%d\n", i, typ[i]);
		if(typ[i] == 3){
			memcpy(f[i], f[i-1], sizeof f[i]);
			continue;
		}
		for(int j = 0;j <= n; j++){
			for(int k = 0;k <= n; k++){
				if(typ[i] == 0){
					f[i][j][k] = (f[i-1][j+1][k] + 1LL * f[i-1][j][k+1] * (k + 1) % mod) % mod;
					if(j > 0)f[i][j][k] = (f[i][j][k] + f[i-1][j-1][k]) % mod;
				}
				else{
					f[i][j][k] = f[i-1][j+1][k];
					if(k > 0)f[i][j][k] = (f[i][j][k] + f[i-1][j][k-1]) % mod;
				}
			}
		}
	}
	int ans = f[n][0][0];
	for(int i = 1;i <= cnt; i++){
		ans = 1LL * ans * i % mod;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n-1);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n-1; i++) cin >> c[i];
    int ans;
    for (int i = 0; i < n; i++) {
        ans += b[a[i]-1];
        if (i != 0 && a[i]-a[i-1] == 1) ans += c[a[i-1]-1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, m;
		HashMap<Integer, LinkedList<Integer>> islands = new HashMap<>();
		boolean result;

		n = sc.nextInt();
		for(int i = 1; i <= n; i++) {
			islands.put(i, new LinkedList<>());
		}
		m = sc.nextInt();
		for(int i = 0; i < m; i++) {
			islands.get(sc.nextInt()).add(sc.nextInt());
		}

		result = islands.get(1).stream().anyMatch(i -> islands.get(i).contains(n));
		if( result ) {
			System.out.println("POSSIBLE");
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}
}


Measured memory_bytes: 149184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll h,w;
  cin >> h >> w;
  if(w==1 || h==1) cout << 1 << endl;
  else {
    cout << (h*w+1)/2 << endl;
  }
      
    

  
  return 0;
    

}


Measured memory_bytes: 256
import java.util.Scanner;
     
public class Main {
//java11
     
    	public static void main(String[] args) {
     
    		Scanner sc = new Scanner(System.in);
     
    		int R = sc.nextInt();
     
    		System.out.println(2*R * 3.14);
     
    	}
     
}

Measured memory_bytes: 35952
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin>>n;
    vector<int> s(n);
    vector<int> t(n);
    for(int i=0;i<n;i++){
    cin>>s.at(i);
    t.at(i)=s.at(i);
    }
    sort(t.begin(),t.end());
    int count=0;
    for(int i=0;i<n;i++){
        if(s.at(i)!=t.at(i)) count++;
    }
    if(count==0||count==2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 3532
#include <cstdio>
#include <vector>

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

using namespace std;

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

void wint(int n) {
  printf("%lld\n", n);
}

struct union_find {
  vector<int> p;
  union_find(int n): p(n) {
    dotimes(x, n)
      p[x] = x;
  }
  int find(int x) {
    while (x != p[x]) {
      int y = p[x];
      p[x] = p[y];
      x = y;
    }
    return x;
  }
  bool eqv(int x, int y) {
    int a = find(x), b = find(y);
    return a == b;
  }
  bool unite(int x, int y) {
    int a = find(x), b = find(y);
    if (a == b)
      return true;
    if (!(a < b))
      swap(a, b);
    p[b] = a;
    return false;
  }
};

signed main() {
  int N = rint();
  int M = rint();
  pair<int, int> edges[M];
  dotimes(i, M) {
    edges[i].first = rint() - 1;
    edges[i].second = rint() - 1;
  }
  int r = 0;
  dotimes(j, M) {
    union_find uf(N);
    dotimes(i, M)
      if (i != j)
        uf.unite(edges[i].first, edges[i].second);
    bool connected = true;
    dotimes(i, N - 1)
      if (!uf.eqv(0, i + 1)) {
        connected = false;
        break;
      }
    if (!connected)
      r++;
  }
  wint(r);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define TT pair<long long, long long>
#define ordered_set tree<TT, null_type, less<TT>, rb_tree_tag, tree_order_statistics_node_update>
#define fo(i,n)   for(i=0;i<n;i++)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define mp make_pair
#define For(m) for(auto it = m.begin();it!=m.end();it++)
#define fi first
#define se second
typedef long long ll;
typedef long double mytype;
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //priority_queue <int, vector<int>, greater<int> > pq;
    //cout << fixed << setprecision(9) <<ans<<endl;
    //ordered_set os;//os.order_of_key();//os.find_by_order();
    ll l,r,count,n,m,sum=0,ans=0,i,j,k,tt,t,x,y,z,c,a[200005]={},b[200005]={};
    string ss;
    set<ll> s;
    vector<ll> v;
    map<ll,ll> ma;
    ll dp[3000][3000][2]={};
    cin>>n;
    fo(i,n){
        cin>>a[i];
        dp[i][i][0]=a[i];
    }
    for(i=1;i<n;i++){
        for(j=0;j<(n-i);j++){
            if((a[j]+dp[j+1][j+i][1])>=(a[j+i]+dp[j][j+i-1][1])){
                dp[j][j+i][0]=a[j]+dp[j+1][j+i][1];
                dp[j][j+i][1]=dp[j+1][j+i][0];
            }
            else{
                dp[j][j+i][0]=a[j+i]+dp[j][j+i-1][1];
                dp[j][j+i][1]=dp[j][j+i-1][0];
            }
        }
    }
    cout<<dp[0][n-1][0]-dp[0][n-1][1]<<endl;
}

Measured memory_bytes: 142464
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#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()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

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); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

int x[105], y[105];
int d[105][1010];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int w, h, n;
  cin >> w >> h >> n;
  bool st_flag = false, en_flag = false;
  REP(i, n) {
    cin >> x[i] >> y[i];
    x[i]--, y[i]--;
    if(x[i] == 0 && y[i] == 0) st_flag = true;
    if(x[i] == w-1 && y[i] == h-1) en_flag = true;
  }

  REP(i, 105) REP(j, 1010) d[i][j] = LLINF;
  priority_queue<VI, VVI, greater<VI>> que;
  REP(i, n) {
    // スタート地点から街灯iに向かうとき
    int cost = x[i]+y[i];
    d[i][cost] = cost;
    que.push({cost, i, cost});
  }

  while(que.size()) {
    VI v = que.top(); que.pop();
    // cout << v << endl;
    int dist = v[0], idx = v[1], cost = v[2];
    if(dist > d[idx][cost]) continue;
    REP(i, n) {
      if(idx == i) continue;
      int n_cost = max(0LL, abs(x[idx]-x[i]) + abs(y[idx]-y[i]) - cost - 1);
      if(d[i][n_cost] > d[idx][cost] + n_cost) {
        d[i][n_cost] = d[idx][cost] + n_cost;
        que.push({d[i][n_cost], i, n_cost});
      }
    }
  }

  int ans = LLINF;
  REP(i, n) REP(j, 1010) {
    // cout << "i:" << i << " j:" << j << " " << d[i][j] << endl;
    chmin(ans, d[i][j] + max(0LL, abs(w-1-x[i]) + abs(h-1-y[i]) - (en_flag?1:0) - j));
  }
  cout << ans << endl;

  return 0;
}



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

int main(void){
    int n;
    std::cin >> n;
    std::vector<int> s, d;
    s.reserve(n);
    d.reserve(n);
    for(int i = 0; i < n; i++){
        int tmp;
        std::cin >> tmp;
        s.push_back(tmp + i + 1);
        d.push_back(i + 1 - tmp);
    }
    std::sort(s.begin(), s.end());
    std::sort(d.begin(), d.end());
    long i = 0, j = 0;
    long c = 0;
    while(true){
        if(n <= i || n <= j) break;
        if(s[i] < d[j]) ++i;
        else if(s[i] > d[j]) ++j;
        else{
            long tmp1 = i, tmp2 = j;
            while(true){
                if(n <= i || s[i] != s[tmp1]) break;
                ++i;
            }
            while(true){
                if(n <= j || d[j] != d[tmp2]) break;
                ++j;
            }
            c += (i - tmp1) * (j - tmp2);
        }
    }
    std::cout << c << std::endl;

    return 0;
}

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

int main() {
  int i, j;
  int n, m, yen = -1000;
  vector<string> s(100), t(100);
  vector<string> kinds(1);
  
  //入力
  cin >> n;
  rep(k, n)
    cin >> s.at(k);
  cin >> m;
  rep(k, m)
    cin >> t.at(k);
  
  kinds.at(0) = s.at(0);
  //種類分け
 for(i = 1; i < n; i++){
   for( j = 0; j < kinds.size(); j++){
     if(s.at(i) == kinds.at(j))
       break;
   }
   //最後までいってたら追加
   if(j == kinds.size())
     kinds.push_back(s.at(i));
 }
 
  vector<int> points(kinds.size(), 0);
  
  //青カードからもらえる金額を種類ごとに加算
  rep(k, n){
    rep(r, kinds.size()){
      if(s.at(k) == kinds.at(r)){
        points.at(r)++;
        break;
      }
    }
  }
  
  //赤カードから引かれる金額を種類ごとに減算
   rep(k, m){
    rep(r, kinds.size()){
      if(t.at(k) == kinds.at(r)){
        points.at(r)--;
        break;
      }
    }
  }
  
  //最高金額を計算
  rep(k, points.size()){
    if(points.at(k) > yen)
      yen = points.at(k);
  }
  
 //最高金額が0より小さくなる時は全く関係ない文字列を言えば最高値0
  if(yen < 0)
    cout << 0 << endl;
  else
    cout << yen << endl;
  
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //printf(f,##__VA_ARGS__),fflush(stdout)

typedef long long ll;

const int N=2005;

bitset<N*N> f;
int n,sum;
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
	freopen("my.out","w",stdout);
#endif
	scanf("%d",&n);
	f[0]=1;
	rep(i,1,n){
		int x;
		scanf("%d",&x);
		sum+=x;
		f|=f<<x;
	}
	for(int x=(sum+1)/2;x<=sum;++x)if(f[x]){
		printf("%d\n",x);
		break;
	}
	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>

using namespace std;

int main() {
    string a, b;
    cin >> a >> b;

    if (a.size() > b.size()) cout << "GREATER" << endl;
    else if (a.size() < b.size()) cout << "LESS" << endl;
    else if (a > b) cout << "GREATER" << endl;
    else if (a < b) cout << "LESS" << endl;
    else cout << "EQUAL" << endl;
    return 0;
}


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

using namespace std;

using ll= long long;

#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


void solve(){
	string s;
	cin>>s;
	if(s[1]=='B'){
		cout<<"ARC"<<endl;
	}else{
		cout<<"ABC"<<endl;
	}
}

int32_t main(){
	IOS

	int t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

/*
   check for overflows int long long
   correct size of array
*/

Measured memory_bytes: 3676
/*
 A Submission by $%U%$
 at time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FILE_IN "text.out"
#define FILE_OUT "result.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#define ord(a,b,c) ((a>=b)and(b>=c))
#define MOD (ll(1000000007))
#define MAX 300001
#define mag 320
#define p1 first
#define p2 second.first
#define p3 second.second
#define fi first
#define se second
#define pow2(x) (ll(1)<<x)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define For(i,__,___) for(int i=__;i<=___;i++)
#define Rep(i,__,___) for(int i=__;i>=___;i--)
#define ordered_set tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update>
#define bi BigInt
#define pi 3.1415926535897
typedef long long ll;
//------------xúc xích normie tám muoi tám phan tram não----------//
int n,m,k,c[2001],t,t1,i,j,minn,maxx,cur,lu,lv;
bitset<4000001> dp;
int main() {
//	ofile;
	fio;
	cin>>n;
	dp[0]=1;
	for (i=1;i<=n;i++) {
	cin>>c[i];
	dp|=(dp<<c[i]);
	t+=c[i];
	}
	if (t%2==0)
	for (i=0;i<=t/2;i++) 
	{
		if (dp[t/2+i]) return cout<<t/2+i,0;
		if (dp[t/2-i]) return cout<<t/2-i,0;
	}
	else
	for (i=0;i<=t/2;i++) 
	{
		if (dp[t/2+i+1]) return cout<<t/2+i+1,0;
		if (dp[t/2-i]) return cout<<t/2-i,0;
	}
}


Measured memory_bytes: 5080
import sys
import bisect
input = sys.stdin.readline

n=int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
ans=0

for j in range(n):
    al=bisect.bisect_left(a,b[j])
    cl=n-bisect.bisect_right(c,b[j])
    ans+=al*cl
print(ans)


Measured memory_bytes: 22720
A, B, C = map(int, input().split())
if (A == B or A == C) and (B != C):
    print('Yes')
elif (B == C or B == C) and (A != C):
    print('Yes')
elif (C == A or C == B) and (A != B):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double counter = 0;
		for(int i = 0; i < n; i++) {
			double x = sc.nextDouble();
			String u = sc.next();
			if(u.equals("JPY")) {
				counter += x;
			}else if(u.equals("BTC")) {
				counter += 380000*x;
			}
		}System.out.println(counter);
	}

}


Measured memory_bytes: 21460
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll H;
  cin >> H;
  cout << POW(2, log2(H) + 1) - 1 << endl;

  return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vl sorted = a;
    sort(sorted.begin(), sorted.end());
    set<ll> unused;
    ll ret = INF;
    for (int i = 0; i < n; ++i) {
        vl mins;
        vl temp;
        for (int j = 0; j < n; ++j) {
            if (unused.count(a[j]) == 0) {
                temp.push_back(a[j]);
            } else if (!temp.empty()) {
                sort(temp.begin(), temp.end());
                for (int m = 0; m < int(temp.size()) + 1 - k; ++m) {
                    mins.push_back(temp[m]);
                }
                temp.clear();
            }
        }
        if (!temp.empty()) {
            sort(temp.begin(), temp.end());
            for (int m = 0; m < int(temp.size()) + 1 - k; ++m) {
                mins.push_back(temp[m]);
            }
        }
        if (mins.size() >= q) {
            sort(mins.begin(), mins.end());
            chmin(ret, mins[q - 1] - mins[0]);
        }
        unused.insert(sorted[i]);
    }
    cout << ret << "\n";
    return 0;
}


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

int main() {
  int S;
  cin >> S;
  
  int A,B,C,D;
  A = (S / 1000) % 10;
  B = (S / 100) % 10;
  C = (S / 10) % 10;
  D = S % 10;
  
  
 
  if((A - B - C - D) == 7){
    cout << A << '-' << B << '-' << C << '-' << D << "=7" << endl;
  }else if((A - B - C + D) == 7){
	cout << A << '-' << B << '-' << C << '+' << D << "=7" << endl;
  }else if((A - B + C - D) == 7){
	cout << A << '-' << B << '+' << C << '-' << D << "=7" << endl;
  }else if((A - B + C + D) == 7){
	cout << A << '-' << B << '+' << C << '+' << D << "=7" << endl;
  }else if((A + B - C - D) == 7){
	cout << A << '+' << B << '-' << C << '-' << D << "=7" << endl;
  }else if((A + B - C + D) == 7){
	cout << A << '+' << B << '-' << C << '+' << D << "=7" << endl;
  }else if((A + B + C - D) == 7){
	cout << A << '+' << B << '+' << C << '-' << D << "=7" << endl;
  }else{
	cout << A << '+' << B << '+' << C << '+' << D << "=7" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
const int MAXN=2e5+10;
const ll Inf=1e18;
struct gao{   int u,v;   ll w;   int Next;   }Edge[MAXN<<1],Kru[MAXN*20];
int n,Top,Es,Size,Root,Ks,First[MAXN],Stack[MAXN];
int Vis[MAXN],Val[MAXN],Tot[MAXN],Bel[MAXN];
ll Ans,Minp,Mins,Dis[MAXN];
inline int Read()
{   rg int a=0,c=1;   rg char b=getchar();
	while(b!='-'&&(b<'0'||b>'9'))b=getchar();
	if(b=='-')c=-1,b=getchar();
	while(b>='0'&&b<='9')a=a*10+b-48,b=getchar();
	return a*c;
}
inline ll Min(rg ll A,rg ll B){   return A<B?A:B;   }
inline ll Max(rg ll A,rg ll B){   return A>B?A:B;   }
inline bool operator < (rg gao A,rg gao B){   return A.w<B.w;   }
inline void Link(rg int u,rg int v,rg int w)
{   Edge[++Es]=(gao){u,v,w,First[u]},First[u]=Es;   }
inline int Find(rg int S){   return Bel[S]==S?S:Bel[S]=Find(Bel[S]);   }
inline int Merge(rg int A,rg int B){   A=Find(A),B=Find(B),Bel[A]=B;   }
inline void Get_Root(rg int Now,rg int Ba,rg int All)
{   rg int Nw=0;   Tot[Now]=1;
	for(rg int i=First[Now],v;i!=-1;i=Edge[i].Next)
		if((v=Edge[i].v)!=Ba&&!Vis[v]) Get_Root(v,Now,All),Tot[Now]+=Tot[v],Nw=Max(Nw,Tot[v]);
	Nw=Max(Nw,All-Tot[Now]),Nw<Size?(Size=Nw,Root=Now):0;
}
inline void Get_Dis(rg int Now,rg int Ba,rg ll Nd)
{   Tot[Now]=1,Dis[Now]=Nd,Stack[++Top]=Now;
	if(Nd+Val[Now]<Mins) Minp=Now,Mins=Nd+Val[Now];
	for(rg int i=First[Now],v;i!=-1;i=Edge[i].Next)
		if((v=Edge[i].v)!=Ba&&!Vis[v]) Get_Dis(v,Now,Nd+Edge[i].w),Tot[Now]+=Tot[v];
}
inline void Solve(rg int Now)
{   Dis[Now]=0,Top=0,Vis[Now]=1,Mins=Inf,Get_Dis(Now,Now,0);
	for(rg int i=1,Np;i<=Top;i++) Np=Stack[i],Kru[++Ks]=(gao){Np,Minp,Mins+Dis[Np]+Val[Np]};
	for(rg int i=First[Now],v;i!=-1;i=Edge[i].Next)
		if(!Vis[v=Edge[i].v]) Size=n,Get_Root(v,Now,Tot[v]),Solve(Root);
}
int main()
{   n=Read();
	memset(First,-1,sizeof(First));
	for(rg int i=1;i<=n;i++) Val[i]=Read();
	for(rg int i=1,u,v,w;i<n;i++) u=Read(),v=Read(),w=Read(),Link(u,v,w),Link(v,u,w);
	Size=n,Get_Root(1,1,n),Solve(Root),sort(Kru+1,Kru+Ks+1);
	for(rg int i=1;i<=n;i++) Bel[i]=i;
	for(rg int i=1;i<=Ks;i++) Ans+=(Find(Kru[i].u)!=Find(Kru[i].v))*Kru[i].w,Merge(Kru[i].u,Kru[i].v);
	printf("%lld\n",Ans);
}


Measured memory_bytes: 105344
n = int(input())
l = list(map(int, input().split()))
count = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if l[i] != l[j] and l[j] != l[k] and l[k] != l[i] and l[i] + l[j] > l[k] and l[j] + l[k] > l[i] and l[k] + l[i] > l[j] and abs(l[i] - l[j]) < l[k] and abs(l[j] - l[k]) < l[i] and abs(l[k] - l[i]) < l[j]:
        count += 1
print(count)

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

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

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

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

int main() {
  int n;
  cin >> n;
  vector<vector<int> > v(n, vector<int>(26));  // それぞれの文字列に、アルファベットがでてきた回数
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < s.size(); j++) {
      v[i][s[j] - 'a']++;
    }
  }

  for (int i = 0; i < 26; i++) {
    int cou = 100;
    for (int y = 0; y < n; y++) {
      cou = min(cou, v[y][i]);
    }

    // 文字を出力
    for (int j = 0; j < cou; j++) {
      cout << (char)(i + 'a');
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
import bisect
n = int(input())
A, B, C = [sorted([int(x) for x in input().split()]) for i in range(3)]
lst = []
res = 0
for b in B:
  res += bisect.bisect_left(A, b) * (n - bisect.bisect_right(C, b))
print(res)
  

Measured memory_bytes: 23244
paper = [[0 for _ in range(10)] for _ in range(10)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def paint(x, y):
    if 0 <= x <= 9 and 0 <= y <= 9:
        paper[x][y] += 1

while True:
    try:
        x, y, s = map(int, input().split(","))
    except EOFError:
        break
    if x == y == s == -1:
        break
    paint(x, y)
    for i in range(4):
        paint(x + dx[i], y + dy[i])
    if s >= 2:
        for i in range(4):
            paint(x + dx[i] + dx[(i + 1) % 4], y + dy[i] + dy[(i + 1) % 4])
    if s >= 3:
        for i in range(4):
            paint(x + 2 * dx[i], y + 2 * dy[i])

print(sum(paper[i].count(0) for i in range(10)))
print(max(paper[i][j] for i in range(10) for j in range(10)))

Measured memory_bytes: 7620
import std.stdio;
import std.algorithm;
import std.math;
import std.string;
import std.conv;
import std.range;

void main() {
    foreach (string line; stdin.lines) {
        string s = line.chomp;
        int joi = 0;
        int ioi = 0;
        for (int i = 0; i < s.length - 2; i++) {
            if (s[i..i+3] == "JOI") {
                joi++;
            } else if (s[i..i+3] == "IOI") {
                ioi++;
            }
        }
        joi.writeln;
        ioi.writeln;
    }
}

Measured memory_bytes: 1064
import java.util.*;


public class Main {

	public static void main(String[] args) {
		
		Scanner cin = new Scanner(System.in);
		
		
		int n = cin.nextInt();
		cin.nextInt();
		cin.nextLine();
		
		String[] strs = new String[n];
		
		for (int i = 0; i < n; i ++) {
			strs[i] = cin.nextLine();
		}
		
		Arrays.sort(strs, (s1,s2) -> (s1+s2).compareTo(s2+s1));
		
		for (int i = 0; i < n; i ++) {
			System.out.print(strs[i]);
		}
	}

}



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

int main(){
    int n;
    cin >> n;
    int A[n];
    int B[n];
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        B[i] = A[i];
    }
    sort(B, B + n);
    int cnt = 0;
    // int i = 0;
    for (int i = 0; i < n; i++) {
        // if (A[i] == B[i]) {
        //     i++;
        //     continue;
        // }
        int tgt_idx = find(A, A + n, B[i]) - A;
        int n_cycle = 1;
        while (tgt_idx != i) {
            int dst_idx = find(A, A + n, B[tgt_idx]) - A;
            cnt += A[tgt_idx] + A[dst_idx];
            swap(A[tgt_idx], A[dst_idx]);
            tgt_idx = dst_idx;
            n_cycle++;
        }
        if ((n_cycle - 3) * B[i] > (n_cycle + 1) * B[0]) {
            cnt -= (n_cycle - 3) * B[i] - (n_cycle + 1) * B[0];
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3140