akhauriyash/Code-Regression huggingface dataset:
N = int(input())
count = [[0]*10 for _ in range(10)]
for i in range(1,N+1):
    s = str(i)
    count[int(s[0])][int(s[-1])] += 1
ans = 0
for c in range(1,10):
    for d in range(1,10):
        nA = count[c][d]
        nB = count[d][c]
        ans += nA * nB
print(ans)


Measured memory_bytes: 40300
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>

using namespace std;

int main()
{
  int n, sum, size, ans=0;
  double ave;
  cin >> n;
  vector <long long int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sum = accumulate(a.begin(), a.end(), 0); 
  size = a.size();
  ave = round(double(sum)/size);
  for(int i=0;i<n;i++){
    ans += (a[i]-ave)*(a[i]-ave);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		String s = null;
		
		try {
			String[] sp = scanner.nextLine().split(" ");
			s = sp[0];
		} catch (NumberFormatException e) {
		} catch (NullPointerException e) {
		}
		scanner.close();
		for(int i = 0; i < s.length(); i++) {
			if((i + 1) % 2 == 1) {
				if(s.charAt(i) != 'R' && s.charAt(i) != 'U' && s.charAt(i) != 'D') {
					System.out.println("No");
					return;
				}
			} else {
				if(s.charAt(i) != 'L' && s.charAt(i) != 'U' && s.charAt(i) != 'D') {
					System.out.println("No");
					return;
				}
			}
		}
		
		
	 	System.out.println("Yes");
	}
}

Measured memory_bytes: 24916
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>

using namespace std;

typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef map<int, int> M;
typedef pair<int, int> P;
typedef stack<int> S;
typedef queue<int> Q;

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

    int n;
    unsigned int  a;
    cin >> n;
    int c = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> a;
        while (!(a%2))
        {
            ++c;
            a /= 2;
        }
    }
    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>

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

using namespace std;


int main(){
  long ii,jj,kk;
  vector<int> a;
  multiset<int> s;
  int q,c,x,l,r;

  cin >> q;
  multiset<int>::iterator it;
  multiset<int>::iterator lit,rit;  
  for(ii=0;ii<q;ii++){
    cin >> c >> x;
    if(c == 0){
      s.insert(x);
      cout << s.size() << endl;
    }
    else if(c == 1){
      it = s.find(x);
      if(it != s.end()){
        cout << s.count(x) << endl;
      }
      else{
        cout << 0 << endl;
      }
    }
    else if(c == 2){
      s.erase(x);
    }
    else{
      l = x;
      cin >> r;
      lit = s.lower_bound(l);
      rit = s.lower_bound(r);

      while(lit != rit){
        cout << *lit << endl;
        lit++;
      }
      int cnt=0;
      if(*lit <= r && lit!=s.end()){
        for(jj=0;jj<s.count(r);jj++){
          cout << *lit << endl;
          lit++;
        }

      }
    }
  }
  
  return 0;
}



Measured memory_bytes: 12276
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader sb = new BufferedReader(new InputStreamReader(System.in));

		Integer[] hList = new Integer[10];
		for (int num = 0; num < 10; num++) {
			int h = Integer.parseInt(sb.readLine());
			hList[num] = h;
		}

		Arrays.sort(hList, Collections.reverseOrder());

		for (int rank = 0; rank < 3; rank++) {
			System.out.println(hList[rank]);
		}
	}
}

Measured memory_bytes: 24204
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void) {
	
	string s;
	cin >>s;
	
	int i,ans,len=s.length(),cnt[2]={0};
	for (i=0 ; i<len ; i++) {
		if (s[i]=='0') cnt[0]++;
		if (s[i]=='1') cnt[1]++;
	}
	ans=2*min(cnt[0],cnt[1]);
	
	cout <<ans <<endl;
	
	return 0;
}

Measured memory_bytes: 512
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  _ = int(input())
  A = list(map(int,input().split()))
  
  A = sorted(A,reverse=True)
  print(abs(A[0] - A[_-1]))
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main{
    public static void main(String[] args) throws java.io.IOException{
        Scanner sc = new Scanner(System.in);
        int time = sc.nextInt();
        int hour = time / 3600;
        int minitue = (time%3600)/60;
        int second = time%60;
        System.out.println(hour+":"+minitue+":"+second);
    }
}

