akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  long one = min(Q*4, min(H*2, S));
  long two = min(one*2, D);
  long ans = 0;
  ans += two * (N / 2);
  ans += one * (N % 2);
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
// Problem Code: abc176_b

#include <bits/stdc++.h>

using namespace std;

string B(string N) {
	long long sum = 0;
	for (char& c: N)
		sum += c - '0';
	return (sum % 9 == 0) ? "Yes" : "No";
}

int main() {
	string N;
	cin >> N;
	cout << B(N);
	return 0;
}

Measured memory_bytes: 3824
#include <iostream>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a == 1 && b == 2) cout << "" << 3 << "";
	else if (a == 2 && b == 1) cout << "" << 3 << "";
	else if (a == 1 && b == 3) cout << "" << 2 << "";
	else if (a == 3 && b == 1) cout << "" << 2 << "";
	else if (a == 2 && b == 3) cout << "" << 1 << "";
	else cout << "" << 1 << "";
}

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

#define ll long long
#define ar array

bool isPalindrome(string s){
    int n = s.size();
    for(int i = 0; i < n; ++i){
        if(s[i] != s[n - i - 1]){
            return false;
        }
    }
    return true;
}
void solve(){
    string s;
    cin >> s;
    int n = s.size();
    if(isPalindrome(s) && isPalindrome(s.substr(0, (n - 1) / 2)) && isPalindrome(s.substr((n + 1) / 2))){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int testCases;
    testCases = 1;
    while(testCases --){
        solve();
    }
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

void printArray(int *a, int n) {
    for (int i = 0; i < n; ++i) {
        printf("%d", a[i]);
        if (i != n - 1) printf(" ");
    }
    printf("\n");
}

void insertionSort(int *a, int n) {
    for (int i = 1; i < n; ++i) {
        printArray(a, n);
        int v = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > v) {
            a[j + 1] = a[j];
            --j;
        }
        a[j + 1] = v;
    }
}

int main(void){
    int n;
    int a[100];
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    
    insertionSort(a, n);
    
    printArray(a, n);
}



Measured memory_bytes: 2692
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=100005;
//i_am_noob
int n,a[maxn];

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	rep(n) cin >> a[i];
	sort(a,a+n);
	print1(a[n/2]-a[n/2-1]);
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

int vs[110];
int main(void) {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  REP(i, n) {
    cin >> vs[i];
    sum += vs[i];
  }
  int ct = 0;
  REP(i, n) {
    if(vs[i]*4*m >= sum) {
      ++ct;
    }
  }
  puts(ct >= m ? "Yes" : "No");
  
  return 0;
}


Measured memory_bytes: 888
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());

            String[] array = reader.readLine().split(" ");
            int diff = 0;
            for (int i = 0; i < N; i++) {
                int p = Integer.parseInt(array[i]);
                if (p != (i + 1)) {
                    diff++;
                }
            }

            if (diff <= 2) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }

}


Measured memory_bytes: 22996
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll N;
    cin>>N;
    if(N==0){
        cout<<0<<endl;
        return 0;
    }
    vector<int> ans;
    while(N!=0){
        int r;
        r=N%2;
        if(r<0) r+=2;
        ans.push_back(r);
        N=(N-r)/(-2);
    }
    reverse(ALL(ans));
    REP(i,ans.size()) cout<<ans[i];
    cout<<endl;
}

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	int n;
	cin >> n;

	int now = 0;
	int step = 1;
	ll res = 0;
	while (now < n) {
		/*
		int dist = n - now;
		if (dist - step < step + 1) {
			now += dist;
			res += 1 + dist - step;
		} else {
			now += step;
			res++;
		}
		step++;
		*/
		now += step;
		step++;
		res++;
	}


	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;

