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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<string> S(N);
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }
  vector<vector<int>> freqs(N, vector<int>(128, 0));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < (int)S[i].size(); ++j) {
      ++freqs[i][S[i][j]];
    }
  }

  string ans;
  for (int c = 'a'; c <= 'z'; ++c) {
    int cnt = INF;
    for (int i = 0; i < N; ++i) {
      cnt = min(cnt, freqs[i][c]);
    }
    ans += string(cnt, c);
  }
  printf("%s\n", ans.c_str());
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
typedef pair<int, int> P;
int sx,sy,H,W,N;
char map1[1002][1002];
int step[1002][1002];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
void find1(int g){
for(int i = 0; i < W; i++)
    for(int k = 0; k < H; k++)
        if(map1[i][k] == 'S' || map1[i][k] == (g+48)){
        if(map1[i][k] == 'S') map1[i][k] ='.';
        sx = i; sy = k;
        return ;
    }
}

int bfs(int n)
{
    memset(step,-1,sizeof(step));
    queue <P> que;
    que.push(P (sx,sy));
    step[sx][sy] = 0;
    while(que.size()){
        int x = que.front().first, y = que.front().second;
        que.pop();
        for(int i = 0; i < 4; i++){
            int xn = x + dx[i], yn = y + dy[i];
            if(xn >= 0 && xn < W && yn >= 0 && yn < H && map1[xn][yn] != 'X' && step[xn][yn] == -1)
                {
                    step[xn][yn] = step[x][y] + 1;
                    if(map1[xn][yn] == (n+48))
                        {
                            return step[xn][yn];
                        }
                    que.push(P(xn, yn));
                }
        }
    }
return 0;
}

int main()
{
    cin >> W >> H >> N;
    for(int i = 0; i < W; i++)
        for(int k = 0; k < H; k++)
        cin >> map1[i][k];
    int step = 0;
    find1(0);
    step += bfs(1);
    for(int i = 1; i < N; i++)
    {

        find1(i);
        step += bfs(i+1);
    }
    cout << step << endl;
    return 0;
}

Measured memory_bytes: 8020
#include"iostream"

using namespace std;

int main()
{
    int n;
    cin >> n;
  
    int l[100] = { 0 };
    for (int i = 0; i < n; i++) {
        cin >> l[i];
        
    }
    int max = 0;
    int k = 0;
    for (int i = 0; i < n; i++) {
        if (l[i] > max) {
            max = l[i];
            k = i;
        }

    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (i != k) {
            sum += l[i];
        }
    }
    if (l[k] < sum) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<cstring>
#include<cmath>
#include <algorithm>
#include <vector>
using namespace std;
long long n;
int main()
{
  cin>>n;
  long long dp[n+1];
  dp[0]=0;
  dp[1]=0;
  long long h[n];
  for(long long i=0; i<n;i++)
    cin>>h[i];
  dp[2]=abs(h[1]-h[0]);
  for(long long i=3; i<=n;i++)
    dp[i]=min(dp[i-1]+abs(h[i-1]-h[i-2]),dp[i-2]+abs(h[i-1]-h[i-3]));
  cout<<dp[n];
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


/*nまでの素数を列挙して配列に保持*/
vector<ll> Eratosthenes(ll n) {

	vector<ll> arr(n);
	for (ll i = 0; i < n; i++) {
		arr[i] = 1;
	}
	arr[0] = arr[1] = 0;
	for (ll i = 2; i < sqrt(n); i++) {
		if (arr[i]) {
			for (ll j = 0; i * (j + 2) < n; j++) {
				arr[i * (j + 2)] = 0;
			}
		}
	}
	return arr;
}


int main() {

	int n;
	
	vector<ll> prime = Eratosthenes(1000005);

	for (int i = 0; i < prime.size()-1; i++)
	{
		prime[i + 1] += prime[i];
	}

	while (cin >> n) {
		cout << prime[n] << endl;
	}

	
	return 0;
}


Measured memory_bytes: 10568
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

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

    int k;
    int ans;
    cin >> k;

    if(k%2 == 0) ans = (k/2) * (k/2);
    else ans = (k/2) * (k/2 + 1);

    cout << ans << endl;

}



Measured memory_bytes: 256
H,W,K = list(map(int,input().split()))
A = []
ans=[]

for i in range(H):
	A.append(input())
S = [["a" for i in range(W)] for j in range(H)]
cnt = 1
for h in range(H):
	found = 0
	stuck = "a"
	for w in range(W):
		if A[h][w] == "#":
			S[h][w] = str(cnt)
			stuck = S[h][w]

			for i in range(found+1, w):
				S[h][i] = str(stuck)
			cnt += 1
			found = w
		if w == W-1:
			for i in range(found+1, W):
				S[h][i] = str(stuck)

for h in range(H):
	found = 0
	for w in range(1,W):
		if S[h][W-w-1] == "a":
			S[h][W-w-1] = str(S[h][W-w])

for w in range(W):
	found = 0
	for h in range(1,H):
		if S[H-h-1][w] == "a":
			S[H-h-1][w] = str(S[H-h][w])
for w in range(W):
	found = 0
	for h in range(1,H):
		if S[h][w] == "a":
			S[h][w] = str(S[h-1][w])
            
            
for i in range(len(S)):
	mojiretu = ' '.join(S[i])
	ans.append(mojiretu)
ans = '\n'.join(ans)
print(ans)

Measured memory_bytes: 10356
#include <stdio.h>
#include <stdlib.h>

#define MAX 20000003

int A[MAX];
int heap_size=0;

int Parent(int i){
  return i/2;
}
int Left(int i){
  return 2*i;
}
int Right(int i){
  return 2*i+1;
}

void maxHeapify(int i){
  int l,r,largest;
  int temp;
  
  l = Left(i);
  r = Right(i);
  
  
  if((l <= heap_size) && (A[l] > A[i])){
    largest = l;
  }
  else {
    largest = i;
  }
  
  if((r <= heap_size) && (A[r] > A[largest])){
    largest = r;
  } 
  
  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    
    maxHeapify(largest);
  } 
}