Measured memory_bytes: 17160
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,d,x,y,count=0;
  cin>>n>>d;
  while(n--)
  {
    cin>>x>>y;
    if(sqrt(x*x+y*y) <= d)
      count++;
  }
  cout<<count;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    deque<char> S;
    string tmp;
    cin >> tmp;
    int a = tmp.size();
    S.resize(a);
    rep(i, a) S[i] = tmp[i];

    int Q, q, f;
    char c;

    cin >> Q;
    bool rev = 0;
    rep(i, Q) {
        cin >> a;
        if(a == 1)
            rev = !rev;
        else {
            cin >> f >> c;
            if(f - int(rev) == 1) {
                S.push_front(c);
            } else {
                S.push_back(c);
            }
        }
    }
    if(rev) reverse(S.begin(), S.end());
    for(auto a : S) {
        cout << a;
    }
}

Measured memory_bytes: 4024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long k = sc.NextLong();
        long a = sc.NextLong();
        long b = sc.NextLong();

        long answer = 1;

        if (b <= a + 1)
        {
            answer = 1 + k;
            Console.WriteLine(answer);
            return;
        }

        if (k + 1 <= a)
        {
            answer = 1 + k;
            Console.WriteLine(answer);
            return;
        }

        answer += a - 1;
        k -= a - 1;

        answer += (k / 2) * (b - a);
        answer += k % 2;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

PRIME_LENGTH = (10**6 + 1)

prime_list = [[] for _ in range(PRIME_LENGTH)]

for i in range(2, PRIME_LENGTH):
    if not prime_list[i]:
        idx = i
        while (idx < PRIME_LENGTH):
            prime_list[idx].append(i)
            idx += i

vote = [0] * (PRIME_LENGTH)

for a in A:
    for v in prime_list[a]:
        vote[v] += 1

if max(vote) == len(A):
    print("not coprime")
elif sum(map(lambda x: x > 1, vote)) > 0:
    print("setwise coprime")
else:
    print("pairwise coprime")


Measured memory_bytes: 268416
# 高橋君の夏休みはN日間です。夏休みの宿題がM個出されており,i番目の宿題をやるにはAi日間かかります。
# 複数の宿題を同じ日にやることはできず、また、宿題をやる日には遊ぶことができません。
# 夏休み中に全ての宿題を終わらせるとき、最大何日間遊ぶことができますか？
# ただし、夏休み中に全ての宿題を終わらせることができないときは、かわりに -1 を出力してください。


N, M = map(int, input().split())
study_days = map(int, input().split())

# リストにM個の数字を、入力したい
# study_days_list = []
# study_days_list.append(study_days)
# print(study_days_list)

total_study_days = sum(study_days)

answer = (N - total_study_days)

if answer < 0:
    print(-1)
else:
    print(answer)

Measured memory_bytes: 9416
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<lld> vi;
typedef pair<lld,lld> pi;
#define F first
#define S second
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (lld i = a; i < b; i++)
lld a,c,r,j,l,x,y,m,b,n,s,f,q,i,z,p,k,d,t,u,e,g;string s1,s2,s3,s4;
vi v[10000001];
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin>>x>>y;p=0;
  rep(i,x,y+1)
  {
    s1=to_string(i);
    s2=s1;reverse(s1.begin(), s1.end());
    if(s1==s2)
      p++;
  }
  cout<<p;
}

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

int main() {
  int n, k; cin >> n >> k;
  vector <int> arr(n);
  for (auto &m: arr) {
    cin >> m;
  }
  int res = 0;
  sort(arr.begin(),arr.end());
  for (int i = 0; i < k; i++ ) {
    res += arr[i];
  }
  cout << res;
}

Measured memory_bytes: 3616
N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
s = A.max

l, r = 1, s

while l <= r
  m = l + (r - l) / 2
  mk = A.map{|v| (v / (m + 0.0)).ceil - 1}.sum
  # pp [l,r,m,mk]
  if mk > K then
    l = m + 1
  else
    r = m - 1
  end
end

puts l


Measured memory_bytes: 74596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    int r; cin >> r;
    string abc="ABC",agc="AGC",arc="ARC";
    string ans;
    if(r<1200) ans = abc;
    else if(r<2800) ans = arc;
    else ans = agc;
    cout << ans;
}


