akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  int ans = 0;
  int height = 0;
  for(int i = 0;i < n - 1; ++i){
    if(h[i] >= h[i + 1]) height++;
    else height = 0;
    ans = max(ans, height);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=1000005;
char s[maxn];
int a[maxn],q[maxn],n,m;
inline void solve(int k){
	int l=1,r=n,tag=0;
	rep(i,1,n)q[i]=s[i]-'A';
	rep(i,1,k){
		if((tag^q[l])==0)
			q[l]^=1;
		else{
			l++;tag^=1;
			q[++r]=tag;
		}
	}
	rep(i,1,n)a[i]=q[l+i-1]^tag;
}
int main(){
//	judge();
	read(n);read(m);scanf("%s",s+1);
	if(m<=2*n)
		solve(m);
	else 
		if(m&1)
			solve(2*n-1);
		else
			solve(2*n);
	rep(i,1,n)putchar('A'+a[i]);
	return 0;
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define nmax 100005
using namespace std;
int n, m, x, v[nmax];
char ch;
struct a
{
    int val, poz;
};
a aint[nmax*4];
void build(int nod, int st, int dr)
{
    if (st == dr){
        aint[nod].val = v[st];
        aint[nod].poz = st;
        return;
    }
    int m = (st + dr) / 2;
    build(nod<<1,st,m);
    build(nod<<1|1,m+1,dr);
    if (aint[nod<<1].val <= aint[nod<<1|1].val){
        aint[nod] = aint[nod<<1];
    } else {
        aint[nod] = aint[nod<<1|1];
    }
}
a query(int nod, int st, int dr, int x, int y){
    if (x <= st && dr <= y){
        return aint[nod];
    }
    int m = (st + dr) / 2;
    a a1, a2;
    a1.val = 999;
    a2.val = 999;
    if (x <= m){
        a1 = query(nod<<1,st,m,x,y);
    }
    if (y > m){
        a2 = query(nod<<1|1,m+1,dr,x,y);
    }
    if (a1.val <= a2.val){
        return a1;
    }
    return a2;
}
int main()
{
    cin>>n>>m;
    for (int i=0;i<=n;++i){
        cin>>ch;
        v[i]=ch-'0';
    }
    build(1, 0, n-1);
    vector<int>ans;
    int poz = n;
    while (poz > 0){
        int cr = max(poz-m, 0);
        a act = query(1, 0, n-1, cr, poz-1);
        if (act.val != 0){
            cout<<"-1\n";
            return 0;
        }
        int add = poz - act.poz;
        ans.push_back(add);
        poz = act.poz;
    }
    reverse(ans.begin(), ans.end());
    for (auto x:ans){
        cout<<x<<' ';
    }
    cout<<'\n';
    return 0;
}


Measured memory_bytes: 3448
import sys
input = sys.stdin.readline

from collections import defaultdict

def DD(arg): return defaultdict(arg)

def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

H,W = list(map(int,input().split()))
data = [list(map(int, input().split())) for _ in range(H)]

class BIT:
  def __init__(self, logn):
    self.n = 1<<logn
    self.data = [0]*(self.n+1)
    self.el = [0]*(self.n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)
  def bisect(self, x):
    w = i = 0
    k = self.n
    while k:
      if i+k <= self.n and w + self.data[i+k] < x:
        w += self.data[i+k]
        i += k
      k >>= 1
    return i+1

dic = DD(int)
for i in range(W):
  dic[i+1] = i+1

members = DD(int)
for i in range(W):
  members[i+1] = 1

B = BIT(int_log(W,2)+1)
for i in range(W):
  B.add(i+1,1)

def calc_prev_valid(x):
  s = B.sum(x-1)
  if s == 0:
    return 0
  else:
    return B.bisect(s)

count_score = DD(int)
count_score[0] = W
score = 0

for i in range(H):
  a,b = data[i]
  now = b

  while now >= a:
    if B.el[now]:
      count_score[now-dic[now]] -= members[now]
      if not B.el[b+1]:
        dic[b+1] = dic[now]
        B.add(b+1,1)
      if b+1 < W+1:
        count_score[(b+1)-dic[b+1]] += members[now]
      B.add(now,-1)
      members[b+1] += members[now]
      members[now] = 0
    now = calc_prev_valid(now)

  while True:
    if count_score[score]:
      print(score+i+1)
      break
    else:
      score += 1
    if score == W:
      for _ in range(H-i):
        print(-1)
      exit()

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

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

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

  sort(a.begin(), a.end());
  int64_t tmp = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    while (tmp < m) {
      if (a[i].second > 0) {
        ans += a[i].first;
        tmp++;
        a[i].second--;
      }
      else {
        break;
      }
    }
    if (tmp >= m) {
      break;
    }
  }

  cout << ans << endl;
}

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

int main(){
    int x; cin >> x;
    vector<bool> expo(x+1);
    
    expo[1] = 1;
    for(int b = 2; b <= x; b++){
        int v = b*b;
        while(v<=x){
            expo[v] = 1;
            v *= b;
        }
    }
    for(int i = x; i >= 1; i--){
        if(expo[i]){
            cout << i << endl;
            break;
        }
    }
}


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

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;

int N;
int P[10];
int Q[10];

