akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int a, b, sum;
    cin >> a >> b;
    if(b>=100) sum = a*1000 + b;
    else if(b>=10) sum = a*100 + b;
    else sum = a*10 + b;
    for(int i = 1; i*i <= sum; i++){
        if(i*i == sum){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <sstream>

using namespace std;

const int N_MAX = 1000000;

void print_vector(vector<int> arr){
    for(int i=0; i<arr.size(); i++){
        cout << arr[i];
	if(i!=arr.size()-1) cout << " ";
    }
    cout << endl;
}

void solve(vector<int> arr){
    int key;
    for(int i=0; i<arr.size(); i++){
        key = arr[i];
        int j = i - 1;
        while(j>=0 && arr[j] > key){
            arr[j+1] = arr[j];
            j--;
        }
        arr[j+1] = key;
        print_vector(arr);
    }
}

int main(){
    int N;
    vector<int> arr;    

    cin >> N;
    int x;
    for(int i=0; i<N; i++){
      cin >> x;
      arr.push_back(x);
    }
    solve(arr);
    return 0;
}  



Measured memory_bytes: 3160
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, d = inintm()

X = []
ans = 0

for _ in range(n):
    x = inintl()
    X.append(x)


for i in range(n):
    Xi = X[i]
    for j in range(i+1, n):
        Xj = X[j]
        z = 0
        for k in range(d):
            z += (Xi[k] - Xj[k])**2
        if z**0.5 == int(z**0.5):
            ans += 1

print(ans)


Measured memory_bytes: 62724
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

class SegmentTree:
    def __init__(self,N,d):
        self.NN = 1
        while self.NN < N:
            self.NN *= 2
        self.SegTree = [d]*(self.NN*2-1)

    def update(self,i,x): #iの値をxに更新
        i += self.NN - 1
        self.SegTree[i] = x
        while i>0:
            i = (i-1)//2
            self.SegTree[i] = self.process(self.SegTree[i*2+1],self.SegTree[i*2+2])

    def query(self,a,b,k=0,l=0,r=None): #[A,B)の値, 呼ぶときはquery(a,b)
        if r == None: r = self.NN
        if r <= a or b <= l: #完全に含まない
            return INF
        elif a <= l and r <= b : #完全に含む
            return self.SegTree[k]
        else: #交差する
            vl = self.query(a,b,k*2+1,l,(l+r)//2)
            vr = self.query(a,b,k*2+2,(l+r)//2,r)
            return(self.process(vl,vr))

    def process(self,x,y): #x,yが子の時，親に返る値
        return min(x,y)


N,Q = inpl()
ST = SegmentTree(N,2**31-1)

for _ in range(Q):
    c,x,y = inpl()
    if c == 0:
        ST.update(x,y)
    else:
        print(ST.query(x,y+1))



Measured memory_bytes: 10448
package main
 
import (
  "fmt"
  "math"
)

const inf = math.MaxInt32

func min(nums ...int) int {
    if len(nums) == 0 {
        panic("funciton min() requires at least one argument.")
    }
    res := nums[0]
    for i := 0; i < len(nums); i++ {
        res = int(math.Min(float64(res), float64(nums[i])))
    }
    return res
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
  
  var n,a,b,c int
  fmt.Scan(&n,&a,&b,&c)
  
  len := make([]int,n)
  for i := range len {
    fmt.Scan(&len[i])
  }
  
  var ans int
  ans = inf
  
  //2ビットで1本の竹の使い方を表す
  //00:使わない 01:Aの素材 10:Bの素材 11:Cの素材
  for m := 1; m <= int(math.Pow(4,float64(n))); m++ {
    tmp_a := 0
    tmp_b := 0 
    tmp_c := 0
    mp := 0
    //2ビットの集まりがn個存在する
    for j := 0; j < n; j++{
      //2ビットずつ右にシフトさせて竹の使い方を判定する
      p := (m>>(uint(2*j))) & 3
      
      if p == 1 {
        //既にAの素材を選んでいる場合は合成する
        if tmp_a > 0 {
          mp += 10
        }
        tmp_a += len[j]
      }
      if p == 2 {
        //既にBの素材を選んでいる場合は合成する
        if tmp_b > 0 {
          mp += 10
        }
        tmp_b += len[j]
      }
      if p == 3 {
        //既にCの素材を選んでいる場合は合成する
        if tmp_c > 0 {
          mp += 10
        }
        tmp_c += len[j]
      }
    }
    //A,B,Cいずれかの素材がない場合は対象外
    if tmp_a==0||tmp_b==0||tmp_c==0{
      continue
    }
    //延長、短縮コストを加算
    mp += abs(a-tmp_a) + abs(b-tmp_b) + abs(c-tmp_c)
    ans = min(ans,mp)
  }
  fmt.Println(ans)
}


Measured memory_bytes: 512
n=input().rstrip()
n=int(n)
a=input().split()
k=0
li=[]
while k<n:
    b=int(a[k])
    li.append(b)
    k+=1
c=tuple(sorted(li,reverse=True))
h=0
sb=0
while 2*h+1<=n-1:
    sb+=c[2*h+1]
    h+=1
h=0
sa=0
while 2*h<=n-1:
    sa+=c[2*h]
    h+=1
d=sa-sb
print(d)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
const int INF = 100000;
ll a[100005];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    ll n,k,l;
    cin>>n>>k>>l;
    for(ll i=1;i<=l;i++){
       ll x;
       cin>>x;
       a[x]++;
    }
    for(ll i=1;i<=n;i++){
        if(k>(l-a[i])){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
}


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

using namespace std;

long long int f(long long n) {
    long long res = 0;
    while (n > 0) {
        res += n % 10;
        n /= 10;
    }
    return res;
}

double g(long long n) {
    return (double) (n) / f(n);
}

int main() {
    vector<long long> res;
    long long base = 1;

    for (int i = 0; i < 15; ++i) {
        for (int j = 1; j < 150; ++j) {
            res.push_back(base * (j + 1) - 1);
        }
        base *= 10;
    }
    sort(res.begin(), res.end());
    res.erase(unique(res.begin(), res.end()), res.end());

    for (long long i = 0; i < res.size(); ++i) {
        for (long long j = i + 1; j < res.size(); ++j) {
            if (g(res[i]) > g(res[j])) {
                res.erase(res.begin() + i--);
                break;
            }
        }
    }

    long long K;
    cin >> K;
    for (long long i = 0; i < K; ++i) {
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 888
#include <cstdio>
#include <iostream> 
#include <ctime>
#include <cmath>
#include <cstring>
#include <cstdlib>                                          
#include <queue>                              
#include <vector>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#define e 2.718281828459045     
#define pi 3.141592653589793239 
#define reg register
using namespace std;
typedef long long ll;            // >10^18
typedef long double ld;          // 3.3621e-4932 ~ 1.18937e4932
typedef unsigned long long ull;  // >10^20
const int INF = 0x3f3f3f3f;      
const int INFS = 0xc0c0c0c0;     
const double eps = 1e-8;         // 1e-8 || 1e-10
//const double pi = acos(-1.0);
inline int read(){
    int sgn = 1, cnt = 0;        // sgn表示正负号 cnt表示读取的数字
    char ch = getchar();
    while(ch < '0' || ch > '9'){ // 读取非数字的字符，保留负号，忽略其余无关符号
        if(ch == '-') sgn = -sgn;
        ch = getchar();
    }
    while('0' <= ch && ch <= '9'){
        cnt = cnt * 10 + (ch - '0');
        ch = getchar();
    }
    return sgn * cnt;
}
int main(int argc, char *argv[]){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);  //使用后无法用scanf, printf
	int n; cin >> n;
	while(n--) printf("ACL");
	return 0;
}

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

int kai(int n){
	int a = 1;
	for( int i=1; i<=n; i++) a *= i;
	return a;
}

vector<int> pp(10 , 100);
vector<int> qq(10 , 100);

int jyuni_pp(int n, int m) {
	int i;
	sort(pp.begin(),pp.end());
	for(i=0; i<8; i++) {
		if (pp[i] == m) {
			pp[i] = 100;
			break;
		}
	}
	//printf("%d %d %d %d %d\n",pp[0],pp[1],pp[2],pp[3]);
	//cout << "i:" << i << endl;
	return i;
}

int jyuni_qq(int n, int m) {
	int i;
	sort(qq.begin(),qq.end());
	for(i=0; i<8; i++) {
		if (qq[i] == m) {
			qq[i] = 100;
			break;
		}
	}

	return i;
}


int main() {
	int		a,b,c,i,j,k,n,m,x,y,ans = 0;
	string	str;
	
	cin >> n;
	
	vector<int>	p(10,100);
	vector<int> q(10,100);

	for(i=0;i<n;i++) cin >> p[i];
	for(i=0;i<n;i++) cin >> q[i];
	
	for(i=0;i<n;i++) {
		pp[i] = p[i];
		qq[i] = q[i];
	}
	
	
	x = y = 0;
	for(i=0;i<n;i++) {
		x += jyuni_pp(n, p[i]) * kai(n-i-1);
		y += jyuni_qq(n, q[i]) * kai(n-i-1);
		//printf("x: %d\n",x);
		//printf("y: %d\n",y);
	}
	if (x > y) {
		ans = x - y;
	} else {
		ans = y - x;
	}

	cout << ans << endl;
	
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int w, h;
char tile[21][21];

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

int dfs(int x, int y){
	if(x<0 || w<=x || y<0 || h<=y) return 0;
	if(tile[y][x] == '#') return 0;

	tile[y][x] = '#';
	int count = 1;
	for(int i=0; i<4; i++){
		count += dfs(x+dx[i], y+dy[i]);
	}
	return count;
}


int main(void){
	while(1){
		cin >> w >> h;
		if(!w && !h) break;

		int x=0, y=0; //pos
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				cin >> tile[i][j];
				if(tile[i][j] == '@'){
					x = j;
					y = i;
				}
			}
		}
		cout << dfs(x, y) << endl;
	}
	return 0;
}


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

using namespace std;
int main(){
	long long int n,m;
	cin >> n >> m;
	if(n==1&&m==1){
		cout << 1 << endl;
	}else if(n==1){
		cout << m-2 << endl;
	}else if(m==1){
		cout << n-2 << endl;
	}else {
		cout << (n-2)*(m-2) << endl;
	}
}

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

using namespace std;

void solve(void)
{
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> xs(n);
	for (int i = 0; i < n; i++)
	{
		cin >> xs[i].first >> xs[i].second;
	}
	sort(xs.rbegin(), xs.rend());
	priority_queue<int, vector<int>, greater<int>> pq;
	int s = 0;
	for (auto &p : xs)
	{
		int a = p.first, b = p.second;
		if (a > m) continue;
		if (a + s > m)
		{
			if (s == 0 || pq.top() < b)
			{
				if (s) pq.pop();
				else s++;
				pq.push(b);
			}
		}
		else
		{
			pq.push(b);
			s++;
		}
	}
	int ans = 0;
	while(!pq.empty())
	{
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1660
N = int(input())
ary = []
s = 'Yes'
for i in range(N):
  w = input()
  if w in ary:
    s = 'No'
    break
  if len(ary) > 0 and w[0] != ary[-1][-1]:
    s = 'No'
    break
  ary.append(w)
    
print(s)

Measured memory_bytes: 3064
s,_,*q=open(0)
a='S'
p=1
for q in q:
  try:
    q,f,c=q.split()
    if(f<'2')^p:a+=c
    else:a=c+a
  except:p^=1
print(a.replace('S',s[:-1])[::p or-1])

Measured memory_bytes: 16488
using System;
using System.Linq;

namespace ProblemB
{
    class Program
    {
        static void Main()
        {
            long N = long.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

            long ans = 1;
            if(A.Contains(0))
            {
                Console.WriteLine(0);
                return;
            }

            for(int i = 0; i < N; i++)
            {
                if (Math.Log10(ans) + Math.Log10(A[i]) > 18 || ans * A[i] > (long)Math.Pow(10,18))
                {
                    Console.WriteLine(-1);
                    return;
                }
                else
                {
                    ans *= A[i];
                }
            }
            if (ans > (long)Math.Pow(10, 18))
            {
                Console.WriteLine(-1);
                return;
            }
            else
            {
                Console.WriteLine(ans);
            }
        }
    }
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")


ll fact[110000];
ll invfact[110000];
ll inv(ll a) {

	ll res = 1;
	int p = MOD - 2;
	while (p > 0) {
		if ((p & 1) == 1) { res *= a; res %= MOD; }
		a = a * a % MOD;
		p >>= 1;
	}
	return res;
}

ll combo(int n, int k) {
	ll res = fact[n];
	res *= invfact[k];
	res %= MOD;
	res *= invfact[n - k];
	return res % MOD;
}

void factpre(int N) {
	fact[0] = 1;
	fx(N) {
		fact[x + 1] = fact[x] * (x + 1);
		fact[x + 1] %= MOD;
	}
	invfact[N] = inv(fact[N]);
	for (int x = N - 1; x >= 0; x--) {
		invfact[x] = invfact[x + 1] * (x + 1);
		invfact[x] %= MOD;
	}
}


int main()
{
	
	int S;
	cin >> S;
	factpre(S*2);
	if (S<3) {
		ce(0);
		return 0;
	}

	ll ans = 0;
	for (int i = 1; i <= S / 3;i++) {
		ans += combo(i + S - 3 * i - 1, S - 3 * i);
		ans %= MOD;
	}
	ce(ans)
    return 0;
}



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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;






int main() {

	

	int n, t;
	cin >> n >> t;

	vector<pair<int, int>> v;
	
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		v.push_back({ a,b });
	}
	sort(ALL(v));

	int dp[3005];

	REP(i, 3005)dp[i] = 0;

	int ans = 0;


	REP(i, n) {
		int a = v[i].first;
		int b = v[i].second;
		for (int j = t-1; j >= a; j--) {
			dp[j] = max(dp[j], dp[j - a] + b);
		}
		int cur = dp[t-1];
		int ma = 0;
		FOR(j, i + 1, n) {
			ma = max(ma, v[j].second);
		}
		ans = max(ans, cur + ma);
	}
	cout << ans << endl;


}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long ret = a *c;
    if (ret < a * d) ret = a*d;
    if (ret < b * c) ret = b * c;
    if (ret < a * c) ret = a * c;
    if (ret < b * d) ret = b * d;
    cout << (ret) << endl;

    return 0;
}


Measured memory_bytes: 3644
N,T=map(int,input().split())
t=list(map(int,input().split()))
total=0
for i in range(1,N+1):
    if i==N:
        total+=T
    elif t[i]<=(t[i-1]+T):
        total+=t[i]-t[i-1]
    else:
        total+=T
print(total)

Measured memory_bytes: 25196
#include<iostream>
using namespace std;
int main(){
int a[3],f=0,s=0;
cin>>a[0]>>a[1]>>a[2];
for(int i=0;i<3;i++){
if(a[i]==5)f++;
if(a[i]==7)s++;
}
if(f==2 && s==1)cout<<"YES"<<endl;else cout<<"NO"<<endl;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
bool prime[1000000];

bool isprime(ll n){
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i == 0){
            return false;
        }
    }
    return true;
}
int main(){
    ll q;
    cin >> q;
    prime[0] = 0;
    prime[1] = 0;
    for(int i=2;i<=100000;i++){
        if(isprime(i)){
            prime[i] = true;
        }
        else{
            prime[i] = false;
        }
    }
    ll sum[1000000];
    sum[0] = 0;
    sum[1] = 0;
    for(int i=2;i<=100000;i++){
        if(i%2 == 0){
            sum[i] = sum[i-1];
        }
        else{
            if(prime[i] && prime[(i+1)/2]){
                sum[i] = sum[i-1] + 1;
            }
            else{
                sum[i] = sum[i-1];
            }
        }
    }
    #if TEST
        for(int i=0;i<10;i++){
            if(prime[i]){
                cout << i << endl;
            }
            else{}
        }
    #endif
    for(int i=0;i<q;i++){
        ll l; ll r;
        cin >> l >> r;
        cout << sum[r]- sum[l] + (sum[l] - sum[l-1]) << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include<iostream>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<iomanip>

using namespace std;

int main() {
	double n, k;
	cin >> n >> k;
	double count;
	int temp;
	double ans = 0;
	for (int i = 0; i < n; i++) {
		temp = i + 1;
		count = 0;
		while (temp < k)
		{
			temp = temp * 2;
			count++;
		}
		ans += (1 / n) * pow(0.5, count);
	}
	cout << setprecision(12) << ans;

	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B, C;
    ll K;
    cin >> A >> B >> C;
    cin >> K;
    rep(i, K) {
        if(A >= B) B *= 2;
        else if(B >= C) C *= 2;
    }
    if(A < B && B < C) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  vector<string> v;
  rep(i,n){
    string t="";
    t+=s[i];
    rep(j,5){
      v.push_back(t);
      if(i+j+1<n){ t+=s[i+j+1]; }
    }
  }
  
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  
  cout << v[k-1] << endl;
  return 0;
}


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

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	string f[52];
	cin >> H >> W;
	f[0] = string(W+2, '#');
	f[H+1] = string(W+2, '#');
	int cnt = 0;
	REP(i, H){
		cin >> f[i+1];
		f[i+1] = '#'+f[i+1]+'#';
		REP(j, W+2)
			if(f[i+1][j] == '.') cnt++;
	}
	H+=2; W+=2;	
	int dx[4] = {-1, 1, 0, 0};
	int dy[4] = {0, 0, -1, 1};
	int d[52][52];
	REP(i, 52)
		fill(d[i], d[i]+52, INF);
	using PIII = tuple<int, int, int>;
	queue<PIII> que;
	d[1][1] = 1;
	que.push(PIII(1, 1, 1));
	while(que.size()){
		int a, y, x;
		tie(a, y, x) = que.front(); que.pop();
		if(a > d[y][x]) continue;
		REP(i, 4){
			int yy = y+dy[i], xx = x+dx[i];
			if(f[yy][xx] != '#' && d[yy][xx] > d[y][x]+1){
				d[yy][xx] = d[y][x]+1;
				que.push(PIII(d[yy][xx], yy, xx));
			}
		}
	}
	if(d[H-2][W-2] != INF)
		cout << cnt-d[H-2][W-2] << endl;
	else
		cout << -1 << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  int N;
  std::string S;
  
  std::cin >> N >> S;
  
  int ans = 1;
  
  for (int i=0; i<N; ++i) {
    if (i != 0 && S[i] != S[i-1])
      ++ans;
  }
  std::cout << ans << std::endl;
}

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

struct dat{
  bool delay; // ?????¶????????????1
  int dvalue; // ?????¶?????????
  int min_value; // ???????????????????°????
  dat(){};
  dat(bool a,int b,int c){
    delay=a,dvalue=b,min_value=c;
  };
};

const int MAX_N=(1<<17);

dat d[2*MAX_N];

void init(){
  for(int i=0;i<2*MAX_N;i++) d[i]=dat(0,0,INT_MAX);
}

void Delay(int k,int l,int r){
  if(r-l==1||d[k].delay==0)return ;
  d[k].delay=0;
  d[k*2+1]=d[k*2+2]=dat(1,d[k].dvalue,d[k].dvalue);
}

void Range_Update(int a,int b,int x,int k=0,int l=0,int r=MAX_N){
  Delay(k,l,r);
  if(r<=a||b<=l)return ;
  if(a<=l&&r<=b){
    d[k].delay=true;
    d[k].dvalue=x;
    d[k].min_value=x;
    return ;
  }
  Range_Update(a,b,x,k*2+1,(l+r)/2,r);
  Range_Update(a,b,x,k*2+2,l,(l+r)/2);
  d[k].min_value=min(d[k*2+1].min_value,d[k*2+2].min_value);
}

int Range_Minimum(int a,int b,int k=0,int l=0,int r=MAX_N){
  Delay(k,l,r);
  if(r<=a||b<=l)return INT_MAX;
  if(a<=l&&r<=b)return d[k].min_value;
  int res=INT_MAX;
  res=min(res,Range_Minimum(a,b,k*2+1,(l+r)/2,r));
  res=min(res,Range_Minimum(a,b,k*2+2,l,(l+r)/2));
  return res;
}

int main(){
  
  init();

  int n,q;

  cin>>n>>q;

  int a,l,r,x;
  for(int i=0;i<q;i++){
    cin>>a>>l>>r;
    
    if(!a){
      
      cin>>x;
      Range_Update(l,r+1,x);
      
    }else cout<<Range_Minimum(l,r+1)<<endl;

  }
  
  return 0;
}

Measured memory_bytes: 6148
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""

#B
def dijkstra(k):
    d[k] = 0
    q = [[0,k]]
    while q:
        dx,x = heappop(q)
        for y,c in v[x]:
            if d[y] > dx+c:
                d[y] = dx+c
                heappush(q,[d[y],y])

n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a].append([b,c])
    v[b].append([a,c])
q,k = LI()
d = [float("inf") for i in range(n)]
dijkstra(k-1)
for i in range(q):
    x,y = LI()
    x -= 1
    y -= 1
    print(d[x]+d[y])
#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 102960
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	std::string s;
	in >> s;

	bool possible = true;
	rep(i, s.length() - 1)
	{
		if (s[i] != s[s.length() - i - 2])
		{
			possible = false;
			break;
		}
	}
	possible &= (s[s.length() - 1] == '0');
	possible &= (s[0] == '1');
	if (!possible)
	{
		out << -1 << std::endl;
		return 0;
	}

	std::vector<LL>base;
	std::vector<std::pair<LL, LL>>ans;
	rep(i, s.length())
	{
		if (s[i] == '1') base.push_back(i + 1);
	}
	base.push_back(s.length());
	for (LL i = 1; i < base.size(); ++i)
	{
		for (LL j = base[i - 1]; j < base[i]; ++j) ans.push_back(std::make_pair(j, base[i]));
	}

	for (auto e : ans) out << e.first << " " << e.second << std::endl;
}


Measured memory_bytes: 4144
#include<iostream>
#include<string>
#include<map>
#include<vector>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
int main(){
	int n,m,sum=0;cin>>n;
	map<string,int>tmp;
	vector<int> ne(n),p,q;
	rep(i,n){
		string s;cin>>s>>ne[i];
		tmp[s]=i;
	}
	cin>>m;
	rep(i,m){
		string a,b;cin>>a>>b;
		p.push_back(tmp[a]);q.push_back(tmp[b]);
	}
	rep(i,m)rep(j,m)ne[p[j]]=ne[q[j]]=min(ne[p[j]],ne[q[j]]);
	rep(i,n)sum+=ne[i];
	cout<<sum<<endl;
}

Measured memory_bytes: 1836
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let v: Vec<T> = read_vec();
    (v[0], v[1])
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read_line().parse().ok().unwrap()).collect()
}

struct UnionFind {
    par: Vec<usize>,
    rank: Vec<usize>
}

impl UnionFind {
    fn new(size: usize) -> UnionFind {
        UnionFind {
            par: (0..size).collect(),
            rank: vec![0; size]
        }
    }

    fn find(&mut self, x: usize) -> usize {
        if self.par[x] == x {
            x
        } else {
            let p = self.par[x];
            let p = self.find(p);
            self.par[x] = p;
            self.par[x]
        }
    }

    fn unite(&mut self, x: usize, y: usize) {
        let x = self.find(x);
        let y = self.find(y);
        if x == y {
            return;
        }

        self.par[x] = y;
        // if self.rank[x] < self.rank[y] {
        //     self.par[x] = y;
        // } else {
        //     self.par[y] = x;
        //     if self.rank[x] == self.rank[y] {
        //         self.rank[x] += 1;
        //     }
        // }
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
}

fn main() {
    loop {
        let (N, Q) = read_tuple::<usize>();
        if N == 0 && Q == 0 {
            break;
        }
        let mut parent: Vec<usize> = read_col(N-1);
        parent.insert(0, 0);
        parent.insert(0, 1);
        let mut queries = Vec::<(char, usize)>::new();
        let mut marked = vec![1];
        for i in 0..Q {
            let vec: Vec<String> = read_vec();
            let o = vec[0].chars().next().unwrap();
            let v: usize = vec[1].parse().unwrap();
            if o == 'M' {
                if marked.contains(&v) {
                    continue;
                }
                marked.push(v);
            }
            queries.push((o, v));
        }

        let mut uf = UnionFind::new(N+1);
        for i in 1..N+1 {
            if !marked.contains(&i) {
                uf.unite(i, parent[i]);
            }
        }

        let mut ans = 0;
        queries.reverse();
        for (o, v) in queries {
            if o == 'M' {
                uf.unite(v, parent[v]);
            } else {
                ans += uf.find(v);
            }
        }

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



Measured memory_bytes: 11140
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll a[330][330];
tuple<ll,ll,ll> g[200000];
ll l[110000],r[110000];
ll z[200000];
int main(){
    ll h,w,d,ans=0;
    cin>>h>>w>>d;
    rep(i,0,h){
        rep(j,0,w){
            cin>>a[i][j];
            get<1>(g[a[i][j]])=i;
            get<2>(g[a[i][j]])=j;
        }
    }
    ll q;
    cin>>q;
    rep(i,0,q)cin>>l[i]>>r[i];

    rep(x,1,d+1){
        ll npx,npy;
        ll pos=x;
        npx=get<1>(g[pos]);
        npy=get<2>(g[pos]);
        while(pos<=h*w){
            pos+=d;
            z[pos]=z[pos-d]+labs(npx-get<1>(g[pos]))+labs(npy-get<2>(g[pos]));
            npx=get<1>(g[pos]);
            npy=get<2>(g[pos]);
        }
    }

    
    rep(x,0,q){
        cout<<z[r[x]]-z[l[x]]<<endl;
    }
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 1e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

vector<int> divisor(int n){
  vector<int> ret;
  for(int i = 0;i * i <= n;i++){
    ret.push_back(i);
    if(i*i != n) ret.push_back(i);
  }
  sort(ALL(ret));
  return ret;
}

signed main()
{
  ios();
	int N;
	int M;
	cin >> N >> M;
	int k[M];
	vi s[M];
	rep(i,M) {
		cin >> k[i];
		rep(j,k[i]) {
			int s1;
			cin >> s1;
			s1 --;
			s[i].push_back(s1);
		}
	}
	int p[M];
	rep(i,M) cin >> p[i];

	int cnt = 0;
	for(int bi = 0; bi < (1 << N);bi++) {
		bool f = true;
		rep(dj,M) {
			int c = count_if(ALL(s[dj]),[=](auto sv){return 1 & (bi >> sv) ;});
			if(c % 2 != p[dj] ) f = false;
		}
		if(f) cnt ++;
	}
	cout << cnt << endl;
}


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

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

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

  bool can = true;
  long long ans = 1;
  if(N % 2 != 0) {
    if(vec.at(0) != 1) can = false;
    for(int i = 2;i < N;i += 2) {
      if(vec.at(i) != 2) can = false;
      ans *= 2;
      ans %= 1000000007;
    }
  }else {
    for(int i = 1;i < N;i += 2) {
      if(vec.at(i) != 2) can = false;
      ans *= 2;
      ans %= 1000000007;
    }
  }

  if(can) {
    cout << ans << endl;
  }else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	int a,b,c;
	cin >> a >> b >> c;

	for(int i=1; i<=b; i++){
		if(a*i%b==c){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

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

using namespace std;

int main(void){
	int n,minus_counter=0;
	long res = 0;
	cin >> n;
	vector<int> a;
	for(int i=0;i<n;++i){
		int k;
		cin >> k;
		if(k < 0){
			minus_counter++;
		}
		a.push_back(abs(k));
	}
	sort(a.begin(),a.end());
	if(minus_counter%2)a[0] *= -1;
	for(int i=0;i<n;i++){
		res += a[i];
	}
	cout << res << endl;
}

Measured memory_bytes: 892
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a < b) {
        if (b < c) {
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
#define lli long long int
#define in int
#define el endl
#define oo cout
#define ii cin
#define pb push_back
#define bg begin()
#define en end()
#define p1 first
#define p2 second
#define FOR(i,a,b,c) for (int i = (a); i < (b); i=i+(c))
#define ROF(i,a,b,c) for (int i = (a); i > (b); i=i-(c))
using namespace std;

//vector< pair<lli,lli> >ccr;
//vector< pair<lli,lli> >jjr;
//vector<string>r;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,aa,bb,cc,i,j,ar[10000],br[10000],cr[10000];
ii>>n;
FOR(i,1,n+1,1){
ii>>cc;
ar[i]=cc;
}
FOR(i,1,n+1,1){
ii>>cc;
br[i]=cc;
}
FOR(i,1,n,1){
ii>>cc;
cr[i]=cc;
}
int ss=0;
aa=ar[1];
ss=br[aa];
FOR(i,2,n+1,1){
    aa=ar[i-1];
    bb=ar[i];

if((aa+1)==bb){
    //oo<<aa<<" "<<br[aa]<<" "<<cr[aa-1]<<el;

    ss=ss+br[bb]+cr[bb-1];
}
else{
    ss=ss+br[bb];
}


}
oo<<ss;


}

Measured memory_bytes: 3580
ABCD = list(map(int,input()))
op=[""]*3
def dfs(opN, ans):
    if opN == 3:
        return ans == 7
    op[opN] = "+"
    if (dfs(opN + 1, ans + ABCD[opN + 1])):
        return True
    op[opN] = "-"
    if (dfs(opN + 1, ans - ABCD[opN + 1])):
        return True
    return False
dfs(0,ABCD[0])
print(str(ABCD[0])+op[0]+str(ABCD[1])+op[1]+str(ABCD[2])+op[2]+str(ABCD[3])+"=7")

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,K;
char S[101010];
vector<ll> lrv;

ll i, j, k,ans;
int main(){
    scanf("%lld%lld%s",&N,&K,S);
    j = 0;
    ll l = 0,c=-1, r = 0;
    fornum(i,1,N+1){
        if(S[i-1]!=S[i]){
            lrv.push_back(j - i);
            ans += i-j - 1;
            j = i;
        }
    }
    ll a = lrv.size() - 1;
    ll b = K * 2;
    ans += min(a, b);

    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
    int n, i = 1;
    while (cin >> n, n)
    {
        cout << "Case " << i << ": " << n << endl;
        ++i;
    }
}



Measured memory_bytes: 3004
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
ll cnt[5];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  cin>>n;
  rep(i,1,n+1)
    {
      string s;
      cin>>s;
      if(s[0]=='M') cnt[0]++;
      else if(s[0]=='A') cnt[1]++;
      else if(s[0]=='R') cnt[2]++;
      else if(s[0]=='C') cnt[3]++;
      else if(s[0]=='H') cnt[4]++;
    }
  ll ans=0;
  rep(i,1,32)
    {
      int x=__builtin_popcount(i);
      if(x!=3) continue;
      ll prod=1;
      rep(j,0,5)
	if(i&(1<<j))
	  prod*=cnt[j];
      ans+=prod;
    }
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 256
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int N;
	cin >> N;
	
	vector< int > A(N);
	for (int i=0; i<N; ++i) cin >> A[i];
	
	vector< int > L(N);
	L[0] = A[0];
	for (int i=1; i<N; ++i) L[i] = __gcd(L[i-1], A[i]);
	
	vector< int > R(N);
	R[N-1] = A[N-1];
	for (int i=N-2; i>=0; --i) R[i] = __gcd(R[i+1], A[i]);
	
	int ans = R[0];
	for (int i=0; i<N; ++i) {
		if (i == 0) maxUpdate(ans, R[1]);
		else if (i == N-1) maxUpdate(ans, L[N-2]);
		else maxUpdate(ans, __gcd(L[i-1], R[i+1]));
	}
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  LL N;
  cin >> N;

  LL sum = 0;

  FOR(i,1,10000000){
    if((N-i)%i!=0){
      continue;
    }
    LL a = (N - i) / i;
    if(a>i){
      sum += a;
    }
  }

  cout << sum << endl;
}


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

#define MAX 3000

int dp[MAX + 1][MAX + 1];

string LCS(string& s, string& t, int len)
{
	string lca = "";
	int i = 0, j = 0;
	while (len)
	{
		if (s[i] == t[j])
		{
			lca.push_back(s[i]);
			i++;
			j++;
			len--;
		}
		else
		{
			if (dp[i][j + 1] > dp[i + 1][j])	//Which option is better??
				j++;
			else
				i++;
		}
	}
	return lca;
}


int lengthLCS(string& s, string& t, int i, int j)
{
	if (i >= s.length() || j >= t.length())
		return 0;

	if (dp[i][j] != -1)
		return dp[i][j];

	if (s[i] == t[j])
		return dp[i][j] = 1 + lengthLCS(s, t, i + 1, j + 1); //Include ith char
	else
	{
		return dp[i][j] = max(lengthLCS(s, t, i, j + 1), lengthLCS(s, t, i + 1, j));
	}
}



string solve(string s, string t)
{
	memset(dp, -1, sizeof dp);
	int len = lengthLCS(s, t, 0, 0);

	return LCS(s, t, len);
}


int main()
{
	string s, t;
	cin >> s >> t;

	cout << solve(s, t);
}

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

same = True
sum_a = 0
min_b = None

for _ in range(N):
    a, b = map(int, input().split())
    # Aの総和を求める
    sum_a += a
    # AとBが等しいどうかを調べる
    if a != b:
        same = False
    # Ai > Biの中で最小のbを求める
    if a > b and (min_b is None or b < min_b):
        min_b = b

# 初めから同じなら手数なし
if same:
    print(0)
    exit()

# Ai > Biの中で最小のbを求める
if min_b is None:
    min_b = 0

print(sum_a - min_b)


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

int main(){
  int N;
  cin>>N;
  if(N==0){
    cout<<0<<endl;
    return 0;
  }
  vector<int>D;
  while(N != 0){
      int m = N%(-2);
      //余りが-1のとき1を出力する
      if(m<0) m+=2;
      D.emplace_back(m);
      N = (N-m)/(-2);
  }
  
  for(int i=0;i<D.size();i++){
    cout<<D[D.size()-1-i];
  }
  cout<<endl;
  
  return 0;
}

  
      
          

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

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

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

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

signed main() {
  ll M; cin >> M;

  ll total = 0;
  ll N = 0;
  rep(i, M) {
    ll d, c;
    cin >> d >> c;
    N += c;
    total += d*c;
  }

  total --;
  ll ans = (N - 1) + total / 9;


  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int n,m,k; 

int dfs(int N,int sum){
	int res=0;
	if(N==0)return (sum>k?sum-k:1);
	else{
		for(int i=1;i<=m;i++){
			res+=dfs(N-1,sum+i);
		}
		return res;
	}
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(cin >> n >> m >> k,n){
		double d=pow(m,n);
		printf("%.9f\n",dfs(n,0)/d);
	}
}



Measured memory_bytes: 3340
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<tuple<string,int,int>> A(N);
  for(int i=0;i<N;i++){
    string s;
    int j;
    cin>>s>>j;
    A[i]=make_tuple(s,100-j,i+1);
  }
  sort(A.begin(),A.end());
  for(int i=0;i<N;i++){
    int j=(get<2>(A[i]));
    cout<<j<<endl;
  }
}

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

int main(){
    int ans = 0;
    int n, a, b; cin >> n >> a >> b;
    
    for(int i = 1; i <= n; i++){
        int tmp = 0, j = i;
        
        for(int j = i; j > 0; j /= 10){
            tmp += j % 10;
        }
        
        if(tmp >= a && tmp <= b){
            ans += i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
a = 10**N%(10**9+7)
b = (2*9**N)%(10**9+7)
c = 8**N%(10**9+7)

ans = (a-b+c)%(10**9+7)

# 出力
print("{}".format(ans))


Measured memory_bytes: 10676
#include<stdio.h>

#define N 100000

int partition(int *,int,int);

int main(){

    int i,m,n;
    int A[N];

    scanf("%d",&n);

    for(i=0;i<n;i++)
      scanf("%d",&A[i]);
    
    m=partition(A,0,n-1);

    for(i=0;i<m;i++)
      printf("%d ",A[i]);

    printf("[%d] ",A[m]);

    for(i=m+1;i<n-1;i++)
      printf("%d ",A[i]);

    printf("%d\n",A[n-1]);

    return 0;

}

int partition(int *A,int p,int r){

    int x,i,j;
    int tmp1,tmp2;

    x=A[r];

    i=p-1;

    for(j=p;j<r;j++){
        if(A[j]<=x){
            i++;
            tmp1=A[i];
            A[i]=A[j];
            A[j]=tmp1;
        }
    }

    tmp2=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp2;
    
    return i+1;

}

Measured memory_bytes: 988
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int a[100005];
int n,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	a[n+1]=0;
	ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==i && a[i+1]==i+1) ans++,i++;
		else if( a[i]==i) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
N = int(input())
s = [0]*N
d = {}

for i in range(N):
    s_lst = sorted(input())
    s[i] = ''.join(s_lst)
    if d.get(s[i]) is None:
        d[s[i]] = 1
    else:
        d[s[i]] += 1

ans = 0
for k, v in d.items():
    if v >= 2:
        ans += v*(v-1)/2

print(int(ans))


Measured memory_bytes: 18736
#include <iostream>
using namespace std;
 
int memo[20][20][4][16];
char data[20][20];
int W,H;
int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};
 
char chg(char c){
    string table = "<>^v";
    return table.find(c);
}
int dfs(int x,int y,int d,int m){
    x = (x+W) % W ;
    y = (y+H) % H ;
     
    if(memo[x][y][d][m]) return 0;
    else memo[x][y][d][m] = true;
     
    char c = data[y][x];
    if(c=='_'){
        d = m ? 0 : 1;
    }else if( c == '|'){
        d = m ? 2 : 3;
    }else if( c == '?'){
        for(int i = 0 ; i < 4 ; i++){
            if( dfs(x+dx[i],y+dy[i],i,m) ) return 1;
        }       
        return 0;
    }else if(c == '.'){
         
    }else if(c == '@'){
        return 1;
    }else if('0' <= c && c <= '9'){
        m = c - '0';
    }else if(c == '+'){
        m = (m+1) % 16;
    }else if(c == '-'){
        m = (m+15) % 16;
    }else{
        d = chg(c);
    }
    return dfs(x+dx[d],y+dy[d],d,m);
}
int main(){
    cin >> H >> W;
    for(int i = 0 ; i < H; i++)
        for(int j = 0 ; j < W ; j++)
            cin >> data[i][j];
    cout << (dfs(0,0,1,0)?"YES":"NO") << endl;
}

Measured memory_bytes: 1868