int heapExtractMax(void){
  int max,j;
  if(heap_size < 1){
    return -20;
  }
  max = A[1];
  A[1] = A[heap_size];
  heap_size = heap_size-1;

  maxHeapify(1);
  
  return max;
}

void heapIncreaseKey(int i,int key){
  int temp;
  if(key < A[i]){
    printf("error\n");
    exit(1);
  }
  
  A[i] = key;
  
  while((i > 1) && (A[Parent(i)] < A[i])){
    temp = A[i];
    A[i] = A[Parent(i)];
    A[Parent(i)] = temp;

    i = Parent(i);
  }
}

void maxHeapInsert(int key){
  heap_size = heap_size+1;
  A[heap_size] = -1000000000;
  heapIncreaseKey(heap_size,key);
}

int main(void){
  int i=1,j=0,max,a;
  char com[20];
  
  while(1){
    scanf("%s",com);  
    if(com[0] == 'i'){
      scanf("%d",&a);
      maxHeapInsert(a);
  
      //heap_size++;
    }
    
    else if(com[0] == 'e' && com[1] == 'x'){
      max = heapExtractMax();
      if(max == -20){
	exit(0);
      }
      printf("%d\n",max);
    }
    else {
      break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 4328
#include<stdio.h>
 
int main()
{
  int t[4][3][10]={0};
  int b,f,r,v,i,j,k,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%d%d%d%d",&b,&f,&r,&v);
t[b-1][f-1][r-1]=t[b-1][f-1][r-1]+v;

      
    
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	printf(" %d",t[i][j][k]);
      }
      printf("\n");
    }
    if(i!=3)printf("####################\n");
  }
  return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <algorithm>

using namespace std;
int main(int argc, char *argv[]) {
	int A, B, C;
	cin >> A >> B >> C;
	cout << max(10 * A + B + C, max(10 * B + C + A, 10 * C + A + B)) << endl;
	return 0;
}

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

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

	for(int i = 0; i <= n; i+=4){
		for(int j = 0; j <= n-i; j+=7){
			if(i+j == n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}


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

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

	int N, X, A, pre = 0;
	cin >> N >> X;
	LL res = 0;
	while (N--) {
		cin >> A;
		if (A + pre > X) {
			res += A + pre - X;
			A -= A + pre - X;
		}
		pre = A;
	}

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

Measured memory_bytes: 256
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("unused")
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(); // 県の個数
		int m = in.nextInt(); // 市の個数

		int city[][] = new int[m + 1][4]; // id, pref, year, number in pref

		// 県、年でソート
		for ( int id = 1; id <= m; id++ ) {
			city[id][0] = id;
			city[id][1] = in.nextInt();
			city[id][2] = in.nextInt();
		}
		Arrays.sort(city, new Comparator<int[]>() {

			@Override
			public int compare(int[] o1, int[] o2) {
				if ( o1[1] != o2[1] ) {
					return o1[1] - o2[1];	// １．prefでソート
				} else {
					return o1[2] - o2[2];	// ２．yearでソート
				}
			}
		});

		// 年を見てナンバリング
		DecimalFormat df = new DecimalFormat("000000");
		String pad[] = { "000000", "00000", "0000", "000", "00", "0", "" };
		String result[] = new String[m];
		int pref = 0;
		int num = 0;
		for ( int i = 1; i <= m; i++ ) {
			int p = city[i][1];
			if ( pref != p ) {
				pref = p;
				num = 1;
			} else {
				num++;
			}
			result[city[i][0] - 1] = pad[String.valueOf(pref).length()] + pref
				+ pad[String.valueOf(num).length()] + num;
			// 	padding(pref) + padding(num); // df.format(pref) + df.format(num);
		}

		StringBuilder sb = new StringBuilder(100000 * 13);
		for ( String s : result ) {
			sb.append(s).append("\n");
		}
		System.out.println(sb);
		in.close();
	}

	private static String padding(int n) {
		String padded = "";
		if ( n < 10 ) {
			padded = "00000" + n;
		} else if ( n < 100 ) {
			padded = "0000" + n;

		} else if ( n < 1000 ) {
			padded = "000" + n;

		} else if ( n < 10000 ) {
			padded = "00" + n;

		} else if ( n < 100000 ) {
			padded = "0" + n;

		} else {
			padded = String.valueOf(n);
		}
		return padded;
	}
}


Measured memory_bytes: 98972
#include <iostream> // cin, cout
#include <algorithm> // sort
#include <vector> // vector
#include <cstdio> // printf
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)

