akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int array[][] = new int[3][3];
		int a[] = new int[3];
		int b[] = new int[3];
		int c[][] = new int[3][3];


		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				array[i][j] = scan.nextInt();
			}
		}

		a[0] = 0;
		
		b[0] = array[0][0] - a[0];
		b[1] = array[0][1] - a[0];
		b[2] = array[0][2] - a[0];

		a[1] = array[1][0] - b[0];
		a[2] = array[2][0] - b[0];
		
		/*System.out.println(a[0]);
		System.out.println(a[1]);
		System.out.println(a[2]);
		System.out.println(b[0]);
		System.out.println(b[1]);
		System.out.println(b[2]);
*/
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if(array[i][j] != a[i]+b[j]) {
					System.out.println("No");
					System.exit(0);
				}
			}
		}
		System.out.println("Yes");
		
		/*
		  for(int i = 0; i<3;i++) { for (int j = 0; j <3; j++) {
		  System.out.print(array[i][j]); } System.out.println(""); }
		*/
	}

}


Measured memory_bytes: 23892
#include <cstdio>
#include <vector>

using namespace std;

int main() {
    int n, k, q;
    scanf("%d%d%d", &n, &k, &q);
    vector<int> score(n, k);
    for (int i = 0; i < q; i++) {
        int a; scanf("%d", &a);
        score[a - 1] += 1;
    }
    for (int s : score) {
        if (s > q) {
            puts("Yes");
        } else {
            puts("No");
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define all(x) (x).begin(),(x).end()

typedef long long LL;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> store(n);
    for (int i = 0; i < n; i++)
        cin >> store[i].first >> store[i].second;

    sort(all(store));

    LL ans = 0;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int value = store[i].first;
        int remain = store[i].second;

        if (remain <= m - cnt) {
            ans += (LL)value*remain;
            cnt += remain;
        } else {
            ans += (LL)value*(m - cnt);
            cnt = m;
        }
    }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

  vector<int64_t> m(8);
  int64_t m2 = 0;
  for (auto i : irange(0L, n)) {
    int64_t a;
    cin >> a;

    if (a >= 3200) {
      ++m2;
    } else {
      ++m[a / 400];
    }
  }

  int64_t ans = 0;
  for (auto mm : m) {
    if (mm > 0) {
      ++ans;
    }
  }

  cout << max(ans, 1L) << " " << ans + m2 << endl;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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<typename T>
void printA(vector<T> &printArray, char between = ' ') {
  int paSize = printArray.size();
  for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
  if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int Len[55], Pat[55];

int rec(int level, int layer) {
  if (level == 0) {
    return 1;
  }

  if (layer <= 1) { // 1
    return 0;
  } else if (layer <= Len[level-1] + 1) { // 2
    return rec(level-1, layer-1);
  } else if (layer <= Len[level-1] + 2) { // 3
    return rec(level-1, layer-1) + 1;
  } else if (layer <= 2*Len[level-1] + 2) { // 4
    return rec(level-1, layer-1) + 1 + rec(level-1, layer - Len[level-1] - 2);
  } else { // 5
    return  2*rec(level-1, layer-1) + 1;
  }
}

/*
int rec(int level, int layer) {
  if (level == 0) {
    return 1;
  }

  if (layer <= 1) { // 1
    return 0;
  } else if (layer <= Len[level-1] + 1) { // 2
    return rec(level-1, layer-1);
  } else if (layer <= Len[level-1] + 2) { // 3
    // return Pat[level-1] + 1;
    return rec(level-1, layer-1) + 1;
  } else if (layer <= 2*Len[level-1] + 2) { // 4
    return Pat[level-1] + 1 + rec(level-1, layer - Len[level-1] - 2);
  } else { // 5
    return  2*Pat[level-1] + 1;
  }
}
*/

signed main() {
  int N, X;
  cin >> N >> X;

  Len[0] = Pat[0] = 1;
  for (int i = 1; i <= N; i++) {
    Len[i] = Len[i-1] * 2 + 3;
    Pat[i] = Pat[i-1] * 2 + 1;
  }

  cout << rec(N, X) << endl;

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> suji(n);
  for (int i = 0; i < n; i++) {
    cin >> suji.at(i);
  }
  
  sort(suji.begin(), suji.end());
  reverse(suji.begin(), suji.end());
  
  int a = 0, b = 0;
  
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      a += suji.at(i);
    }
    else {
      b += suji.at(i);
    }
  }
  cout << a - b << endl;
}


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


int main(){
    //ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("../input.txt","r",stdin);


    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll p = a*c;
    ll q = a*d;
    ll r = b*c;
    ll s = b*d;
    ll p_q = max(p,q);
    ll r_s = max(r,s);
    cout << max(p_q,r_s) << "\n";
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cstring>

char c[6];

int main(){
	scanf("%s",c);
	if(strlen(c)<2){
		puts("No");
		return 0;
	}
	for(int i=0;i<strlen(c)-1;++i){
		if(c[i]=='A' && c[i+1]=='C'){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}

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

int main(int argc, char* argv[])
{
  int a, b;
  std::cin >> a >> b;
  int ofs = 0;
  if (a > b) {
    ofs = 1;
  }
  std::cout << a - ofs << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
const int MAX = 2048;
inline int Max(int a, int b)
{
	return a > b ? a : b;
}
int dp[MAX][MAX];

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

	int t;
	std::string a, b;
	std::cin >> t;
	while (t--)
	{
		memset(dp, 0, sizeof(dp));
		std::cin >> a >> b;
		int len1 = a.size(), len2 = b.size();
		
		for (int i = 0; i < len1; ++i)
			for (int j = 0; j < len2; ++j)
			{
				if (a[i] == b[j])
					dp[i+1][j+1] = dp[i][j] + 1;
				else
					dp[i+1][j+1] = Max(dp[i][j+1], dp[i+1][j]);
			}
		
		printf("%d\n", dp[len1][len2]);
	}
	
	return 0;
}


Measured memory_bytes: 19688
#include <iostream>

using namespace std;

int main()
{
  int X, Y;
  cin >> X;
  cin >> Y;
  
  if ((Y - 2 * X) % 2 == 0 && Y - 2 * X >= 0 && 4 * X - Y >= 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	int ma = 0;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int H; cin >> H;
		ma = max(ma, H);
		ans += (ma == H);
	}
	cout << ans << '\n';

	return 0;
}


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

const int K = 18, N = 55;
long long C[N][N];

void pre() {
    for (int i=0; i<N; i++) C[i][0] = 1;
    for (int i=1; i<N; i++)
        for (int j=1; j<N; j++)
            C[i][j] = C[i-1][j-1] + C[i-1][j];

    for (int i=0; i<N; i++)
        for (int j=1; j<N; j++)
            C[i][j] += C[i][j-1];
}

bool between(int sub, int super, int x) {
    return (sub&x) == sub && (super&x) == x;
}

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

    int n, k, S, T;
    cin>>n>>k>>S>>T;

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

    long long ans = 0;
    for (int mask = 0; mask < (1<<K); mask++) {
        if (!between(S, T, mask))  continue;

        vector<int> vv;
        for (int i=0; i<n; i++)
            if (between(S, T, v[i]))
                vv.push_back(v[i] & (~mask));

        sort(vv.begin(), vv.end());

        long long ww = 0;
        while (vv.size()) {
            int last = vv.back();
            int cnt = 0;
            while (vv.size() && vv.back() == last)  cnt++, vv.pop_back();
            ww += C[cnt][k]-1;
        }

        int bc = __builtin_popcount(mask);
        if (bc%2)   ans += ww;
        else        ans -= ww;
    }
    cout<<abs(ans)<<endl;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a;
    cin>>n>>a;
    cout<<n*n-a<<endl;
}

Measured memory_bytes: 256
import           Control.Monad

main :: IO ()
main = do
    n <- readLn
    xyhs <- replicateM n $ do
        [x, y, h] <- map read.words <$> getLine
        return (x, y, h)
    case solve xyhs of
        (cx, cy, h) -> putStrLn . unwords $ map show [cx, cy, h]

solve :: [(Int, Int, Int)] -> (Int, Int, Int)
solve xyhs = head $ do
    cx <- [0..100]
    cy <- [0..100]
    let hs = [h + abs(x-cx) + abs(y-cy) | (x,y,h)<-xyhs, h > 0]
    let ub = minimum $ maxBound:[abs(x-cx) + abs(y-cy) | (x,y,0)<-xyhs]
    case (hs, ub) of
        ([], 1) -> return (cx, cy, 1)
        ([], _) -> undefined
        (h:hs, ub)
          | all(==h)hs, h <= ub -> return (cx, cy, h)
          | otherwise -> []

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef pair<int,int> P;
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define lowbit(x) (x&-x)
const ll INF=0x3f3f3f3f;
const double EPS=1e-7;
const int N=3e5+10;
const ll mod=1e9+7;
const ll MOD=998244353;
inline ll read()  
{  ll f=1,x=0;char ch=getchar();
   for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-') f=-1;
   for(;ch<='9'&&ch>='0';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
   return x*f;
}
int n;
int a[N];
int main()
{  string s;
   cin>>s;
   int ans=0;
   for(int i=0;i<3;i++)if(s[i]=='R')ans++;
   if(ans==2)
   {  ans=1;
      if(s[0]==s[1]&&s[0]=='R')ans=2;
      if(s[1]==s[2]&&s[1]=='R')ans=2;
   }
   cout<<ans;
}

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

int main()
{
  string s;
  cin >> s;
  int i, p;
  p = s.size()-1;
  int ch = 0;
  int point = 0;
  while(p >= 4)
  {
    if(p>=4)
    {
      if(s.at(p-4) == 'd'&&s.at(p-3) == 'r'&&s.at(p-2) == 'e'&&s.at(p-1) == 'a'&&s.at(p) == 'm')
      {
        p -= 5;
        point++;
      }
      else if(s.at(p-4)=='e'&&s.at(p-3)=='r'&&s.at(p-2)=='a'&&s.at(p-1)=='s'&&s.at(p)=='e')
      {
        p -= 5;
        point++;
      }
    }
    if(p>=5 && point == 0)
    {
      if(s.at(p-5) == 'e'&&s.at(p-4) == 'r'&&s.at(p-3) == 'a'&&s.at(p-2) == 's'&&s.at(p-1) == 'e'&&s.at(p) == 'r')
      {
        p -= 6;
        point++;
      }
    }
    if(p>=6 && point == 0)
    {
      if(s.at(p-6) == 'd'&&s.at(p-5) == 'r'&&s.at(p-4) == 'e'&&s.at(p-3) == 'a'&&s.at(p-2) == 'm'&&s.at(p-1) == 'e'&&s.at(p) == 'r')
      {
        p -= 7;
        point++;
      }
    }
    if(point == 0)
    {
      ch = 1;
      break;
    }
    point = 0;
  }
  if(p == -1 && ch == 0)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 512
a = gets.to_i
b = gets.to_i 
c = gets.to_i
x = gets.to_i
sum = 0
0.upto(a) do |i|
  0.upto(b) do |j|
    0.upto(c) do |k|
      if 500*i + 100*j + 50*k == x
        sum += 1
      end
    end
  end
end
puts sum


Measured memory_bytes: 1788
#!/usr/bin/env python
# coding: utf-8

# In[2]:


coord = [int(input()) for i in range(5)]
k = int(input())


# In[6]:


max_d = coord[-1]-coord[0]


# In[7]:


if max_d <= k:
    print('Yay!')
else:
    print(':(')


# In[ ]:






Measured memory_bytes: 2940
n = int(input())
yen = 100000

for i in range(n):
    yen *= 1.05
    yen = int(yen)

    rest = int(yen % 1000)
    if (rest != 0):
        yen /= 1000
        yen = int(yen)
        yen *= 1000
        yen += 1000

print yen

Measured memory_bytes: 4224
#include<stdio.h>

int main(){
  char s[10000],t[10000];
  scanf("%s",s);
  scanf("%s",t);
  
  int ans=10000,ssize,tsize;
  for(int i=0;i>=0;i++){
    if(s[i]=='\0'){
      ssize=i;
      break;
    }
  }
  for(int i=0;i>=0;i++){
    if(t[i]=='\0'){
      tsize=i;
      break;
    }
  }
  
  for(int i=0;i<=ssize-tsize;i++){
    int a=tsize;
    for(int j=i;j<=i+tsize-1;j++){
      if(s[j]==t[j-i]){
        a-=1;
      }
    }
    if(ans>a){
      ans=a;
    }
  }
  
  printf("%d",ans);
  return 0;
}


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

ll n;

inline ll read(){
	ll s = 0, w = 1;
	char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) w *= ch == '-' ? -1 : 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
	return s * w;
}

inline void work(){
	n = read();
	printf("%lld\n", n + n * n + n * n * n);
}

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

Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

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

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  ll a, x;
  cin >> x >> a;
  if (x < a)
  {
    cout << 0 << endl;
  }
  else
  {
    cout << 10 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    vi a(4);
    for(int i=0;i<4;i++) cin>>a[i];
    sort(a.begin(),a.end());
    cout<<abs(a[0]+a[3]-(a[1]+a[2]))<<'\n';

}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}
ll myceil(ll x,ll y){//yがいくつ集まったらx以上になるか
	if(x<=y) return 1;
	else if(x%y==0) return x/y;
	else return x/y+1;
}

//a,b x
int main(){
	ll N,H; cin>>N>>H;
	vector<ll> A(N);
	vector<ll> B(N);
	rep(i,N) cin>>A[i]>>B[i];
	sort(A.bg,A.ed,greater<ll>());
	sort(B.bg,B.ed,greater<ll>());
	ll bsum=0,cnt=0;
	rep(i,N){
		if(B[i]>A[0]){
			bsum+=B[i];
			cnt++;
		}
		else break;

		if(bsum>=H){
			cout<<cnt;
			return 0;
		}
	}
	cout<<cnt+myceil(H-bsum,A[0]);
}

Measured memory_bytes: 1792
<?php
fscanf(STDIN, "%s", $n);
if($n[0] == $n[2] || ($n[0] == $n[1] && $n[1] == $n[2] && $n[0] == $n[2])) {
    echo 'Yes';
} else {
    echo 'No';
}
echo "\n";

Measured memory_bytes: 4604
A = []
p = 10**18
for i in range(15,2,-1):
  l = max(0,10**(i-3) - 1)
  m = 10**(i-3)
  for j in range(999,9,-1):
    c = l+m*j
    s = c/sum(map(int,str(c)))
    if s-p <= 1e-7:
      A.append(c)
      p = s

for i in range(9,0,-1):A.append(10*i+9)
for i in range(9,0,-1):A.append(i)
A = A[::-1]
A = list(set(A))
A.sort() 


X = int(input())
for i in range(X):print(A[i])

Measured memory_bytes: 3188
import bisect
 
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    a.sort()
    b.sort()
    c.sort()
    ans = 0
    for y in b:
        i = bisect.bisect_left(a, y)
        j = bisect.bisect_right(c, y)
        if i > 0 and j != len(c):
            ans += i * (n - j)
 
    print(ans)
 
main()

Measured memory_bytes: 22720
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<ll, ll> II;
typedef pair<int, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 610;
const int MAXM = 10010;
const int MAXK = 110;
const int MAXQ = 200010;

int n, m, A[MAXN][MAXN];
ld dp[MAXN];
vector<II> a[MAXN];
int check[MAXN];

inline int cmp(ld a, ld b) {
    return (a < b - EPS) ? -1 : ((a > b + EPS) ? 1 : 0);
}

ld solve(int u, int ban) {
    if (dp[u] != -1) return dp[u];

    int num = 0;

    FOR(i,0,SZ(a[u])-1) {
        int idx = a[u][i].SE;
        if (idx == ban) continue;
        num++;
    }

    ld res = 0;
    FOR(i,0,SZ(a[u])-1) {
        int v = a[u][i].FI;
        int idx = a[u][i].SE;
        if (idx == ban) continue;
        res += 1.0 / num * (solve(v, ban) + 1);
    }

    if (cmp(res, 0) == 0) res = -1000000000;

    return dp[u] = res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,m) {
        int u, v;
        cin >> u >> v;
        a[u].emplace_back(II(v, i));
        A[u][v] = i;
    }

    FOR(i,1,n) dp[i] = -1;
    dp[n] = 0;
    ld res = solve(1, 0);
    FOR(i,1,n) {
        int pos = 0;
        ld Max = 0;
        FOR(j,0,SZ(a[i])-1) {
            int v = a[i][j].FI;
            if (dp[v] > Max) {
                Max = dp[v];
                pos = v;
            }
        }
        if (pos > 0) check[i] = pos;
    }

    FOR(i,1,n) {
        if (!check[i]) continue;
        FOR(j,1,n) dp[j] = -1;
        dp[n] = 0;
        int edge = A[i][check[i]];
        ld x = solve(1, edge);
        if (cmp(x, 0) <= 0) continue;
        // cout << i << ' ' << x << endl;
        res = min(res, x);
    }

    cout << fixed << setprecision(9) << res;
    return 0;
}


Measured memory_bytes: 6016
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[1])

ok = True
time = 0
for a, b in AB:
  time += a
  if time <= b: continue
  else:
    ok = False
    break
print("Yes" if ok else "No")

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

ll H, N;

void solve() {
    cin >> H >> N;
    vector<l_l> a(N);
    for (auto& i : a) cin >> i.first >> i.second;
    ll dp[H + 1] = { 0 };
    for (int i = 0; i < H; i++) {
		if (i && !dp[i]) continue;
		for (int j = 0; j < N; j++) {
			int k = min(H, i + a[j].first);
			if (!dp[k]) dp[k] = dp[i] + a[j].second;
			else chmin(dp[k], dp[i] + a[j].second);
		}
	}
	
	// for (auto& i : dp) cout << i << " ";
	// cout << "\n";
	cout << dp[H];
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 3708
H,W,n = map(int, input().split())
sr, sc  = map(int, input().split())
S = input()
T = input()

# 最後の状態から、後手が勝てる範囲をさかのぼって見ていく
nL, nR = 1, W
# 上下の座標逆転 上方向はインクリメントとする
sr = H + 1 - sr
nD, nU = 1, H

for s,t in zip(S[::-1],T[::-1]):
    # 青木くんは自分の領土を広げる方向
    # 動かせる駒の逆方向に領土を広げられる
    if t == "R" :nL -= 1
    elif t == "L": nR += 1
    elif t == "U": nD -= 1
    elif t == "D": nU += 1

    # 青木くんはマスの領域以上には広がらない
    if nL < 1: nL = 1
    if nR > W: nR = W
    if nD < 1: nD = 1
    if nU > H: nU = H

    # 高橋くんは領土を縮める方向
    if s == "R" :nR -= 1
    elif s == "L": nL += 1
    elif s == "U": nU -= 1
    elif s == "D": nD += 1


    if nL > nR or nD > nU:
        print("NO")
        exit()


if (nL <= sc <= nR) and (nD <= sr <= nU):
    print("YES")
else:
    print("NO")


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

using namespace std;
using ll=long long;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
        --a[i];
    }
    int c=0;
    int ans=0;
    for (int i = 0; i < n; ++i) {
        c=a[c];
        ++ans;
        if(c==1)break;
    }
    if(c==1)cout<<ans<<endl;
    else cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;
#define USINT_MAX 4294967295

int main(){
	int k,i;
	char a[100000];
	cin >> a;
	cin >> k;
	a:
	for (i = 0; k > 0; i++) {
		if(a[i]!='a'){
			if ('z' + 1 - a[i] <= k) { k -= ('z' + 1 - a[i]); a[i] = 'a'; }
	}
		if (a[i+1] == 0) {
			if (k > 26)k = k % 26;
			for (int j = 0;k>0; j++) {
				if (a[i - j] + k <= 'z') {
					a[i - j] += k; k=0;
				}
				if(a[i - j] + k>'z'){ k -= ('z' - a[i - j]); a[i-j] = 'z'; }
				if ((i - j) == 0)goto a;
			}
		}
	}
	for (i = 0; a[i] != 0; i++) {
		cout << a[i];
	}
	return 0;
}

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

using namespace std;

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    set<long long> a = {1,3,2};

    long long b;

    cin >> b;

    long long c;

    cin >> c;

    a.erase(b);

    a.erase(c);

    cout << *a.begin() << '\n';

    return 0;

}



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

