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

const int MAXN = 300010;
int A[MAXN], pre[MAXN], n;
bool solve(int x) {
	int pmin = 0;
	for (int i = 2; i <= n; i += 2)
		if (pre[i - 1] - pmin >= x)
			pmin = std::min(pmin, pre[i]); 
	return pre[n] - pmin >= x;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	int sa = 0, sb = 0, sum = 0l;
	for (int i = 1; i <= n; ++i) {
		std::cin >> A[i]; sum += A[i];
		i & 1 ? sa += A[i] : sb += A[i];
		pre[i] = pre[i - 1] + (i & 1 ? 1 : -1) * A[i];
	}
	int Ans = std::max(sa, sb);
	if (n & 1) {
		int l = -sum, r = sum, ans = 0;
		while (l <= r) {
			int mid = l + r >> 1;
			if (solve(mid)) ans = mid, l = mid + 1; else r = mid - 1;
		}
		Ans = std::max(Ans, sb + ans);
	}
	std::cout << Ans << ' ' << sum - Ans << std::endl;
	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
#define db double

using namespace std;
const int N=2000+10,mod=924844033;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
void ad(int &x,int y){x+=y,x-=x>=mod?mod:0;}
int fpow(int a,LL b,int mod){int an=1;while(b){if(b&1) an=1ll*an*a%mod;a=1ll*a*a%mod,b>>=1;}return an;}
int ginv(int a,int mod){return fpow(a,mod-2,mod);}
int n,k,fac[N],iac[N],id[N][N],tt,cn[N],f[N];
int C(int a,int b){return b<0||a<b?0:1ll*fac[a]*iac[b]%mod*iac[a-b]%mod;}

int main()
{
	fac[0]=1;
	for(int i=1;i<=N-10;++i) fac[i]=1ll*fac[i-1]*i%mod;
	iac[N-10]=ginv(fac[N-10],mod);
	for(int i=N-10;i;--i) iac[i-1]=1ll*iac[i]*i%mod;
	n=rd(),k=rd();
	for(int i=1;i<=n;++i)
		for(int j=-k;j<=k;j+=k+k)
		{
			int x=i,y=i+j;
			if(y<=0||y>n) continue;
			if(x-k-k>0&&id[x-k-k][y]) id[x][y]=id[x-k-k][y];
			else if(y-k-k>0&&id[x][y-k-k]) id[x][y]=id[x][y-k-k];
			else id[x][y]=++tt;
			++cn[id[x][y]];
		}
	f[0]=1;
	for(int i=1;i<=tt;++i)
		for(int j=n;j;--j)
		{
			int sm=f[j];
			for(int l=1;l<=cn[i]&&j-l>=0;++l)
				ad(sm,1ll*C(cn[i]-l+1,l)*f[j-l]%mod);
			f[j]=sm;
		}
	int ans=0;
	for(int i=0;i<=n;++i)
	{
		int dt=1ll*f[i]*fac[n-i]%mod;
	    ad(ans,(i&1)?mod-dt:dt);
	}
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 14464
#include <iostream> // cout, endl, cin
using namespace std;

int main(){
    int N,flg;
    cin>>N;
    flg=0;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(i*j==N){
                flg=1;
            }
        }
    }
    if(flg){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// const ll INF = 1e18;
// const ll MOD = 1e9+7;
const double pi = 3.14159265358979;
using vl = vector<ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

ll N;

int Main() {
    cin >> N;
    double ans = N* pi* 2;
    cout << fixed << ans << endl;
    return 0;
}

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


Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,i,j,k;
    cin>>n;
    ll arr[n];
    ll ans=0;
    for(i=0;i<n;i++)
        cin>>arr[i];
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            for(k=j+1;k<n;k++)
            {
                if(arr[i]!=arr[j] and arr[j]!=arr[k] and arr[i]!=arr[k])
                {
                    if (arr[i] + arr[j] <= arr[k] || arr[i] + arr[k] <= arr[j] || arr[j] + arr[k] <= arr[i]) ;
                    else ans++;
                }
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3636
#ifdef LOCAL
#  define _GLIBCXX_DEBUG
#else
#  define cerr __get_ce
#endif
#include <bits/stdc++.h>
#define ff first
#define ss second
#define szof(x) ((int)x.size())

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;
mt19937 tw(9450189);
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }


void solve() {
	int h, w, n;
	cin >> h >> w >> n;
	vector<set<int>> here(h);
	for (int i = 0; i < n; ++i) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		here[x].insert(y);
	}
	int l = 0, r = 0;
	for (int i = 0; i < h; ++i) {
		if (i == h - 1 || (szof(here[i + 1]) && *here[i + 1].begin() <= r)) {
			cout << i + 1 << "\n";
			return;
		}
		if (r == w - 1 || (szof(here[i + 1]) && *here[i + 1].begin() == r + 1)) {

		} else {
			++r;
		}
	}
}


int main() {
#ifdef LOCAL
	auto start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	cout << setprecision(15) << fixed;
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int test_count = 1;
	// cin >> test_count;
	for (int test = 1; test <= test_count; ++test) {
		solve();
	}
	
#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}


Measured memory_bytes: 19072
def hanteib(bfield,r,c):
    count=0
    for b in bfield:
        ccount=bin(b).count("1")
        count=count+max(ccount,r-ccount)
    return count

def turnrb(bfield,rn,r,c):
    if rn==r:
        return hanteib(bfield,r,c)
    bfield1=bfield
    bfield2=[b ^ 2**rn for b in bfield]
    return max(turnrb(bfield1,rn+1,r,c),turnrb(bfield2,rn+1,r,c))

while(1):
    [r,c]=[int(x) for x in raw_input().split()]
    if r==0:
        break
    else:
        field=[]
        bfield=[]
        for i in range(r):
            field.append([int(x) for x in raw_input().split()])
        for j in range(c):
            bb=0
            for i in range(r):
                bb=bb+2**i*field[i][j]
            bfield.append(bb)
        print turnrb(bfield,0,r,c)

Measured memory_bytes: 7924
// @ts-ignore
import * as fs from 'fs';
import { kMaxLength } from 'buffer';

// メイン
var g_root: number[];
var g_count: number[];

function main(input: string[]) {
    var work0: number[] = input.shift().split(" ").map(x => Number(x));
    var n: number = work0[0];
    var m: number = work0[1];
    var node: number[][] = input.map(x => x.split(" ").map(x => Number(x) - 1));
    g_root = new Array(n).fill(-1);
    g_count = new Array(n).fill(1);
    node.forEach(value => {
        var a: number = value[0];
        var b: number = value[1];
        var roota: number = getRoot(a);
        var rootb: number = getRoot(b);
        if (roota == rootb) return;
        if (roota > rootb) [roota, rootb] = [rootb, roota];
        mergeRoot(roota, rootb);
    });
    // TODO Math.max(...)は使ってはダメ、スプレッド構文はスタックに展開するのでスタックがあふれる
    // console.log(Math.max(g_cound));
    console.log(Math_max(g_count));
}

function Math_max(arr: number[]) {
    return arr.reduce(function(x, y) {
        return Math.max(x, y);
    });
}
function getRoot(index: number) {
    if (g_root[index] < 0) {
        return index;
    } else {
        var work0: number = getRoot(g_root[index]);
        g_root[index] = work0;
        return work0
    }
}

function mergeRoot(root0: number, root1: number) {
    g_count[root0] += g_count[root1];
    g_count[root1] = 0;
    g_root[root1] = root0;
}

// エントリポイント
// - OSによるパラメタの処理の違いを吸収
function entrypoint() {
    try {
        var input = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        console.debug = function () { };
        main(input);
    }
    catch (ex) {
        console.log("----");
        console.log("file='%s'", __filename.split("\\").slice(-1)[0]);
        console.log("----");
        const lines: string[] = [];
        // @ts-ignore
        const reader = require('readline').createInterface({
            // @ts-ignore
            input: process.stdin,
            // @ts-ignore
            output: process.stdout
        });
        reader.on('line', function (line: string) {
            lines.push(line);
        });
        reader.on('close', function () {
            input = lines;
            console.log("input=%o", input);
            console.time();
            console.log("----")
            main(input);
            console.log("----")
            console.timeEnd();
        });
    }
}
entrypoint();


Measured memory_bytes: 88276
#include <stdio.h>

int main (void) {
  int a, b;
  char s[11];
  scanf("%d%d",&a, &b);
  scanf("%s", s);

  int i;
  for (i=0;i<a;i++) {
    if (s[i] < 48 || s[i] > 57) {
      printf("No\n");
      return 0;
    }  
  }
  
  if (s[i] != '-') {
    printf("No");
    return 0;
  }
  
  for (i++;i<a+b+1;i++) {
    if (s[i] < 48 || s[i] > 57) {
      printf("No\n");
      return 0;
    }  
  }

  printf("Yes\n");
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  int n,k;
  cin >> n >> k;
  double ans=0;
  for(int i=1;i<=n;i++){
    int p=i;
    double ct=1;
    if(i>=k){
      ans+=1;
      continue;
    }
    while(p<k){
      p=p*2;
      ct=ct/2;
    }
    ans+=ct;
  }
  printf("%.10lf",ans/n);
}

Measured memory_bytes: 3732
#include "math.h"
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <functional>
#include <numeric>
#include <cmath>
using namespace std;

int t;

int main()
{
	int l, r, d;
	cin >> l >> r >> d;
	int ans = floor(r*1.0 / d) - floor(l*1.0/d);
	if (l%d == 0 && r % d == 0) ans++;
	cout << ans;
	return 0;
}


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

const int MAXN = 100005;

int N, A[MAXN], ai;
int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%d", &ai);
		A[ai - 1] = i;
	}
	
	for(int i = 0; i < N; i++){
		if(i > 0)printf(" ");
		printf("%d", A[i] + 1);
	}
	printf("\n");
	
	return 0;
}


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