int main(){

    cin >> N;
    for(int i = 0; i < N; i++) cin >> P[i];
    for(int i = 0; i < N; i++) cin >> Q[i];
    
    int *A[2] = {P, Q};

    vector<int> vals;
    for(int j = 0; j < 2; j++){
        int *V = A[j];
        vector<int> v;
        for(int i = 0; i < N; i++) v.push_back(1 + i);
        int cnt = 1;
        do{
            bool match = true;
            for(int i = 0; i < N; i++){
                if(v[i] != V[i]) match = false;
            }
            if(match){
                vals.push_back(cnt);
                break;
            }
            cnt++;
        }while(next_permutation(v.begin(), v.end()));
    }
    cout << abs(vals[0] - vals[1]) << endl;;
    


    return 0;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
S = []
for i in range(H):
	S.append(list(input()))

ans = [['' for i in range(W)] for j in range(H)]
for i in range(H):
	for j in range(W):
		if S[i][j] == '#':
			ans[i][j] = '#'
			continue
		x = [1,1,1,0,0,-1,-1,-1]
		y = [1,0,-1,1,-1,1,0,-1]
		cnt = 0
		for k in range(len(x)):
			ii = i+x[k]
			jj = j+y[k]
			if 0 <= ii and ii < H and 0 <= jj and jj < W:
				if S[ii][jj] == '#':
					cnt += 1
		ans[i][j] = str(cnt)

for i in range(H):
	print(''.join(ans[i]))


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

int main(){
    int N;
    cin>>N;
    
    string s;
    
    cin>>s;
    
    int red=0,ans=0;
    for(int i=0;i<N;i++){
        if(s[i]=='R')
            red++;
    }
    
    for(int i=0;i<red;i++){
        if(s[i]=='W')
            ans++;
            
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3668
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int d = scanner.nextInt();
		int x = scanner.nextInt();
		int[] a = new int[n];
		int ans = 0;
		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		
		
		for (int i = 0; i < n ; i++) {
			for (int j = 0; ((j * a[i]) + 1) <= d; j++) {
				ans++;
				
			}
		}
		
		ans += x;
		
		System.out.println(ans);
		scanner.close();

	}

}


Measured memory_bytes: 21972
<?php
define("MOD", 10**9+7);
define("MAX", 10**5);
fscanf(STDIN, "%d%d", $n, $k);
$A = array_map("intval", explode(" ", fgets(STDIN)));
sort($A);

$f[0] = $invf[0] = $invf[1] = 1;
for($i = 1; $i <= $n; $i++)$f[$i] = $f[$i-1]*$i%MOD;
for($i = 2; $i <= $n; $i++)$invf[$i] = (MOD - intdiv(MOD, $i))*$invf[MOD%$i]%MOD;
for($i = 2; $i <= $n; $i++)$invf[$i] = $invf[$i]*$invf[$i-1]%MOD;;
$ans = 0;
foreach($A as $i => $a){
    if($n-$i-1 >= $k-1){
        $ans = ($ans + MOD*MOD - $a * nCm($n-$i-1, $k-1))%MOD;
    }
}
$A = array_reverse($A);
foreach($A as $i => $a){
    if($n-$i-1 >= $k-1){
        $ans = ($ans + $a * nCm($n-$i-1, $k-1))%MOD;
    }
}
echo (($ans%MOD)+MOD)%MOD;
function nCm($n, $m){
    global $f, $invf;
    return $f[$n] * $invf[$n-$m] % MOD * $invf[$m] % MOD;
}


Measured memory_bytes: 25200
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
signed main()
{
	long long n, ans = 1ll << 60;
	scanf("%lld", &n);
	for(long long i = 1; i <= sqrt(n) + 1; ++i)
	{
		if(n % i == 0)
		{
			ans = min(ans, i + n / i);
		}
	}
	printf("%lld\n", ans - 2);
}


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

const int INF = 0x3f3f3f3f;
const int maxn = 1000010;

//变量
int n, m, root;
int a[maxn] = { 0 }; 
int ch[maxn][2];//记录儿子，0为左儿子，1为右儿子
int val[maxn];//当前点对应的值
int fa[maxn];//记录当前结点的父亲
int siz[maxn] = { 0 };//记录子树大小
int tag[maxn];//区间翻转的标记 

inline void refresh(int now) {//对于不同题而言，更新信息也不同 
	if (!now) return;
	siz[now] = siz[ch[now][0]] + siz[ch[now][1]] + 1;
} 

int build(int l, int r, int f) {
	if (l > r) return 0;
	int mid = l + r >> 1;
	fa[mid] = f;
	val[mid] = a[mid];
	ch[mid][0] = build(l, mid - 1, mid);
	ch[mid][1] = build(mid + 1, r, mid);
	refresh(mid);
	return mid;
}

void pushdown(int now) {//标记下传 
	if (tag[now]) {
		if (ch[now][0]) {
			tag[ch[now][0]] ^= 1;
			swap(ch[ch[now][0]][0], ch[ch[now][0]][1]);
		}
		if (ch[now][1]) {
			tag[ch[now][1]] ^= 1;
			swap(ch[ch[now][1]][0], ch[ch[now][1]][1]);
		}
		tag[now] = 0;
	}
}

int chk(int x) {//判断这个结点是父亲的左儿子还是右儿子，是左儿子返回0，是右儿子返回1 
	return ch[fa[x]][1] == x;
} 

void rotate(int now) {//旋转操作 
	int f = fa[now], gf = fa[f], k = chk(now), w = ch[now][k ^ 1];
	ch[f][k] = w; fa[w] = f;
	ch[gf][chk(f)] = now; fa[now] = gf;
	ch[now][k ^ 1] = f; fa[f] = now;
	refresh(f); refresh(now);
} 

void splay(int now, int goal = 0) {//伸展操作 
	while (fa[now] != goal) {
		int f = fa[now], gf = fa[f];
		if (gf != goal) {
			if (chk(f) == chk(now)) rotate(f);
			else rotate(now);
		}
		rotate(now);
	} 
	if (!goal) root = now;
}

int kth(int k) {//查询第k大结点 
	int now = root;//从根结点开始搜索
	while (1) {
		pushdown(now);//多一个pushdown 
		if (ch[now][0] && k <= siz[ch[now][0]]) {
			//如果有左子树且左子树大小大于等于k，说明k在左子树上
			now = ch[now][0]; 
		}
		else if (k > siz[ch[now][0]] + 1) {
			//否则如果左子树加上当前结点的大小依然小于k，说明在右子树上
			k -= siz[ch[now][0]] + 1;
			now = ch[now][1];
		}
		else {//否则说明第k大就是当前结点 
			return now;
		}
	} 
}

int split(int l, int r) {
	l = kth(l); r = kth(r + 2);
	splay(l); splay(r, l);
	return ch[r][0];
}

void turn(int l, int r) {
	int now = split(l, r);
	tag[now] ^= 1;
	swap(ch[now][0], ch[now][1]);
}

void dfs(int now) {
	pushdown(now);
	if (ch[now][0]) dfs(ch[now][0]);
	if (val[now] != -INF) printf("%d ", val[now]);
	if (ch[now][1]) dfs(ch[now][1]);
}

int main() {
	scanf("%d", &n);
	a[1] = -INF; a[n + 2] = -INF;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i + 1]);
	}
	root = build(1, n + 2, 0);
	for (int i = 1; i <= n; ++i) {
		turn(1, i);
	}
	dfs(root);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 22912
