akhauriyash/Code-Regression huggingface dataset:
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    persons = inputs
    N = 5
    kinds = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0, }
    for n in persons:
        if n[0] in kinds:
            kinds[n[0]] += 1
    kinds_list = list(kinds.keys())

    if len(persons) < 3:
        return 0

    pattern = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            for k in range(j+1, N):
                p1 = kinds_list[i]
                p2 = kinds_list[j]
                p3 = kinds_list[k]
                pattern += kinds[p1] * kinds[p2] * kinds[p3]
    return pattern


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)


Measured memory_bytes: 10652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; 
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i<N; i++){
    cin >> a.at(i);
  }
  int p = a.at(0);
  int count = 0;
  for(int i = 0; i<N; i++){
    if(p >= a.at(i)){
      p = a.at(i);
      count++;
    }
  }
  cout << count << endl;
}

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

using namespace std;

int sol, K, N, a[109];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &K, &N);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]);
sort (a + 1, a + N + 1);
while (a[N] * 2 - 1 > K) K --, a[N] --, sol ++;
printf ("%d\n", sol);
return 0;
}


Measured memory_bytes: 256
use proconio::input;
use std::mem;

fn main() {
    input! {
        n: usize,
        k: isize,
        a: [isize; n],
    }

    let mo = 1_000_000_007;
    let mut v_first = vec![0; n];
    let mut v_repeat = vec![0; n];

    for i in 0..n {
        for j in i + 1..n {
            if a[i] > a[j] {
                v_first[i] += 1;
            }
        }
    }
    for i in 0..n {
        for j in 0..n {
            if a[i] > a[j] {
                v_repeat[i] += 1;
            }
        }
    }

    let sum_first: isize = v_first.iter().sum();
    let sum_repeat: isize = v_repeat.iter().sum();
    //ans += (sum_first + (sum_repeat % mo) * (k - i - 1) % mo) % mo;
    let ans = (k * sum_first % mo + (sum_repeat * (k * (k - 1) % mo) % mo) * modinv(2, mo) % mo) % mo;
    println!("{}", ans);
}

fn modinv(mut a: isize, m: isize) -> isize {
    let mut b: isize = m;
    let mut u: isize = 1;
    let mut v = 0;

    while b != 0 {
        let t = a / b;
        a -= t * b;
        mem::swap(&mut a, &mut b);
        u -= t * v;
        mem::swap(&mut u, &mut v);
    }

    u %= m;

    if u < 0 {
        u += m;
    }
    u
}


Measured memory_bytes: 2212
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int k;
	cin >> k;
	int n = 1 << k;
	multiset<int> s;
	for (int i = 0; i < n; i++) {
		int cur;
		cin >> cur;
		s.insert(cur * (-1));
	}
	multiset<int> vals;
	vals.insert(*s.begin());
	s.erase(s.begin());
	for (int j = 0; j < k; j++) {
		vector<int> newVals;
		for (auto x : vals) {
			auto it = s.upper_bound(x);
			if (it == s.end()) {
				return cout << "No", 0;
			}
			newVals.push_back(*it);
			s.erase(it);
		}
		for (int i = 0; i < newVals.size(); i++) {
			vals.insert(newVals[i]);
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 13304
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		while (str!=null) {
			List<Integer> stack = new ArrayList<>();
			int top = 0;
			String[] data = str.split(" ", 0);
			for (int i = 0; i < data.length; i++) {
				if (data[i].equals("+")) {
					int x = stack.get(top - 1);
					top--;
					int y = stack.get(top - 1);
					top--;
					stack.add(top, x + y);
					top++;
				} else if (data[i].equals("-")) {
					int x = stack.get(top - 1);
					top--;
					int y = stack.get(top - 1);
					top--;
					stack.add(top, y - x);
					top++;
				} else if (data[i].equals("*")) {
					int x = stack.get(top - 1);
					top--;
					int y = stack.get(top - 1);
					top--;
					stack.add(top, x * y);
					top++;
				} else {
					stack.add(top, Integer.parseInt(data[i]));
					top++;
				}
			}
			System.out.println(stack.get(top - 1));
			str = br.readLine();
		}
	}
}

Measured memory_bytes: 24364
#include <stdio.h>
#include <math.h>

#define MAX_NUM 1000000

int main(void)
{
	int prime[MAX_NUM];
	int input;
	int count;
	int i;
	int j;

	prime[0] = 0;
	prime[1] = 0;

	for(i = 2; i < MAX_NUM; i++)
	{
		prime[i] = 1;
	}

	for(i = 2; (i*i) < MAX_NUM; i++)
	{
		if(prime[i])
		{
			for(j = i * 2; j < MAX_NUM; j += i)
			{
				prime[j] = 0;
			}
		}
	}

	while(scanf("%d", &input) != EOF)
	{
		count = 0;
		for(i = 2; i < (input+1); i++)
		{
			count += prime[i];

		}
		printf("%d\n", count);
	}
	return 0;
}

Measured memory_bytes: 4500
n = int(input())
cL = []
for i in range(n):
    inputS = input()
    inputL = inputS.split()
    cL.append([inputS, int(inputL[1])])