int a[5];

int main(){
	cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
	sort(a,a+5);
	cout<<a[4]<<" "<<a[3]<<" "<<a[2]<<" "<<a[1]<<" "<<a[0]<<endl;
	return 0;
}

Measured memory_bytes: 3140
def gcd(x,y):
    if x < y:
        x,y = y,x
    if x%y == 0:
        return y
        
    return gcd(y,x%y)

n=int(input())

a=list(map(int,input().split()))
ans=a[0]
for i in range(1,len(a)):
    ans = gcd(ans,a[i])
    
print(ans)    

Measured memory_bytes: 14252
#include <stdio.h>



int main(void)
{
	//変数の宣言
	char s[210];
	char t[110];
	int len;
	int i,j;
	int flag;
	int ans=0;
	
	//データの読み込み
	scanf("%s %s",&s,&t);
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	
	
	//実際の処理
	
	sprintf(s,"%s%s",s,s);
	
	len=strlen(t);
	
	for(i=0;i<len;i++){
		if(s[i]==t[0]){
			flag=1;
			for(j=0;j<len;j++){
				if(s[i+j]!=t[j]){
					flag=0;;
				}
			}
			if(flag==1){
				ans=1;
			}
		}
	}
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	if(ans==1){
		printf("Yes");
	}else{
		printf("No");
	}
	
//	printf("結果の出力終了\n");
	
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>

using namespace std;
using ll = long long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI = 4.0 * atan(1.0);

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

int main() {
    int A; cin >> A;
    int B; cin >> B;

    if ((A + B) % 2 != 0) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    cout << (A + B) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

val br = BufferedReader(InputStreamReader(System.`in`))
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    // 回答をここに書く
    val (a, b, c) = listOfInt()
    val r = if(a + b >= c) "Yes" else "No"
    println(r)
}

// 入力取得
fun next() = br.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
            .filter { value % it == 0L }
            .map { listOf(it, value / it) }
            .flatten()
            .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 35884
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int value_type; /* ソートするキーの型 */
typedef long long int lli;

value_type med3(value_type x, value_type y, value_type z)
/* x, y, z の中間値を返す */
{
  if (x < y)
    if (y < z)
      return y;
    else if (z < x)
      return x;
    else
      return z;
  else if (z < y)
    return y;
  else if (x < z)
    return x;
  else
    return z;
}

void quicksort(value_type a[], int left, int right)
/* クイックソート
 * a     : ソートする配列
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 */
{
  if (left < right) {
    int i = left, j = right;
    value_type tmp,
        pivot = med3(a[i], a[i + (j - i) / 2],
                     a[j]); /* (i+j)/2ではオーバーフローしてしまう */
    while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
      while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
      while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
      if (i >= j) break;
      tmp = a[i];
      a[i] = a[j];
      a[j] = tmp; /* a[i],a[j] を交換 */
      i++;
      j--;
    }
    quicksort(a, left, i - 1);  /* 分割した左を再帰的にソート */
    quicksort(a, j + 1, right); /* 分割した右を再帰的にソート */
  }
}