int main(){
  int n; cin >> n;
  string a = to_string(n);
  bool ok = false;
  for(int i = 0; i < a.size(); i++){
    if(a.at(i) == '7'){
      ok = true;
    }
  }
  if(ok){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 100010
typedef long long ll;
 
int main()
{
    ll N, M, P[MAX], A[MAX], B[MAX], C[MAX];
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
	cin >> P[i]; P[i]--;
    }
    for (int i = 0; i < N-1; i++) {
	cin >> A[i] >> B[i] >> C[i];
    }
    int dp[MAX] = {};
    for (int i = 0; i < M-1; i++) {
	ll arr[2] = {P[i],P[i+1]};
	if (P[i] > P[i+1])  swap(arr[0],arr[1]); 
	dp[arr[0]]++; dp[arr[1]]--;
    }
    for (int i = 1; i < N; i++) {
	dp[i] += dp[i-1];
    }
    ll res = 0LL;
    for (int i = 0; i < N; i++) {
	res += min(A[i]*dp[i], B[i]*dp[i]+C[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6620
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint a[114514],sum[114514];
int main()
{
	int n,ma=0;
	cin>>n;
	rep(i,n) cin>>a[i];sort(a,a+n);
	sum[0]=0;
	rep(i,n) sum[i+1]=sum[i]+a[i];
	REP(i,1,n){
		if(sum[i]*2<a[i]) ma=max(ma,i);
	}
	cout<<n-ma<<endl;
}


Measured memory_bytes: 1792
// includes, macros {{{
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <climits>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
using namespace std;

#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)

#define rep(i, s, e)    for (int i = (s); i < (int)(e); i++)
//#define PB(e) push_back(e)
//#define MP(a, b) make_pair(a, b)

// for debug
#define kita            cout << "kita\n"
#define print2(i, n)    cout << (i) << ": " << (n) << endl
#define print3(i, j, n)     cout << "(" << (i) << ", " << (j) << ") : " << (n) << endl
#define print4(i, j, n, m)  cout << "(" << (i) << ", " << (j) << ") : " << (n) << ", " << (m) << endl
#define print_mat(mat, h, w) for(int i=0;i<(h);i++){for(int j=0;j<(w);j++){cout << mat[i][j] << " ";}cout << endl;}
 
typedef long long ll;
typedef unsigned long long ull; // }}}

int W, H, N;
bool mmap[200][200];

int main(){
    cin >> W >> H >> N;
    for(int x=0;x<W;x++){
        for(int y=0;y<H;y++){
            mmap[x][y] = false;
        }
    }
    
    for(int i=0;i<N;i++){
        int X, Y, A;
        cin >> X >> Y >> A;
        switch(A){
            case 1:
                for(int x=0;x<X;x++){
                    for(int y=0;y<H;y++){
                        mmap[x][y] = true;
                    }
                }
                break;
            case 2:
                for(int x=X;x<W;x++){
                    for(int y=0;y<H;y++){
                        mmap[x][y] = true;
                    }
                }
                break;
            case 3:
                for(int x=0;x<W;x++){
                    for(int y=0;y<Y;y++){
                        mmap[x][y] = true;
                    }
                }
                break;
            case 4:
                for(int x=0;x<W;x++){
                    for(int y=Y;y<H;y++){
                        mmap[x][y] = true;
                    }
                }
                break;
        }
    }

    int ans=0;
    
    for(int x=0;x<W;x++){
        for(int y=0;y<H;y++){
            if(!mmap[x][y]) ans++;
        }
    }

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


Measured memory_bytes: 256
#include <cstdio>
#include <iterator>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <climits>
#include <string>
#include <set>
#include <numeric>
#include <bitset>
#include <cmath>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <numeric>
#include <vector>
#include <cassert>
#include <ctime>

using namespace std;
 
#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
 
using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;
using pii=pair<int, int>;
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto& p: c) os << p << " ";
	return os<<']';
}
 
void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}
 
 
template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}
 
 
constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;
constexpr int maxn=1001;
constexpr int pro=2000;

string st;

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

	while(cin>> st) {
		ll zon;
		zon = 1;
		vi arf(26, 0);
		for(int i = st.size() - 1; i >= 0; i--) {
			int ind = st[i] - 'a';
			arf[ind]++;
			zon += st.size() - i - arf[ind];
		}
		cout << zon << endl;
	}
	return 0;
}


Measured memory_bytes: 720
#include <cstdio>
#define N 200010
#define ll long long
#define mod 1000000007
using namespace std;

int h, w, a, b;
ll n[N] = {1}, m[N], ans;

inline ll pow(ll x, ll k) {
	ll ans = 1;
	while (k) {
		if (k & 1)
			ans = ans * x % mod;
		x = x * x % mod;
		k >>= 1;
	}
	return ans;
}

inline ll c(int a, int b) {
	return (n[a] * m[b] % mod) * m[a - b] % mod;
}

int main() {
	scanf("%d %d %d %d", &h, &w, &a, &b);
	for (int i = 1; i <= h + w - 2; ++i)
		n[i] = n[i - 1] * i % mod;
	m[h + w - 2] = pow(n[h + w - 2], mod - 2);
	for (int i = h + w - 3; i >= 0; --i)
		m[i] = m[i + 1] * (i + 1) % mod;
	for (int i = 1; i <= h - a; ++i)
		ans = (ans + c(b + i - 2, b - 1) * c(h - i + w - b - 1, h - i)) % mod;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 3328
n = int(input())
s = []
h = []
c = []
d = []
for i in range(n):
    a, b = input().split()
    if a == "S":
        s.append(int(b))
    if a == "H":
        h.append(int(b))
    if a == "C":
        c.append(int(b))
    if a == "D":
        d.append(int(b))
a = list(range(1,13+1))

sa = list(set(a) - set(s))
sa.sort()
for i in sa:
    print("S " + str(i))

ha = list(set(a) - set(h))
ha.sort()
for i in ha:
    print("H " + str(i))

ca = list(set(a) - set(c))
ca.sort()
for i in ca:
    print("C " + str(i))

da = list(set(a) - set(d))
da.sort()
for i in da:
    print("D " + str(i))


Measured memory_bytes: 5608
import itertools

n,m,x = map(int,input().split())
C, A = [], []
for i in range(n):
    ca = list(map(int, input().split()))
    C.append(ca[0])
    A.append(ca[1:])

min_price = 10**9
for k in range(n):
    for comb in itertools.combinations(range(n), k+1):
        sums = [0] * m
        price = 0
        for c in comb:
            price += C[c]
            for i in range(m):
                sums[i] += A[c][i]

#         print(comb)
#         print(sums)
#         print(min_price)
        if sum([y >= x for y in sums]) == m:
            min_price = min(min_price, price)

if min_price == 10**9:
    print('-1')
else:
    print(min_price)

Measured memory_bytes: 9260
d,g=map(int,input().split())
LC=[]
LB=[]
for i in range(d):
	c,b=map(int,input().split())
	LC.append(c)
	LB.append(b)
ans=sum(LC)
for i in range(1<<d):
	P=0
	c=0
	n=-1
	for j in range(d):
		if i&(1<<j):
			P+=(j+1)*100*LC[j]+LB[j]
			c+=LC[j]
		else:
			n=max(n,j)
	if P>=g:
		ans=min(ans,c)
	else:
		if n!=-1:
			for k in range(LC[n]-1):
				P+=(n+1)*100
				c+=1
				if P>=g:
					ans=min(ans,c)
print(ans)
					

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
	long long int n,k,s;
	cin>>n>>k>>s;
	
	for(int i=0;i<n;i++)
	{
		if(i<k)
		{
			cout<<s<<" ";
		}
		else
		{
			if(s!=1000000000)
			{
				cout<<s+1<<" ";
			}
			else
			{
				cout<<s-1<<" ";
			}
		}
	}
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	fast_io();
	int n,m;
	cin >> n >> m;
	vector<ll> v(n);
	cu(i,0,n)cin >> v[i];
	sort(all(v));
	vector<pii> op(m);
	cu(i,0,m)cin >> op[i].S >> op[i].F;
	sort(all(op), greater<pii>());
	int opind = 0;
	cu(i,0,n){
		if(opind < m && v[i] < op[opind].F){
			v[i] = op[opind].F;
			if(--op[opind].S == 0)++opind;
		}
		whatis(v[i]);
	}
	ll sum = accumulate(all(v), 0LL);
	cout << sum << '\n';
}


Measured memory_bytes: 1792
def with_prev(filt, prev, ad=None):
  def _filt(x):
    nonlocal prev
    if filt(x, prev):
      prev = x
      return ad(x) if ad else True
    return False
  return _filt

def solve():
  N, K, C = map(int, input().split())
  workable = [i for i, s in enumerate(input(), 1) if s=="o"]
  
  if len(workable) == K:
    return workable
  
  filt = with_prev((lambda x,p:p-x>C), workable[-1]+C+1)
  latest = set(filter(filt, reversed(workable)))

  if len(latest) > K:
    return []
  
  filt = with_prev((lambda x,p:x-p>C), -C-1, latest.__contains__)
  return filter(filt, workable)

print("\n".join(map(str, solve())))


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long n, k;
    cin >> n >> k;
    const long long p = int(1e9) + 7;
    long long ans = 0;
    if (k >= n + 1) {
        cout << 1 << '\n';
    } else {
        for (long long chosen = k; chosen <= n + 1; ++chosen) {
            long long upper_bound = (chosen * (2 * n - chosen + 1)) / 2;
            long long lower_bound = (chosen * (chosen - 1)) / 2;
            ans += (upper_bound - lower_bound + 1) % p;
            ans %= p;
        }
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 3656
N = int(input())
X = list(map(int,input().split()))

A = sorted(X)
f = N // 2 - 1
b = f + 1
C1 = A[f]
C2 = A[b]

for i in range(N):
  if X[i] <= C1:
    print(C2)
  elif X[i] >= C2:
    print(C1)

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

int main(){
    string s;
    cin >> s;
    if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

bool bo[400010];
int n,L,sum[400010],a[400010],tot,q[400010],l,r,fl[400010],fr[400010],pre[400010],suf[400010],t[400010],tn,Q[400010],Qn,x,nxt[400010];
pair<int,int> val[200010];
long long ans;

int main()
{
	scanf("%d%d",&n,&L),a[0]=a[n+1]=-1;
	for (int i=1; i<=n; i++) scanf("%d",&a[i]),val[i]=make_pair(a[i],i),fl[i]=fr[i]=1;
	sort(val+1,val+1+n),l=200000,r=l-1,suf[0]=1,pre[n+1]=n,tot=n+1,ans=n;
	for (int i=1; i<=n; i++) q[++r]=val[i].second,pre[i]=i-1,suf[i]=i+1;
	while (l<=r)
	{
		int R=l;
		while (R<r&&a[q[R+1]]==a[q[l]]) R++;
		for (int i=l; i<=R; i++) if (!bo[q[i]])
		{
			x=q[i];
			while (a[pre[x]]==a[x]) x=pre[x];
			t[tn=1]=x,bo[x]=1;
			while (a[suf[x]]==a[x]) x=suf[x],t[++tn]=x,bo[x]=1;
			nxt[tn+1]=tn+1;
			for (int j=tn; j; j--) if (t[j]<=n) nxt[j]=j; else nxt[j]=nxt[j+1];
			sum[tn+1]=0;
			for (int j=tn; j; j--) sum[j]=sum[j+1]+fr[t[j]];
			for (int j=1; j<=tn; j++) ans+=1ll*fl[t[j]]*sum[min(max(j+L-1,nxt[j]),tn+1)];
			if (tn>=L) for (int j=1; j<=tn; j++) pre[suf[t[j]]]=pre[t[j]],suf[pre[t[j]]]=suf[t[j]];
			int pr=pre[t[1]],sf=suf[t[tn]],cnt=tn/L;
			for (int j=1; j<=cnt; j++) suf[pr]=(++tot),a[tot]=a[t[1]]+1,pre[sf]=tot,pre[tot]=pr,suf[tot]=sf,pr=tot,Q[++Qn]=tot;
			for (int j=1; j<=cnt; j++)
			{
				fr[tot-cnt+j]=0;
				for (int k=j*L; k<(j+1)*L&&k<=tn; k++) fr[tot-cnt+j]+=fr[t[k]];
			}
			for (int j=cnt; j; j--)
			{
				fl[tot-cnt+j]=0;
				for (int k=tn-(cnt-j+1)*L+1; k>tn-(cnt-j+2)*L+1&&k; k--) fl[tot-cnt+j]+=fl[t[k]];
			}
		}
		l=R+1;
		for (int i=1; i<=Qn; i++) q[--l]=Q[i];
		Qn=0;
	}
	return printf("%lld\n",ans),0;
}

Measured memory_bytes: 16768
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

void sieve(bool* pn){
	for(int i=2;i<sqrt(105000.);++i){
		if(pn[i]){
			for(int j=i*2;j<105000;j+=i){
				pn[j]=false;
			}
		}
	}
}

int main(){
	int i,n,sum;
	bool pn[105000];
	memset(pn , true , sizeof(pn));
	pn[0]=false;
	pn[1]=false;
	sieve(pn);
	while(cin >> n , n){
		sum=0 ; i=2;
		while(n>0){
			if(pn[i]) {
				sum+=i;
				n--;
			}
			i++;
		}
		cout << sum << endl;
	}
	
	return 0; 
}

Measured memory_bytes: 1268
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

k = ni()
s = ns()

print(s if len(s) <= k else s[:k]+'...')

Measured memory_bytes: 9192
program main;
var 
    i, j, k, n, a, b, t : integer;
    sum : longint;
begin
    readln(n);

    sum := 0;
    for i := 1 to n do
        for j := 1 to n do
            for k := 1 to n do begin
                a := i; b := j;
                while (a <> 0) do begin
                    t := a;
                    a := b mod a;
                    b := t;
                end;

                a := k;
                while (a <> 0) do begin
                    t := a;
                    a := b mod a;
                    b := t;
                end;

                sum := sum + b;
            end;

    writeln(sum);
end.

Measured memory_bytes: 1368
a = []
b = []
n,m,l = gets.split.map(&:to_i)
n.times {a << gets.split.map(&:to_i)}
m.times {b << gets.split.map(&:to_i)}

n.times do |ni|
  l.times do |li|
    sum = 0
    m.times do |mi|
      sum += a[ni][mi] *b[mi][li]
    end
    print ' ' if li != 0
    print sum
  end
  puts
end

Measured memory_bytes: 9044
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[101];
	int i,flag=0,a,b;
	cin>>a>>b;
    cin>>s;
    for(i=0;i<=a-1;i++){
    	if((int)s[i]<48||(int)s[i]>57)
    	flag=1;
	}
	if((int)s[a]!=45)
	flag=1;
	for(i=a+1;i<=a+b;i++){
    	if((int)s[i]<48||(int)s[i]>57)
    	flag=1;
	}
	if(flag==1)
	cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 20000;

lint dp[800][800];
char mp[800][800];
lint H, W, K, sy, sx;
int main() {
	cin >> H >> W >> K;
	REP(i, H) {
		REP(j, W) {
			cin >> mp[i][j];
			if (mp[i][j] == 'S') sy = i, sx = j;
			dp[i][j] = INF;
		}
	}
	queue<plint> que;
	lint dy[4] = { 0, 1, 0, -1 }, dx[4] = { 1, 0, -1, 0 };
	dp[sy][sx] = 0;
	que.push({ sy, sx });
	while (!que.empty()) {
		plint curr = que.front(); que.pop();
		REP(k, 4) {
			lint ny = curr.first + dy[k], nx = curr.second + dx[k];
			if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
			if (mp[ny][nx] == '#') continue;
			if (dp[curr.first][curr.second] + 1 > K) continue;
			if (dp[ny][nx] > dp[curr.first][curr.second] + 1) {
				dp[ny][nx] = dp[curr.first][curr.second] + 1;
				que.push({ ny, nx });
			}
		}
	}
	lint minv = 2000;
	REP(i, H) {
		REP(j, W) {
			if (dp[i][j] == INF) continue;
			if (i == 0 || j == 0 || i == H - 1 || j == W - 1) {
				cout << 1 << endl;
				return 0;
			}
			chmin(minv, min((min(i, H - i - 1) - 1)/ K + 1, (min(j, W - j - 1) - 1)/ K + 1) + 1);
		}
	}
	cout << minv << endl;
}


Measured memory_bytes: 9256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    int a,b;
    cin >> a >> b;

    cout << (a+b)%24 << endl;

    return 0;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int avg =  (a+b) / 2;
    avg = ((a+b) % 2 != 0) ? avg + 1 : avg;
    System.out.println(avg);
  }
}


Measured memory_bytes: 21460
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#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 <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
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;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}