def partition(A, l, r):
    pivot = A[r][1]
    minVI = l-1
    i = l
    while i < r:
        if A[i][1] <= pivot:
            minVI+=1
            A[i], A[minVI] = A[minVI], A[i]
        i+=1
    A[minVI+1], A[i] = A[i], A[minVI+1]
    return minVI+1

def quickSort(A, l, r):
    if l < r:
        pivotI = partition(A, l, r)
        quickSort(A, l, pivotI-1)
        quickSort(A, pivotI+1, r)

def merge(l, r):
    lI = 0
    rI = 0
    newL = []
    while lI < len(l) and rI < len(r):
        if l[lI][1] <= r[rI][1]:
            newL.append(l[lI])
            lI+=1
        else:
            newL.append(r[rI])
            rI+=1
    while lI < len(l):
        newL.append(l[lI])
        lI+=1
    while rI < len(r):
        newL.append(r[rI])
        rI+=1
    return newL

def mergeSort(curL):
    if len(curL) <= 1:
        return curL
    else:
        mid = len(curL)//2
        left = mergeSort(curL[:mid])
        right = mergeSort(curL[mid:])
        return merge(left, right)

mergeSorted = mergeSort(cL)
quickSort(cL, 0, len(cL)-1)
quickSorted = cL
if mergeSorted == quickSorted:
    print('Stable')
else:
    print('Not stable')
for v in quickSorted:
    print(v[0])



Measured memory_bytes: 24748
ans = 1
ok1 = True
_n = int(input())
a = list(map(int,input().split()))
ok2 = False
if 0 in a:
    ok2 = True

for i in a:
    ans *= i
    if ans > 1e18:
        ok1 = False
        break

if ok2:
    print(0)
elif ok1:
    print(ans)
else :
    print(-1)
    


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

