akhauriyash/Code-Regression huggingface dataset:
n = int(raw_input())
p = [0 for i in range(0, 101)]
m = [[0 for i in range(0, 101)] for j in range(0, 101)]
for i in range(1, n+1):
    p[i-1], p[i] = map(int, raw_input().split())
     
for l in range(2, n+1):
    for i in range(1, n-l+2):
        j = i+l-1
        m[i][j] = float("inf")
        for k in range(i, j):
            m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j])
 
print m[1][n]

Measured memory_bytes: 6576
import math
import sys
input = sys.stdin.readline
import heapq
def main():
    N,D,A=map(int,input().split())
    xh = [tuple(map(int,input().split())) for _ in range(N)]
    xh = sorted(xh, key = lambda x:x[0])
    x = [elem[0] for elem in xh]
    h = [elem[1] for elem in xh]
    res = 0
    buff = 0
    q = []
    heapq.heapify(q)
    #heapq.heappush(q,x[0])
    for i in range(N):
        while len(q)!=0:
            p = heapq.heappop(q)
            if p[0] < x[i]:
                #buff -= int((p-int(p))*(10**9))
                buff -= p[1]
            else:
                heapq.heappush(q,p)
                break
        nowhp = h[i] - buff*A
        if nowhp <= 0:
            continue
        cnt = math.ceil(nowhp/A)
        res += cnt
        buff += cnt
        #print(cnt,buff)
        ins = (x[i]+2*D, cnt)
        heapq.heappush(q,ins)
    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 102568
#include <bits/stdc++.h>
using namespace std;
 
int main() {

 vector<char> ore(3);
  for(int i=0;i<3;i++){
    cin>>ore.at(i);
  }
 if(ore.at(0)==ore.at(1)&&ore.at(1)==ore.at(2)){
   cout<<"No"<<endl;
 }else{
   cout<<"Yes"<<endl;
 }
}

Measured memory_bytes: 256
import java.util.*;

class Main {

	static List<Long> orthometric = new LinkedList<Long>();
	static Map<Long,List<Integer>> seaLevel = new TreeMap<Long,List<Integer>>();

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int len = sc.nextInt();
			long now = 0l;
			for (int i=0; i<len; i++) {
				long a = sc.nextLong();
				if (a != now) {
					orthometric.add(a);
					if (!seaLevel.containsKey(a)) {
						List<Integer> list = new LinkedList<Integer>();
						list.add(orthometric.size()-1);
						seaLevel.put(a, list);
					} else seaLevel.get(a).add(orthometric.size()-1);
					now = a;
				}
			}
			if (orthometric.size()>0) {
				int max = findLand();
				System.out.println(max);
			} else System.out.println("0");  //全部0だったら
		}
	}

	public static int findLand() {
		int max = 0;
		Long[] oArray = new Long[orthometric.size()];
		orthometric.toArray(oArray);
		int count = 1;
		for (List<Integer> l : seaLevel.values()) {
			for (int i : l) {
				if ((i!=0)&&(i!=oArray.length-1)) {
					if ((oArray[i-1]!=-1)&&(oArray[i+1]!=-1)) count++;
					else if ((oArray[i-1]==-1)&&(oArray[i+1]==-1)) count--;
				} else if ((i==0)&&(i!=oArray.length-1)) {
					if (oArray[i+1]==-1) count--;
				} else if ((i!=0)&&(i==oArray.length-1)) {
					if (oArray[i-1]==-1) count--; 
				}
				oArray[i] = -1l;
			}
			max = Math.max(max, count);
		}
		return max;
	}
}


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

using namespace std;

struct Graph {
    vector<vector<int>> G;
    vector<bool> flag;
    vector<int> dp;

    Graph(int N) {
        G.assign(N+1, vector<int>{});
        flag.assign(N+1, false);
        dp.assign(N+1, 0);
    };

    void make_edge(int u, int v) {
        G[u].push_back(v);
    }

    void make_twoedge(int u, int v) {
        G[u].push_back(v);
        G[v].push_back(u);
    }

    // uを始点とする最長経路の長さf(u)
    int f(int u) {
        // dpの値が計算済みのときその値を返す
        if (flag[u] == true) {
            return dp[u];
        }

        flag[u] = true;
        int tmp = 0;
        
        for (auto v : G[u]) {
            tmp = max(tmp, f(v)+1);
        }

        return dp[u] = tmp;
    }
};


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

    int x,y;
    Graph G(N);

    for (int i = 0; i < M; i++) {
        cin >> x >> y;
        G.make_edge(x, y);
    }

    int answer = 0;

    for (int i = 1; i <= N; i++) {
        answer = max(answer, G.f(i));
    }

    cout << answer << endl;
	return 0;
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n,q,ele;
    scanf("%d",&n);
    map<int,int> mp;
    ll sum1=0;
    for (int i=0;i<n;i++)
    {
        scanf("%d",&ele);
        mp[ele]++;
        sum1+=ele;
    }
    scanf("%d",&q);
    int b,c;
    for (int i=0;i<q;i++)
    {
        scanf("%d%d",&b,&c);
        mp[c]=mp[c]+mp[b];
        sum1=sum1-1LL*mp[b]*b+1LL*mp[b]*c;
        printf("%lld\n",sum1);
        mp[b]=0;
    }
    return 0;
}