Measured memory_bytes: 256
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=200005;
const int mod=1e9+7;
int n,m,mn,ans;
char s[maxn],ch;
int f[maxn],sum[maxn],g[maxn][2];

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d%d%s",&n,&m,s);
	ch=s[0];
	int cnt=0;
	mn=INF;
	bool fir=true;
	rep(i,m){
		if(s[i]!=ch){
			if(!cnt)continue;
			if(fir){
				if(cnt%2==0)cnt++;
				mn=min(mn,cnt);
			}
			else{
				if(cnt&1)mn=min(mn,cnt);
			}
			cnt=0;	
			fir=false;
		}
		else cnt++;
	}
	if(mn==INF){
		g[1][0]=1;
		for(int i=2;i<=n;i++){
			g[i][0]=(g[i-1][0]+g[i-1][1])%mod;
			g[i][1]=g[i-1][0];
		}
		ans=(g[n][0]+g[n][1])%mod;
		REP(i,n)g[i][0]=g[i][1]=0;
		g[1][1]=1;
		for(int i=2;i<=n;i++){
			g[i][0]=(g[i-1][0]+g[i-1][1])%mod;
			g[i][1]=g[i-1][0];
		}
		ans=(ans+g[n][0])%mod;
	}
	else{
		if(n&1)ans=0;
		else{
			n/=2;
			mn=(mn+1)/2;
			f[0]=1;sum[0]=1;
			REP(i,n){
				f[i]=(sum[i-1]-(i-mn-1>=0?sum[i-mn-1]:0)+mod)%mod;
				sum[i]=(sum[i-1]+f[i])%mod;
			}
			rep(i,n)if(n-i<=mn)ans=(ans+2LL*(n-i)*f[i]%mod)%mod;
		}
	}
	printf("%d\n",ans);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}
void _main();
int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); return 0;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

void _main(){
  int D;
  cin >> D ;
  cout << "Christmas";
  rep(i,25-D) cout << " Eve";
  cout << "" << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

/*
   AtCoder contest code
   coder : yoichidon
 */

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N+1];
        for(int n=0; n<N; n++) A[n]=sc.nextLong();

        long ans = 0;
        for(int n=0; n<N; n++){
            ans += (A[n]/2);
            if(A[n]%2!=0 && A[n+1]>0){
                A[n+1]--;
                ans++;
            }
        }
        System.out.println(ans);
    }
}


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

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;

int32_t main()
{
    ll n;
    cin>>n;
    ll ans=0;
    for(ll k=5; k<=n; k*=5){
        ll nw=n/k;
        ans+=nw/2;
    }
    if(n%2==1) ans=0;
    cout<<ans<<nl;
    return 0;
}


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

using namespace std;


int main(void){
    unsigned long N, Q;
    string S;
    
    std::cin >> N >> Q;
    std::cin >> S;
    
    std::vector<unsigned long> v;
     unsigned long ret = 0;
     v.push_back(0); 
    
    for(int i=0; i<S.length()-1; ++i){
        if(S[i]=='A' && S[i+1]=='C')
            ret++;
        v.push_back(ret); 
    }
    
    
    unsigned long l, r;
    for(int i=0; i<Q; i++){
        std::cin >> l >> r;
        std::cout << v[r-1] - v[l-1] << std::endl;
    }
    
        
    return 0;
}


Measured memory_bytes: 1908
using System;

namespace AOJ
{
  class Program
  {
    static void Main(string[] args)
    {
      string[] ary = Console.ReadLine().Split(' ');

      int a = int.Parse(ary[0]);
      int b = int.Parse(ary[1]);

      int d, r;
      double f;

      d = a / b;
      r = a % b;

      f = (double)a / b;

      Console.WriteLine("{0} {1} {2:f6}", d, r, f);
    }
  }
}

