akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
	int H,W,i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0){
			break;
		}
		for(i = 0;i < H;i++){
			for(j = 0;j < W;j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

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

bool used[26];
int d[26][26];

void dfs(int from){
    used[from] = true;
    for(int j = 0; j < 26; j++){
        if(d[from][j] && !used[j])  dfs(j);
    }
}

int main(){
    int n;
    while(cin >> n, n){
        for(int i = 0; i < 26; i++) used[i] = false;
        for(int i = 0; i < 26; i++) for(int j = 0; j < 26; j++) d[i][j] = 0;

        bool avail[26] = {};
        string w;

        for(int i = 0; i < n; i++){
            cin >> w;
            avail[w[0]-'a'] = avail[w[w.length()-1]] = true;
            if(w[0] == w[w.length()-1]) continue;
            d[w[0]-'a'][w[w.length()-1]-'a']++;
        }

        bool euler = true;
        for(int i = 0; i < 26; i++){
            int indeg = 0, outdeg = 0;
            for(int j = 0; j < 26; j++){
                indeg += d[i][j];
                outdeg += d[j][i];
            }
            if(indeg != outdeg) euler = false;
        }

        if(euler){
            dfs(w[0]-'a');
            for(int i = 0; i < 26; i++) if(avail[i] && !used[i])    euler = false;
        }

        if(euler)   cout << "OK" << endl;
        else        cout << "NG" << endl;
    }
    return 0;
}


Measured memory_bytes: 3196
def main():
    import sys,bisect
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int,input().split()))

    b = [0] + sorted(a)

    res = [0]*n

    d = dict()
    for i in range(n):
        if not a[i] in d:
            d[a[i]] = i

    p = n
    while p > 0:
        k = bisect.bisect_left(b,b[p])
        res[d[b[k]]] += (n+1-k)*(b[k]-b[k-1])
        if k -1 >= 1:
            d[b[k-1]] = min(d[b[k]],d[b[k-1]])
        p = k-1
    for e in res:
        print(e)

if __name__ == '__main__':
    main()

Measured memory_bytes: 74936
s = input()
t = input()
ans = []
a = ''
for i in range(len(s)-len(t)+1):
    flag = True
    a = s[:i]
    for j in range(len(t)):
        if s[i+j] == t[j] or s[i+j] == '?':
            a += t[j]
        else:
            flag = False
            break
    a += s[i+j+1:]
    if flag:
        ans.append(a.replace('?','a'))
if ans:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

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

using namespace std;

using ll=int64_t;

ll pow_expo(ll a,ll b)
{

    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=res*a;
        a=a*a;
        b>>=1;
    }
return res;
}

void factorize(ll n,ll p)
{
    ll ans=1,r=p;
    for(ll i=2;i*i<=p;i++)
    {
        if(r%i==0)
        {
            ll power=0;
            while(r%i==0)
            {
                r/=i;
                ++power;
            }
            power/=n;
            if(power)
            {
               ans*=pow_expo(i,power);
            }
        }
    }
    if(n==1)
        ans*=r;

    cout<<ans<<endl;
}

int main()
{
    ll n,p;
    cin>>n>>p;
    factorize(n,p);
}


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


int main(){


    int a, b, k, i;

 
    cin >> a >> b >> k;


    for( i = 0 ; i < k ; i = i + 1 ){

         if( i % 2 == 0 ){

             if( a % 2 != 0 ) a -= 1;

             b += a / 2;

             a = a / 2;

             }

         else{

               if( b % 2 != 0 ) b -= 1;  

               a += b / 2;

               b = b / 2;

               }

         }


    cout << a << " " << b << endl;


    return 0;


    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	int a,b;
	cin>>a>>b;
	cout<<a*b<<endl; 
	return 0;
}



Measured memory_bytes: 3652
N, Ma, Mb = map(int, input().split())
items = [[int(x) for x in input().split()] for _ in range(N)]

A, B = 0, 0
for a, b, _ in items:
    A += a
    B += b

dp = [[[float("inf")] * (B + 1) for _ in range(A + 1)] for _ in range(N + 1)]
for i in range(N + 1):
    dp[i][0][0] = 0

for i in range(N):
    a, b, c = items[i]
    for j in range(A + 1):
        for k in range(B + 1):
            if j - a >= 0 and k - b >= 0:
                dp[i + 1][j][k] = min(dp[i][j - a][k - b] + c, dp[i][j][k])
            else:
                dp[i + 1][j][k] = dp[i][j][k]