int main() {
  int i, j;
  lli* d = (lli*)malloc(sizeof(lli) * 200001);
  int* dnum = (int*)malloc(sizeof(int) * 200001);
  lli* t = (lli*)malloc(sizeof(lli) * 200001);
  int* tnum = (int*)malloc(sizeof(int) * 200001);

  int N, M;
  lli temp;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%lld", &d[i]);
  }
  scanf("%d", &M);
  /*
  if(M>N) {
    printf("No");
  }
  */
  for (i = 0; i < M; i++) {
    scanf("%lld", &t[i]);
  }

  quicksort(d, 0, N - 1);
  quicksort(t, 0, M - 1);
  /*
  printf("N: \n");
  for (i = 0; i < N; i++) {
    printf("%lld\n", d[i]);
  }
  printf("M; \n");
  for (i = 0; i < M; i++) {
    printf("%lld\n", t[i]);
  }
  */
  int flag = 0;
  int nd_flag = 0;
  int cur = 0;
  for (i = 0; i < M; i++) {
    //printf("Go\n");
    flag = 0;
    for (j = cur; j < N; j++) {
      if (t[i] == d[j]) {
        cur = j + 1;
        d[j] = 0;
        flag = 1;
        //printf("t: %d, d: %d\n", t[i], d[j]);
        break;
      } else if (d[j] > t[i]) {
        break;
      }
    }
    if (flag == 0) {
      nd_flag = 1;
      break;
    }
  }
  /*
    for (i = 0; i < M; i++) {
      flag = 0;
      for (j = 0; j < N; j++) {
        if (t[i] == d[j]) {
          flag = 1;
          d[j] = 0;
          break;
        }
      }
      if (flag == 0) {
        nd_flag = 1;
        break;
      }
    }
    */

  if (nd_flag != 1) {
    printf("YES");
  } else {
    printf("NO");
  }
  return 0;
}

Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderPractice
{
    class Replacing
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            ulong[] a = Console.ReadLine().Split().Select(ulong.Parse).ToArray();
            var q = int.Parse(Console.ReadLine());
            int[,] bc = new int[q,2];
            ulong sum = 0;
            int[] num = new int[100001];

            for(int i = 0; i < q; i++)
            {
                var input = Console.ReadLine().Split();
                bc[i, 0] = int.Parse(input[0]);
                bc[i, 1] = int.Parse(input[1]);
            }

            foreach(var x in a)
            {
                num[x]++;
                sum += x;
            }

            for(int i = 0; i < q; i++)
            {
                sum += (ulong)((bc[i, 1]- bc[i, 0]) * num[bc[i, 0]]);;
                num[bc[i, 1]] += num[bc[i, 0]];
                num[bc[i, 0]] -= num[bc[i, 0]];
                Console.WriteLine(sum);
            }
        }
    }
}