Measured memory_bytes: 9204
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		vi p(n);
		for(int&m:p) scanf("%d", &m);

		int cur_min=n+1;
		int ans=0;
		for(int&m:p)
		{
			if(cur_min>m)
			{
				cur_min=m;
				ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 1024
from collections import deque
n,m = map(int,input().split())
rootlist = [[] for i in range(n)]
flag = [False for i in range(n)]

for i in range(m):
    a,b= map(int,input().split())
    rootlist[a-1].append(b)
    rootlist[b-1].append(a)

que = deque()
que.append(1)
while len(que) !=0:
    now = que.popleft()
    for room in rootlist[now-1]:
        if flag[room-1] == False:
            flag[room-1] = now
            que.append(room)

print('Yes')
for root in flag[1:]:
    print(root)

Measured memory_bytes: 34920
n , a0 , b0 , c0 , d0 = map(int,input().split())
s = input()

# a < b に変換する
if a0 > b0 : # 入れ替える
    a = b0
    b = a0
    c = d0
    d = c0
else : # 入れ替えない
    a = a0
    b = b0
    c = c0
    d = d0

right = max(c,d)
left = min(a,b)
middle = max(a,b)

for i in range(n-1) :
    if s[i] == '#' and s[i+1] == '#' : # 岩が2個連続である場合
        if i <= right - 2 and i >= left - 1 :
            print('No')
            break
else :
    if c < d :
        print('Yes')
    else :
        for i in range(n-2) :
            if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.' : # 入れ替え可能
                if i + 1 == b - 1 :
                    print('Yes')
                    break
                if i <= d - 2 and i >= b - 1 :
                    print('Yes')
                    break
        else :
            print('No')


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


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

    vector<int> s(N);
    REP(i,N) cin >> s[i];

    sort(ALL(s));
    ll sums = accumulate(ALL(s),0LL);

    REP(i,N) {
        if (sums%10 != 0) {
            cout << sums << endl;
            return 0;
        }
        if (s[i]%10 != 0) sums -= s[i];
    }

    cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define int long long
#define swap(x,y) (x^=y^=x^=y)

#define debug1(a) cerr<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cerr<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

using namespace std;
 
#define mod 1000000007
long long modexpo(long long x, long long p){
    int res = 1;x = x%mod;
    while(p){
        if(p%2)res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

struct compare{
    bool operator() (const pair<int,int> a, const pair<int,int> b) const{
        return a.first < b.first;
    }
};

int32_t main(){
    IOS
    int n;
    cin >> n;
    int arr[n+1];
    int brr[n];
    for(int i = 0; i <= n; i++){
        cin >> arr[i];
    } 
    for(int i = 0; i < n; i++){
        cin >> brr[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        int x = min(brr[i], arr[i]);
        int left = brr[i] - x;
        ans += x;
        int y = min(arr[i+1], left);
        arr[i+1] -= y;
        ans += y;
    }
    cout << ans << "\n";
} 

Measured memory_bytes: 5136
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int main()
{
	ll N, ans = 0;
	cin >> N;
	for (ll i = 2, M = N; i * i <= M; i++)
	{
		if (N % i == 0)
		{
			ll z = i;
			while (N % z == 0)
			{
				ans++;
				N /= z;
				z *= i;
			}
			while (N % i == 0)
				N /= i;
		}
	}
	if (N != 1)
		ans++;
	cout << ans << "\n";
}

Measured memory_bytes: 3612
import java.util.*;
import java.lang.*;
import java.io.*;
 
class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
    	//  W <= 300
    	char[] sh = "##############################################################################################################################################################################################################################################################################################################"
    		.toCharArray();
    	char[] dt = ".............................................................................................................................................................................................................................................................................................................."
    		.toCharArray();
        String u, nl = System.getProperty("line.separator");
        StringBuilder
            p = new StringBuilder(1000),
            k = new StringBuilder(100);
        Scanner r = new Scanner(System.in);
        int h, w;
        while (0 != ((h = r.nextInt()) | (w = r.nextInt()))) {
            p.append(sh, 0, w).append(nl);
            k.setLength(0);
            k.append(dt, 0, w).append(nl)
            .replace(0, 1, "#").replace(w - 1, w, "#");
            while (2 != h--) {
                p.append(k);
            }
            p.append(sh, 0, w).append(nl).append(nl);
        }
        System.out.print(p);
    }
}

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

namespace _0029
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> strList = new List<string>();
            int wordCount = 0;
            strList = Console.ReadLine().Split(' ').ToList();
            var strList1 = strList.GroupBy(x => x);
            string modeword = "";
            int strLength = 0;
            string longestStr = "";
            foreach (var item in strList1)
            {
                if (wordCount < item.Count())
                {
                    wordCount = item.Count();
                    modeword = item.Key;
                }
            }
            foreach(var item in strList)
            {
                if (strLength < item.Length)
                {
                    strLength = item.Length;
                    longestStr = item;
                }
            }
            Console.WriteLine(modeword + " "+ longestStr);
        }
    }
}



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