Measured memory_bytes: 8164
def show(nums):
    for i in range(len(nums)):
        if i!=len(nums)-1:
            print(nums[i],end=' ')
        else:
            print(nums[i])

def bubble_sort(A, N):
    num_exchange = 0
    FLAG = 1
    while FLAG:
        FLAG = 0

        for j in reversed(range(1, N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                num_exchange += 1
                FLAG = 1
    show(A)
    print(num_exchange)

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split(' ')))
    bubble_sort(A, N)




Measured memory_bytes: 5612
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX=101;
bool Visited[MAX]; //??\?????????????¢??????????
vector<int> Adjacency[MAX];
int dTime[MAX]; int fTime[MAX]; //?¢??????°??¶??´????¢?????????¶??´
void dfs(int j,int& clock)
{

    stack<int> S;
    S.push(j);dTime[j]=++clock;
    Visited[j]=true;
    while(!S.empty())
    {
        int p=S.top(); //???????????¶??????
        if(Adjacency[p].size()==0)
        {
            S.pop();
            fTime[p]=++clock;
            continue;
        }
        int i=0;
        if(Adjacency[p].size())
          while(Visited[Adjacency[p][i]]==true)
          {
            i++;
            if(i==Adjacency[p].size()) //???????°??????????????±?????????????
            {
                S.pop();
                fTime[p]=++clock;
                break;
            }
          }
        if(i==Adjacency[p].size()) continue;
        //if founded
        S.push(Adjacency[p][i]); dTime[Adjacency[p][i]]=++clock;
        Visited[Adjacency[p][i]]=true;
    }
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) Visited[i]=false;

    for(int i=1;i<=n;i++)
    {
        int p;cin>>p;
        int num;
        cin>>num;

        for(int j=0;j<num;j++)
        {
            int t;
            cin>>t;
            Adjacency[p].push_back(t);
        }
    }
    int clock=0;
    for(int i=1;i<=n;i++)  //???????????????????????°DFS?£?????????????
    {
        if(Visited[i]==false) dfs(i,clock);
    }
    for(int i=1;i<=n;i++)
        cout<<i<<' '<<dTime[i]<<' '<<fTime[i]<<endl;
}

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

using namespace std;

int dfs(vector<vector<int> > &adj, vector<bool> &used, vector<int> &dp,int v){
	if(used[v]) return dp[v];
	if((int)adj[v].size() == 0){
		dp[v] = 0;
		return dp[v];
	} 
	used[v] = true;
	for(int i = 0; i < adj[v].size(); i++){
		int u = adj[v][i];
		int ret = dfs(adj, used, dp, u);
		dp[v] = max(dp[v], ret + 1);
	}
	return dp[v];
}

int exp(vector<vector<int> > &adj){
	vector<bool> used(adj.size());
	vector<int> dp(adj.size(), INT_MIN);
	for(int i = 0; i < adj.size(); i++){
		if(!used[i]){
			int a = dfs(adj, used, dp, i);
		}
	}
	int ans = INT_MIN;
	for(int i = 0; i < adj.size(); i++) ans = max(ans, dp[i]);
	return ans;
}

int
main(void){
	int n, m; cin >> n >> m;
	vector<vector<int> > adj(n);
	int u, v;
	for(int i = 0; i < m; i++){
		cin >> u >> v;
		--u; --v;
		adj[u].push_back(v);
	}
	cout << exp(adj);
}

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

ll f(ll n){
  if(n<0)return 0;
  switch(n%4){
    case 0:return n;
    case 1:return 1;
    case 2:return n+1;
    case 3:return 0;
  }
}
ll solve(ll a, ll b){
  return f(a-1)^f(b);
}

int main(){
    ll a, b;
    cin >> a >> b;
    
    ll ans = solve(a,b);
    cout << ans << endl;
}

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

int main(){
    vector<int> v;
    int q, op, val;
    scanf("%d", &q);

    for(int i = 0; i < q; i++){
        scanf("%d", &op);
        if(op == 0){
            scanf("%d", &val);
            v.push_back(val);
        }else if(op == 1){
            scanf("%d", &val);
            cout << v[val] << endl;
        }else if(op == 2){
            v.pop_back();
        }
    }

    return 0;
}


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

#define endl "\n"
#define ll long long
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define read(v) for(auto &it:v) cin>>it;
#define out(v) for(auto &it:v) cout<<it<<" ";
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<ll> vll;

#define deb(x) cout << ">" << #x << '=' << x << endl;
#define setbits(n) __builtin_popcountll(n)
#define done {cout<<"-1"<<endl; return;}

#define inf INT_MAX
#define ninf INT_MIN
const ll N = 1e5 + 5;
#define MOD 1000000007