/* 
	بسم الله الرحمن الرحیم

	(; طلا یک جهانی
*/

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

const int MAX_N = 1000 * 1000 + 5, MOD = 1e9 + 7;
int n, h, d, dp[MAX_N], c, sum;

void read_input() {
	cin >> n >> h >> d;
}

void prep() {
	int fac = 1;
	for (int i = 1; i <= n; i++) {
		fac = 1LL * i * fac % MOD;
		(c += fac) %= MOD;
	}
	sum = dp[0] = fac;
}

void solve() {
	prep();
	for (int i = 1; i <= h; i++) {
		dp[i] = sum;
		if (i < h)
			dp[i] = 1LL * dp[i] * c % MOD;
		(sum += dp[i]) %= MOD;
		if (i >= d)
			(sum -= dp[i - d]) %= MOD;
	}
}

void print_output() {
	cout << (dp[h] + MOD) % MOD;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	read_input();
	solve();
	print_output();
}


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

int gcd(int x, int y){
    if(x < y) swap(x, y);
    int b;
    while(x%y != 0){
        b = x;
        x = y;
        y = b%y;
    }
    return y;
}

int main(){
    int x, y;
    cin >> x >> y;
    cout << gcd(x, y) << endl;
    return 0;
}


Measured memory_bytes: 3128
import java.util.*;

