akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

int main()
{
    std::vector<int> V;
    V.resize(5);
    int k;
    for (auto& it : V) {std::cin >> it;}
    std::cin >> k;
    bool flag = true;

    for (int i=0; i<5; ++i)
    {
        for (int j=0; j<5; ++j)
        {
            if (i != j)
            {
                if (k < std::abs(V[i] - V[j])) {flag = false;}
            }
        }
    }

    if (flag) {std::cout << "Yay!" << std::endl;}
    else {std::cout << ":(" << std::endl;}

    return 0;
}

Measured memory_bytes: 256
#include<math.h>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include <array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
//AtCoderC++.cpp

using namespace std;


int main() {
	int N, L; cin >> N >> L;
	int min_abs = abs(L) + N;
	auto sum = 0;
	auto bite = 0;
	for (int i = 0; i < N; i++) {
		sum += L + i;
		if (min_abs > abs(L + i)) {
			min_abs = abs(L + i);
			bite = L + i;
		}
	}
	cout << sum - bite << endl;
}


Measured memory_bytes: 256
def primes(n):
    is_prime = [1]*(n+1)
    is_prime[0] = 0
    is_prime[1] = 0
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i*2,n+1,i):
            is_prime[j] = 0
    return is_prime

max = 100001
prime = primes(max)
a = [0]*max
for i in range(max):
    if i % 2 == 0:
        continue
    if prime[i] and prime[(i+1)//2]:
        a[i] = 1

s = [0]*(max+1)
for i in range(max):
    s[i+1] = s[i] + a[i]

Q = int(input())
for i in range(Q):
    l,r = map(int, input().split())
    print(s[r+1]-s[l])

Measured memory_bytes: 52184
def main():
    import copy
    S = str(input())
    T = str(input())
    ans = 0
    temp = 0

    for i in range(len(S)) :
        #print("S=",S[i])
        ans = 0
        for j in range(len(T)):
            #print("S=", S[i+j])
            #print("T=", T[j])
            if i+j >= len(S) :
                ans = 0
                break
            #print("T=", T[j])
            #print("S=", S[i+j])
            if T[j] in S[i+j] :
                ans += 1
                #print(ans)
        temp = max(ans, temp)

    ans = len(T) - temp
    #if len(S) == 1 and len(T) == 1 and S == T :
    #    ans = 0
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9244
#include<bits/stdc++.h>
using namespace std;
const  long long     mx=1e5+100;

#define      mod     1e9+7
#define      pai     acos(-1)
#define      ff      first
#define      ss      second
#define      ll      long long
#define      pb      push_back
#define      mp      make_pair
#define      fi      freopen("input.txt","r",stdin);
#define      fo      freopen("output.txt","w",stdout);
#define      fast    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

//typedef pair<ll,ll> pi;
//typedef map<ll,ll> mi;


int main()
{
    fast;
    ll i,j,a,b,c,d,n,m,k,x,y,t;
    cin>>n>>k>>x>>y;
    k=min(k,n);
    t=(k*x)+((n-k)*y);
    cout<<t<<endl;
    return 0;

}



Measured memory_bytes: 3576
N = str(input())
max_num = len(N) - 1

if N[max_num] == '2' or N[max_num] == '4' or N[max_num] == '5' or N[max_num] == '7' or N[max_num] == '9':
  print('hon')
elif N[max_num] == '0' or N[max_num] == '1' or N[max_num] == '6' or N[max_num] == '8':
  print('pon')
elif N[max_num] == '3':
  print('bon')

Measured memory_bytes: 9132
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


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

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

double dist (double a, double b,  double c, double d){
    
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
    
}

bool check(int x,int y,vector<string> a,vector<string> b ){
    for(auto i = 0; i<b.size();i++){
        for(auto j =0; j<b.size();j++){
            if(a[x+i][y+j]!= b[i][j]) return false;
        }
    }
    return true;
}

int dist(pii a, pii b){
    return abs(a.first-b.first) + abs(a.second-b.second);
}

bool is_even(string a){
    
    int len = (int)a.size();
    return (a.substr(0,len/2) == a.substr(len/2,len));
    
}

int main() {
    string s;
    cin >> s;
    s = s.substr(0,s.size()-2);
    while(!is_even(s)) {
        s=s.substr(0,s.size()-2);
    }
    
    cout << s.size() << endl;
    return 0;
}







Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(raw_input())
dic = set()
for i in range(n):
    com, s = map(str, raw_input().split())
    if com == "insert":
        dic.add(s)
    elif com == "find":
        if s in dic:
            print "yes"
        else:
            print "no"

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

a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]

for i in range(q):
    x = int(input())
    sh = bisect.bisect_left(s, x)
    te = bisect.bisect_left(t, x)
    dist_sh_e = float("inf")
    dist_sh_w = float("inf")
    dist_te_e = float("inf")
    dist_te_w = float("inf")
    if sh != 0:
        dist_sh_w = x - s[sh - 1]
    if sh != a:
        dist_sh_e = s[sh] - x
    if te != 0:
        dist_te_w = x - t[te - 1]
    if te != b:
        dist_te_e = t[te] - x
    print(min(max(dist_sh_w, dist_te_w), max(dist_sh_e, dist_te_e), dist_sh_w * 2 + dist_te_e, dist_te_w * 2 + dist_sh_e, dist_sh_e * 2 + dist_te_w, dist_te_e * 2 + dist_sh_w))