void solve() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = LLONG_MIN;
	if (a <= 0 && b >= 0 || c <= 0 && d >= 0) ans = 0;
	ans = max(ans, a * c);
	ans = max(ans, b * d);
	ans = max(ans, a * d);
	ans = max(ans, b * c);
	cout << ans << endl;



}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("inputc.txt", "r", stdin);
	freopen("outputc.txt", "w", stdout);
#endif
	int t = 1;
	//cin>>t;
	while (t--) solve();
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 3780
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
const int inf = 1012345678;
int dir[] = { 0, 1, 0, -1 };
int H, W, K, sx, sy, d[809][809]; string s[809];
int main() {
	cin >> H >> W >> K;
	for (int i = 0; i < H; i++) cin >> s[i];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == 'S') sx = i, sy = j;
			d[i][j] = inf;
		}
	}
	queue<pair<int, int> > que; que.push(make_pair(sx, sy)); d[sx][sy] = 0;
	int ret = inf;
	while (!que.empty()) {
		pair<int, int> u = que.front(); que.pop();
		int z = min({ u.first, H - u.first - 1, u.second, W - u.second - 1 });
		ret = min(ret, (z + K - 1) / K + 1);
		int r = d[u.first][u.second];
		if (r < K) {
			for (int i = 0; i < 4; i++) {
				int tx = u.first + dir[i], ty = u.second + dir[i ^ 1];
				if (0 <= tx && tx < H && 0 <= ty && ty < W && d[tx][ty] == inf && s[tx][ty] != '#') {
					d[tx][ty] = r + 1;
					que.push(make_pair(tx, ty));
				}
			}
		}
	}
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 3584
import math

n, m = map(int, input().split())
array = []
for i in range(1, int(math.sqrt(m)+1)):
    if m % i == 0:
        array.append([i, m//i])

diff = float("inf")
res = 0
for i, j in array:
    if i >= n:
        res = max(res, j)
    if j >= n:
        res = max(res, i)
print(res)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vvc vector<vector<char> >
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    vvc v(100,vc(100,0));
    int h,w; cin>>h>>w;
    vvi u(100,vi(100,0));
    rep(i,h)rep(j,w)cin>>v[i][j];
    rep(i,h)rep(j,w)u[i][j]=v[i][j]-48;
    rep(i,h)rep(j,w){
        if(i==0&&j!=0)u[i][j]+=u[i][j-1];
        else if(j==0&&i!=0)u[i][j]+=u[i-1][j];
        else if(i==0&&j==0)continue;
        else u[i][j]+=min(u[i-1][j],u[i][j-1]);
    }
    cout<<u[h-1][w-1]<<endl;
}

Measured memory_bytes: 3180
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc =new Scanner(System.in);
		int k = sc.nextInt();
		if(k == 1) {
			System.out.println(1);
			System.out.print(1);
			return;
		}
		int n = 2 * ((k+3)/4);
		int curt = n*2 - k;
		int[][] mat = new int[n][n];
		for(int r=0; r<n; r++) {
			for(int c=0; c<n;c++) {
				if(r%2 == 1 && (r+c)%n < n -curt) {
					mat[r][c] = n + (r+c)%n;
					mat[r][c]++;
				} else {
					mat[r][c] = (r+c)%n;
					mat[r][c]++;
				}
			}
		}
		int rr = 1;
		System.out.println(n);
		for(int[] row: mat) {
			int cc = 1;
			for(int x : row) {
				System.out.print(x);
				if(cc <n) 
					System.out.print(" ");
				cc++;
			}
			if(rr < n)
				System.out.println("");
			rr++;
		}
	}
}

Measured memory_bytes: 56228
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

var mat []map[int]bool
var visited []bool

func dfs(a, cnt int) int {
	if visited[a] {
		return cnt
	}
	visited[a] = true
	cnt++

	for b := range mat[a] {
		cnt = dfs(b, cnt)
	}

	return cnt
}