int main() {
	int n;
	while (cin >> n, n) {
		int k[5003];
		for (int i = 0;i < n;i++)cin >> k[i];

		int dp[5002];
		dp[0] = 0;
		for (int i = 1;i <= n;i++) {
			dp[i] = max(dp[i - 1] + k[i - 1], k[i - 1]);
		}

		int ans = -1800000000;
		for (int i = 1;i <= n;i++)ans = max(ans, dp[i]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
import math
import itertools
#n = int(input())
#n, d = list(input().split())
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
point = 0
i = 0
while N > point:
    i+=1
    if i==1:
        point+=K
    else:
        point+=(K-1)

print(i)


Measured memory_bytes: 14256
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

string s;
int w;

int main() {
  cin >> s;
  cin >> w;
  
  for (int i = 0; i < s.length(); i += w) cout << s[i];
  cout << endl;
}


Measured memory_bytes: 256
import java.io.*;

public class Main{
	public static void main(String[] args){
		BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
		String s;
		double v;
		double high;
		int f;
		try{
			while((s=reader.readLine()) !=null){
				v=Double.parseDouble(s);
				high = (v*v)/19.6;
				f = (int)high/5;
				System.out.println(f+2);
			}
		}catch(IOException e){
			System.out.println(e);
		}
	}
}

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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int memo[1000000];
int res(int n) {
  if(n == 0) return 0;
  if(memo[n] != -1) return memo[n];
  int ans = n;
  for(int i = 1; i <= n; i *= 6) {
    ans = min(ans, res(n - i) + 1);
  }

  for(int i = 1; i <= n; i *= 9) {
    ans = min(ans, res(n - i) + 1);
  }

  return memo[n] = ans;
}

int main() {
  int H, W;
  cin >> H >> W;
  char s[H][W];
  int dx[4] = {0, 1, -1, 0};
  int dy[4] = {1, 0, 0, -1};

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> s[i][j];
    }
  }
  int sum;
  bool flag = true;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(s[i][j] == '#') {
         sum = 0;
        for(int k = 0; k < 4; k++) {
        
          if(i + dx[k] < 0 || j + dy[k] < 0) continue;
          if(i + dx[k] >= H || j + dy[k] >= W) continue;
          if(s[i + dx[k]][j + dy[k]] == '#') { sum++; } 
        }
        if(sum == 0) { flag = false; break; }
      }
    }
  }

  if(flag) cout << "Yes";
  else cout << "No";
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+7;
ll dp[N][2];
ll arr[N];
int main(){
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++)  cin>>arr[i];
	dp[2][0]=arr[1];
	dp[2][1]=arr[2];
	for(ll i=3;i<=n;i++){
		if(i&1){
			dp[i][1]=max({dp[i-2][1],dp[i-2][0],dp[i-3][1],dp[i-3][0]})+arr[i];
			dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
		}
		else {
			dp[i][1]=max({dp[i-2][1],dp[i-2][0],dp[i-1][0]})+arr[i];
			dp[i][0]=arr[i-1]+dp[i-2][0];
		}
	}
	cout<<max(dp[n][0],dp[n][1])<<endl;
	return 0;
}

