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

using namespace std;

int func(int i)
{
    if(i%2)
        return 0;
    return 1+func(i/2);
}

int main()
{
    int n,ans;
    scanf("%d", &n);

    int mx=0;

    for(int i=1; i<=n; i++)
    {
        int x=func(i);

        if(x>=mx)
        {
            mx=x;
            ans=i;
        }
    }

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N;
    ll K;
    cin >> N >> K;
    vector<int> P(N);
    vector<ll> C(N);
    REP(i, N) {
        cin >> P[i];
        P[i]--;
    }
    REP(i, N) {
        cin >> C[i];
    }
    ll res = -1000000000;
    REP(s, N) {
        int i = s;
        vector<ll> csum(1, 0), cmax(1, -1000000000);
        while (true) {
            i = P[i];
            ll tmp = csum.back() + C[i];
            csum.push_back(tmp);
            tmp = max(tmp, cmax.back());
            cmax.push_back(tmp);
            if (i == s) break;
        }
        if (K < csum.size()) {
            res = max(res, cmax[K]);
        } else {
            ll a = K / (csum.size() - 1);
            ll b = K % (csum.size() - 1);
            ll tmp = 0;
            if (csum.back() > 0) {
                tmp += csum.back() * a;
                if (b > 0) {
                    if (cmax[b] > 0) {
                        tmp += cmax[b];
                    }
                }
                tmp = max(tmp, csum.back() * (a - 1) + cmax.back());
            } else {
                tmp = cmax.back();
            }
            res = max(res, tmp);
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		int count = 0;
		int tmp = i;
		while(tmp) {
			tmp /= 10;
			count++;
		}
		
		ans += count % 2;
	}
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

int total,A,B,C,X,Y,temp;

void func(int x,int temp,int C,int &total) {
	//cout << x << temp << endl;
	//cout << C << endl;
	int temp_x = temp * x;
	int temp_C = temp * C * 2;
	//cout << temp_x << temp_C << endl;
	if (temp_x > temp_C) {
		total += temp_C;
		//cout << temp_C << endl;
		//cout << total << endl;
	}
	else {
		total += temp_x;
		//cout << temp_x << endl;
		//cout << total << endl;
	}
}

int main() {
	//入力
	int A = 0, B = 0, C = 0, X = 0, Y = 0;
	cin >> A >> B >> C >> X >> Y;
	int total = 0;
	//処理
	if (A + B > C * 2) {
		if (X > Y) {
			total += C * Y * 2;//1600 * 2 * 2 = 6400
			int temp = X - Y;//1
			/*
			if (temp * A > temp * C) {
				total += temp * C;
			}
			else {
				total += temp * A;
			}
			*/
			func(A,temp,C,total);
		}
		else {
			total += C * X * 2;
			int temp = Y - X;
			/*
			if (temp * B > temp* C) {
				total += temp * C;
			}
			else {
				total += temp * B;
			}
			*/
			func(B, temp,C,total);
		}
	}
	else {
		if (X > Y) {
			total += A * Y + B * Y;
			int temp = X - Y;
			func(A, temp, C, total);
		}
		else {
			total += A * X + B * X;
			int temp = Y - X;
			func(B, temp, C, total);

		}
	}

	//出力
	cout << total << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{ int n;
cin>>n;
double p[n];
for(int i=0;i<n;i++) cin>>p[i];
double dp[n][n+1];
dp[0][0]=1-p[0];
dp[0][1]=p[0];
for(int i=1;i<n;i++)
for(int j=0;j<=i+1;j++) 
if(j==0) dp[i][0]=(1-p[i])*dp[i-1][0];
else dp[i][j]=p[i]*dp[i-1][j-1]+(1-p[i])*dp[i-1][j];

double ans=0;
for(int i=ceil(n/2.0);i<=n;i++) ans+=dp[n-1][i];

cout<<setprecision(10)<<ans;
return 0;
}


Measured memory_bytes: 69888
using System;
using System.Text;

public class Test
{
	static public void Main( )
	{
		int[] nm = Array.ConvertAll( Console.ReadLine().Split( ' ' ), int.Parse );
		int n = nm[0];
		int m = nm[1];
		int[,] a = new int[ n, m ];
		int[] b = new int[ m ];
		int[] c = new int[ n ];		
		for( int i=0; i<n; i++ ) {
			int[] row = Array.ConvertAll( Console.ReadLine().Split( ' ' ), int.Parse );
			for( int j=0; j<m; j++ ) {
				a[ i, j ] = row[j];
			}
		}
		for( int i=0; i<m; i++ ) {
			b[i] = int.Parse( Console.ReadLine() );
		}
		StringBuilder output = new StringBuilder();
		for( int i=0; i<n; i++ ) {
			for( int j=0; j<m; j++ ) {
				c[i] += ( a[ i, j ] * b[j] );
			}
			output.AppendLine( string.Format( "{0}", c[i] ) );
		}
		Console.Write( output );
	}
}

Measured memory_bytes: 20156
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int K = sc.nextInt();

		String[] array = S.split("");

		String X = array[K - 1];

		for (int i = 0; i < array.length; i++) {
			if(!( array[i].equals(X))){
				array[i] = "*";
			}

		}

		for (String string : array) {
			System.out.print(string);
		}

	}

}


Measured memory_bytes: 23764
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
#define INF 1 << 30
#define MOD 1000000007;
#define pi 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
static const int dx[] = {0, 0, 1, -1};
static const int dy[] = {-1, 1, 0, 0};

int main() { 
  int a, b;
  cin >> a >> b;
  a += b;
  D(a % 24);
  return 0;
}



Measured memory_bytes: 256
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    for i in range(N-K):
        if A[i] < A[i+K]:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 33132
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  sort(A.begin(), A.end());
  int t = 0, c = 0;
  while(t < N && !A[t]) ++t;
  vector<int> B(t,0);
  if(t < N && t%2){
    B.push_back(0);
    B[1] = A[t];
    ++t;
  }
  while(t + c < N && A[t+c] == 1){
    ++c;
  }
  if(t + c + 2 <= N && A[N-1] == 3 && A[N-2] == 2){
    B.push_back(2);
    B.push_back(3);
    N -= 2;
  }
  reverse(B.begin(), B.end());
  for(int i = t + c; i < N; ++i) cout << A[i] << endl;
  for(int i = 0; i < B.size(); ++i) cout << B[i] << endl;
  for(int i = 0; i < c; ++i) cout << 1 << endl;
  return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const ll mod = 1e9 + 7;

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

   int n;
   cin >> n;
   vector <vector <int>> adj(n + 1);
   for (int i = 0; i < n - 1; i++) {
      int x, y;
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
   }

   vector <pair <ll, ll>> dp(n + 1, pair <ll, ll> {1, 1});
   vector <bool> vis(n + 1);

   function <void(int)> dfs = [&](int v) {
      vis[v] = true;
      for (auto u : adj[v]) {
         if (!vis[u]) {
            dfs(u);
            dp[v].ff *= (dp[u].ff + dp[u].ss) % mod;
            dp[v].ss *= dp[u].ff % mod;
            dp[v].ff %= mod;
            dp[v].ss %= mod;
         }
      }
   };

   dfs(1);

   cout << (dp[1].ff + dp[1].ss) % mod << '\n';

   return 0;
}