func main() {
	n, m := readInt(), readInt()
	mat = make([]map[int]bool, n)
	for i := 0; i < m; i++ {
		a, b := readInt()-1, readInt()-1
		if mat[a] == nil {
			mat[a] = make(map[int]bool)
		}
		if mat[b] == nil {
			mat[b] = make(map[int]bool)
		}
		mat[a][b] = true
		mat[b][a] = true
	}

	ans := 0
	visited = make([]bool, n)
	for i := 0; i < n; i++ {
		if visited[i] {
			continue
		}
		ans = max(ans, dfs(i, 0))
	}

	fmt.Println(ans)
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

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

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


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

main(){
	while(true){
		int n;
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		int a[n];
		for(int i=0; i<n; ++i){
			cin >> a[i];
		}
		
		long long maxv = a[0];
		for(int l=0; l<n; ++l){
			long long sumv = 0;
			for(int r=l; r<n; ++r){
				sumv += a[r];
				if(sumv >= maxv){
					maxv = sumv;
				}
			}
		}
		
		cout << maxv << endl;
	}
}


Measured memory_bytes: 3004
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,s;
    scanf("%d%d%d",&n,&k,&s);
    if(s==1000000000)
    {
        for(int i=1;i<=k;i++)
            printf("1000000000 ");
        for(int i=1;i<=n-k;i++)
            printf("1 ");
    }
    else
    {
        for(int i=1;i<=k;i++)
            printf("%d ",s);
        for(int i=1;i<=n-k;i++)
            printf("1000000000 ");
    }
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
#define MAXN 1000005
#define PLI pair<long log,int>
#define fi first
#define se second
#define mp make_pair
#define ha 99994711
#define ba 823
//#define ivorysi
using namespace std;
typedef long long int64;
int N,Lim,dis;
int64 X,D,m[55],cost[55];
int p[55],siz[55],q[125005],id[55];
int64 dp[125005],ans;
int ql,qr;
bool cmp(int a,int b) {
    return siz[a] * cost[b] > siz[b] * cost[a];
}
void update(int64 &x,int64 y) {
    x = min(x,y);
}
void Solve() {
    scanf("%d%lld%lld",&N,&X,&D);
    Lim = N * N * N;
    scanf("%d",&m[1]);
    for(int i = 2 ; i <= N ; ++i) scanf("%d%d",&m[i],&p[i]);
    for(int i = N ; i >= 1 ; --i) {
        cost[i] += m[i];siz[i]++;
        cost[p[i]] += cost[i];siz[p[i]] += siz[i];
        id[i] = i;
    }
    for(int i = 1 ; i <= Lim ; ++i) dp[i] = X + 1;
    sort(id + 1,id + N + 1,cmp);
    dis = min(N,(int)D);
    for(int k = 1 ; k <= N ; ++k) {
        int s =  siz[id[k]];int64 v = cost[id[k]];
        for(int j = 0 ; j < s ; ++j) {
            int T = min((Lim - j)/ s,dis);
            if(id[k] == 1) T = min((Lim - j) / s,N);
            int p = (Lim - j) / s;
            ql = 1,qr = 0;
            for(int i = (Lim - j) / s ; i >= 1 ; --i) {
                while(p >= 0 && i - p <= T) {
                    while(ql <= qr && dp[j + q[qr] * s] - q[qr] * v > dp[j + p * s] - p * v) --qr;      
                    q[++qr] = p;
                    --p;
                }
                while(ql <= qr && q[ql] >= i) ++ql;
                if(ql <= qr) {
                    update(dp[j + i * s],dp[j + q[ql] * s] + (i - q[ql]) * v);
                }
            }
        }
    }
    for(int i = 0 ; i <= Lim ; ++i) {
        int64 T = X - dp[i];
        if(T < 0) continue;
        int64 tmp = i;
        int num;
        for(int k = 1 ; k <= N ; ++k) {
            if(id[k] == 1) num = T;
            else num = D - dis;
            int t = min(T / cost[id[k]],(int64)num);
            tmp += 1LL * t * siz[id[k]];
            T -= t * cost[id[k]];
        }
        ans = max(ans,tmp);
    }
    printf("%lld\n",ans);
}
int main() {
    Solve();
    return 0;
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	ll n, x, m;
	cin >> n >> x >> m;

	vector<ll> nms({x});
	map<ll, int> mp;
	mp[x] = 0;

	while(1) {
		x = x * x % m;
		if(mp.count(x))
			break;
		mp[x] = nms.size();
		nms.push_back(x);
	}

	if(n <= nms.size()) {
		cout << accumulate(nms.begin(), nms.begin() + n, 0LL) << '\n'; return 0;
	}

	int w = mp[x];
	ll tmp = accumulate(nms.begin(), nms.begin() + w, 0LL);
	n -= w;
	ll cycsz = int(nms.size()) - w;
	ll tot = accumulate(nms.begin() + w, nms.end(), 0LL);
	ll ende = accumulate(nms.begin() + w, nms.begin() + w + n % cycsz, 0LL);
	cout << (n / cycsz) * tot + ende + tmp << '\n';
}



Measured memory_bytes: 6720
#include<bits/stdc++.h>
using namespace std;
#define rep(i, c) for(ll i = 0; i < (ll)c; i++)
#define ll long long
const int inf = 1000000000; // 10^9

int main(){
    ll k, i = 0, now;
    cin >> k;
    queue<ll> q;
    for(int j = 1; j < 10; j++) q.push(j);

    if(k == 1) cout << 1 << endl;

    else{
        while(k - 1 > i)
        {
            now = q.front();
            q.pop();
            i++;
            if(now % 10 != 0) q.push(10 * now + now%10 - 1);
            q.push(10 * now + now%10);
            if(now % 10 != 9) q.push(10 * now + now%10 + 1);
        }
        cout << q.front() << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <limits>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define lli long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define um unordered_map
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define mem(data_structure, val) memset(data_structure, val, sizeof(data_structure))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl "\n"
const ll mod = 1e9+7;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 
um<pii, int, hash_pair> map_with_pair{};
priority_queue <int, vector<int>, greater<int> > pq_desc; // decreasing order

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	lli n;
	cin >> n;
	lli a[n];
	lli left[n], right[n];
	left[0] = right[n-1] = -1;
	fo(i, n) cin >> a[i];
	Fo(i, 1, n) left[i] = max(left[i-1], a[i-1]);
	Fo(i, n-2, -1) right[i] = max(right[i+1], a[i+1]);
	fo(i, n) cout << max(left[i], right[i]) << endl;
 
	return 0;
}

Measured memory_bytes: 6272
def run():
	X, N = [int(v) for v in input().rstrip().split()]
	p = []
	if N > 0:
		p = [int(v) for v in input().rstrip().split()]

	i = -1
	try:
		i = p.index(X)
	except ValueError:
		pass

	if i == -1:
		# not contained	
		return X

	d1 = {}
	for k in range(0, 102):
		d1[k] = k

	for v in p:
		del d1[v]

	l2 = sorted(list(d1.keys()))

	l2.append(X)
	l2.sort()
	i = l2.index(X)

	r = 0
	if i == 0:
		r = l2[1]
	elif (i + 1) == len(l2):
		r = l2[-2]
	else:
		v1 = l2[i + 1] - X
		v2 = X - l2[i - 1]
		if v1 < v2 :
			r = l2[i + 1]
		elif v1 > v2 :
			r = l2[i - 1]
		else:
			# v1 == v2
			r = l2[i - 1]


	return r

r = run()
print(r)



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

using namespace std;

int main(){
	char d[50];
	string s, t, m = "", cur;
	getline(cin, s);
	getline(cin, t);
	int c = 0;
	for(string::iterator it = s.begin(); it != s.end(); it++){
		d[c] = *it;
		c++;
	}
	bool valid;
	int tz = t.size();
	for(int i = 0; i < c; i++){
		if(c - i >= tz){
			cur = "";
			valid = true;
			for(int j = 0; j < i; j++)
				cur += d[j];
			for(int j = i; j < c; j++){
				if(d[j] == '?' || j - i >= tz || d[j] == t[j - i]){
					if(j - i < tz)
						cur += t[j - i];
					else if(d[j] == '?')						
						cur += 'a';
					else
						cur += d[j];
				}
				else{
					valid = false;
					break;
				}
			}
			if(valid){
				if(m == "")
					m = cur;
				else if(m > cur)
					m = cur;
			}
		}
		if(d[i] == '?')
			d[i] = 'a';
	}	
	cout << (m == "" ? "UNRESTORABLE" : m);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
         
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
         
        System.out.println((a*b) + " " + (2*(a+b)) );
    }
}


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

using namespace std;

const long long mod = 1e9 + 7ll ;
const int N = 21 ;
const int MAX = 1ll << N ;
long long dp[N][MAX] ;
int arr[N][N] ;
int n ;

long long solve(int idx , int mask)
{
    if(idx == n)
    {
        if(mask == (1 << n)-1)
            return 1 ;
        return 0 ;
    }
    long long &ret = dp[idx][mask] ;
    if(ret != -1)
        return ret ;
    ret = 0 ;
    for(int j = 0 ; j < n ; ++j)
    {
        if(arr[idx][j] == 1 && ((mask & (1 << j)) == 0))
            ret = (ret + solve(idx+1 , mask | (1ll << j))) % mod ;
    }
    ret = (ret % mod) ;
    return ret ;
}

int main()
{
    memset(dp , -1 , sizeof(dp));
    scanf("%d" , &n);
    for(int i = 0 ; i < n ; ++i)
    {
        for(int j = 0 ; j < n ; ++j)
            scanf("%d" , &arr[i][j]);
    }
    return printf("%lld\n" , solve(0 , 0)) , 0 ;
}


Measured memory_bytes: 344320
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <numeric>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
/*
bool ok(vector<int>& L, int X){
  int idx = L.size();
  int first = 0;
  while(true){
    int cnt = 1;
    int now = first;
    bool ok = true;
    REP(i, idx){
      if(now + L[i] <= X){
        now += L[i];
      }else{
        now = L[i];
        cnt++;
      }
      if(cnt > M || now > X){
        ok = false;
        break;
      }
    }
    if(ok) return true;

    idx--;
    assert(idx >= 0);
    first += L[idx];
    if(first > X) break;
  }
  return false;
}
*/
int N, M;
vector<int> L;
bool ok(int X){
  REP(i, N) if(L[i] > X) return false;

  int firstsum = 0;
  for(int b = 0; b < N; b++){
    if(firstsum > X) break;
    int rest = M - 1;
    int partial = 0;
    for(int i = b; i < N; i++){
      if(partial + L[i] > X){
        partial = L[i];
        assert(partial <= X);
        rest --;
      }else{
        partial += L[i];
      }
    }
    //printf("rest = %d partial = %d firstsum = %d X = %d\n", rest, partial, firstsum, X);
    if(rest >= 0 && partial + firstsum <= X) return true;

    firstsum += L[b];
  }
  return false;
}

int main(){
  while(cin>>N>>M && N){
    L.assign(N, 0);
    REP(i, N) scanf("%d", &L[i]);
    int S = accumulate(L.begin(), L.end(), 0);
    int lb = ceil(double(S) / M) - 1;
    int ub = S;
    while(ub - lb > 1){
      int mid = (ub + lb) / 2;
      if(ok(mid)){
        ub = mid;
      }else{
        lb = mid;
      }
    }
    cout<<ub<<endl;
  }
  return 0;
}

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

const int maxn=3e5+5;

char s[maxn];
char ans[maxn];

struct node
{
    char a;
    bool dir;
    int id;
    int pre;
}point[maxn];

int cnt1,cnt2,n;
int t,f;
char c;

bool cmp(node a,node b)
{
    if(a.dir!=b.dir)
        return a.dir>b.dir;
    if(a.dir==1&&b.dir==1)
        return a.id>b.id;
    if(a.dir==0&&b.dir==0)
        return a.id<b.id;
}

void reverse(char s[],int length)
{
    int l=length/2;
    char c;
    for(int i=0;i<l;i++)
    {
        c=s[i];
        s[i]=s[length-1-i];
        s[length-1-i]=c;
    }
}

using namespace std;

int main()
{
    scanf("%s",s);
    int length=strlen(s);
    int flag1=1;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&t);
        if(t==1)
            cnt1++;
        else if(t==2)
        {
            cnt2++;
            cin>>f>>c;
            point[cnt2].id=cnt2;
            point[cnt2].a=c;
            point[cnt2].pre=cnt1;
            if(f==1)
                point[cnt2].dir=1;
            else
                point[cnt2].dir=0;
        }
    }

    if(cnt1%2)
        reverse(s,length);
    for(int i=1;i<=cnt2;i++)
    {
        if((cnt1-point[i].pre)%2)
            point[i].dir=!point[i].dir;
        else
            continue;
    }
    sort(point+1,point+cnt2+1,cmp);
        //for(int i=1;i<=cnt2;i++)
       // printf("%c %d %d %d\n",point[i].a,point[i].id,point[i].dir,point[i].pre);

    int k=0,j=0,sum=1;
    for(int i=1;i<=cnt2;i++)
    {
        if(point[i].dir==1)
            ans[k++]=point[i].a;
        else
        {
            if(flag1)
            {
                while(j<length)
                    ans[k++]=s[j++];
                flag1=0;
            }
            ans[k++]=point[i].a;
        }
    }
    if(flag1)
        while(j<length)
            ans[k++]=s[j++];
    ans[k]='\n';
    printf("%s\n",ans);
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int n,m; cin >> n >> m;
  std::cout << (100*n+1800*m)*pow(2,m) << '\n';
}