int main(){
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(b-a>k){
    cout << ":(" << endl;
  }
  else if(c-b>k){
    cout << ":(" << endl;
  }
  else if(d-c>k){
    cout << ":(" << endl;
  }
  else if(e-d>k){
    cout << ":(" << endl;
  }
  else if(e-a>k){
    cout << ":(" << endl;
  }
  else{
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl '\n'
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
   vector<int> v(3);
   for(auto &it:v)cin>>it;
   cout<<(v[0]+v[1]>=v[2]?"Yes":"No")<<endl;
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}


Measured memory_bytes: 764
n=int(input())
x=list(map(int,input().split()))

s=0
for i in range(len(x)):
	s+=x[i]
i=0
l=0
while (l<(s//2)):
	l+=x[i]
	i+=1
r=abs(s-l-l) 
i=len(x)-1
l=0
while(l<(s//2)):
	l+=x[i]
	i-=1
if abs((s-l)-l)<r:
	r=abs(s-l-l) 
print (r)

Measured memory_bytes: 26220
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, ans = inf;
    cin >> n;
    vector<int> a(n);
    rep(i, n)cin >> a.at(i);
    REP(i, 100){
        ll now = 0;
        rep(j, n){
            now += (a[j]-i) * (a[j]-i); 
        }
        ans = min(ans, now);
    }
    cout << ans << endl;
}

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

typedef unsigned long long ll;
using namespace std;


ll cnt(ll num){
  ll res = 0;
  ll cnt = 0;
  ll p = 10;
  ll keep = 0;
  ll k = 1;//桁
  while(p < num){
	ll tmp = (p - 1)/3 + (p - 1)/5 - (p - 1)/15;//けさないとあかん値の量
	res -= (tmp - keep)*k;//ひかなあかんりょう
	res += (p - p/10)*k;//たさなあかん
	keep = tmp;
	p *= 10;
	k++;
  }
  ll tmp = num/3 + num/5;
  res -= (tmp - num/15 - keep)*k;
  res += (num - (p/10 - 1))*k;
  res += tmp*4;
  return res;
}
pair<ll,ll> bs(ll num){
  ll l,r;
  l = 0, r = num;
  while(l+1 < r){
	ll m = (l + r)/2;

	if(cnt(m) >= num){
	  r = m;
	}
	else if(cnt(m) < num){
	  l = m;
	}
  }
 
  return pair<ll,ll>(l,cnt(l));
}
int main(){
  ll n;
  cin >> n;
  pair<ll,ll> res = bs(n);
  string str = "";
  ll cnt = 1;
  while(str.size() <= 30){
	string tmp;
	if((res.first + cnt)%3 == 0 &&  (res.first + cnt)%5 == 0){
	  str.append("FizzBuzz");	  
	}else if((res.first + cnt)%5 == 0){
	  str.append("Buzz");	  
	}else if((res.first + cnt)%3 == 0){
	  str.append("Fizz");	  	  
	}else{
	  str.append(to_string(res.first + cnt));
	}
	cnt++;
  }
  
  for(ll i = n - res.second - 1;i < n - res.second - 1 + 20;i++){
	cout << str[i];
  }
  cout << endl;
   
  return 0;
}

Measured memory_bytes: 1236
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		String s = sc.next();
		String[] line = s.split("");
        List<Integer> array = new ArrayList<Integer>();
        int count = 0;
		//int sum = 0;
		int min = num;
for(int i=0; i<num; i++){
  if(line[i].equals(".")) count++;
}
int sum = count;
for(int i=0; i<num; i++){
  if(sum < min) min = sum;
  if(line[i].equals("#")) sum++;
  else sum--;
  //System.out.println(sum);
}
if(sum < min) min = sum;
System.out.println(min);
    }
}

Measured memory_bytes: 56636
#include<bits/stdc++.h>
 
using namespace std;
 
#define D(x) cout << (#x) << " is " << x << endl;
#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
 
 
int main()
{
    int n;
    cin >> n;
    vector<int> p;
    p.push_back(2);
    for(int i=3; i*i<=n; i+=2){
		bool fl = true;
		for(int j=2; j*j<=i; j++){
			if(i%j == 0){
				fl = false;
				break;
			}
		}
		if(fl) p.push_back(i);
	}
	int ans = 0;
	for(int i=1; i<n; i++){
		int res = 1;
		int val = i;
		for(int j: p){
			if(val % j == 0){
				int cnt = 0;
				while(val%j==0){
					val/=j;
					cnt++;
				}
				cnt++;
				res *= cnt;
			}
		}
		if(val != 1){
			res *= 2;
		}
		ans += res;
	}
	cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n;
	cin >> n;
	string s;
	ll sum = 1; ll a = 1;
	for (int i = 0; i < 13; i++)
	{
		a *= 26;
		sum += a;
		if (n >= sum)
			s += 'a';
		else
		{s += 'a'; sum -= a; break;}
	} //cout << sum << endl;
	for (ll i = 0; i < s.size(); i++)
	{
		ll a = 1; int f = 0;
		for (ll  j = 1; j < s.size() - i; j++)
			a *= 26;
		//cout << a << "fds" << endl;
		for (ll j = 1; j <= 26; j++)
		{
			ll q = j - 1;
			q *= a;
			q += sum;
			//cout << q << "sda" << n << endl;
			if (j == 26)
			{
				if (q > n)
				{

					sum = sum + (j - 2) * a;  break;
				}
				else if (q == n)
				{
					s[i] = 'z'; //cout << "q";
					f = 1; break;
				}
				else
				{
					s[i] = 'z'; sum = q;
				}

			}
			else if (q > n)
			{
				if (j == 1)
					break;

				sum = sum + (j - 2) * a;  break;
			}
			else if (n == q)
			{
				char c = 'a' - 1 + j; //cout << c << endl;
				s[i] = c; //cout << "q";
				f = 1; break;
			}
			else
			{
				char c = 'a' - 1 + j; //cout << c << endl;
				s[i] = c;
			}
		}
		//cout << sum << endl << endl << endl;
		if (f == 1)
			break;
	}
	for (int i = 0; i < s.size(); i++)
		cout << s[i];
	return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int>a(30);
  string s;
  cin>>s;
  for(auto c:s)a[c-'a']++;
  int f=1;
  rep(i,30)if(a[i]%2)f=0;
  if(f){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N, X, T, W;

        N = int.Parse(input[0]);
        X = int.Parse(input[1]);
        T = int.Parse(input[2]);

        if (N % X == 0)
        {
            W = N / X * T;
            Console.WriteLine(W);
        }
        else
        {
            W = (N / X + 1) * T;
            Console.WriteLine(W);
        }

        //Console.ReadLine();
    }
}


Measured memory_bytes: 27504
#include<stdio.h>
const int N = 15;
int main()
{
	int a[N] = {0};
	for(int i = 0; i < 10; i++)
	{
		scanf("%d", &a[i]);
	}
	for(int i = 0; i < 10; i++)
	{
		
		for(int j = i; j < 10; j++)
		{
			if(a[i] < a[j])
			{
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	} 
	for(int i = 0; i < 3; i++)
	{
		printf("%d\n", a[i]);
	}
	return 0;
} 


Measured memory_bytes: 2696
n,q=map(int,input().split())
s=input()
ls=[0]*n
i=1
while i < len(s):
  if s[i-1]+s[i]=="AC":
    ls[i]=1
  i+=1
for i in range(len(ls)-1):
  ls[i+1]=ls[i+1]+ls[i]

for i in range(q):
  l,r=map(int,input().split())
  print(ls[r-1]-ls[l-1])

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


auto solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c, std::vector<long long> d){
    std::vector<int> result(N);

    for(int i = 0; i < N; ++i){
        long long minv = numeric_limits<long long>::max();
        for(int j = 0; j < M; ++j) {
            long long dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(dist < minv){
                minv = dist;
                result[i] = j;
            }
        }
    }


    stringstream ss;
    for(const auto& i : result) {
        ss << (i + 1) << endl;
    }
    return ss.str();
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    std::vector<long long> c(M);
    std::vector<long long> d(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&c[i]);
        scanf("%lld",&d[i]);
    }
    auto result = solve(N, M, std::move(a), std::move(b), std::move(c), std::move(d));
    cout << result;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

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

    int sum = 0;
    rep(i,n) sum ^= a[i];
    rep(i,n) cout << (a[i]^sum) << " ";
    cout << endl;
}

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

#define int long long 
#define dou  double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	int n,i,sum=0,j;
	cin >> n;
	vector<int> v(n);
	for(i=0;i<n;i++)
		cin >> v[i];

	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	sum += v[0];
	j=1;
	for(i=1;i<n-1;i++)
	{
		sum += v[j];
		if(i%2==0)
			j++;
	}
	cout << sum << endl;
}

main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    ll rt_n = int(sqrt(n));
    vector<ll> s(n);
    cin >> s;
    vector<vector<vector<ll>>> modsum(rt_n);
    for(int c = 1; c < rt_n; c++) {
        modsum[c] = vector<vector<ll>>(c);
        for(int i = 0; i < n; i++) {
            modsum[c][i % c].push_back(s[i]);
        }
        for(int j = 0; j < c; j++) {
            partial_sum(modsum[c][j].begin(), modsum[c][j].end(), modsum[c][j].begin());
        }
    }
    auto rsq = [](vector<ll>& p, int L, int R) {
        return p[R - 1] - (L ? p[L - 1] : 0);
    };
    ll ans = 0;
    for(ll c = 1; c <= n; c++) {
        for(ll a = (n - 1) % c; a < n - 1; a += c) {
            ll b = a - c;
            if(b > 0 and b < a and (a % c != 0 or a + c * (a / gcd(a, b) - 1) >= n - 1)) {
                ll cur = 0;
                if(c >= rt_n) {
                    for(int i = a, step = 0; i < n and step < (n - 1 - a) / c; i += c, step++) {
                        cur += s[i];
                    }
                    for(int i = a - b, step = 0; i < n and step < (n - 1 - a) / c; i += c, step++) {
                        cur += s[i];
                    }
                } else {
                    int L1 = a / c, L2 = (a - b) / c;
                    cur += rsq(modsum[c][a % c], L1, L1 + (n - 1 - a) / c);
                    cur += rsq(modsum[c][(a - b) % c], (a - b) / c, L2 + (n - 1 - a) / c);
                }
                ans = max(ans, cur);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 342456
using System;
using System.Collections.Generic;

public class Program {
  public static void Main(string[] args) {
    List<Pair> conns = new List<Pair>();
    
    int N = int.Parse(Console.ReadLine());
    int[] nodeSumMaxes = new int[N];
    nodeSumMaxes[1-1] = (N-1) * (2 + N) / 2; //2からNまでの和
    for(int i = 1; i < N; ++i) {
      nodeSumMaxes[i] = nodeSumMaxes[i-1] - 1;
    }
    
    int S = nodeSumMaxes[N-1];
    if(N % 2 == 0) --S;
    
    for(int i = 0; i < N; ++i) {
      int diff = nodeSumMaxes[i] - S;
      for(int j = i; j < N; ++j) {
        if(j+1 != diff && i != j) {
          conns.Add(new Pair(i+1, j+1));
        }
      }
    }
    
    Console.WriteLine(conns.Count);
    foreach(var conn in conns) {
      Console.WriteLine(conn.a + " " + conn.b);
    }
  }
}

class Pair {
  public int a;
  public int b;
  
  public Pair(int a, int b) {
    this.a = a;
    this.b = b;
  }
}


Measured memory_bytes: 11220
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int m = sc.nextInt();
        int n = sc.nextInt();
        int o = sc.nextInt();
        int p = sc.nextInt();
        int q = sc.nextInt();
        String command = sc.next();
        sc.close();
        Dice dice = new Dice(l, m, n, o, p, q);
        for (int s=0; s < command.length(); s++) {
        	String t = command.substring(s,s+1);
        	if("N".equals(t)){
        		dice.N();
        	} else if("E".equals(t)){
            	dice.E();
            } else if("W".equals(t)){
            	dice.W();
            } else if("S".equals(t)){
            	dice.S();
            }
        }
        dice.print();
    }
}
    class Dice{
		int one;
		int two;
		int three;
		int four;
		int five;
		int six;
		int tmp;
    	Dice(int a, int b, int c, int d, int e, int f){
    		one=a;
    		two=b;
    		three=c;
    		four=d;
    		five=e;
    		six=f;
    	}
    	void N(){//1-2-6-5
    		tmp =one;
    		one=two;
    		two=six;
    		six=five;
    		five=tmp;
    	}
    	void E(){//1-4-6-3
    		tmp =one;
    		one=four;
    		four=six;
    		six=three;
    		three=tmp;
    	}
    	void W(){//1-3-6-4
    		tmp =one;
    		one=three;
    		three=six;
    		six=four;
    		four=tmp;
    	}
    	void S(){//1-5-6-2
    		tmp =one;
    		one=five;
    		five=six;
    		six=two;
    		two=tmp;
    	}
    	void print(){
    		System.out.println(one);
    	}

    }



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

int main() {
    int a, b;
    cin >> a;
    cin >> b;

    if (a > b) {
        cout << "a > b" << endl;
    } else if (a < b) {
        cout << "a < b" << endl;    
    } else {
        cout << "a == b" << endl; 
    }
    
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
int n, m, f[105][105];
char a[105][105];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf(" %s", a[i] + 1);
	}
	f[1][1] = (a[1][1] == '#');
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) if (i != 1 || j != 1) {
			f[i][j] = 1145141;
			if (i > 1) {
				if (a[i - 1][j] == '.' && a[i][j] == '#') f[i][j] = min(f[i][j], f[i - 1][j] + 1);
				else f[i][j] = min(f[i][j], f[i - 1][j]);
			}
			if (j > 1) {
				if (a[i][j - 1] == '.' && a[i][j] == '#') f[i][j] = min(f[i][j], f[i][j - 1] + 1);
				else f[i][j] = min(f[i][j], f[i][j - 1]);
			}
		}
	}
	printf("%d\n", f[n][m]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long int
#define db long double 
#define ull unsigned long long int
// #define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define Nmax 1000005
// #define INF 10000000000000
#define MOD 1000000007
#define MAXN 200005
 
using namespace std;

ll mod=998244353;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}