Measured memory_bytes: 51456
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

const int mod = 1000000007;

int main()
{
	LL n, k;
	cin >> n >> k;
	LL ans = n - k + 2;
	while(k <= n+1) {
		ans += (n * (n+1) - (n-k) * (n-k+1) - k * (k-1)) / 2 % mod;
		++k;
	}
	cout << ans%mod << endl;
	return 0;
}


Measured memory_bytes: 3620
/***********************************************************
	When you are inspired by passion 
	and you want to live for the current moment

	When your every thought and action
	has the power to become the story of your future

	When difficulties stand to demolish your Glory
	Just remember that Life is a 'Golden adverse Story'

	Withstand it to acheive your passion and dreams
	more amazingly more easily.

	Why then? When writing the story of your Life
	You want to Let someone else hold your pen

					huzaifa242©

***********************************************************/
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define MAX 100005
#define x first 
#define y second

int seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = numeric_limits <int>::max())
{return uniform_int_distribution<int> (l, r)(rng);}

template <typename T, typename G>
ostream& operator << (ostream& out, const pair <T, G> &a) 
{return out << "( " << a.x << ", " << a.y << ")";}

template <typename T>
ostream& operator << (ostream& out, const vector <T> &a) 
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

template <typename T>
ostream& operator << (ostream& out, const set <T> &a) 
{out << "{ "; for(const auto &i: a) out << i << ", "; return out << "}" << endl;}

template <typename T, typename G>
ostream& operator << (ostream& out, const map <T, G> &a) 
{out << "< "; for(const auto &i: a) out << i << ", "; return out << ">" << endl;}

template <typename T, size_t N>
typename enable_if<!is_same <typename remove_cv <T>::type, char>::value,
ostream&>::type operator << (ostream& out, T (&a)[N])
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

void debug_out(){cerr << endl;} 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr << (H) << ' '; debug_out(T...);}
 
#ifdef LOCAL
#define debug(...) cerr << '#' << #__VA_ARGS__ << ":\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 24
#endif