class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int cnt = 0;
		int ans = 0;

		for(int j = 1; j<=N; j=j+2){
				cnt = 0;
			for(int i = 1; i<=j; ++i){
				if(j%i == 0){
					++cnt;
				}
			}
			if(cnt == 8) ++ans;
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 22864
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""

N,T=map(int,input().split())
A=list(map(int,input().split()))
ruimin=[A[0]]
ruimax=[A[-1]]
for i in range(1,N):
    ruimin.append(min(ruimin[-1],A[i]))
for i in range(0,N-1)[::-1]:
    ruimax.append(max(ruimax[-1],A[i]))
ruimax.reverse()

value=1
lst=[]
for i in range(0,N-1):
    if ruimax[i+1]-A[i]==value:
        lst.append(i)
    elif ruimax[i+1]-A[i]>value:
        value=ruimax[i+1]-ruimin[i]
        lst=[i]

print(len(lst))


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


int main()
{
	int a,b,c;
	scanf("%d %d %d", &a,&b,&c);
	if (a < b&&b < c)
		printf("Yes\n", a, b, c);
	else 
		 printf("No\n", a, b, c);
}


Measured memory_bytes: 3192
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    double m = sc.nextDouble();
    int a[] = new int[n];
    long sum = 0;
    int buf = 0;
    String ans = "No";

    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
      sum += a[i];
    }

    for(int i = 0; i < n; i++){
      if(a[i] >= sum / (4 * m)){
        buf += 1;
      }
    }

    if(buf >= m){
      ans = "Yes";
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 24144
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

ld a,b,h,m,T=0;

void solve(){
    cin >> a >> b;
    cin >> h >> m;
    T=60*h+m;
    ld s1=T/(ld)360*pi;
    ld s2=m/(ld)30*pi;
    ld d=abs(s1-s2);
    if(d>pi) d=2*pi-d;
    cout << sqrt(a*a+b*b-2*a*b*cosl(d)) << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 4188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ll n,a[100010][3],dp[100010][3];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(int i=1;i<n;i++){
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
}


Measured memory_bytes: 4992
object Main extends scala.App {
    import java.util
    import scala.collection._
    import scala.collection.mutable
    import scala.math._

    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt()

    val (t1, t2) = ((n.toFloat * 100.0 / 108.0), ((n+1).toFloat * 100.0 / 108.0))
    val (t_min, t_max) = (t1.toInt, t2.toInt)
    val ans = (t_min to t_max).find(_.toFloat.*(1.08).toInt == n)

    ans match {
        case Some(value) => println(value)
        case None => println(":(")
    }
}

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define PB push_back
#define pb push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len(stuff) (int) stuff.size()

#define int long long
#define float long double 
#define ll long long
#define ld long double

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const int inf = (int) 2e18;
const int upper = (int) 3e5 + 50;
const int M = (ll) 1e9 + 7;
const int mod = (ll) 998244353;
const double eps =  1e-8;

int n;
string s;

std::vector<int> pos[26];
signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	 
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	cin >> n >> s;
	s = '%' + s;
	for (int i = 0; i < 26; i += 1) {
		pos[i].push_back(0);
	}
	for (int i = 1; i <= n; i += 1) {
		pos[s[i] - 'a'].push_back(i);
	}
	int ans = 1;
	for (int i = 0; i < 26; i += 1) {
		ans *= len(pos[i]), ans %= M;
	}
	ans--, ans += M, ans %= M;
	cout << ans;
 	end_routine();		
}


Measured memory_bytes: 1644
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define FOR(i,a,b) for (size_t i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (size_t i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define INF 1e7
#define num 111111

int p1[num], p2[num];
vector<int> a, b;

int main()
{
  int n, m1 = 1, m2 = 1, tmp;

  cin>>n;
  REP(i,n/2) {
    cin>>tmp;
    p1[tmp]++;
    cin>>tmp;
    p2[tmp]++;
  }

  REP(i,num) {
    if (p1[i] > m1) {
      a.clear();
      a.push_back(i);
      m1 = p1[i];
    } else if (p1[i] == m1) {
      a.push_back(i);
    }

    if (p2[i] > m2) {
      b.clear();
      b.push_back(i);
      m2 = p2[i];
    } else if (p2[i] == m2) {
      b.push_back(i);
    }
  }

  if (a.size() > 2 || b.size() > 2) {
    cout<<n - m1 - m2<<endl;
  } else if (a[0] != b[0]) {
    cout<<n - m1 - m2<<endl;
  } else {
    sort(p1, p1+num);
    sort(p2, p2+num);
    int r = max(m1 + p2[num-2], m2 + p1[num-2]);
    cout<<n-r<<endl;
  }

  return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	string str;
	cin>>str;
	int mx = 0,mn = 0;
	for(int i = 0;i<str.size()-1;i++){
		if(str[i] != 'C') continue;
		for(int j = i+1;j<str.size();j++){
			if(str[j] != 'F') continue;
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
} 

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
old = A[0]
a = 0 # 持ち株
b = 1000 # 所持金
for i in range(1, N):
    Ai = A[i]
    if old < Ai:
        a += b // old
        b = b % old
    elif old > Ai:
        b += old * a
        a = 0
    old = Ai
b += old * a
print(b)

Measured memory_bytes: 9112
import collections

n = int(input())
s = [input() for _ in range(n)]
c_sort = collections.Counter(s).most_common()
list_most = [c_sort[i][0] for i in range(len(c_sort)) if c_sort[i][1] == c_sort[0][1]]
for i in sorted(list_most):
    print(i)

Measured memory_bytes: 45040
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ans = 0
ruiseki = [0]

for i in A:
    ruiseki.append(ruiseki[-1] + i)

for i in range(N - 1):
    ans += ((ruiseki[N] - ruiseki[i + 1]) * A[i]) % MOD
    ans %= MOD
print(ans)


Measured memory_bytes: 31564
#include <stdio.h>
#include <stdlib.h>
 
struct node{
	int key;
	int priority;
	struct node *right;
	struct node *left;
};

typedef struct node * Node;
#define NIL NULL

Node delete(Node, int); 
Node root;

Node treeMinimum(Node x){
	while ( x->left != NIL ){ x = x->left; }
	return x;
}
 
Node treeMaximum(Node x){
	while ( x->right != NIL ){ x = x->right; }
	return x;
}
 
Node Search(Node u, int k){
	Node ret = NIL;
	if ( u->key == k ){ return u; }
	else if ( u->key > k ){
		if ( u->left != NIL ){ return Search(u->left, k); }
	}
	else if (u->right!=NIL){ return Search(u->right, k); }
	return ret;
}

Node rightRotate(Node t){
	Node s = t->left;
	if ( t == root ){ root = s; }
	t->left = s->right;
	s->right = t;
	return s;
}
 
Node leftRotate(Node t){
	Node s = t->right;
	if ( t == root ){ root=s; }
	t->right = s->left;
	s->left = t;
	return s;
}
 
Node _delete(Node t, int key){
	if (t->left == NIL && t->right==NIL){ return NIL; }
	
	if (t->left == NIL){ t=leftRotate(t); }
	else if (t->right == NIL){ t=rightRotate(t); }
	else{
		if (t->left->priority > t->right->priority){
			t = rightRotate(t);
		}
		else
		{
			t = leftRotate(t);
		}
	}
	return delete(t, key);
}

Node delete(Node t, int key){
	if (key < t->key){ 
		t->left = delete(t->left,key); }
	else if (key > t->key){
		t->right = delete(t->right, key);
	}
	else{
		return _delete(t, key);
	}
	return t;
}

Node insert(Node t, int key, int priority){
	if (t == NIL)
	{
		Node z = malloc(sizeof(struct node));
		z->key = key;
		z->priority = priority;
		z->left = NIL;
		z->right=NIL;
		if (root==NIL) root = z;
		return z;
	}

	if (key == t->key){ return t; }
	
	if (key < t->key)
	{
		t->left = insert(t->left, key, priority);
		if (t->priority < t->left->priority){ t = rightRotate(t); }
	}
	else 
	{
		t->right = insert(t->right, key, priority);
		if (t->priority < t->right->priority){ t = leftRotate(t); }
	}

	return t;
}
 
void inorder(Node u){
	if (u->left != NIL){ inorder(u->left); }
	printf(" %d", u->key);
	if (u->right != NIL){ inorder(u->right); }
}
 
void preorder(Node u){
	printf(" %d", u->key);
	if (u->left != NIL){ preorder(u->left); }
	if (u->right != NIL){ preorder(u->right); }
}
 
void print(){
	if (root == NIL){ return; }
	preorder(root);
	printf("\n");
	inorder(root);
	printf("\n");
}
 
int main(){
	int n, i, x, y;
	Node t;
	char tmp[10];
	root = NIL;
	scanf("%d", &n);

	for (i=0; i<n; i++)
	{
		scanf("%s", tmp);
		if(tmp[0] == 'f')
		{
			scanf("%d", &x);
			t = Search(root, x);
			if (t != NIL){ printf("yes\n"); }
			else{ printf("no\n"); }
		}
		else if(tmp[0] == 'i')
		{
			scanf("%d %d", &x, &y);
			insert(root, x, y);
		}
		else if(tmp[0] == 'p')
		{
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if(tmp[0] == 'd')
		{
			scanf("%d", &x);
			t = Search(root, x);
			if (t != NIL){ delete(root, x); }
		}
	}
	return 0;
}


Measured memory_bytes: 7984
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))
from functools import reduce;gcd=lambda*x:reduce(math.gcd,x);lcm=lambda*x:reduce(lambda x,y:(x*y)//gcd(x,y),x,1)
from collections import deque
Yes=lambda b:print("Yes"if b else"No");YES=lambda b:print("YES"if b else"NO")
is_even=lambda x:True if x%2==0 else False

def main():
  k=aint();a,b=ints()
  ans=0
  for i in range(a,b+1):
    if i%k==0:
      ans+=1
      break
  print("OK"if ans>0 else"NG")

if __name__ == '__main__':
    main()

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007


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

int main()
{
	string A,B;
	cin >> A >> B;
	if(A.size() > B.size()){
		cout << "GREATER" << endl;
		return 0;
	}
	if(A.size() < B.size()){
		cout << "LESS" << endl;
		return 0;
	}
	REP(i,A.size()){
		if(A[i] > B[i]){
			cout << "GREATER" << endl;
			return 0;
		}
		if(A[i] < B[i]){
			cout << "LESS" << endl;
			return 0;
		}
	}
	cout << "EQUAL" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

struct aa {
	int x;
	int y;
	int time;
};


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

int prx, pry;
int hax, hay;
int dfs(const vector<vector<int>>&field, vector<vector<int>>&memo) {

	queue<aa>que;
	que.push(aa{ prx,pry,0 });
	while (!que.empty()) {
		aa atop(que.front());
		if (atop.y == hay&&atop.x == hax)return atop.time;
		que.pop();
		for (int way = 0; way < 4; ++way) {
			const int nextx = atop.x + dx[way];
			const int nexty = atop.y + dy[way];
			const int nexttime = atop.time + 1;
			if (field[nexty][nextx] > nexttime) {

				if (memo[nexty][nextx]>nexttime) {
					memo[nexty][nextx] = nexttime;
					que.push(aa{ nextx,nexty,nexttime });
				}
			}
		}
	}
	return -1;
}

int main() {
	int H, W; cin >> H >> W;
	vector<vector<int>>field(H + 2, vector<int>(W + 2, -1));
	vector<vector<int>>memo(H + 2, vector<int>(W + 2, 1000));

	queue<aa>que;
	for (int i = 0; i < H; ++i) {
		string st; cin >> st;
		for (int j = 0; j < W; ++j) {
			char ch = st[j];
			if (ch == '@') {
				prx = j + 1, pry = i + 1;
				field[i+1][j+1] = 1000;
			}
			else if (ch == '%') {
				hax = j + 1, hay = i + 1;
				field[i + 1][j + 1] = 1000;
			}
			else if (ch == '$') {
				que.push(aa{ j + 1,i + 1,0 });
				field[i + 1][j + 1] = 0;
			}
			else if (ch == '.') {
				field[i + 1][j + 1] = 1000;
			}
			else {
				field[i + 1][j + 1] = -1;
			}
		}
	}
	memo[pry][prx] = 0;
	while (!que.empty()) {
		aa atop(que.front());
		que.pop();
		for (int way = 0; way < 4; ++way) {
			const int nextx = atop.x + dx[way];
			const int nexty = atop.y + dy[way];
			const int nexttime = atop.time + 1;
			if (field[nexty][nextx] >= 0) {

				if (field[nexty][nextx]>nexttime) {
					field[nexty][nextx] = nexttime;
					que.push(aa{ nextx,nexty,nexttime });
				}
			}
		}
	}
	int ans = dfs(field, memo);
	if (ans >= 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3744
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	L := make([]int,N+1)
	L[0] = 2
	L[1] = 1

	for i := 2; i <= N; i++{
		L[i] = L[i-1] + L[i-2]
	}	
	
	fmt.Println(L[N])

}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){

int x;

while(scanf("%d",&x) != EOF){

int count=0;

for(int i= 0; i<=9; i++){
   for(int j = 0; j<= 9; j++){
       for(int k = 0; k<=9; k++){
           for(int l = 0; l<=9; l++){
              if(i+j+k+l==x){
                 count++;
              }
}
}
}
}
printf("%d\n",count);
}
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

i64 n;

const i64 MOD = 1e9 + 7;

i64 dp[202020];
i64 c[202020];
i64 wait[202020];

int main() {
  cin >> n;
  rep(i,1,n) cin >> c[i];
  dp[0] = 1;
  rep(i,1,n) {
    dp[i] = dp[i - 1];
    if(c[i] != c[i - 1]) {
      i64 ww = wait[c[i]];
      wait[c[i]] = (wait[c[i]] + dp[i]) % MOD;
      dp[i]  = (dp[i] + ww) % MOD;
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 4992
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
    static long mod=1000000007;
    
    public static void main(String[] args) {        
        new Thread(null, new Main(), "", 200 * 1024 * 1024).start();        
    }

    public void run() {
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

//        int n=sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();
        for (int i = 1; i < 20000; i++) {
			if(i*8/100==a && b==i*1/10)ret(i);
		}
        

        out.println(-1);
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }

    static void ret(long ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

//class P {
//	int x,y; double d;
//	P(int  x, int y, double d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}


class P implements Comparable<P>{
    int p,h,f; long m;
    P(int p,int h, int f, long m) {
    	this.p=p;
    	this.h=h;
    	this.f=f;
    	this.m=m;
    }

    public int compareTo(P p){
    	if(this.p==p.p) {
    		if(this.f==-1) return 1;
    		return -1;
    	}
        return this.p-p.p;
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString()
    {
        while( st==null || !st.hasMoreTokens() )
			try {
				st = new StringTokenizer(x.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) {
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) {
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() {
        return this.nextString().toCharArray();
    }    
    public long nextLong()
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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

using namespace std;

const int N = 123456;

int n, m;
int color[N];
vector<int> g[N];

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  long long isolated = 0;
  long long bipart = 0;
  long long other = 0;
  fill_n(color, n, -1);
  for (int i = 0; i < n; i++) {
    if (color[i] != -1) {
      continue;
    }
    vector<int> que;
    que.push_back(i);
    color[i] = 0;
    bool bad = false;
    for (int i = 0; i < (int)que.size(); i++) {
      int v = que[i];
      for (int j = 0; j < (int)g[v].size(); j++) {
        int u = g[v][j];
        if (color[u] >= 0) {
          bad |= (color[v] == color[u]);
        } else {
          que.push_back(u);
          color[u] = 1 - color[v];
        }
      }
    }
    if ((int)que.size() == 1) {
      assert(!bad);
      isolated++;
    } else if (bad) {
      other++;
    } else {
      bipart++;
    }
  }
  long long ans = isolated * (2 * n - isolated) + 2 * bipart * bipart + 
    2 * bipart * other + other * other;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 8316
#include <cstdio>
#define MAX 26
#define NIL -1
 
struct Node { int parent, left, right; };
 
Node T[MAX];
int n, D[MAX], H[MAX];
 
void setDepth(int u, int d) {
  if ( u == NIL ) return;
  D[u] = d;
  setDepth(T[u].left, d + 1);
  setDepth(T[u].right, d + 1);
}
 
int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if ( T[u].left != NIL ) h1 = setHeight(T[u].left) + 1;
  if ( T[u].right != NIL ) h2 = setHeight(T[u].right) + 1;
  return H[u] = ( h1 > h2 ) ? h1 : h2;
}
 
int getSibling(int u) {
  int v = T[u].parent;
  if ( v == NIL ) return NIL;
  if ( T[v].left != u && T[v].left != NIL ) return T[v].left;
  if ( T[v].right != u && T[v].right != NIL ) return T[v].right;
  return NIL;
}
 
void print(int u) {
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if ( T[u].left != NIL ) deg++;
  if ( T[u].right != NIL ) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);
  if ( T[u].parent == NIL ) printf("root\n");
  else if ( deg > 0 ) printf("internal node\n");
  else printf("leaf\n");
}
 
int main() {
  int root, n, v, l, r;
  root = 0;
scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) T[i].parent = NIL;
 
  for ( int i = 0; i < n; i++ ) {
    scanf("%d %d %d", &v, &l, &r);
    T[v].left = l;
    T[v].right = r;
    if ( l != NIL ) T[l].parent = v;
    if ( r != NIL ) T[r].parent = v;
  }
 
  for ( int i = 0; i < n; i++ ) if ( T[i].parent == NIL ) root = i;
 
  setDepth(root, 0);
  setHeight(root);
 
  for ( int i = 0; i < n; i++ ) print(i);
 
  return 0;
}


Measured memory_bytes: 2752
#include<iostream>
#include<algorithm>
#include<queue>
#include<functional>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define int long long
#define inf 1145141919810931
typedef pair<int, int> P;
struct edge { int to, cost; };
vector<edge>G[114514];
int d[114514];

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>Q;
	fill(d, d + 114014, inf);
	d[s] = 0;
	Q.push(P(0, s));
	while (Q.size()) {
		P p = Q.top();
		Q.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				Q.push(P(d[e.to], e.to));
			}
		}
	}
}
signed main() {
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		G[a - 1].push_back({ b - 1,c });
		G[b - 1].push_back({ a - 1,c });
	}
	int q, k;
	cin >> q >> k;
	dijkstra(k - 1);
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		cout << d[x - 1] + d[y - 1] << endl;
	}
}

Measured memory_bytes: 11632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e7;
const ll MOD = 1e9 + 7;
const int MAX = 101;

int n; // 行列の数
int m[MAX][MAX]; // m[i][j] := 行列iと行列jの最小の演算数
int p[MAX]; // p[i] := 行列iの行数(縦の長さ)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i - 1] >> p[i];
    }

    for (int i = 1; i <= n; ++i) {
        m[i][i] = 0;
    }
    for (int l = 2; l <= n; ++l) { // 行列のlengthは2~n
        for (int i = 1; i <= n-l+1; ++i) { // iからn-l+1まで
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for (int k = i; k < j; ++k) { // m[i][j]を求める
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }

    cout << m[1][n] << endl;

    return 0;
}


Measured memory_bytes: 3256
def black(now):
    nextb=[]
    while now:
        a=now.pop()
        while desn[a]:
            go=desn[a].pop()
            if nodes[go]=='N':
                nodes[go]='B'
                nextb.append(go)
    return nextb

def white(now):
    nextb=[]
    while now:
        a=now.pop()
        while desn[a]:
            go=desn[a].pop()
            if nodes[go]=='N':
                nodes[go]='W'
                nextb.append(go)
    return nextb

n = int(input())
nodes=[]
desn=[]
for i in range(0,n+1):
    nodes.append("N")
    desn.append([])
nodes[1]='B'
nodes[n]='W'
for i in range(0,n-1):
    b, c = (int(i) for i in input().split())
    desn[b].append(c)
    desn[c].append(b)

nowb=[1]
noww=[n]
while nowb or noww:
    nowb=black(nowb)
    noww=white(noww)

b=nodes.count('B')
w=nodes.count('W')
if b>w:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 21996
<?php 
$count = trim(fgets(STDIN));

for ($i = 0; $i < $count; $i++) {
    $out = 0;
    $run = 0;
    $score = 0;
     while(1) {
        $r = trim(fgets(STDIN));
        switch($r) {
            case 'OUT' :
                $out ++;
                break;
            case 'HIT' :
                $run ++;
                break;
            case 'HOMERUN' :
                $score += $run + 1;
                $run = 0;
                break;
        }
        if($out == 3) {
            break;
        }else if ($run == 4) {
            $score += 1;
            $run -=1;
        }
        
     }
     echo $score . PHP_EOL;
}


Measured memory_bytes: 9220
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
a = int(input())
ar = make_divisors(a)
br = []
for r in ar:
    br.append((r - 1) +  ((a // r) - 1))
print(min(br))

Measured memory_bytes: 3552
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = str(input())

L = [[] for _ in range(K)]
for i in range(N):
  temp = T[i]
  MOD = i%K
  L[MOD].append(temp)
ans = 0
for i in range(len(L)):
  for j in range(len(L[i])):
    if j == 0:
      Flag = True #なんでも出せる
    elif not Flag: #前回が制限された
      Flag = True
    elif Flag and L[i][j] == L[i][j-1]:
      Flag = False
    if L[i][j] == "r" and Flag: 
      ans += P
    elif L[i][j] == "s" and Flag: 
      ans += R
    elif L[i][j] == "p" and Flag: 
        ans += S
print(ans)
      

Measured memory_bytes: 55804
#define ll long long
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long double a,b,x;
    cin>>a>>b>>x;
    long double h = b-(x/(a*a));
    //cout<<h<<endl;
    long double v= a*a*b;
    if(h==0||b==0)
    {
        cout<<0<<endl;
        return 0;
    }
    if(x<v/2)
    {
        long double base = b/(a*b);

        cout<<setprecision(9)<<fixed<<atan(b/(2*x/(b*a)))*180/acos(-1)<<endl;
    }
    else
    {
        cout<<setprecision(9)<<fixed<<atan(2*h/a)*180/acos(-1)<<endl;
    }



}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#include <math.h>
#include <iomanip>
using namespace std;
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
   	
   	int n,a,b,aa,bb;
    cin>>n>>a>>b;
    
    if(b==a+1){cout<<"Borys"<<endl;return 0;}
    if((b-a)%2==1){cout<<"Borys"<<endl;return 0;}
    if((b-a)%2==0){cout<<"Alice"<<endl;return 0;}
            return 0;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
  string s;
  cin>>s;
  sort(s.begin(),s.end());
  bool baket[26]={false};
  for(int i=0;i<s.size();i++){
    baket[s[i]-'a']=true;
  }
  for(int i=0;i<26;i++){
    if(baket[i]==false){
      cout<<char(i+'a')<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
  return 0;
}


Measured memory_bytes: 512
/*
 * @Author: Kaizyn
 * @Date: 2020-04-19 19:55:17
 * @LastEditTime: 2020-04-28 16:21:15
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const int N = 2e5+7;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;

int n;
int c[N], num[N], col[N];
long long res[N];
vector<int> e[N];

inline long long calc(const int &x) {
    return x*(x+1ll)/2;
}

void dfs(const int &u, const int &fa) {
    num[u] = 1;
    int tmp = col[c[u]];
    for (int &v : e[u]) if (v != fa) {
        col[c[u]] = 0;
        dfs(v, u);
        num[u] += num[v];
        res[c[u]] -= calc(num[v]-col[c[u]]);
    }
    col[c[u]] = tmp+num[u];
    #ifdef DEBUG
    cout << u << ": ";
    for (int i = 1; i <= n; ++i) cout << res[i] << " \n"[i==n];
    cout << "   ";
    for (int i = 1; i <= n; ++i) cout << col[i] << " \n"[i==n];
    #endif
}

inline void solve()
{
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> c[i];
    for (int i = 1, u, v; i < n; ++i) {
        cin >> u >> v;
        e[u].emplace_back(v);
        e[v].emplace_back(u);
    }
    for (int i = 1; i <= n; ++i) {
        res[i] = calc(n);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; ++i) {
        res[i] -= calc(n-col[i]);
    }
    for (int i = 1; i <= n; ++i) {
        cout << res[i] << endl;
    }
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int testcase = 1;
    // cin >> testcase;
    for (int i = 1; i <= testcase; ++i) {
        solve();
    }
    return 0;
}

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 2000000000;
constexpr auto MOD = 1000000007;

int main() {


	string s,t;
	cin >> s >> t;
	int ans = 0;
	rep(i, 3)if (s[i] == t[i])ans++;

	cout << ans << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
ll r,c;

vector<string> arr;
vector<VL> visit2;
void dfs(ll i,ll j)
{
    if(i+1<r)
    {
        if(visit2[i][j]+1<visit2[i+1][j]&&arr[i+1][j]=='.')
        {
            visit2[i+1][j]=visit2[i][j]+1;
            dfs(i+1,j);
        }
    }
    if(i-1>=0)
    {
        if(visit2[i][j]+1<visit2[i-1][j]&&arr[i-1][j]=='.')
        {
            visit2[i-1][j]=visit2[i][j]+1;
            dfs(i-1,j);
        }
    }
    if(j+1<c)
    {
        if(visit2[i][j]+1<visit2[i][j+1]&&arr[i][j+1]=='.')
        {
            visit2[i][j+1]=visit2[i][j]+1;
            dfs(i,j+1);
        }
    }
    if(j-1>=0)
    {
        if(visit2[i][j]+1<visit2[i][j-1]&&arr[i][j-1]=='.')
        {
            visit2[i][j-1]=visit2[i][j]+1;
            dfs(i,j-1);
        }
    }
    return;
}
void solve()
{
    cin>>r>>c;
    arr.assign(r,"");
    fr(i,0,r)
    {
        cin>>arr[i];
    }
    ll ct=0;
    fr(i,0,r)
    {
        fr(j,0,c)
        {
            if(arr[i][j]=='.')
            {
                ct++;
            }
        }
    }
    visit2.assign(r,VL(c,inf));
    visit2[0][0]=1;
    if(arr[0][0]=='#'||arr[r-1][c-1]=='#')
    {
        cout<<"-1\n";
        return;
    }
    dfs(0,0);
    if(visit2[r-1][c-1]==inf)
    {
        cout<<"-1\n";
    }
    else
    {
        cout<<ct-visit2[r-1][c-1]<<endl;
    }
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm


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

int main(){
    int n, m;
    long int x[1001] = {}, y[1001] = {}, z[1001] = {}, score[8][1001] = {};

    cin >> n >> m;
    
    // 各ケーキのスコア
    // 足し方を変えて正負いずれの最大化を行うべきかを調べる
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i] >> z[i];
        score[0][i] +=  x[i] + y[i] + z[i];
        score[1][i] +=  x[i] + y[i] - z[i];
        score[2][i] +=  x[i] - y[i] + z[i];
        score[3][i] +=  x[i] - y[i] - z[i];
        score[4][i] += -x[i] + y[i] + z[i];
        score[5][i] += -x[i] + y[i] - z[i];
        score[6][i] += -x[i] - y[i] + z[i];
        score[7][i] += -x[i] - y[i] - z[i];
    }
    
    long int sum[9] = {};

    for(int i=0; i<8; i++){
        sort(score[i], score[i] + n);
        reverse(score[i], score[i] + n);
    }

    // 8通りの総合スコアの求め方の最大値を求める
    for(int i=0; i<m; i++){
        sum[0] += score[0][i];
        sum[1] += score[1][i];
        sum[2] += score[2][i];
        sum[3] += score[3][i];
        sum[4] += score[4][i];
        sum[5] += score[5][i];
        sum[6] += score[6][i];
        sum[7] += score[7][i];
    }

    long int maximum = -10000000000000;
    int maxindex = -1;
    for(int i=0; i<8; i++){
        maximum = max(sum[i], maximum);
        if(maximum == sum[i]){
            maxindex = i;
        }
    }

    sort(score[maxindex], score[maxindex] + n);
    reverse(score[maxindex], score[maxindex] + n);

    long int result = 0;
    for(int i=0; i<m; i++){
        result += score[maxindex][i];
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 384
N, M = map(int, input().split())
A = list(map(lambda x:(-1)*int(x), input().split()))
import heapq  # heapqライブラリのimport

heapq.heapify(A)  # リストを優先度付きキューへ

# 最小値の取り出し

for i in range(M):
  heapq.heappush(A, ((-1)*heapq.heappop(A))//2*(-1))

print(sum(A)*(-1))

Measured memory_bytes: 14224