ans = float("inf")
for x in range(1, min(A // Ma, B // Mb) + 1):
    a = Ma * x
    b = Mb * x
    ans = min(dp[N][a][b], ans)

if ans == float("inf"):
    ans = -1
print(ans)


Measured memory_bytes: 71084
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    internal static class Program
    {
        private static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            List<double> nbrs = Console.ReadLine().Split().ToList().ConvertAll(double.Parse);
            double res = nbrs.Min();
            nbrs.Remove(res);

            while(nbrs.Count > 0)
            {
                double min = nbrs.Min();
                nbrs.Remove(min);

                res += min;
                res /= 2;
            }

            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 13268
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double[] a = new double[]{sc.nextDouble(), sc.nextDouble(), sc.nextDouble()};
        System.out.println(a[0] * a[1] * Math.sin((Math.PI / 180) * a[2]) / 2.0);
        System.out.println(
            a[0] + a[1] + Math.sqrt(a[0] * a[0] + a[1] * a[1] - 2 * a[0] * a[1] * Math.cos(Math.PI / 180 * a[2])));
        System.out.println(a[1] * Math.sin(Math.PI / 180 * a[2]));
    }
}


Measured memory_bytes: 27876
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 998244353
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pll a, pll b)//true for a before b
{
	if(a.F*b.S < b.F*a.S)
		return 1;
	if(a.F*b.S > b.F*a.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (2e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 900;
const int SQRT = BUCK+9;

pii a[N];

void solve()
{
	int n, i, ans = INF, val, bal;
	cin >> n;
	fo(i,1,n+1)
	{
		cin >> a[i].F;
		a[i].S = i;
	}
	sort(a+1,a+n+1);
	val = 1;
	bal = 1;
	fo(i,2,n+1)
	{
		if(a[i-1].S < a[i].S)
			val++;
		else
			val = 1;
		bal = max(bal, val);
	}
	ans = n-bal;
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 1792
# range set query
from collections import defaultdict
import sys


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


class BIT():
    # 1,,,,,,,Nまでの数値を扱える
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)

    def to_sum(self, i):
        # i番目のところまでのΣ
        s = 0
        while i > 0:
            s += self.data[i]
            i -= (i & -i)
        return s

    def add(self, i, x):
        # i 番目のところに+
        while i <= self.n:
            self.data[i] += x
            i += (i & -i)

    def get(self, i, j):
        # i番目からj番目までの要素のΣ(1<=i<=j<=Nという制約)
        return self.to_sum(j)-self.to_sum(i-1)


que = []
color_data = defaultdict(list)

N, Q = map(int, input().split())
C = list(map(int, input().split()))

for i in range(Q):
    l, r = map(int, input().split())
    que.append((i, l, r))

que.sort(key=lambda x: x[-1])

ans = [-1]*(Q)
previous_color = [-1]*(N+1)

for i, v in enumerate(C):
    color_data[v].append(i+1)

for key in color_data.keys():
    D = color_data[key]
    for i in range(1, len(D)):
        previous_color[D[i]] = D[i-1]

bit_tree = BIT(N)
i0, l0, r0 = que[0]

for _ in range(1, r0+1):
    bit_tree.add(_, 1)
    prev = previous_color[_]
    if prev > 0:
        bit_tree.add(prev, -1)
    ans[i0] = bit_tree.get(l0, r0)

for _ in range(1, Q):
    i, l, r = que[_]
    prv_r = que[_-1][-1]
    for j in range(prv_r+1, r+1):
        bit_tree.add(j, 1)
        prev = previous_color[j]
        if prev > 0:
            bit_tree.add(prev, -1)
    ans[i] = bit_tree.get(l, r)

for x in ans:
    print(x)

Measured memory_bytes: 277148
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <iomanip>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[2] = {0, 1};
ll dy[2] = {1, 0};

int main(void){
    double pi = 3.14159265358979;
    ll r;
    cin >> r;
    double ans = pi*2*(double)r;
    //cout << ans << endl;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab  (int  x ) { return (x>0?x:-x); }

const int F=3e5+5; 
const ll mod =1e9+7; 
ll dp[105][F];
int a[105];  
int main(){
	int n , k ; 
	cin >> n >>k; 
	for(int i = 0 ; i < n ; i++ )cin >>a[i];  
	dp[0][0]=1; 
	for(int i = 0 ; i < n ; i++ ){
		for(int j = 0 ; j <= k ; j++ ){
			
			dp[i+1][j]+=dp[i][j]; //dp[i+1][j]%=mod;
			// if(j+a[i]<=k){
				dp[i+1][j+a[i]+1]-=dp[i][j]; //dp[i+1][j+a[i]+1]%=mod; 
			
		}
		dp[i+1][0]%=mod; 
		for(int j = 1 ; j<= k ; j++ )dp[i+1][j]+=dp[i+1][j-1]+mod,assert(dp[i+1][j]>=0),dp[i+1][j]%=mod; 
	}
	// for(int i = 1 ; i <= n ; i++ ){for(int j = 0 ; j <= k ; j++ )cout << dp[i][j]<<" " ; cout<<endl; }
	cout << dp[n][k]<<endl; 
}

Measured memory_bytes: 235776
using System;
class ProgramB
    {
        static void Main(string[] args)
        {
            
            //入力
            string input = Console.ReadLine();
            int n = int.Parse(input);

            
            //
            int x =(int)(Math.Ceiling((double)n / 1.08));
            int xn = (int)(x * 1.08);

            if(xn == n)
                Console.WriteLine(x);
            else
            {
                Console.WriteLine(":(");
            }

            
                
        }
    }

Measured memory_bytes: 13140
N, M = [int(i) for i in input().split()]
J = []
for i in range(N):
    A = list([int(j) for j in input().split()])
    J.append(A)

J.sort()
total = 0
for i in range(N):
    if M - J[i][1] < 0:
        total += M * J[i][0]
        break
    else:
        total += J[i][0]*J[i][1]
        M = M - J[i][1]
print(total)

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

int main() {
  string S;
  cin >> S;
  
  string ans;
  if (S == "Sunny") ans = "Cloudy";
  if (S == "Cloudy") ans = "Rainy";
  if (S == "Rainy") ans = "Sunny";
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
##############################

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

hi = 0

for i in range(N-1):
    diff = X[i+1] - X[i]
    hi += min(diff*A, B)

print(hi)

Measured memory_bytes: 14168
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <map> 
#include <set>
#include <vector>
#include <list>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define ll long long
#define debug cout << __FILE__ << ":" << __LINE__ << endl;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    if (v.empty()) {
        ostr << "{ }";
        return ostr;
    }
    ostr << "{" << v.front();
    for (auto itr = ++v.begin(); itr != v.end(); itr++) {
        ostr << ", " << *itr;
    }
    ostr << "}";
    return ostr;
}

int gcd(int a, int b) {
    if (a < b) a, b = b, a;
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

void solve() {
    int N;
    cin >> N;

    int L[N];
    rep(i, N) cin >> L[i];
    
    vector<int> a;
    vector<int> b;
    vector<int> c;
    rep(i, N) {
        if (L[i] % 4 == 0) {
            a.push_back(L[i]);
        } else if (L[i] % 2 == 0) {
            b.push_back(L[i]);
        } else {
            c.push_back(L[i]);
        }
    }

    int ax = 0;
    int bx = 0;
    int cx = 0;
    int before = 0;
    bool f = true;
    while (N != (ax + bx + cx)) {
        if (before == 0) {
            if (c.size()) {
                before = c[cx];
                cx++;
            } else if (b.size()) {
                before = b[bx];
                bx++;
            } else {
                before = a[ax];
                ax++;
            }
            continue;
        }
        if (before % 2 != 0) {
            if (ax == a.size()) {
                f = false;
                break;
            }
            before = a[ax];
            ax++;
        } else if (before % 4 != 0) {
            if (ax == a.size() && bx == b.size()) {
                f = false;
                break;
            }

            if (bx != b.size()) {
                before = b[bx];
                bx++;
            } else {
                before = b[ax];
                ax++;
            }
        } else {
            if (ax == a.size() && bx == b.size() && cx == c.size()) {
                f = false;
                break;
            }

            if (cx != c.size()) {
                before = c[cx];
                cx++;
            } else if (bx != b.size()) {
                before = b[bx];
                bx++;
            } else {
                before = a[ax];
                ax++;
            }
        }
    }

    if (f) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    cout.precision(20);
    cout << fixed;

    solve();
}


Measured memory_bytes: 1404
//🔴    
//繰り返し二乗法
//x^nを高速に求めるアルゴリズム
//pow()はどうなっているんだろう
#include<math.h>
#include<iostream>
#define MOD 1000000007
using namespace std;

long long mod_pow(long long x, long long n){
    long long res = 1;
    while(n > 0){
        if(n & 1) res = res * x % MOD;

        x = (x * x) % MOD;
        n = n >> 1;
    }

    return res;
}

int main(){
    long long x, n; cin >> x >> n;
    //cout << pow(x, n) << endl;
    cout << mod_pow(x, n) << endl;
    return 0;
}


Measured memory_bytes: 3116
#define ll long long
#define ld long double
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set2d(array, val, m, n) memset(array, val, sizeof(array[0][0]) * m * n);
#include <bits/stdc++.h>
using namespace std;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x %= p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll po(ll base, ll powerRaised)
{
    if (powerRaised != 0)
        return (base * po(base, powerRaised - 1));
    else
        return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif //*/
    ll n;
    cin >> n;
    ll ans = 0;
    vector<ll> v;
    map<ll, ll> mpp;
    for (int i = 0; i < n; i++)
    {
        ll x;
        cin >> x;
        ans += mpp[x];
        v.pb(x);
        mpp[x]++;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << ans - (mpp[v[i - 1]] - 1) << endl;
    }

    return 0;
}


Measured memory_bytes: 11120
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.A
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			var a = cin.Next().ToCharArray();
			a[3] = '8';
			Console.WriteLine(string.Concat(a));
			
			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=200005;
int a[N],n,m;

inline int chk(int lim){
	int p=2*n;
	rep(i,1,2*n){
		int t=upper_bound(a+1,a+2*n+1,lim-a[i])-a-1;
		if(i<t)p=min(p,i+t-1);
		else {p=min(p,2*i-2);break;}
	}
	int l=0;
	per(i,2*n,1){
		int t=lower_bound(a+1,a+2*n+1,m-a[i])-a;
		if(t<i)l=max(l,t+i-1-2*n);
		else {l=max(l,2*i-2*n);break;}
	}
	if(p&1)p--;
	if(l&1)l++;
	if(p<l)return 0;
	for(int x=l+1,y=2*n;x<y;x++,y--)
		if(a[x]+a[y]>m+lim)return 0;
	return 1;
}

int main(){
	read(n),read(m);
	rep(i,1,2*n)read(a[i]);
	sort(a+1,a+2*n+1);
	int l=0,r=m;
	for(int mid;l<r;){
		mid=(l+r)>>1;
		if(chk(mid))r=mid;
		else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
template<typename T> void no(const T&s){cout << s; exit(0);}
struct node{
	LL b, l, u;
};
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	LL N, X;
	cin >> N >> X;
	vector<node> v(N);
	LL sum = 0, ans = X;
	for(node& p : v) {
		cin >> p.b >> p.l >> p.u;
		sum -= p.b * p.l;
	}
	sort(v.begin(), v.end(), [&](const node& p, const node &q){
		return (X - p.b) * p.u + p.b * p.l > (X - q.b) * q.u + q.b * q.l;
		return p.u < q.u;
	});
	int M;
	LL csum = sum;
	for(M = 0; M < N; M += 1){
		csum += (X - v[M].b) * v[M].u + v[M].b * v[M].l;
		if(csum >= 0) break;
	}
	vector<LL> s;
	s.push_back((X - v[0].b) * v[0].u + v[0].b * v[0].l);
	for(int i = 1; i < N; i += 1) s.push_back(s.back() + (X - v[i].b) * v[i].u + v[i].b * v[i].l);
	for(int i = 0; i < N; i += 1){
		LL psum;
		if(i >= M) psum = sum + (~(M - 1) ? s[M - 1] : 0);
		else psum = sum + s[M] - (X - v[i].b) * v[i].u - v[i].b * v[i].l;
		LL y = (-psum + v[i].l - 1) / v[i].l;
		ans = min(y, ans);
		y = (-psum + v[i].b * (v[i].u - v[i].l) + v[i].u - 1) / v[i].u;
		if(y >= v[i].b) ans = min(y, ans);
	}
	cout << M * X + ans;
	return 0;
}

Measured memory_bytes: 3704
#include <stdio.h>

int main(void){
	int F[30], a, i;
	for (i = 0; i < 30; i++){
		F[i] = 1;
	}
	for (i = 0; i < 28; i++){
		scanf("%d", &a);
		F[a - 1] = 0;
	}
	for (i = 0; i < 30; i++){
		if (F[i]) printf("%d\n", i + 1);
	}
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <string.h>

int main(void)
{
	int blood[8] = {0}, n, i;
	char b[4], ca;
	
	while (scanf("%d%c%s", &n, &ca, b) != EOF){
		if (strcmp(b, "A") == 0)blood[0]++;
		else if (strcmp(b, "B") == 0)blood[1]++;
		else if (strcmp(b, "AB") == 0)blood[2]++;
		else blood[3]++;
		
	}
	
	for (i = 0; i < 4; i++)printf("%d\n", blood[i]);
	
	return (0);
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N;
ll mo=1000000007;
ll F[1010101];
ll S[1010101];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	
	F[1]=S[1]=N;
	F[2]=N*N%mo;
	S[2]=(S[1]+F[2])%mo;
	for(i=3;i<=N;i++) {
		F[i]=F[i-1]+(N-1)*(N-1);
		
		F[i]+=S[i-3]+(N-1-(i-3));
		
		F[i]%=mo;
		S[i]=(S[i-1]+F[i])%mo;
	}
	
	cout<<F[N]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

using namespace std;

int main(void)
{
    int n, k, d, A, B[105]={}, counter=0;
    cin >> n >> k;
    for (int i=0; i < k; ++i) {
        cin >> d;
        for (int j=0; j < d; ++j) {
            cin >> A;
            B[A] = 1;
        }
    }

    for (int i=1; i <= n; ++i) {
        if (!B[i]) counter++;
    }
    cout << counter << endl;
    return 0;
}


Measured memory_bytes: 3596
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
vector<int> divisor(int n) {
    vector<int> ret;

    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != n / i) ret.push_back(n / i);
        }
    }

    return move(ret);
}

signed main() {
    int N;
    cin >> N;
    vector<int> A(N + 1);
    for (int i = 1; i <= N; i++) cin >> A[i];

    vector<int> X(N + 1);
    vector<int> B(N + 1, 0);

    for (int i = N; i >= N/2 + 1; i--) {
        X[i] = A[i];

        if (A[i] == 1) {
            vector<int> divs = divisor(i);
            for (int div : divs) {
                B[div]++;
                B[div] %= 2;
            }
        }
    }

    for (int i = N / 2; i >= 1; i--) {
        X[i] = (A[i] + B[i]) % 2;
        if (X[i] == 1) {
            vector<int> divs = divisor(i);
            for (int div : divs) {
                B[div]++;
                B[div] %= 2;
            }
        }
    }

    vector<int> ans;
    for (int i = 1; i <= N; i++) {
        if (X[i] == 1) ans.push_back(i);
    }


    int M = ans.size();
    cout << M << endl;
    for (int i = 0; i < M; i++) {
        cout << ans[i];
        if (i != M - 1) cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 6516
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define inf 1<<30
using namespace std;

int n,m;
long long G[501][501];
vector<pair<int,int> > V;

long long Prim()
{
  priority_queue<pair<int,int> > PQ;
  long long d[501],color[501],parent[501];
  for(int i=0;i<n;i++){
    d[i]=inf;
    color[i]=0;
  }
  d[0]=0;
  parent[0]=0;
  PQ.push(make_pair(0,0));
  color[0]=0;
  while(!PQ.empty()){
    pair<int,int> p=PQ.top();PQ.pop();
    int u=p.s;
    color[u]=2;

    if(d[u]<p.f*(-1))continue;

    for(int i=0;i<n;i++){
      if(color[i]==2 || G[u][i]==inf)continue;
      if(d[i]>G[u][i]){
	d[i]=G[u][i];
	PQ.push(make_pair(d[i]*(-1),i));
	parent[i]=u;
	color[i]=1;
      }
    }
  }
  if(V.empty()){
    for(int i=1;i<n;i++){
      V.push_back(mp(i,parent[i]));
    }
  }
  long long res=0;
  for(int i=0;i<n;i++)res+=d[i];
  return res;
}  

int main()
{
  int x,y,c;
  cin>>n>>m;
  for(int i=0;i<501;i++)for(int j=0;j<501;j++)G[i][j]=inf;
  for(int i=0;i<m;i++){
    cin>>x>>y>>c;
    x--;y--;
    G[x][y]=c;
    G[y][x]=c;
  }
  long long sum=Prim(),sump=0,sumc=0;
  for(int i=0;i<V.size();i++){
    int tmp=G[V[i].f][V[i].s];
    G[V[i].f][V[i].s]=inf;
    G[V[i].s][V[i].f]=inf;
    long long a=Prim();
    if(sum<a){
      sump++;
      sumc+=tmp;
    }
    G[V[i].f][V[i].s]=tmp;
    G[V[i].s][V[i].f]=tmp;
  }
  cout<<sump<<" "<<sumc<<endl;
  return 0;
}

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

int main (){
    long long X, K, D;
    cin >> X >> K >> D;
    X = abs(X);


    if (X/D - K >= 0)
    {
        cout << X - K*D << endl;
    }
    else
    {
        K -= X/D;
        X -= (X/D)*D;
        cout << abs(X - D*(K%2)) << endl;
        //cout << min(X + (K%2)*D,abs(X - D) + ((1 + K)%2)*D) << endl;
    }

    
}


Measured memory_bytes: 3620
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        K: usize,
        H: [i64; N],
    }
    let mut dp = vec![0; N];
    for i in 1..N{
        let mut cost = 999999999;
        for k in 1..K+1{
            if k>i{
                break;
            }
            cost = min(cost, dp[i-k] + (H[i]-H[i-k]).abs());
        }
        dp[i] = cost;
    }
    println!("{}", dp[N-1]);
}

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

ll solve() {
    ll H, W;
    cin >> H >> W;
    ll N = H + W + 2;
    vector<vector<ll>> S(N, vector<ll>(N));
    string s;
    for ( int h = 0; h < H; h++ ) {
        cin >> s;
        for ( int w = 0; w < W; w++ ) {
            if ( s[w] == '#' ) {
                S[h+W-w+1][h+w+1] = 1;
            }
        }
    }

    auto count1 = [](ll N, vector<vector<ll>>& s,bool border) {
        vector<vector<ll>> pt(N);
        vector<vector<ll>> cs(N,vector<ll>(N));
        for ( int i = 0; i < N; i++ ) {
            for ( int j = 1; j < N; j++ ) {
                if ( s[i][j] ) pt[i].push_back(j);
                cs[i][j] = cs[i][j-1] + s[i][j];
            }
        }
        ll c = 0;
        for ( int i = 0; i < N; i++ ) {
            for ( int j1 = 0; j1 < pt[i].size(); j1++ ) {
                for ( int j2 = j1+1; j2 < pt[i].size(); j2++ ) {
                    int p1 = pt[i][j1], p2 = pt[i][j2];
                    int d = p2 - p1;
                    int dd = border ? 0 : 1;
                    if ( i - d >= 0 && p1-1+dd < p2-dd) {
                        c += (ll)(cs[i-d][p2-dd] - cs[i-d][p1-1+dd]);
                    }
                    if ( i + d < N && p1-1+dd < p2-dd ) {
                        c += (ll)(cs[i+d][p2-dd] - cs[i+d][p1-1+dd]);
                    }
                }
            }
        }
        return c;
    };

    ll ans = 0;
    ans += count1(N, S, true);
    for ( int i = 0; i < N; i++ ) {
        for ( int j = i+1; j < N; j++ ) {
            swap(S[i][j],S[j][i]);
        }
    }
    ans += count1(N, S, false);
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6912
#!/usr/bin/env python3
import sys
INF = float("inf")
from collections import deque


class Dinic:
    def __init__(self, n):
        self.n = n
        self.links = [[] for _ in range(n)]
        self.depth = None
        self.progress = None

    def add_edge(self, _from, to, cap):
        self.links[_from].append([cap, to, len(self.links[to])])
        self.links[to].append([0, _from, len(self.links[_from]) - 1])

    def bfs(self, s):
        depth = [-1] * self.n
        depth[s] = 0
        q = deque([s])
        while q:
            v = q.popleft()
            for cap, to, rev in self.links[v]:
                if cap > 0 and depth[to] < 0:
                    depth[to] = depth[v] + 1
                    q.append(to)
        self.depth = depth

    def dfs(self, v, t, flow):
        if v == t:
            return flow
        links_v = self.links[v]
        for i in range(self.progress[v], len(links_v)):
            self.progress[v] = i
            cap, to, rev = link = links_v[i]
            if cap == 0 or self.depth[v] >= self.depth[to]:
                continue
            d = self.dfs(to, t, min(flow, cap))
            if d == 0:
                continue
            link[0] -= d
            self.links[to][rev][0] += d
            return d
        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.depth[t] < 0:
                return flow
            self.progress = [0] * self.n
            current_flow = self.dfs(s, t, float('inf'))
            while current_flow > 0:
                flow += current_flow
                current_flow = self.dfs(s, t, float('inf'))


def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    red = [[a[i], b[i]] for i in range(N)]
    blue = [[c[i], d[i]] for i in range(N)]

    # 最大マッチング問題として解く。
    dn = Dinic(2*N+2)
    for i, (rx, ry) in enumerate(red):
        dn.add_edge(0, i+1, 1)
    for j, (bx, by) in enumerate(blue):
        dn.add_edge(N+j+1, 2*N+1, 1)

    for i, (rx, ry) in enumerate(red):
        for j, (bx, by) in enumerate(blue):
            if rx < bx and ry < by:
                dn.add_edge(i+1, N+j+1, 1)

    ans = dn.max_flow(0, 2*N+1)
    print(ans)

    # print(dn.links)


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    c = [int()] * (N)  # type: "List[int]"
    d = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, a, b, c, d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double tansin = 0.5 * (60*h + m);
  double chosin = 6 * m;
  double ans = sqrt(a*a + b*b - 2*b*a* cos((tansin-chosin)*acos(-1)/180));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4240
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <functional>
#include <map>
using namespace std;

int N, A[100009], B[100009], T[300009]; vector<int>vec;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
		vec.push_back(A[i]);
		vec.push_back(B[i] + 1);
	}
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());

	for (int i = 1; i <= N; i++) {
		A[i] = lower_bound(vec.begin(), vec.end(), A[i]) - vec.begin();
		B[i] = lower_bound(vec.begin(), vec.end(), B[i] + 1) - vec.begin();
		T[A[i]]++; T[B[i]]--;
	}
	for (int i = 0; i < vec.size(); i++) T[i + 1] += T[i];
	int maxn = 0;
	for (int i = 0; i <= vec.size(); i++) {
		maxn = max(maxn, T[i]);
	}
	cout << maxn << endl;
	return 0;
}


Measured memory_bytes: 5496
def main():
    n = int(input())
    aaa = list(map(int, input().split()))

    ans = 'APPROVED'
    for a in aaa:
        if a % 2 == 0:
            if a % 3 == 0 or a % 5 == 0:
                pass
            else:
                ans = 'DENIED'
        else:
            pass
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
N = int(input())
H = [int(_) for _ in input().split()]

result = True
for i in range(1, N):
    if H[i] < H[i - 1]:
        if H[i] == H[i - 1] - 1:
            H[i] += 1
        else:
            result = False
            break

print(["No", "Yes"][result])


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

int n,a[110];

int main() {
  cin >> n;
  int sum=0;
  rep(i,n){
  cin >> a[i]; sum+=a[i];
  }
  double b=(double)sum/n,d=1000,ans=1000;
  for(int i=n-1;i>=0;i--){
    if(abs(a[i]-b)<d){
    d=abs(a[i]-b),ans=i;
    } else if(abs(a[i]-b)==d)
    ans=i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include<cmath>
using namespace std;

#define ll long long
int main(){
  int N;
  cin>>N;
  ll ans=0;
  for(int n=1;n<=N;n++){
    ans=0;
    for(int A=2;A<=142;A++){
      for(int B=2;B<=142;B++){
        if(A*A+B*B>2*n) break;
        int C=sqrt(2*n-A*A-B*B);
        int S=A+B+C;
        if(C*C==2*n-A*A-B*B && S%2==0 && S/2>max({A,B,C})){
          ans++;
          //cout<<2*n<<" "<<A<<" "<<B<<" "<<C<<endl;
        }
        
      }
    }
    cout<<ans<<endl;
    }
  return 0;}


Measured memory_bytes: 3528
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
	int n, *a;
	cin >> n;
	a = new int[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	long long sum = 0;
	for (int i = 0; i < n; i++)
		sum += a[i];

	printf("%d %d %ld\n", a[0], a[n-1], sum);
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>

using namespace std;



static int A[1000];
int main() {
    int n=0;
    cin >> n;
    //int A[n];
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    for (int k = 0; k < n - 1; k++) {
        cout << A[k] << " ";
    }
    cout << A[n - 1] << "\n";
    int v, j;
    for (int i = 1; i < n; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 and A[j] > v) {
            A[j + 1] = A[j];
            --j;
        }
        A[j + 1] = v;
        for (int k = 0; k < n-1; k++) {
            cout << A[k] << " ";
        }
        cout << A[n - 1] << "\n";
    }

}




Measured memory_bytes: 3084
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 500
int main() {
  int i,result,count=0,num,j,len;
  int stack[99];
  char n[MAX];
  
  fgets(n,MAX,stdin);
  len = strlen(n);
  for(i=0;i<len;i++)
    {
      if(n[i]>=48 && n[i]<=57 && n[i+1]==' ')
	{
	  stack[count] = atoi(&n[i]);
	  count++;
	}
      else if(n[i]>=48 && n[i]<=57 && n[i+1]!=' ')
	{
	  stack[count] = atoi(&n[i]);
	  num = stack[count];
	  while(num!=0)
	    {
	      num /= 10;
	      i++;
	    }
	  count++;
	}
      /*for(j=0;j<count;j++)
	{
	  printf("%d ",stack[j]);
	
	}
	printf("\n");*/
      if(n[i]==43)
	{
	  stack[count-2]+=stack[count-1];
	  count--;
	}
      if(n[i]==45)
	{
	  stack[count-2]-=stack[count-1];
	  count--;
	}
      if(n[i]==42)
	{
	  stack[count-2]*=stack[count-1];
	  count--;
	}
    }
  printf("%d\n",stack[count-1]);
}
      



Measured memory_bytes: 2100
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();
    let m: usize = read().unwrap();
    let mut vec: Vec<f64> = Vec::new();
    let mut count: usize = 0;

    for _ in 0..n {
        vec.push(read().unwrap());
    }

    let total: f64 = vec.iter().sum();
    for x in vec.iter() {
        let score: f64 = 1.0 / (4.0 * (m as f64));
        if (x / total as f64) >= score {
            count += 1;
        }
    }
    if count >= m {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    s=input()
    x=int(s)
    fx=sum(int(c) for c in s)
    print("No") if x%fx else print("Yes")

main()

Measured memory_bytes: 2940
import collections

def search(sy, sx, gy, gx):
    visited = [[False for j in range(W)] for i in range(H)]
    visited[sy][sx] = True
 
    dq = collections.deque()
    dq.append((0, sy, sx))
    while dq:
        cost, y, x = dq.popleft()
        if (y,x) == (gy, gx):
            return cost
        for dy, dx in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            ny = y + dy
            nx = x + dx
            if ny < 0 or ny >= H or nx < 0 or nx >= W:
                continue
            if visited[ny][nx] or cells[ny][nx] == 'X':
                continue
            dq.append((cost + 1, ny, nx))
            visited[ny][nx] = True

def main(H, W, N, cells):
    points = {}
    for i in range(H):
        for j in range(W):
            points[cells[i][j]] = (i, j)
    points['0'] = points['S']
    total = 0
    for i in range(1, N+1):
        sy, sx = points[str(i-1)]
        gy, gx = points[str(i)]
        total += search(sy, sx, gy, gx)
    print(total)
 
 
if __name__ == '__main__':
    H, W, N = map(int, input().split())

    cells = []
    for i in range(H):
        cells.append(input())
    main(H, W, N, cells)

Measured memory_bytes: 17904
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
        v = A[i]
        j = i-1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(*A)


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

using namespace std;

const int N = 1e5 + 1;

int n, m;

vector<int> g[N];
bool visit[N];
int dp[N];

void dfs(int u) {
  visit[u] = true;
  for(auto v: g[u]) {
    if(!visit[v]) {
      dfs(v);
    }
    dp[u] = max(dp[u], dp[v] + 1);
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> m;
  while(m--) {
    int u, v;
    cin >> u >> v;
    g[u].emplace_back(v);
  }
  int ans = 0;
  for(int i = 1; i <= n; ++i){
    if(visit[i] == false) {
      dfs(i);
    }
  }
  for(int i = 1; i <= n; ++i) {
    ans = max(ans, dp[i]);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 8320
use proconio::{input, marker::Usize1};

fn main() {
    input!(h: usize, w: usize, bomb: [(Usize1, Usize1)]);

    let mut row = vec![0; h];
    let mut col = vec![0; w];
    for &(i, j) in &bomb {
        row[i] += 1;
        col[j] += 1;
    }
    let rm = *row.iter().max().unwrap();
    let cm = *col.iter().max().unwrap();
    let rc = row.iter().filter(|&&c| c == rm).count();
    let cc = col.iter().filter(|&&c| c == cm).count();
    let bc = bomb
        .iter()
        .filter(|&&(i, j)| row[i] == rm && col[j] == cm)
        .count();
    let ans = if bc < rc * cc { rm + cm } else { rm + cm - 1 };

    println!("{}", ans);
}


Measured memory_bytes: 12944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=200010;
ll x[maxn],c[maxn],sum_x[maxn];
int main(){
	int n;
	ll X;
	scanf("%d%lld",&n,&X);
	for(int i=1;i<=n;i++){
		scanf("%lld",x+i);
		sum_x[i]=sum_x[i-1]+x[i];
	}
	c[1]=c[2]=5;
	for(int i=3;i<=n;i++)
		c[i]=c[i-1]+2;
	ll ans=8000000000000000000ll;
	for(int k=1;k<=n;k++){
		ll cost=k*X;
		for(int i=n,j=1;i>0 && cost<ans;i=max(i-k,0),j++)
			cost+=c[j]*(sum_x[i]-sum_x[max(i-k,0)]);
		ans=min(ans,cost);
	}
	printf("%lld\n",ans+n*X);
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> pii;
#define INF 0x3f3f3f3f
const int N = 100010;
int mod = 1000000007;
int main()
{
	//freopen("in.txt", "r", stdin);
	int T, n, k;
	while (~scanf("%d", &n))
	{
		set<char> S;
		for (int i = 0; i < n; i++)
		{
			char c[3];
			scanf("%s", c);
			S.insert(c[0]);
		}
		printf("%s\n", S.size() == 3?"Three":"Four");
	}
   	return 0;
}

Measured memory_bytes: 256
n = int(input())
*li, = map(int, input().split())
input()
*Q, = map(int, input().split())

bits = 1
for i in li:
    # print(f"{i=}")
    # print(f"{bin(bits)=}")
    bits |= bits << i
    # print(f"{bin(bits)=}")
    # print()

# print()
for q in Q:
    # print(f"{bin(bits)=}")
    print("yes"*((bits >> q) & 1) or "no")
    # print()



Measured memory_bytes: 5620
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

bool has_target(string s, int from, int to, string target) {
	auto x = s.find(target, from);

	// printf("has_target %d, %d, %s\n", x, to, target.c_str());
	if (x == string::npos) {
		return false;
	} else if (x < to) {
		return true;
	}

	return false;
}

int main() {
	string s;
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	cin >> s;

	a--;
	b--;
	c--;
	d--;

	if (c > d) {
		bool overtakes = has_target(s, b - 1, d, "...");
		if (!overtakes) {
			cout << "No" << endl;
			return 0;
		}
	}

	bool ok1 = !has_target(s, a, c, "##");
	bool ok2 = !has_target(s, b, d, "##");
	cout << (ok1 && ok2 ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int h, w;
	int i, j;

	while (1) {
		scanf("%d %d", &h, &w);

		if (h == 0 && w == 0) {
			break;
		}
		for (i = 1; i <= h; i++) {
			for (j = 1; j <= w; j++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 2056
from collections import deque
S = input()
S = list(S)
counter = 0
que = deque([])
stack = deque([])
for i in range(len(S)):
    que.append(S[i])
for i in range(1000000):
  if stack:
    1
  else:
    if que:
      stack.append(que.popleft())
    else:
      break
  if que:
    s1 = que.popleft()
  else:
    break
  s2 = stack.pop()
  if(s1 != s2):
    counter+=2
  else:
    stack.append(s1)
    stack.append(s2)
print(counter)

Measured memory_bytes: 5028
import math


def main():
    amax = int(1e6+1)
    n = int(input())
    a = [int(v) for v in input().split()]
    dp = [0 for _ in range(amax)]
    dup = {}
    a.sort()
    for v in a:
        if dup.get(v) is None:
            dup[v] = 0
        else:
            dup[v] = 1
            continue
        if dp[v] == 0:
            for i in range(2, amax):
                if i * v > 1e6:
                    break
                dp[i*v] = 1
    ans = 0
    for v in a:
        if dp[v] == 0 and dup[v] == 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

char rot(char c, int n) {
	char r;
	n = n % 26;
	if (c + n > 'z') {
		r = 'a' + c + n - 'z' -1;
	}else{
		r = c + n;
	}
	return r;
}

int main() {
	string str; cin >> str;
	int n; cin >> n;
	int l = str.size();
	for (int i = 0; i < l; i++ ) {
		if ( str[i] != 'a' ) {
			int d = 'z' - str[i] + 1;
			if (n >= d) {
				str[i] = rot( str[i], d );
				n = n - d;
			}
		}
	}
	str[l-1] = rot( str[l-1], n );
	cout << str << endl;
	return 0;
}


Measured memory_bytes: 512