const ll M=3000006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // compute();
    int tests=1;
    // cin>>tests;    
    while(tests--)
    {
    	string s;
    	cin>>s;
    	if(s.back()=='s') s+="es";
    	else s+="s";
    	cout<<s;

    }

    return 0;
}
    

Measured memory_bytes: 3644
#include <stdio.h>

int main()
{
  int n,i,t;
  int data[100];

  scanf("%d",&n);

  for (i=0;i<n;i++){
    scanf("%d",&data[i]);
  }

  for (i=0;i<n/2;i++){
    t=data[i];
    data[i]=data[n-i-1];
    data[n-i-1]=t;
  }
  for(i=0;i<n-1;i++){
    printf("%d ",data[i]);
  }
  printf("%d\n",data[n-1]);

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;

int N,X[200010],Y[200010];

signed main(){
  cin>>N;
  for(int t=1;t<=N;t++){
    cin>>X[t];
    Y[t]=X[t];
  }

  sort(Y+1,Y+1+N);

  for(int t=1;t<=N;t++){
    if(X[t]<=Y[N/2]){
      cout<<Y[N/2+1]<<"\n";
    }else if(X[t]>=Y[N/2+1]){
      cout<<Y[N/2]<<"\n";
    }
  }

  return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N), B(M);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (ll i = 0; i < M; i++) {
        cin >> B[i];
    }

    sort(ALL(A), greater<ll> ());
    sort(ALL(B), greater<ll> ());

    ll inda = 0;
    ll indb = 0;

    ll ans = 1;
    ll c, d;
    bool checka, checkb;
    for (ll i = N*M; i >= 1; i--) {
        checka = false; checkb = false;
        if(inda >= N) {
            c = N;
            checka = true;
        }
        else if(A[inda] == i){
            c = 1;
            inda++;
            if(inda < N && A[inda] == i){
                printf("0\n"); return 0;
            }
        }
        else{
            c = inda;
            checka = true;
        }

        if(indb >= M) {
            d = M;
            checkb = true;
        }
        else if(B[indb] == i){
            d = 1;
            indb++;
            if(indb < M && B[indb] == i){
                printf("0\n"); return 0;
            }
        }
        else{
            d = indb;
            checkb = true;
        }

        if(checka && checkb){
            if(c * d <= N*M - i){
                printf("0\n"); return 0;
            }
            else{
                ans = ans * (c * d - N * M + i) % MOD;
            }
        }
        else{
            ans = ans * c * d % MOD;
        }

    }

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

}