Measured memory_bytes: 15616
#include <iostream>
#include <vector>

std::vector< int > preprocess(int n, std::string s) {
    std::vector< int > ans(n);
    ans[0] = 0;
    for (int i=1; i<n; ++i) {
        if (s[i-1] == 'A' && s[i] == 'C') ans[i] = ans[i-1] + 1;
        else ans[i] = ans[i-1];
    }
    return ans;
}

int main() {
    int n, q;
    std::string s;
    std::vector< int > vec;
    std::cin >> n >> q >> s;
    vec = preprocess(n, s);
    for (int i=0; i<q; ++i) {
        int l, r, ans;
        std::cin >> l >> r;
        --l;  --r;
        ans = vec[r];
        if (l > 0) ans -= vec[l];
        std::cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#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)
typedef long long ll;
long long mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

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

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

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

  int ans = 0;

  ans += (x / 500) * 1000;

  ans += ((x - (x / 500) * 500) / 5) * 5;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N;
    cin >> N;
    ll ans = pow(N, 3);
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n, pcount, a, d;
	cin >> n;
	
	for(int i = 1; i <= n; i++){
		d = 0;
		cin >> a;
		if(a == 3){
			pcount++;
			continue;
		}
		for(int j = 2; j <= sqrt(a); j++){
			if(a%j == 0){
				d = 1;
				break;
			}
		}
		if(d == 0)
			pcount++;
	}
	
	cout << pcount << endl;
	
	return 0;
}

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

using namespace std;

#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int N,Q,s,t;
string S;
vi vec;

void print_vec(){
    for(auto itr = vec.begin(); itr != vec.end(); itr++)
        cout << *itr;
    cout << endl;
}

void solve(int s, int t){
    int s_id = lower_bound(vec.begin(), vec.end(), s) - vec.begin();
    int t_id = upper_bound(vec.begin(), vec.end(), t) - vec.begin();

    // printf("(%d, %d): (%d, %d)\n",s, t, s_id,t_id);

    cout << t_id - s_id << endl;
}

int main(){
    cin >> N >> Q >> S;

    for(int i = 1; i < N; i++){
        if(S[i] == 'C' && S[i-1] == 'A') vec.push_back(i-1);
    }

    // print_vec();
    
    rep(i, Q){
        cin >> s >> t;
        solve(s-1, t-2);
    }
}


Measured memory_bytes: 1276
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int i,c[3],j,temp;
    for (i=0; i<3; i++)
    {
        cin>>c[i];
    }
    for (i=0; i<2; i++)
    {
        for(j=0; j<(3-i-1); j++)
		{
			if(c[j]>c[j+1])
			{
				temp=c[j];
				c[j]=c[j+1];
				c[j+1]=temp;
			}}}
    for(i=0; i<2; i++)
    {
        cout<<c[i]<<" ";
    }
    cout<<c[i]<<endl;
}



Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String a = "";
        String ans = "";
        int sum = 0;
        for (int i = 0; i < 8; i++) {
            a = s.substring(0, 1);
            sum = Integer.parseInt(a);
            ans = a;
            for (int j = 0; j < s.length() - 1; j++) {
                a = s.substring(j + 1, j + 2);
                if ((i >> j & 1) == 0) {
                    ans += "+" + a;
                    sum += Integer.parseInt(a);
                } else {
                    ans += "-" + a;
                    sum -= Integer.parseInt(a);
                }
            }
            if (sum == 7) {
                System.out.println(ans + "=7");
                break;
            }
        }
    }
}


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

