akhauriyash/Code-Regression huggingface dataset:
#include <math.h>

#include <cmath>
#include <iostream>
using namespace std;
int main() {
    int a,keta1,keta2,keta3;
    cin >> a;
    keta1 = a - (a / 10 * 10);
    keta2 = ((a - (a / 100 * 100) - keta1) / 10);
    keta3 = a / 100;
    if(keta1==7||keta2==7||keta3==7){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3560
from heapq import heappop, heappush
n, m, *AB = map(int, open(0).read().split())
AB = [(a, b) for a, b in zip(AB[::2], AB[1::2]) if a <= m]
AB_ = [[] for _ in range(m)]
for a, b in AB:
    AB_[a-1].append(b)

ans = 0
heap = []
for ab in AB_:
    for x in ab:
        heappush(heap, -x)
    if heap:
        ans -= heappop(heap)
print(ans)


Measured memory_bytes: 28652
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 二項係数計算
long long COM(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;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];
int t[64];
int d[100100];
ll rec(int num) {
	if (num == 0) return 0;
	return rec(num - 1) + num;
}

void Solve() {

	ll x, y;
	cin >> x >> y;
	ll a = abs(abs(y) - abs(x));
	if (abs(y) >= abs(x)) {

		if (y < 0 && x < 0) {
			cout << (a + 2) << endl;
		}
		else if (x < 0 ^ y < 0) {
			cout << (a + 1) << endl;
		}
		else cout << a << endl;
	}
	else {
		if (x < 0 && y <= 0) {
			cout << (y - x) << endl;
		}
		else if (x < 0) {
			cout << ((-1 * y) - x + 1) << endl;
		}
		else if (x > 0 && y > 0){
			cout << (a + 2) << endl;
		}
		else {
			cout << (y - (-1 * x) + 1) << endl;
		}
	}
}


int main() {
	Solve();
	return 0;
}



Measured memory_bytes: 6016
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
// << fixed << setprecision
// --------------------------------------
int n, k;
const int mod = 998244353;
#include <cassert>
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint dp[200005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;
  vector<PLL> vp;
  REP(i, k) {
    ll l, r;
    cin >> l >> r;

    vp.push_back(P(l, r));
  }

  dp[0] = 1;
  dp[1] = -1;
  mint sum = 0;
  REP(i, n) {
    sum += dp[i];
    dp[i] = sum;
    REP(j, k) {
      ll l = vp[j].first, r = vp[j].second;

      if(i + l <= n) dp[i + l] += dp[i];
      if(i + r + 1 <= n) dp[i + r + 1] -= dp[i];
    }
  }

  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 5196
x,y,z,w = map(int, input().split())
u = (x-z,y-w)
v = (w-y, x-z)
x1, y1 = z - v[0] ,w - v[1]
z1,w1 = x1 + u[0], y1 + u[1]
print(x1, y1, z1, w1)

Measured memory_bytes: 61604
#include <algorithm>
#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()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    rep(i, N) { cin >> A[i]; }
    rep(i, N) { cin >> B[i]; }
    int res = 0;
    rep(i, N) {
        int sum = 0;
        for (int j = 0; j <= i; j++) {
            sum += A[j];
        }
        for (int k = i; k < N; k++) {
            sum += B[k];
        }
        res = max(res, sum);
    }

    cout << res << endl;
}

Measured memory_bytes: 256
H = int(input())

keys = [None] + input().split()

for i in range(1, H + 1):
    print('node {0}: '.format(i), end = '')
    print('key = {0}, '.format(keys[i]), end = '')
    if i != 1:
        print('parent key = {0}, '.format(keys[i // 2]), end = '')
    left_index = i * 2
    if left_index <= H:
        print('left key = {0}, '.format(keys[left_index]), end = '')
    right_index = left_index + 1
    if right_index <= H:
        print('right key = {0}, '.format(keys[right_index]), end = '')
    print('')

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  ll ans = 0;
  rep(i,n/2) ans += a[i]*2;
  ans -= a[0];
  if (n%2==1) ans += a[n/2];
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

typedef pair<P,P> PP;
ll h,w;
vector<string> s,t;
ll slx,sly,srx,sry;
ll glx,gly,grx,gry;
bool used[51][51][51][51];

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

bool in(int y,int x){
    return y >= 0 && y < h && x >= 0 && x < w;
}

bool solve(){
    queue<PP> que;
    que.push(PP(P(sly,slx),P(sry,srx)));
    used[sly][slx][sry][srx] = 1;
    while(!que.empty()){
        PP p = que.front();
        que.pop();
        ll cly = p.first.first;
        ll clx = p.first.second;
        ll cry = p.second.first;
        ll crx = p.second.second;
        // cout << cly << " " << clx << " " << cry << " " << crx << endl;
        rep(i,4){
            ll nly = cly + dy[i];
            ll nlx = clx + dx[i];
            ll nry = cry + dy[i];
            ll nrx = crx + dx[i];
            if(!in(nly,nlx) || s[nly][nlx] == '#'){
                nlx = clx; nly = cly;
            }
            if(!in(nry,nrx) || t[nry][nrx] == '#'){
                nrx = crx; nry = cry;
            }
            if(nry == gry && nrx == grx && nly == gly && nlx == glx)return true;
            if(nry == gry && nrx == grx)continue;
            if(nly == gly && nlx == glx)continue;
            if(used[nly][nlx][nry][nrx])continue;
            PP tmp = PP(P(nly,nlx),P(nry,nrx));
            used[nly][nlx][nry][nrx] = 1;
            que.push(tmp);
        }
    }
    return false;
}

int main(){
    while(cin >> w >> h && w){
        s.clear();
        t.clear();
        rep(i,51)rep(j,51)rep(k,51)rep(l,51)used[i][j][k][l] = 0;
        s.resize(h);
        t.resize(h);
        rep(i,h){
            cin >> s[i] >> t[i];
            reverse(ALL(t[i]));
            // cout << s[i] << " " << t[i] << endl;
            rep(j,w){
                if(s[i][j] == 'L'){
                    slx = j,sly = i;
                }
                if(s[i][j] == '%'){
                    glx = j,gly = i;
                }
                if(t[i][j] == 'R'){
                    srx = j,sry = i;
                }
                if(t[i][j] == '%'){
                    grx = j,gry = i;
                }
            }
        }
        if(solve())cout << "Yes" << endl;
        else cout << "No" << endl;

    }
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int mod = 1e9+7;

vector<int> a[30];

void solve() {
  int n; string s; cin >> n >> s;
  for (int i = 0; i < n; ++i) {
    a[s[i]-'a'].push_back(i);
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    int skip = s[i]-'a';
    long long cur = 1;
    for (int j = 0; j < 26; ++j) {
      if (j == skip) continue;
      if (a[j].empty()) continue;
      int x = a[j].size()-(lower_bound(a[j].begin(), a[j].end(), i)-a[j].begin());
      if (!x) continue;
      (cur *= x+1) %= mod;
      //(cur += x) %= mod;
    }
    (ans += cur) %= mod;
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 972
def main():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
    
    ans = 0

    for i in range(A+1):
        for j in range(B+1):
            tmp = X - 500*i - 100*j
            if tmp >= 0 and tmp//50 <= C:
                ans += 1 
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
import java.util.*;
public class Main {
    public static void main(String[] args){

        long NUM=1000000007;
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int N=sc.nextInt();
        int K=sc.nextInt();
        boolean[] access=new boolean[N];
        int [] pathnum=new int[N];
        ArrayList<Integer>[] path=new ArrayList[N];
        for(int i=0;i<N;i++){
            access[i]=false;
            path[i]=new ArrayList<>();
            pathnum[i]=0;
        }
        for(int i=0;i<N-1;i++){
            int a=sc.nextInt()-1;
            int b=sc.nextInt()-1;
            path[a].add(b);
            path[b].add(a);
        }
        Stack<Integer>posHis=new Stack<>();
        Stack<Integer>posIndex=new Stack<>();
        int nowPos=0;
        int nowIndex=0;
        posHis.push(0);
        posIndex.push(0);
        pathnum[nowPos]=-1;
        long result=K;
        access[0]=true;
        main:
        while(!posHis.empty()){
            for(;nowIndex<path[nowPos].size();nowIndex++){
                if(!access[path[nowPos].get(nowIndex)]){
                    posHis.push(nowPos);
                    posIndex.push(nowIndex+1);
                    result=(result*(K-pathnum[nowPos]-2))%NUM;

                    nowPos=path[nowPos].get(nowIndex);
                    nowIndex=0;
                    access[nowPos]=true;
                    continue main;
                }
            }
            nowPos=posHis.pop();
            nowIndex=posIndex.pop();
            pathnum[nowPos]++;

        }
        System.out.println(result);

    }
}


Measured memory_bytes: 104724
R=range
while True:
    n,x=map(int,input().split())
    if n==x==0:
        break
    r=0
    for a in R(1,x//3):
        for b in R(a+1,x//2):
            c=x-a-b
            if b<c<=n:
                r+=1
    print(r)

Measured memory_bytes: 7660
import math
from numba import jit

K = int(input())


@jit
def apt(N):
    cnt = 0
    for i in range(1, K+1):
        for j in range(1, K + 1):
            for k in range(1, K + 1):
                cnt += math.gcd(k, math.gcd(i, j))
    return cnt


print(apt(K))


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

int main() {
	int n;
	cin >> n;
	long long  sum = 0;
	for (int i = 1; i <= n; ++i) {
		if (i % 3 == 0 && i % 5 == 0) continue;
		if (i % 3 == 0) continue;
		if (i % 5 == 0) continue;
		sum += i;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.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>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        ll now = 1000;
        for(ll i = 1; i*i <= N; ++i) {
                if (N % i == 0) now = i;
        }
        ll el1 = now;
        ll el2 = N / now;
        cout << (el1 - 1) + (el2 - 1) << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
)

type IOTp struct {
	iBuffer []byte
	iPos int
}
func (this *IOTp) GetChar() byte {
	res:=this.iBuffer[this.iPos]
	this.iPos++
	return res
}
func (this *IOTp) ReadInt() int {
	res:=0
	k:=1
	for ch:=this.iBuffer[this.iPos]; !(ch>='0' && ch<='9'); ch=this.iBuffer[this.iPos]{
		if ch=='-' {
			k=-1
		}
		this.iPos++
	}
	for ch:=this.iBuffer[this.iPos]; ch>='0' && ch<='9'; ch=this.iBuffer[this.iPos]{
		res=res*10+int(ch-'0')
		this.iPos++
	}
	res*=k
	return res
}
func NewIOTp() *IOTp {
	now:=new(IOTp)
	inputFile,_:=os.Open("in.txt")
	//inputFile:=os.Stdin
	now.iBuffer,_=ioutil.ReadAll(inputFile)
	now.iBuffer=append(now.iBuffer, '\n')
	now.iPos=0
	return now
}
var cin *bufio.Reader
var cout *bufio.Writer
func min(x,y int) int {
	if x<y {
		return x
	}
	return y
}
func max(x,y int) int {
	if x>y {
		return x
	}
	return y
}
func check(a []bool) bool {
	for _,v:=range a {
		if !v {
			return false
		}
	}
	return true
}
func main() {
	//inputFile,_:=os.Open("in.txt")
	inputFile:=os.Stdin
	var s string
	fmt.Fscan(inputFile,&s)
	ans:=100
	var a [200]bool
	for i:='a'; i<='z'; i++ {
		for j,v:=range s {
			if v==i {
				a[j]=true
			} else {
				a[j]=false
			}
		}
		j:=0
		for ; !check(a[:len(s)-j]); j++ {
			for k:=0; k<len(s)-j-1; k++ {
				a[k]=a[k] || a[k+1]
			}
		}
		ans=min(ans,j)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
 int x;
  cin>>x;
  if(x>=400&&x<=599){
    cout<<8<<endl;
  }
  if(x>=600&&x<=799){
    cout<<7<<endl;
  }
  if(x>=800&&x<=999){
    cout<<6<<endl;
  }
  if(x>=1000&&x<=1199){
    cout<<5<<endl;
  }
  if(x>=1200&&x<=1399){
    cout<<4<<endl;
  }
  if(x>=1400&&x<=1599){
    cout<<3<<endl;
  }
  if(x>=1600&&x<=1799){
    cout<<2<<endl;
  }
  if(x>=1800&&x<=1999){
    cout<<1<<endl;
  }
  return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }


int main() {
    int n, k;
    cin >> n >> k;
    vector<bool> done(n);
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int a;
            cin >> a;
            done[a - 1] = true;
        }
    }
    int cnt = 0;
    rep(i, n) if (!done[i]) cnt++;
    cout << cnt << endl;
}

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

int main() {
  long long int N,A,B;
  cin >> N >> A >> B;
  long long int num=0;
  long long int rep;
  rep = N / (A+B);
  num += rep*A;
  if( N - rep*(A+B) > A){
	num += A;
  }else{
    num +=  N - rep*(A+B);
  }
  
  cout << num << endl;
  return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    vector<int> a;
    cin >> n;
    for(int i = 0;i < n;i++){
        int input;
        cin >> input;
        a.emplace_back(input);
    }
    vector<int> b = a;
    sort(b.begin(), b.end());
    for(int i = 0; i < n; i++){
        if(a[i] == b[n-1]){
            if(a[i] == b[n-2]){
                cout << a[i] << endl;
            }else{
                cout << b[n-2] << endl;
            }
        }else{
            cout << b[n-1] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3316
def d(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

a, b = map(int, input().split())

ad = set(d(a))
bd = set(d(b))

cd = ad & bd

cnt = 0

for i in cd:
    if len(d(i)) == 2:
        cnt += 1

print(cnt+1)

Measured memory_bytes: 42988
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using lond = long double;
#define rep(i,n) for (int i = 0; i < (n); ++i)
//ans
int main (){
	lint n;
	cin >> n;
	vector<int> l(n);
	lint a,b,c,c2;
	rep(i,n) cin >> l[i];
	c2 = 0;
	rep(i,n){
		a = l[i];
		for (int j = i+1; j < n; ++j){
			if (a != l[j]){
				b = l[j];
				for (int k = j+1; k < n; ++k){
					if (a != l[k] && b != l[k]){
						if (abs(a-b) < l[k] && l[k] < a+b) c2++;
					}
				}
			}
		}

	}
	cout << c2 << endl;
	return 0;
}


Measured memory_bytes: 3652
x,y,z,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)

a = a.sort.reverse
b = b.sort.reverse
c = c.sort.reverse


all = []
a.each_with_index do |aa, ai|
  b.each_with_index do |bb, bi|
    c.each_with_index do |cc, ci|
      break if (ai+1) * (bi+1) * (ci+1) > k
      all << aa + bb + cc
    end
  end
end

puts all.sort.reverse.take(k)


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

void GG(){
	puts("No");
	exit(0);
}
const int N=200200;
char s[N]={'\0'};
int n,a,b,c,d;
#define WALK\
		(s[pos++]='.',\
		s[pos]='X')
#define JMP\
		(s[pos]='.',\
		s[pos+=2]='X')
#define F1 (s[pos+1])
#define F2 (s[pos+2])
void move(int& pos,int &oth,bool sw){
	if(F1=='.'){
		WALK;
		// printf("%s\n",s);
	}else if(F1=='X'&&F2=='.'){
		if(sw){
			JMP;
		}else{
			move(oth,pos,false);
			WALK;
		}
		// printf("%s\n",s);
	}else if(F1=='#'&&F2=='.'){
		JMP;
		// printf("%s\n",s);
	}else if(F1=='X'&&F2=='#'){
		move(oth,pos,false);
		WALK;
		// printf("%s\n",s);
	}else if(F1=='#'&&F2=='X'){
		move(oth,pos,false);
		JMP;
		// printf("%s\n",s);
	}else GG();
}

int main(){
	scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
	s[0]=' ';
	scanf("%s",s+1);
	s[a]=s[b]='X';
	if(c<d){
		while(b<d)move(b,a,false);
		while(a<c)move(a,b,false);
	}else{
		while(a<c)move(a,b,true);
		if(b>d)GG();
		while(b<d)move(b,a,false);
	}
	puts("Yes");
	return 0;
}

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

constexpr int MOD = 1000000007;
int N, K;
vector<vector<int>> G;

long dfs(int pre, int v) {
  long ret = 1;
  int k = (pre == -1) ? K : K - 1;
  for (auto next : G.at(v)) {
    if (next == pre) continue;
    ret *= --k;
    ret %= MOD;
    ret *= dfs(v, next);
    ret %= MOD;
  }
  return ret;
}

int main() {
  cin >> N >> K;
  G.resize(N);
  for (int a, b; cin >> a >> b;) {
    G.at(--a).push_back(--b);
    G.at(b).push_back(a);
  }
  cout << dfs(-1, 0) * K % MOD << "\n";
}

Measured memory_bytes: 14496
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* ]]] */

int main(){
  auto cv = [](int x){ return x / 100 * 60 + x % 100; };
  int n, p, q;
  while (cin >> n >> p >> q, n){
    vector<int> c(cv(2400), 0);
    rep(i, n){
      int m;
      cin >> m;
      rep(j, m){
        int a, b;
        cin >> a >> b;
        rep(k, cv(a), cv(b)){
          c[k]++;
        }
      }
    } 
    int mx = 0, t = 0;
    rep(j, cv(p), cv(q)){
      if (c[j] == n) t = 0;
      else chmax(mx, ++t);
    }
    cout << mx << endl;
  }
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

vector<ll> a, b, c;

int main(){
    ll x, y, z, k;
    cin >> x >> y >> z >> k;
    rep(i, x){
        ll A;
        cin >> A;
        a.push_back(A);
    }
    rep(i, y){
        ll B;
        cin >> B;
        b.push_back(B);
    }
    rep(i, z){
        ll C;
        cin >> C;
        c.push_back(C);
    }
    sort(c.begin(), c.end(), greater<ll>());
    vector<ll> ab;
    rep(i, x){
        rep(j, y) ab.push_back(a[i] + b[j]);
    }
    sort(ab.begin(), ab.end(), greater<ll>());
    
    vector<ll> ans;
    ll idx_ab = min(k, x * y);
    ll idx_c = min(k, z);

    rep(i, idx_ab) rep(j, idx_c) ans.push_back(ab[i] + c[j]);
    sort(ans.begin(), ans.end(), greater<ll>());

    rep(i, k) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 43256
#include <stdio.h>
 
int main(){
  int N, K;
  scanf("%d %d",&N, &K);
  
  int x;
  int i;
  x = N / K;
  for (i=1; i<1000000000; i++){
    if(x==0){
      printf("%d\n",i);
      break;
    }
    x = x/K;
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(x) cerr<<#x": "<<(x)<<endl
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second

template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}

template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

int main()
{
	ios_base::sync_with_stdio(false);
  
  int n, m, x;
  priority_queue<int> q;
  
  cin >> n >> m;
  for(int i = 1; i <= n; ++i) cin >> x, q.push(x);
  for(int i = 1; i <= m; ++i) {
	x = q.top(); q.pop();
    q.push(x / 2);
  }
  
  ll ans = 0;
  while(!q.empty()) ans += q.top(), q.pop();
  
  cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 892
bld = [0] * 4

for i in range(4):
  bld[i] = [0] * 3
  for j in range(3):
    bld[i][j] = [0] * 10
    
n = int(input())
list = [input() for i in range(n) ]

for i in list:
    b, f, r, v = map(int, i.split())
    bld[b - 1][f - 1][r - 1] += v

count = 0
for i in bld:
    for j in i:
      print(' ', end='')
      print(*j)
    if count < 3:
      print('####################')
    count += 1



Measured memory_bytes: 5620
#include <random>    //ランダム
#include <algorithm> //アルゴリズム
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <fstream>
#include <cmath>
#include <cstring>
#include <string>
#include <sstream>
#include <cassert>
#include <cfloat>
#include <numeric>
#include <climits>
#include <stdint.h>
#include <ctime>
using namespace std;
// vector<int> temple(7,0);
    // for(int i=0; i<temple.size(); i++){
    
    // }
    // int maxtemp=*max_element(temple.begin(), temple.end());;
    // int mintemp=*min_element(temple.begin(), temple.end());;
    // int answer=0;
    // for(int i=0; i<temple.size(); i++){
    //     if(temple[i]==maxtemp||temple[i]==mintemp){
            
    //     }else{
    //         answer+=temple[i];
    //     }
    // }
    // answer/=5;
    // cout << answer << std::endl;
    void ifmagic(int select, int depth, int kaisuu, int red, int green, int blue, int& answer){
        if(depth!=0){
            if(select==1){
                red*=2;
            }else if(select==2){
                green*=2;
            }else{
                blue*=2;
            }
        }
        if(depth>kaisuu){
            return;
        }else if(depth==kaisuu){
        if(green>red&blue>green){
            answer=1;
            return;
        }else{
            return;
        }        
        }
        // cout<<"depth="<<depth<<endl;
        // cout<<"red=="<<red<<endl;
        // cout<<"green=="<<green<<endl;
        // cout<<"blue=="<<blue<<endl;
        for(int i=1; i<4; i++){
            ifmagic(i,depth+1,kaisuu,red,green,blue,answer);
        }
        return;
    }
int main()
{
    int red, green, blue, kaisuu;
    cin >> red >> green >>blue;
    cin >> kaisuu;
    int answer=0;
    ifmagic(0,0,kaisuu,red,green,blue,answer);
    if(answer==1){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3620
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    using namespace std;
    #define INF 10000000;
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

  
  
    int main(){
      string s;
      cin >> s;
      int size = s.size()-1;
      bool f = false;
      int memo;
      for(int i=0;i<(1<<size);i++){
        int sum = s[0]-'0';
        rep(j,size){
          if(i & (1<<j))sum += s[j+1]-'0';
          else sum -= s[j+1]-'0';
        }
        if(sum == 7){
          f = true;
          memo = i;
          break;
      } 
      if(f)break;
      }
      string ans;
      ans.push_back(s[0]);
      for(int i=0;i<size;i++){
        if(memo & (1<<i))ans += '+';
        else ans += '-';
        ans += s[i+1];
      }
      ans +="=7";
      cout << ans <<endl;
    }
      


    


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int> 

int main(){
  int A[3][3];
  rep(i,3){
    rep(j,3){
      cin >> A[i][j];
    }
  }
  int N; cin >> N;
  int b;
  vector<bool> c(101,false);
  rep(i,N){
    cin >> b;
    c[b] = true;
  }

  bool flag = false;
  rep(i,3){
    flag += (c[A[i][0]] && c[A[i][1]] && c[A[i][2]]);
    flag += (c[A[0][i]] && c[A[1][i]] && c[A[2][i]]);
  }
  flag += (c[A[0][0]] && c[A[1][1]] && c[A[2][2]]);
  flag += (c[A[0][2]] && c[A[1][1]] && c[A[2][0]]);

  cout << (flag? "Yes" : "No") << endl;  

  return 0;
}


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

int main(int argc, char const *argv[])
{
    long a;
    cin >> a;
    if (a >= 30)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
import sys
input = sys.stdin.readline
from collections import deque
from operator import itemgetter

N, D, A = map(int, input().split())
X = []
for _ in range(N):
    x, h = map(int, input().split())
    X.append((x, h))
X = sorted(X, key = itemgetter(0))[::-1]
Q = deque([])

ans = 0
k = 0
while X:
    if len(Q) == 0 or X[-1][0] <= Q[0][0]:
        x, h = X.pop()
        h = max(h - k * A, 0)
        a = (h + A - 1) // A
        ans += a
        k += a
        deque.append(Q, (x + 2 * D, a))
    else:
        x, a = deque.popleft(Q)
        k -= a

print(ans)


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> town(N);
  vector<int> road(M*2);
  
  for (int i = 0; i < M*2; i=i+2) {
    cin >> road.at(i) >> road.at(i+1);
  }
  for (int i = 0; i < N; i++){
    for (int j =0; j < M*2; j++){
      if (road.at(j) == i+1){
        town.at(i)++;
      }
    }
  }
  for (int i = 0; i <N; i++){
    cout << town.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k,a[1000005];
int mx[1000005][36],mi[1000005][36];
int d[1000005];
inline int Max(int x,int y)
{
	int l=(int)log2(y-x+1);
	return max(mx[x][l],mx[y-(1<<l)+1][l]);
}
inline int Min(int x,int y)
{
	int l=(int)log2(y-x+1);
	return min(mi[x][l],mi[y-(1<<l)+1][l]);
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;)
	{
		int x1=i;
		while(a[x1+1]>a[x1])
			x1++;
		while(i<=x1)
			d[i++]=x1;
	}
	for(int i=1;i<=n;i++)
		mx[i][0]=mi[i][0]=a[i];
    for(int l=1;(1<<l)<=n;l++)
        for(int i=1;i+(1<<l)-1<=n;i++)
			mi[i][l]=min(mi[i][l-1],mi[i+(1<<(l-1))][l-1]),
            mx[i][l]=max(mx[i][l-1],mx[i+(1<<(l-1))][l-1]);
	int ans=1;
	bool f1=0;
	if(d[1]>=k)
		f1=1;
	for(int i=2;i+k-1<=n;i++)
	{
		if((Max(i,i+k-2)<a[i+k-1]&&Min(i,i+k-2)>a[i-1]))
			continue;
		if(d[i]>=i+k-1)
		{
			if(f1)
				continue;
			f1=1;
		}
		ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 64512
import java.util.*;

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        if ((a==1 && b==2)||(a==2 && b==1)){
            System.out.println(3);
        }else if ((a==1 && b==3)||(a==3 && b==1)){
            System.out.println(2);
        }else {
            System.out.println(1);
        }

    }

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define ull         unsigned long long int
#define ll          long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000000001
#define all(a)      (a).begin(),(a).end()
#define ordered_set     tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> 
 
const long long INF = (long long) 1e16+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

ll power(ll x,ll y){
  ll res=1;
  while(y>0){
    if(y%2) res=(x%hell*res%hell)%hell;
    x=(x%hell*x%hell)%hell;    
    y=y/2;
  }
  
  return res%hell;
}
 
ll modinv(ll x){
  return power(x,hell-2);
}

ll gcd(ll a,ll b){
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}    
    
void fastIO(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}    
ll n,k;
ll a[200005];

bool F(ll x){
    ll cnt=0;
    forn(i,0,n){
        if(a[i]<=x)
        continue;
        cnt+=(a[i]/x);
    }
    return cnt<=k;
}

void solve(){
    cin>>n>>k;
    forn(i,0,n)
    cin>>a[i];
    
    ll l=1,h=1e9;
    ll ans;
    while(l<=h){
        ll m=l+(h-l)/2;
        if(F(m)){
            ans=m;
            h=m-1;
        }
        else
        l=m+1;
    }    
    cout<<ans;
}    

int main(){
   fastIO();
   int test;
   //cin>>test;
   test=1;    
      
   while(test--)
   solve();
}    

Measured memory_bytes: 5156
from itertools import accumulate

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

a_acc = [0] + list(accumulate(a))  # aを0冊読む=1冊も読まない場合があるので
b_acc = [0] + list((accumulate(b)))  # 今度は[0]が必要です

ans = 0
for an in range(n + 1):
    rem = k - a_acc[an]
    if rem < 0:
        break

    # 最初は 0 <= x < m + 1 の範囲で、この範囲を狭めていきます
    ok = 0
    ng = m + 1   
    # ng = ok + 1のとき、ok <= x < ng は ok <= x < ok + 1で、x = okに確定します
    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        # bをmid冊読めるか？
        if b_acc[mid] <= rem:
        # 読めるならok
            ok = mid
        else:
        # 読めないならng
            ng = mid

    bn = ok
    ans = max(ans, an + bn)

print(ans)

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

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

vector<vector<int>> G;
int main() {
  ll n, m, ans = 0;
  cin >> n >> m;
  G.resize(n, vector<int>());
  vector<ll> h(n), a(m), b(m);
  rep(i, n) cin >> h[i];
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }

  for (int i = 0; i < n; ++i) {
    if (G[i].size() == 0) {
      ans++;
    } else {
      bool ok = true;
      for (int next : G[i])
        if (h[i] <= h[next]) ok = false;
      if (ok) ans++;
    }
  }

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


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

void solve(){
  int N, D; cin >> N >> D;
  pair<double, double> r[N];
  rep(i, N) cin >> r[i].first >> r[i].second;
  int cnt = 0;
  for(int i = 0; i < N;++i){
    if((double)D >= sqrt(r[i].first * r[i].first + r[i].second * r[i].second)) cnt++;
  }
  cout << cnt << endl;

}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 6968
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  string s;
  cin >> s;

  int res=0;
  
  if(s.size()%2==0){
    for(int i=0;i+1<s.size();i+=2){
      if(s.substr(i,2)!="hi") res=1;
    }
  }else{
    res=1;
  }
  if(res==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

int main(){
    int a,b; cin >> a >> b;
    rep(i,3){
        if(i+1 != a && i+1 != b){
            cout << i+1;
            break;
        }
    }
}

Measured memory_bytes: 256
from collections import deque


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

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

used = [False] * n
def dfs(i):
    q = deque([i])
    used[i] = True
    set_ = set([i])
    ans = 0
    while q:
        v = q.pop()
        for nxt_v in graph[v]:
            if used[nxt_v]:
                continue
            used[nxt_v] = True
            q.append(nxt_v)
            set_.add(nxt_v)
    for i in set_:
        if p[i] - 1 in set_:
            ans += 1
    return ans

res = 0
for i in range(n):
    if used[i]:
        continue
    else:
        res += dfs(i)
print(res)

Measured memory_bytes: 89580
use std::io::{self, Read};
use std::str::FromStr;
use std::usize;

pub struct Scanner<R: Read> {
    reader: R,
}
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let s = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        s.parse::<T>().ok().expect("failed to parse token")
    }
}

fn solve(mat: &Vec<(usize, usize)>) -> u64 {
    // 2行列(m,n)と(n,l)の積では、結果となる(m,l)の各値において、n回の乗算と和が計算される。
    // よって、2行列の積ではmnl回の乗算が行われる。

    // 乗算回数が最小となる条件を考える
    // 行列M1M2M3の積なら、(M1M2)M3とM1(M2M3)の比較でよい。
    // 行列M1M2M3M4の積なら、
    // (M1)(M2M3M4), (M1M2)(M3M4), (M1M2M3)(M4)の3通りでコストを比較
    // コストの計算は(Mi)は0、(MiMi+1)ならminimi+1という感じ？

    let n = mat.len();

    // dp[i][j]を次のように定義してみる
    // Mi..Mjの最小乗算回数
    // よってdp[i][j] = 0 (i>=j)
    let mut dp: Vec<Vec<usize>> = vec![vec![0; n]; n];

    // 走査が斜めになるのでちょっと複雑
    for c in 1..n { // 乗算対象の行列数
        for r in 0..n-c {   // 対象の行。行列数が増えるごとに減少する
            let i = r;
            let j = r + c;

            // Mr..Mcの最小値を計算する
            let mut mn = usize::max_value();

            for e in i..j {
                // (Mr..Me)(Me+1..Mc)の最少スコアを考える
                let v = dp[i][e] + dp[e+1][j] + mat[i].0 * mat[e].1 * mat[j].1;
                if v < mn {
                    mn = v;
                }
            }
            dp[i][j] = mn;
        }
    }

    // for i in 0..n {
    //     println!("{:?}", &dp[i]);
    // }

    dp[0][n-1] as u64
}


fn main() {
    let sin = io::stdin();
    let sin = sin.lock();
    let mut sc = Scanner::new(sin);

    let n: usize = sc.read();

    let mat: Vec<(usize, usize)> = (0..n)
        .map(|_| (sc.read(), sc.read()))
        .collect();

    println!("{}", solve(&mat));
}



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

using namespace std;

int main(void){
    string str;
    string judge_b;
    string judge_a;
    int i;
    int n;
    int judge;
    
    cin>>n;
    cin.get();
    for(i=0;i<n;i++){
        getline(cin,str);
        while(judge=str.find("Hoshino"),judge!=string::npos){
            str.replace(judge,7,"Hoshina");
        }
        cout<<str<<endl;
    }
    return(0);
}

Measured memory_bytes: 1208
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;
 
/*
    Author: Koushik Sahu
    Created: 02 September 2020 Wed 21:14:21
*/

public class Main {

    static FastScanner fs=new FastScanner();
        
    static long x, k, d;

    public static void main(String[] args){
        x = fs.nextLong();
        k = fs.nextLong();
        d = fs.nextLong();
        x = Math.abs(x);
        long s = Math.min(k, x/d);
        k -= s;
        x -= s*d;
        if(k%2==0){
            System.out.println(x);
        }else{
            System.out.println(d-x);
        }
    }
        
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
                            
        public String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        public String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
                                        
        public int nextInt() {
            return Integer.parseInt(next());
        }
                                                
        public int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
                                                        
        public long nextLong() {
            return Long.parseLong(next());
        }
                                                                
        public long[] readLongArray(int n) {
            long[] a=new long[n];
            for (int i=0; i<n; i++) a[i]=nextLong();
            return a;
        }

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

Measured memory_bytes: 32560
#include<stdio.h>
#include<string.h>
#define LEN 1000005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=1, tail=1, n;

void enqueue(P x){
  
  Q[tail] = x;
  tail++;
}

void dequeue(){
  head++;
}

int main(){
  int elaps = 0, judgement;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  tail = i;
  
  while(head < tail){
    
    if(tail == LEN) tail = 1;
    if(head == LEN) head = 1;
    judgement = Q[head].t - q;
    
    if(judgement <= 0){
      elaps += Q[head].t;
      dequeue();
      printf("%s %d\n",Q[head-1].name,elaps);
    }
    
    else{
      elaps += q;
      Q[head].t -= q;
      enqueue(Q[head]);
      dequeue(); 
    } 
  } 
  return 0;
}

Measured memory_bytes: 21072
n = int(input())
a = list(map(int, input().split()))
a.sort()
s = []
t = 0
for i in range(n-1):
    t += a[i] 
    s.append(t)
y = 1
for i in range(n-1, 0, -1):
    if s[i-1]*2 >= a[i]:
        y += 1
    else: break
print(y)

Measured memory_bytes: 14316
#include <cstdio>

long long X, Y;

void solve()
{
	int i=1;
	while(X<=Y){
		X *= 2;
		i ++;
	}
	i --;
	printf("%d\n", i);
}

int main()
{
	scanf("%lld %lld", &X, &Y);
	solve();
	return 0;
}

Measured memory_bytes: 128
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/05/02.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC165
//
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

template<class T> inline bool chmin(T& a, T b){ if(a>b){a=b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b){ if(a<b){a=b; return 1;} return 0;}

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const int MOD = 1000000007;
//#define __DBG__



void solve(void){
  
  ll X;
  
  cin >> X;
  
  ll Aans=0;
  ll Bans=0;
  
  REP2(A,-120,120){
    REP2(B,-120,120){
      if(A*A*A*A*A-B*B*B*B*B==X){
        Aans=A;
        Bans=B;
        break;
      }
    }
  }
  
  cout << Aans << " " << Bans << endl;
  return;
}



#define TESTCASES 1

int main() {

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

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}




Measured memory_bytes: 3652
var
  flag:boolean;
  da,sl:int64;
  hs:array[1..2] of int64;
  x,y,n,u,m,i:longint;
  hd,nx,t,ys:array[0..200100] of longint;
  procedure jb(x,y:longint);
    begin
      u:=u+1;
      nx[u]:=hd[x];
      hd[x]:=u;
      t[u]:=y;
    end;
  function ss(q,sc:longint):boolean;
    var
      i:longint;
      cg:boolean;
    begin
      ys[q]:=sc;
      sl:=sl+1;
      hs[sc]:=hs[sc]+1;
      cg:=true;
      i:=hd[q];
      while i<>0 do
        begin
          if ys[t[i]]=0 then cg:=cg and ss(t[i],3-sc);
          if ys[t[i]]=sc then flag:=false;
          i:=nx[i];
        end;
      exit(cg);
    end;
begin
  readln(n,m);
  for i:=1 to m do
    begin
      readln(x,y);
      jb(x,y);
      jb(y,x);
    end;
  for i:=1 to n do
    if ys[i]=0 then
      begin
        hs[1]:=0;
        hs[2]:=0;
        sl:=0;
        flag:=true;
        ss(i,1);
        if flag then da:=da+hs[1]*hs[2]
        else da:=da+sl*(sl-1) div 2;
      end;
  writeln(da-m);
end.

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

typedef unsigned long long ll;

ll md = 1000000007;

int main(int, char**)
{
	double x[10][10];
	ll n, d, ans = 0;
	cin >> n >> d;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < d; j++)
			cin >> x[i][j];

	for (int i = 0; i < n-1; i++) {
		for (int j = i + 1; j < n; j++) {
			double a2 = 0.0;
			for (int k = 0; k < d; k++) {
				a2 += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
			}
				double a1 = sqrt(a2);
				if ((ceil(a1)-floor(a1)) < 0.000000000001) {
					ans++;
				}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;

void Cout(char c,int num){
  for(int i=0;i<num;i++){
    cout<<c;
  }
}

int main(){
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;

  Cout('U',ty-sy);
  Cout('R',tx-sx);
  Cout('D',ty-sy);
  Cout('L',tx-sx);

  cout<<"L";

  Cout('U',ty-sy+1);
  Cout('R',tx-sx+1);

  cout<<"D";

  cout<<"R";

  Cout('D',ty-sy+1);
  Cout('L',tx-sx+1);

  cout<<"U"<<endl;

}


Measured memory_bytes: 256