Measured memory_bytes: 3744
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b>c+d){
	cout << "Left" << endl;
  }
  else if(a+b<c+d){
	cout << "Right" << endl;
  }
  else{
	cout << "Balanced" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        String S = sc.next();

        System.out.println(solve(S));
    }

    private static long solve(String S) {
        long count = 0;
        int black = 0;

        for (int i=0; i<S.length(); i++) {
            char ch = S.charAt(i);

            if (ch == 'B') black++;
            else {
                count += black;
            }
        }

        return count;
    }
}

Measured memory_bytes: 26068
def main():
    n = int(input())
    a_list = [int(input()) for _ in range(n)]

    idx, flag = 1, 1
    for i in range(1, n+1):
        idx = a_list[idx-1]
        if idx == 2:
            print(i)
            flag = 0
            break

    if flag: print(-1)
    

if __name__ == "__main__":
    main()

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

using namespace std;

#define INF ((1LL<<31)-1)
#define D 10

struct SegTree {
	int segSize, realSegSize, nodeSize;
//	vector<int> seg;
	int *seg;

	void init(int n) {
		realSegSize = n;

		nodeSize = 0;
		for (segSize = 1; segSize < n; segSize *= D) nodeSize += segSize;

		seg = (int*)malloc(sizeof(int) * (nodeSize+segSize));
		fill(&seg[0], &seg[0]+nodeSize+segSize, INF);
//		seg = vector<int>(nodeSize+n, INF);
	}

	int get(int n) {
		return seg[n];
//		if (n < (int)seg.size()) return seg[n];
//		else return INF;
	}
	void set(int n, int v) {
		seg[n] = v;
//		if (n < (int)seg.size()) seg[n] = v;
	}

