akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#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; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    if( D == 25 ) cout << "Christmas" << endl;
    else if( D == 24 ) cout << "Christmas Eve" << endl;
    else if( D == 23 ) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;

}


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

ll gcd(ll a,ll b){
	if(b==0)return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow!=0){
        if(pow&1==1){ans = ans*base;}
        base *= base;pow/=2;}return ans;
}
ll inv(ll x){return expo(x,mod-2);}

ll nCr[5010][5010], fact[5001];

void pre(){
     for(int i = 0; i <= 5000; i++){
         nCr[i][i] = 1LL;
         nCr[i][0] = 1LL;
     }
     for(int i = 2; i <= 5000; i++){
         for(int j = 1; j < i; j++){
             nCr[i][j] = (nCr[i-1][j-1]+nCr[i-1][j])%mod;
         }
     }

     fact[0] = 1;
     for(int i = 1; i <= 5000; i++) fact[i] = (1LL*fact[i-1]*i)%mod;
}

int cmp(pair <pair<ll,ll>, ll> p1, pair <pair<ll,ll>, ll> p2){
    int dif1 = abs(p1.first.first-p1.first.second);
    int dif2 = abs(p2.first.first-p2.first.second);
    return dif1 < dif2;
}

int ok(long double x1, long double y1){
    if(abs(x1-y1) < 1e-5) return 1;
    return 0;
}


int main(){
    //freopen("ip.txt", "rt", stdin);
    //freopen("op.txt", "wt", stdout);
    map <int,int> mp;
    int n, m;
    cin >> n;
    for(int i = 0; i < n; i++){
        int n1;
        cin >> n1;
        mp[n1]++;
    }
    cin >> m;
    int cond = 1;
    while(m--){
          int n1;
          cin >> n1;
          if(mp[n1] > 0) mp[n1]--;
          else{
               cond = 0;
          }
    }
    if(cond)
    cout << "YES";
    else
    cout << "NO";
               return 0;
}


Measured memory_bytes: 9600
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

template <typename T>
class FenwickTree
{
    int n;
    std::vector<T> bit;

  public:
    FenwickTree(int _n) : n(_n), bit(_n, 0) {}

    void add(int pos, const T &w)
    {
        assert(0 <= pos && pos < n);
        for (int i = pos; i < n; i |= i + 1)
            bit[i] += w;
    }
    // v[0] + ... + v[pos-1]
    T sum(int pos)
    {
        assert(0 <= pos && pos <= n);
        T res = 0;
        for (int i = pos - 1; i >= 0; i = (i & (i + 1)) - 1)
        {
            res += bit[i];
        }
        return res;
    }
    T sum(int l, int r)
    {
        assert(0 <= l && l <= r && r <= n);
        return sum(r) + (-sum(l));
    }
};

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

    int n, k;
    while (cin >> n >> k, n || k)
    {
        FenwickTree<int> ft(100010);
        set<int> used;
        bool zero = false;
        while (k--)
        {
            int a;
            cin >> a;
            if (a == 0)
            {
                zero = true;
                continue;
            }
            if (used.find(a) != used.end())
                continue;
            ft.add(a, 1);
            used.insert(a);
        }
        int lb = 0, ub = n + 1;
        while (ub - lb > 1)
        {
            int mid = (lb + ub) / 2;
            bool f = false;
            for (int i = 1; i <= n + 1 - mid; i++)
            {
                if (zero)
                {
                    if (ft.sum(i, i + mid) >= mid - 1)
                        f = true;
                }
                else
                {
                    if (ft.sum(i, i + mid) >= mid)
                        f = true;
                }
            }
            if (f)
                lb = mid;
            else
                ub = mid;
        }
        cout << lb << endl;
    }
}