Measured memory_bytes: 256
/**
  @file c.cpp
  @title C - Alchemist
  @url https://atcoder.jp/contests/abc138/tasks/abc138_c
**/

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

typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)

int main() {
  int N;
  cin >> N;
  vector<double> v(N, 0);

  REP(i, N) {
    cin >> v[i];
  }
  sort(ALL(v));

  if (N == 2) {
    cout << (v[0] + v[1]) / 2 << endl;
  } else {
    for (int i = 0; i < N - 1; i++) {
      double ave = (v[0] + v[1]) / 2;
      v.erase(v.begin());
      v.erase(v.begin());
      v.insert(v.begin(), ave);
    }

    cout << v[0] << endl;
  }

  return 0;
}


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

using namespace std;

const int DIM = 1e5 + 7;

int dp[DIM][3];

main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	 int n, k;
	 int r, s, p;
	 string v;
	 cin >> n >> k >> r >> s >> p >> v;
	 
	 v = ' ' + v;
	 
	 for(int i = 1; i <= n; i++)
	 {
		 if(v[i] == 'r')
		 {
			 int pos = max(0, i - k);
			 
			 dp[i][0] = max(dp[pos][1], dp[pos][2]);
			 dp[i][1] = max(dp[pos][0], dp[pos][2]);
			 dp[i][2] = max(dp[pos][0], dp[pos][1]) + p;
		 }
		 
		 if(v[i] == 's')
		 {
			 int pos = max(0, i - k);
			 
			 dp[i][0] = max(dp[pos][1], dp[pos][2]) + r;
			 dp[i][1] = max(dp[pos][0], dp[pos][2]);
			 dp[i][2] = max(dp[pos][0], dp[pos][1]);
		 }
		 
		 if(v[i] == 'p')
		 {
			 int pos = max(0, i - k);
			 
			dp[i][0] = max(dp[pos][1], dp[pos][2]);
			dp[i][1] = max(dp[pos][0], dp[pos][2]) + s;
			dp[i][2] = max(dp[pos][0], dp[pos][1]);
		 }
	 }
	 
	 int res = 0;
	 
	 for(int i = max(n - k + 1, 1); i <= n; i++)
		 res += max({dp[i][0], dp[i][1], dp[i][2]});
		
	cout << res;
}