int main(){
  int N , K ; 
  cin >> N >> K ; 
  int min_A = N+1 ; 
  int cnt = 0 ; 
  
  vector<int> A(N) ; 
  for(int i = 0  ; i < N ; i++) {
    cin >> A.at(i) ; 
    if(min_A > A.at(i)){
      min_A = A.at(i)  ;
      cnt = i; 
      
    }
  }
  int ans = 0 ; 
  if((N-1)%(K-1) == 0 ){
  	cout << (N-1)/(K-1) << endl ;
  }
  else{
      	cout << (N-1)/(K-1)  + 1<< endl ;
  }
}

Measured memory_bytes: 3772
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <math.h>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>

#define MAX 100005
using namespace std;


int main(void)
{
	int table[MAX];

	int i, j;
	int n;
	int temp1, temp2;
	int max = 0;
	int count = 0;
	bool ha[MAX];

	cin >> n;

	vector <pair<int, int>> a;

	for (i = 0; i < MAX; i++) {
		table[i] = 0;
	}

	for (i = 0; i < n; i++) {
		cin >> temp1 >> temp2;
		a.push_back(make_pair(temp1, temp2));


	}

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



	for (i = 0; i <= n; i++) { //?????????????????°i????¢???????????????????????????????????????????
		count = 0;

		for (j = 0; j < n; j++) {
			if (a[j].first <= i + 1 && i + 1 <= a[j].second) {
				count++;
			}

			if (count == i) {
				max = i;
				break;
			}
		}

	}



	cout << max << endl;



	return (0);
}

Measured memory_bytes: 3792
#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>;

