akhauriyash/Code-Regression huggingface dataset:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [0,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod

# nCrの和をとる関数
def comb_sum(base: int, start: int, last: int, mod: int, fac: list, facInv:list):
    ret = 0
    for i in range(start, last+1):
        ret += nCr(base, i, mod, fac, facInv)
        
    return ret

n,a,b = li()
v = list(li())

v.sort(reverse=True)
maxv = max(v)
maxs = v.count(maxv)

MOD = 2**61-1
MAXN = 100
inv = inv_mod(MAXN, MOD)
fac = fact(MAXN, MOD)
fac_inv = fact_inv(MAXN, inv, MOD)


if maxs <= a:
    ans = sum(v[:a]) / a
    lastcnt = v.count(v[a-1])
    pat = nCr(lastcnt, a-v.index(v[a-1]), MOD, fac, fac_inv)
    
elif a < maxs < b:
    ans = maxv
    pat = comb_sum(maxs, a, maxs, MOD, fac, fac_inv)
    
else:
    ans = maxv
    pat = comb_sum(maxs, a, b, MOD, fac, fac_inv)
    
print(ans)
print(pat)
    

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define repn(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) for(int i = 0; i < (a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
const int MOD = 1e9 + 7;

char g[1005][1005];
ll dp[1005][1005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	rep(i, n){
		rep(j, m){
			cin >> g[i][j];
		}
	}
	dp[0][0] = 1;
	rep(i, n){
		rep(j, m){
			if(g[i][j] == '#'){
				dp[i][j] = 0;
				continue;
			}
			if(i - 1 >= 0 && g[i - 1][j] != '#') dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
			if(j - 1 >= 0 && g[i][j - 1] != '#') dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
		}
	}
	cout << dp[n - 1][m - 1] << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  if((c-a-b) < 0) cout <<  "No" << endl;
  else if((a+b-c)*(a+b-c) > 4*a*b) cout << "Yes" << endl;
  else cout << "No" << endl;
  
 
  return 0;
}


Measured memory_bytes: 256
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)
for _ in range(m):
  tmp_min = heapq.heappop(a)
  heapq.heappush(a, (-1)*(-tmp_min//2))
print(-sum(a))

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

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    bool ans = false;
    for (int i = a; i <= b; i++){
        if (i % k == 0){
            ans = true;
            break;
        }
    }
    
    if(ans) cout << "OK" << endl;
    else cout << "NG" << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
void pop(int *i,int *a){
	cout<<*a<<endl;
	*i-=1;
	*a=0;
}
void push(int *i,int *a,int n){
	*a=n;
	*i+=1;
}
int main(){
	int a[100],i,n,j,k,p;

	for(i=0;i<100;i++){
		a[i]=0;
	}
	i=0;
	while(cin>>n){
		if(n==0){
			pop(&i,&a[i-1]);
		}else{
			push(&i,&a[i],n);
		}
	}
    return 0;
}

Measured memory_bytes: 1160
/*
 * AOJ 2251: Merry Christmas
 * ?¢?????????????????????????????????????????????????????????????????????????????????¨???????????¶??????????±?????°???????????°???????????????????????????????
 * ?±????????????????+????????????
 * ??????????????¨Floyd?±????????????´??????????????\??????????????¶??´???????¶????????????????????????\??????????????????????????\???????????????????????¬???????????????????????°-?????§?????????2??????????±????
 */

#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

const int INF = 0x3f3f3f3f;

vector<int> e[1010];
bool vis[1010];
int rec[1010];
int n1;

int n, m;
int d[110][110];

int p[1010], t[1010];

bool Dfs(int u) {
  for (vector<int>::iterator it = e[u].begin(); it != e[u].end(); ++it) {
    int v = *it;
    if (!vis[v]) {
      vis[v] = true;
      if (rec[v] == -1 || Dfs(rec[v])) {
        rec[v] = u;
        return true;
      }
    }
  }
  return false;
}

int Hungary() {
  int ans = 0;
  memset(rec, -1, sizeof(rec));
  for (int i = 0; i < n1; ++i) {
    memset(vis, 0, sizeof(vis));
    if (Dfs(i)) ++ans;
  }
  return ans;
}

void Floyd() {
  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() {
//  freopen("/Users/yogy/acm-challenge-workbook/db.in", "r", stdin);
  while (scanf("%d%d%d", &n, &m, &n1) != EOF && n) {
    memset(d, 0x3f, sizeof(d));
    for (int i = 0; i < n; ++i) d[i][i] = 0;
    for (int i = 0; i < m; ++i) {
      int u, v, c;
      scanf("%d%d%d", &u, &v, &c);
      d[u][v] = d[v][u] = c;
    }
    Floyd();
    for (int i = 0; i < n1; ++i) {
      scanf("%d%d", &p[i], &t[i]);
      e[i].clear();
    }
    for (int i = 0; i < n1; ++i) {
      for (int j = 0; j < n1; ++j) {
        if (i == j) continue;
        if (t[i] + d[p[i]][p[j]] <= t[j]) {
          e[i].push_back(j);
        }
      }
    }
    printf("%d\n", n1 - Hungary());
  }

  return 0;
}

Measured memory_bytes: 6900
#include<stdio.h>
#define NUM 10

int main(void)
{
	int a,b,temp;
	int top1,top2,top3;
	int mountain[NUM];
	
	for(a = 0 ; a < NUM ; a++){
		scanf("%d",&mountain[a]);
	}
	for(b = NUM-1 ; b >= 0 ; b--){
		for(a = 0 ; a < b ; a++){
			if(mountain[a] > mountain[a+1]){
				temp = mountain[a];
				mountain[a] = mountain[a+1];
				mountain[a+1] = temp;
			}
		}
	}
	top1 = mountain[NUM-1];	top2 = mountain[NUM-2];	top3 = mountain[NUM-3];
	
	printf("%d\n%d\n%d\n",top1,top2,top3);
	
	return 0;
}

Measured memory_bytes: 600
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			int[][] t = new int[n][n+1];
			for(int i=0;i<n;i++) {
				for(int j=0;j<=n;j++) {
					t[i][j] = sc.nextInt();
				}
			}
			int[] dp = new int[1<<n];
			Arrays.fill(dp, 1 << 29);
			dp[0] = 0;
			for(int i=0;i<1<<n;i++) {
				for(int j=0;j<n;j++) {
					if ((i >> j & 1) == 1) {
						continue;
					}
					int to = i | (1 << j);
					int min = t[j][0];
					for(int k=0;k<n;k++) {
						if ((i >> k & 1) == 1) {
							min = Math.min(min,t[j][k+1]);
						}
					}
					dp[to] = Math.min(dp[to], dp[i] + min);
				}
			}
			System.out.println(dp[(1<<n)-1]);
		}
	}

}

Measured memory_bytes: 44732
import bisect


def main():
    n = int(input())
    l_list = list(map(int, input().split()))
    l_list.sort()

    ans = 0
    for i, a in enumerate(l_list):
        for j, b in enumerate(l_list[i+1:]):
            x = a + b
            temp = bisect.bisect_left(l_list, x)
            ans += temp - (i + 1 + j + 1)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43484
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f(x,n) for (int i=x;i<n;i++)

int count(int a[], int n, int minh[])
{
  if(minh[n]!=-1)
    return minh[n]; 
  
  if(n==1)
  {
    return 0;
  }
  if (n==2)
  {
    return abs(a[2]-a[1]);
  }
  minh[1]= 0;
  
  minh[2]=abs(a[2]-a[1]);

  int ansp,anspp,ans;

  ansp=abs(a[n]-a[n-1])+count(a,n-1,minh);

  anspp=abs(a[n]-a[n-2])+count(a,n-2,minh);

  minh[n]= min(ansp,anspp);

  return minh[n];
  
}

int main()
{
  int n;
  cin>>n;
  int a[n+1];
  int minh[n+1];
  for(int i=0;i<=n;i++)
  minh[i]=-1;
  for(int i=1;i<=n;i++)
    cin>>a[i];
  int ans=count(a,n,minh);
  cout<<ans;

  return 0;
}

Measured memory_bytes: 12176
using System;
using System.Linq;

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            int[] input;
            bool first = true;
            while(((input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray())[0] | input[1]) != 0){
                if(!first) {
                    Console.WriteLine();
                }
                else {
                    first = false;
                }
                bool exist = false;
                for(int i=input[0]; i <= input[1]; ++i) {
                    if(System.DateTime.IsLeapYear(i)) {
                        Console.WriteLine(i);
                        exist = true;
                    }
                }
                if(!exist) {
                    Console.WriteLine("NA");
                }
            }
        }
    }
}