Measured memory_bytes: 1664
def main():
    from collections import deque
    from functools import cmp_to_key
    
    N, W, *A = map(int, open(0).read().split())
    A = [list(a) for a in zip(*[iter(A)]*3)]

    Vmax = max(v for v, w, m in A)
    Vsum = 0
    B = []
    for i, (v, w, m) in enumerate(A):
        m_upper = min(m, Vmax-1)
        m_rest = m - m_upper
        A[i][2] = m_upper
        if m_rest:
            B.append((v, w, m_rest))
        Vsum += v*m_upper

    INF = 1<<60
    dp = [INF]*(Vsum+1)
    dp[0] = 0

    for v, w, m in A:
        for ofs in range(v):
            q = deque()
            for j in range(Vsum+1):
                vj = ofs + j*v
                if vj > Vsum:
                    break
                src = dp[vj] - j*w
                while q and q[-1][1] >= src:
                    q.pop()
                q.append((j, src))

                if q:
                    ni, nw = q[0]
                    dp[vj] = nw + j*w
                    if ni == j - m:
                        q.popleft()
    
    B.sort(key=cmp_to_key(lambda a, b: -1 if a[0]*b[1] > a[1]*b[0] else 1))

    ans = 0
    for V, d in enumerate(dp):
        if d > W:
            continue
        W_rest = W - d
        for v, w, m in B:
            n_item = min(m, W_rest//w)
            if n_item:
                V += n_item * v
                W_rest -= n_item * w
        if ans < V:
            ans = V

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 13252
N = int(input())
A = list(map(int, input().split()))

import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)