int		main(void)
{
	int a, b;
	char op;
	cin >> a >> op >> b;
	while (op != '?') {
		switch (op) {
			case '+':
				cout << a + b << endl;
				break ;
			case '-':
				cout << a - b << endl;
				break ;
			case '*':
				cout << a * b << endl;
				break ;
			case '/':
				cout << a / b << endl;
				break ;
		}
		cin >> a >> op >> b;
	}
	return (0);
}



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

int n;
 double x[100],y[100];
 double distance(double p){
 double sum=0;
 for(int i=0;i<n;i++){
 double w=abs(x[i]-y[i]);
 sum+=pow(w,p);
 }
 return pow(sum,1.0/p);
}
 
int main(){
cout<<fixed<<setprecision(12);
cin>>n;
 for(int i=0;i<n;i++){
 cin>>x[i];
 }
 for(int i=0;i<n;i++){
 cin>>y[i];
 }
 cout<<distance(1)<<endl;
 cout<<distance(2)<<endl;
 cout<<distance(3)<<endl;
 double mx=0;
 for(int i=0;i<n;i++){
 mx=max(mx,abs(x[i]-y[i]));
 }
 cout<<mx<<endl;
 
}


Measured memory_bytes: 3392
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int num = sc.nextInt();
        int countAC = 0;
        int countWA = 0;
        int countTLE = 0;
        int countRE = 0;
         for (int i = 0; i < num; i++) {
            String str = sc.next();
            switch(str) {
                case "AC":
                    countAC++;
                    break;
                case "WA":
                    countWA++;
                    break;
                case "TLE":
                    countTLE++;
                    break;
                case "RE":
                    countRE++;
                    break;
            }
        }
        System.out.println("AC x " + countAC);
        System.out.println("WA x " + countWA);
        System.out.println("TLE x " + countTLE);
        System.out.println("RE x " + countRE);

    }
}

Measured memory_bytes: 49096
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
s = input()

if 2*s.count('R') > len(s):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
    string a, b;
    cin >> a;
    cin >> b;
    int ans = 0;

    if (a.size() > b.size()) {
        ans = 1;
    }
    else if (a.size() < b.size()) {
        ans = 2;
    }
    else {
        for (int i = 0; i < a.size(); i++) {
            if (a[i] > b[i]) {
                ans = 1;
                break;
            }
            else if (a[i] < b[i]) {
                ans = 2;
                break;
            }
        }
    }

    if (ans == 1) {
        cout << "GREATER" << endl;
    }
    else if (ans == 2) {
        cout << "LESS" << endl;
    }
    else {
        cout << "EQUAL" << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			int N = sc.nextInt(), i = 0;
			while(true){
				if(String.valueOf(N-i).equals(new StringBuilder(String.valueOf(N-i)).reverse().toString())){
					System.out.println(N-i);
					break;
				}
				if(String.valueOf(N+i).equals(new StringBuilder(String.valueOf(N+i)).reverse().toString())){
					System.out.println(N+i);
					break;
				}
				i++;
			}
		}
	}
}