Measured memory_bytes: 6004
from collections import deque


n, m = map(int, input().split())

g = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

dist = [-1] * n
prev = [-1] * n
que = deque([0])
dist[0] = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in g[v]:
        if dist[w] > -1:
            continue
        dist[w] = d + 1
        que.append(w)
        prev[w] = v

print("Yes")
for i in prev[1:]:
    print(i + 1)

Measured memory_bytes: 35696
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n; cin >> n;
  	int a[n]; for(int i=0;i<n;i++) cin >> a[i];
  	sort(a,a+n);
  	cout<<a[n-1]-a[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	int number = 0;
	std::cin >> number;

	int check_num = 0;

	for (int count = 0; count < number; count++)
	{
		std::cin >> check_num;

		if (check_num % 2 == 0)
		{
			int buffer = check_num % 3;
			if (check_num % 3 != 0 && check_num % 5 != 0)
			{
				std::cout << "DENIED" << std::endl;
				return 0;
			}
		}
	}
	std::cout << "APPROVED" << std::endl;
}

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

int main() {
  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  ll g = min({a, b, c, d, e});
  ll ans = (n + g - 1) / g + 4;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3540
#include <stdio.h>
int main(){
    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: 2040
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main()
        {
            var info = Console.ReadLine().Split(' ');
            var range = Int64.Parse(info[0]);
            var blue = Int64.Parse(info[1]);
            var red = Int64.Parse(info[2]);
            if (blue + red == 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Int64 time = range / (blue + red);
                var ans = time * blue;
                var rem = range % (blue + red);
                if (rem >= blue)
                {
                    ans += blue;
                }
                else
                {
                    ans += rem;
                }
                Console.WriteLine(ans);
            }
            //Console.ReadKey();
        }
    }
}


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