tmp = [0 for i in range(N + 1)]

for i in range(N):
    tmp[i+1] = tmp[i] + A[i]
    


dic = {}
for i in range(N + 1):
    if tmp[i] in dic:
        dic[tmp[i]] += 1
    else:
        dic[tmp[i]] = 1
       
res = 0
for i in dic:
    if dic[i] > 1:
        res += C(dic[i], 2)
        
print(res)

Measured memory_bytes: 111620
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define END puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     return p.first>q.first;
//     return p.first<q.first;
//     return p.second>q.second;
//     return p.second<q.second;
// }

// bool cmp(int p,int q) {
//     return p>q;
//     return p<q;
// }

int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    string s,t;
    cin>>s>>t;
    int n=s.size();
    int count=0;
    f1(i,n) {
        if(s[i]!=t[i])++count;
    }

    cout<<count<<endl;

    return 0;
}

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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

typedef vector<vector<int> > vvi;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 52, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

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

void add(int &x, int y) {
	x += y;
	if (x >= MOD) x -= MOD;
}

vvi mult(vvi a, vvi b) {
	vvi ret(N, vector<int>(N, 0));
	for (int i = 1; i < N; i++) {
		for (int j = 1; j < N; j++) {
			for (int k = 1; k < N; k++) {
				add(ret[i][j], (a[i][k] * 1ll * b[k][j]) % MOD);
			}
		}
	}
	return ret;
}

vvi bin_pow(vvi a, ll k) {
	vvi ret(N, vector<int>(N, 0));
	for (int i = 0; i < N; i++) ret[i][i] = 1;
	while (k > 0) {
		if (k & 1) {
			ret = mult(ret, a);
			k--;
		}
		a = mult(a, a);
		k /= 2;
	}
	return ret;
}

int main() {
	FREOPEN();
	ll k;
	int n;
	vvi a(N, vector<int>(N, 0));
	scanf("%d %lld", &n, &k);
	for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
	a = bin_pow(a, k);
	int ans = 0;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) add(ans, a[i][j]);
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 384
n, k = map(int, input().split())
s = input()
c = 1
l = []

if s[0] == '0':
    l.append(0)

for i in range(1, n):
    if s[i-1] != s[i]:
        l.append(c)
        c = 1
    else: 
        c +=1
l.append(c)

if s[n-1] == '0':
    l.append(0)

ll = len(l)
pl = 2 * k + 1

if ll <= pl:
    t = 0
    for i in range(ll):
        t += l[i]
    print(t)
else:
    t = 0
    for i in range(0,pl):
      t += l[i]
    m = t
    for i in range(0, ll-pl, 2):
        t += l[pl+i] + l[pl+i+1]
        t -= l[   i] + l[   i+1]
        m = t if (t > m) else m
    print(m)