Measured memory_bytes: 26356
#include<iostream>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
main(){
  int w, d, L[10], R[10];
  while( cin >> w >> d && w){
    rep(i, w) cin >> L[i];
    rep(i, d) cin >> R[i];
    int s = 0;
    rep(i, w) rep(j, d){
      if ( R[j] && L[i] == R[j] ){ s += R[j]; L[i] = R[j] = 0;}
    }
    rep(i, w) if (L[i]) s += L[i];
    rep(i, d) if (R[i]) s += R[i];
    cout << s << endl;
  }
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		long[] b = new long[n + 1];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		// 累積和作成
		for(int i = 0 ; i < n ; i++) {
			b[i + 1] = a[i] + b[i];
		}
		long ans = Long.MAX_VALUE;
		for(int i = 1 ; i < n ; i++) {
			long dis = Math.abs(b[i] - (b[n] - b[i]));
			ans = Math.min(ans, dis);
		}
		System.out.println(ans);
	}
}


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

int main()
{
  std::string T, S;
  std::cin >> S;
  std::cin >> T;

  if (T.substr(0, T.length() - 1) == S)
  {
    std::cout << "Yes" << std::endl;
  }
  else
  {
    std::cout << "No" << std::endl;
  }

  return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

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

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.tr", "r", stdin);
	double q;

	while (cin >> q &&  q != -1.0 ){
		double x = q/2.;
		while (fabs (x*x*x - q) >= 0.00001*q  ){
			double y = (x*x*x - q)/(3.*x*x);
			x = x - y;
		} // end while

		printf ("%.6f\n", x);
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
#include <omp.h>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}



void solve(long long N, long long K, string S){
    int now_cnt = 0;
    int now_type = 1;
    vector<pair<int,int>> going;
    for(int i = 0;i < S.length();++i){
        if(S[i] - '0' == now_type){
            now_cnt++;
        }else{
            going.push_back(make_pair(now_type,now_cnt));
            now_cnt = 1;
            now_type += 1;
            now_type %= 2;
        }
    }
    going.push_back(make_pair(now_type,now_cnt));
    int final_ans = 0;
    int now_ans = 0;
    int back_itr = 0;
    for(int i = 0;i < going.size();++i){
        if(going[i].first == 0){
            //penalty
            K--;
            while(K < 0){
                now_ans -= going[back_itr].second;
                if(going[back_itr].first == 0) K++;
                back_itr++;
            }
            now_ans += going[i].second;
            final_ans = max(final_ans,now_ans);
        }else{
            now_ans += going[i].second;
            final_ans = max(final_ans,now_ans);
        }
    }
    cout << final_ans << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    string S;
    cin >> S;
    solve(N, K, S);
    return 0;
}


Measured memory_bytes: 1656
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define _GLIBCXX_DEBUG
const int INF=1e15;

signed main(){
    int N;
    int ans=0;
  	cin>>N;
    REP(i,N){
        int a,b;cin>>a>>b;
        ans+=b-a+1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define N 200010
const int inf=0x3f3f3f3f;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[N],b[N],head[N],cnt,ia[N],ib[N],tot,S,T,dep[N],pre[N];
struct Edge{
	int to,nxt,val;
}edge[N<<2];
void Add(int a,int b,int c){
	edge[++cnt]={b,head[a],c};
	head[a]=cnt;
}
void adde(int a,int b,int c){
	Add(a,b,c),Add(b,a,0);
}
queue<int> q;
bool bfs(){
	memset(dep,0,sizeof(dep));
	dep[S]=1;
	q.push(S);
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=head[u];i;i=edge[i].nxt){
			int v=edge[i].to;
			if(edge[i].val&&!dep[v]){
				dep[v]=dep[u]+1;
				q.push(v);
			}
		}
	}
	return dep[T]>0;
}
int dfs(int u,int limit){
	if(u==T)return limit;
	int flow=0;
	for(int &i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(edge[i].val&&dep[v]==dep[u]+1){
			int k=dfs(v,min(limit,edge[i].val));
			edge[i].val-=k;
			edge[i^1].val+=k;
			flow+=k;
			limit-=k;
		}
		if(!limit)break;
	}
	if(!flow)dep[u]=inf;
	return flow;
}
int Dinic(){
	int maxflow=0;
	for(int i=1;i<=tot;++i){
		pre[i]=head[i];
	}
	while(bfs()){
		maxflow+=dfs(S,inf);
		for(int i=1;i<=tot;++i){
			head[i]=pre[i];
		}
	}
	return maxflow;
}
int main(){
	n=read(),cnt=1,S=++tot,T=++tot;
	for(int i=1;i<=n;++i){
		a[i]=read()+1;
	}
	for(int i=1;i<=n;++i){
		b[i]=read()+1;
	}
	for(int i=1;i<=n;++i){
		if(ia[i])continue;
		int u=i;
		++tot;
		while(!ia[u]){
		   ia[u]=tot;
		   u=a[u];
		}
	}
	for(int i=1;i<=n;++i){
		if(ib[i])continue;
		int u=i;
		++tot;
		while(!ib[u]){
		   ib[u]=tot;
		   u=b[u];
		}
	}
	int same=0;
	for(int i=1;i<=n;++i){
		if(a[i]==i&&b[i]==i){
			++same;
		}
		else if(a[i]==i){
			adde(S,ib[i],1);
		}
		else if(b[i]==i){
			adde(ia[i],T,1);
		}
		else{
			adde(ia[i],ib[i],1);	
			if(a[i]==b[i])adde(ib[i],ia[i],1);
		}
	}
	same+=Dinic();
	printf("%d\n",n-same);
	return 0;
}



Measured memory_bytes: 13884
#include <iostream>
#include <vector>
#include <cstring>

//isprimeðìÁÄ­êéÖ
int* prime(int num){
	std::vector<int> v;
	int* res = new int[num+1];
	memset(res, 0, sizeof(res));
	res[2] = 1;
	v.push_back(2);

	bool f;
	for(int i=3;i<=num;i+=2){
		f = true;
		for(int j=0;v[j]*v[j]<=i;j++){
			if(i % v[j] == 0){f=false;break;}
		}
		if(f){v.push_back(i),res[i] = 1;}
	}

	return res;
}

int main(){
	int* isprime = prime(50000);

	int n, res = 0;
	while(std::cin >> n, n){
		res = 0;
		for(int i=2;i<=n/2;i++){
			if(isprime[i] && isprime[n-i])res++;
		}
		std::cout << res << std::endl;
	}

	delete[] isprime;
	
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int x[100000];
	for(int i = 0; i < m; i++){
		cin >> x[i];
	}


	sort(x, x + m, greater<int>());

	int min = x[m - 1], max = x[0];

	int sa[100000 - 1];
	for(int i = 0; i < m - 1; i++){
		sa[i] = x[i] - x[i + 1];
	}

	sort(sa, sa + m - 1, greater<int>());

	int sum = 0;
	for(int i = 0; i < n - 1; i++){
		sum += sa[i];
	}


	cout << max - min - sum << endl;
}


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

    vector<int> mochi(N);
    for(int i=0; i<N; i++){
        cin >> mochi.at(i);
    }

    sort(mochi.begin(), mochi.end());
    reverse(mochi.begin(), mochi.end());

    int count=0;

    for(int i=0; i<N-1; i++){
        if(mochi.at(i) > mochi.at(i+1)){
            count++;
        } 
    }

    cout << count + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int N;
	cin >> N;
	cout << N / 3 << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner scn  = new Scanner(System.in);
		int[] arr = new int[5];
		for(int i=0;i<5;i++) {
			arr[i] = scn.nextInt();
		}
		for(int i=0;i<5;i++) {
			if(arr[i]==0) {
				System.out.println(i+1);
				break;
			}
		}

	}

}


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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;