	void update(int pos, int val) {
		int n = nodeSize + pos;
		set(n, val);
		while (n) {
			n = (n-1)/D;

			int r = INF;
			for (int i = 0; i < D; ++i) {
				r = min(r, seg[n*D+i+1]);
			}
			set(n, r);
		}
	}
	int get(int n, int l, int r, int L, int R) {
//		cout << n << " " << l << " " << r << endl;
		if (L <= l && r <= R) return get(n);
		else if (R <= l || r <= L) return INF;
		else {
			int ret = INF;
			int prev = l;
			for (int i = 0; i < D; ++i) {
				int next = i == D-1 ? r : prev + (r-l)/D;
				ret = min(ret, get(n*D+i+1, prev, next, L, R));
				prev = next;
			}
			return ret;
		}
	}
	int get(int L, int R) {
		return get(0, 0, segSize, L, R);
	}

	~SegTree() {
		free(seg);
		//seg.clear();
		//seg.shrink_to_fit();
	}
};

struct Query {
	int y1, x1, y2, x2;
};

int main() {
	int H, W, Q;
	while ( cin >> H >> W >> Q, H || W || Q ) {
		vector< vector<int> > m(H, vector<int>(W, 0));

		for (int y = 0; y < H; ++y) {
			for (int x = 0; x < W; ++x) {
				cin >> m[y][x];
			}
		}

		bool isSegRow = H < W;
		vector<SegTree> seg;

		if (isSegRow) {
			seg.resize(H);
			for (int y = 0; y < H; ++y) {
				seg[y].init(W);
			}
		}
		else {
			seg.resize(W);
			for (int x = 0; x < W; ++x) {
				seg[x].init(H);
			}
		}

		for (int y = 0; y < H; ++y) {
			for (int x = 0; x < W; ++x) {
				if (isSegRow) seg[y].update(x, m[y][x]);
				else seg[x].update(y, m[y][x]);
			}
		}

		for (int t = 0; t < Q; ++t) {
			int y1, x1, y2, x2; cin >> y1 >> x1 >> y2 >> x2;

			int ans = INF;
			if (isSegRow) {
				for (int y = y1; y <= y2; ++y) {
					ans = min(ans, seg[y].get(x1, x2+1));
				}
			}
			else {
				for (int x = x1; x <= x2; ++x) {
					ans = min(ans, seg[x].get(y1, y2+1));
				}
			}
			cout << ans << endl;
		}

		seg.clear();
		seg.shrink_to_fit();
	}
}

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

main(){
	int n,k,m ;
	cin >> n ;
	for( int i=0 ; i<n ; i++ ){
		cin >> k >> m ;
		int ans=0 ;
		for( int j=1 ; j<=k ; j++ ){
			ans++ ;
			if( ans > m ) ans = 1 ;
		}
		cout << ans << endl ;
	}
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];

    double ans = 0;
    double tmp = 0;
    queue<double> que;

    rep(i,n) {
        double ex = (1+(double)p[i])/2;
        que.push(ex);
        tmp += ex;
        if (que.size()==k) {
            ans = max(ans,tmp);
            double qf = que.front(); que.pop();
            tmp -= qf;
        }
    }
    printf("%.8f\n",ans);
    return 0;
}






























Measured memory_bytes: 2688
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(){
	long long n,a,b;
	bool flag;
	int number;
	map<int,long long> info;
	vector<int> seq;
	
	while(cin >> n && n){
		info.clear();
		seq.clear();
		while(n--){
			cin >> number >> a >> b;
			if(!info[number])seq.push_back(number);
			info[number] += a*b;
		}
		flag = true;
		for(int i=0;i<seq.size();i++){
			if(info[seq[i]]>=1000000){
				flag = false;
				cout << seq[i] << endl;
			}
		}
		if(flag)cout << "NA" << endl;
	}
}

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

ll dp[102][100005];
const int totval = 1e5;

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

  int n;
  ll totwt;
  cin >> n >> totwt;
  ll w[102], v[102];
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= totwt; j++) {
      dp[i][j] = -1e18;
    }
  }
  dp[n][0] = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j <= totwt; j++) {
      dp[i][j] = dp[i + 1][j];
      if (j >= w[i]) {
        dp[i][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
      }
    }
  }

  ll ans = -1e18;
  for (int j = totwt; j >= 0; j--) {
    ans = max(ans, dp[0][j]);
  }
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 79232
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long Int;
typedef pair<Int, Int> P;
vector<Int> ans;
Int sum(Int x){
	if(x==0)return x;
	return x % 10 + sum(x/10);
}

double calc(Int hoge){
	return hoge*1.0 / sum(hoge);
}

double  best = 1LL<<62;

vector<Int> nums;

void hoge(Int b){
	for(Int i = 1;i * b < 1000000000000020LL;i*=10){
		nums.push_back(b*i-1);
	}
}
	