Measured memory_bytes: 4092
#include<bits/stdc++.h>
#define ll long long
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define pb push_back
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define mod 1000000007
#define f first
#define sec second
#define gcd(x,y) __gcd(x, y)
using namespace std;
int main()
{
	ll n;
	cin>>n;
	if(n>=30)
	yes;
	else
	no;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

ll mod = 1e9+7 ;
const ld error = 1e-8;
const ld PI = acosl(-1); //const ld PI = acosl(-1)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

#define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
#define hoise cerr<<"hoise - "<<__LINE__<<"\n"
#define tham getchar()
//mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count()); //mt199937_64 for ll
//mt19937 rng(199);

inline ll MOD(ll x, ll m = mod){
    ll y = x % m;
    return (y >= 0) ? y: y+m;
}

const int inf = 1e9;
const ll infl = 1e18+1;
const int nmax = 1e5 + 10;
///===========================================  template  =======================================================

int arr[nmax];

int main(){
    FASTIO;
    int n, m;

    cin>>n>>m;

    int sum = 0;
    for(int i = 0; i<n; i++){
        cin>>arr[i];
        sum += arr[i];
    }

    int taken = 0;
    for(int i = 0; i<n; i++){
        if(arr[i] *4 * m >= sum) taken++;
    }

    if(taken >= m) cout<<"Yes";
    else cout<<"No";

    return 0;
}


Measured memory_bytes: 256
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int Mod=998244353;
const int N=4e5+5;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
char s[N];
int n,m,Ans,a[N],b[N],f[N];
int mod(int x){return x>=Mod?x-Mod:x;}
int Solve(int T){
	int L=T/2,ans=0,flag=1;
	for(int i=1;i<=L;i++){ans=mod(ans*2+a[i]);b[i]=a[i];}
	for(int i=L+1;i<=n;i++)b[i]=a[i-L]^1;
	for(int i=1;i<=n;i++){
		if(b[i]<a[i])break;
		if(b[i]>a[i]){flag=0;break;}
	}
	ans=mod(ans+flag);
	return f[T]=ans;
}
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();scanf("%s",s+1);
	for(int i=1;i<=n;i++)a[i]=s[i]-'0';
	for(int i=1;i<=n*2;i++)if(n%i!=0&&n*2%i==0)Solve(i);
	for(int i=1;i<=n*2;i++){
		if(!(n%i!=0&&n*2%i==0))continue;
		for(int j=i*2;j<=n*2;j+=i){
			if(!(n%j!=0&&n*2%j==0))continue;
			f[j]=mod(f[j]-f[i]+Mod);
		}
	}
	for(int i=1;i<=n*2;i++)Ans=mod(Ans+1ll*f[i]*i%Mod);
	printf("%d\n",Ans);
	return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  cin >> a >> b;
  cout << (a - 1) * (b - 1) << endl;
  
  return 0;
}


Measured memory_bytes: 256
var s:string;n,m,i,j:longint;
begin
  readln(s);
  for i:=1 to length(s) do
    begin
      if s[i]='C' then
          for j:=i+1 to length(s) do
               if s[j]='F' then
                 begin
                   writeln('Yes');
                   halt;
                 end;
    end;             
    writeln('No');
end.

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
  int n, a, b;
  scanf("%d %d %d",&n,&a,&b);
  if(n*a<b) printf("%d\n",n*a);
  else printf("%d\n",b);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <cstdio>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

ll gcd(ll a,ll b) { return b ? gcd(b, a%b) : a; }

ll func(ll a,ll b,ll& ans_x,ll& ans_y){
    if(b == 0){
        ans_x = 1;
        ans_y = 0;
        return a;
    }else{
        ll ret = func(b,(a%b),ans_y,ans_x);
        ans_y -= (a/b)*ans_x;
        return ret;
    }
}

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];

ll dp[50010];



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

    string s,t;
    ll ans=0;
    cin>>s>>t;
    rep(i,s.size()){
        if(s[i]!=t[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3884
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
int main(){
  set<Int> st;
  Int a,b,k;cin >> a >> b >> k;
  for(Int i=0;i<k;i++) if(a<=i+a&&i+a<=b) st.insert(i+a);
  for(Int i=0;i<k;i++) if(a<=b-i&&b-i<=b) st.insert(b-i);
  for(auto &i:st) cout << i << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> A >> B >> C >> K;
  Vec(P,lli,A,0);
  Vec(Q,lli,B,0);
  Vec(O,lli,C,0);
  rep(i,0,A)cin >> P[i];
  rep(i,0,B)cin >> Q[i];
  rep(i,0,C)cin >> O[i];
  priority_queue<lli> que;
  Sort(P);Sort(Q);Sort(O);
  Rev(P);Rev(Q);Rev(O);
  rep(i,0,A)rep(j,0,B)rep(k,0,C)if((i+1)*(j+1)*(k+1)<K+1)que.push(P[i]+Q[j]+O[k]);
  rep(i,0,K){
    Out(que.top());
    que.pop();
  }
}


Measured memory_bytes: 1404
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,x,y = map(int,readline().split())
ans = [0]*n
for i in range(1,n):
    for j in range(i+1,n+1):
        ans[min(abs(i-j),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y))] += 1

for i in ans[1:]:
    print(i)


Measured memory_bytes: 47196
Tou = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]

n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().split())
    Tou[b-1][f-1][r-1] = Tou[b-1][f-1][r-1] + v

for i in range(4):
    for j in range(3):
        sent =' '
        for k in range(10):
            sent = sent + str(Tou[i][j][k]) + ' '
        print(sent[:-1])
    if i != 3:
        print("####################")



Measured memory_bytes: 5608