int main() {
    int N;
    cin >> N;
    if(N%10 == 9 || N/10 == 9) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  cin >> N;
  string s;
  cin >> s;
  rep(i,(int)s.size()){
    cout << (char)('A'+((s[i]-'A'+N)%26));
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[derive(Eq, PartialEq, Clone, Debug)]
struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn main() {
    let n = get!(usize);
    let mut aa = util::gets::<u64>();

    aa.sort_by_key(|&a| Rev(a));

    let ans = (0..n).map(|i| aa[i * 2 + 1]).sum::<u64>();

    println!("{}", ans);
}


Measured memory_bytes: 13428
//
//AtCoder Beginner Contest 139
//D - ModSum
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#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 FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    ll ans = 0;
    FOR(i, 1, n-1){
        ans+=i;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdarg>
#include <cstdlib>
using namespace std;

int main(){
    int N, k;
    cin >> N;
    for(int i = 0; i < N; i ++){
        cin >> k;
        if (k % 2 == 0 && k % 3 != 0 && k % 5 != 0){
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long 	ll;
typedef pair<int, int> pll;
typedef vector<int> vl;
#define pb push_back
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6+5;
const ll 	w1  	= 	1e5+5;
ll n,W;
vl v,w;
ll val,wt;
ll dp[108][100001];
ll ksack(ll n, ll W)
{
	if(n==0 || W==0)
	{
		return 0;
	}
	if(dp[n][W]!=-1)
	{
		return dp[n][W];
	}
	if(w[n-1]>W)
	{
		return dp[n][W]=ksack(n-1,W);
	}
	else
		return dp[n][W]=max(v[n-1]+ksack(n-1,W-w[n-1]),ksack(n-1,W));

}
ll solve()
{
	cin>>n>>W;
	for(int i=0;i<n;i++)
	{
		cin>>wt>>val;
		v.pb(val);
		w.pb(wt);
	}
	memset(dp,-1,sizeof(dp));
	ll res=ksack(n,W);
	return res;
}
int main() {
	
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	
	cout<<solve();
	
}

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

char a,b,c;
int main(){
	scanf("%c%c%c",&a,&b,&c);
	int d=0;
	if(a=='a'){
		d+=1;
	}
	if(b=='a'){
		d+=1;		
	}
	if(c=='a'){
		d+=1;		
	}
		if(a=='b'){
		d+=2;		
	}
		if(b=='b'){
		d+=2;		
	}	if(c=='b'){
		d+=2;		
	}	if(a=='c'){
		d+=3;		
	}	if(b=='c'){
		d+=3;		
	}	if(c=='c'){
		d+=3;		
	}
	if(d==6){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
/*
for(int i=1;i<=x;i++){
	ans++;
	plus+=i;
	if(plus>=x)break;
}
printf("%d\n",ans);
*/
	
//	printf("%lld\n",ans);
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    n, m = map(int, input().split())
    s = input()
    t = input()
    ans = lcm(n, m)
    ln = ans // n
    lm = ans // m
    l = lcm(ln, lm)
    i = 0
    while i * l // ln < n and i * l // lm < m:
        if s[i * l // ln] != t[i * l // lm]:
            ans = -1
            break
        i += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9356
#include <iostream>
using namespace std;
typedef long long ll;

const ll INF = 100000000000000000;

ll dp[5002][5002];

int main()
{
    int n;
    ll a, b;
    cin >> n >> a >> b;
    int p[5002], q[5002];
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
        q[p[i]] = i;
    }
    int left[5002], right[5002];
    fill(left, left + n, n);
    fill(right, right + n, -1);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < q[i]; j++){
            if(p[j] > i) left[i] = min(left[i], p[j]);
        }
        for(int j = q[i] + 1; j < n; j++){
            if(p[j] < i) right[i] = max(right[i], p[j]);
        }
    }
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++) dp[i][j] = INF;
    }
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= n; j++){
            if(dp[i - 1][j] == INF) continue;
            if(j > p[i - 1] + 1) dp[i][j] = dp[i - 1][j] + b;
            else dp[i][j] = dp[i - 1][j] + a;
        }
        for(int j = 0; j < p[i - 1] + 1; j++) dp[i][p[i - 1] + 1] = min(dp[i][p[i - 1] + 1], dp[i - 1][j]);
    }
    ll ans = INF;
    for(int j = 0; j <= n; j++) ans = min(ans, dp[n][j]);
    cout << ans << endl;
}


Measured memory_bytes: 195712
import sys

readline = sys.stdin.buffer.readline


sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = readline().decode('utf-8')
    S = S.replace('BC', 'D')

    count_a = 0
    ans = 0

    for s in S:
        if s == 'A':
            count_a += 1
        elif s == 'D':
            ans += count_a
        else:
            count_a = 0

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3508
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main (){
	ll q,h,s,d,n;
	scanf ("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
	n*=4ll;
	h=min(h,q*2ll);
	s=min(s,h*2ll);
	d=min(d,s*2ll);
	ll ans=0;
	ans+=d*(n/8);n%=8;
	ans+=s*(n/4);n%=4;
	ans+=h*(n/2);n%=2;
	ans+=q*n;
	printf ("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
import sys

x = input()

A = int(x[0])
B = int(x[1])
C = int(x[2])
D = int(x[3])

work = A
op1,op2,op3 = "","",""
for i in range(2):
    for j in range(2):
        for k in range(2):
            if i == 1:
                op1 = "+"
                work += B
            else:
                op1 = "-"
                work -= B
            if j == 1:
                op2 = "+"
                work += C
            else:
                op2 = "-"
                work -= C
            if k == 1:
                op3 = "+"
                work += D
            else:
                op3 = "-"
                work -= D
            if work ==7:
                print(x[0]+op1+x[1]+op2+x[2]+op3+x[3]+"=7")
                sys.exit()
            else:
                work = A

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<ll> v(N);
  rep(i,N) cin >> v[i];
  sort(all(v));
  int s = -1, e = N-1;
  while(e-s>1){
    int m = (s+e)/2;
    ll sum = v[m];
    bool issat = true;
    rep(i,N){
      if(i==m)continue;
      if(v[i] > 2*sum) issat = false;
      sum += v[i];
    }
    if(issat) e = m;
    else s = m;
  }
  cout << N-e << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'U' || s[i] == 'D')
            continue;
        else if (i % 2 == 0) {
            if (s[i] != 'R') {
                cout << "No" << "\n";
                return 0;
            }
        }
        else if (i % 2 == 1) {
            if (s[i] != 'L') {
                cout << "No" << "\n";
                return 0;
            }
        }
    }
    cout << "Yes" << "\n";
}

Measured memory_bytes: 256
#!/usr/bin/env python
# encoding: utf-8

import copy


class Solution:
    def stable_sort(self):
        # write your code here
        array_length = int(input())
        array = [str(x) for x in input().split()]
        array_2 = copy.deepcopy(array)

        bubble_result = self.bubble_sort(array=array, array_length=array_length)
        selection_result = self.selection_sort(array=array_2, array_length=array_length)

        # check whether selection sort is stable
        if bubble_result == selection_result:
            print("Stable")
        else:
            print("Not stable")

    @staticmethod
    def selection_sort(array, array_length):
        # selection sort
        selection_count = 0
        for i in range(array_length):
            min_j = i
            for j in range(i, array_length):
                if array[j][1] < array[min_j][1]:
                    min_j = j
            array[i], array[min_j] = array[min_j], array[i]
            if i != min_j:
                selection_count += 1

        result = " ".join(map(str, array))
        print(result)
        return result

    @staticmethod
    def bubble_sort(array, array_length):
        flag, bubble_count, cursor = 1, 0, 0
        while flag:
            flag = 0
            for j in range(array_length - 1, cursor, -1):
                if array[j][1] < array[j - 1][1]:
                    array[j], array[j - 1] = array[j - 1], array[j]
                    flag = 1
                    bubble_count += 1
        cursor += 1
        result = " ".join(map(str, array))
        print(result)
        print("Stable")
        return result


if __name__ == '__main__':
    solution = Solution()
    solution.stable_sort()

Measured memory_bytes: 8152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }

int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}

