akhauriyash/Code-Regression huggingface dataset:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = list(input())
t = list(input())
s.sort()
t.sort(reverse = True)
print('Yes' if s < t else 'No')

Measured memory_bytes: 65004
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <sstream>
using namespace std;



int main() {
	int d;
	int g;
	cin >> d >> g;

	vector<int> p(d);
	vector<int> c(d);
	vector<int> tot(d);
	for (int i = 0; i < d; i++) {
		int pp;
		int cc;
		cin >> pp >> cc;
		p.at(i) = pp;
		c.at(i) = cc;
		tot.at(i) = pp * (i + 1) * 100 + cc;
	}

	auto piter = max_element(p.begin(), p.end());
	int pmax = *piter;
	int ans = (pmax + 1) * (pmax + 1);
	for (int bit = 0; bit < (1 << d); bit++) {
		int pts = 0;
		int count = 0;
		vector<int> pcopy = p;
		int pos = -1;
		for (int i = 0; i < d; i++) {
			// fully solve
			if (bit & (1 << i)) {
				pts += tot.at(i);
				count += p.at(i);
				pcopy.at(i) = 0;
			}
			else {
				pos = max(pos, i);
			}
		}
	
		if (pos >= 0) {
			for (int j = 1; j < p.at(pos); j++) { // p: # of questions; pos + 1 = point/100. Do not fully solve the questions
				if (pts < g) {
					pts += (pos + 1) * 100;
					count += 1;
				}
				else {
					break;
				}
			}
		}
		if(pts >= g) ans = min(ans, count);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)cin >> a[i];
    ll ans = inf;
    for(int i = -100; i <= 100; i++){
        ll now = 0;
        rep(j, n){
            now += pow(a[j]-i, 2);
        }
        ans = min(ans, now);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vs s(n); vl l(n);
    rep(i,n)cin>>s[i]>>l[i];
    ll ans=0;
    string x; cin>>x;
    rrep(i,n){
        if(s[i]==x)break;
        ans+=l[i];
    }
    puta(ans);
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Array
import Data.List
main = do
  n <- read <$> getLine
  xs <- replicateM (n-1) $ read <$> getLine
  let a = accumArray (flip (:)) [] (1,10^5) $ zip xs [2..]
      f [] = 0
      f is = maximum $ zipWith (+) [1..] $ reverse $ sort $ map (f . (a!)) is
  print $ f $ a!1

Measured memory_bytes: 47740
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int cnt = 0;

		for (int i = 0; i < C + 1; i++) {

			int Y = X - 50 * i;

			if(Y == 0) {
				cnt ++;
				continue;
			}

			for (int j = 0; j < B + 1; j++) {

				int Z = Y - 100 * j;

				if(Z == 0) {
					cnt++;
					continue;
				}

				for (int k = 0; k < A + 1; k++) {

					int W = Z - 500 * k;

					if(W == 0) {
						cnt ++;
						continue;
					}
				}
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define Fi first
#define Se second
string s;
signed main(){
    cin>>s;
    int k=s.size();
    int v=15-k;
    rep(i,k){
        if(s[i]=='o')v++;
    }
    if(v>=8)puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 256
## C - Average Length
import math
import itertools
N = int(input())
X = [0] * N
Y = [0] * N
L = [n for n in range(N)]

for n in range(N):
    X[n], Y[n] = map(int, input().split())

dist = 0
cnt = 0
for i in itertools.permutations(L, N):
    cnt += 1
    for n in range(1,N):
        dist += math.sqrt( (X[i[n]]-X[i[n-1]]) ** 2 + (Y[i[n]]-Y[i[n-1]]) ** 2 )
print(dist / cnt)

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

using namespace std;
 
int main() {
    long r,d,x;
    cin>>r>>d>>x;
    long moto = x;
    for(int i = 0;i<10;i++){
      moto = moto*r-d;
      cout<<moto<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    x_p1, y_p1, x_p2, y_p2 = map(lambda x: int(x), input().split())
    q = int(input())

    p1p2 = (x_p2 - x_p1, y_p2 - y_p1)
    for _ in range(q):
        x_p0, y_p0 = map(lambda x: int(x), input().split())
        p1p0 = (x_p0 - x_p1, y_p0 - y_p1)
        r = (p1p2[0] * p1p0[0] + p1p2[1] * p1p0[1]) / (p1p2[0] ** 2 + p1p2[1] ** 2)
        proj_p = (x_p1 + p1p2[0] * r, y_p1 + p1p2[1] * r)
        proj_v = (proj_p[0] - x_p0, proj_p[1] - y_p0)
        print(x_p0 + 2 * proj_v[0], y_p0 + 2 * proj_v[1])



Measured memory_bytes: 5628
#include <bits/stdc++.h> 
#include <queue>
using namespace std;
char maze[20][20];
int H,W;
typedef pair<int,int> P;
int getMoves( int sx, int sy )
{
	int dirx[] = { 0, 0, 1, -1 };
	int diry[] = { 1, -1,0, 0};
	queue<P> poss; 
	poss.push(P(sx,sy));
	map<P,int> steps;
	steps[P(sx,sy)] = 0;
	int step = 0;
	//cout << "----------------------"<<sx<<"-"<<sy<<"-----------------------------"<<endl;
	while( !poss.empty() )
	{
		P pos = poss.front();
		poss.pop();
		for( int i=0; i<4; i++ )
		{
			int gx = pos.first + dirx[i];
			int gy = pos.second + diry[i];
			if( gx>=0 && gx<H && gy>=0 && gy<W && maze[gx][gy]=='.' )
			{				
				if( !steps.count(P(gx,gy) ) )
				{
					steps[P(gx,gy)] = steps[P(pos.first,pos.second)]+1;
					poss.push(P(gx,gy));
					if( step < steps[P(gx,gy)] )
						step = steps[P(gx,gy)];
						
					//cout << "("<<gx<<","<<gy<<")="<<step<<endl;
				}
			}
		}
	}
	//cout << "----------------------"<<step<<"------------------------------"<<endl;
	
	//cout << "("<<startX<<","<<startY<<"),("<<endX<<","<<endY<<"):"<<step<<endl;
	return step;
}
int main()
{
	//while(true)
	{
		cin>>H>>W;
		for( int i=0; i<H; i++ )
		{
			for( int j=0; j<W; j++ )
			{
				cin>>maze[i][j];
			}
		} 
		
		int maxMoves = 0;
		for( int i=0; i<H; i++ ) 
		{
			for( int j=0; j<W; j++ )
			{
				if( maze[i][j] == '.')
				{
					int moves = getMoves(i,j);
					if( maxMoves < moves )
						maxMoves = moves;	
				}
			}
		}
		cout <<maxMoves<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    final int A, B, C, D;

    AtCoder(FastScanner sc) {
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        D = sc.nextInt();
    }

    void solve(PrintWriter out) {
        out.println(Math.max(A * B, C * D));
    }

}

class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21460
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

ll dig(ll n){
	return to_string(n).size();
}

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

	ll N;
	cin >> N;

	ll mn = 100;
	for(ll i =1;i<=sqrt(N);i++){
		if(N % i == 0) {
			mn = min(mn,max(dig(i),dig(N/i)));
		}
	}

	cout << mn << endl;
}

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

const int mod = 1e9+7;

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

    int dp[1001] = {};
    dp[0] = 1;

    for(int i = 0; i < t.length(); i++){
        for(int j = b.length()-1; j >= 0; j--){
            if(t[i] == b[j]){
                dp[j+1] = (dp[j+1]+dp[j])%mod;
            }
        }
    }

    cout << dp[b.length()] << endl;

    return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
int n,m,ans;
int main(){
	scanf("%d%d",&n,&m);
	if (n>=2) ans+=n*(n-1)/2;
	if (m>=2) ans+=m*(m-1)/2;
	printf("%d\n",ans);
return 0;	
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val k = sc.nextInt()
    val a, b = sc.nextInt()

    var flag = false

    for (i <- a to b) {
      flag = flag || i % k == 0
    }

    val ans = if (flag) "OK" else "NG"

    println(ans)
  }

  @scala.annotation.tailrec
  def gcd(a: Int, b: Int): Int = {
    if (b == 0) a else gcd(b, a % b)
  }
  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}


Measured memory_bytes: 55276
#include<iostream>
#include<string.h>
using namespace std;

int main(){
    char s[4],t[4];
    int n=0;
    cin>>s;
    cin>>t;
    for(int i=0;i<=2;i++){
        if(s[i]==t[i]){
            n++;
            
        }
        }
        cout<<n<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int x, t;
	cin >> x >> t;

	cout << max(x - t, 0) << endl;

}

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

using namespace std;
using ll = long long;

#define debug(x) cerr << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

const int maxn = 2e5 + 10;

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

ll a[maxn];
ll suff[maxn];

int main()
{
	ios::sync_with_stdio(false);
	int test = 1;
	while(test--)
	{
		int n;
		cin >> n;
		for(int i = 1; i <= n ; i++)
			cin >> a[i];

		for(int i = n ; i >= 1; i--)
			suff[i] = (suff[i + 1] + a[i]) % mod;
		
		ll ans = 0;
		for(int i = 1 ; i < n ; i++)
		{
			ans += (a[i] * suff[i + 1]) % mod;
			ans %= mod;
		}

		cout << ans << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 6760
// Problem Code: abc172_d

#include <iostream>

using namespace std;

long long sum_of_divisors(int N) {
	long long res = 0;
	for (int i = 1; i <= N; i++) {
		long long f = N / i;
		res += i * f * (f + 1) / 2;
	}
	return res;
}

int main() {
	int N;
	cin >> N;
	cout << sum_of_divisors(N);
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  long k;
  cin >> n >> k;
  vector<long>a(n);
  int i;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  long bit = 1;
  long bitss = 0;
  int tmp = 0;
  long bb = 1;

  while(bb<=k) bb*=2;
  bb/=2;
  for(bit=bb;bit>=1;bit/=2){
    tmp = 0;
    for(i=0;i<n;i++){
      if(bit & a[i])tmp++;
    }
    if(tmp*2<n && bitss+bit<=k)bitss += bit;
  }
  long ans = 0;
  for(i=0;i<n;i++){
    ans += bitss^a[i];
  }
  cout << ans << endl;


}


Measured memory_bytes: 1024
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1000000000

using namespace std;
typedef pair<llint, llint> P;

llint n;
vector<llint> G[10005];
bool used[10005];
llint ans[105][105];

int main(void)
{
  cin >> n;
  llint u, v;
  for(int i = 1; i <= 2*n*n-2*n; i++){
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for(int i = 1; i <= n*n; i++){
    if(G[i].size() == 2){
      v = i;
      break;
    }
  }

  ans[1][1] = v, used[v] = true;
  for(int i = 2; i <= n; i++){
    for(int j = 0; j < G[v].size(); j++){
      u = G[v][j];
      if(used[u]) continue;
      if(G[u].size() > 3) continue;
      v = u;
      ans[1][i] = v;
      used[v] = true;
      break;
    }
  }
  for(int i = 2; i <= n; i++){
    for(int j = 1; j <= n; j++){
      int v = ans[i-1][j];
      for(int k = 0; k < G[v].size(); k++){
        int u = G[v][k];
        if(used[u]) continue;
        ans[i][j] = u;
        used[u] = true;
        break;
      }
    }
  }

  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      cout << ans[i][j];
      if(j < n) cout << ' ';
      else cout << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 4016
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,avx,avx2,mmx,abm")
//#pragma GCC optimize("O3,unroll-loops,inline")
#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;

int add(int a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

const int MAXN = 3010;
int n, s;
int a[MAXN];
int dp[MAXN];

signed main() {
	scanf("%d%d", &n, &s);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	int ans = 0;
	for (int i = 0; i <= s; i++)
		dp[i] = 0;
	for (int i = 1; i <= n; i++) {
		for (int w = s - a[i]; w >= 1; w--) {
			int nxt = w + a[i];
			dp[nxt] = add(dp[nxt], dp[w]);
		}
		int nxt = a[i];
		if (nxt <= s) dp[nxt] = add(dp[nxt], i);
		ans = add(ans, dp[s]);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
main = do
  _ <- getLine
  as <- map read . words <$> getLine
  let o = length [ a | a <- as, odd a]
  let f = length [ a | a <- as, a `mod` 4 == 0 ]
  let t = if length as - o - f > 0 then 1 else 0
  putStr $ if f + 2 > o + t then "Yes" else "No"

Measured memory_bytes: 36220
N,K = map(int,input().split())
cc = list(map(int,input().split()))
memo = []
aa = ['.']*N
a = 1
while aa[a-1] == '.':
  memo.append(a)
  aa[a-1] = 'v'
  a = cc[a-1]
if len(memo)>K:
  print(memo[K])
else:
  b = memo.index(a)
  m = len(memo)-b
  mm = (K-b) % m
  del memo[:b]
  print(memo[mm])

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

int main(){
  string s;
  cin>>s;
  int a=s[0]-'0';
  int b=s[1]-'0';
  int c=s[2]-'0';
  int d=s[3]-'0';
  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 if(a-b-c-d==7)cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
  return 0;
}


Measured memory_bytes: 3628
S = list(str(input()))
T = list(str(input()))
i = 0
ans = []
len_s = len(S)
len_t = len(T)
while i < len_s-len_t+1:
    cnt = 0
    for ss, tt in zip(S[i:i+len_t], T):
        if ss != tt:
            cnt += 1
    ans.append(cnt)
    i += 1
print(min(ans))

Measured memory_bytes: 8892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

map<ll, ll> m;

ll solve(long long h){
	if (m[h] != 0) return m[h];
	if (h == 1) return m[h] = 1;
	return m[h] = solve(h/2)*2+1;
}

int main(){	
	long long H;
	scanf("%lld",&H);
	cout << solve(H) << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n;
  std::cin >> n;
  vt<int> v(9);
  rep(i,n) {
    int a;
    std::cin >> a;
    if(a/400 < 8)
      v[a/400] = 1;
    else
      v[8]++;
  }

  int ans = 0;
  rep(i,8) {
    ans += v[i];
  }

  if(ans == 0)
    std::cout << 1 << ' ' << v[8] << '\n';
  else
    std::cout << ans << ' ' << ans + v[8] << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

using namespace std;

double calFormula(const int64_t &A, const int64_t &B, const int64_t &C, const int64_t &D)
{
    return (double)(A+B) / (C-D);
}

int main()
{

    int N;
    cin >> N;

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

    sort(list.begin(),list.end());
    reverse(list.begin(),list.end());

    double max_val = 0;
    //loop

    for(int a = 0; a < N; a++)
    {
        if(a > 10){ break; }
        for(int b = a + 1; b < N; b++)
        {
            if(b > 10){ break; }
            for(int c = 0; c < N; c++)
            {
                if(a == c || b == c){ continue; }
                for(int d = c + 1; d < N; d++)
                {
                    if(a == d || b == d){ continue; }
                    max_val = max(max_val, calFormula( list[a], list[b], list[c], list[d] ));
                }
            }
        }
    }


    cout << fixed << setprecision(5);
    cout << max_val << endl;

    return 0;
}

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


int SegTree[1<<18];

void update(int l,int r,int x)
{
	while (l!=r)
	{
		if(l%2)
		{
			SegTree[l] +=x;
			l++;
		}
		if(r%2)
		{
			SegTree[r-1] += x;
			r--;
		}
		l/=2;
		r/=2;
	}
	//SegTree[l] = make_pair(x,t);
	//cout<<l<<endl;
}

int get(int i)
{
	int res = 0;
	while(i!=0)
	{
		res += SegTree[i];
		i/=2;
	}
	return res;
}


int main()
{
	//cout<<(1<<18)<<endl;
	int n,q;
	cin >> n >> q;
	for(int i = 0;i<(1<<18);i++)
	{
		SegTree[i]=0;
	}
	for(int i = 0;i<q;i++)
	{
		int op;
		cin >> op;
		if(op)
		{
			int I;
			cin >> I;
			I += (1<<17);
			I--;
			cout<<get(I)<<endl;
			
		}
		else
		{
			int s,t,x;
			cin >> s >> t >> x;
			s--;
			t--;
			s+=(1<<17);
			t+=(1<<17);
			t++;
			update(s,t,x);

		}
		//cout<<SegTree[(1<<17)].first<<endl;
	}
}


Measured memory_bytes: 4116
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 200005
using namespace std;

int main() {
  int r;
  cin >> r;
  if(r < 1200) cout << "ABC" << endl;
  else if(r < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, vs, n, m) vector<vector<T>> vs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]

using namespace std;
using ll = long long;

int main(void){
    Cin(ll, n);
    Cin(ll, m);
    Cout(abs(n-2)*abs(m-2));
}


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

ll INF = 1LL << 60;
ll weights [(int) 1e5 + 1];
ll rewards [(int) 1e5 + 1];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    ll N, M;
    cin >> N >> M;
    map<int, vector<int>> jobs;

    for (int i = 0; i < N; ++i) {
        ll t, r;
        cin >> t >> r;
        if (t > M) continue;
        jobs[t].push_back(r);
    }

    multiset<int> possibleJobs;
    ll total = 0;
    for (int t = 1; t <= M; ++t) {
        for (int x : jobs[t]) {
            possibleJobs.insert(x);
        }
        if (possibleJobs.empty()) continue;
        
        total += *(--possibleJobs.end());
        possibleJobs.erase(--possibleJobs.end());
    }
    cout << total << endl;
}

Measured memory_bytes: 13172
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(void){
    ll N=0;
    cin >> N;
    ll count=0;;
    for(ll i=1;i<=N;i++){
        if(i%3!=0&&i%5!=0){
            count+=i;
        }
    }
    
    cout << count;

}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
#define s second
#define int long long

int32_t main()
{
 
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   // int t;
   // cin >> t;
   // while(t--){
 	int n;
 	cin >> n;
 	if(n%1000 == 0)cout << 0 << endl;
 	else cout << (1000 - n%1000) << endl;
   // }
return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Knapsack(ll* weights,ll* values, int w, int n){
    ll dp[n+1][w+1];
    for(int i =0; i <= n; i++){
        for(int j =0; j <=w; j++){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
            }
            else if(weights[i-1] <= j){
                dp[i][j] = max(dp[i-1][j], values[i-1] + dp[i-1][j - weights[i-1]]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    return dp[n][w];
}
int main(){
    int n, w;
    cin >> n >> w;
    ll* weights = new ll[n];
    ll* values = new ll[n];
    for(int i =0; i < n; i++){
        cin >> weights[i] >> values[i];
    }
    ll answer = Knapsack(weights, values, w, n);
    cout<<answer<<"\n";
    return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define MAXN 100005
#define MOD 1000000007LL

using namespace std;
using ll = long long;

int N;
vector<int> graph[MAXN];
ll dp[MAXN][2];

ll solve(int node, int par, int col) {
  ll& res = dp[node][col];
  if (res != -1) { return res; }
  res = 1LL;
  for (int child : graph[node]) {
    if (child == par) { continue; }
    ll cur = solve(child, node, col ^ 1);
    if (col) { cur = (cur + solve(child, node, col)) % MOD; }
    res = (res * cur) % MOD;
  }
  return res;
}

int main() {
  fill(&dp[0][0], &dp[0][0] + MAXN * 2, -1LL);
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int a, b; cin >> a >> b;
    a--, b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  cout << (solve(0, -1, 0) + solve(0, -1, 1)) % MOD << '\n';
  return 0;
}


Measured memory_bytes: 15616
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 555;
int h, w;
char a[N][N],b[N][N],c[N][N];


int main() {
	scanf("%d%d", &h, &w);
	REP(i,1,h) scanf("%s",a[i]+1);
	memcpy(b,a,sizeof a);
	memcpy(c,a,sizeof a);
	REP(i,1,h) {
		b[i][1]=c[i][w]='#';
		if (i&1) REP(j,1,w-1) b[i][j]='#';
		else REP(j,2,w) c[i][j]='#';
	}
	REP(i,1,h) puts(b[i]+1);
	REP(i,1,h) puts(c[i]+1);
}








Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static int N;
    static int A;
    static int B;
    static int C;
    static int D;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        D = sc.nextInt();

        System.out.println( solve() ? "YES" : "NO" );
    }

    static boolean solve() {
        // GはgoalのG
        int G = Math.abs(A-B);
        int times = N - 1;

        // C*q D*q G という状態まで詰める
        int q = G / D;
        int r = G % D;
        times -= q;

        // 回数切れで届かない
        if( times < 0 ) return false;
        // ぴったりのケース(ここでやらなくてもよい気がする)
        if( times == 0 ) return r == 0;

        if( times % 2 == 0 ) {
            // +D -Cとすることで D-Cずつ距離を詰めることができる
            long available = (times / 2) * (long)(D-C);
            return r <= available;

        } else {
            // もう一歩進む
            // G C1 D1 or C1 G D1
            long C1 = C * (q+1);
            long D1 = D * (q+1);
            times -= 1;

            // C1 <= G <= D1 の場合はそれで終了(0で足踏みすればよい)
            if( C1 <= G && G <= D1 ) return true;

            // G C1 D1 という状態なので C1からGに向かって詰めることができたらOK
            long r1 = C1 - G;
            long available = (times / 2) * (long)(D-C);
            return r1 <= available;
        }
    }

    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}



Measured memory_bytes: 21204
def calc():
  n=int(input())
  s=list(input())
  cnt1=0
  cnt2=0
  cnt3=0
  for i in range(n):
      if s[i]=='R':
          cnt1+=1
          s[i]=1
      elif s[i]=='G':
          cnt2+=1
          s[i]=2
      elif s[i]=='B':
          cnt3+=1
          s[i]=4
  ans=cnt1*cnt2*cnt3
  for i in range(n):
      for j in range(i+1,n):
        k=2*j-i
        if k>=n:
          continue
        if s[i]+s[j]+s[k]==7:
            ans-=1
  print(ans)
calc()

Measured memory_bytes: 9236
import sys
input = sys.stdin.readline
A,B,K = map(int, input().split())
 
while(K > 0):
  if A >= K:
    A -= K
    K = 0
    break
  else:
    K -= A
    A = 0
    if B >= K:
      B -= K
      K = 0
      break
    else:
      K -= B
      B = 0
      break
print(' '.join(map(str, [A,B])))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(){
    int r,D;
    long int x;
    cin>>r>>D>>x;
    for(int i=1;i<=10;i++){
        x=r*x-D;
        cout<<x<<endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
#define MOD (1000000007ll)
#define l_ength size

int main(void){
	int n;
	cin >> n;
	cout << "ABC" << n << endl;
	return 0;
}

Measured memory_bytes: 256
n,x=map(int,input().split())
a=list(map(int,input().split()))
a=sorted(a)
b=0

for i in range(n):
	x=x-a[i]
	if x>=0:
		b+=1
if x==0:
	print(b)
elif x<0:
	print(b)
else:
	print(b-1)

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (auto &v : vec)
    cin >> v;

  int sum = 0;
  for (int i = 0; i < n; ++i)
    for (int j = i+1; j < n; ++j)
      sum += vec[i] * vec[j];

  cout << sum << endl;
}

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



int intPow(int base, int exp) {
    return (exp <= 1) ? base : (base * intPow(base, exp - 1));
}

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<string>> map(H);

    rep(i, H) {
        map[i] = vector<string>(W);
        string row;
        cin >> row;
        rep(j, W) {
            map[i][j] = row[j];
        }
    }

    auto getCount = [H, W, &map](int HMask, int WMask){
        int cnt = 0;
        rep(i, H) {
            rep(j, W) {
                if (map[i][j] == "#" &&
                    !(HMask & (1 << i)) &&
                    !(WMask & (1 << j))) cnt++;
            }
        }
        return cnt;
    };

    int ans = 0;
    int cnt = 0;
    rep(i, intPow(2, H)) {
        rep(j, intPow(2, W)) {
            if (getCount(i, j) == K) ans++;
            cnt++;
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;


int main()
{
    int n, l;
    cin >> n >> l;
    int sum = l*n + n*(n-1)/2;
    int d = n + l - 1;
    if (l <= 0 && d >= 0){
        cout << sum << endl;
    } else if (d < 0) {
        cout << sum - d<< endl;
    } else {
        cout << sum - l<< endl;
    }
}



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

void solve() {
   int n, m;
   cin >> n >> m;
   vector <string> s(n);
   for(int i = 0; i < n; i++) {
      cin >> s[i];
      s[i] = "#" + s[i] + "#";
   }
   string pad(m + 2, '#');
   cout << pad << endl;
   for(auto str: s)
      cout << str << endl;
   cout << pad << endl;
}

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}


Measured memory_bytes: 3632
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BC
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  [a, b, c] <- getInts
  print $ solve a b c

solve :: Int -> Int -> Int -> Int
solve a b c
  | a == b    = c
  | b == c    = a
  | otherwise = b

readInts :: BC.ByteString -> [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words

getInts :: IO [Int]
getInts = readInts <$> BC.getLine


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

int main() {
	vector<int>a(3);
	for (int i = 0; i < 3; i++)cin >> a.at(i);
	sort(a.begin(), a.end());
	int k;
	cin >> k;
	ll ans = a.at(0) + a.at(1) + pow(2, k) * a.at(2);
	cout << ans << endl;
}

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

long long n,l;
vector<long long> x,pre,suf;

long long solve();

int main(){
    cin >> l >> n;
    x.resize(n);
    for(int i = 0;i < n;++i)cin >> x[i];
    cout << solve() << endl;
    return 0;
}

long long solve(){
    pre.assign(n+1,0);
    suf.assign(n+1,0);
    for(int i = 0;i < n;++i){
        pre[i+1] = x[i] + pre[i];
        suf[i+1] += l - x[n-1-i] + suf[i];
    }
    long long ans = 0;
    for(int i = 0;i <= n;++i){
        long long now = 0;
        now += (pre[i+(n-i+1)/2] - pre[i] + suf[(n-i)/2]) * 2;
        if((n-i)%2)now -= x[i+(n-i)/2];
        else now -= l - x[n-1-(n-i-1)/2];
        ans = max(ans,now);
    }
    swap(pre,suf);
    reverse(x.begin(),x.end());
    for(int i = 0;i < n;++i)x[i] = l - x[i];
    for(int i = 0;i <= n;++i){
        long long now = 0;
        now += (pre[i+(n-i+1)/2] - pre[i] + suf[(n-i)/2]) * 2;
        if((n-i)%2)now -= x[i+(n-i)/2];
        else now -= l - x[n-1-(n-i-1)/2];
        ans = max(ans,now);
    }
    return ans;
}

Measured memory_bytes: 4992
# include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,B,a[1000],b[1000],sum=0;
    cin>>N;
    for(int i=1;i<N;i++)
        cin>>a[i];
    b[0]=a[1];
    b[N-1]=a[N-1];
    for(int i=1;i<N-1;i++)
        b[i]=min(a[i],a[i+1]);
    for(int i=0;i<N;i++)
        sum+=b[i];
    cout<<sum<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    int n;
    ll k, z = 0;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll& i : a) cin >> i;
    sort(ALL(a));
    vector<ll> neg, pos;    
    for(ll& i : a) if(i < 0) neg.emplace_back(i); else if(i > 0) pos.emplace_back(i); else z++;

    auto check = [&](ll val)
    {
        ll cnt = 0;

        if(val < 0)
        {
            if(LEN(neg) && LEN(pos))
            {
                for(int i = 0, j = 0; i < LEN(pos); i++)
                {
                    while(j < LEN(neg) && pos[i] * neg[j] < val) j++;
                    cnt += j;
                }
            }
        }
        else if(!val)
        {
            cnt += LEN(neg) * 1LL * LEN(pos);
        }
        else
        {
            cnt += z * (z - 1LL) / 2LL;
            cnt += z * (LEN(neg) + LEN(pos));
            cnt += LEN(neg) * 1LL * LEN(pos);

            if(LEN(neg) > 1)
            {
                for(int i = 0, j = LEN(neg) - 1; i < LEN(neg) - 1; i++)
                {
                    while(j >= 0 && neg[i] * neg[j] < val) j--;
                    cnt += LEN(neg) - max(i, j) - 1;
                }
            }

            if(LEN(pos) > 1)
            {
                for(int i = 0, j = LEN(pos) - 1; i < LEN(pos) - 1; i++)
                {
                    while(j >= 0 && pos[i] * pos[j] >= val) j--;
                    cnt += max(j - i , 0);
                }
            }
        }

        // cout << val << ": " << cnt << endl;
        return cnt < k;
    };

    // check(-6); 
    // check(-7); 
    // check(-8); 
    // check(-9); 

    // ll l = -20, r = 20, ans = 2 * INF<ll>;
    ll l = -INF<ll>, r = INF<ll>, ans = 2 * INF<ll>;
    while(l <= r)
    {
        ll mid = l + (r - l) / 2;
        if(check(mid)) ans = mid, l = mid + 1;
        else r = mid - 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7132
import numpy as np
import time
import random
import collections
import bisect  

start = time.time()

def insert(list, n): 
    bisect.insort(list, n)  
    return list

def read_input():
  D = int(input())
  c = list(map(int, input().split()))
  s = [list(map(int, input().split())) for _ in range(D)]
  return D, c, s
D, c, s = read_input()

c = np.array(c)
s = np.array(s)
tests = np.argmax(s, axis=1)

def get_dates_for_tests(tests):
  dates_for_tests = [list([-1]) for _ in range(26)]
  for i, t in enumerate(tests):
    dates_for_tests[t].append(i)
  for t in range(26):
    dates_for_tests[t].append(D)
  return dates_for_tests

dates_for_tests = get_dates_for_tests(tests)

def get_score(tests):
  dates_for_tests = get_dates_for_tests(tests)
  score = 0
  d = np.zeros(26, dtype=np.int64)
  for selected, S in zip(tests, s):
    d += 1
    d[selected] = 0
    score += S[selected] - (c * d).sum()
  return score

def score_diff(date, test):
  #print(date, test)
  before = tests[date]
  if test == before:
    return 0, None, None
  pos_diff = s[date, test] - s[date, before]
  new_index = bisect.bisect_left(dates_for_tests[test], date, 1)
  new_diff = c[test] * (dates_for_tests[test][new_index] - date) * (date - dates_for_tests[test][new_index-1])

  old_index = bisect.bisect_left(dates_for_tests[before], date, 1)
  #print(c[test], dates_for_tests[test])
  #print(c[before], dates_for_tests[before])
  old_diff = c[before] * (dates_for_tests[before][old_index+1] - date) * (date - dates_for_tests[before][old_index-1])
  
  total_diff = pos_diff + new_diff - old_diff
  #print(test, total_diff, pos_diff, new_diff, -old_diff)
  return total_diff, new_index, old_index

def update(date, test, dates_for_tests=dates_for_tests, tests=tests):
  dates_for_tests[tests[date]].remove(date)
  insert(dates_for_tests[test], date)
  tests[date] = test

# current_score = get_score(tests)
while time.time() < start + 1.8:
  t = time.time()
  for date in range(D):
    for test in range(26):
      # date = 4
      # test = 23

      total_diff, new_index, old_index= score_diff(date, test)
      to_update = total_diff > 0
      if t < start + 1.6 and total_diff > -5000:
        to_update += random.randrange(5) == 0
      if to_update:
        update(date, test)
        
# print(get_score(tests))
for t in tests:
  print(t+1)


Measured memory_bytes: 27364
#include<iostream>
using namespace std;
const int inf =0x3f3f3f3f;
int n,q,k;
int a[100005] ;
int main()
{
	cin >> n >> k >> q;
	int x;
	for(int i=0;i<q;i++) {
		cin >> x;
		a[x]++;		
	}
	for(int i=1;i<=n;i++)  {
		if(k-q+a[i]>0) printf("Yes\n");
		else printf("No\n" ) ;
	}	
	return 0;
}

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

#define ll long long

int main() {
    std::ios::sync_with_stdio(false);
    using namespace std;
    const int max_v = 100'000, max_n = 12, max_cost = max_v * max_n;
    int n, m, a, b, c;
    cin >> n >> m;
    vector<int> A(m), B(m, 0), C(1<<n, max_cost + 1);
    for(int i = 0; i < m; i++) {
        cin >> A[i] >> b;
        for(int j = 0; j < b; j++) {
            cin >> c;
            B[i] += (1<<(c - 1));
        }
    }
    C[0] = 0;
    for(int i = 1; i < (1<<n); i++) {
        for(int j = 0; j < m; j++)
            C[i] = min(C[i], C[i & (~B[j])] + A[j]);
    }
    int res = C[(1<<n) - 1];
    cout << (res == max_cost + 1 ? -1 : res) << "\n";
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define range(i,a,b) for(int i=a; i<(int)(b); i++)
#define rep(i,b) range(i,0,b)

typedef int Capacity;
struct Edge {
    int src, dst;
    Capacity cap;
    Edge(int src_, int dst_, int cap_) :
        src(src_), dst(dst_), cap(cap_) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<int> Array;
typedef vector<Array> Matrix;

int const inf = 1e9;

typedef int Capacity;
struct FordFulkerson {
    typedef vector<vector<Capacity>> Matrix;
    int n, t;
    Capacity res;
    vector<bool> vis;
    Matrix cap, flow;
    vector<vector<int>> g;
    FordFulkerson(const int n){ *this = FordFulkerson(Graph(n)); }
    FordFulkerson(const Graph &graph)
        : n(graph.size()), res(0), cap(n, Array(n)), flow(n, Array(n)), g(n, vector<int>()){
        rep(i,n)rep(j,graph[i].size()){
            int u = graph[i][j].src, v = graph[i][j].dst; Capacity c = graph[i][j].cap;
            cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
        }
        rep(i,n)rep(j,n) if(cap[i][j]) g[i].push_back(j), g[j].push_back(i);
    }
    void add_edge(int u, int v, Capacity c){
        g[u].push_back(v); g[v].push_back(u);
        cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
    }
    Capacity solve(int s, int t){
        this->t = t;
        Capacity f = -1;
        while(f) vis.assign(n,false), res += (f = augment(s,inf));
        return res;
    }
    Capacity augment(int v, Capacity lim){
        vis[v] = true;
        if(v == t) return lim;
        for(const int &i : g[v]){
            if(vis[i] || flow[v][i] == cap[v][i]) continue;
            Capacity f = augment(i, min(lim, cap[v][i] - flow[v][i]));
            flow[v][i] += f; flow[i][v] -= f;
            if(f) return f;
        }
        return 0;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    FordFulkerson g(N);
    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        g.add_edge(a,b,c);
    }
    cout << FordFulkerson(g).solve(0,N-1) << endl;
}

Measured memory_bytes: 1420
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int n, m;
LL zip(LL p, LL c) {
  return n * c + p;
}

int main(void)
{
  cin >> n >> m;
  map<LL, set<tuple<LL, int> >> e;
  REP(i,m) {
    int p, q, c;
    cin >> p >> q >> c;
    e[zip(p, c)].emplace(zip(q, c), 0);
    e[zip(q, c)].emplace(zip(p, c), 0);
    e[zip(p, 0)].emplace(zip(p, c), 1);
    e[zip(p, c)].emplace(zip(p, 0), 0);
    e[zip(q, 0)].emplace(zip(q, c), 1);
    e[zip(q, c)].emplace(zip(q, 0), 0);
  }
  set<LL> already;
  priority_queue<tuple<int, LL>> pq; // negc, station
  pq.emplace(0, zip(1, 0));
  while(!pq.empty()) {
    int negc;
    LL station;
    tie(negc, station) = pq.top();
    pq.pop();
    if(!already.insert(station).second) continue;
    if(station == zip(n,0)) {
      cout << -negc << endl;
      return 0;
    }
    for(auto t : e[station]) {
      LL to;
      int ec;
      tie(to, ec) = t;
      pq.emplace(negc - ec, to);
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 141292