Measured memory_bytes: 110044
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int R;cin>>R;
  
  if(R<1200){
    cout<<"ABC"<<endl;
  }
  else if(1200<=R&&R<2800){
    cout<<"ARC"<<endl;
  }
  else{
    cout<<"AGC"<<endl;
  }
}

Measured memory_bytes: 3620
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h,w;
        while(true){
            h = sc.nextInt();
            w = sc.nextInt();
            if(h==0) break;
            for(int l=0;l<w;l++){
                System.out.print("#");
            }
            System.out.print("\n");
            for(int i=1;i<h-1;i++){
                System.out.print("#");
                for(int l=1;l<w-1;l++){
                    System.out.print(".");
                }
                System.out.print("#");
                System.out.print("\n");
            }
            for(int l=0;l<w;l++){
                System.out.print("#");
            }
            System.out.println("\n");
        }
        sc.close();
    }
}


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

int main(){
	long long n,b,r,count=0,res;
  	cin >> n >> b >> r;
  	count = n/(b+r);
  	
  	res = b*count;
  	n %= (b+r);
  	if((n-b)<=0) res += n;
  	else res += b;
   
  	cout << res << endl;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  int a,b;
  cin >> a >> b;
  int aa = (a+11)%13;
  int bb = (b+11)%13;
  if(aa > bb) cout << "Alice" << endl;
  if(aa == bb) cout << "Draw" << endl;
  if(aa < bb) cout << "Bob" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


void warshall_floyd(int n){
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                //d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}

int main() {
//    long double w,h,x,y; cin >> w >> h >> x >> y;
//    long double vertical = h * x;
//    long double side = w * y;
//
//    if(vertical > side ){
//        cout << fixed << setprecision(9) << side << " " << 0 << endl;
//    }else if(vertical < side){
//        cout << fixed << setprecision(9) << vertical << " " << 0 << endl;
//    }else{
//        cout << fixed << setprecision(9) << vertical << " " << 1 << endl;
//    }
    long long W, H, x, y;
    cin >> W >> H >> x >> y;
    double res = (double)(W) * H / 2;
    cout << fixed << setprecision(10) << res << " ";

    if (x*2 == W && y * 2 == H) cout << 1 << endl;
    else cout << 0 << endl;
    
 }



Measured memory_bytes: 3760
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main{

	public static void main(String[] args) throws Exception
	{
		String[] strRing = {"24532453","64136413","56215621","51265126","63146314","54235423"};
		String strT,strS,strB;
		int nE=0,nW=0;
		boolean bInsane=false,bSum=false;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );
		int n = Integer.parseInt(br.readLine() );// input n
		String[] strValue = br.readLine().split(" ");// input Dice value


		StringBuilder sb = new StringBuilder();
		StringBuilder sb2 = new StringBuilder();

		for(String strEach : strValue)
		{
			sb.append(strEach);
		}

		sb.append(sb);

		String strStr = sb.toString();


		HashMap<String,String> map = new HashMap<String,String>();

		for(int i=0; i<6; i++)
		{
			map.put(strValue[i],Integer.toString(i+1) );
		}

		for(int i=0; i<n-1; i++)
		{
			String[] str = br.readLine().split(" ");//get 2nd dice

    try{

			strT = map.get(str[0]);
			strS = map.get(str[1]);
			strB = Integer.toString(7 - Integer.parseInt(strT) );
			
        }catch(NumberFormatException e){
            strB = null;
            strT = null;
            strS = null;
            
        }

			String strBST = strB + strS + strT;

			for(int j=0; j<6; j++)
			{
				if(-1 < strRing[j].indexOf(strBST) )
				{
					nE = j;
					nW = 5-j;
				}
			}

			if(strValue[nE].equals(str[2]) && strValue[nW].equals(str[3]) )
			{
				int nB = Integer.parseInt(strB);
				bInsane = strValue[nB-1].equals(str[5]) ? true : false;

//				System.out.println(strValue[nB-1].equals(str[5]) ? "Yes" : "No");
			}
			else
			{
				for(String strEach : str)
				{
					sb2.append(strEach);
				}

				if(-1 < strStr.indexOf(sb2.toString() ) ) bInsane = true;
				else bInsane = false;
//				System.out.println("No");
			}

			bSum = bSum | bInsane;

			if(bSum)
			{
				System.out.println("No");
				System.exit(0);
			}

		}

		System.out.println("Yes");

	}
}

Measured memory_bytes: 24452
//https://atcoder.jp/contests/dp/tasks/dp_d
//D - Knapsack 1
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
    ll N,W; cin>>N>>W;
    vector<pair<ll,ll>> wvn(N+1);
    FOR(i,1,N+1){
        cin>>wvn[i].first>>wvn[i].second;
    }
    vector<vector<ll>> dp(N+1,vector<ll>(W+1,0));
    FOR(i,1,N+1){
        ll w=wvn[i].first;
        ll v=wvn[i].second;
        FOR(j,1,W+1){
            dp[i][j]=dp[i-1][j];
            if (j-w>=0) {
                dp[i][j]=max(dp[i-1][j-w]+v,dp[i][j]);
            }
        }
    }
    ll ans=0;
    FOR(i,1,N+1){
        chmax(ans, dp[i][W]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 80256
# dn 解説の要点は2つ
# 1,各桁のbitは独立に決定できる(一番大事)(解説後半)
# 2,K以下で探すように成約を入れる（解説前半）


N, K = list(map(int, input().split()))
A = list(map(int, input().split()))


ans = 0

for i in range(40, -1, -1):
    # print(ans)
    # 桁の大きい方から探索していく.
    power = 1 << i  # i個桁をシフトさせることでi桁目について考えることができる。
    # まずは1の処理からしていこう
    # i番目のビットに1はいくつあるか
    bit_count_of_1 = sum(1 for a in A if a & power != 0)  # この書き方は頭いい

    # 寄与の分岐
    # 注意すべきはpower>Kのときで、ビットは必ず0なので寄与はその時点で決まる。
    if power > K:
        # print(i)
        ans += power * bit_count_of_1
        # print(ans)
    elif bit_count_of_1 > N - bit_count_of_1:
        # その桁で1のほうが多い場合は最適なXは0を与えたほうがいい。0を与えるのはつまり その桁の大きさ×1の個数
        ans += power * bit_count_of_1
    else:
        ans += power * (N - bit_count_of_1)
        K -= power  # なにげに一番むずかしいポイントはここだった
        #→power==Kかつ ans X_kが1を与えるほうが良いとき、一つ下の桁も問題の条件を満たしているかはわからない。そこでこの演算が必要
        # イメージとしては最上位のビットを削除している。
        # その結果次のiterで一つ下の桁が問題条件（K以下）かを判断することができる。


print(ans)


Measured memory_bytes: 14620
#include<bits/stdc++.h>
#define fi first
#define se second
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pb push_back
#define ll long long
using namespace std;
const ll inf=1e18;
const int mod=1e9+7;
const int maxn=1e5+10;
int n,m;
ll tr[maxn<<2],tag[maxn<<2];
struct ppo{
	int l,r,c;
	bool operator<(const ppo &r)const{
		return l<r.l;
	}
}a[maxn];
void bd(int l,int r,int p){
	tr[p]=tag[p]=inf;
	if(l==r) return;
	int mid=l+r>>1;
	bd(lson);bd(rson);
}
void up(int dl,int dr,int l,int r,int p,ll k){
	tr[p]=min(tr[p],k);
	if(l==dl&&r==dr){
		tag[p]=min(tag[p],k);
		return;
	}int mid=l+r>>1;
	if(dr<=mid) up(dl,dr,lson,k);
	else if(dl>mid) up(dl,dr,rson,k);
	else up(dl,mid,lson,k),up(mid+1,dr,rson,k);
}
ll qy(int x,int l,int r,int p,ll k){
	if(l==r) return min(tr[p],k);
	int mid=l+r>>1;
	if(x<=mid) return qy(x,lson,min(tag[p],k));
	else return qy(x,rson,min(tag[p],k));
}
int main(){
	ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>a[i].l>>a[i].r>>a[i].c;
	}
	sort(a+1,a+m+1);
	bd(1,n,1);
	up(1,1,1,n,1,0);
	for(int i=1;i<=m;i++){
		ll res=qy(a[i].l,1,n,1,inf)+a[i].c;
		up(a[i].l+1,a[i].r,1,n,1,res);
	}
	ll ans=qy(n,1,n,1,inf);
	if(ans==inf) ans=-1;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  ll A[N];
  REP(i, N) cin >> A[i];

  vector<ll> L(N + 1, 0), R(N + 1, 0);
  REP(i, N) L[i + 1] = __gcd(L[i], A[i]);
  REPR(i, N - 1) R[i] = __gcd(R[i + 1], A[i]);

  ll ans = 1;
  REP(i, N) {
    ll l = L[i];
    ll r = R[i + 1];
    ans = max(ans, __gcd(l, r));
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<stack>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include <iomanip>
#include<unordered_map>
#include<set>
using namespace std;
typedef long long ll;
const int maxn = 105;

int n,m,a[maxn];

int main() {
   // freopen("in.cpp","r",stdin);
    cin>>m>>n;
    int sum=0,mx = 0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
        mx = max(mx, a[i]);
    }
    int ret=max(0, mx-(sum-mx+1));
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define fast ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define umll unordered_map<ll,ll>
#define mll map<ll,ll>
#define forr(i,p,n) for(ll i=p;i<(ll)n;i++)
#define fore(i,n,k) for(ll i=n-1;i>=k;i--)
#define MAXN 1000003
typedef long long ll;
using namespace std;
ll mult(ll a, ll b, ll p = MOD) {return ((a % p) * (b % p)) % p;}
ll add(ll a, ll b, ll p = MOD) {return (a % p + b % p) % p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD) {ll m0 = m; ll y = 0, x = 1; if (m == 1)return 0; while (a > 1) {ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t;} if (x < 0)x += m0; return x;}
using namespace __gnu_pbds;
typedef tree<ll, null_type, less< ll>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
void functiontosolve()
{
    ll n;
    cin >> n;
    ll a[n], b[n], c[n];
    forr(i, 0, n) {
        ll x, y, z;
        cin >> x >> y >> z;
        if (i == 0 ) {
            a[0] = x;
            b[0] = y;
            c[0] = z;
            continue;
        }
        a[i] = max(b[i - 1], c[i - 1]) + x;
        b[i] = max(a[i - 1], c[i - 1]) + y;
        c[i] = max(a[i - 1], b[i - 1]) + z;
    }
    cout << max(a[n - 1], max(b[n - 1], c[n - 1])) << "\n";
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int test;
    test  = 1;
    forr(i, 1, test + 1) {
        functiontosolve();
    }
    return 0;
}

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

int main() {
  int money;
  cin >> money;
  int big_happiness;
  big_happiness = money / 500;
  money -= big_happiness * 500;
  big_happiness *= 1000;
  
  int small_happiness;
  small_happiness = money / 5 * 5;
  
  cout << big_happiness + small_happiness;
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  string s;cin >> s;
  ll ans = 0;
  rep(i,n){
    vector<bool> a(26,false);
    vector<bool> b(26,false);
    rep(j,i+1){
      a[s[j]-'a'] =true;
    }
    FOR(j,i+1,n){
      b[s[j]-'a'] =true;
    }
    ll anstmp=0;
    rep(j,26){
      if(a[j]&&b[j]){
        anstmp++;
      }
    }
    ans = max(ans,anstmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;


bool check(ll k, ll A, ll B){
  if(k*k/4 + B*B + B*k < A*B) return true;
  else return false;
}

int main(){
  int Q;
  cin >> Q;
  ll a[Q],b[Q];
  for(int i=0;i<Q;i++) cin >> a[i] >> b[i];

  for(int i=0;i<Q;i++){
    ll ans = 0;
    ll A = max(a[i], b[i]);
    ll B = min(a[i], b[i]);
    ans += 2 * (B - 1);

    ll l = 0;
    ll r = A - B;
    while(r - l > 1){
      ll mid = (l + r) / 2;
      if(check(mid,A,B)){
        l = mid;
      } else {
        r = mid;
      }
    }

    ans += l;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
def main():
    h, w = map(int, input().split())
    ss = [input() for _ in range(h)]

    matl = [[0 for _ in range(w)] for _ in range(h)]
    matr = [[0 for _ in range(w)] for _ in range(h)]
    matu = [[0 for _ in range(w)] for _ in range(h)]
    matd = [[0 for _ in range(w)] for _ in range(h)]

    for j in range(h):
        for i in range(w):
            if ss[j][i] == '#':
                matd[j][i] = 0
            elif j == 0:
                matd[j][i] = 1
            else:
                matd[j][i] = matd[j - 1][i] + 1

            if ss[h - j - 1][i] == '#':
                matu[h - j - 1][i] = 0
            elif h - j == h:
                matu[h - j - 1][i] = 1
            else:
                matu[h - j - 1][i] = matu[h - j][i] + 1

            if ss[j][i] == '#':
                matr[j][i] = 0
            elif i == 0:
                matr[j][i] = 1
            else:
                matr[j][i] = matr[j][i - 1] + 1

            if ss[j][w - i - 1] == '#':
                matl[j][w - i - 1] = 0
            elif w - i == w:
                matl[j][w - i - 1] = 1
            else:
                matl[j][w - i - 1] = matl[j][w - i] + 1

    maxv = 0
    for j in range(h):
        for i in range(w):
            tmp = matu[j][i] + matd[j][i] + matr[j][i] + matl[j][i]
            if tmp > maxv:
                maxv = tmp
    print(maxv - 3)

if __name__ == '__main__':
    main()


Measured memory_bytes: 183684
if __name__ == '__main__':

	while True:
		try:
			n = int(input())
			if n == 0:
				break

			no = []
			total = []
			for i in range(n):
				e,p,q = map(int,input().split())

				if e not in no:
					no.append(e)
					total.append(p*q)
				else:
					ind = no.index(e)
					total[ind] += p*q

			cnt = 0
			for j,k in enumerate(total):
				if k >= 1000000:
					cnt += 1
					print(no[j])
			if cnt == 0:
				print("NA")

		except EOFError:
			break



Measured memory_bytes: 5804
n,d = (int(x) for x in input().split())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]

count = 0
for i in range(n):
    if d**2 >= x[i]**2 + y[i]**2:
        count += 1

print(count)

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

int main(){
 int S;
 cin >> S;
 int h,m,s;
 h = S/3600;
 m = S/60 - 60*h;
 s = S - h*3600 - m*60;
 cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3136
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			Map<Character, Character> map = new HashMap<>();
			for (char a = 'A'; a <= 'Z'; a++) {
				map.put(a, (char) ((a - 'A' + n) % 26 + 'A'));
			}
			char[] s = scanner.next().toCharArray();
			char[] result = new char[s.length];
			IntStream.range(0, s.length).forEach(i -> result[i] = map.get(s[i]));
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 28212
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

l={}
r={}
ans = 0
now = 0

a.each do |v|
  l[now + 1 + a[now]] = 0 if l[now + 1 + a[now]].nil?
  l[now + 1 + a[now]] += 1 
  r[now + 1 - a[now]] = 0 if r[now + 1 - a[now]].nil?
  r[now + 1 - a[now]] += 1 
  now += 1
end

l.each do |k, v|
  next if r[k].nil?
  ans += v*r[k]
end

puts ans

Measured memory_bytes: 43568
#include<bits/stdc++.h>
using namespace std;
#define int long long

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int dp[n+5][n+5];
    int a[n+5];
    for(int i=0;i<n;i++)
        cin>>a[i],dp[i][i]=a[i];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j+i<n;j++)
        {
            dp[j][i+j]=max(a[j]-dp[j+1][i+j],a[i+j]-dp[j][i+j-1]);
        }
    }
    cout<<dp[0][n-1];

}


Measured memory_bytes: 49780
#include<stdio.h>
#include<string.h>
int i,j,n,f,t,s;

void unit(int d[50],int s[50])
{
	int i;
	for(i=0;i<n;i++)
		d[i]=d[i]|s[i];
}

int ch(int d[50])
{
	int i;
	for(i=0;i<n;i++)
		if(d[i]!=1)
			return 0;
	return 1;
}

int solve()
{
	int dp[31][50][50]={0};
	int s[31][50]={0};
	int p[50];
	for(i=0;i<n;i++)
		dp[0][i][i]=1;
	for(i=0;i<n;i++)
	{
		scanf("%d",&f);
		for(j=0;j<f;j++)
		{
			scanf("%d",&t);
			s[t][i]=1;
		}
	}
	for(i=1;i<31;i++)
	{
		memset(p,0,sizeof(p));
		for(j=0;j<n;j++)
		{
			memcpy(dp[i][j],dp[i-1][j],sizeof(dp[i][j]));
			if(s[i][j])
				unit(p,dp[i][j]);
		}
		if(ch(p))
		{
			printf("%d\n",i);
			return 0;
		}
		for(j=0;j<n;j++)
			if(s[i][j])
				memcpy(dp[i][j],p,sizeof(p));
	}
	puts("-1");
	return 0;
}

int main()
{
	for(;scanf("%d",&n),n;)
		solve();
	return 0;
}

Measured memory_bytes: 928
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextssort(n,a){return a?cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>b-a):cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>a-b);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

class unionFind{
  constructor(n){this.a=Array(n+1).fill(-1);}
  root(i){
    return this.a[i]<0?i:this.a[i]=this.root(this.a[i]);
  }
  same(x,y){return this.root(x)===this.root(y);}
  unite(x,y){
    const a=this.a;
    x=this.root(x),y=this.root(y);
    if(x===y)return false;
    if(a[y]<a[x])a[y]+=a[x],a[x]=y;
    else a[x]+=a[y],a[y]=x;
    return true;
  }
  size(i){return -this.a[this.root(i)];}
}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var [n,q] = nexts(2);
  var uf = new unionFind(n);
  var ans = [];
  for(var i = 0; i < q; i++){
    var [t,u,v] = nexts(3);
    if(t){
      if(uf.same(u,v))ans.push(1);
      else ans.push(0);
    }else{
      uf.unite(u,v);
    }
  }
  return ans.join("\n");
}

Measured memory_bytes: 106924
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    if(A < 10 && B < 10) cout << A*B << endl;
    else cout << "-1" << endl;
         
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll min(ll a,ll b)
{   if(a<b)
    {
        return a;
    }
    else
    {
        return b;
    }
}
int main()
{   ll n;
    cin>>n;
    ll a[n+1]={0};
    ll dp[n+1]={0};
    ll i=1;
    while(i<=n)
    {
        cin>>a[i];
        i++;
    }
    
    dp[1]=1;
    dp[1]--;
   
    dp[2] = abs(a[1]-a[2]);
    i=3;
    while(i<=n)
    {ll k1,k2;
    k1=abs(a[i]-a[i-1]);
    k1=k1+dp[i-1];
    k2=abs(a[i]-a[i-2]);
    k2=k2+dp[i-2];
     dp[i]= min(k1,k2);
     i++;
    }
 cout<<dp[n];
 return 0;
    }

Measured memory_bytes: 1792
# D
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

x, y = map(int, input().split())
if ((2*x - y) % 3 != 0) or ((2*y - x)% 3 != 0):
    print(0)
else:
    mod = 10**9 + 7
    s = (2*x - y) // 3
    t = (2*y - x) // 3
    val = cmb(s+t, s, mod)
    print(val)

Measured memory_bytes: 122176
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getLine >>= putStrLn

solve :: String -> String
solve xs
  | ys == "EW" = "Yes"
  | ys == "NS" = "Yes"
  | ys == "ENSW" = "Yes"
  | otherwise = "No"
  where
    ys = sort . nub $ xs


Measured memory_bytes: 508
const main = (input) => {
  const a = '0abcdefghijklmnopqrstuvwxyz'
  let N = BigInt(input.trim())

  const ans = []
  while (N > 0n) {
    let r = Number(N % 26n)
    if (r === 0) r = 26
    
    ans.unshift(a[r])
    N = (N - BigInt(r)) / 26n
  }
  // if (N > 0n) ans.unshift(a[Number(N)])
  return console.log(ans.join(''))
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29648
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

int N, Q, A[1<<20], L[1<<20], R[1<<20], foc[1<<20];
vector<int> qord;

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(NULL);

 cin>>N>>Q;
 rep(i,N){cin>>A[i+1];}
 rep(i,Q) {cin>>L[i]>>R[i];qord.pb(i);}
 sort(qord.begin(), qord.end(), [](const int &i, const int &j){
   return L[i] > L[j];
 });

 BIT<int> bit(N+5);
 int j = N;
 for(int &i: qord) {
   int l = L[i] , r = R[i];
   while(j >= l) {
     if(foc[A[j]]) {bit.add(foc[A[j]], -1);}
     foc[A[j]]=j;bit.add(j, 1);
     j--;
   }
   // cout << "||" << bit.sum(r) << endl;
   // cout << "||" << bit.sum(l-1) << endl;
   L[i] = bit.sum(r) - bit.sum(l-1);
 }

 rep(i,Q) cout<<L[i]<<endl;

 return 0;
}


Measured memory_bytes: 15596
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9
 
struct Puzzle{
    int f[N2];
    int space;
    string path;
     
    bool operator < (const Puzzle &p) const{
        for(int i = 0; i < N2; i++){
            if(f[i] == p.f[i]) continue;
            return f[i] > p.f[i];
        }
        return false;
    }
};
 
static const int dx[4] = {-1,0,1,0};
static const int dy[4] = {0,-1,0,1};
static const char dir[4] = {'u','l','d','r'};
 
bool isTarget(Puzzle p){
    for(int i = 0; i < N2; i++)
        if(p.f[i] != (i + 1)) return false;
    return true;
}
 
string bfs(Puzzle s){
    queue<Puzzle> Q;
    map<Puzzle, bool> V;
    Puzzle u, v;
    s.path = "";
    Q.push(s);
    V[s] = true;
     
    while(!Q.empty()){
        u = Q.front(); Q.pop();
        if(isTarget(u)) return u.path;
        int sx = u.space / N;
        int sy = u.space % N;
        for(int r = 0; r < 4; r++){
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
            v = u;
            swap(v.f[u.space], v.f[tx * N + ty]);
            v.space = tx * N + ty;
            if(!V[v]){
                V[v] = true;
                v.path += dir[r];
                Q.push(v);
            }
        }
    }
    return "unsolvable";
}
 
int main(){
    Puzzle in;
    for(int i = 0; i < N2; i++){
        cin >> in.f[i];
        if(in.f[i] == 0){
            in.f[i] = N2;
            in.space = i;
        }
    }
    string ans = bfs(in);
    cout << ans.size() << endl;
     
    return 0;
}



Measured memory_bytes: 30600
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <stack>
#include <string>
#include <iomanip>
#include <queue>
#include <deque>
#include<cstring>
#include<limits>
#include <sstream>
#include<unordered_map>
using namespace std;
#define sz(x) (x).size()
#define all(v) (v).begin(),(v).end()
#define m_p make_pair
void run()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
void fast()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
long long mem[1001][1001];
long long grid[1001][1001];
int n, m;

int dp(int i, int j)
{
	if (i == n || j == m)
		return 0;
	if (i == n - 1 && j == m - 1)
		return grid[i][j];
	if (mem[i][j] != -1)
		return mem[i][j];
	int ch1 = dp(i, j + 1);
	int ch2 = dp(i + 1, j);
	return mem[i][j] = max(ch1, ch2) + grid[i][j];
}
int main()
{
	fast();
	memset(mem, -1, sizeof mem);
	cin >> m;
	n = 2;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> grid[i][j];
		}
	}
	cout << dp(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 9856
import sys
import heapq


def input():
    return sys.stdin.readline().strip()


def dijkstra(start, n_nodes, edge):
    dist = [float("inf")] * n_nodes
    dist[start] = 0
    # 優先度キューの準備
    q = [(dist[start], start)]
    heapq.heapify(q)
    while q:
        # スタートから最も最短距離のものを取り出す
        d, i = heapq.heappop(q)
        # 記録してある情報よりも，取り出した要素に入っている距離情報の方が大きければ
        # 打ち切り．次の要素を取り出す操作に戻る
        if dist[i] < d:
            continue
        # そこから移動できる頂点を探し，最短距離が更新できるものがあれば，
        # 距離を更新して，その頂点への距離と頂点の方法を優先度キューにpush
        for cost, j in edge[i]:
            if dist[j] > dist[i] + cost:
                dist[j] = dist[i] + cost
                heapq.heappush(q, (dist[j], j))
    return dist


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    H, W = map(int, input().split())
    C = [list(map(int, input().split())) for _ in range(10)]
    edge = [[] for _ in range(10)]
    for i in range(10):
        for j in range(10):
            edge[i].append((C[i][j], j))

    D = [dijkstra(i, 10, edge) for i in range(10)]
    answer = 0
    for _ in range(H):
        A = list(map(int, input().split()))
        for w in range(W):
            if A[w] != -1:
                answer += D[A[w]][1]
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var cin = new MyInputStream();

            var ans = 0;
            var N = cin.ri();
            var hs = new HashSet<long>();
            for (var i = 0; i < N; ++i)
            {
                var A = cin.ri();
                if (hs.Contains(A)) hs.Remove(A);
                else hs.Add(A);
            }
            WriteLine(hs.Count);
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Trim().Split(separator);
            for (int i = 0; i < tmp.Length; i++)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine() => Console.ReadLine();
        public int ReadInt() => int.Parse(Read());
        public long ReadLong() => long.Parse(Read());
        public double ReadDouble() => double.Parse(Read());
        public string r() => Read();
        public int ri() => ReadInt();
        public long rl() => ReadLong();
        public double rd() => ReadDouble();
    }
}


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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n,k;
    cin>>n>>k;
    ll ans = 0;
    map<ll,ll> mp;
    ll sum=0;
    mp[0]=1;
    ll a[n];
    ll ret=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum += a[i]-1;
        sum %= k;
        if(i==k-1) mp[0]--;
        if(i>=k){
            ret += a[i-k]-1;
            ret %= k;
            //cerr << ret << endl;
            mp[ret]--;
        }
        ans += mp[sum];
        mp[sum]++;
        //cerr << i << " " << ans << endl;
    }
    cout << ans << endl;

}