int main() {
    ll n;
    cin >> n;
    string s;
    vector<ll> num(5,0);
    rep1(i, n){
        cin >> s;
        if (s[0]=='M') num[0]++;
        if (s[0]=='A') num[1]++;
        if (s[0]=='R') num[2]++;
        if (s[0]=='C') num[3]++;
        if (s[0]=='H') num[4]++;
    }
    ll ans = 0;
    int bit = (1<<3)-1;
    for (;bit < (1<<5); bit = next_combination(bit)) {
        ll cnt=1;
        for (int i = 0; i < 5; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                cnt *= num[i];
            }
        }
        ans += cnt;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3588
//#include <fstream>

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int NMAX = 100005;
int n, m;
vector <int> graph[NMAX], dp;

int DFS(int node)
{
	if (dp[node] != -1)
		return dp[node];
	int best = 0;
	for (auto i : graph[node])
		best = max(best, 1 + DFS(i));
	dp[node] = best;
	return best;
}

int main()
{
	//ifstream cin("test.in");
	//ofstream cout("test.out");
	cin >> n >> m;
	dp.resize(n + 1, -1);
	for (int i = 1;i <= m;++i)
	{
		int x, y;
		cin >> x >> y;
		graph[x].push_back(y);	
	}
	int ans = 0;
	for (int i = 1;i <= n;++i)
		ans = max(ans, DFS(i));
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,h;
	cin>>n>>h;
	ll a[n],b[n], amax = -1;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		amax = max(a[i],amax);
	}
	sort(b,b+n);
	ll ans = 0;
	int i = n-1;
	while(h > 0 && i>=0 && b[i] >= amax){
		h-=b[i];
		++ans;
		--i;
	}
	if(h > 0) ans+= ceil((ld)h/(ld)amax);
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 1792
/*raghav0307 - Raghav Gupta*/

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

#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long ll;
typedef long double ld;

int main(){
	fast_io();
	ld n, k;
	cin >> n >> k;
	ld ans = 0;
	for(ld i = 1; i <= n; i++){
		ld a = 1;
		ld b = 1;
		while(a*i < k){
			a *= 2;
			b /= 2;
		}
		// cout << a << "\n";
		ans += b;
	}
	cout << fixed << setprecision(24);
	ans /= n;
	cout << ans;
	return 0;
}

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

int N;
vector<int> a;

void solve() {
    vector<int> res;
    for (int i = 0; i < N; ++i) {
        int pivot = -1;
        for (int j = (int)a.size()-1; j >= 0; --j) {
            if (a[j] == j) {
                pivot = j;
                break;
            }
        }
        if (pivot == -1) {
            cout << -1 << endl;
            return;
        }

        res.push_back(pivot + 1);
        a.erase(a.begin() + pivot);
    }
    reverse(res.begin(), res.end());
    for (auto v : res) cout << v << endl;
}

int main() {
    cin >> N;
    a.resize(N);
    for (int i = 0; i < N; ++i) cin >> a[i] , --a[i];
    solve();
}

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

typedef long long LL;

int main()
{
    LL k, a, b;
    cin >> k >> a >> b;
    LL ans = 1;
    if (a >= b - 1 || k <= a - 1)
        ans = k + 1;
    else
    {
        k -= a - 1;
        ans += a - 1;
        LL ls = k / 2;
        ans += ls * (b - a);
        if (k % 2)
            ans++;
    }
    cout << ans;
    return 0;
}
// 48518828946040168 48518828981938099 48518828981938099

Measured memory_bytes: 256
n = int(input())
mod = 998244353
data = [0]*(n+1)
d = list(map(int,input().split()))
if d[0] != 0:
    print(0)
    exit()
for x in d:
    data[x] += 1

if data[0] != 1:
    print(0)
    exit()

q = 0
ans = 1
for i in range(1,n):
    ans *= pow(data[i-1],data[i],mod)
    ans %= mod

print(ans)

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

const string YES = "Yes";
const string NO = "No";

int main(){
    int n;
    cin >> n;
    int sum = 0, n2 = n;
    while (n2 > 0) {
        sum += n2 % 10;
        n2 /= 10;
    }
    if (n%sum==0) cout << YES << endl;
    else cout << NO << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN



int main(void){
	ll n,m,visited[100010]={};
	vector<ll> v[100010];
	deque<ll> Q;
	cin>>n>>m;
	rep(i,m){
		ll a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	reg(i,1,n){//次数が１以上の点を選ぶ
		if(v[i].size()>=1){
			//最初の点から適当な方向に詰まるまで探索．
			ll c=i;
			Q.push_front(c);
			visited[c]=1;
			while(true){
				bool update=false;
				rep(j,v[c].size()){
					ll d=v[c][j];
					if(visited[d]==0){
						c=d;
						Q.push_front(c);
						visited[c]=1;
						update=true;
						break;
					}
				}
				if(!update)break;//通れる点がなくなったら出る
			}
			//最初の点から別の方向に詰まるまで探索．
			c=i;
			while(true){
				bool update=false;
				rep(j,v[c].size()){
					ll d=v[c][j];
					if(visited[d]==0){
						c=d;
						Q.push_back(c);
						visited[c]=1;
						update=true;
						break;
					}
				}
				if(!update)break;//通れる点がなくなったら出る
			}
			break;
		}
	}
	cout<<Q.size()<<endl;
	while(!Q.empty()){
		printf("%lld",Q.front());
		Q.pop_front();
		if(Q.size()>0)printf(" ");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 7936
h = int(input())
w = int(input())
n = int(input())
cnt = 0
blk = 0

if h > w:
  for i in range(w):
    blk += h
    cnt += 1
    if blk >= n:
      break
else:
  for j in range(h):
    blk += w
    cnt += 1
    if blk >= n:
      break

print(cnt)

Measured memory_bytes: 9124
a = [0] * 5
b = [0] * 5
for i in range(5):
    a[i] = int(input())
for i in range(5):
    if a[i] % 10 != 0:
        b[i] = a[i] % 10
    else:
        b[i] = 10
print(sum(a) - sum(b) + 50 - 10 + min(b))


Measured memory_bytes: 3060
N = int(input())

AB_list = [[0,0,0] for i in range(N)]

for i in range(N):
    a,b = map(int,input().split())
    AB_list[i][0] = a
    AB_list[i][1] = b
    AB_list[i][2] = a+b
AB_list.sort(reverse=True,key=lambda x:x[2])

total = 0
for i in range(N):
    if i%2==0:
        total += AB_list[i][0]
    else:
        total -= AB_list[i][1]

print(total)

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

using namespace std;
using lint = long long;


int main(){
    string s,l;
    int w;
    cin>>s>>w;
    for (int i=0; i*w<s.size(); i++) {
        l += s.at(i*w);
    }
    cout<<l<<endl;
    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

void solve(){
	ll n;
	cin >> n;
	ll ans = 0ll;
	for(ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ll m = n / i - 1;
			if (m > i) {
				ans += m;
			}
		}
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

int main() {
    int n;cin>>n;
    int p[n];
    rep(i,n)cin>>p[i];
    int sum = 0;
    int max = 0;
    rep(i,n){
        sum+=p[i];
        if(p[i]>max)max=p[i];
    }
    cout<<sum-max/2<<endl;
}

Measured memory_bytes: 256