int mod = 998244353;
int md(int x, int mdo = mod) {
	x %= mdo;
	return x < 0? x + mdo: x;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n, x, m, sum = 0, rem;
	cin >> n >> x >> m;
	mod = m;
	rem = n;
	vector <int> edge(m, 0);
	pair <int,int> cyc = {-1, -1};
	int cyc_sum = 0, cur;
	for (int i = 1; i <= n; ++i) {
		sum = sum + x;
		rem--;
		if (edge[x]) {
			cyc = {edge[x], i - 1};
			cur = x;
			sum -= x;
			rem++;
			for (int j = edge[x]; j < i; ++j) {
				cyc_sum = cyc_sum + cur;
				cur = md(cur * cur);
			} 
			break;
		}
		edge[x] = i;
		x = md(x * x);
	}
	if (cyc != pair <int,int> (-1, -1)) {
		int complete = rem / (cyc.y - cyc.x + 1);
		rem -= (complete * (cyc.y - cyc.x + 1));
		sum = sum + complete * cyc_sum;
		for (int i = 0; i < rem; ++i) {
			sum = sum + cur;
			cur = md(cur * cur);
		}
	} 
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 3980
#include<bits/stdc++.h>
using namespace std;
int n,ar[55];
int main(){
    cin>>n;for(int i=1;i<=n;i++){cin>>ar[i];}
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            swap(ar[i],ar[j]);
            if(is_sorted(ar+1,ar+n+1)){
                cout<<"YES";return 0;
            }
            swap(ar[i],ar[j]);
        }
    }
    cout<<"NO";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>  // ver1.9.4
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl;
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(8);
  string s;
  cin >> s;
  Vi a(26);
  
  rep(i,0,s.size()){
    a[s[i]-'a']++;
  }
  
  if(s=="zyxwvutsrqponmlkjihgfedcba") cout<<-1<<endl;
  
  else if(s.size()!=26){
    int memo;
    rep(i,0,26){
      if(a[i]==0) {memo=i;break;}
      
    }
    char c = 'a' + memo;
    s += c;
    cout << s << endl;
  }
  
  else{
    vector<char> ch(0);
    int qw,er=s.size()-1;
    char are,memo2;
    repreq(i,er,1) {
      if(s[i-1]<s[i]){qw=i;ch.pb(s[i]);are=s[i-1];break;}
      ch.pb(s[i]);
    }
    sort(ALL(ch));
    string ans="";
    rep(i,0,qw-1) ans+=s[i];
    
    rep(i,0,ch.size()){
      if(ch[i]>are) {memo2=ch[i];break;}
    }
    
    ans += memo2;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[100010]={};
vector<int>v;
main(){
    for(int i=2;i<1e5+10;++i){
        if(a[i])continue;
        else{
            v.emplace_back(i);
            for(int k=1;i*k<1e5+10;++k){
                a[i*k]=1;
            }
        }
    }
    int x;
    cin>>x;
    int pos=lower_bound(v.begin(),v.end(),x)-v.begin();
    cout<<v[pos]<<endl;
}


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

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        int[][][] array = new int [4][3][10];
        for(int i = 0; i < x; i++){
            String[] str = br.readLine().split(" ");
            int house  = Integer.parseInt(str[0])-1;
            int floor  = Integer.parseInt(str[1])-1;
            int room   = Integer.parseInt(str[2])-1;
            int person = Integer.parseInt(str[3]);
            array[house][floor][room] += person;
        }
        for(int i = 0; i < array.length; i++){
            if(!(i ==0)){
                System.out.println("####################");
            }
            for(int j = 0; j < array[i].length; j++){
  
                for(int k = 0; k < array[i][j].length; k++){
                    System.out.print(" "+array[i][j][k]);
                    if(k == array[i][j].length-1){
                        System.out.println("");
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 24452
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>
using ll = long long;
using namespace std;
const ll MOD = 1e9 + 7;

int sx,sy,tx,ty;



int main(int argc, const char * argv[]) {
 
    cin >> sx >> sy >> tx >> ty;
    string cmd = "";
    string tmp = "";
    for(int i = 0; i < ty - sy; i++){
        tmp += 'U' ;
    }
    for(int i = 0; i < tx - sx; i++){
        tmp += 'R' ;
    }
    cmd += tmp;
    for(int i = 0; i < tmp.size(); i++){
        if(tmp[i] == 'U'){
            cmd += 'D';
        }else if(tmp[i] == 'R'){
            cmd += 'L';
        }
    }
    
    tmp = 'L';
    for(int i = 0; i < ty - sy + 1; i++){
        tmp += 'U' ;
    }
    for(int i = 0; i < tx - sx + 1; i++){
        tmp += 'R' ;
    }
    tmp += 'D';
    cmd += tmp;
    for(int i = 0; i < tmp.size(); i++){
        if(tmp[i] == 'U'){
            cmd += 'D';
        }else if(tmp[i] == 'R'){
            cmd += 'L';
        }else if(tmp[i] == 'D'){
            cmd += 'U';
        }else if(tmp[i] == 'L'){
            cmd += 'R';
        }
    }
    
    cout << cmd << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define MOD (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

int h,w;
char board[410][410];
bool board1[410][410];

bool check1(int i, int j) {
	return (i >= 0) && (i < h) && (j >= 0) && (j < w) && (!board1[i][j])&&(board[i][j]=='#');
}

bool check2(int i, int j) {
	return (i >= 0) && (i < h) && (j >= 0) && (j < w) && (!board1[i][j])&&(board[i][j]=='.');
}

int main(void){
	ll n,k;
	cin>>n>>k;
	vector<ll>a(n),x;
	for(ll i=0;i<n;i++)cin>>a[i];
	for(ll i=0;i<n;i++){
		ll sum=0;
		for(ll j=i;j<n;j++){
			sum+=a[j];
			x.push_back(sum);
		}
	}
	ll digit=0,sum=0;
	for(ll i=39;i>=0;i--){
		digit=(1LL<<i);
		ll cnt=0;
		for(ll j=0;j<x.size();j++){
			if(((sum+digit)&x[j])==sum+digit)cnt++;
		}
		if(cnt>=k)sum+=digit;
	}
	cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 6388
A, B, C, X = [int(input()) for _ in range(4)]
cnt = 0
for l in range(A+1):
    for m in range(B+1):
        for n in range(C+1):
            if 500 * l + 100 * m + 50 * n == X:
                cnt += 1
print(cnt)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

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;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n;cin >> n;
  vector<string> hoge(n);
  vector<int> Alpha(26, 100000);
  string tmp;
  rep_i(i, n){
    cin >> tmp;
    sort(tmp.begin(), tmp.end());
    for (int i = 0; i < Alpha.size(); i++){
      char a = 97 + i;
      int count = 0;
      for (int t = 0; t < tmp.length(); t++){
        if(tmp[t] == a){
          count += 1;
        }
      }
      if(count <= Alpha[i]){
        Alpha[i] = count;
      }
    }
  }
  string ans;
  char al;
  rep_i(i, 26){
    for (int v = 0; v < Alpha[i]; v++){
      al = 97 + i;
      ans += al;
    }
  }
  say(ans);
  // vector<char> common(hoge[0].length());
  // rep_i(i, hoge[0].length()){
  //   common[i] = hoge[0][i];
  // }
  // vector<int> ng;
  // for(int i = 1; i < n; i++){
  //   for(int v = 0; v < common.size(); v++){
  //     if(hoge[i].find(common[v]) == string::npos){
  //       common[v] = 0;
  //     }
  //   }
  // }

  // string ans;
  // rep_i(i, common.size()){
  //   if(common[i] == 0){
  //     continue;
  //   }
  //   ans += common[i];
  // }
  
  // say(ans);
}

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

using namespace std;

int main()
{
	long long i, min;
	min = 1000000000000000;
	long long N;
	long long a[5];
	cin >> N;
	for (i = 0; i < 5; i++)
	{
		cin >> a[i];
		if (a[i] < min)
		{
			min = a[i];
		}
	}
	cout << 4 + ((N + min - 1) / min);
	
	return 0;
}

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

typedef long long ll;

int main() {
  ll s;
  cin >> s;
  vector<int> S;
  while( s > 0) {
      S.push_back(s%10);
      s /= 10;
  }
  reverse(S.begin(), S.end()); 
  int N = S.size();
  ll ans = 0;
  rep(i, N) {
    int left = i;
    int right = N - i - 1;
    ll score = 1;
    rep(k, right+1) {
      if (right - k > 0) {
        ans += S[i] * score * (1 << left) * (1 << (right - k-1));
      }
      else {
        ans += S[i] * score * (1 << left);
      }
      score *= 10;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>

void draw_as(int num)
{
	if (num == 0) return;
	printf("*");
	draw_as(--num);
}

int main(void)
{
	float in_tmp;
	int data[6] = { 0 };
	int no;
	int i;
	
	scanf("%d ", &no);
	
	while (no--){
		scanf("%f", &in_tmp);
		if (in_tmp < 165.0) data[0]++;
		else switch((int)((in_tmp - 165) / 5)){
		  case 0:
		  	data[1]++;
			break;
			
		  case 1:
		   	data[2]++;
			break;
			
		  case 2:
		  	data[3]++;
			break;
			
		  case 3:
		  	data[4]++;
			break;
			
		  default:
		  	data[5]++;
			break;
		}
	}
	
	for (i = 0; i < 6; i++){
		printf("%d:", i + 1);
		draw_as(data[i]);
		puts("");
	}
	
	return (0);
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
const ll mod = 1000000007;

string s;
int main(){
	cin >> s;
	SORT(s);
	if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]){
		puts("Yes");
	}
	else{
		puts("No");
	}
}

Measured memory_bytes: 256
mod=10**9+7
h,w,a,b=map(int,input().split())
def comb(a,b):
	p=fac[a-b]*fac[b]%mod
	return fac[a]*pow(p,mod-2,mod)%mod
fac=[1]
for i in range(h+w):
	fac.append(fac[-1]*(i+1)%mod)
ans=0
for i in range(w-b):
	p=comb(h-a-1+b+i,b+i)*comb(w-b-i-2+a,a-1)
	ans+=p%mod
	ans%=mod
print(ans)

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

int main() {
    ll N, K, ans = 0, z = 0; cin >> N >> K;
    for (ll i = 1; i <= N; i++) ans += N/i * max(i-K, z) + max(z, N%i - K +1);
    if (K == 0) ans -= N;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 100002979
#define mod2 998244353
#define space 5005
//<<fixed << setprecision(9)
int p=31;
int p2=37;
int main()
{
    int n,i,j,t;
    boost;

    ll po[space],po2[space];
    po2[0]=po[0]=1;
    rep(i,1,space)
    {
        po[i]=po[i-1]*p;
        po[i]%=mod;
        po2[i]=po2[i-1]*p2;
        po2[i]%=mod2;
    }
    string s;
    cin>>n>>s;

    ll h[n+1],h2[n+1];
    h2[0]=h[0]=0;
    rep(i,1,n+1)
    {
        h[i]=h[i-1] + (s[i-1]-'a'+1)*po[i-1];
        h[i]%=mod;
        h2[i]=h2[i-1] + (s[i-1]-'a'+1)*po2[i-1];
        h2[i]%=mod2;
    }
    ll hsh,hsh2;
    int r=n/2,l=0,mid=(l+r)/2;
    while(r-l>1)
    {
        mid=(l+r)/2;

        i=mid;
            map<pii,vi> mp;
            rep(j,i-1,n)
            {
                hsh=h[j+1]-h[j-i+1]+mod;
                hsh%=mod;
                hsh*=po[n-1-j];
                hsh%=mod;

                hsh2=h2[j+1]-h2[j-i+1]+mod2;
                hsh2%=mod2;
                hsh2*=po2[n-1-j];
                hsh2%=mod2;
                mp[{hsh,hsh2}].pb(j);
            }
            int flag=0;
            for(auto z:mp)
            {
                if((int)z.S.size()>1)
                {
                    if(z.S.back()-z.S[0]>=i)
                    {
                        flag=1;break;
                    }
                }
            }

        if(flag)   
        {
            l=mid;
        }
        else r=mid-1;
    }

    i=r;
            map<pii,vi> mp;
            rep(j,i-1,n)
            {
                hsh=h[j+1]-h[j-i+1]+mod;
                hsh%=mod;
                hsh*=po[n-1-j];
                hsh%=mod;

                hsh2=h2[j+1]-h2[j-i+1]+mod2;
                hsh2%=mod2;
                hsh2*=po2[n-1-j];
                hsh2%=mod2;
                mp[{hsh,hsh2}].pb(j);
            }
            int flag=0;
            for(auto z:mp)
            {
                if((int)z.S.size()>1)
                {
                    if(z.S.back()-z.S[0]>=i)
                    {
                        flag=1;break;
                    }
                }
            }
            if(flag)l=r;
    cout<<l;

    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

LL C[51][51];

void comb_table(int N){
    REP(i,N+1) REP(j,i+1){
        if(j == 0 || j == i){
            C[i][j] = 1LL;
        }
        else{
            C[i][j] = (C[i-1][j-1]+C[i-1][j]);
        }
    }
}


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
    int N; cin >> N;
    int A,B; cin >> A >> B;
    comb_table(N);
    VL v(N); REP(i,N) cin >> v[i];
    sort(v.begin(),v.end(),greater<LL>());
    double ans = 0;
    REP(i,A){
        ans += v[i];
    }
    ans = ans / double(A);
    cout << ans << endl;


    //cout << printVector(v) << endl;

    if(v[0] != v[A-1]){
        int end;
        int start = -1;
        for(int i = 1; i < N; i++){
            if(v[i] == v[A-1]){
                dump(i)
                if(start == -1) start = i;
                //cnt = i - A + 1;
                end = i;
            }
        }
        dump(A)
        dump(end)
        dump(start)
        cout << C[end-start+1][A-start] << endl;
    }
    else{
        LL cnt = N;
        LL ans2 = 0;
        for(int i = A; i < N; i++){
            if(v[i] != v[0]){
                cnt = i;
                break;
            }
        }

        dump(cnt)
        for(int i = A; i <= B; i++){
            if(cnt >= i){
                dump(i)
                dump(C[cnt][i])
                ans2 += C[cnt][i];
            }
        }
        cout << ans2 << endl;

    }



}

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

int main() {
	string s;
	cin >> s;
	if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int N = 21;
const int M = 1e9+7;
int dp[N][1<<N];
bool g[N][N];
int n;

int lg2(const int &x) { return 31-__builtin_clz(x); }

int f(int id, int mask) {
    if (id == n) return 1;
    int &r = dp[id][mask];
    if (r != -1) return r;
    
    r = 0;
    for (int aux = mask; aux; aux &= aux-1) {
        int j = lg2(aux & -aux);
        if (g[id][j]) {
            int next = mask^(1<<j);
            r = (r + f(id+1, next)) % M;
        }
    }
    return r;
    
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> n;
    forn(i, 0, n) {
        forn(j, 0, n) {
            cin >> g[i][j];
        }
    }
    
    memset(dp, -1, sizeof dp);
    cout << f(0, (1<<n)-1) << endl;
}


Measured memory_bytes: 175696
#include <stdio.h>
int B[101],cnt=0;
void SelectionSort(int n);
int main(void){
	int i,j,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&B[i]);
	SelectionSort(n);
	for(i=0;i<n;i++){
		if(i) printf(" ");
		printf("%d",B[i]);
	}
	printf("\n%d\n",cnt);
	return 0;
}

void SelectionSort(int n){
	int min,z,tmp,i,j;
	for(j=0;j<n-1;j++){
		min = B[j];
		z = j;	
		for(i=j+1;i<n;i++){	
			if(B[i] < min){
				min = B[i];
				z = i;
			}
		}
		if(B[j] != B[z]){
			tmp = B[j];
			B[j] = B[z];
			B[z] = tmp;
			cnt++;
		}
	}
}

Measured memory_bytes: 604
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

const int N = 100010;

int A[N], n;
int cnt[5];

int main(){
	scanf("%d", &n);
	For(i, 1, n){
		scanf("%d", &A[i]);
		if(A[i] % 4 == 0) cnt[2]++;
		else if(A[i] % 2 == 0) cnt[1]++;
		else cnt[0]++;
	}
	int nxt = 2;
	For(i, 1, n){
		bool flag = false;
		For(j, 2 - nxt, 2) if(cnt[j]) {flag = true; --cnt[j]; nxt = j; break;}
		if(!flag){
			puts("No"); return 0;
		}
	}
	puts("Yes");
	return 0;
}

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

#define INF 2147483647
#define RMQ_SIZE 262144  // 2^18

int tree[RMQ_SIZE];

int dfs(int a, int b, int k, int l, int r);
int find(int first, int second);
void update(int pos, int value);
int min(int a, int b);


int main(void)
{
    int n, q, com, x, y, i;

    scanf("%d %d", &n ,&q);

    for (i = 0; i < n; i++) {
        update(i, INF);
    }

    for (i = 0; i < q; i++) {
        scanf("%d %d %d", &com, &x, &y);
        if (com) {
            printf("%d\n", find(x, y+1));
        } else {
            update(x, y);
        }
    }
    
    return 0;
}

/*
 * a??????b???????????????????????¢?´¢????????????????±????.
 * ?????¨???tree[k]???????????????.
 * tree[k]???l??????r?????§???????°?????????????.
 */
int dfs(int a,int b,int k,int l,int r)
{
    int m;
    //* a~b??¨l~r??????????????????????????¨????????¨?????????.
    if (r <= a || b <= l) {
        return INF;
    }
    //* tree[k]?????¬?????????????±?????????\???a~b?????????????????¨???.
    if (a <= l && r <= b) {
        return tree[k];
    }
    m = (l+r)/2;
    return min(dfs(a, b, k*2, l, m), dfs(a, b, k*2+1, m, r));
}

int find(int right, int left)
{
    return dfs(right, left, 1, 0, RMQ_SIZE/2);
}

void update(int pos, int value)
{
    pos += RMQ_SIZE/2;
    tree[pos] = value;
    while (pos) {
        pos = pos/2;
        tree[pos] = min(tree[pos*2], tree[pos*2+1]);
    }
}

int min(int a, int b)
{
    return a < b ? a: b;
}

Measured memory_bytes: 1412
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		// top k in maxheap (store min elements)
		PriorityQueue<Integer> maxHeap = new PriorityQueue<>(k, Collections.reverseOrder());
		for (int i = 0; i < n; i++) {
			int val = sc.nextInt();
			// System.out.println("val: " + val);
			if (maxHeap.size() < k) {
				maxHeap.offer(val);
			} else {
				if (val < maxHeap.peek()) {
					maxHeap.poll();
					maxHeap.offer(val);
				}
			}
		}

		int ans = 0;
		while (!maxHeap.isEmpty()) {
			ans += maxHeap.poll();
		}
		System.out.println(ans);
	}

}


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

int main() {
    int n;
    int ver = 0, edg = 0;
    std::cin >> n;
    std::vector<int> pow(21);
    pow[0] = 1;
    for (int i = 1; i < 21; i++) pow[i] = pow[i - 1] * 2;
    int d = 1, cnt = std::bitset<20>(n).count();
    while (n >> (d + 1) > 0) d++;
    std::cout << d + 1 << " " << 2 * d + cnt - 1 << "\n";
    std::vector<std::deque<int>> g(d + 1), c(d + 1);
    for (int i = 0; i < d; i++) {
        int cost = pow[d - 1 - i];
        g[i].push_back(i + 1);
        c[i].push_back(0);
        g[i].push_back(i + 1);
        c[i].push_back(cost);
    }
    int cc = 1 << d;
    n -= cc;

    while (n) {
        while (n >> (d - 1) == 0) d--;
        g[0].push_back(g.size() - d);
        c[0].push_back(cc);
        cc += pow[d - 1];
        n -= pow[d - 1];
    }

    for (int i = 0; i < g.size(); i++) {
        while (!g[i].empty()) {
            std::cout << i + 1 << " " << g[i].front() + 1 << " " << c[i].front() << "\n";
            g[i].pop_front();
            c[i].pop_front();
        }
    }
    std::cout << std::flush;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    boolean ans=false;

    for (int i=1;i<10;i++) {
      for (int j=1;j<10;j++) {
        if(i*j==n) ans=true;
      }
    }

    if (ans==true) {
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23124
var s:array[1..20] of char;
    a:char;
    n,k,i:integer;
begin
  readln(n);
  i:=1;
  repeat
   read(s[i]);
   inc(i);
  until eoln;
  read(k);
  a:=s[k];
  for i:=1 to n do 
    if s[i]=a then write(a)
    else write('*')
end.


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long 
#define INF 1e9
#define LINF 1e18
 
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;
 
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int N, M;
int dist[101][101], tmp[101][101];
P p[1000];

void Warshall_Floyd() {
    for(int k = 0; k < N; ++k) {
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                chmin(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

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

    cin >> N >> M;
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            dist[i][j] = LINF;
        }
    }
    for(int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        dist[a][b] = dist[b][a] = c;
        tmp[a][b] = tmp[b][a] = c;
        p[i] = P(a, b);
    }
    Warshall_Floyd();
    int res = 0;
    for(int i = 0; i < M; ++i){
        int a = p[i].first, b = p[i].second;
        if(dist[a][b] != tmp[a][b]) ++res;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <string>
using namespace std;
#include<chrono>
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define foo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define min3(a,b,c)         min(a,min(b,c))
#define max3(a,b,c)         max(a,max(b,c))
#define min4(a,b,c,d)       min(a,min(b,min(c,d)))
#define max4(a,b,c,d)       max(a,max(b,max(c,d)))
#define max5(a,b,c,d,e)     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)     min(min3(a,b,c),min(d,e))
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void DFS(int n);
bool isprime(ll n);
int gcd(int a,int b);
void rstgraph(int n);

const int mod = pow(10,9)+7;
const int N = 3e5, M = N;

//=======================================================================================
vi g[N];
int vis[N];
int nodes=0;
// ll ans=0;
void iluzn() {
  int r;
  cin>>r;
  cout<<2*PI*r;
}

 
int main() {
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t=1,i;
    // cin>>t;
     while(t--) iluzn();
    return 0;
}
int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}
bool isprime(ll n){
    if(n<=1)
        return false;
    if(n==2)
        return true;
    if(n%2==0)
        return false;
    ll rt = sqrt(n);
    for(ll i=3;i<rt;i+=2){
        if(n%i==0)
            return false;
    }
    return true;
}
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
void ipgraph(int m){
  int u, v;
  while(m--){
    cin>>u>>v;
    g[u].pb(v);
    // g[v].pb(u);
  }
}

void DFS(int n)
{  ++nodes;
    vis[n] = 1;
    for(vector<int>::iterator i = g[n].begin(); i != g[n].end() ; i++)
    {
        if(!vis[*i])
            DFS(*i);
    }
}
void rstgraph(int n){
  int i;
  fo(i,n+1){
    g[i].clear();
    vis[i]=0;
  }
  nodes=0;
}

Measured memory_bytes: 10828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int k,n;
    cin>>k>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int l=0;
    rep(i,n){
        if(i==n-1) l=max(l,k-a[i]+a[0]);
        else l=max(l,a[i+1]-a[i]);
    }
    cout<<k-l<<endl;
}

Measured memory_bytes: 1024