int main(){
	for(Int i = 1;i < 10000;i++){
		hoge(i);
	}
	sort(nums.begin(), nums.end());
	nums.erase(unique(nums.begin(),nums.end()), nums.end());
	
	for(int i = nums.size() - 1;i >= 0;i--){
		double tmp = calc(nums[i]);
		if(tmp <= best){
			ans.push_back(nums[i]);
			best = tmp;
		}
	}
	sort(ans.begin(), ans.end());
	//	cout << ans.size();
	Int k;
	cin >> k;
	for(Int i = 0;i < k;i++)cout << ans[i] << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()

typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//#define int long long


inline void solve(){

    int n;
    string s[2];
    cin >> n >> s[0] >> s[1];

    ll ans = (s[0][0]==s[1][0]?3:6);
    for(int i = 0; i < n-1; i++) {
        bool isH = (s[0][i]==s[1][i]);
        i += !isH;      
        int j = i+1;
        bool ish =(s[0][j]==s[1][j]);
        if(isH)
            ans *=2;
        else{
            if(ish)
                ans *= 1;
            else
                ans *= 3;
        }
        ans %= SMOD;

    }
    cout << ans << endl;
        

}

struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<cstring>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

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

typedef unsigned long long u64;
typedef long long i64;

int n, m, c;
int b[50];
int a[50][50];

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

        cin >> n >> m >> c;
        REP(i,m)
                cin >> b[i];
        REP(i,n)
                REP(j,m)
                        cin >> a[i][j];
        int r = 0;
        int k;
        REP(i,n) {
                k = c;
                REP(j,m)
                        k += a[i][j]*b[j];
                if (k > 0)
                        r++;
        }

        cout << r << endl;

        return 0;
}


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

int main()
{
	long long n;
	cin >> n;
	vector<long long> av(n);
	for (auto& a : av) {
		cin >> a;
	}

	vector<pair<long long, long long>> c;
	c.push_back({1000, 0});	// 値段重視
	c.push_back({ 1000, 0 });	// 株重視
	for (auto& a : av) {
		long long value = c[1].second * a + c[1].first;
		if (value > c[0].first) {
			c[0].first = value;
		}

		long long kabu1 = c[0].first / a;
		long long kabu2 = c[1].first / a + c[1].second;
		if (kabu1 < kabu2) {
			c[1].first = c[1].first % a;
			c[1].second = kabu2;
		}
		else {
			c[1].first = c[0].first % a;
			c[1].second = kabu1;
		}
	}

	cout << c[0].first << endl;

	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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; }
using ll = long long;
const ll MOD=1e9+7;
const long long INF = 1LL<<60;

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

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

    int answer = INT_MAX;
    for(int i = 1;i<=n/2;i++){
        int a = i, b = n-i;
        answer = min(answer, sum_digit(a)+sum_digit(b));
    }

    cout << answer << endl;
}

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