const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main() {
    int n;
    cin >> n;
    map<string, int> m;
    rep(i,n){
        string s;
        cin >> s;
        ++m[s];
    }
    int max = 0;
    for(auto x:m) {
        if (x.second > max) max = x.second;
    }
    for(auto x:m) {
        if(x.second == max)
            cout << x.first << endl;
    }
    return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define forn(i, a, b) for (int i = a; i < b; ++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}

int n;

int main() {
#ifdef LOCAL
  freopen("e.txt", "r", stdin);
// freopen("main.txt", "w", stdout);
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
#define endl '\n'
#define dbg(...) 18
#endif
  string a, b;
  cin >> a >> b;
  n = stoi(a + b);
  double d = sqrt(n);
  ll c = sqrt(n);
  dbg(d, c);
  if (d - c == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#define mod 1000000007
using namespace std;
int inv[2000005],jc[2000005],jcinv[2000005];
inline int C(int x,int y)
{
	return (long long)jc[x]*jcinv[y]%mod*jcinv[x-y]%mod;
}
inline int cal(int x,int y)
{
	int rtn=0;
	for(int i=1;i<=y+1;i++)
		rtn=(rtn+C(i+x,i))%mod;
	return rtn;
}
int main(int argc, char** argv) {
	inv[1]=jc[0]=jc[1]=jcinv[0]=jcinv[1]=1;
	for(int i=2;i<=2000004;i++)
	{
		jc[i]=(long long)jc[i-1]*i%mod;
		inv[i]=(long long)(mod-mod/i)*inv[mod%i]%mod;
		jcinv[i]=(long long)jcinv[i-1]*inv[i]%mod;
	}
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << ((cal(c,d)-cal(c,b-1)-cal(a-1,d)+cal(a-1,b-1))%mod+mod)%mod;
	return 0;
}

Measured memory_bytes: 26592
def primes(n)
  l = (2..n).to_a
  ps = []
  until l[0] > Math.sqrt(n)
    x = l[0]
    ps << x
    l = l.delete_if {|y| (y % x).zero?}
  end
  ps + l
end

def like2017s(n)
  primes = primes(n)

  like2017s = []
  primes.each do |p|
    like2017s << p if primes.include?((p + 1) / 2)
  end
  like2017s
end

like2017s = like2017s(100000)

q = gets.to_i
q.times do
  l, r = gets.split.map(&:to_i)
  si = like2017s.bsearch_index {|x| x >= l} || like2017s.size
  ei = like2017s.bsearch_index {|x| x > r} || like2017s.size
  puts ei - si
end

Measured memory_bytes: 3068
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string A = Console.ReadLine();
            string B = Console.ReadLine();

            if (A.Length < B.Length)
            {
                Console.WriteLine("LESS");
            }
            else if (B.Length < A.Length)
            {
                Console.WriteLine("GREATER");
            }
            else if(A.Length == B.Length)
            {
                for (int i = 0; i < A.Length; i++)
                {
                    if (int.Parse(A.Substring(i, 1)) < int.Parse(B.Substring(i, 1)))
                    {
                        Console.WriteLine("LESS");
                        return;
                    }
                    else if (int.Parse(B.Substring(i, 1)) < int.Parse(A.Substring(i, 1)))
                    {
                        Console.WriteLine("GREATER");
                        return;
                    }
                    else if(int.Parse(A.Substring(i, 1)) == int.Parse(B.Substring(i, 1)))
                    {
                        if (i == A.Length -1)
                        {
                            Console.WriteLine("EQUAL");
                            return;
                        }
                    }
                }
            }
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


//Console.WriteLine(ans);

Measured memory_bytes: 27532
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

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

  int ans = 0;
  rep(i, 3) {
    if (S[i] == T[i])
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double P,E,T;

double dfs(int k,double L,double R){
  double H=(R+L)/2,PP=H>=T ?1-P:P;
  if(k==0||(max(abs(L-T),abs(R-T))<=E))return abs(H-T)<=E;
  if(T<R-E||L+E<T)return 0;
  return PP*dfs(k-1,H,R)+(1-PP)*dfs(k-1,L,H);
}

int main(){
  double K,R,L;
  cin>>K>>R>>L>>P>>E>>T;
  printf("%.10f\n",dfs(K,L,R));
  return 0;
}

Measured memory_bytes: 1240
h, w = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
ans = [[0]*w for _ in range(h)]

idx_ls = []

flip = 0
for i in range(h):
    if not flip:
        for j in range(w):
            idx_ls.append((i, j))
    else:
        for j in range(w-1, -1, -1):
            idx_ls.append((i, j))
    flip ^= 1


for color, a in enumerate(A):
    color += 1
    for _ in range(a):
        i, j = idx_ls.pop()
        ans[i][j] = color

for x in ans:
    print(*x)

Measured memory_bytes: 4212
NM = input().split()
N = int(NM[0])
M = int(NM[1])

from collections import defaultdict
sc = defaultdict(lambda: -1)
flg = False
for i in range(M):
  scc = input().split()
  if sc[scc[0]] == -1:
    sc[scc[0]] = scc[1]
  else:
    if scc[0] == "1" and scc[1] == 0 and N != 1:
      flg = True
      break
    elif sc[scc[0]] != scc[1]:
      flg = True
      break
if not flg:
  if N == 1:
    string = ["0"]
    for key, value in sc.items():
      string[int(key)-1] = value
    string = "".join(string)
    print(string)
  else:
    string = ["0"]*N
    string[0] = "1"
    for key, value in sc.items():
      string[int(key)-1] = value
    string = "".join(string)
    if string == "0"*N:
      print(-1)
    else:
      print(string)

else:
  print("-1")


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

#define ED return 0;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) long(pow(x,y))
const long long int mod = 1000000007;
unsigned long long int gcd(unsigned long long int a, unsigned long long int b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> vec (3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
    SORT(vec)
    REV(vec)
    cout << vec.at(0) * 10 + vec.at(1) + vec.at(2) << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

string s;
int k;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    int n = s.size();
    cin >> k;
    string ans;
    rep(i, n) {
        if (s[i] == 'a') {
            ans += s[i];
        }
        else {
            int cnt = 26 - (s[i] - 'a');
            if (k >= cnt) {
                ans += 'a';
                k -= cnt;
            }
            else {
                ans += s[i];
            }
        }
    }
    if (k > 0) {
        k %= 26;
        ans[n - 1] = char(((ans[n - 1] - 'a') + k) % 26 + 'a');
    }
    cout << ans << endl;
}


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

constexpr int MOD = 1000000007;

int main() {
  int N;
  string S, T;
  cin >> N >> S >> T;
  long ans, pre, i;
  if (S.at(0) == T.at(0)) ans = 3, pre = 1, i = 1;
  else ans = 6, pre = 2, i = 2;
  for (; i < N; i++) {
    if (S.at(i) == T.at(i)) {
      if (pre == 1) ans *= 2;
      pre = 1;
    } else {
      if (pre == 1) ans *= 2;
      else ans *= 3;
      pre = 2;
      i++;
    }
    ans %= MOD;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define all(v) v.begin(), v.end()
int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a.at(i);
  sort(all(a));
  int kotae=a.at(n/2)-a.at(n/2-1);
  cout<<kotae<<endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    long long ans = 0;
    vector<int> a(n, 0);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++){
        if (i == 0) ans += a[i] / 2, a[i] %= 2;
        else {
            if (a[i - 1] % 2) {
                if (a[i] % 2) ans += (a[i] + 1) / 2, a[i] = 0;
                else if (a[i] > 0) ans += a[i] / 2, a[i] = 1;
            }
            else ans += a[i] / 2, a[i] %= 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    ll a[n+2];
    a[0]=0;
    for(int i=1;i<=n;i++) cin >> a[i];
    a[n+1]=0;
    ll sum=0;
    for(int i=0;i<n+1;i++){
        sum += abs(a[i+1]-a[i]);
    }
    for(int i=1;i<=n;i++) cout << sum + abs(a[i+1]-a[i-1])-abs(a[i]-a[i-1])-abs(a[i+1]-a[i]) << endl;
}

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

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

typedef long long ll;

typedef pair<ll, ll> P;
struct edge { ll to, cost; };

const int MAX_V =100000;
const ll INF = 1LL<<60;

int V;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(ll s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        rep(i,G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int M, A, B;
    cin >> V >> M;
    rep(i, M) {
        cin >> A >> B;
        G[A - 1].push_back({B - 1, 1});
        G[B - 1].push_back({A - 1, 1});
    }
    dijkstra(0);

    vector<int> ans(V - 1);
    for (int i = 1; i < V; i++) {
        //cout << "i=" << i << "\n";
        rep(j, G[i].size()) {
            int k = G[i][j].to;
            //cout << "d[" << k << "]=" << d[k] << "\n";
            if (d[k] < d[i]) {
                ans[i - 1] = k + 1;
                break;
            }
        }
    }
    cout << "Yes\n";
    rep(i, V - 1) {
        cout << ans[i] << "\n";
    }
}

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

int main(){
    char s[100],t[100],p;
    int i,j,m=0;

    gets(s);
    gets(t);

    for(i=0;i<strlen(s);i++){
        if(strcmp(s,t)==0){
            m++;
            break;}
        else{
            p=s[strlen(s)-1];
            for(j=strlen(s)-1;j>=0;j--){
                s[j]=s[j-1];}
            s[0]=p;}}
    if(m==0)printf("No");
    else
        printf("Yes");}


Measured memory_bytes: 1640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for(int i = l; i <= r; i++){
        if (i % d == 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <map>
#include <deque>
#include <queue>
#include <vector>
#include <algorithm>
#define maxn 105
#define inf 0x3f3f3f
using namespace std;


int main()
{
    int a,b,c;
    int f[55];
    int sum=0,ans=-inf;
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",&f[i]);
    for(a=0;a<=k;a++)
        for(b=0;b<=k;b++)
            for(c=0;c<=k;c++)
    {

        priority_queue<int >q;
        if((a+b+c)<=k&&(a+b)>=c&&a+b<=n)
        {
            sum=0;
            for(int i=0;i<a;i++)
                q.push(f[i]);
            for(int i=0;i<b;i++)
                q.push(f[n-i-1]);
            for(int i=0;i<a+b-c;i++)
            {
                sum+=q.top();
                q.pop();
            }

            ans=max(sum,ans);

        }

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


Measured memory_bytes: 3668
#include "bits/stdc++.h"
using namespace std;

int main() {
	int A,B,C,X,Y;
	cin >>  A >> B >> C >> X >> Y;
	long long int s = 99999999999;

	for(int i=0;i<=100000;i++){
		int a,b;
		a = max(0,X-i);
		b = max(0,Y-i);
		//cout << a << b;
		long long int s1 = 2*C*i + A*a + B*b;
		s = min(s,s1);
	}
	cout << s << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map> 
#include<set> 
using namespace std;
#define mid 1000000007
#include <stdio.h>
int main(){
	string s;
	cin>>s;
	if(s=="ABC")
	cout<<"ARC";
	else
	cout<<"ABC";
	return 0;
}

Measured memory_bytes: 3628
var input = require("fs").readFileSync("/dev/stdin","utf8");
var array = (input.trim()).split("\n");
var x = 0;
for (var i = 0; i < array.length; i++) {
  // array[i]?????????????????????????????°??????
  for (var a = 0; a < 10; a++) {
    for (var b = 0; b < 10; b++) {
      for (var c = 0; c < 10; c++) {
        for (var d = 0; d < 10; d++) {
          if (a + b + c + d == array[i]) {
            x += 1
          }
        }
      }
    }
  }
  console.log(x)
  x = 0
}

Measured memory_bytes: 15836
n = int(input())
a = [ int(i) for i in input().split() ]
c = [ 0 for _ in range(8)]
cou = 0

for i in range(n):
    keep=a[i]

    if 1<= keep <=399:
        c[0]=1
    elif 400<= keep <=799:
        c[1]=1
    elif 800<= keep <=1199:
        c[2]=1
    elif 1200<= keep <=1599:
        c[3]=1
    elif 1600<= keep <=1999:
        c[4]=1
    elif 2000<= keep <=2399:
        c[5]=1
    elif 2400<= keep <=2799:
        c[6]=1
    elif 2800<= keep <=3199:
        c[7]=1
    else:
        cou += 1

MAX = MIN = c.count(1)
MAX += cou
MIN = max(MIN,1)


print(MIN,MAX)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
using ll = long long;
using namespace std;
int main(){
    ll n;
    cin>>n;
    if(n%2==0){
        cout<<n<<" "<<n<<" "<<n/2<<endl;
    }/*else if(n%3==2){
        ll tmp=(n+1);
        ll tmp2=tmp/3;
        tmp*=n;
        cout<<n<<" "<<tmp2<<" "<<tmp/3;
    }*/else{
        ll afloor=(n/4)+1;
        ll aceil=3*n/4;
        for(ll i=afloor; i<=aceil; i++){
            ll d=(4*i-n);
            ll e=n*i;
            ll bfloor=max(i,e/d+1LL);
            ll bceil=2*e/d;
            for(ll j=bfloor; j<=bceil; j++){
                if( (e*j)%(d*j-e)==0){
                    cout<<i<<" "<<j<<" "<<(e*j)/(d*j-e)<<endl;
                    return 0;
                }
            }
        }

    }
    
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
 
  int i,j,k;
  int n,x;
  int count = 0;
   
 
  while(1){
    scanf(" %d %d",&n,&x);
    if(n == 0 && x == 0){
      break;
    }
   
      for(i = 1;i <= n;i++){
       for(j = i+1;j <= n;j++){
        for(k = j+1;k <= n;k++){
         if(i+j+k == x){
           count++;
         }
        }
       }
      }
 
    printf("%d\n",count);
    count = 0;
  }
  return 0;
}


Measured memory_bytes: 2048
A, B, C, X, Y = map(int, input().split())

ans = 10 ** 18
for i in range(0, 2 * max(X, Y) + 1, 2):
    tmpx = X - (i // 2)
    if tmpx <= 0:
        tmpx = 0
    tmpy = Y - (i // 2)
    if tmpy <= 0:
        tmpy = 0
    ans = min(ans, (i * C) + (tmpx * A) + (tmpy * B))

print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    int n;
    cin >> n;
    int a  =0;
    rep1(i, n+1){
        if(i%2) a++;
    }
    cout << decimal << 1.*a/n << endl;
}

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

int main(void) {
	std::string S;
	long long sum = 0;
	std::cin >> S;
	int L = S.length();
	for(int i = 0; i < L; ++i) {
		long long d = static_cast<long long>(S[L - 1 - i] - '0');
		for(int j = 0; j <= i; ++j) {
			if(j == i) {
				sum += pow(2, L - 1 - j) * pow(10, j) * d;
			} else {
				sum += pow(2, L - 2 - j) * pow(10, j) * d;
			}
		}
	}
	std::cout << sum << '\n';
	return 0;
}



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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<set<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

// int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int n, m, q;
ll ans = 0;
vector<int> a, b, c, d;

void dfs(vector<int> A){
  if(A.size() == n+1){
    ll now = 0;
    REP(i, q){
      if(A[b[i]] - A[a[i]] == c[i])now += d[i];
    }
    ans = max(ans, now);
    // REP(i, n+1){
    //   cout << A[i] << " ";
    // }cout << endl;
    return ;
  }
  A.push_back(A.back());
  while(A.back() <= m){
    dfs(A);
    A.back()++;
  }
}

int main() {

  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  REP(i, q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;


}


/*
みんな、くるくるぱーにな〜れ
　∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/


Measured memory_bytes: 3628
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		// 出力
      if((a*b)%2 == 0){
		System.out.println("Even");
      }else{
        System.out.println("Odd");
      }
	}
}

Measured memory_bytes: 35792
use std::io;
use std::io::prelude::*;
use std::iter::repeat;

struct SumSegTree {
    n: usize,
    nodes: Vec<i32>,
}

impl SumSegTree {
    fn init(n: usize) -> SumSegTree {
        let n = 1 << f64::log2(n as f64).ceil() as usize;
        SumSegTree {
            n,
            nodes: repeat(0).take(2 * n - 1).collect(),
        }
    }

    fn update1(&mut self, idx: usize) {
        self.nodes[idx] = self.nodes[2 * idx + 1] + self.nodes[2 * idx + 2];
    }

    fn update_rec(&mut self, idx: usize) {
        self.update1(idx);
        if idx > 0 {
            self.update_rec((idx - 1) / 2);
        }
    }

    fn add(&mut self, i: usize, x: i32) {
        let ni = self.n + i - 1;
        self.nodes[ni] += x;
        if self.n > 1 {
            self.update_rec((ni - 1) / 2);
        }
    }

    fn get_sum(&self, i: usize, j: usize, ni: usize, l: usize, r: usize) -> i32 {
        if i <= l && r <= j {
            self.nodes[ni]
        } else if r <= i || j <= l {
            0
        } else {
            self.get_sum(i, j, 2 * ni + 1, l, (l + r) / 2)
                + self.get_sum(i, j, 2 * ni + 2, (l + r) / 2, r)
        }
    }
}

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();

    let line0 = lines.next().unwrap().unwrap();
    let n = line0.split_whitespace().next().unwrap().parse().unwrap();

    let mut mst = SumSegTree::init(n);

    for l in lines.map(Result::unwrap) {
        let mut words = l.split_whitespace();
        let com = words.next().unwrap().parse().unwrap();
        let x: usize = words.next().unwrap().parse().unwrap();
        let y: usize = words.next().unwrap().parse().unwrap();
        match com {
            0 => mst.add(x - 1, y as i32),
            1 => println!("{}", mst.get_sum(x - 1, y, 0, 0, mst.n)),
            _ => (),
        }
    }
}



Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll h;
  cin >> h;
  ll beki = 1;
  while(h >= beki) {
    beki *= 2;
  }
  cout << beki - 1 << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <map>
#include <complex>
#include <ctime>
#include <numeric>
#include <set>

using namespace std;

typedef long long ll;

typedef struct node{
    int s, e, val, pos;
    bool operator<(const node& n) const{
        if(e != n.e) return e < n.e;
        return val > n.val;
    }
    node(){};
    node(int ss, int ee, int v, int p){
        s = ss, e = ee, val = v, pos = p;
    }
}node;

int occs[500009], tree[500009], n, ans[500009];

void update(int x, int val){
    while(x <= n){
        tree[x] += val;
        x += x & -x;
    }
}

int query(int x){
    int ret = 0;
    while(x > 0){
        ret += tree[x];
        x -= x & -x;
    }
    return ret;
}

int main()
{

    
    int q, s, e;
    vector<node> v;
    scanf("%d", &n);
    scanf("%d", &q);
    for(int i = 1; i <= n; i++){
        scanf("%d", &s);
        v.push_back(node(i, i, s, -1));
    }
    
    for(int i = 0; i < q; i++){
        scanf("%d %d", &s, &e);
        v.push_back(node(s, e, 0, i));
    }
    
    sort(v.begin(), v.end());
    
    for(int i = 0;i < v.size(); i++){
        if(v[i].val == 0){
            ans[v[i].pos] = query(v[i].e) - query(v[i].s - 1);
        }else{
            if(occs[v[i].val] != 0) update(occs[v[i].val], -1);
            update(v[i].s, 1);
            occs[v[i].val] = v[i].s;
        }
    }
    
    for(int i = 0; i < q; i++){
        printf("%d\n", ans[i]);
    }
    
    return 0;
}



Measured memory_bytes: 25372
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:usize,
    b:String,
    c:String,
    }
    let b=b.chars().collect_vec();
    let c=c.chars().collect_vec();
    for i in 0..a {
        let mut u=0;
        for j in 0..a-i {
            if b[j+i]!=c[j]{
                u=1;
            }
        }
        if u==0{
            println!("{}",a+i);
            exit(0)
        }
    }
    println!("{}",a*2)
}

Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

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

  int ans = 0;
  FOR(m,4,M+1) {
    FOR(d,1,D+1) {
      int d1 = d%10;
      int d10 = d/10;
      if (d1>=2 && d10>=2 && d1*d10==m) ans++;
    }
  }

  cout << ans << endl;
} 

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    B -=A;
    A=0;
    if(B<0) B*=-1;
    ll aru = (D-C)*(N-1)+1;
    ll nai = 2*C - (N-2)*(D-C)-1;
    ll ma = (N-1)*D;
    if(nai<=0){
        if(B<=ma){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }else{
        ll tmp = (ma-B)%(aru+nai);
        if(tmp<=aru-1){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
/*input
3
334 1000
334 1000
334 1000
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

pll a[maxn];

int main(){
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i].S>>a[i].F;
	sort(a,a+n);

	ll T=0;
	REP(i,n){
		T+=a[i].S;
		if(T>a[i].F){
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;
}


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

int main(){    
  string s,t;
  cin >> s >> t;
  rep(i,s.size()){
    if(s.at(i) != t.at(i)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

int main()
{
	int n;
	long long a;
	long long max=-1000000;
	long long min=1000000;
	long long s=0;
	cin>>n;
	
	for(int i=0;i<n;i++){
		cin>>a;
		if(a>max) max=a;
		if(a<min) min=a;
		s+=a;
	}
	cout<<min<<" "<<max<<" "<<s<<endl;
	return 0;
}

Measured memory_bytes: 3032
import itertools

########関数部分##############
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
############################

n = int(input())
size = len(str(n))
l = [3,5,7]
counter = 0
test = []
while size >= 3:
    for i in range(3**size):
        temp = list(Base_10_to_n(i,3))
        for k in range(size-len(temp)):
            temp.insert(0,'0')
        test.append(temp)
    size -= 1

for i in range(len(test)):
    val = 0
    three = 0
    five = 0
    seven = 0
    for k in range(len(test[i])):
        val += l[int(test[i][k])] * 10**(len(test[i])-k-1)
        if l[int(test[i][k])] == 3:
            three += 1
        elif l[int(test[i][k])] == 5:
            five += 1
        elif l[int(test[i][k])] == 7:
            seven += 1
    if three > 0 and five > 0 and seven > 0 and val <= n:
        counter += 1

print(counter)

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

int d1(int a, int b) { return std::abs(a - b); };

int main() {
	std::vector<int> ds{};
	int n, x, y;
	cin >> n >> x >> y;
	ds.resize(n);
	auto rr = [&](int i, int j) 
	{
		ds.at(std::min(d1(i, j), d1(i, x) + 1 + d1(j, y)) - 1)++;
	};
	for (int i = 1; i <= n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			rr(i, j);
		}
	}
	for (int i = 0; i < n-1; i++)
	{
		cout << ds[i] << endl;
	}
}


Measured memory_bytes: 256
import os
import sys
from fractions import gcd

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

T = int(sys.stdin.readline())
ABCD = [list(map(int, sys.stdin.readline().split())) for _ in range(T)]


def solve(A, B, C, D):
    if B > D:
        return False
    if A < B:
        return False
    if C >= B:
        return True
    # C < B <= D
    # A から D を無限に足してったとき、mod B が C より大きくなったらだめ
    p = gcd(D, B)  # p ごとの値しか取らない
    if p < B - C:
        return False
    if (B - A - 1) % p < B - C - 1:
        return False
    return True


ans = []
for a, b, c, d in ABCD:
    ans.append('Yes' if solve(a, b, c, d) else 'No')
print(*ans, sep='\n')


Measured memory_bytes: 5328
from math import sqrt
while True:
  n = int(input())
  if n == 0:
    break
  scores = list(map(int, input().split()))
  ave = sum(scores)/len(scores)
  A = 0
  for i in range(len(scores)):
    A += (scores[i] - ave)**2
  a = sqrt(A/len(scores))
  print('{:.08f}'.format(a))


Measured memory_bytes: 5708