Measured memory_bytes: 16384
#include <iostream>
#include <stack>
#include <map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <string.h>

using namespace std;

int N;

int main(int argc, char** argv) {
    cin >> N;
    if (N < 0) N = -N;
    int n2 = N;
    int sum = 0;
    while (n2 != 0) {
        sum += n2 % 10;
        n2 /= 10;
    }
    if (N % sum == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = (int)1e9 + 7, INF = (int)1e9;


int main(void) {
	int n, i, a, nm[200003] = {};

	scanf("%d", &n);
	for (i = 0; i < n - 1; i++) {
		scanf("%d", &a);
		nm[a - 1]++;
	}

	for (i = 0; i < n; i++) {
		printf("%d\n", nm[i]);
	}

	return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define MOD 1000000007

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

int N,K;
ll x[55],y[55];

int main()
{
	cin >> N >> K;
	vector<ll> xary,yary;
	rep(i,0,N){
		cin >> x[i] >> y[i];
		xary.push_back(x[i]);
		yary.push_back(y[i]);
	}
	sort(xary.begin(),xary.end());
	sort(yary.begin(),yary.end());
	ll ans;
	bool T = true;
	rep(xl,0,N) rep(xr,xl+1,N) rep(yl,0,N) rep(yr,yl+1,N){
		ll lx = xary[xl], rx = xary[xr];
		ll ly = yary[yl], ry = yary[yr];
		int num=0;
		rep(i,0,N){
			if(lx <= x[i] and x[i] <= rx and ly <= y[i] and y[i] <= ry) num++;
		}
		if(num >= K){
			if(T){
				ans = (rx-lx)*(ry-ly);
				T = false;
			}else ans = min(ans,(rx-lx)*(ry-ly));
		}
	}
	cout << ans << endl;

	return 0;
}


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    string ans = "";
    /*start*/
    int n;
    cin >> n;
    // vector<string> s(n);
    // vector<vector<int>> q(n, vector<int>(10, 0));
    map<string, ll> r;
    ll res = 0;
    rep(i, n)
    {
        string s;
        cin >> s;
        sort(All(s));
        //c(r.count(s));
        if (r.count(s) > 0)
        {

            r.at(s)++;
        }
        else
        {
            r[s] = 1;
        }
        //r.insert(make_pair(q[i],0));
        //c(s[i]);
    }
    for (auto a : r)
    {
        ll b = a.second;
        res += b * (b - 1) / 2;
    }
    c(res);

    return 0;
}


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

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

using namespace std;
using lint=long long;

const long long INF=1LL<<61;

int main(){
	int n; scanf("%d",&n);
	lint a[16][16];
	rep(i,n) rep(j,n) scanf("%lld",&a[i][j]);

	lint cost[1<<16]={};
	rep(S,1<<n){
		rep(i,n) if(S>>i&1) rep(j,i) if(S>>j&1) cost[S]+=a[i][j];
	}

	lint dp[1<<16];
	rep(S,1<<n) dp[S]=-INF;
	dp[0]=0;
	rep(S,1<<n){
		for(int T=S;;T=(T-1)&S){
			dp[S]=max(dp[S],dp[T]+cost[S&~T]);
			if(T==0) break;
		}
	}
	printf("%lld\n",dp[(1<<n)-1]);

	return 0;
}


Measured memory_bytes: 1280
j,p[1<<20],n;
main(i)
{
	for(;++i<999;)
		for(j=i;!p[i]&(j+=i)<1<<20;)p[j]=1;
	for(;scanf("%d",&n),j=0,n;printf("%d\n",j))
		for(i=1;++i<=n/2;)j+=!p[i]&!p[n-i];
	exit(0);
}

Measured memory_bytes: 0
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    L = [int(l) for l in input().split()]
    L.sort()
    lsum = sum(L[:N-1])
    if L[N-1] < lsum: print("Yes")
    else: print("No")

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define mod 1000000007
#define int long long

void solve() {
	int N, W;
	cin >> N >> W;
	int i, j;
	int v[N], w[N];

	for (i = 0; i < N; i++)cin >> w[i] >> v[i];
	int dp[N + 1][W + 1];

	for (i = 0; i <= N; i++) {
		for (j = 0; j <= W; j++)dp[i][j] = -1;
	}

	for (i = 0; i <= N; i++) {
		for (j = 0; j <= W; j++) {
			if (i == 0 || j == 0) {
				dp[i][j] = 0;
				continue;
			}
			if (j >= w[i - 1]) {
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
			}
			else dp[i][j] = dp[i - 1][j];
		}
	}


	cout << dp[N][W] << endl;
	return;
}

int32_t main() {
	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 82524
#include <iostream>
#include <vector>
#include <climits>
using namespace std;



long long int merge(vector<int>& slimes){
    int size = slimes.size();

    vector<vector<pair<long long int, long long int>> > records = vector<vector<pair<long long int, long long int>> >(size+1, vector<pair<long long int, long long int> >(size+1, make_pair(0, 0)));


    for(int i = 0;i < size; i++){
        records[i][i+1].first = slimes[i];
       // records[i][i+1].second = slimes[i];
    }

    for(int length = 1; length <= size; length++){
        for(int i = 0; i < size; i++){
            int j = i+length;

            if(j > size)
                continue;

            if(j-i == 1){
                continue;
            }

            pair<long long int, long long int> min_value = make_pair(0, LLONG_MAX);
            for(int split = i+1; split < j; split++){
                pair<long long int, long long int> value;

                value.first = records[i][split].first + records[split][j].first;
                value.second = records[i][split].second + records[split][j].second+value.first; 
               
      //          cout << i << "-" << split << "-" << j << " left=" << records[i][split].second << " right=" << records[split][j].second << "\n";  
                
                if(value.second < min_value.second){
                   min_value = value;  
                }
            }

            records[i][j] = min_value;

  //          cout << "(" << i << "," << j << ") value=" << min_value.first << " cost=" << min_value.second << "\n";
        }
    }

    return records[0][size].second;
}

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

    vector<int> slimes = vector<int>(n);

    for(int i = 0; i < n; i++)
        cin >> slimes[i];

    long long int result = merge(slimes);
    cout << result << "\n";
    
    return 0;
}


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

using namespace std;

int main(void){

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++) cin >> a[i];

    bool ok = true;
    int ans = 0;

    for(int i = 0;i < n;i++){
        if(a[i] == 2) ans++;
        for(int j = 2; j <= sqrt(a[i])+1;j++){
            if(a[i] % j == 0) ok = false;
        }
        if(ok) ans++;
        ok = true;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3096
function Main(s) {
  var s = s.split("\n").map(e => e.split(" ").map(e => e*1));
  n = s[0][0], m = s[0][1];
  a_b = s.slice(1, m+1).sort((a, b) => a[1]-b[1]);
  var end = a_b[0][1];
  var ans = 1;
  for (var i = 0; i < m; i++) {
    if (end <= a_b[i][0]) {
      ans++;
      for (var j = i; j < m; j++) {
        if (end < a_b[j][1]) {
          end = a_b[j][1];
          break;
        }
      }
    }
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 52484
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll mod=(1e9)+7;
const int maxn=(1e6)+10;
int n;
ll iv[maxn],ans,t1,t2;
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	iv[0]=iv[1]=1;
	for (int i=2;i<maxn;i++) {
		iv[i]=(mod-mod/i)*iv[mod%i]%mod;
	}
	t1=1;
	for (int i=1;i<=n;i++) {
		t1=t1*iv[3]%mod;
		t2=iv[n-i+1];
		ans=(ans+t1*t2)%mod;
	}
	ans=ans*iv[n]%mod;
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size() / 2; i++)
    {
        if(s[i]!=s[s.size()-1-i])
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;

using namespace std;

bool used[30];
string str;
vector<string> cand;

void dfs(int i){
	if(i==str.size()) cand.push_back(str);
	else{
		if(str[i]=='a' || used[str[i]-'a']) dfs(i+1);
		if(!used[str[i]-'a'+1] && str[i]!='z'){
			str[i]++;
			used[str[i]-'a'] = 1;
			dfs(i+1);

			used[str[i]-'a'] = 0;
			str[i]--;
		}
	}
}


int main(void){
	while(1){
		cin >> str;
		if(str == "#") break;

		fill(used, used+30, false);
		cand.clear();
		dfs(0);
		cout << cand.size() << endl;
		if(cand.size() <= 10){
			for(int i=0; i<cand.size(); i++){
				cout << cand[i] << endl;
			}
		} else{
			for(int i=0; i<5; i++){
				cout << cand[i] << endl;
			}
			for(int i=cand.size()-5; i<cand.size(); i++){
				cout << cand[i] << endl;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 4252
A, B, C = (int(i) for i in input().split()) 






result = 0
memory = [[A, B, C]]
while True:
    if A % 2 != 0 or B % 2 != 0 or C % 2 != 0:
        break
    else:
        result += 1
    
    a = A / 2
    b = B / 2
    c = C / 2

    A = b + c
    B = a + c
    C = a + b

    l = sorted([A, B, C])
    for m in memory:
        if m[0] == l[0] and m[1] == l[1] and m[2] == l[2]:
            result = -1
            break
    
    if result == -1:
        break

	

    

    memory.append(l)
    

print(result)




Measured memory_bytes: 3064