void solv() {

	ll n, k;
	cin >> n >> k;

	ll sum = 0;
	vector<pii> v;
	for (size_t i = 2; i <= n; i++)
	{
		for (size_t j = i + 1; j <= n; j++)
		{
			sum += 1;
		}
		v.push_back(make_pair(1, i));
	}
	if (sum < k) {
		cout << -1 << endl;
		return;
	}

	for (size_t i = 2; i <= n; i++)
	{
		for (size_t j = i + 1; j <= n && sum > k; j++)
		{
			sum--;
			v.push_back(make_pair(i, j));
		}
	}

	cout << v.size() << endl;
	for (size_t i = 0; i < v.size(); i++)
	{
		cout << v[i].first << " " << v[i].second << endl;
	}
}

int main() {
	//	COMinit();
	solv();

	return 0;
}
 

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll> 
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m,s;cin>>n>>m;
  char c;
  set<pair<ll,char>> st;rep(i,m) {cin>>s>>c;st.insert(P(s,c));}
  bool isok=true,is00=false;
  string str;rep(i,n) str+='0';
  for(P p:st) {
    if(p.first==1&&p.second=='0') is00=true;
    if(str[p.first-1]!='0') {isok=false;break;}
    str[p.first-1]=p.second;
  }
  ll ans=0;
  if(!isok) ans=-1;
  else {
    if(str[0]=='0'&&n>1) {
      if(is00) ans=-1;
      else {str[0]='1';ans=stoll(str);}
    }
    else ans=stoll(str);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
 
typedef long long lld;
typedef vector<lld> vlld;
typedef pair<lld,lld> pi;
typedef tuple<lld,lld,lld> tup;
const lld mod=(lld)1e9+7;
 vector<int>vis(100001,0);
 vector<lld>adj[100001];

void dfs(int s)
{
  vis[s]=1;
   for(auto i:adj[s])
   {
        if(!vis[i])
        {
          dfs(i);
        }
   }

} 

int main() {
    
   lld n,m;
   cin>>n>>m;
   lld x,y;
   
   forn(i,m)
   {
     cin>>x>>y;
     adj[x].push_back(y);
     adj[y].push_back(x);
   }
    lld c=0;

    // memset(vis,0,sizeof(vis));
   for(int i=1;i<=n;i++)
   {
        if(!vis[i])
        {
            dfs(i);
            c++;
        }
   }

   cout<<c-1<<"\n";

  
  return 0;
}

Measured memory_bytes: 10360