int main(){
    int n; //文字数
    cin >> n;
    string s; //R,G,Bからなる文字列
    cin >> s;

    long long r = 0; //rを数える
    long long g = 0; //gを数える
    long long b = 0; //bを数える

    /* r、g、bの個数を数える */
    for(int i=0; i<n; i++){
        if(s[i] == 'R') r++;
        else if(s[i] == 'G') g++;
        else if(s[i] == 'B') b++;
    }

    long long int ans = r*g*b;

    for(int i=0; i<n-2; i++){
        for(int j=i+1; 2*j-i<n; j++){
            if(s[i] != s[j] && s[i] != s[2*j-i] && s[j] != s[2*j-i]){
                ans--;
            }
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define S 2500005
#define N 1005
using namespace std;
typedef pair<int,int> P;
struct d{
  int a,b,c;
  d(){}
  d(int A,int B,int C){
    a=A,b=B,c=C;
  };
  bool operator<(const d&r)const{
    if(a!=r.a)return a<r.a;
    return b<r.b;
  }
};

int n,slen,tlen,r[S];
char s[S],t[N];
d ran[S];
P a[S];

void init(){

  for(int j=0;j<slen;j++)r[j]=s[j];

  int x=1;
  r[slen]=0;
  while(1){
    for(int i=0;i<slen;i++){
      int o=i+x;
      if(o>slen)o=slen;
      ran[i]=d(r[i],r[o],i);
    }
    sort(ran,ran+slen);
    int cnt=0;
    for(int i=0;i<slen;i++){
      r[ran[i].c]=cnt;
      if(ran[i].a==ran[i+1].a&&ran[i].b==ran[i+1].b)
	continue;
      cnt++;
    }
    if(x>slen)break;
    x*=2;
  }
  for(int i=0;i<slen;i++)a[i]=P(r[i],i);
  sort(a,a+slen);
}

bool bynary_search(){
  int L=0,R=slen;
  while(L<R){
    int M=(L+R)/2;
    if(strncmp(s+a[M].second,t,tlen)<0)L=M+1;
    else R=M;
  }
  if(!strncmp(s+a[L].second,t,tlen))return true;
  return false;
}

int main(){
  scanf("%s%d",s,&n);
  slen=strlen(s);
  init();  
  while(n--){
    scanf("%s",t);
    tlen=strlen(t);
    if(bynary_search())printf("1\n");
    else printf("0\n");
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define first F
#define second S
#define int ll

int32_t main(){
    FAST
    int n; cin >> n;
    if(n%2){
        cout << 0;
    }
    else{
        int num = 5;
        int ans = 0;
        for (int i = 10; n / i >= 1; i *= 5){
            ans += n/i;
        }

        cout << ans;
    }
}


Measured memory_bytes: 3672
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue


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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE b(n); rep(i, n)cin >> b[i];
	VE a(n);
	rep(i, n) {
		bool ok = false;
		for (int j = b.size() - 1; j >= 0; j--) {
			if (b[j] == j + 1) {
				a[i] = b[j];
				b.erase(b.begin() + j); ok = true; break;
			}
		}
		if (!ok) {
			cout << -1 << endl; return 0;
		}
	}
	reverse(a.begin(), a.end());
	rep(i, n) {
		cout << a[i] << endl;
	}
	return 0;
}

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

int main(void) {

	std::string s;
	int a;

	std::cin >> a >> s;

	int max = 0;
	for (size_t i = 0; i < s.length(); i++) {
		int alpha[26] = { 0 };

		for (size_t j = 0; j <= i; j++) {
			alpha[s[j] - 'a']++;
		}

		int count = 0;
		for (size_t j = i + 1; j < s.length(); j++) {
			if (alpha[s[j] - 'a'] > 0) {
				count++;
				alpha[s[j] - 'a'] = 0;
			}
		}

		max = std::max(max, count);
	}

	std::cout << max << std::endl;

	return 0;
}

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

int main() {
    long long n, ret = 0;
    std::cin >> n;
    std::vector<long long> a(n + 1), s(n + 1), x(n + 1);
    for (auto i = 1ll; i <= n; i++) {
        std::cin >> a[i];
        s[i] = s[i - 1] + a[i];
        x[i] = x[i - 1] ^ a[i];
    }

    auto prev = 1ll;
    for (auto i = 1ll; i <= n; i++) {
        for (auto r = prev; r <= n; r++) {
            if (s[r] - s[i - 1] != (x[r] ^ x[i - 1])) {
                ret += r - i;
                prev = r;
                break;
            } else if (r == n) {
                ret += n - i + 1;
                prev = n;
            }
        }
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 5120
// 解き直し.
// ABC 129解説.
// https://img.atcoder.jp/abc129/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL MOD = 1e9 + 7;
char L[123321];
LL dp[123321][2];

int main() {
    
    // 1. 入力情報取得.
    scanf("%s", L);
    
    // 2. 解説通り.
    // ex.
    // L = 10 の 場合.
    //        L[0] = 1          L[1] = 0
    // -----------------------------------------
    // dp1  dp1[0] = 1         dp1[1] = dp1[0] * 3 + dp2[0] * 1 = 5通り
    //      ※(A, B) = (0, 0)  ※第1項: (A, B) = (0, 0)
    //                         ※第2項: (A, B) = (0, 0)
    // -----------------------------------------
    // dp2  dp2[0] = 2         
    //      ※(A, B) = (0, 1), 
    //                 (1, 0)
    // 
    // L = 101 の 場合(※前述の考え方を踏襲).
    //        L[0] = 1    L[1] = 0             L[2] = 1
    // -------------------------------------------------------------------------
    // dp1  dp1[0] = 1    dp1[1] = dp1[0] * 3  dp1[1] = dp1[1] * 3
    //                           + dp2[0] * 0         + dp2[1] * 3 = 15通り
    // -------------------------------------------------------------------------
    // dp2  dp2[0] = 2    dp2[1] = dp2[0]
    // 
    // L = 111 の 場合(※前述の考え方を踏襲).
    //        L[0] = 1    L[1] = 1             L[2] = 1
    // -------------------------------------------------------------------------
    // dp1  dp1[0] = 1    dp1[1] = dp1[0] * 3  dp1[1] = dp1[1] * 3
    //                           + dp2[0] * 1         + dp2[1] * 3 = 27通り
    // -------------------------------------------------------------------------
    // dp2  dp2[0] = 2    dp2[1] = dp2[0] * 2
    
    // 2-1. L = '1'.
    int l = strlen(L);
    if(l == 1){
        printf("%d\n", 3);
        return 0;
    }
    
    // 2-2. L[0] ～ L[l - 2] を 確認.
    dp[0][0] = 1, dp[0][1] = 2;
    for(int i = 1; i < l - 1; i++){
        // dp[i][0] の 更新(i桁目 が '0' or '1' で 処理 を 分岐).
        if(L[i] == '0') dp[i][0] = dp[i - 1][0] * 3;
        else            dp[i][0] = dp[i - 1][0] * 3 + dp[i - 1][1];

        // dp[i][1] の 更新(i桁目 が '0' or '1' で 処理 を 分岐).
        if(L[i] == '0') dp[i][1] = dp[i - 1][1];
        else            dp[i][1] = dp[i - 1][1] * 2;
        
        // MOD.
        dp[i][0] %= MOD, dp[i][1] %= MOD;
    }

    // 2-3. L[l - 1] を 確認.
    dp[l - 1][0] = dp[l - 2][0] * 3;
    if(L[l - 1] == '0') dp[l - 1][0] += dp[l - 2][1],     dp[l - 1][0] %= MOD;
    else                dp[l - 1][0] += dp[l - 2][1] * 3, dp[l - 1][0] %= MOD;
    
    // dp確認.
    // for(int i = 0; i < l; i++) printf("%lld ", dp[i][0]);
    // printf("\n");
    // for(int i = 0; i < l; i++) printf("%lld ", dp[i][1]);
    // printf("\n");
    
    // 3. 出力 ～ 後処理.
    printf("%lld\n", dp[l - 1][0]);
    return 0;
    
}

Measured memory_bytes: 1920