Measured memory_bytes: 8284
#include <iostream>
using namespace std;
int main()
{
  long long x, ans;
  cin >> x;
  ans = (x / 11) * 2;
  long long rem = x % 11;
  if (rem > 6)
  {
    ans += 2;
  }
  else if (rem > 0)
  {
    ans += 1;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  int B[n-1];
  for(int i = 0; i < n-1; i++){
    cin >> B[i];
  }
  int A[n];
  A[0] = B[0];
  for(int i = 1; i < n-1; i++){
    A[i] = std::min(B[i-1],B[i]);
  }
  A[n-1] = B[n-2];
  int ans = 0;
  for(int i = 0; i < n; i++){
    ans += A[i];
  }

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
import math

a, b, C = [float(_) for _ in input().split()]

S = 0.5 * a * b * math.sin(math.radians(C))
c = math.sqrt(pow(a,2) + pow(b,2) - 2 * a * b * math.cos(math.radians(C)))
L = a + b + c
h = S / a * 2
print(S)
print(L)
print(h)

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll quick_pow(ll a, ll b) {
    ll ans = 1;
    while(b) {
        if(b & 1) ans *= a;
        a *= a;
        b >>= 1;
    }
    return ans;
}

int main(void) {
    int n, p;
    while(~scanf("%d%d", &n, &p)) {
        bool flag = 0;
        for(int i = 0; i < n; ++i) {
            int x; scanf("%d", &x);
            if(x & 1) flag = 1;
        }
        if(p) {
            printf("%lld\n", flag ? quick_pow(2, n - 1) : 0);
        } else {
            printf("%lld\n", flag ? quick_pow(2, n - 1) : quick_pow(2, n));
        }
    }
}


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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

int cmp(int a, int b) {
    if (a == b) {
        return 0;
    }
    return a < b ? -1 : 1;
}

void solve() {
    int n;
    read(n);
    vt<int> a(n), b(n);
    FOR(n) {
        read(a[i], b[i]);
    }
    int x = 1, y = 1;
    FOR(n) {
        int c1;
        int c2;
        
        c1 = (x + a[i] - 1) / a[i];
        c2 = (y + b[i] - 1) / b[i];
        int c = max(c1, c2);
        x = c * a[i];
        y = c * b[i];
    }
    print(x + y);
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
//    read(tt);
    FOR(tt) {
//        write("Case #", i + 1, ": ");
        solve();
    }
    
}



Measured memory_bytes: 3640
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    string S; cin >> S;

    if(S=="Sunny")
        cout << "Cloudy" << endl;

    if(S=="Cloudy")
        cout << "Rainy" << endl;

    if(S=="Rainy")
        cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 888
subroutine heapsort(n,array)
  implicit none
  integer,intent(in) :: n
  integer(8),intent(inout) :: array(1:n)
 
  integer ::i,k,j,l
  double precision :: t
 
  if(n.le.0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n.eq.1)return

  l=n/2+1
  k=n
  do while(k.ne.1)
     if(l.gt.1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k.eq.1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(array(j).lt.array(j+1))j=j+1
        endif
        if (t.lt.array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo

  return
end subroutine heapsort


program BegC
  implicit none
  integer :: N, K, j!, sumh!, hmax(1)
  integer(8) ::sumh
  integer(8),allocatable,dimension(:) :: H

  read(*,*) N, K
  allocate(H(N))
  read(*,*) (H(j) ,j=1,N)
  

  
  
  if(K.ge.N) then
     print*, 0
     stop
  end if
  
  ! do j=1,K
  !    H(maxloc(H))=0
  ! enddo
  ! print *, sum(H)

  call  heapsort(N,H)
!  print *, H
  sumh=0
  do j=1,N-K
     sumh=sumh+H(j)
!     print *, sumh
  enddo
  
  print *,  sumh
  

end program BegC




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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define Si size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define Em empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define Fi first
#define Se second
#define Pi acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>

void FAST();
LL big_mod(LL val,LL pow,LL mod);
LL mod_inverse(LL val,LL mod);









int main()
{
//    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,n,h,l=0,ans=0;
    S("%d",&n);
    for(i=0;i<n;i++)
    {
        S("%d",&h);
        if(h >= l)
        {
            l=h;
            ans++;
        }
    }
    P("%d",ans);
    return 0;
}







void FAST()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

LL big_mod(LL val,LL pow,LL mod)
{
    LL res = 1;
    val = val % mod;
    while(pow > 0)
    {
        if(pow & 1)
        {
            res = (res*val) % mod;
        }
        pow = pow >> 1;
        val = (val*val) % mod;
    }
    return res;
}

LL mod_inverse(LL val,LL mod)
{
    LL mod1 = mod;
    if(mod == 1)
    {
        return 0;
    }
    LL y = 0;
    LL x = 1;
    LL quotient,temp;
    while(val > 1)
    {
        quotient = val / mod;
        temp = mod;
        mod = val % mod;
        val = temp;
        temp = y;
        y = x - quotient * y;
        x = temp;
    }
    if(x < 0)
    {
        x += mod1;
    }
    return x;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MAX = (int)1e9;
const int LIMIT = 31623;  //sqrt(1e9)
bool prime[LIMIT + 1];
int main() {
	int n;
	cin >> n;
	int tmp = n;
	vector<int> factr;
	fill(prime, prime + LIMIT + 1, 1);
	prime[0] = prime[1] = 0;
	for (int i = 2; i <= LIMIT; i++) {
		if (tmp < i) {
			break;
		}
		if (prime[i]) {
			while (tmp%i == 0) {
				tmp /= i;
				factr.push_back(i);
			}
			for (int k = 2; k*i <= LIMIT; k++) {
				prime[i*k] = 0;
			}
		}
	}
	if (factr.size() == 0) factr.push_back(n);
	cout << n << ":";
	for (int i = 0; i < factr.size(); i++) {
		cout << " " << factr[i];
	}
	cout << endl;
}

Measured memory_bytes: 3160
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

N = int(stdin.readline().rstrip())
result = []

while N > 0:
    result.append(stdin.readline().rstrip())
    N -= 1
    
ans = list(set(result))
print(len(ans))

Measured memory_bytes: 36416
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main(){
    let r:f64 = read();
    let s = r * r * std::f64::consts::PI;
    let a = 2 as f64 * r * std::f64::consts::PI;
    println!("{} {}", s, a);
}




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

int main() {

    int N, K, sum;
    cin >> N >> K;
    sum = 1;

    for(int i = 0; i < N; i++){
        if(sum * 2 < sum + K)
            sum *= 2;
        else
            sum += K;

    }

    cout << sum;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    ll n, k;
    cin >> n >> k;
    ll a = 0;
    ll b = 0;
    for (int i =1; i <= n; i++ ) {
        if (i % k == k/2 && k % 2 == 0) {
            a++;
        }
        else if (i % k == 0) {
            b++;
        }
    }
    ll ans = 0;
    ans = a * a * a + b * b * b;
    cout << ans  << endl;
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void mysort(vector<pll> &a){sort(a.begin(),a.end()) ;}
void myrev(vector<pll> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll x,y,r,g,n ;
	cin >> x >> y >> r >> g >> n ;
	vector<pll> a(r+g+n) ;
	for(int i=0;i<r;i++){
		cin >> a.at(i).first ;
		a.at(i).second = 0 ;
	}
	for(int i=0;i<g;i++){
		cin >> a.at(r+i).first ;
		a.at(r+i).second = 1 ;
	}
	for(int i=0;i<n;i++){
		cin >> a.at(r+g+i).first ;
		a.at(r+g+i).second = 2 ;
	}
	mysort(a) ;
	myrev(a) ;
	ll cntr = 0 ;
	ll cntg = 0 ;
	ll cntn = 0 ;
	ll sum = 0 ;
	for(int i=0;i<r+g+n;i++){
		if(cntr+cntg+cntn==x+y) break ;
		if(a.at(i).second==0){
			if(cntr!=x){
				cntr++ ;
				sum += a.at(i).first ;
			}
		}else if(a.at(i).second==1){
			if(cntg!=y){
				cntg++ ;
				sum += a.at(i).first ;
			}
		}else{
			cntn++ ;
			sum += a.at(i).first ;
		}
	}
	cout << sum << endl ;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cin, cout の高速化
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i <= (n); i++)
const ll INF = 1e15;

int main()
{
    int N;
    cin >> N;
    REP(i,N/4+1){
        REP(j,N/7+1){
            if(i*4+j*7==N){
                cout << "Yes" <<endl;
                return 0;
            }
        }
    }

    cout << "No" <<endl;

}

Measured memory_bytes: 256
import collections
N = int(input())
S = [list(input()) for i in range(N)]

for i in range(N):
    Si = S[i]
    Si.sort()
    Si2 = ''.join(Si)
    S[i] = Si2

ans = 0
Sc = collections.Counter(S).most_common()
for s in Sc:
    ans += s[1]*(s[1]-1)//2

print(ans)

Measured memory_bytes: 37012
#include<bits/stdc++.h>
using namespace std;
long long dp[55][55][2505];
long long X[55];
int main()
{
	int N,A;
	cin>>N>>A;
	for(int i=0;i<N;i++)
		cin>>X[i];
	dp[0][0][0]=1;
	for(int i=0;i<N;i++)
		for(int j=0;j<=i+1;j++)
			for(int k=0;k<=2500;k++)
				if(dp[i][j][k])
				{
					dp[i+1][j][k]+=dp[i][j][k];
					dp[i+1][j+1][k+X[i]]+=dp[i][j][k];
				}
	long long ans=0;
	for(int i=1;i<=N;i++)
		ans+=dp[N][i][i*A];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 53504
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int N,M,K,a,b;
	int ans;
	cin>>N>>M>>K;
	long long int A[N+1]={0},B[M+1]={0};
	cin>>A[1];
	for(int i=2;i<=N;i++){
		cin>>a;
		A[i]=A[i-1]+a;
	}
	cin>>B[1];
	for(int i=2;i<=M;i++){
		cin>>b;
		B[i]=B[i-1]+b;
	}
	ans=0;
	a=M;
	for(int i=0;i<=N;i++){
		for(;A[i]+B[a]>K;a--){}
		if(a<0)break;
		ans=max(i+a,ans);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6684
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

signed main(){
  int n;cin>>n;string s;cin>>s;
  int a[26];rep(i,26)a[i] = 0;
  rep(i,n){
    a[s[i]-'a']++;
  }
  int ans = 1;
  rep(i,26){
    ans *= a[i]+1;
    ans %= MOD;
  }
  cout << ans-1 << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	int N, H, W;
	Scanner sc=new Scanner(System.in);

	public void run(){
		N=sc.nextInt();
		
		while (N-- != 0) {
			H=sc.nextInt();
			W=sc.nextInt();
			char[][] map=new char[30][30];
			
			int ph=-1,pw=-1;
			sc.nextLine();
			for(int h=0;h<H;h++){
				String s=sc.nextLine();
				map[h]=s.toCharArray();
				for(int w=0;w<W;w++) {
					if (map[h][w] == '^' || map[h][w] == '<' || map[h][w] == '>'
							|| map[h][w] == 'v') {
						ph=h;pw=w;
					}
				}
			}
			int M=sc.nextInt();sc.nextLine();
			String ops=sc.nextLine();
			for(int m=0;m<M;m++) {
				char op=ops.charAt(m);
				switch (op) {
				case 'S':
					switch (map[ph][pw]) {
					case '^':
						for (int h = ph - 1; h >= 0; h--) {
							if (map[h][pw] == '*') {
								map[h][pw] = '.';
								break;
							}
							if (map[h][pw] == '#') {
								break;
							}
						}
						break;
					case 'v':
						for (int h = ph + 1; h < H; h++) {
							if (map[h][pw] == '*') {
								map[h][pw] = '.';
								break;
							}
							if (map[h][pw] == '#') {
								break;
							}
						}
						break;
					case '<':
						for (int w = pw - 1; w >= 0; w--) {
							if (map[ph][w] == '*') {
								map[ph][w] = '.';
								break;
							}
							if (map[ph][w] == '#') {
								break;
							}
						}
						break;
					case '>':
						for (int w = pw + 1; w < W; w++) {
							if (map[ph][w] == '*') {
								map[ph][w] = '.';
								break;
							}
							if (map[ph][w] == '#') {
								break;
							}
						}
						break;
					}
					break;
				case 'U':
					map[ph][pw] = '^';
					if (ph >= 1 && map[ph - 1][pw] == '.') {
						map[ph][pw] = '.';
						map[ph - 1][pw] = '^';
						ph--;
					}
					break;
				case 'D':
					map[ph][pw] = 'v';
					if (ph < H - 1
							&& map[ph + 1][pw] == '.') {
						map[ph][pw] = '.';
						map[ph + 1][pw] = 'v';
						ph++;
					}
					break;

				case 'R':
					map[ph][pw] = '>';
					if (pw < W - 1
							&& map[ph][pw + 1] == '.') {
						map[ph][pw] = '.';
						map[ph][pw + 1] = '>';
						pw++;
					}
					break;
				case 'L':
					map[ph][pw] = '<';
					if (pw >= 1 && map[ph][pw - 1] == '.') {
						map[ph][pw] = '.';
						map[ph][pw - 1] = '<';
						pw--;
					}
					break;
				}
			}
			for(int h=0;h<H;h++){ 
				for(int w=0;w<W;w++){
					pr(map[h][w]);
				}
				ln();
			}
			if(N>0)ln();
		}

	}	
	public static void main(String[]_){
		new Main().run();
	}
	
	
	public static void pr(Object o){
		System.out.print(o);
	}
	
	public static void ln(Object o){
		System.out.println(o);
	}
	public static void ln(){
		System.out.println();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

set<int> s;

bool isOk(int n)
{
    while (n > 0)
    {
        int mod = n % 10;
        if(s.count(mod))
            return false;
        n = n / 10;
    }
    return true;
}

int main()
{
    int n, k;
    cin >> n >> k;
    for(int i = 0, x; i < k; i++)
    {
        cin >> x;
        s.insert(x);
    }
    while(1)
    {
        if(isOk(n))
            break;
        n++;
    }
    cout << n;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        int N = cin.Nextint;
        var P = cin.Scanint.Select(i => i - 1).ToArray();
        var A = Enumerable.Range(0, N).Select(i => i * N + 1).ToArray();
        var B = A.Reverse().ToArray();
        for (int i = 0; i < N; i++)
        {
            A[P[i]] += i;
        }
        WriteLine($"{string.Join(" ", A)}\n{string.Join(" ", B)}");
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 21852
import re

def gcd(x, y):
    if x == y:
        return x
    if x < y and y % x == 0:
        return x
    if x > y and x % y == 0:
        return y
    if x <= y:
        m = y % x
        return gcd(x, m)
    if x >= y:
        m = x % y
        return gcd(y, m)

    l = list(range(1, int(min(x, y) / 2) + 1))
    l.reverse()
    r = 1
    for i in l:
        if x % i == 0 and y % i == 0:
            return i
    return 1
 
x, y = map(int, re.split(' ', raw_input()))
print(gcd(x, y))

Measured memory_bytes: 6404
#include <stdio.h>
#include <inttypes.h>

int N, K;
int H[512];

/* [最初, 2番目) */
int64_t sakugenTable[512][512];

int64_t memo[512][512];

int64_t search(int pos, int stock) {
	int64_t answer;
	int i;
	if (pos > N) return 0;
	if (memo[pos][stock]) return ~memo[pos][stock];

	/* 使わない */
	answer = search(pos + 1, stock);
	/* 使う */
	for(i = 1; i <= stock && pos + i <= N + 1; i++) {
		int64_t candidate = search(pos + i + 1, stock - i) + sakugenTable[pos][pos + i];
		if (candidate > answer) answer = candidate;
	}

	return ~(memo[pos][stock] = ~answer);
}

int main(void) {
	int i, j;
	int64_t all_cost;
	if (scanf("%d%d", &N, &K) != 2) return 1;
	for (i = 1; i <= N; i++) {
		if (scanf("%d", &H[i]) != 1) return 1;
	}
	H[0] = H[N + 1] = 0;
	for (i = 1; i <= N; i++) {
		int64_t sum = 0;
		for (j = i; j <= N + 1; j++) {
			if (H[j] < H[j - 1]) sum += H[j - 1] - H[j];
			sakugenTable[i][j] = sum + H[j];
		}
	}
	all_cost = sakugenTable[1][N + 1];
	for (i = 1; i <= N; i++) {
		for (j = i; j <= N + 1; j++) {
			int64_t after_cost = (H[i - 1] >= H[j]) ? H[i - 1] : H[j];
			sakugenTable[i][j] -= after_cost;
		}
	}
	printf("%" PRId64 "\n", all_cost - search(1, K));
	return 0;
}

/*

Nが十分小さいので、以下の方法が使えそう

1. 各区間全部について、そこの両側を変えずにそこを変えたときにコストをどれだけ削減できるかを計算する
   O(N^2 * 計算のコスト)
2. それを用いてDP
   O(N^3)

コストを削減するには、余計な穴を埋めるとよい
→ 両端を見てどっちかに合わせればよい

変更後コスト = 両端のうち塗る行が少なくない方の行数
変更前コスト = ？

止まる行数を加算していく O(N)

*/


Measured memory_bytes: 3456
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,ans=0,t,x=0,y=0,z=0;
    cin>>a;
    cin>>b;
    cin>>c;
    cin>>t;
    while(x<=a)
    {
        y=0;
        while(y<=b)
        {
            z=0;
            while(z<=c)
            {
                if (x*500+y*100+z*50==t) ans=ans+1;
                if (x*500+y*100+z*50>t) break;
                z=z+1;
            }
            y=y+1;
        }
        x=x+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(s) for s in input().split()]
B = [0 for i in range(N)]
def nC2(n):
  return n*(n-1)//2
for i in range(N):
  B[A[i]-1] += 1
Ctot = 0
for i in range(N):
  Ctot += nC2(B[i])
for i in range(N):
  current_idx = A[i]-1
  if B[current_idx] == 1:
    count = Ctot
  else:
    count = Ctot + nC2(B[current_idx]-1) - nC2(B[current_idx])
  print(count)

Measured memory_bytes: 26140
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int a,b,c,d,n;
	cin>>n;
		d=n%10;
		c=(n/10)%10;
		b=(n/100)%10;
		a=n/1000;
		if(a+b+c+d==7){cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;}
		else if(a+b+c-d==7){cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;}
		else if(a+b-c+d==7){cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;}
		else if(a+b-c-d==7){cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;}
		else if(a-b+c+d==7){cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;}
		else if(a-b-c+d==7){cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;}
		else if(a-b+c-d==7){cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;}
		else if(a-b-c-d==7){cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;}
	return 0;
}

Measured memory_bytes: 256
n,m=map(int, input().split(" "))
tower=list(map(int, input().split(" ")))
road=[list(map(int, input().split(" "))) for i in range(m)]
kosuu = [0 for i in range(n)]
temp = [0 for i in range(n)]
ans=0
for i in range(m):
  kosuu[road[i][0] - 1] += 1
  kosuu[road[i][1] - 1] += 1
for i in range(m):
  if tower[road[i][0] - 1] > tower[road[i][1] - 1]:
    temp[road[i][0] - 1] += 1
  elif tower[road[i][0] - 1] < tower[road[i][1] - 1]:
    temp[road[i][1] - 1] += 1
count = 0
for i in range(n):
  #print(n)
  if kosuu[i] == temp[i]:
    count += 1
print(count)

Measured memory_bytes: 32808
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M, K;
  cin>>N>>M>>K;
  bool can = false;
  for(int i=0;i<=N;++i){
    for(int j=0;j<=M;++j){
      if(i*M+j*N-i*j*2==K) can = true;
    }
  }
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
using namespace std;
int D, N, a[111], e[111], r[111], dp[111][111];
int main() {
	while (cin >> D >> N, D | N) {
		for (int i = 0; i < N; i++) cin >> a[i] >> e[i] >> r[i];
		int maxr = *max_element(r, r + N);
		for (int i = 0; i <= D; i++) fill(dp[i], dp[i] + maxr + 1, 999999999);
		dp[0][0] = 0;
		for (int i = 0; i < D; i++) {
			for (int j = 0; j <= maxr; j++) {
				for (int k = 0; k < N; k++) {
					if (j < r[k]) continue;
					int p = min(j + e[k], maxr), q = min(i + a[k], D);
					dp[q][p] = min(dp[q][p], dp[i][j] + 1);
				}
			}
		}
		int ret = *min_element(dp[D], dp[D] + maxr + 1);
		if (ret == 999999999) cout << "NA" << endl;
		else cout << ret << endl;
	}
}

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

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

	string N;
	int i,j;
	int tmp;
	string answer;
	int counter=0;
	double ave;
	vector<int> given;

	cin >> N;

	if(N[0]=='S'){
		answer="Cloudy";
	}else if(N[0]=='C'){
		answer="Rainy";
	}else{
		answer="Sunny";
	}
	cout << answer << endl;

	return 0;
}



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

long long Q, dp[60][200009], A[2000009];

void init() {
	for (int i = 1; i <= 2000000; i++) {
		long long V1 = A[i - 1] + 1;
		long long V2 = 1LL * i * (i - 1) / 2LL + 1;
		A[i] = V1 + V2 - 1; if (A[i] >= (1LL << 61)) A[i] = (1LL << 61);
	}
	for (int i = 1; i <= 200000; i++) {
		long long V1 = dp[4][i - 1] + 1;
		long long V2 = A[i - 1] + 1;
		dp[4][i] = V1 + V2 - 1; if (dp[4][i] >= (1LL << 61)) dp[4][i] = (1LL << 61);
	}
	for (int i = 5; i < 60; i++) {
		for (int j = 1; j < 200000; j++) {
			long long V1 = dp[i][j - 1] + 1;
			long long V2 = dp[i - 1][j - 1] + 1;
			dp[i][j] = V1 + V2 - 1; if (dp[i][j] >= (1LL << 61)) dp[i][j] = (1LL << 61);
		}
	}
}

long long score(long long x, long long y) {
	// x 個の卵で y 回の操作
	if (x == 1) return y;
	if (x == 2) {
		if (y >= 2000000000) return (1LL << 61);
		return y * (y + 1) / 2;
	}
	if (x == 3) {
		if (y >= 2000000) return (1LL << 61);
		return A[y];
	}
	if (y >= 200000) return (1LL << 61);
	return dp[x][y];
}

int main() {
	cin >> Q; init();
	for (int i = 1; i <= Q; i++) {
		long long N, E; cin >> N >> E;
		
		long long L = 1, R = (1LL << 60), M, minx = (1LL << 60);
		for (int j = 1; j <= 80; j++) {
			M = (L + R) / 2;
			if (score(E, M) >= N) { R = M; minx = min(minx, M); }
			else L = M;
		}
		cout << minx << endl;
	}
	return 0;
}


Measured memory_bytes: 106236
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

X, Y = map(int, input().split())

for turu in range(0, X+1):
    kame = X - turu

    ashi = turu * 2 + kame * 4
    if ashi == Y:
        print('Yes')
        quit()
print('No')

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

int main() {
	int d[7];
	string q;
	cin >> d[1] >> d[2] >> d[3] >> d[4] >> d[5] >> d[6] >> q;
	for (int i = 0; i < q.length(); i++) {
	    int o;
	    if (q[i] == 'N') {
	        o = d[1];
	        d[1] = d[2];
	        d[2] = d[6];
	        d[6] = d[5];
	        d[5] = o;
	    } else if (q[i] == 'W') {
	        o = d[1];
	        d[1] = d[3];
	        d[3] = d[6];
	        d[6] = d[4];
	        d[4] = o;
	    } else if (q[i] == 'S') {
	        o = d[1];
	        d[1] = d[5];
	        d[5] = d[6];
	        d[6] = d[2];
	        d[2] = o;
	    } else {
	        o = d[1];
	        d[1] = d[4];
	        d[4] = d[6];
	        d[6] = d[3];
	        d[3] = o;
	    }
	}
	cout << d[1] << endl;
}



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

int main(){
  int n , count = 0 , x;
  cin>>n;
  for(int i = 0; i < n; i++){
      cin>>x;
     if((i + 1) % 2 != 0 && x % 2 != 0){
         count++;
     }
  }
  cout<<count<<endl;
    return 0;
}



Measured memory_bytes: 3584
// E - Divisible Substring
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rep(i,n) for(int i=0;i<(n);++i)

ll N,P;
string S;

ll solve(){
	vl s(N);
	rep(i,N) s[i] = S[i]-'0';

	if(P==2 || P==5){
		ll ret = 0;
		rep(i,N){ // 文字位置: i: 左から, n-1-i:右から (0 基準)
			ll lsd = s[N-1-i]; //最下位桁
			if(lsd % P == 0) ret += N - i; // LSD が割り切れたら LSD から右の桁数分加算
		}
		return ret;
	}

	ll ten = 1; // S[l,r) のときの 10^r, init r=0 -> 10^0 = 1
	vl cnt(P, 0); // 余りで仕分けして個数を集計
	ll r = 0; // 左からの文字数 0 のときの余り
	cnt[r]++; // 余りが同じものをカウント
	rep(i,N){ // 文字位置: i: 左から, n-1-i:右から (0 基準)
		ll msd = s[N-1-i]; // 最上位桁
		r = (msd*ten + r) % P; // r: 今回の余り
		ten = ten*10 % P; // N≦2*10^5 桁 なので剰余計算忘れずに！
		cnt[r]++; // 余りが同じものをカウント
	}

	ll ret = 0;
	rep(r,P) ret += cnt[r] * (cnt[r]-1) / 2; // nCr(n=i,r=2)= n(n-1)/2
	return ret;
}

int main(){
	cin>>N>>P>>S;
	cout<< solve() <<endl;
}

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

int main()
{
    char y[][4] = {"MON","TUE","WED","THU","FRI","SAT","SUN"},s[4];
    scanf("%s",s);
    int i;
    for (i = 0; i < 6; i++)
    {
        if(strcmp(y[i],s) == 0)break;
    }
    printf("%d",i == 6 ? 7: 6 - i);
    
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <string>
#include<iomanip>
#include<limits>
using namespace std;
int main(void){
    long long int a,b;
    cin>>a>>b;
    long long int A=0,B=0;
    for(int i=0;i<b;i++){
        A+=a*pow(10,i);
    }
    for(int i=0;i<a;i++){
        B+=b*pow(10,i);
    }
    if(a>b){
        cout<<B<<endl;
    }
    else{
        cout<<A<<endl;
    }
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string s;
  cin >> s;
  string ans = "Yes";
  REP(i, s.size()) {
    if (i % 2 == 0) {
      if (s[i] == 'L') ans = "No";
    } else {
      if (s[i] == 'R') ans = "No";
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int64_t count_solve(int64_t n, int64_t k, int64_t b, int64_t d) {
    if (k == 0) {
        return (b / d) * n;
    }
    if (k >= d || b >= d) {
        return ((k / d) * (n - 1) + 2 * (b / d)) * n / 2 + count_solve(n, k % d, b % d, d);
    }
    return count_solve((k * n + b) / d, d, (k * n + b) % d, k);
}
int main() {
  int t;
  std::cin >> t;
  while (t--) {
    int64_t n,m,a,b;
    std::cin>>n>>m>>a>>b;
    std::cout<<count_solve(n,a,b,m)<<'\n';
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    string s = to_string(i);
    if (s.size() % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

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

  list<pair<int, int>> C;
  for (int i = 0; i < N; ++i)
    C.push_back(make_pair(A[i], B[i]));
  C.sort();

  priority_queue<int> pq;
  int ans = 0;
  for (int i = 1; i <= M; ++i) {
    if (!C.empty()) {
      while (C.front().first == i) {
        pq.push(C.front().second);
        C.pop_front();
        if (C.empty())
          break;
      }
    }

    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 4740
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template<class T1,class T2,class BiOp1,class BiOp2,class BiOp3>
struct LazySegmentTree {
	//BiOp1:T1×T1->T1
	//BiOp2:T2×T2->T2
	//BiOp3:T1×T2->T1
	vector<T1> data;
	vector<T2> lazy;
	T1 e1;
	T2 e2;
	BiOp1 op1;
	BiOp2 op2;
	BiOp3 op3;
	int size;
	LazySegmentTree(int n, T1 e1, T2 e2, BiOp1 op1, BiOp2 op2, BiOp3 op3) :e1(e1), e2(e2), op1(op1), op2(op2), op3(op3) {
		size = 1;
		while (size < n) size *= 2;
		data.resize(size * 2 - 1);
		lazy.resize(size * 2 - 1);
		for (int i = 0; i < size * 2 - 1; i++) {
			data[i] = e1;
			lazy[i] = e2;
		}
	}
	void push(int k) {
		if (lazy[k] == e2) return;
		if (k < size) {
			lazy[k * 2 + 1] = op2(lazy[k * 2 + 1], lazy[k]);
			lazy[k * 2 + 2] = op2(lazy[k * 2 + 2], lazy[k]);
		}
		data[k] = op3(data[k], lazy[k]);
		lazy[k] = e2;
	}
	T1 query(int a, int b, int k, int l, int r) {
		if (b <= l || r <= a) return e1;
		if (a <= l && r <= b) return op3(data[k], lazy[k]);
		push(k);
		return op1(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
	}
	void update(int a, int b, T2 v, int k, int l, int r) {
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] = op2(lazy[k], v);
			return;
		}
		push(k);
		update(a, b, v, k * 2 + 1, l, (l + r) / 2);
		update(a, b, v, k * 2 + 2, (l + r) / 2, r);
		data[k] = op1(op3(data[k * 2 + 1], lazy[k * 2 + 1]), op3(data[k * 2 + 2], lazy[k * 2 + 2]));
	}
};
struct Update {
	int operator()(int a, int b) const {
		return b;
	}
};
struct Min {
	int operator()(int a, int b) const {
		return min(a, b);
	}
};
struct Apply {
	int operator()(int a, int b) const {
		if (b == -1) return a;
		return b;
	}
};
int main() {
	int n, q;
	cin >> n >> q;
	LazySegmentTree<int, int, Min, Update, Apply> S(n, (1LL << 31) - 1, -1, Min(), Update(), Apply());
	for (int i = 0; i < q; i++) {
		int type;
		int s, t, x;
		cin >> type;
		if (type == 0) {
			cin >> s >> t >> x;
			t++;
			S.update(s, t, x, 0, 0, S.size);
		}
		else {
			cin >> s >> t;
			t++;
			cout << S.query(s, t, 0, 0, S.size) << endl;
		}
	}

}


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

int main() {
  int k;
  cin >> k;
  if(k % 2 == 0) cout << (k / 2) * (k / 2) << "\n";
  else cout << (k / 2) * (k / 2 + 1) << "\n";
}


Measured memory_bytes: 3608