int main(){

    long long n;
    cin >> n;
    long long x = 0LL;
    int s = 0;
    while((9LL + 10LL * x) <= n) {
        x = 9LL + 10LL*x;
        s+=9;
    }
    for(int fst = 9; fst >= 0; --fst){
        if((x + 1LL)*fst - 1 <= n){
            cout << s + fst - 1 << endl;
            exit(0);
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n,t;
	cin >> n;
	int * a = new int[n+1];
	for (int i = 0;i <=n;i++)
	{
		a[i] = 0;
	}
	for (int i = 2;i <= n;i++)
	{
		cin >> t;
		a[t]++;
	}
	for (int i = 1;i <= n;i++)
	{
		cout << a[i] << "\n";
	}
}

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

using namespace std;

int main(void) {
    int D, G;
    cin >> D >> G;
    vector<int> p(D);
    vector<int> c(D);
    for(int i=0; i<D; i++) {
        cin >> p[i] >> c[i];
    }

    int ans = INT32_MAX;
    for(int i=0; i<(1<<D); ++i) {
        int ans_tmp = 0;
        int point = 0;
        for(int j=0; j<D; j++) {
            if((i>>j) & 1) {
                ans_tmp += p[j];
                point += 100*(j+1)*p[j] + c[j];
            }
        }
        for(int j=D-1; j>=0; --j) {
            if(point < G && !((i>>j) & 1)) {
                int solve = min((G-point) / (100*(j+1)), p[j]);
                ans_tmp += solve;
                point += 100*(j+1)*solve;
            }
        }
        ans = min(ans, ans_tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{ 
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()

    {
        var st = ReadLine();
        WriteLine(8 - st.Count(c => c == 'o') <= 15 - st.Length ? "YES" : "NO");
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public  static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
using namespace std;
int main(){
    int N; cin >> N;
    vector<ll> A(N+1);
    for(int i = 1; i<=N; i++) cin >> A[i];

    vector<ll> X(N+1);
    for(int i = 1; i<=N; i++) X[i] = 0;

    ll sum = 0;
    for(int i = 1; i<=N; i++) sum += A[i];

    ll sum_odd = 0;
    for(int i = 1; i<=N; i += 2) sum_odd += (A[i] + A[i]);

    X[1] = sum_odd - sum;

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

    for(int i = 1; i<=N; i++){
        printf("%lld%c", X[i], i+1==X.size()?'\n':' ');
    }
}


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

int n, k;

int main() {
    scanf("%d%d", &n, &k);
    LL ans = 0;
    for(int i = 1; i <= n; i++) {
        int r = i % k;
        if(r == 0) {
            ans += 1LL * (n / k) * (n / k);
        }
        else if(k % 2 == 0 && r == k / 2) {
            int cnt = (n - r) / k + 1;
            ans += 1LL * cnt * cnt;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
def area(a,b):
    c=a*b
    return c
def perimeter_of_the_rectangle(a,b):
    c=(a+b)*2
    return c
def Rectangle():
    a,b=map(int,input().split())
    c=area(a,b)
    d=perimeter_of_the_rectangle(a,b)
    print("{} {}".format(c,d))
    
if __name__ == '__main__':
    Rectangle()


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  string s, t, u;
  int a, b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;

  if(s==u) a--;
  else if(t==u) b--;
  
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto a = readln.split[0].to!int;
	auto b = readln.split[0].to!int;
	auto c = readln.split[0].to!int;
	auto d = readln.split[0].to!int;
	auto e = readln.split[0].to!int;
	auto k = readln.split[0].to!int;
	if ( e-a > k ) writeln(":(");
	else writeln("Yay!");
}



Measured memory_bytes: 256
H,W = map(int,input().split())
S = [[c=="#" for c in input()] for _ in [0]*H]

d = [[H*W*10]*W for _ in [0]*H]
d[0][0] = int(S[0][0])

d0 = d[0]
S0 = S[0]
for j in range(1,W):
    if S0[j] and (not S0[j-1]):
        d0[j] = d0[j-1]+1
    else:
        d0[j] = d0[j-1]
for i in range(1,H):
    Si = S[i]
    di = d[i]
    if Si[0] and (not S[i-1][0]):
        di[0] = d[i-1][0] + 1
    else:
        di[0] = d[i-1][0]
    #
    for j in range(1,W):
        if Si[j] and (not S[i-1][j]):
            di[j] = d[i-1][j] + 1
        else:
            di[j] = d[i-1][j]
        if Si[j] and (not Si[j-1]):
            di[j] = min(di[j],di[j-1] + 1)
        else:
            di[j] = min(di[j],di[j-1])
print(d[-1][-1])

Measured memory_bytes: 41968
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	static long[] reverse(long a[], int n) {
		long[] b = new long[n];
		int j = n;
		for (int i = 0; i < n; i++) {
			b[j - 1] = a[i];
			j = j - 1;
		}
		return b;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long m = sc.nextLong();
		long v = sc.nextLong();
		int p = sc.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextLong();
		}
		sc.close();
		Arrays.sort(a);
		a = reverse(a, a.length);

		boolean flag = true;

		int l = 0;
		int r = n;
		while (l < r) {
//			System.out.printf("Checking l=%d r=%d \n", l, r);
			int mid = (l + r) >>> 1;
			boolean able = true;
			if (mid < p) {
				flag = true;
			} else if (a[mid] + m < a[p - 1]) {
				flag = false;
			} else {
				long sum = (p - 1) * m + (n - mid - 1) * m + m;

				for (int i = p - 1; i < mid; i++) {
					sum += a[mid] + m - a[i];
					if (a[mid] + m < a[i]) {
						able = false;
					}
				}
//				System.out.println(sum);
				flag = sum >= m * v;
			}

			if (able && flag) {
				l = mid + 1;
			} else {
				r = mid;
			}
		}
		System.out.println(l);
	}
}


Measured memory_bytes: 62700
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < N; ++i) {
            String[] array = scanner.nextLine().split(" ");
            long A = Long.parseLong(array[0]);
            long B = Long.parseLong(array[1]);
            long C = Long.parseLong(array[2]);
            long D = Long.parseLong(array[3]);

            if (A < B) {
                System.out.println("No");
            } else if (D < B) {
                System.out.println("No");
            } else if (D % B == 0) {
                if (A % B > C) {
                    System.out.println("No");
                } else {
                    System.out.println("Yes");
                }
            } else {
                long lcm = B;
                long b = D % lcm;
                while (b != 0) {
                    long temp = lcm;
                    lcm = b;
                    b = temp % lcm;
                }

                if (B - lcm <= C) {
                    System.out.println("Yes");
                } else {
                    System.out.println("No");
                }
            }
        }
    }
}

Measured memory_bytes: 24916
local function readas(N)local l=io.read()local r={}for s in l:gmatch"(%a+)"do table.insert(r,s)end return r end
N=io.read"*n"
io.read()
t={}
for i=1,N do
	t[io.read()]=0
end
s=0
for _,_ in pairs(t)do s=s+1 end
print(s)

Measured memory_bytes: 17820
N = int(input())
# %%

digit = len(str(N))
cnt = 0

for x in range(digit):
    x += 1
    if x % 2 != 0:
        if x < digit:
            cnt += (10**x) - (10**(x-1))
        else:
            cnt += N - (10**(x-1)) + 1

print('{}'.format(cnt))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
const int N=1e5+5;
int n;

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

inline int hbit(int x){
	int ans=0;
	for(int i=16; i; i>>=1){
		if(x>>i) x>>=i,ans+=i;
	}
	return ans;
}

namespace G{
	int cnt,ans,fir[N];
	struct edge{
		int to,nx;
	}eg[N<<1];

	inline void add(const int a,const int b){
		eg[++cnt]=(edge){b,fir[a]};
		fir[a]=cnt;
	}

	inline int dfs(const int x,const int fa){
		int cand=0,cor=0;
		for(int i=fir[x]; i; i=eg[i].nx){
			const int y=eg[i].to;
			if(y!=fa){
				int tmp=dfs(y,x);
				cand|=cor&tmp;
				cor|=tmp;
			}
		}
		int ans=-1;
		for(int i=0; i<30; ++i){
			if(!(cand>>i)&&!(cor>>i&1)){
				ans=i;
				break;
			}
		}
		int tmp=((1<<30)-1)^((1<<ans)-1);
		assert(~ans);
		return (cor&tmp)|1<<ans;
	}
}

int main(){
	n=nxi();
	for(int i=1; i<n; ++i){
		const int a=nxi(),b=nxi();
		G::add(a,b);
		G::add(b,a);
	}
	printf("%d\n",hbit(G::dfs(1,0)));
	return 0;
}

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

using namespace std;
//const int OO = 0x3f3f3f3f;
const long long OO = (long long) 1e18+7;
//const unsigned long long UOO = (long long) 10e18+7;
#define lp(i,a,n) for(long long i = a ; i < n ; ++i)
#define lpr(i,a,n) for(long long i = a ; i >= n ; --i)
#define rep(i,vec) for(ll i = 0 ; i < vec.size() ; ++i)
#define reprv(i,vec) for(ll i = vec.size()-1; i >=0 ; --i)
#define eps (1e-5)
#define pb(i) push_back(i)
#define EPS 1e-9
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define debug(x) cout<<(#x)<<": \""<<x<<"\""<<endl
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl

typedef vector<int> vi ;
typedef   long long ll;
typedef   unsigned long long ull;
typedef vector<ll> vll ;
typedef pair<int,int> pii ;
typedef vector< pair<int,int> >  vpii;
typedef vector<pair<long long,long long>> vpll;
typedef vector<vector<int> > vvi ;
typedef complex<double> point;
typedef pair<ll,ll> pll;

using namespace std;
ll  inv(ll a, ll b) {return 1 < a ? b - inv(b % a, a) * b / a : 1;}
ll  Pow(ll  B,ll  P){ll  R=1; while(P>0)  {if(P&1) R=(R*B);P/=2;B=(B*B);}return R;} //compute b^p
ll  GCD(ll  a,ll  b){ while(b){b ^= a ^=b ^= a %=b;}  return a;}
ll  LCM(ll  a,ll  b) { return (a / GCD(a,b)*b); }
ll  BigMod(ll  B,ll  P,ll  M){ ll  R=1; while(P>0)  {if(P&1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (ll )R;} //compute b^p%m
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//int i=uniform_int_distribution<int>(1,n)(rng);


int n1,n2;
string s1 ,s2;

int mem[3005][3005];


void dp1(int pos1, int pos2){
    if(pos1==n1||pos2==n2) return;
    int a = 0,b = 0,c = 0;
    a = mem[pos1+1][pos2];
    b = mem[pos1][pos2+1];
    if(s1[pos1]==s2[pos2]) c = mem[pos1+1][pos2+1] + 1;
    if(mem[pos1][pos2]==a) dp1(pos1+1,pos2);
    else if(mem[pos1][pos2]==b)dp1(pos1,pos2+1);
    else{
        cout << s1[pos1];
        dp1(pos1+1,pos2+1);
    }
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
//    cout.tie(0);
//#ifndef ONLINE_JUDGE
//   freopen( "output.txt" , "w" , stdout ) ;
//   freopen( "input.txt" , "r" , stdin ) ;
//#endif


    cin >> s1 >> s2;
    n1 = s1.size();
    n2 = s2.size();

    lpr(i,n1-1,0){
        lpr(j,n2-1,0){
            if(s1[i]==s2[j]){
                mem[i][j] = max(mem[i][j],mem[i+1][j+1]+1);
            }
            mem[i][j] = max(mem[i][j],mem[i+1][j]);
            mem[i][j] = max(mem[i][j],mem[i][j+1]);
        }

    }
    dp1(0,0);


    return 0;
}


Measured memory_bytes: 39016
#include <bits/stdc++.h>
#define mod 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll x;

    cin >> x;

    if(x==0) cout << "1" << endl;
    else cout << "0" << endl;

    return 0;
}

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

typedef long long ll;
const int N = 25010, K = 405, mo = 1e9 + 7;
int a[N], n, m, k;
ll dp[N][K], q[N][K], sum[N][K], q2[N][K];
ll pr[N], sf[N], ans;
ll power(ll a, ll b = mo - 2) {
	ll ans = 1;
	while (b) {
		if (b & 1)ans = ans * a % mo;
		a = a * a % mo;
		b >>= 1;
	}return ans;
}
ll dp0() {
	dp[1][1] = q[1][1] = k;
	if (m == 1)sum[1][1] = q2[1][1] = k;
	for (int i = 2; i <= n; i++) {
		for (int j = k - 1; j >= 1; j--) {
			dp[i][j] = (q[i - 1][j] + dp[i - 1][j - 1] * (k - j + 1)) % mo;
			q[i][j] = (q[i][j + 1] + dp[i][j]) % mo;
			sum[i][j] = (q2[i - 1][j] + sum[i - 1][j - 1] * (k - j + 1) + (j >= m ? dp[i][j] : 0)) % mo;
			q2[i][j] = (q2[i][j + 1] + sum[i][j]) % mo;
		}
	}
	return q2[n][1];
}
ll jc[N], ny[N];
ll ty2(ll pre, ll suf) {
	for (int i = 1; i <= n; i++)
		for (int j = 1; j < k && j <= i; j++) {
			if (j >= pre)pr[i - pre] = (pr[i - pre] + dp[i][j]) % mo;
			if (j >= suf)sf[i - suf] = (sf[i - suf] + dp[i][j]) % mo;
		}
	for (int i = 0; i <= n; i++)
		pr[i] = pr[i] * jc[k - pre] % mo * ny[k] % mo,
		sf[i] = sf[i] * jc[k - suf] % mo * ny[k] % mo;
	ll ans = 0;
	for (int i = 0; i <= n - m; i++)
		ans = (ans + pr[i] * sf[n - m - i]) % mo;
	return ans;
}
int la[N];

int main() {
	cin >> n >> k >> m;
	for (int i = 1; i <= m; i++)scanf("%d", &a[i]);
	int lim = 25000;
	jc[0] = 1;
	for (int i = 1; i <= lim; i++)jc[i] = jc[i - 1] * i % mo;
	ny[lim] = power(jc[lim]);
	for (int i = lim; i >= 1; i--)ny[i - 1] = ny[i] * i % mo;
	int las = 0, tag1 = 0, pre = 0, suf;
	for (int i = 1; i <= m; i++) {
		las = max(las, la[a[i]]);
		la[a[i]] = i;
		if (i - las >= k)tag1 = 1;
		if (!las)pre = i;
	}
	ans = power(k, n - m) * (n - m + 1) % mo;
	if (tag1) {
		cout << ans << endl;
		return 0;
	}
	ll z = dp0();
	if (!las) {
		z = z * jc[k - m] % mo * ny[k] % mo;
		cout << (ans - z + mo) % mo << endl;
		return 0;
	}
	reverse(a + 1, a + m + 1);
	memset(la, 0, sizeof la);
	las = 0;
	for (int i = 1; i <= m; i++) {
		las = max(las, la[a[i]]);
		la[a[i]] = i;
		if (!las)suf = i;
	}
	z = ty2(pre, suf);
	cout << (ans - z + mo) % mo << endl;

	return 0;
}


Measured memory_bytes: 317696
#include<iostream>

using namespace std;

int main() {
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 1; i <= N; i += 2) {
		int count = 0;
		for (int j = 1; j <= N; j += 2) {
			if (i%j == 0) {
				count++;
			}
		}
		if (count == 8) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// AOJ 2978 Undo Swapping
// 2019.9.24 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

char R[100005], C[100005];
int rel[100005];

int dfs(int r, int n) {
	int c = rel[r];
	if (c == 0) return n;
	rel[r] = 0;
	return dfs(c, n+1);
}

int main()
{
	int i, N, r, c, ans;
	
	N = in();
	i = N; while (i--) {
		r = in(), c = in();
		if (R[r]) { puts("-1"); return 0; }
		R[r] = 1;
		if (C[c]) { puts("-1"); return 0; }
		C[c] = 1;
		if (r != c) rel[r] = c;
	}
	ans = 0; for (r = 1; r <= N; r++) if (rel[r]) ans += dfs(r, 0)-1;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2308
/* ex9_2
  terakura */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 100000

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    char cube[SIZE];
    int count = 0;
    //最初のノードの指す先
    node *first = NULL;
    scanf("%s", cube);

    for(int i=0; i<strlen(cube); i++){

        //最初のキューブまたは前と同じいろ
        if(first == NULL || cube[i] == first->elem){
            //スタックにノードを追加
            push(&first, cube[i]);
        }
        //一つ前と色が異なる
        else{
            //スタックからデータを取り出す
            pop(&first);
            count += 2;
        }
    }

    printf("%d\n", count);


    return 0;
}


Measured memory_bytes: 4860
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
#include<queue>
#include<map>

using namespace std;
int s[1000000];
int n;


int main(){
    int ans = 0;
    cin >> n;
    int q;
    for(int i=0;i<n;i++) cin >> s[i];

    cin >> q;
    int t;
    for(int i=0;i<q;i++){
        cin >> t;
        if(*lower_bound(s, s+n, t) == t) ans++;
    } 
    
    cout << ans << endl;
}






Measured memory_bytes: 3452
#include <cstdio>

char S[100010];

int main(){
  scanf("%s", S);

  int GC = 0, PC = 0;
  for(int i = 0; S[i]; i++){
    if(S[i] == 'g') GC++;
    if(S[i] == 'p') PC++;
  }

  printf("%d\n", (GC - PC) / 2);
  return 0;
}

Measured memory_bytes: 256
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int sum = 0;
  REP(i, n) {
    if(i < k)
      sum += x;
    else
      sum += y;
  }
  cout << sum;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class AtCoder{
	public static void Main(){
	    
	    Tree tree = new Tree();
	    Console.WriteLine(tree.Calc(1));
	}

	public static void DebugWL(object x){ System.Diagnostics.Debug.WriteLine(x); }
}

class Tree{
    
    int n;
    int[] a;
    List<int>[] list;
    List<int>[] m;
    
    public Tree() {
        n = int.Parse(Console.ReadLine());
	    a = new int[n+1];
	    for(int i=2; i<=n; i++){
	        a[i] = int.Parse(Console.ReadLine());
	    }
	    
	    list = new List<int>[n+1];
	    m = new List<int>[n+1];
	    for(int i=1; i<=n; i++){
	        list[i] = new List<int>();
	        m[i] = new List<int>();
	    }
	    for(int i=2; i<=n; i++){
	        list[a[i]].Add(i);
	    }
    }
    
    public int Calc(int x){
        int c = 0;
        int max = -1;
        foreach(int i in list[x]){
            m[x].Add(Calc(i));
            c++;
        }
        m[x].Sort();
        for(int i=0; i<c; i++){
            m[x][i] += c - 1 - i;
            if(m[x][i]>max) max = m[x][i];
        }
        if(c==0) return 0;
        else return max + 1;
    }
}


Measured memory_bytes: 50784
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m; i <= n; i++)
using namespace std;

int main(){
    int n, x;
    while (true) {
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        int cnt = 0;
        FOR(i, 1, n) FOR(j, i+1, n) FOR(k, j+1, n){
            if (i+j+k == x) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3048
# N = int(input())
#
# ans = []
# for i in range(N):
#     A = int(input())
#     for j in range(A):
#         ans.append(list(map(int, input().split())))
#
# print(ans)

# print(bin(1 << 15))
# print(1 << 15)
# print(2**15)
n= int(input())
shogens = []
for i in range(n):
    a = int(input())
    shogens.append([])
    for j in range(a):
        x, y = map(int, input().split())
        x -= 1
        shogens[i].append((x, y))
# print(shogens)

# def is_honest(i, j):
#     return (i >> j) % 2 == 1
#
# def honest_cnt(i):
#     ans = 0
#     for j in range(n):
#         ans += is_honest(i, j)
#     return ans
# ans = 0
#
# for i in range(1 << n):
#     ok = True
#     print(bin(i))
#     for j in range(n):
#         if not is_honest(i, j):continue
#         for (x, y) in shogens[j]:
#             if y == 0 and is_honest(i, x):ok = False
#             if y == 1 and not is_honest(i, x):ok = False
#
#     if ok:
#         ans = max(ans, honest_cnt(i))
#
# print("ans", ans)

lists = {i : 0 for i in range(1 << 15)}
for i in range(1 << 15):
    count = 0
    for j in range(n):
        if (i >> j) & 1:
            for x, y in shogens[j]:
                if y == 0 and (i >> x) & 1: count -= 1
                if y == 1 and not (i >> x) & 1: count -= 1
    if count == 0:
        ans = 0
        for k in range(n):
            ans += (i >> k) % 2
        lists[i] = ans

print(max(lists.values()))
# print(0 >> 0)





Measured memory_bytes: 6132
import Control.Monad
import Data.List
import qualified Data.Map as M

main :: IO ()
main = do
  d <- readLn

  when (d /= 0) $ do
    vs <- replicateM (d+3) readLn
    print $ head $ filter (outlier d $ M.fromList $ zip [0..] vs) [0..d+2]
    main
  
lerp :: M.Map Int Double -> Int -> Double
lerp vs x = sum $ zipWith (*) (map (\i -> mkCoef i (fromIntegral x) / mkCoef i (fromIntegral i)) $ M.keys vs) $ M.elems vs
  where
    mkCoef :: Int -> Double -> Double
    mkCoef i y = product $ map ((y-) . fromIntegral) $ delete i $ M.keys vs

deleteIds :: [Int] -> [a] -> [a]
deleteIds ids xs = map snd $ filter ((\i -> all (/=i) ids) . fst) $ zip [0..] xs

outlier :: Int -> M.Map Int Double -> Int -> Bool
outlier d vs e = all f $ delete e [0..d+2]
  where
    f i = abs (lerp xs i - vs M.! i) < 0.1
      where
        xs = M.fromList $ map (\idx -> (idx, vs M.! idx)) $ deleteIds [i,e] [0..d+2]

Measured memory_bytes: 4304
import sys
K = int(input())

listup = []
listup.append(list(range(1, 10)))
list_length = 9
if K <= 9:
    print(listup[0][K - 1])
    sys.exit(0)
for i in range(10000000):
    new_list_floor = []
    for value in listup[i]:
        newlist = []
        mod_value = value % 10
        if mod_value == 0:
            newlist.append(value * 10 + mod_value)
            newlist.append(value * 10 + mod_value + 1)
        elif mod_value == 9:
            newlist.append(value * 10 + mod_value - 1)
            newlist.append(value * 10 + mod_value)
        else:
            newlist.append(value * 10 + mod_value - 1)
            newlist.append(value * 10 + mod_value)
            newlist.append(value * 10 + mod_value + 1)
        list_length_before = list_length
        list_length += len(newlist)
        new_list_floor.extend(newlist)
        if list_length >= K:
            diff = K - list_length_before
            print(newlist[diff - 1])
            sys.exit(0)
    listup.append(new_list_floor)
print(listup)

Measured memory_bytes: 7204
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

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

//START OF CODE ->->->->->->->

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

    vector<int> a(n);

    rep(i,0,a.size())
    {
        cin>>a[i];
    }
    vector<int> b = a;
    sort(all(a));
    int cnt = 0;
    rep(i,0,a.size())
    {
        if ( b[i] != a[i] )
        {
            cnt++;
        }
    }

    if ( cnt <= 2 )
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



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

int main() {

	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	rep(i, 0, tx - sx) cout << 'R';
	rep(i, 0, ty - sy) cout << 'U';
	rep(i, 0, tx - sx) cout << 'L';
	rep(i, 0, ty - sy + 1) cout << 'D';

	rep(i, 0, tx - sx + 1) cout << 'R';
	rep(i, 0, ty - sy + 1) cout << 'U';
	cout << 'L' << 'U';
	rep(i, 0, tx - sx + 1) cout << 'L';
	rep(i, 0, ty - sy + 1) cout << 'D';
	cout << 'R' << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
const int inf = 1e7;
int dp[44][444][444];
int main()
{
  int N, ma, mb;
  cin >> N >> ma >> mb;
  int a[N],b[N],c[N];
  FOR(i,0,N)
  {
    cin>>a[i]>>b[i]>>c[i];
  }
  FOR(i,0,44) FOR(j,0,444) FOR(k,0,444) dp[i][j][k] = inf;
  dp[0][0][0] = 0;
  FOR(i,0,N)
  {
    FOR(j,0,444)
    {
      FOR(k,0,444)
      {
        if(dp[i][j][k]==inf) continue;
        dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
        if(j+a[i]>400||k+b[i]>400) continue;
        dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
      }
    }
  }
  int ans = inf;
  FOR(i,1,401)
  {
    FOR(j,1,401)
    {
      if(i*mb==j*ma)
      {
        ans = min(ans, dp[N][i][j]);
      }
    }
  }
  if(ans==inf) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 34176
from collections import deque
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())


H, W = MI()
N = II()
a = LI()
color = deque()
ans = [[0] * W for _ in range(H)]
# visited = [[0] * W for _ in range(H)]
# x_diff = [-1, 0, 1, 0]
# y_diff = [0, 1, 0, -1]

for i, num in enumerate(a):
    for j in range(num):
        color.append(i + 1)

# coordinate_q = deque()
# coordinate_q.append([0, 0])
# visited[0][0] = 1
# ans[0][0] = color.popleft()

"""
while len(coordinate_q) != 0:
    y_tmp, x_tmp = coordinate_q.popleft()
    for i in range(4):
        y, x = y_tmp + y_diff[i], x_tmp + x_diff[i]
        if 0 <= y <= H-1 and 0 <= x <= W-1 and visited[y][x] == 0:
            ans[y][x] = color.popleft()
            visited[y][x] = 1
            coordinate_q.append([y, x])
"""

for i in range(H):
    for j in range(W):
        if i % 2 == 0:
            ans[i][j] = color.popleft()
        else:
            ans[i][-(j+1)] = color.popleft()

for i in range(H):
    for j in range(W):
        print(ans[i][j], end=' ')
    print('')


Measured memory_bytes: 45288
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lld long double
#define pii pair<int,int>
#define MOD 1000000007
void solve(){
    ll n,x,y; cin>>n;
    ll cnt = 0;
    for(ll i = 0; i<n; i++){
        cin>>x>>y;
        if(x==y) cnt++;
        else if(cnt<3) cnt = 0;
        else break;
    }
    // cout<<cnt<<endl;
    if(cnt>=3) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
int main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1; 
    // cin>>t;
    while(t-->0){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
N,M=map(int,input().split())
H=list(map(int,input().split()))
good=[1]*N
for i in range(M):
    A,B=map(int,input().split())
    A=A-1
    B=B-1
    if H[A]>=H[B]:
        good[B]=0
    if H[B]>=H[A]:
        good[A]=0
print(sum(good))

    




Measured memory_bytes: 20056
let () = Scanf.scanf "%d\n" @@ fun n ->
  let ws = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun w -> w in
  let acc = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    acc.(i + 1) <- acc.(i) + ws.(i)
  done;
  Printf.printf "%d\n" @@
  Array.fold_left min max_int @@
  Array.init n @@ fun i -> abs (acc.(n) - 2 * acc.(i))

Measured memory_bytes: 384
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n,m;cin>>n>>m;
    vector<string> a(n),b(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];

    for(ll i=0;i+m-1<n;++i){
        for(ll j=0;j+m-1<n;++j){
            bool ok=true;
            rep(k,m)rep(l,m){
                ok&=a[i+k][j+l]==b[k][l];
            }
            if(ok){
                cout<<"Yes"<<endl;
                return;
            }
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T, class U> inline void chmax(T &a, const U &b) { if ((a) < (b)) (a) = (b); }
template <class T, class U> inline void chmin(T &a, const U &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#include <atcoder/dsu>
using namespace atcoder;

int solve() {
    int n, q;
    scanf("%d %d", &n, &q);
    dsu d(n);
    for (int i = 0; i < q; i++) {
        int t, u, v;
        scanf("%d %d %d", &t, &u, &v);
        if (t) {
            puts(d.same(u, v) ? "1" : "0");
        } else {
            d.merge(u, v);
        }
    }
    return 0;
}

int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/



Measured memory_bytes: 4076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll sum[200005],cnt=1,cnt1=0,ans1=0,all=0,max1=0;
int main()
{
  ll n,k;
  scanf("%lld %lld",&n,&k);
  for(ll i=0;i<n;i++){
    scanf("%lld",&sum[i]);
    if(cnt<k){
        all+=sum[i];
        cnt++;
    }
    else{
        if(cnt==k){
            all+=sum[i];
            max1=all;
            cnt++;
        }
        else{
            all-=sum[cnt1++];
            //printf("~%lld\n",all);
            all+=sum[i];
            if(all>max1){
                max1=all;
                ans1=cnt1;
            }
        }
    }
    //printf("%lld\n",all);
  }
  //printf("%lld\n",ans1);
  double ans=0;
  for(ll i=ans1;i<ans1+k;i++){
    ans+=(1.0+sum[i]*1.0)/2.0;
  }
  printf("%.12f\n",ans);

}


Measured memory_bytes: 1792