Measured memory_bytes: 6860
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n;
	string s;
	cin >> n >> s;
	vector<ll> a(n);
	vector<ll> b(n);
	
	ll l=0,r=0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'W'){
			l++;
		}
		if(s[n - i - 1] == 'E'){
			r++;
		}
		a[i] = l;
		b[n - i - 1] = r;

	}	
	ll ans = LINF;
	for(int i = 0; i < n; i++) {
		ans = min(ans,a[i] + b[i] - 1);
		// cout << a[i] << b[i] << endl;
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main()
{
    int A, B, T;
    cin >> A >> B >> T;
    T = 2 * T + 1;
    A *= 2;
    cout << B * (T / A) << endl;
    return 0;
}


Measured memory_bytes: 888
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder
{
    class Program
    {
        //メイン関数
        static void Main(string[] args)
        {
            int N = ReadI();
            string[] A = Read().Split(' ').ToArray();
            float denominator = 0;

            for (int i = 0; i < N; i++)
            {
                denominator = denominator + 1.0f / int.Parse(A[i]);
            }

            Write(1 / denominator);
        }

        //メインじゃない関数
        private static string Read() { return ReadLine(); }
        private static int ReadI() { return int.Parse(ReadLine()); }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()	
{
	int n,a;
	vector<int>v;
	map<int,int>m;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		m[a]++;
		m[a+1]++;
		m[a-1]++;
	}
	for (auto i=m.begin();i!=m.end();i++) 
	{
		v.push_back(i->second);
	}
	sort(v.begin(),v.end());
	cout<<v[v.size()-1]<<endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<double>x(N);
  vector<string>u(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> u.at(i);
  }
  double ans = 0;
  for (int i = 0; i < N; i++) {
    if (u.at(i) == "JPY") {
      ans += x.at(i);
    }
    else {
      ans += x.at(i) * 380000.0;
    }
  }
  cout << ans;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
#define p printf
#define s scanf
#define REP(i, a, b) for(int i = 1; i<=n; i++)
int main()
{
	int n; cin >> n;
	long long int sum = 0;
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 != 0 && (i % 5 != 0))
		{
			sum = sum + i;
		}
	}
	cout << sum << "\n";
}


Measured memory_bytes: 3596
A = list(input())
B = list(input())
C = list(input())
esult = ""


def pop_card(s):
    global result
    if s == "a":
        if (A):
            pop_card(A.pop(0))
        else:
            result = "A"
    elif s == "b":
        if (B):
            pop_card(B.pop(0))
        else:
            result = "B"

    elif s == "c":
        if (C):
            pop_card(C.pop(0))
        else:
            result = "C"


pop_card("a")
print(result)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S;
    cin >> S;

    int N = S.length();

    if (N < 4){
        cout << "No" << endl;
    }
    else if (S.substr(0, 4) == "YAKI"){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
(defun read-list-from-string (str)
  (read-from-string (concatenate 'string "(" str ")")))

(defun read-list ()
  (read-list-from-string (read-line)))

(defun init-array (n)
  (make-array (1+ n) :initial-element 0))

(defun count-load (m arr)
  (dotimes (num m arr)
    (let ((list (read-list)))
      (incf (aref arr (car list)))
      (incf (aref arr (cadr list))))))

(defun print-arr (arr)
  (dotimes (n (1- (length arr)))
    (princ (aref arr (1+ n)))
    (fresh-line)))

(defun solve ()
  (let* ((list (read-list))
	 (arr (init-array (car list))))
    (print-arr (count-load (cadr list) arr))))

(solve)

Measured memory_bytes: 15844
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {
    int X;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>X;
    int a = 1000*(X/500);
    int b = 5*((X%500)/5);
    int c = a+b;
    cout<<c<<endl;
    return 0;
}



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

#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	ll x, y;
	cin >> x >> y;

	ll cnt = 0;
	for (ll i = x; i <= y; i=i*2) {
		cnt++;
	}
	cout << cnt << endl;

	return 0;
}

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

int main()
{
    int n;
    int alice=0, bob=0;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n,greater<int>());


    for(int i=0;i<n;i+=2)
    {
        alice=alice+arr[i];
        if((i+1)<n)
        {
        bob=bob+arr[i+1];

        }
    }



    cout<<alice-bob;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //Prime FACTORIZE!
//1e18 = 5^18*2^18 (Simply consider 5s since all factors are even anyway)
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		long N = input.nextLong();
		if (N%2==1) System.out.println(0);
		else {
			long cnt = 0;
			long div = 5;
			cnt+=N/div/2;
			while (div<N) {
				div*=5;
				cnt+=(N/div)/2; //Odd multiples of 5 are excluded
			}
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 21972
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
  char s;
  
  for(int i = 0; i<n; i++){
      cin>>s;
      if(s == 'Y'){
          cout<<"Four"<<endl;
          return 0;
      }
  }
  
  cout<<"Three"<<endl;
  return 0;
}

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

int main(void) {
  int length = 200020;
  char a[length];
  char b[length];

  scanf("%s", a);
  scanf("%s", b);

  int ans = 0;
  for (int i = 0; i < strlen(a); i++) {
    if (a[i] != b[i]) {
      ans++;
    }
  }

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

  return 0;
}

Measured memory_bytes: 2104
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    string s;
    string q = "yuiophjklnm";
    while(cin >> s){
        if(s == "#")return 0;
        int ans = 0;
        bool now = !!count(q.begin(),q.end(), s.front());
        for(char c : s){
            if(now != !!count(q.begin(),q.end(),c)){
                now = !!count(q.begin(),q.end(),c);
                ans++;
            }
        }
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 3076
n = int(input())
a = list(map(int, input().split()))
q = int(input())
ans = sum(a)

l = [0] * 100001

for i in a:
  l[i] += 1
  
for j in range(q):
  b, c = map(int,input().split())
  l[c] += l[b]
  ans += l[b] * (c-b)
  l[b] = 0
  print(ans)


Measured memory_bytes: 20904
n,k=map(int,input().split())
p=list(map(int,input().split()))
data=[0]*n
for i in range(n):
  data[i]=p[i]/2+float(0.5)
res=sum(data[0:k])
ans=sum(data[0:k])
for i in range(n-k):
  res-=data[i]-data[i+k]
  ans=max(ans,res)
print(ans)

Measured memory_bytes: 32148
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int[] col = new int[9];
        for (int i = 0; i < n; i++) {
            int an = sc.nextInt();
            int r = Math.min(an / 400, 8);
            col[r] += 1;
        }

        int mi = 0;
        for (int i = 0; i < 8; i++) {
            if (col[i] > 0) {
                mi += 1;
            }
        }
        int ma = mi;
        if (col[8] == 0) {
            System.out.println(mi + " " + ma);
            System.exit(0);
        }

        if (mi == 0) {
            mi = 1;
        }
        ma += col[8];
        System.out.println(mi + " " + ma);
    }

}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int S[100005];

int main()
{
    int N, M;
    cin >> N >> M;
    REP(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        S[a]++;
        S[b]++;
    }

    string ans = "YES";
    REP(i, N)
    {
        if (S[i] % 2 == 1)
            ans = "NO";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        ++$this->pointer;

        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int) $this->next();
    }

    public function nextDouble()
    {
        return (float) $this->next();
    }
}

$sc = new Scanner();
$n = $sc->nextInt();
$limit = $sc->nextInt();
$current_min = 10000;

for($i=0;$i<$n;$i++){
    $c = $sc->nextInt();
    $t = $sc->nextInt();
    if($t <= $limit){
        if($c < $current_min){
            $current_min = $c;
        }
    }
}

if($current_min == 10000){
    $current_min = "TLE";
}

echo $current_min.PHP_EOL;

Measured memory_bytes: 16232
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int N, M;
vector<vector<int>> t;
vector<vector<int>> p;
vector<string> ans;
string id(int p, int num){
    string tmp1 = to_string(p);
    string tmp2 = to_string(num);
    while(tmp1.size()<6)tmp1='0'+tmp1;
    while(tmp2.size()<6)tmp2='0'+tmp2;
    return tmp1+tmp2;
}
int main() {
    cin >> N >> M;
    t.resize(M);
    p.resize(N);
    ans.resize(M);
    for (int i = 0; i < M; i++)
    {
        t[i].resize(3);
        cin >> t[i][1] >> t[i][0];
        t[i][2] = i;
    }
    sort(t.begin(), t.end());
    for(auto m : t){
        p[m[1]-1].push_back(m[2]);
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < p[i].size(); j++)
        {
            ans[p[i][j]]=id(i+1, j+1);
        }
    }
    
    for (int i = 0; i < M; i++)
    {
        cout << ans[i] << endl;
    }
    

}

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

using namespace std;

int main() {
  int64_t N, M, K;
  cin >> N >> M >> K;
  vector<int64_t> A(N), B(M);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < M; i++) cin >> B[i];

  vector<int64_t> TA(N + 1, 0), TB(M + 1, 0);
  for (int i = 0; i < N; i++) {
    TA[i + 1] = TA[i] + A[i];
  }
  for (int i = 0; i < M; i++) {
    TB[i + 1] = TB[i] + B[i];
  }

  int64_t ib = M;
  int64_t answer = 0;
  for (int ia = 0; ia <= N; ia++) {
    int64_t T = TA[ia];
    int64_t remain = K - T;
    if (remain < 0) break;
    while (ib >= 0 && TB[ib] > remain) ib--;

    if (ib < 0) break;
    answer = max(answer, ia + ib);
  }
  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 9592
#include <stdio.h>
#define N 1000000
#define MOD 1000000007
typedef long long ll;

ll fac[N], finv[N], inv[N];

void cminit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

ll cmb(int n, int k) {
	if (n < k)
		return 0;
	if (n < 0 || k < 0)
		return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void) {
	int x, y;
	scanf("%d%d", &x, &y);

	if ((x + y) % 3 != 0) {
		printf("0\n");
		return 0;
	}

	int m = x - (x + y) / 3;
	int n = y - (x + y) / 3;
	if (n < 0 || m < 0) {
		printf("0\n");
		return 0;
	}

	cminit();

	printf("%lld\n", cmb(n + m, n));
	return 0;
}

Measured memory_bytes: 23552
using System;
class Program
{
    static void Main(string[] args)
    {
        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int c = int.Parse(input[2]);

        int max = 0;
        int min = 0;
        int z = 0;

        if (b >= c)
        {
            max = c;
            min = c - a + b;
        }
        else
        {
            max = b;
            min = b - a + c;
        }

        if (min < 0)
        {
            min = 0;
        }


        //出力
        Console.WriteLine(max + " " + min);
        //string s = Console.ReadLine();
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007

using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll N; cin >> N;
	vector<ll> a(3*N);
	for (int i = 0; i < 3*N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ans += a[3*N - 2 - 2 * i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(int argc, char *argv[])
{
	int H, W;
	while (1)
	{
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0){
			break;
		}
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 2100
// doot diddly donger cuckerino Hahahahahah


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vi = vector<int>;

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

const ld PI = acos(-1);

template <typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template <typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T, typename U>
std::ostream& operator<<(std::ostream& stream, const pair<T, U>& p) {
  return stream << p.first << " " << p.second;
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const vector<T>& vec) {
  for (const T& x: vec) out << x << ' ';
  return out;
}
template <typename T>
std::istream& operator>>(std::istream& in, vector<T>& vec) {
  for(auto& x: vec) in >> x;
  return in;
}
// @formatter:on


class ARepeatACL {
public:
  
  void solve(std::istream& cin, std::ostream& cout) {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
      cout << "ACL";
    }
  }
};

int32_t main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
	ARepeatACL solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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


int main(){
    char in[2];
    scanf("%s",in);
    in[0]++;
    printf("%s",in);
    return 0;
}

Measured memory_bytes: 3708
def isOK(mid,N,K,sort_F,sort_A):
    cnt = 0
    for i in range(N):
        cnt += max(sort_A[i] - (mid // sort_F[i]),0)
    return cnt <= K

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))
    sort_A = sorted(A)
    sort_F = sorted(F, reverse=True)

    ng = -1
    ok = 10 ** 12 + 5
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if isOK(mid,N,K,sort_F,sort_A):
            ok = mid
        else:
            ng = mid

    print(ok)



if __name__ == "__main__":
    main()

Measured memory_bytes: 121036
#include<iostream>
#include<queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n, G[100][100];
int d[100];

void bfs(int s){
  queue<int> q;
  q.push(s);
  for(int i = 0;i < n;i++) d[i] = INFTY;
  d[s] = 0;
  int u;
  while(!q.empty()){
    u = q.front(); q.pop();
    for(int v = 0;v < n;v++){
      if(G[u][v] == 0) continue;
      if(d[v] != INFTY) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  for(int i = 0;i < n;i++){
    cout << i+1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
  }
}

int main(){
  int u, k, v;

  cin >> n;
  for(int i =0;i < n;i++){
    for(int j = 0;j < n;j++){
      G[i][j] = 0;
    }
  }

  for(int i = 0;i < n;i++){
    cin >> u >> k;
    u--;
    for(int j = 0;j < k;j++){
      cin >> v;
      v--;
      G[u][v] = 1;
    }
  }

  bfs(0);

  return 0;
}

Measured memory_bytes: 3124
import java.io.{BufferedReader, InputStreamReader}

import scala.collection.mutable.ListBuffer

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val Array(n, m) = in.readLine().split("\\s+").map(_.toInt)

    val rooms = new Array[ListBuffer[Int]](n)
    for {
      i <- rooms.indices
    } {
      rooms(i) = new ListBuffer[Int]
    }

    (1 to m).foreach { _ =>
      in.readLine().split("\\s+").map(_.toInt) match {
        case Array(s, t) => rooms(s - 1) += t - 1
      }
    }

    val exps = new Array[Double](n)

    def expectation(aoki: Int): Double = {
      exps(n - 1) = 0.0
      for {
        i <- n - 2 to 0 by -1
      } {
        exps(i) = {
          var sum = 0.0
          var max = 0.0
          rooms(i).foreach { dest =>
            sum = sum + exps(dest)
            max = Math.max(max, exps(dest))
          }
          val size = rooms(i).length
          if (size == 1) {
            sum + 1.0
          } else if (i == aoki) {
            (sum - max) / (size - 1) + 1.0
          } else {
            sum / size + 1.0
          }
        }
      }
      exps(0)
    }

    var minE = Double.MaxValue
    rooms.indices.foreach { aoki =>
      minE = Math.min(minE, expectation(aoki))
    }

    System.out.println(f"$minE%2.10f")
  }
}

Measured memory_bytes: 111004
#define _GLIBCXX_DEBUG
#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;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;

static const int INF = 1<<29;
int N, A, B, C;
int l[8];
int dfs(int a, int b, int c, int i){
  int minv = INF;
  if (i == N) return ((a==0 || b==0 || c==0) ? INF : abs(a - A) + abs(b - B) + abs(c - C) - 30);
  minv = min(minv, dfs(a + l[i], b, c, i + 1) + 10);
  minv = min(minv, dfs(a, b + l[i], c, i + 1) + 10);
  minv = min(minv, dfs(a, b, c + l[i], i + 1) + 10);
  minv = min(minv, dfs(a, b, c, i + 1));
  return minv;
}

int main(){
  cin >> N >> A >> B >> C;
  rep(i, N)cin >> l[i];
  cout << dfs(0, 0, 0, 0) << endl;
}

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

int main() {
  int N,M;
  cin >> N;
  long long int T[N], sum=0;
  for(int i=0;i<N;i++){
    cin>>T[i];
    sum+=T[i];
  }
  cin >> M;
  for(int i=0;i<M;i++){
    int p,x;
    cin>>p>>x;
    cout<<sum+x-T[p-1]<<endl;
  }
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

total = sum(A)
count = 0
cut = 0
for num, a in enumerate(A):
    count += a
    if count >= total//2:
        cut = num
        break

left = sum(A[:cut+1])
right = sum(A[cut+1:])
ans1 = abs(left-right)

left -= A[cut]
right += A[cut]
ans2 = abs(left-right)

print(min(ans1, ans2))

Measured memory_bytes: 26220
#include<stdio.h>
main(){
  int day,mon,data;

  while(1){
    scanf("%d %d",&mon,&data);
    if(mon == 0){
      break;
    }

    if(mon==2) data += 31;
    if(mon==3) data += 60;
    if(mon==4) data += 91;
    if(mon==5) data += 121;
    if(mon==6) data += 152;
    if(mon==7) data += 182;
    if(mon==8) data += 213;
    if(mon==9) data += 244;
    if(mon==10) data += 274;
    if(mon==11) data += 305;
    if(mon==12) data += 335;

    day=data%7;

    if(day==1) printf("Thursday\n");
    if(day==2) printf("Friday\n");
    if(day==3) printf("Saturday\n");
    if(day==4) printf("Sunday\n");
    if(day==5) printf("Monday\n");
    if(day==6) printf("Tuesday\n");
    if(day==0) printf("Wednesday\n");
  }

  return 0;
}

Measured memory_bytes: 584
#include<stdio.h>
int main(){
	int n,w,x,y,z;
	scanf("%d%d",&w,&n);
	int a[31];
	for(int i=1;i<=w;i++)a[i]=i;
	for(int i=0;i<n;i++){
		scanf("%d,%d",&x,&y);
		z=a[x];a[x]=a[y];a[y]=z;}
	for(int i=1;i<=w;i++)printf("%d\n",a[i]);
	return 0;}


Measured memory_bytes: 2052
#include <iostream>

using namespace std;

int main(){

int A, B;
cin>>A>>B;

if(A*B>A+B && A*B>A-B){
   cout<<A*B;

}else if(A+B>A*B && A+B>A-B){
   cout<<A+B;

}else{
   cout<<A-B;
}

return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

int w, h, x, y, r;

scanf("%d %d %d %d %d", &w,&h,&x,&y,&r);

if(y-r < 0 || x-r < 0 || x+r > w || y+r > h)
printf("No\n");
else printf("Yes\n");

return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  int a;
  int ans=0;
  for(int i=0;i<n;i++){
    cin >> a;
    if(a%2==0) ans++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3108
#include <stdio.h>
#include <set>
#include <iterator>
using namespace std;
int main(){
    int n,temp,k;
    multiset<int> s;
    multiset<int>::iterator u;
    scanf("%d",&n);
    while(n--){
        scanf("%d%d",&k,&temp);
        if(k==0){
            s.insert(temp);
            printf("%ld\n",s.size());
        }
        else if(k==1)printf("%ld\n",s.count(temp));
        else if(k==2)s.erase(temp);
        else{
            u=s.lower_bound(temp);
            scanf("%d",&temp);
            while(u!=s.end()){
                if(*u>temp)break;
                printf("%d\n",*u);
                u++;
            }
        }
    }
}


Measured memory_bytes: 12072
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict

N,P=map(int, sys.stdin.readline().split())
S=sys.stdin.readline().strip()
S=S[::-1]

ans=0
if P in (2,5):
    len_S=len(S)
    for i,x in enumerate(S):
        x=int(x)
        if x%P==0:
            ans+=(len_S-i)
    print ans
else:
    L=[0] 
    val=0
    for i,x in enumerate(S):
        x=int(x)
        val+=pow(10,i,P)*x
        L.append(val%P)

    C=defaultdict(lambda: 0)    #mod2019の値の出現個数を記録
    for x in L:
        ans+=C[x]   #自分とmod2019の結果が同じ値となる出現個数をansに足す
        C[x]+=1     #自分のmod2019の値を出現個数に+1カウント
    print ans


Measured memory_bytes: 40860
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let  s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    ipt_1_1_d();
}

fn ipt_1_1_d(){
    input!{
        _s: usize
    }
    let s = _s % 60;
    let m = (_s / 60) % 60;
    let h = _s / 3600;
    println!("{}:{}:{}", h, m, s)
}


Measured memory_bytes: 5036
from heapq import *
from bisect import *

N=int(input())
L=list(map(int,input().split()))
h=[]
for i in range(N):
    heappush(h,L[i])
h2=[]
for i in range(N):
    heappush(h2,heappop(h))
s=0
for i in range(N):
    for j in range(N-1-i):
        bmc=h2[j+i+1]-h2[i]
        bpc=h2[j+i+1]+h2[i]
        a=-bisect_right(h2, bmc)+bisect_left(h2, bpc)-1
        if a>0:
            s+=a
            if bmc < h2[i]:
                s-=1
print(s//3)


Measured memory_bytes: 50908
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int a, b;
	cin >> a >> b;
	int m = a + b;
	m = max(m, a - b);
	m = max(m, a * b);
	cout << m << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
struct po{double x, y;};
 
void saiki(po p1,po p2,int dep){
  if(dep==0) return;
  po s,t,u;
  s.x=(2*p1.x+p2.x)/3;
  s.y=(2*p1.y+p2.y)/3;
  t.x=(p1.x+2*p2.x)/3;
  t.y=(p1.y+2*p2.y)/3;
  u.x=(t.x-s.x)/2-(t.y-s.y)*(sqrt(3.0)/2)+s.x;
  u.y=(t.x-s.x)*(sqrt(3.0)/2)+(t.y-s.y)/2.0+s.y;
 
  saiki(p1,s,dep-1);
  printf("%.8f %.8f\n",s.x,s.y);
  saiki(s,u,dep-1);
  printf("%.8f %.8f\n",u.x,u.y);
  saiki(u,t,dep-1);
  printf("%.8f %.8f\n",t.x,t.y);
  saiki(t,p2,dep-1);
}
 
int main(){
  int n;
  cin>>n;
  po a,b;
  a.x=0,a.y=0;
  printf("%.8f %.8f\n",a.x,a.y);
   
  b.x=100,b.y=0;
  saiki(a,b,n);
  printf("%.8f %.8f\n",b.x,b.y);
  return 0;
}

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

bool doublet[100];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        doublet[i] = false;
    }
    
    for (int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        if (a == b) {
            doublet[i] = true;
        }
    }
    
    bool res = false;
    for (int i = 0; i < n - 2; i++) {
        if (doublet[i] && doublet[i+1] && doublet[i+2]) {
            res = true;
            break;
        }
    }
    
    cout << (res ? "Yes" : "No");
    
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(void){
	int t,n;
	float a[100];
	scanf("%d",&n);
	for(t=0;t<n;t++){
		scanf("%f",&a[t]);
	}
	printf("1:");
	for(t=0;t<n;t++){
		if(a[t]<165){
			printf("*");
		}
	}
	printf("\n");
	printf("2:");
	for(t=0;t<n;t++){
		if((a[t]>=165)&&(a[t]<170)){
			printf("*");
		}
	}
	printf("\n");
	printf("3:");
	for(t=0;t<n;t++){
		if((a[t]>=170)&&(a[t]<175)){
			printf("*");
		}
	}
	printf("\n");
	printf("4:");
	for(t=0;t<n;t++){
		if((a[t]>=175)&&(a[t]<180)){
			printf("*");
		}
	}
	printf("\n");
	printf("5:");
	for(t=0;t<n;t++){
		if((a[t]>=180)&&(a[t]<185)){
			printf("*");
		}
	}
	printf("\n");
	printf("6:");
	for(t=0;t<n;t++){
		if(a[t]>=185){
			printf("*");
		}
	}
	printf("\n");

return 0;
}

Measured memory_bytes: 620
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<Integer> p = new ArrayList<>();
        List<Integer> y = new ArrayList<>();
        for(int i = 0 ; i < m; i++) {
            p.add(sc.nextInt());
            y.add(sc.nextInt());
        }
        Map<Integer,Map<Integer,Integer>> lookup = getLookupTable(p,y);
        for(int i = 0; i < m ;i++) {
            print(p.get(i),lookup.get(p.get(i)).get(y.get(i)));
        }
    }
    private static Map getLookupTable(List<Integer> p, List<Integer> y) {
        Map<Integer,List<Integer>> perfYear = new HashMap<>();
        for(int i = 0; i < p.size(); i++) {
            if(!perfYear.containsKey(p.get(i))) {
                perfYear.put(p.get(i),new ArrayList<Integer>());
            }
            perfYear.get(p.get(i)).add(y.get(i));
        }
        for(Map.Entry<Integer,List<Integer>> entry : perfYear.entrySet()) {
            Collections.sort(entry.getValue());
        }
        return getPerfYearIndexMap(perfYear);
    }
    private static Map<Integer,Map<Integer,Integer>> getPerfYearIndexMap(Map<Integer,List<Integer>> perfYear){
        Map<Integer,Map<Integer,Integer>> perfYearIndexMap = new HashMap<>();
        perfYear.forEach((K,V) -> {
            if(!perfYearIndexMap.containsKey(K)) {
                perfYearIndexMap.put(K, new HashMap<Integer,Integer>());
            }
            Map<Integer,Integer> yearIndex = perfYearIndexMap.get(K);
            int count = 1;
            for(Integer a : V) {
                yearIndex.put(a,count);
                count++;
            }
        });
        return perfYearIndexMap;
    }
    private static int countDigit(int n) {
        if(n == 0) return 0;
        return 1 + countDigit(n/10);
    }
    private static void print(int p, int y) {
        int pDig = countDigit(p);
        int yDig = countDigit(y);
        StringBuilder sb = new StringBuilder();
        int MAX_DIGIT = 6;
        while(pDig < MAX_DIGIT) {
            sb.append('0');
            pDig++;
        }
        sb.append(String.valueOf(p));
        while(yDig < MAX_DIGIT) {
            sb.append('0');
            yDig++;
        }
        sb.append(String.valueOf(y));
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 123876
H,W,K=map(int,input().split())
A=[input() for i in range(H)]
for i,l in enumerate(A):
    if 'S' in l:
        S=(K,i,l.index('S'))
from collections import deque
q=deque([S])
X=[(S[1],S[2])]
n=((0,1),(0,-1),(1,0),(-1,0))
v=[[0]*W for i in range(H)]
v[S[1]][S[2]]=1
while q:
    m,i,j=q.popleft()
    for x,y in n:
        if 0<=i+x<H and 0<=j+y<W:
            if v[i+x][j+y]:continue
            v[i+x][j+y]=1
            if A[i+x][j+y]=='.' and m>0:
                q.append((m-1,i+x,j+y))
                X.append((i+x,j+y))
print(min([min(0--i//K,0--(H-i-1)//K,0--j//K,0--(W-j-1)//K) for i,j in X])+1)

Measured memory_bytes: 121052
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 20160116
#define pb push_back
#define mp make_pair
using namespace std;
//orz mqy
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}
const int Maxn=45;
int dp[Maxn][Maxn*10][Maxn*10];
int a[Maxn],b[Maxn],c[Maxn];
int main(){
	int n,ma,mb;
	scanf("%d %d %d",&n,&ma,&mb);
	for (int i=1;i<=n;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
	}
	for (int i=0;i<Maxn;i++){
		for (int j=0;j<Maxn*10;j++){
			for (int k=0;k<Maxn*10;k++){
				dp[i][j][k]=1000000000;
			}
		}
	}
	dp[0][0][0]=0;
	for (int i=1;i<=n;i++){
		for (int j=0;j<Maxn*10;j++){
			for (int k=0;k<Maxn*10;k++){
				dp[i][j][k]=dp[i-1][j][k];
				if (j>=a[i] && k>=b[i]){
					dp[i][j][k]=min(dp[i][j][k],dp[i-1][j-a[i]][k-b[i]]+c[i]);
				}
			}
		}
	}
	int MIN=INF;
	for (int j=1;j<Maxn*10;j++){
		for (int k=1;k<Maxn*10;k++){
			if (j%ma==0 && k%mb==0 && j/ma==k/mb){
				MIN=min(MIN,dp[n][j][k]);
			}
		}
	}
	if (MIN==1e9){
		printf("-1\n");
	}
	else
	printf("%d\n",MIN);
}

Measured memory_bytes: 35840
from collections import deque

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

tree=[[] for i in range(n)]
for i in range(n-1):
 i,j=map(int,input().split())
 tree[i-1].append(j-1)
 tree[j-1].append(i-1)

t_cnt=[0 for i in range(n)]
for i in range(q):
 p,x=map(int,input().split())
 t_cnt[p-1]+=x

cnt=[-1]*n
cnt[0]=t_cnt[0]

seen=set([0])

dq=deque()
dq.append(0)

while dq:
 x=dq.popleft()
 for i in tree[x]:
#  if cnt[i]==-1:
#  if i in seen:
#   continue
#  else:
   if i not in seen:
    seen.add(i)
    dq.append(i)
    cnt[i]=cnt[x]+t_cnt[i]

print(*cnt)

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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int n,k;
char s[maxn];
vector<int > p;

int cmp(int a,int b) {
    for(;a&&b;a--,b--)
        if(s[a]>s[b]) return 0;
        else if(s[a]<s[b]) return 1;
    return 0;
}

int main() {
    read(n),read(k),scanf("%s",s+1);int t=1e9;
    for(int i=n+1;i<=2*n;i++) s[i]=s[2*n-i+1],t=min(t,(int)s[i]);
    // cout<<s+1<<endl;
    int mx=0,r=0;
    for(int i=1;i<=(n<<1)+1;i++)
        if(s[i]!=t&&s[i-1]==t) {
            if(r>mx) mx=r,p.clear(),i>n?p.pb(i-1):void();
            else if(r==mx) i>n?p.pb(i-1):void();r=0;
        } else if(s[i]==t) r++;
    // for(auto x:p) printf("%d ",x);puts("");
    t=p[0];
    for(int i=1;i<p.size();i++) if(cmp(p[i],t)) t=p[i];k--;
    // write(t);
    if(k>18) for(int i=1;i<=n;i++) putchar(s[t]);
    else {
        for(int i=1;i<=min(n,mx*(1<<k));i++) putchar(s[t]);
        for(int i=1;i<=max(0,n-mx*(1<<k));i++) putchar(s[t-mx+1-i]);
    }puts("");
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

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

    int zrm = 0;
    for (int i=0; i<N; i++){
        int di, dj;
        cin >> di >> dj;
        if (di == dj)zrm++;
        else zrm = 0;
        if (zrm >=3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("6 3");
            //9
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("6 4");
            //error
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
        int A = wkArr[0];
        int B = wkArr[1];

        int SumVal = A + B;
        if (SumVal >= 10)
            Console.WriteLine("error");
        else Console.WriteLine(SumVal);
    }
}


Measured memory_bytes: 13268
#include "stdio.h"

int main(){

	int i;
	char s,a[53] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

	while (s != '\n') {
		scanf("%c", &s);
		for (i = 0; i < 52; i++) 
			if (a[i] == s) {
				s = a[(i + 26) % 52];
				break;
			}	
		printf("%c", s);
	} 
	return 0;
}


Measured memory_bytes: 2148
#include <iostream>
using namespace std;
/** Problem0173 : Haunted House **/
int main()
{
	int c[9]={0}, num[9];
	string n[9];
	
	for (int i=0; i<9; i++) {
		int am, pm;
		cin >> n[i] >> am >> pm;
		c[i] = am*200 + pm*300;
		num[i] = am+pm;
	}
	
	for (int i=0; i<9; i++)
		cout <<n[i] << " " << num[i] << " " << c[i] << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define _end '\n'
#define Out(x) cout<<(x)<<_end
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c, d;

    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;

    Out(min(a, b) + min(c, d));

    return 0;
}


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

int arr[3005][3005];
vector<pair<int, int>> vec;
int n, t;
int KS(int index, int current_time) {
  if(current_time >= t || index >= n) return 0;
  if(arr[index][current_time]) return arr[index][current_time];
  int result = 0;
  result = max(result, KS(index+1,current_time));
  result = max(result, KS(index+1, current_time+vec[index].first)+vec[index].second);
  arr[index][current_time] = result;
  return result;

}


signed main() {
 cin >> n >> t;
  for(int i = 0; i < n;i++){
    int x, y;
    cin >> x >> y; vec.push_back(make_pair(x, y));
  }
  sort(vec.begin(), vec.end());
  KS(0,0);
  int result = 0;
  for(int i = 0; i < 3005; i++) {
    for(int j = 0; j < 3005; j++) {
      result = max(result, arr[i][j]);
    }
  }
  cout << result;


}


Measured memory_bytes: 69376
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import copy


def main():
    K, S = map(int, input().split())
    result = 0
    for x in range(K + 1):
        for y in range(K + 1):
            z = S - x - y
            if 0 > z or z > K:
                continue
            else:
                result += 1

    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3444
// Author: 23forever
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
typedef long long LL;
const int MAXN = 400;
const int P = 1e9 + 7;
using namespace std;

inline int read() {
  int x = 0; char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x;
}

int n, c, a[MAXN + 5], b[MAXN + 5];

void init() {
  n = read(), c = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i <= n; ++i) b[i] = read();
}

namespace subtask1 {

int dp[MAXN + 5][MAXN + 5], x[MAXN + 5][MAXN + 5];

bool isSubtask1() {
  for (int i = 1; i <= n; ++i) {
    if (a[i] != b[i]) return false;
  }
  return true;
}
void solve() {
  for (int i = 1; i <= n; ++i) {
    x[i][0] = 1;
    for (int j = 1; j <= c; ++j) {
      x[i][j] = 1LL * x[i][j - 1] * a[i] % P;
    }
  }

  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= c; ++j) {
      dp[i][j] = 1; 

      int sum = 0; 
      for (int k = 0; k <= j; ++k) {
        sum = (sum + 1LL * dp[i - 1][j - k] * x[i][k]) % P;
      }
      dp[i][j] = 1LL * dp[i][j] * sum % P;
    }
  }

  printf("%d\n", dp[n][c]);
}
}

namespace subtask2 {

int dp[MAXN + 5][MAXN + 5], x[MAXN + 5][MAXN + 5];
int pre[MAXN + 5][MAXN + 5];

int qpow(int b, int m) {
  int ret = 1;
  while (m) {
    if (m & 1) ret = 1LL * ret * b % P;
    b = 1LL * b * b % P;
    m >>= 1;
  }
  return ret;
}

void solve() {
  for (int i = 1; i <= MAXN; ++i) {
    for (int j = 0; j <= c; ++j) {
      pre[i][j] = qpow(i, j) % P;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= c; ++j) {
      for (int k = a[i]; k <= b[i]; ++k) {
        x[i][j] = (x[i][j] + pre[k][j]) % P;
      }
    }
  }

  //1 ^ 2 + 2 ^ 2 + 3 ^ 2

  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= c; ++j) {
      dp[i][j] = 1; 

      int sum = 0; 
      for (int k = 0; k <= j; ++k) {
        sum = (sum + 1LL * dp[i - 1][j - k] * x[i][k]) % P;
      }
      dp[i][j] = 1LL * dp[i][j] * sum % P;
    }
  }

  printf("%d\n", dp[n][c]);
}
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#endif
  init();

  if (subtask1::isSubtask1()) {
    subtask1::solve();
  } else {
    subtask2::solve();
  }
#ifdef forever23
  printf("Running Time = %d ms\n", int(clock() * 1000.0 / CLOCKS_PER_SEC));
#endif
  return 0;
}

Measured memory_bytes: 2176