const int N = 201000;

int n;
long long X, a[N], s[N];

int main(void) {
  scanf("%d%lld", &n, &X);
  for(int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    s[i] = s[i - 1] + a[i];
  }
  __int128 Ans = s[n] * 5 + n * X;
  for(int i = 1; i <= n; i++) {
    __int128 now = 0;
    int num = n / i, res = n % i, j, tmp = 2 * num + 3;
    now += s[res] * tmp; tmp -= 2;
    for(j = res; j < n; j += i, tmp -= 2)
      now += (s[min(j + i, n)] - s[j]) * max(tmp, 5);
    Ans = min(Ans, now + i * X);
  }
  printf("%lld\n", Ans + n * X);
}


Measured memory_bytes: 3328
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long w = sc.nextLong();
		if(h==1||w==1) {
			System.out.println(1);
			return;
		}
		
		long ans = (h*w+1)/2;
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 35848
N, C = map(int, input().split())
TV = [list(map(int, input().split())) for _ in range(N)]

TV = sorted(TV, key=lambda x: x[1])

rec = [0] * (10 ** 5 + 1)
cs =  [set() for _ in range(10 ** 5 + 1)]

for s, t, c in TV:
    rec[t] -= 1
    if c not in cs[s]:
        rec[s - 1] += 1
    else:
        rec[s] += 1
    cs[t].add(c)

rec_s = [rec[0]]
for r in rec[1:]:
    rec_s.append(rec_s[-1] + r)

print(max(rec_s))

Measured memory_bytes: 53460
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

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

int main(){
  int elaps = 0,c;
  int i,q;
  P u;
  scanf("%d %d", &n,&q);

  for( i = 1;i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  head = 1;
  tail = n + 1;

  while( head != tail){
    u = dequeue();
    c = min(q,u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }

  return 0;
}



Measured memory_bytes: 11864
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
using ll = long long;

int main() {
    int A, B, C;
    std::cin >> A >> B >> C;
    if (A + B >= C) {
        std::cout << "Yes" << std::endl;
    }
    else {
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 256
import sys

MOD = 998244353

class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )

    def make_combination(n):
        fact = [1, 1]
        factinv = [1, 1]
        inv = [0, 1]

        for i in range(2, n+1):
            fact.append((fact[-1] * i) % MOD)
            inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
            factinv.append((factinv[-1] * inv[-1]) % MOD)

        comb = [0 for _ in range(n+1)]
        for r in range(n+1):
            comb[r] = fact[n] * factinv[r] * factinv[n-r] % MOD

        return list(map(ModInt, comb))

input = sys.stdin.readline

N, M, K = map(int, input().split())
comb = ModInt.make_combination(N-1)

ans = 0

for x in range(K+1):
    ans += comb[x]*M*pow(M-1, N-x-1, MOD)

print(ans)


Measured memory_bytes: 128780
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);

const int MAX=200010;


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

    vector<int> c(3);
    int k;
    rep(i,3) cin >> c[i];
    cin >> k;
    vector<vector<ll>> a(3);
    rep(i,3) {
        rep(j,c[i]) {
            ll x;
            cin >> x;
            a[i].push_back(x);
        }
        sort(a[i].begin(),a[i].end(),greater<>());
    }
    vector<ll> s(c[0]*c[1]);
    rep(i,c[0]) {
        rep(j,c[1]) s[i*c[1]+j]=a[0][i]+a[1][j];
    }
    sort(s.begin(),s.end(),greater<>());
    int m=min(k,c[0]*c[1]);
    vector<ll> t(c[2]*m);
    rep(i,m) {
        rep(j,c[2]) t[i*c[2]+j]=s[i]+a[2][j];
    }
    sort(t.begin(),t.end(),greater<>());

    rep(i,k) cout << t[i] << endl;
    
    return 0;
}


Measured memory_bytes: 34620
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
-- import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

solve :: Int -> [Int] -> Int
solve bN as = cost
  where
  vA = VU.fromListN bN as
  acc = VU.scanl' (+) 0 vA

  enc (len,i) = len * bN + i
  size = bN*(bN+1)
  cost = buildVec VU.! (enc (bN,0))

  buildVec = VU.create $ do
    vec <- VUM.replicate size (-1)
    calc vec (bN,0)
    return vec
    where
      calc vec (1,_) = return 0
      calc vec (len,i) = do
        val <- VUM.read vec (enc (len,i))
        if val >= 0 then return val
          else do
          newVal <- top <$> minimumM (map f [1 .. len-1])
          VUM.write vec (enc (len,i)) newVal
          return newVal
        where
          top v = v + (acc VU.! (i+len)) - (acc VU.! i)
          f k = (+) <$> calc vec (k, i) <*> calc vec (len-k, i+k)

minimumM :: (Monad m, Ord a) => [m a] -> m a
minimumM [] = error "list is empty for minimumM"
minimumM (x:xs) = x >>= sub xs
  where sub [] p     = return p
        sub (x:xs) p = do
          q <- x
          sub xs (min p q) 


readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_bN]:remLines1 = remLines0
      bN = readBInt bs_bN
      line2:remLines2 = remLines1
      as = map readBInt line2
  in solve bN as

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents

-------------------------------------------------------------------------------

inp1 = "4\n10 20 30 40\n"
inp2 = "5\n10 10 10 10 10\n"
inp3 = "3\n1000000000 1000000000 1000000000\n"
inp4 = "6\n7 6 8 6 1 1\n"
tv1 = tmain $ B.pack inp1
tv2 = tmain $ B.pack inp2
tv3 = tmain $ B.pack inp3
tv4 = tmain $ B.pack inp4
test1 = tv1 == 190
test2 = tv2 == 120
test3 = tv3 == 5000000000
test4 = tv4 == 68
alltest = test1 && test2 && test3 && test4



Measured memory_bytes: 5500
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>

int d()
{
    int n;
    std::cin >> n;
    
    std::vector<int> num(n);
    std::vector<int> count(n, 0);
    for(int i = 0; i < n; i++)
    {
        int temp;
        std::cin >> temp;
        num[i] = temp;
        count[temp - 1]++;
    }
    
    std::vector<long long> other(n, 0);
    std::vector<long long> self(n, 0);
    for(int i = 0; i < n; i++)
    {
        long long temp = count[i];
        
        if(temp <= 1)
        {
            other[i] = 0;
            self[i] = 0;
        }
        else if(temp == 2)
        {
            other[i] = 1;
            self[i] = 0;
        }
        else
        {
            other[i] = (temp * (temp - 1)) / 2;
            self[i] = ((temp - 1) * (temp - 2)) / 2;
        }
    }
    
    long long totalCount = 0;
    for(int i = 0; i < n; i++)
    {
        totalCount += other[i];
    }
    
    std::vector<long long> ans(n);
    for(int i = 0; i < n; i++)
    {
        ans[i] = totalCount - other[i] + self[i];
    }
    
    for(int i = 0; i < n; i++)
    {
        int myNum = num[i] - 1;
        std::cout << ans[myNum] << std::endl;
    }
    
    return 0;
}


