akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main{

    int n, m, sz;
    char[] kakko;
    int[] a, bkt, add;

    void solve(){
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        m = sc.nextInt();
        kakko = sc.next().toCharArray();

        sz = Math.max(1, (int)Math.sqrt(n) + 10);
        a = new int[n];
        bkt = new int[n/sz+10];
        add = new int[n/sz+10];
        TreeSet<Integer> set = new TreeSet<Integer>();

        for(int i=0; i<n; i++){
            if(i==0) a[i] = 1;
            else{
                if(kakko[i]=='(') a[i] = a[i-1] + 1;
                else{
                    a[i] = a[i-1] - 1;
                    set.add(i);
                }
            }
            bkt[i/sz] = Math.min(a[i], bkt[i/sz]);
        }

        for(int i=0; i<m; i++){
            int q = sc.nextInt()-1;
            int idx = 0;
            if(kakko[q]=='('){
                kakko[q] = ')';
                set.add(q);
                add(q, n, -2);
                //idx = set.higher(new Integer(-1));
                idx = set.pollFirst();
                kakko[idx] = '(';
                set.remove(idx);
                add(idx, n, 2);
            }else{
                kakko[q] = '(';
                set.remove(q);
                add(q, n, 2);
                idx = search(q);
                kakko[idx] = ')';
                add(idx, n, -2);
                set.add(idx);
            }
            //System.out.println(Arrays.toString(kakko));
            System.out.println(idx+1);
        }
    }

    void add(int start, int last, int num){
        int from = start - start%sz;
        int to = from + sz;
        for(int i=start/sz; i * sz <=last; i++){
            if(start<=from && to<=last){
                add[i] += num;
            }else{
                for(int j=Math.max(from, start); j<to && j<last; j++){
                    a[j] += num;
                }
                int min = Integer.MAX_VALUE;
                for(int j=from; j<to && j<a.length; j++){
                    min = Math.min(min, a[j]);
                }
                bkt[i] = min;
            }
            from = to;
            to += sz;
        }
    }

    int search(int f){        
        int from = f - f%sz;
        int to = from + sz;
            
        for(int i=f/sz; i>=0; i--){
            if(bkt[i]+add[i]<=1){
                for(int j=Math.min(f-1, to-1); j>=from; j--){
                    if(a[j]+add[i]==1) return j+1;
                }
            }
            to = from;
            from -= sz;
        }
        return 0;
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 116352
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x = i;
        if (x % 3 == 0){
            cout << " " << i;
        }
        else{
            while (x){
                if (x % 10 == 3){
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    string s, t;
    cin >> s >> t;
    cout << t + s << endl;
}


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

using ll=long long; 

void solve(){
	ll a,b,c;
	cin>>a>>b>>c;
	if(a%2==0||b%2==0||c%2==0){
		cout<<0<<endl;
		return;
	}
	vector<ll>ar(3);
	ar[0]=a,ar[1]=b,ar[2]=c;
	sort(ar.begin(), ar.end());
	cout<<ar[0]*ar[1]<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a; int b1, b2;
  scanf("%lld", &a);
  scanf("%d.%d", &b1, &b2);
  cout << a*b1+a*b2/100 << "\n";
  return 0;
}


Measured memory_bytes: 3796
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <vector>
using namespace std;
int main(){
    int n,y;
    cin>>n>>y;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            if((i*10000)+(j*5000)+((n-i-j)*1000)==y){
                cout<<i<<" "<<j<<" "<<n-i-j<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
    return 0;
}


Measured memory_bytes: 256
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let a = buf.trim().chars().collect::<Vec<char>>();
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let b = buf.trim().chars().collect::<Vec<char>>();
	if a.len() > b.len() {
		println!("GREATER");
	}else if a.len() < b.len() {
		println!("LESS");
	}else{
		for i in 0..a.len() {
			if a[i] > b[i] {
				println!("GREATER");
				break;
			}else if a[i] < b[i] {
				println!("LESS");
				break;
			}else{
				if i == 0 {
					println!("EQUAL");
				}
			}
		}
	}
}

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

using namespace std;

int main()
{
  while(1){
    int e;
    cin>>e;
    if(e == 0){
      break;
    }

    int ans;
    bool check = false;
    for(int z = 0;z * z * z <= e;++z){
      for(int y = 0;y * y <= e - z * z * z;++y){
        int x = e - ((y * y) + (z * z * z));

        if(check == false){
          ans = x + y + z;
          check = true;
        }
        else{
          ans = min(ans,x+y+z);
        }
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 2996
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
Mod = 1000000007



def main(): #startline-------------------------------------------
    A,B = map(int,input().split())
    def modfour(i):
        return i % 4
    ans = 0
    if A % 2 == 0:
        for i in range(modfour(B-A+1)):
            ans ^= B-i
        print(ans)
    else:
        ans = A
        for i in range(modfour(B-A+1)+3):
            ans ^= B-i
        print(ans)
if __name__ == "__main__":
    main() #endline===============================================




def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Measured memory_bytes: 5176
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
l = [0]*n
r = [0]*n
for i in range(n):
    l[i] = i+a[i]
    r[i] = i-a[i]
    
l=Counter(l)
r=Counter(r)
ans = 0
for i in range(max(r.keys())+1):
    ans += l[i]*r[i]
print(ans)

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

#define eps 1e-12
#define PI acos(-1)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	double a, b, x;
	cin >> a >> b >> x;
	x /= a;
	
	double lo = 0, mid = 0, hi = PI/2;
	
	for(int rep = 0; rep < 100; rep++) {
		mid = lo + (hi-lo)/2;
		
		double water, y;
		y = b / tan(mid);
		water = b * y /2;
		if(y > a) {
			y -= a;
			double tmp = y * tan(mid);
			water -= tmp * y / 2;
		}
		
		//$ cerr << water << endl;
		if(water >= x) {
			lo = mid;
		} else {
			hi = mid;
		}
	}
	
	cout << fixed << setprecision(10) << mid * 180.0 / PI << endl;
}


Measured memory_bytes: 256
from collections import Counter
mod=10**9+7
n=int(input())
A=list(map(int,input().split()))
Count=sorted(Counter(A).items())
cnt=0
if n%2==1:
    if Count.pop(0)[1]==1:
        point=2
        for v,m in Count:
            if v==point and m==2:
                cnt +=1
                point +=2
        print((2**cnt)%mod)
    else:print(0);exit()
else:
    point=1
    for v,m in Count:
        if v==point and m==2:
            cnt +=1
            point +=2
        else:print(0);exit()
    print((2**cnt)%mod)

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

int gcd(int a, int b){
    if(a<b){
        int tmp = a;
        a = b;
        b = tmp;
    }
    int r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main(void){
    int N, X, ans=0;
    cin >> N >> X;
    int px[100100], sa[100100];
    for(int i=0;i<N;i++){
        cin >> px[i];
        sa[i] = abs(px[i]-X);
    }
    if(N>1) ans = gcd(sa[0], sa[1]);
    else ans = sa[0];
    for(int i=2;i<N;i++){
        ans = gcd(ans, sa[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public long N;
        public long MOD = 1000000007;

        public void Run()
        {
            N = Input.ReadLong();

            int ret = int.MaxValue;
            for (long i = 1; i * i <= N; i++)
            {
                if (N % i != 0) continue;
                long a = i;
                long b = N / a;
                ret = Math.Min(ret, Math.Max(Digits(a), Digits(b)));
            }

            Console.WriteLine(ret);
        }

        int Digits(long n)
        {
            int ret = 0;
            while (n > 0)
            {
                ret++;
                n /= 10;
            }
            return ret;
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13012
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

string s;
int f(int pos)
{
    if (s[pos] == 'r')
        return 2;
    if (s[pos] == 's')
        return 0;
    return 1;
}

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

    int n, k, cost[3];
    cin >> n >> k;
    rep(i, 3) cin >> cost[i];
    cin >> s;
    int ans = 0;
    rep(i, k) ans += cost[f(i)];
    for (int i = k; i < n; i++)
    {
        if (s[i] == s[i - k])
            s[i] = '.';
        else
            ans += cost[f(i)];
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
import math
N = int(input())

def prime_decomposition(x):
  i = 2
  ls = []
  while i * i <= x:
    while x % i == 0:
      x /= i
      ls.append(i)
    i += 1
  if x > 1:
    ls.append(int(x))
  return ls

def counter(n):
  i = 1
  while n > 0.5*(i+1)*(i+2)-1:
    i += 1
  return i

cnt = 0
numbers = prime_decomposition(N)
set_number = set(numbers)

for i in set_number:
  cnt += counter(numbers.count(i))
  
print(cnt)

Measured memory_bytes: 9276
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	H, W, _ := getInt(), getInt(), getInt()
	s := make([]string, H)
	for i := 0; i < H; i++ {
		s[i] = getString()
	}
	t := make([][]int, H)
	h := make([]int, H)
	cnt := 1
	for i := 0; i < H; i++ {
		t[i] = make([]int, W)
		for j := 0; j < W; j++ {
			if s[i][j] == '#' {
				t[i][j] = cnt
				cnt++
				h[i]++
			}
		}
	}

	for i := 0; i < H; i++ {
		for j := 1; j < W; j++ {
			if t[i][j] == 0 {
				t[i][j] = t[i][j-1]
			}
		}
		for j := W - 2; j >= 0; j-- {
			if t[i][j] == 0 {
				t[i][j] = t[i][j+1]
			}
		}
	}
	for i := 1; i < H; i++ {
		if h[i] == 0 {
			for j := 0; j < W; j++ {
				t[i][j] = t[i-1][j]
			}
		}
	}

	for i := H - 2; i >= 0; i-- {
		if h[i] == 0 {
			for j := 0; j < W; j++ {
				t[i][j] = t[i+1][j]
			}
		}
	}

	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			fmt.Print(t[i][j], " ")
		}
		fmt.Println()
	}
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repll(i, a, b) for(ll i=(a); i<(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define COUT(a) cout << a << endl
#define ALL(a) (a).begin(),(a).end()
const long long int mod = 1e9 + 7;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
    int N;
    cin >> N;
    bool flag = false;
    rep(i,1,10){
        rep(j,1,10){
            if(i*j==N) flag=true;
        }
    }
    if(flag) Yes;
    else No;
}

Measured memory_bytes: 256
#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 int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << 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

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	if((v - w) * t >= abs(b - a)) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}

	return 0;
}

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

int main(){
  int a,b,c;
  
  cin >> a >> b;
  
  c = (a+b+1)/2;
  
  if (1<=a && b<=100){
  cout << c << endl;
  }
  else {
    cout << "error" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=998244353;
const int N=2e5+5;
int main() {
   
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        int n;cin>>n;
        vector<int> a[n+1];
        rep(i,n-1){
        	int x;cin>>x;
        	a[x].pb(i);
        }
        for(int i=1;i<=n;i++){
        	cout<<sz(a[i])<<endl;
        }
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 14548
#include <iostream>

using namespace std;

int main() {
    int n;cin>>n;
    long long ans=0;
    for(int i=1;i<=n;i++){
        if((i%3==0)||(i%5==0)) continue;
        ans+=i;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3600
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(ulong[]);

    size_t i, j;
    ulong res, sum = AS[j], xor = AS[j];
    while (i < N)
    {
        if (sum == xor && j < N)
        {
            if (++j == N)
                continue;
            sum += AS[j];
            xor ^= AS[j];
        }
        else
        {
            res += j - i;
            sum -= AS[i];
            xor ^= AS[i];
            ++i;
        }
    }

    writeln(res);
}


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

int main(){
  int a,b,c,d,e,f,g;
  scanf("%d%d%d",&a,&b,&c);
  d = c / (a*7+b);
  e = c % (a*7+b);
  f = e / a;
  g = e % a;
  if(g == 0){
    printf("%d\n",min(7*d+f,7*(d+1)));
  }
  else{
    printf("%d\n",min(7*d+f+1,7*(d+1)));
  }
}


Measured memory_bytes: 3216
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    string s,t;
    cin >> s >> t;
    ll N = s.size();
    vector<vector<ll>> ch(26,vector<ll>());
    for(int i=0;i<N;i++){
        ch[s[i]-'a'].push_back(i);
    }
    ll ans=0;
    ll pos=0;
    for(int i=0;i<t.size();i++){
        if(ch[t[i]-'a'].size()==0){
            cout << "-1" << endl;
            return 0;
        }
        else{
            ll tmp = lower_bound(ch[t[i]-'a'].begin(),ch[t[i]-'a'].end(),pos) - ch[t[i]-'a'].begin();
            if(tmp==ch[t[i]-'a'].size()){
                ans+=N-pos;
                pos = ch[t[i]-'a'][0]+1;
                ans += pos;
            }
            else{
                ans+=ch[t[i]-'a'][tmp]+1 - pos;
                pos = ch[t[i]-'a'][tmp]+1;
            }
        }
        //cout << ans << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1724
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n == 0) {
			System.out.println("0"); // 解答を見た
		}
		System.out.println(calc(n));
	}
	public static String calc(int num) {
		if (num == 0) {
			return ""; // 桁数が尽きたら終了
		} else if (num%2 == 0) {
			// 割り切れる==このループが担当する桁には役割がない
			return calc(-num/2) + "0";
		} else {
//			return calc(-num/2) + "1"; 誤回答
			// 割り切れない==このループが担当する桁には役割がある
			return calc(-(num-1)/2) + "1"; //
		}
	}
}

Measured memory_bytes: 22868
eval"N,K,*A="+`dd`.split*?,
*s=0;N.times{|i|s<<s[-1]+A[i]}
t=s.combination(2).map{|i,j|j-i}.sort.reverse
b=t[0].bit_length
(b-1).downto(0){|i|
  u=t.select{|x|x[i]>0}
  if u.size>=K
    t=u
  end
}
p t.reduce(:&)

Measured memory_bytes: 19636
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut minus_count = 0;
    let mut abs_sum = 0;
    let mut abs_min = 1i64 << 40;
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<i64>();
        abs_sum += seq[i].abs();
        abs_min = std::cmp::min(abs_min, seq[i].abs());
        if seq[i] < 0 {
            minus_count += 1;
        }
    }
    let ans = if minus_count % 2 == 0 {
        abs_sum
    } else {
        abs_sum - abs_min * 2
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

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



int main(){
    int n;
    cin >> n;
    vector<vector<P>> A(n);
    rep(i,n){
        int a;
        cin >> a;
        rep(j,a){
            int x,y;
            cin >> x >> y;
            x--;
            A[i].emplace_back(x,y);
        }
    }
    ll ans = 0;
    
    rep(is, 1 << n){
        ll cnt = 0;
        vector<int> res(n,0);
        bool isOk = true;
        rep(i,n){
            if(!(is >> i & 1)) continue;
            cnt++;
            res[i] = 1;
        }
        rep(i,n){
            if(!(is >> i & 1)) continue;
            vector<P> t = A[i];
            rep(j,t.size()){
                int f = t[j].first;
                int s = t[j].second;
                if(res[f] != s) isOk = false;
            }
        }
        
        if(isOk) ans = max(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=50+10;
ll K,N;
int main()
{
	scanf("%lld",&K);
	printf("50\n");
	for(register ll i=0;i<50;i++)printf("%lld ",49-i+(49-i+K)/50);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    string num; cin >> num;
    if(num[0] == '9' or num[1] == '9') cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_A
 */
#include <iostream>
#include <sstream>
#include <vector>
#include <limits>

using namespace std;

void
printv(const vector<int> a)
{
    stringstream ss;
    for (auto it = a.cbegin(); it != a.cend(); it++) {
        if (it != a.begin()) {
            ss << ' ';
        }
        ss << *it;
    }
    cout << ss.str() << endl;
}

int
merge(vector<int> &a, const int left, const int mid, const int right)
{
    int n1 = mid - left;
    vector<int> L(n1 + 1);
    for (int i = 0; i < n1; i++) {
        L[i] = a[left + i];
    }
    L[n1] = numeric_limits<int>::max();

    int n2 = right - mid;
    vector<int> R(n2 + 1);
    for (int i = 0; i < n2; i++) {
        R[i] = a[mid + i];
    }
    R[n2] = numeric_limits<int>::max();

    int i = 0;
    int j = 0;
    int count = 0;
    for (int k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            a[k] = L[i++];
        } else {
            a[k] = R[j++];
        }
        count++;
    }

    return count;
}

int
mergeSort(vector<int> &a, const int left, const int right)
{
    if (left + 1 >= right) return 0;

    int count = 0;
    int mid = (left + right) / 2;
    count += mergeSort(a, left, mid);
    count += mergeSort(a, mid, right);
    count += merge(a, left, mid, right);
    return count;
}

int
main()
{
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n; cin.ignore();

    vector<int> S(n);
    for (int i = 0; i < n; i++) {
        cin >> S[i]; cin.ignore();
    }

    int count = mergeSort(S, 0, S.size());
    printv(S);
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 17316
#include <cstring>
#include <cstdint>
#include <iostream>
#include <string>
#include <memory>
#include <queue>
#include <limits>
#include <list>
#include <utility>
#include <sstream>
#include <random>
using namespace std;

int main() {
	int n;
	cin >> n;
	long long a;
	long long sump0, sump1, summ0, summ1;
	long long ansp = 0, ansm = 0;
	cin >> a;
	if (a == 0) {
		ansp = ansm = 1;
		sump0 = 1;
		summ0 = -1;
	}
	else if (a < 0) {
		ansp += -a + 1;
		sump0 = 1;
		summ0 = a;
	}
	else {
		ansm += a + 1;
		summ0 = -1;
		sump0 = a;
	}
	auto calc = [] (long long a, long long& sum0, long long& sum1, long long& ans){
		sum1 = sum0 + a;
		if (sum1 == 0) {
			++ans;
			sum0 = (sum0 < 0) ? 1 : -1;
		}
		else if (!((sum1 < 0) ^ (sum0 < 0))) {
			ans += std::abs(sum1) + 1;
			sum0 = (sum0 < 0) ? 1 : -1;
		}
		else {
			sum0 = sum1;
		}
	};
	for (int i = 1; i < n; i++)
	{
		cin >> a;
		calc(a, sump0, sump1, ansp);
		calc(a, summ0, summ1, ansm);
	}

	cout << std::min(ansp, ansm);

	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define R register
typedef long long ll;
inline int read(){
	R int x; R bool f; R char c;
	for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');
	for (x=c^'0'; (c=getchar())>='0'&&c<='9'; x=(x<<1)+(x<<3)+(c^'0'));
	return f?-x:x;
}
#define M (1<<18)
#define MN 200005
int T[M<<1],n,q,cost[MN],cnt;
std::vector<int> rang[MN];
inline void rw(int k,int v){for (k+=M; k; k>>=1) if (T[k]<=v) return; else T[k]=v;}
inline int query(int l,int r){
	R int res=0x3f3f3f3f;
	for (l+=M-1,r+=M+1; l^r^1; l>>=1,r>>=1){
		if (~l&1) res=std::min(T[l^1],res);
		if ( r&1) res=std::min(T[r^1],res);
	}return res;
}
int main(){
	n=read();for (R int i=1; i<=n; ++i)
		cost[i]=read()?1:-1,cnt+=(bool)(!(~cost[i]));
	q=read();for (R int i=1,x,y; i<=q; ++i)
		x=read(),y=read(),rang[x].push_back(y);
	memset(T,0x3f,sizeof(T));rw(0,0);
	for (R int i=1; i<=n; ++i){
		for (auto j : rang[i]){
			R int res = T[i+M-1];
			res=std::min(res,query(std::max(i-1,1),j));
			rw(j,res);
		}rw(i,T[i+M-1]+cost[i]);
	}printf("%d\n",T[n+M]+cnt);
	return 0;
}

Measured memory_bytes: 11776
N,M =map(int,input().split())
H = list(map(int,input().split()))
ab = [map(int, input().split()) for _ in range(M)]
a, b = map(list, zip(*ab))

cnt = 0
removeList = []

for i in range(len(a)):
  if (H[a[i]-1] > H[b[i]-1]):
    removeList.append(b[i])
  elif (H[a[i]-1] < H[b[i]-1]):
    removeList.append(a[i])
  else:
    removeList.append(a[i])
    removeList.append(b[i])

set(removeList)
print(N - len(set(removeList)))


Measured memory_bytes: 68272
#include<stdio.h>

int main(void){
    int n,i,cnt;
    scanf("%d",&n);
    int p[n];
    cnt = 0;
    for(i=1; i<=n; i++){
        scanf("%d",&p[i]);
        if(i != p[i]) cnt++;
    }

    if(cnt == 0 || cnt == 2){
        printf("YES\n");
    }else{
        printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
using namespace std ; 
int main(){
	int n , k ; 
	cin>> n >> k ; 
	vector<int> a(n) ; 
	for(int i = 0 ; i < n ; ++i) cin>> a[i] ; 
	sort(a.begin() , a.end()) ; 
	reverse(a.begin() , a.end()) ; 
	ll x = 0 ; 
	for(int i = k ; i < n ; ++i)
	    x+=a[i] ; 
	cout<<x<<endl;
	
	
}



Measured memory_bytes: 1024
//Bismillahhir Rahminir Rohim
    #include<bits/stdc++.h>
    #define dbug printf("I am here\n");
    #define Fast ios_base::sync_with_stdio(false); cin.tie(0);
    #define vs            v.size()
    #define ss             s.size()
    #define be            v.begin(),v.end()
    #define pii             pair<int,int>
    #define ll               long long
    #define pb             push_back
    #define mpp            make_pair
    using namespace std;

    int main(){
    ll int a,b,c,k;
    cin>>a>>b>>k;
   vector<ll int>ar(a+1),arr(b+1);

   ll int v,sum = 0;

    for(int i =1;i<=a;i++){
        cin>>v;
        sum += v;
        ar[i] = sum;
    }
    sum = 0;
    for(int i =1;i<=b;i++){
        cin>>v;
        sum += v;
        arr[i] = sum;
    }

    ll int j = b,ans = 0;

    for(int i=0; i<=a; i++){
        if(ar[i] > k)break;
        while((ar[i]+arr[j]) > k){
                j--;
        }
         ans = max(ans,i+j);
         //cout<<ans<<endl;
    }
    cout<<ans<<endl;

    return 0;
    }


Measured memory_bytes: 6412
# coding:utf-8
s = input()
n = len(s)
b = 0
w = 0

# 文字列パターンを作る
if n % 2 == 0:
    black = '01' * (n // 2)
    white = '10' * (n // 2)
else:
    black = '01' * (n // 2) + '0'
    white = '10' * (n // 2) + '1'

#print(black, white)

for i in range(n):
    if s[i] != black[i]:
        b += 1
    if s[i] != white[i]:
        w += 1

print(min(b, w))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long
#define arena ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main() 
{
    arena
    ll n,k;
    cin>>n>>k;
    ll x=500*n;
    if(x>=k)
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N,A,B,ret;
int solve(int z)
{
	int sum = 0;
	while(z>0)
	{
		sum+=z%10;
		z/=10;
	}
	if(sum>=A && sum<=B)
		return 1;
	return 0;
}
int main()
{

	cin >> N;
	cin >> A >> B;
	for(int i = 1; i <= N; ++i)
	{
		ret+=solve(i)?i:0;
	}
	cout << ret << endl;
}

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

namespace ACLBC_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int K = int.Parse(Console.ReadLine());
            string s = null;
            for (int i = 0; i < K; i++) s += "ACL";
            Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 27448
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i,a,b) for(int i=a;i<=b;i++)
#define g(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout<<"Case #"<<x<<": "
#define op1(x) cout<<"Scenario #"<<x<<": "
#define endl "\n"
using namespace std;
const ll mod = 1000000007;
const ll INF = LLONG_MAX;
const ll NEGINF = LLONG_MIN;
const int N = 18;
const ll MAXN = 1000001;


void solve(int t)
{
	string s;
	cin >> s;
	int n = s.length();

	if (s[n - 1] == 's') s += "es";
	else s += "s";
	cout << s << endl;



}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);




	int t = 1;
	//cin >> t;



	for (int i = 1; i <= t; i++)
	{
		solve(i);

	}
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
vector <int> adj[100005];


int main()
{
    int n, k;
    cin>>n>>k;
    
    int h[n+1];
    for (int i = 1; i<=n; i++)
        cin>>h[i];
        
    int dp[n+1];
    memset (dp, 0, sizeof(dp));
    
    for (int i = 2; i<=n; i++)
    {
        int minm = INT_MAX;
        for (int j = i-1; j>=i-k && j>0; j--)
        {
            minm = min(minm, abs(h[i]-h[j])+dp[j]);
        }
        dp[i] = minm;
        //cout<<dp[i]<<endl;
    }
    cout<<dp[n];
    
    return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int n, k;
int dp1[5005][5005];
int dp2[5005][5005];
int a[5005];

int main() {
    std::ios::sync_with_stdio(false);
    cin >> n >> k;
    inc(i, 0, n) cin >> a[i];
    dp1[0][0] = dp2[n][0] = 1;
    inc(i, 0, n){
        inc(j, 0, k){
            if(!dp1[i][j]) continue;

            dp1[i+1][j] = 1;
            if(j+a[i] < k){
                dp1[i+1][j+a[i]] = 1;
            }
        }
    }
    dec(i, 0, n){
        inc(j, 0, k){
            if(!dp2[i+1][j]) continue;

            dp2[i][j] = 1;
            if(j+a[i] < k){
                dp2[i][j+a[i]] = 1;
            }
        }
    }

    int cnt = 0;
    inc(i, 0, n){
        int rui[5005];
        mset(rui, 0);
        inc(j, 0, k){
            rui[j+1] = rui[j]+dp1[i][j];
        }

        bool f = false;
        inc(j, 0, k){
            if(!dp2[i+1][j]) continue;

            if(rui[k-j]-rui[max(0, k-a[i]-j)] > 0){
                f = true;
            }
        }
        if(!f) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 195968
#include<bits/stdc++.h>
using namespace std;
#define maxn 100100
#define ll long long
int a[maxn];
int n;
ll cal(int val)
{
    ll pre=0;
    ll ret=0;
    for(int i=1;i<=n;++i)
    {
        pre+=a[i];
        if(pre*val<=0)
        {
            ret+=abs(pre-val);
            pre=val;
        }
        val=-val;
    }
    return ret;
}
int main()
{
    scanf("%d",&n);
    long long ans=0;
    long long sum=0;
    for(int i=1;i<=n;++i) scanf("%d",&a[i]);
    ans=min(cal(-1),cal(1));
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long int ncr(long long int n,long long int r)
{
long long int i,s=1,t=1;
for(i=1;i<=r;i++)
{
s=s*(n+1-i);
t=t*i;
}
return s/t;
}
int main()
{
long long int k,l,m=0,n,p=0,i;
string s;
cin>>s;
cin>>k;
l=s.length();
if(k==1)
  n=9;
else if(k==2)
    n=81;
else
    n=729;
if(l<k)
{
cout<<"0"<<endl;
return 0;
}
if(l>k)
{
 m=m+ncr(l-1,k)*n;
}

for(i=0;i<l;i++)
{
if(s[i]>'0'){
p++;
if((l-1-i)>=k-p+1&&p!=1){
 m=m+ncr(l-1-i,k-p+1)*pow(9,k-p+1);
//cout<<"hello1"<<endl;
}
if((l-1-i)>=k-p&&k!=p){
m=m+ncr(l-1-i,k-p)*pow(9,k-p)*(s[i]-'1');
//cout<<"hello2"<<endl;
}
else{
   m=m+(s[i]-'0');
   //cout<<"hello3"<<endl;
}
//cout<<s[i]-'0'<<endl;
if(p==k)
    break;
}
}

cout<<m<<endl;


}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using graph = vector<VI>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n; cin >> n;
    VL a(n); cin >> a;

    ll m = 1, ans = 0;
    FOR(i, 0, n) {
        if (a[i] != m) {
            ans += a[i] / m;
            a[i] %= m;
            if (a[i] == 0) {
                ans--;
                a[i] = 1;
            }
        }
        chmax(m, a[i] + 1);
    }

    cout << ans << "\n";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
vector<int> v,v2;
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
signed main(){
	int n,m,sum=0;
	string s;
	cin>>n>>m>>s;
	f(i,n){
		int z=i;
		for(;s[i+1]=='1'&&i<n;i++){}
		v.push_back(i-z+1);
	}
	for(int i=v.size()-1;i>=0;i--){
		sum+=v[i];
		if(sum>m){
			if(sum==v[i]){
				puts("-1");
				return 0;
			}
			v2.push_back(sum-v[i]);
			i++;
			sum=0;
		}
	}
	v2.push_back(sum);
	for(int i=v2.size()-1;i>=0;i--){
		cout<<v2[i];
		if(i)cout<<" ";
	}
	return 0;
}


Measured memory_bytes: 2676
#pragma GCC optimize(2) 
#include<iostream>
 
using namespace std;
const int mod=998244353;
long long a[100010];
long long n,x;
long long ksm(long long a,long long b){
	long long res=1;
	while(b){
		if(b&1){
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}
 
int main(){
//	ios::sync_with_stdio(0);
//	cin.tie(0),cout.tie(0);
	scanf("%lld",&n);
	int flag=0;
	scanf("%lld",&x);
	int ans=x;
	if(x!=0) flag=1;
	for(int i=1;i<n;i++){
		scanf("%lld",&x);
		a[x]++;
		if(x==0) flag=1;
		if(x>ans){
			ans=x;
		}
	}
	
	if(flag){
		printf("0\n");
	}
	else{
	long long sum=1;
		for(int i=1;i<ans;i++){
			if(a[i]==0){
				flag=1;
				break;
			}
			sum*=ksm(a[i],a[i+1]);
			sum%=mod;
//			cout<<"SUM:"<<sum<<endl;
		}
		if(flag) printf("0\n");
		else printf("%lld\n",sum);
	}
	return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#pragma region
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#pragma endregion


int r, c, k;
char grid[11][1111];
void solve()
{
    cin>>r>>c>>k;
    forn(i, r) forn(j, c) cin>>grid[i][j];

    int ans = (r - 1)*(c - 1);

    forn(bit, 1<< (r-1) )
    {
        bool gd = 1;
        int n = 0;
        vector<int> ord(r, 0);
        for (int i=0;i<r-1;++i)
        {
            if (! ((bit >> i)&1) ) ord[i+1] = ord[i];
            else ord[i+1] = ord[i] + 1, ++n;
        }
        int add = 0;
        vector<int> nums(n+1, 0);
        for(int w = 0; w < c; ++w)
        {
            vector<int> one(n+1, 0);
            bool ok = true;
            for (int h = 0; h < r; ++h)
            {
                one[ord[h]] += grid[h][w] - '0';
                nums[ord[h]] += grid[h][w] - '0';
                if (one[ord[h]] > k) gd = false;
                if (nums[ord[h]] > k) ok = false;
            }
            if (!ok) ++add, nums = one;
        }
        if (gd) ans = min(ans, n + add);
    }
    cout << ans << '\n';
}

signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(22);
    //cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    string s;
    cin >> s;
    int sum = 0;
    ll digit2 = stoll(s);
    ll digit3 = digit2;
    if (digit3 >= 9) {
        digit2 -= 10;
        digit2 /= 10;
        digit2 *= 10;
        digit2 += 9;
        bool replace = false;
        for (auto ss : s)if (ss != '9')replace = true;
        if (replace)for (int i = 1; i < s.size(); i++)s[i] = '0';
        ll digit = stoll(s);
        if (replace)digit--;
        int sum2 = 0;
        int sum3 = 0;
        while (digit > 9) {
            sum += digit % 10;
            digit /= 10;
        }
        while (digit2 > 9) {
            sum2 += digit2 % 10;
            digit2 /= 10;
        }
        while (digit3 > 9) {
            sum3 += digit3 % 10;
            digit3 /= 10;
        }
        cout << max(digit3 + sum3, max(sum + digit, sum2 + digit2)) << endl;
    }
    else cout << digit3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n, in;
	ll ans = 0;
	vi v(100001);
	cin >> n;
	rep(i, n) {
		cin >> in;
		if (in > v.size() - 1) ans++;
		else v[in]++;
	}
	rep(i, v.size()) {
		if (i != v[i] && v[i] != 0) {
			ans += (i < v[i] ? v[i] - i : v[i]);
		}
	}
	cout << ans;
}

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

using namespace std;
const int maxn = 1e3 + 5;
char s[maxn];
int main()
{
    while (cin >> s) {
        int ok = 0;
        for (int i = 0; i <strlen(s) - 1; i++)
            if (s[i] == 'A' && s[i + 1] == 'C')
                ok = 1;
        if (ok)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]

max_A = max(A)
min_A = min(A)

# すべて0の場合
if min_A == max_A == 0:
    print(0)

# Aの要素が0以上の値の場合
elif min_A >= 0:
    print(N - 1)
    for i in range(N - 1):
        print(i + 1, i + 2)

# Aの要素が0以下の値の場合
elif max_A <= 0:
    print(N - 1)
    for i in range(N - 1)[::-1]:
        print(i + 2, i + 1)

# Aの要素が正と負の値が混在する場合
else:
    print(2 * N - 1)
    if abs(max_A) >= abs(min_A):
        index = A.index(max_A)
        for i in range(N):
            print(index + 1, i + 1)
        for i in range(N - 1):
            print(i + 1, i + 2)
    else:
        index = A.index(min_A)
        for i in range(N):
            print(index + 1, i + 1)
        for i in range(N - 1)[::-1]:
            print(i + 2, i + 1)


Measured memory_bytes: 3188