int main(int argc, const char * argv[])
{
    d();
    return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
int a,b,flag = 1,i,j;
string s;

cin >> a >> b >> s;

if(s[a] != '-'){
  flag = 0;
}

for(i = 0;i < a;i++){
  if(s[i] >= '0' && s[i] <= '9'){

  }
  else{
    flag = 0;
  }
}

for(j = 1;j < b;j++){
  if(s[a + j] >= '0' && s[a + j] <= '9'){
    
  }
  else{
    flag = 0;
  }
}

if(flag){
  cout << "Yes" << endl;
}
else{
  cout << "No" << endl;
}

  return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var Nums = InputNumList();
            var N = Nums[0];
            var K = Nums[1];
            var Hs = InputNumList();

            int HsCount = Hs.Count();
            if (K >= HsCount)
            {
                WriteLine(0);
                return;
            }

            Hs.Sort();
            long Ans = 0;
            for (int i = 0; i < Hs.Count - K; i++)
            {
                Ans += Hs[i];
            }
            WriteLine(Ans);
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main()
{
	vector<int> ans_list;
	while (1)
	{
		int m;
		cin >> m;
		int n_min, n_max;
		if (m == 0)
			break;
		cin >> n_min >> n_max;
		n_min--;
		n_max--;
		vector<int> p(m);
		for (int i = 0; i < m; i++)
		{
			cin >> p[i];
		}
		sort(p.begin(), p.end(), greater<int>());
		int ans = 0, gap = 0;
		for (int i = n_min; i <= n_max; i++)
		{
			if (gap <= p[i] - p[i + 1])
			{
				gap = p[i] - p[i + 1];
				ans = i + 1;
			}
		}
		ans_list.push_back(ans);
	}
	for (int i = 0; i < ans_list.size(); i++)
		cout << ans_list[i] << endl;

	return 0;
}


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

int main(){
	int N ;
	cin>>N;
	vector<int> p(N);
	vector<int> q(N);
	for (int i = 0; i<N;i++){
		cin>>p.at(i);
	}
	q =p;
	sort(q.begin(),q.end());
	int flag = 0;
	for (int i = 0;i<N;i++){
		if (p.at(i)!=q.at(i)){
			flag+=1;
		}
	}

	if (flag == 0 ||flag==2){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}


Measured memory_bytes: 256
#import numpy as np

#T= str(input())
K = int(input())
#A,B,M= map(int,input().split())
#A = list(map(int,input().split()))
#B = list(map(int,input().split()))
S= str(input())

if len(S)<=K:
    print(S)
else:
    S=S[:K]+'...'
    print(S)


Measured memory_bytes: 9152
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall


def next_locations(maze, H, W, i, j):
    if maze[i][j] == '#':
        return list()
    locations = list()
    if i - 1 >= 0 and maze[i - 1][j] == '.':
        locations.append((i - 1, j))
    if i + 1 < H and maze[i + 1][j] == '.':
        locations.append((i + 1, j))
    if j - 1 >= 0 and maze[i][j - 1] == '.':
        locations.append((i, j - 1))
    if j + 1 < W and maze[i][j + 1] == '.':
        locations.append((i, j + 1))
    return locations


def location_to_index(W, i, j):
    return W * i + j


def main():
    H, W = list(map(int, input().split(' ')))
    INF = H * W
    maze = list()
    for _ in range(H):
        maze.append(input())
    d = [[INF for _ in range(H * W)] for _ in range(H * W)]
    for i in range(H):
        for j in range(W):
            from_index = location_to_index(W, i, j)
            locs = next_locations(maze, H, W, i, j)
            for loc in locs:
                to_index = location_to_index(W, loc[0], loc[1])
                d[from_index][to_index] = 1 if from_index != to_index else 0
    d = csgraph_from_dense(d, null_value=INF)
    d = floyd_warshall(d)
    answer = 0
    for from_index in range(H * W):
        for to_index in range(H * W):
            dist = d[from_index][to_index]
            if dist == float('inf'):
                continue
            if dist > answer:
                answer = dist
    print(int(answer))


if __name__ == '__main__':
    main()

Measured memory_bytes: 31740
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    long n, l;
    scan(n, l);
    auto tmp = new string[](n);
    foreach (i; 0 .. n)
    {
        string s;
        s = sread();
        tmp[i] = s;
    }
    // writeln(tmp);
    auto tmp_sort = tmp.sort();
    foreach (i; 0 .. n)
    {
        write(tmp_sort[i]);
    }
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


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

int main(){
  string S;cin >> S;
  int N = S.size();
  for(int i=0;i*2<N;i++){
    if(S[i]!=S[N-1-i]){
      cout << "No" << endl;
      return 0;
    }
  }
  for(int i=0;i*2<(N-1)/2;i++){
    if(S[i]!=S[(N-1)/2-i-1]||S[N-1-i]!=S[(N-1)/2+i+1]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(vec, s) vec.find(s) != vec.end()
#define Set_union(A, B, res) set_union(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_intersection(A, B, res) set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_difference(A, B, res) set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_symmetric_difference(A, B, res) set_symmetric_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));

int main() {
	unsigned int x;
	cin >> x;
	cout << bitset<32>(x) << endl;
	cout << bitset<32>(~x) << endl;
	cout << bitset<32>(x << 1) << endl;
	cout << bitset<32>(x >> 1) << endl;
	return 0;
}


Measured memory_bytes: 3160
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353

n = I()
x = S()
rx=x.replace("1","2").replace("0","1").replace("2","0")
D = []
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        if n // i % 2:
            D += [i]
        if i != n // i and i % 2:
            D += [n // i]

D.sort()
bx=int(x,2)
cnt = [0] * len(D)
ans = 0
for k in range(len(D)):
    t=x[:D[k]]
    rt=rx[:D[k]]
    f=(t+rt)*(n//D[k]//2)+t
    cnt[k]=cnt[k]+int(int(f,2)<=bx)+int(t,2)
    cnt[k]%=mod
    ans += cnt[k]*D[k]*2
    for kk in range(k + 1, len(D)):
        if D[kk] % D[k] == 0:
            cnt[kk] -= cnt[k]
            cnt[kk]%=mod
    ans %= mod

print(ans % mod)


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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(base, fastExp(times(base, base), exp/2));
    }
}

ll choose(ll a, ll b)
{
    ll res = 1LL;
    for(ll i = a; i>=a-b+1; i--)
    {
        res = times(res, i);
    }

    for(ll i = 1; i<= b; i++)
    {
        res = times(res, fastExp(i, MOD-2));
    }
    return res;
}

const int MAXN = (int)1e5+1;
ll N, K, val[MAXN];
ll c[MAXN]; //choose[i] returns (i+K-1)C(K-1);

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> K;
    ll ans = 0;
    for(ll i=0; i<N; i++)
    {
        cin >> val[i];
    }
    sort(val, val+N);
    c[0] = 1LL;
    for(ll i=1; i<=N-K; i++)
    {
        c[i] = times(c[i-1], i+K-1);
        c[i] = times(c[i], fastExp(i, MOD-2));
    }

    for(ll i=N-1; i>=K-1; i--)
    {
        ans = add(ans, times(c[i-K+1], val[i]-val[N-1-i]));
    }
    cout << ans;
    //N-K..N-1
    return 0;
}



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

constexpr int MAX = 500010;

struct Node{
  int key;
  Node* left;
  Node* right;
  Node* p;
};

Node gT[MAX];
Node* gRoot = nullptr;

void Insert( int k ){
  Node* y = nullptr;
  Node* x = gRoot;
  Node* z = new Node;
  z->key = k; z->left = nullptr; z->right = nullptr;
  
  while( x != nullptr ){
    y = x;
    if( z->key < x->key ) x = x->left;
    else                  x = x->right;
  }
  z->p = y;

  if( y == nullptr ){
    gRoot = z;
  }else if( z->key < y->key ){
    y->left = z;
  }else{
    y->right = z;
  }
}

Node* Find( int k ){
  Node* x = gRoot;
  while( x != nullptr ){
    if( k == x->key ) return x;
    if( k < x->key ) x = x->left;
    else x = x->right;
  }
  return nullptr;
}

void Inorder( Node* s ){
  if( s == nullptr ) return;

  Inorder( s->left );
  cout << " " << s->key;
  Inorder( s->right );
}

void Preorder( Node* s ){
  if( s == nullptr ) return;

  cout << " " << s->key;
  Preorder( s->left );
  Preorder( s->right );
}

int main(){
  for( int i = 0; i < MAX; i++ ){
    gT[i].left = gT[i].right = gT[i].p = nullptr;
  }
  
  int m; cin >> m;
  for( int i = 0; i < m; i++ ){
    char cmd[10]; cin >> cmd;
    if( cmd[0] == 'i' ){
      int key; cin >> key;
      Insert( key );
    }else if( cmd[0] == 'p' ){
      Inorder( gRoot ); cout << endl;
      Preorder( gRoot ); cout << endl;
    }else if( cmd[0] == 'f' ){
      int key; cin >> key;
      if( Find( key ) != nullptr ) cout << "yes" << endl;
      else cout << "no" << endl;
    }
  }
}



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


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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

vector<pair<ll,ll>> prime_fact(ll x){
    ll i = 2; 
    vector<pair<ll,ll>> ans;
    while(i*i <= x){
        ll tmp = 0;
        while(x%i == 0){
            tmp++;
            x/=i;
        }
        if(tmp != 0){
            ans.push_back(make_pair(i,tmp));
        }
        i++;
    }
    if(x != 1)ans.push_back(make_pair(x,1));

    return ans;
}

int main(){
    ll N,P;
    cin>>N>>P;
    vector<pair<ll,ll>> a = prime_fact(P);
    ll ans =1;
    rep(i,0,a.size()){
        if(a[i].second >= N){
            rep(j,0,a[i].second/N){
                ans *= a[i].first;
            }
        }    
    }

    cout<<ans;
    return 0;
}

Measured memory_bytes: 3552