akhauriyash/Code-Regression huggingface dataset:
N, M = gets.split.map &:to_i
XS = gets.split.map &:to_i
YS = gets.split.map &:to_i

MOD = 10**9+7

def calc(n, xs)
  ans = 0
  for k in 1..n
    ans += (xs[k-1] * ((k-1) - (n-k)))
    ans %= MOD if ans >= MOD
  end
  ans
end

p (calc(N, XS) * calc(M, YS)) % MOD


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

int main(){
    int n;
    int card[52] = {0};
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
    char c;
    int a;
    scanf(" %c %d", &c, &a);
    
    if(c=='S') card[a-1]=1;
    else if(c=='H') card[a-1+13]=1;
    else if(c=='C') card[a-1+26]=1;
    else if(c=='D') card[a-1+39]=1;
    }
    for (int i = 0; i < 52; i++)
    {
        if(card[i]==0){
            if(i<13)printf("S ");
            else if(i<26) printf("H ");
            else if(i<39) printf("C ");
            else if(i<52) printf("D ");

            printf("%d\n", i%13+1);
        }
    }
    return 0;
}







Measured memory_bytes: 3220
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();

		Set<Integer> set = new TreeSet<>();
		for (int i = a; i < a + k && i <= b; i++) {
			set.add(i);
		}

		for (int i = b; i > b - k && i >= a; i--) {
			set.add(i);
		}

		for (int i : set) {
			System.out.println(i);
		}

		sc.close();
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n;
  cin >> n;
  int d[n];
  rep(i,n) cin >> d[i];
  ll ans=0;
  rep(i,n-1){
    for(int j=i+1;j<n;j++){
      ans+=d[i]*d[j];
    }
  }
  cout << ans << endl;

  
  return 0;
    

}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	string s;
	cin >> s;
	long long cnt = 0, ans = 0;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'B') {
			cnt++;
		}
		if(s[i] == 'W') {
			ans += cnt;
		}
	}
	cout << ans << endl;
	return 0;	
}


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

int main(){
	string s,t;
	cin>>s>>t;
	vector<vector<int> > dp(s.length()+1,vector<int>(t.length()+1,0));
	vector<vector<int> > f(s.length()+1,vector<int>(t.length()+1,0));
	for(int i=1;i<=s.length();i++){
		for(int j=1;j<=t.length();j++){
			if(s[i-1]==t[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
				f[i][j]=1;
			}
			else if(dp[i-1][j]>=dp[i][j-1]){
				dp[i][j]=dp[i-1][j];
				f[i][j]=2;
			}
			else{
				dp[i][j]=dp[i][j-1];
				f[i][j]=3; 
			}
		}
	}
	string ans;
	int i=s.length(),j=t.length();
	while((i>0 && i<=s.length()) && (j>0 && j<=t.length())){
		if(f[i][j]==1){
			ans+=s[i-1];
			i=i-1;
			j=j-1;
		}
		else if(f[i][j]==2){
			i=i-1;
		}
		else{
			j=j-1;
		}
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	//cout<<dp[s.length()][t.length()]<<endl;
	return 0;
}

Measured memory_bytes: 70912
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int 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;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	string ans;
	for (int i = 0; i < tx - sx; i++) {
		ans = ans + "R";
	}
	for (int i = 0; i < ty - sy; i++) {
		ans = ans + "U";
	}
	for (int i = 0; i < tx - sx; i++) {
		ans = ans + "L";
	}
	for (int i = 0; i < ty - sy; i++) {
		ans = ans + "D";
	}
	ans = ans + "D";
	for (int i = 0; i < tx - sx; i++) {
		ans = ans + "R";
	}
	ans = ans + "R";
	for (int i = 0; i < ty - sy; i++) {
		ans = ans + "U";
	}
	ans = ans + "U";
	ans = ans + "L";
	ans = ans + "U";
	for (int i = 0; i < tx - sx; i++) {
		ans = ans + "L";
	}
	ans = ans + "L";
	for (int i = 0; i < ty - sy; i++) {
		ans = ans + "D";
	}
	ans = ans + "D";
	ans = ans + "R";
	cout << ans;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
typedef long long ll;
int main(){
    ll a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}


Measured memory_bytes: 3600
puts [0, 1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692][gets.to_s.to_i]

Measured memory_bytes: 14324
#include <algorithm>
#include <chrono>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using llong = long long;
using ullong = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()
#define loop(i, times) for (llong i = 0; i < times; i++)
#define rloop(i, times) for (llong i = times -1; 0 <= i; i--)

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif


class ABC123C
{
public:
	ABC123C()
	{
		cin >> n_;

		limits_collection_.resize(5);
		loop(i, 5)
			cin >> limits_collection_[i];
	}
	void Run(void)
	{
		sort(all(limits_collection_));
		if (n_ < limits_collection_[0])
		{
			cout << 5;
			return;
		}
		if ((n_ - limits_collection_[0]) % limits_collection_[0] != 0)
		{
			ans_ = 5 + ((n_ - limits_collection_[0]) / limits_collection_[0]) + 1;
		}
		else
		{
			ans_ = 5 + ((n_ - limits_collection_[0]) / limits_collection_[0]);
		}
		cout << ans_;
	}
private:
	llong n_;
	llong ans_;
	vector<llong> limits_collection_;
};



int main(void)
{
//	ABC123B abc123b;
//	abc123b.Run();

	ABC123C abc123c;
	abc123c.Run();
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
using namespace std;

int main(){
    long n;
    cin >> n;
    n = (1+(n-1)) * (n-1) /2;
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	int N, M; cin >> N >> M;
	vector<bool>card(N);
	REP(i, N) {
		card[i] = true;
	}
	int left = 0, right = N - 1;
	REP(i, M) {
		int l, r; cin >> l >> r;
		l--; r--;
		if (left < l)left = l;
		if (right > r) right = r;
	}

	print(max(0, right - left + 1));

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    S = input()
    T = input()

    return S, T


def main(S: str, T: str) -> None:
    """
    メイン処理.

    Args:\n
        S (str): 文字列(1 <= |S| <= 1000)
        T (str): 文字列(1 <= |T| <= |S|)
    """
    # 求解処理
    ans = len(T)
    for i in range(len(S) - len(T) + 1):
        diff = 0
        for j in range(len(T)):
            if T[j] != S[i + j]:
                diff += 1
        ans = min(ans, diff)

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    S, T = get_input()

    # メイン処理
    main(S, T)


Measured memory_bytes: 9084
N, K = map(int, input().split())
list_A = list(map(int, input().split()))

l = [1]
s = {1}

while True:
    next = list_A[l[-1] - 1]

    if not next in s:
        l.append(next)
        s.add(next)

    else:
        start = l.index(next)
        roop = len(l) - start
        break

if len(l) == 1:
    print(1)
    exit()

elif len(l) > K:
    print(l[K])
    exit()

else:
    roop_remainder = (K + 1 - start) % roop
    if roop_remainder == 0:
        print(l[-1])
    else:
        print(l[start + roop_remainder -1])


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

int main(){
   int n;
   cin >> n;
   int a[n];
   bool b[n];
   for(int i=0;i<n;i++){
       cin >> a[i];
       b[i] = false;
   } 
    int ans = 0;
    int i = 0;
    while(1){
        if(i == 1){
            break;
        }
        else if(b[a[i]-1] == true){
            ans = -1;
            break;
        }
        else{
            b[a[i]-1] = true;
            i = a[i]-1;
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  deque<int> B;
  for (int i = 0; i < N; i++) {
    if (N % 2 == 0 && i % 2 == 0)
      B.push_back(A.at(i));
    else if (N % 2 == 0 && i % 2 == 1)
      B.push_front(A.at(i));
    if (N % 2 == 1 && i % 2 == 0)
      B.push_front(A.at(i));
    else if (N % 2 == 1 && i % 2 == 1)
      B.push_back(A.at(i));
  }

  for (int i = 0; i < N; i++) cout << B.at(i) << ' ';
  cout << endl;
}


Measured memory_bytes: 3840
from collections import deque

h, w = map(int, input().split())
Map = [['#'] * (w+2)]
Map += [['#'] + list(input()) + ['#'] for _ in range(h)]
Map += [['#'] * (w+2)]

cnt = 0

for i in range(h+2):
    for j in range(w+2):
        if Map[i][j] == '.':
            cnt += 1
            
stack = deque([(1,1)])
Map[1][1] = 1
moved = [[0,1], [0,-1], [1,0], [-1,0]]

while stack:
    x, y = stack.popleft()
    for s, t in moved:
        if Map[x+s][y+t] == '.':
            stack.append((x+s, y+t))
            Map[x+s][y+t] = Map[x][y] + 1

goal = Map[-2][-2]
if goal == '.':
    print(-1)
else:
    print(cnt - goal)

Measured memory_bytes: 9448
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007


int H, W;
vector<string> V;
ll ans = 0;
int black = 0;
int white = 0;
vector<int> dy = {-1, 0, 1, 0};
vector<int> dx = {0, 1, 0, -1};
string s = "#.";
vector<vector<int>> visited;

void solve(int i, int j, int k){
    if(k==0) black++;
    else white++;

    visited[i][j] = 1;
    for(int l=0; l<4; l++){
        int ny = i + dy[l];
        int nx = j + dx[l];
        if(ny>=0 && nx>=0 && ny<H && nx<W && !visited[ny][nx] && V[ny][nx]==s[k^1])
            solve(ny, nx, k^1);
    }
    return;
}

int main(){
    cin >> H >> W;
    for(int i=0; i<H; i++){
        string s; cin >> s;
        V.push_back(s);
    }
    visited.resize(H);
    for(vector<int> &v:visited)
        v.resize(W);
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            black = 0;
            white = 0;
            if(V[i][j]=='#') solve(i,j, 0);
            ans += (ll)black * white;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16128
#include <iostream>

using namespace std;

const int MAX = 10000001;
 
bool prime[MAX];
 
void pr()
{
    prime[0] = prime[1] = true;
 
    for(int i = 2 ; i*i < MAX ; i++){
	if(!prime[i]){
	    for(int j = i*i ; j < MAX ; j+=i){
		prime[j] = true;
	    }    
	}
    }
}
 
int main()
{
    int n;
 
    pr();
    while(cin >> n ,n){
	for(int i = n ; i >= 0 ; i--){
	    if(!prime[i]&&!prime[i-2]&&!prime[i-6]&&!prime[i-8]){
		cout << i << endl;
		break;
	    }
	}
    }
    return 0;
}

Measured memory_bytes: 12764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

const ll inf = LONG_LONG_MAX / 2 - 1;
ll n, u, v;
vector<vector<ll>> g;
vector<ll> du, dv;

void dfs(ll v, ll p, ll d, vector<ll> &dist) {
    dist[v] = d;
    for(auto u : g[v]) {
        if (u == p) continue;
        dfs(u, v, d + 1, dist);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    cin >> n >> u >> v;
    u--; v--;
    g.resize(n);
    rep(i, n - 1) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    du.resize(n, inf);
    dv.resize(n, inf);
    dfs(u, -1, 0, du);
    dfs(v, -1, 0, dv);
    ll ans = 0;
    rep(i, n) {
        if (du[i] < dv[i]) ans = max(ans, dv[i] - 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12544
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9
#define OO 1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=105;

int main()
{
    IO;
    int n,m,X,Y;
    cin >> n >> m >> X >> Y;
    int MaxX=-oo,MinY=oo;
    while(n--){
        int x;
        cin >> x;
        MaxX=max(MaxX,x);
    }
    while(m--){
        int y;
        cin >> y;
        MinY=min(MinY,y);
    }
    MaxX=max(MaxX+1,X+1);
    MinY=min(MinY,Y);
    if(MaxX<=MinY)cout<<"No War\n";
    else cout<<"War\n";
    re 0;
}

Measured memory_bytes: 256
/*
    Author : RAJON BARDHAN
    AUST CSE 27th Batch
    All my programming success are dedicated to my mom , dad , little sister madhobi , teachers , friends and love TANIA SULTANA RIMY

    Problem Name :
    ALGORITHM :
*/

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

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define memo(a,b) memset(a,b,sizeof(a))
#define INF 1e9
#define EPS 1e-8
#define PI 3.14159265358979323846

typedef long long ll ;
typedef unsigned long long ull ;

/* int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction

const int blockSZ = 600 ;
int arr[100000+10] , BLOCK[600] ;

int getID(int index)
{
    return index / blockSZ ;
}

void update(int index,int value)
{
    arr[index] = value ;
    int blockID = getID(index) , start = blockID*blockSZ , end = (blockID+1)*blockSZ-1 ;

    for(int i=start ; i<=end ;i++)
    {
        if(i==start) BLOCK[blockID] = arr[i] ;
        else BLOCK[blockID] = min(BLOCK[blockID],arr[i]);
    }
}

int query(int L,int R)
{
    int lid = getID(L) , rid = getID(R) ;
    if(lid==rid)
    {
        int mn = 2147483647 ;
        for(int i=L;i<=R;i++) mn = min(mn,arr[i]);
        return mn ;
    }
    int mn1 = 2147483647 , mn2 = 2147483647 , mn3 = 2147483647 ;
    for(int i=L;i<=lid*blockSZ+blockSZ-1;i++) mn1 = min(mn1,arr[i]);
    for(int i=lid+1;i<rid;i++) mn2 = min(mn2,BLOCK[i]);
    for(int i=rid*blockSZ;i<=R;i++) mn3 = min(mn3,arr[i]);

    return min(min(mn1,mn3),mn2);
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int N , Q ;
    scanf("%d%d",&N,&Q);
    for(int i=0;i<N;i++) update(i,2147483647);

    while( Q-- )
    {
        int d , x , y ;
        scanf("%d%d%d",&d,&x,&y);

        switch( d )
        {
            case 0 :
                update(x,y);
                break ;
            case 1 :
                printf("%d\n",query(x,y));
                break ;
        }
    }
    return 0;
}

Measured memory_bytes: 1580
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using V = vector<int>;
using Vll = vector<ll>;
using VV = vector<V>;
using VVll = vector<Vll>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

char s[1000000];

int main() {
  int n, q;
  scanf("%d%s%d", &n, s, &q);

  VVll t(3, Vll(n+1));
  VV pos(3, V());
  string dmc = "DMC";

  rep(i, n) rep(j, 3) {
    t[j][i+1] = t[j][i];
    if (s[i] == dmc[j]) {
      ++t[j][i+1];
      pos[j].push_back(i);
    }
  }

  rep(_, q) {
    int k; 
    scanf("%d", &k);
    ll ans = 0;
    for (auto c : pos[2]) ans += t[1][c] * (t[0][c] - t[0][max(c-k+1, 0)]);
    for (auto a : pos[0]) ans -= t[1][a+1] * (t[2][min(a+k, n)] - t[2][a+1]);
    cout << ans << endl;
  }
  return 0;
}


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

int main()
{
    int N;
    cin >> N;
    int Hi;
    vector<int> H;
    int count = 0;
    int res = 0;
    int prev;
    cin >> prev;
    for(int i=1;i<N;i++){
        cin >> Hi;
        if(Hi <= prev){
            count++;
        }else{
            res = max(res, count);
            count = 0;
        }
        prev = Hi;
    }
    res = max(res, count);
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <set>

int main()
{
    int H, W;
    std::cin >> H >> W;

    std::map<int, int> M;
    std::multiset<int> S;
    for (int i = 0; i < W; i++) {
        M[i] = i;
        S.insert(0);
    }

    for (int i = 0; i < H; i++) {
        int A, B;
        std::cin >> A >> B;
        A--;

        auto cur = M.lower_bound(A);
        int ma = -1;
        while (cur != M.end() and cur->first <= B) {
            ma = std::max(ma, cur->second);

            const int x = cur->first - cur->second;
            S.erase(S.find(x));
            M.erase(cur++);
        }

        if (ma != -1 and B < W) {
            S.insert(B - ma);
            M[B] = ma;
        }

        if (S.empty()) {
            std::cout << -1 << '\n';
        } else {
            std::cout << *S.begin() + i + 1 << '\n';
        }
    }
}

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

int main(){
	int n;
	cin >> n;
	string s[n + 1], tmp[n + 1];
	for(int i = 0; i < n; i++) cin >> s[i];
	cin >> s[n];
	for(int i = 0; i < n + 1; i++) tmp[i] = s[i];
	for(int i = 0; i < n; i++) for(int j = 0; j < tmp[i].size(); j++) if(tmp[i][j] == '?') tmp[i][j] = 'a';
	sort(tmp, tmp + n + 1);
	int last;
	for(int i = 0; i < n + 1; i++) if(tmp[i] == s[n]) last = i;
	for(int i = 0; i < n + 1; i++) tmp[i] = s[i];
	for(int i = 0; i < n; i++) for(int j = 0; j < tmp[i].size(); j++) if(tmp[i][j] == '?') tmp[i][j] = 'z';
	sort(tmp, tmp + n + 1);
	int first;
	for(int i = 0; i < n + 1; i++) if(tmp[i] == s[n]){
		first = i;
		break;
	}
	for(int i = first + 1; i <= last + 1; i++){
		if(i != first + 1) cout << ' ';
		cout << i;
	}
	cout << endl;
}

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

int main() {
    string s; cin >> s;
    int start, end;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A') {
            start = i;
            break;
        }
    }
    for (int i = s.size() - 1; i > 0; i--) {
        if (s[i] == 'Z') {
            end = i;
            break;
        }
    }
    cout << end - start + 1 << endl;
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] cookingTimes = new int[5];

            for (int i = 0; i < cookingTimes.Length; i++)
            {
                cookingTimes[i] = RInt();
            }

 
            int min = int.MaxValue;
            foreach (var idxs in GetPermutation(Enumerable.Range(0, 5), 5))
            {
                int[] order = idxs.ToArray();

                int time = 0;
                for (int i = 0; i < order.Length; i++)
                {
                    time += cookingTimes[order[i]];
                    if (i < 4)
                    {
                        time += cookingTimes[order[i]] % 10 == 0 ? 0 : 10 - cookingTimes[order[i]] % 10;
                    }
                }
                min = Math.Min(min, time);
            }

            Console.WriteLine(min);
        }

        /// <summary>
        /// 配列の順列を列挙する
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items">配列</param>
        /// <param name="r">取得数</param>
        /// <returns>配列の組み合わせの列挙</returns>
        public static IEnumerable<IEnumerable<T>> GetPermutation<T>(IEnumerable<T> items, int r)
        {
            if (r == 0)
            {
                yield return Enumerable.Empty<T>();
            }
            else
            {
                foreach (var x in items)
                {
                    var xs = items.Where(y => !y.Equals(x));
                    foreach (var c in GetPermutation(xs, r - 1)) yield return Concat(x, c);
                }
            }
        }

        public static IEnumerable<T> Concat<T>(T first, IEnumerable<T> items)
        {
            yield return first;
            foreach (var i in items) yield return i;
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,L;
  cin>>N>>L;
  
  vector<string> vec;
  for(int i=0;i<N;i++){
    string A;
    cin>>A;
    vec.push_back(A);
    }
  sort(vec.begin(),vec.end());
  for(int i=0;i<N;i++){
    cout<<vec.at(i);
  }
  cout<<endl;
}

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

typedef long long ll;

//最大公約数の定義
ll gcd(ll a, ll b){
    ll A,B;
    A=max(a,b);
    B=min(a,b);
    if(A%B==0){
        return B;
    }
    else{
        ll r;
        r=A%B;
        while(!(A%B==0)){
            A=B;
            B=r;
            r=A%B;
        }
        return B;
    }
}

//最小公倍数の定義
ll lcm(ll a,ll b){
    ll x;
    x=gcd(a,b);
    return a*b/x;
}

//最大公約数最小公倍数のプログラムの動作確認
/*
ll main(){
    ll a,b;
    cin>>a>>b;
    cout<<gcd(a,b)<<lcm(a,b);
}
*/




int main(){
    ll A,B,C,D;
    cin>>A>>B>>C>>D;

    //CとDの最小公倍数を求める。
    ll x;
    x=lcm(C,D);

    //A以上B以下でCで割り切れる数cを求める。
    ll c;
    if(A%C==0){
        c=B/C-A/C+1;
    }
    else{
        c=B/C-A/C;
    }

    ll d;
    if(A%D==0){
        d=B/D-A/D+1;
    }
    else{
        d=B/D-A/D;
    }

    ll xx;
    if(A%x==0){
        xx=B/x-A/x+1;
    }
    else{
        xx=B/x-A/x;
    }
    cout<<(B-A+1)-(c+d-xx)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
const double inf=1e10;
struct D {
  //各速度ごとの左or下端と右or上端
  vector<double> l,r;
  D():l(3,inf),r(3,-inf) {}
  //点追加のメソッド
  void add(double x, int v){
    //vが-1から始まることを考慮
    v++;
    mins(l[v],x);
    maxs(r[v],x);
  }
  // 時間を与えた時の幅を返す関数
  double get(double t){
    double nl = inf,nr = -inf;
    rep(i,3){
      mins(nl, l[i]+i*t);
      maxs(nr, r[i]+i*t);
    }
    return nr-nl;
  }
  // 点同士がすれ違うタイミングを返す関数
  vector<double> events(){
    vector<double> ts;
    rep(i,3)rep(j,i){//j<iつまり速度が違う時の列挙
      //左端同士がすれ違うタイミング
      {
      double t=(l[j]-l[i])/(i-j);
      if(t>0) ts.push_back(t);
      }
      // 右端同士がすれ違うタイミング
      {
      double t=(r[j]-r[i])/(i-j);
      if(t > 0) ts.push_back(t);
      }
    }
    // 変化しうる点を全て返す
      return ts;
  }
};
int main(){
 int N;cin>>N;
 D xd,yd;
 rep(i,N){
   int x,y;
   char d;
   cin>>x>>y>>d;
   if(d=='L') xd.add(x,-1),yd.add(y,0);
   if(d=='R') xd.add(x,1),yd.add(y,0);
   if(d=='U') xd.add(x,0),yd.add(y,1);
   if(d=='D') xd.add(x,0),yd.add(y,-1);
 }
 // 点同士がすれ違うタイミングを列挙する
 vector<double> ts;
 ts.push_back(0);
 ts.push_back(inf);
 {
   auto nts = xd.events();
   ts.insert(ts.end(),nts.begin(),nts.end());
 }
 {
   auto nts = yd.events();
   ts.insert(ts.end(),nts.begin(),nts.end());
 }
 // rep(i,ts.size())cout<<ts.at(i)<<endl;
 sort(ts.begin(),ts.end());
 double ans= 1e18;
 for(double t:ts){
   double now = xd.get(t)*yd.get(t);
   // cout<<now<<endl;
   mins(ans,now);
 }
 printf("%.10f\n",ans);
 return 0;
}


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

void calc_divisor(int64_t n, std::vector<int64_t>* divisor) {
  if (n != 1) divisor->emplace_back(n);
  int64_t sqrt = std::sqrt(n + 0.5);
  for (int64_t i = 2; i <= sqrt; ++i) {
    if (n % i == 0) {
      divisor->emplace_back(i);
      int64_t j = n / i;
      if (j != i) divisor->emplace_back(j);
    }
  }
}

int solve(int64_t n) {
  std::vector<int64_t> divisor;
  calc_divisor(n - 1, &divisor);
  std::vector<int64_t> ans(divisor);
  divisor.clear();
  calc_divisor(n, &divisor);
  for (const auto& d : divisor) {
    int64_t cur = n / d;
    while (cur % d == 0) cur /= d;
    if (cur % d == 1) ans.emplace_back(d);
  }
  std::sort(ans.begin(), ans.end());
  return (int)(std::unique(ans.begin(), ans.end()) - ans.begin());
}

int main() {
  int64_t n;
  std::cin >> n;
  std::cout << solve(n) << std::endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()

const int mod = 1000000007;
int binpow(int a, int b, int mod)
{
    int ans = 1;
    a = a % mod;
    b = b % mod;
    if (b == 0)
        return 1;
    while (b)
    {
        if (b & 1)
            ans = ((ans % mod) * (a % mod)) % mod;
        a = ((a % mod) * (a % mod)) % mod;
        b >>= 1;
    }
    return ans % mod;
}

//read question carefully!

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        // vector<int> v;
        int x, y;
        set<int> s;
        set<int> s1;
        for (int i = 0; i < n; ++i)
        {
            cin >> x >> y;
            s.insert(x + y);
            s1.insert(x - y);
        }
        int mi1 = *s.begin();
        int ma1 = *s.rbegin();
        int mi2 = *s1.begin();
        int ma2 = *s1.rbegin();
        cout << max(ma1 - mi1, ma2 - mi2) << "\n";
    }
}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;


int main() {
  long long N; cin >> N;
  if (N % 2 != 0) {
    cout << 0 << endl;
    return 0;
  }
  long long i = 10;
  long long count = 0;
  while (N / i >= 1) {
    count += (long long)(N / i);
    i *= 5;
  }
  cout << count << endl;

  return 0;
}


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

int main()
{
    int total = 0, N, A[50], B[50], C[50];

    cin >> N;
    for (int i = 0; i < N; i++)   cin >> A[i];
    for (int i = 0; i < N; i++)   cin >> B[i];
    for (int i = 0; i < N-1; i++) cin >> C[i];

    for (int i = 0; i < N; i++) {
        total += B[A[i] -1];
        if ( i+1 != N && A[i] == A[i+1] -1)
            total += C[A[i] -1];
    }

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
s_list = []
c_list = []
for _ in range(M):
    s,c = input().split()
    s_list.append(int(s)-1)
    c_list.append(c)

ans = -1

if N ==1:
    num=str(0)
    flag = 1
    for j in range(M):
        s = s_list[j]
        c = c_list[j]
        if num[s]==c:
            pass
        else:
            flag=0
    if flag==1:
        ans = num
        
if ans ==-1:
    for i in range(10**(N-1),10**(N)):
        num = str(i)
        flag = 1
        for j in range(M):
            s = s_list[j]
            c = c_list[j]
            if num[s]==c:
                pass
            else:
                flag=0
        if flag==1:
            ans = num
            break
print(ans)


Measured memory_bytes: 3064
import numpy as np
n = int(input())
a = [list(map(int,input().split())),[i for i in range(1,n+1)]]
b = np.array(a).T
b_sort = b[np.argsort(b[:,0])]
b_list = b_sort[:,1].tolist()
for i in b_list:
    print(i,end=' ')

Measured memory_bytes: 28112
n, m = map(int, input().split())
a = []
b = []
for i in range(n): a.append(input())
for i in range(m): b.append(input())

for i in range(n-m+1):
    for j in range(n-m+1):
        is_match = True
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    is_match = False
        if is_match:
            print('Yes')
            exit()
print('No')
            

Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
    int main(){
        int A, B, C;
            cin >> A >> B >> C;
                if(A >= B && A >= C){
                    cout << 10*A + B + C << endl;
                        return 0;
                }else{}
                    if(B >= A && B >= C){
                        cout << A + 10*B + C << endl;
                            return 0;
                    }else{}
                        if(C >= A && C >= B){
                            cout << A + B + 10*C << endl;
                                return 0;
                        }else{}
    return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
int gcd(int a,int b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int n,ans = 0,mn = 0,mx;
    cin >> n;
    vector<int> a(9);
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if(x <= 399) a[0]++;
        if(x >= 400 && x < 800) a[1]++;
        if(x >= 800 && x < 1200) a[2]++;
        if(x >= 1200 && x < 1600) a[3]++;
        if(x >= 1600 && x < 2000) a[4]++;
        if(x >= 2000 && x < 2400) a[5]++;
        if(x >= 2400 && x < 2800) a[6]++;
        if(x >= 2800 && x < 3200) a[7]++;
        if(x >= 3200) a[8]++;
    }
    for (int i = 0; i < 9; ++i) {
        if(a[i] > 0) mn++;
    }
    if(a[7]&&a[8]){
        mn--;
        mx = mn;
        mx += a[8];
    }else if(a[8]) {
        mx = mn - 1+a[8];
    }else{
        mx = mn;
    }

    cout << mn << " " << mx << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
cnt = {"R":0,"G":0,"B":0}
"""
#editorial
i≤jのときai<=aj< bj< cjである
→(=　i<jのとき持っているボールは全てaiより大きい)
→各iに対し、番号がaiより小さいボールの割り当てられている人は人1から人(i−1)のいずれか.
&aiより小さいボールは各色たかだか(i-1)個しかない(=? ちょうどi-1個しかない)
ciについても同様
"""
"""
editorialの簡単に数えられるの箇所？
"""
ans = 1
mod = 998244353
for i in range(3*n):
    cnt[s[i]] += 1
    rem = []
    for k in {"R","G","B"}:
        if k != s[i]:
           rem.append(cnt[k])
    rem.sort()
    if rem[0]<cnt[s[i]]<=rem[1]:#中間色(または最多色2つ)
        ans *=  (cnt[s[i]]-rem[0])*(rem[1]-cnt[s[i]]+1)*cnt[s[i]] #？？？
        ans %=mod
print(ans)
"""
for i in range(1,n+1):
    ans *= i
    ans%=mod
print(ans)
"""

Measured memory_bytes: 44840
/*
ID: computerbox --> Huseyn Hajiyev
LANG: C++
TASK: target_mode_on
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAX3 2010
#define MAX4 20010
#define MAX5 200010
#define MAX6 2000010
#define MOD1 1000000007
#define MOD2 998244353

//cin.ignore (7777, '\n');

using namespace std;
using namespace __gnu_pbds;

#define debug(args...)(Debugger()) , args
class Debugger
{
  public:
  Debugger(const std::string& _separator=", ") :
  first(true),separator(_separator){}
  template<typename ObjectType>
  Debugger& operator,(const ObjectType& v)
  {
        if(!first)cerr<<separator;
        cerr<<v;
        first=false;
        return *this;
  }
  ~Debugger() {cerr<<endl;}      
  private:
    bool first;
    string separator;
};
 
template <typename T1, typename T2>
inline ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
   return os<<"("<<p.first<<", "<<p.second<<")";
}
template<typename T>
inline ostream &operator<<(ostream & os,const vector<T>& v)
{
    bool first=true;
    os<<"[";
    for(unsigned ll i=0;i<v.size();i++)
    {
        if(!first)os<<", ";
        os<<v[i];
        first=false;
    }
        return os<<"]";
}
template<typename T>
inline ostream &operator<<(ostream & os,const set<T>&v)
{
    bool first=true;
    os<<"[";
    for(typename set<T>::const_iterator ii=v.begin();ii!=v.end();++ii)
    {
        if(!first)os<<", ";
        os<<*ii;
        first=false;
    }
    return os<<"]";
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream & os,const map<T1, T2>&v)
{
        bool first=true;
        os<<"[";
        for(typename map<T1,T2>::const_iterator ii=v.begin(); ii!=v.end();++ii)
        {
            if(!first)os<<", ";
            os<<*ii;
            first=false;
        }
        return os<<"]";
}


int main(){
FAST_READ;
ll n;
cin>>n;
cout<<n*n<<endl;







return 0;
} 


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

int main() {
  vector<int> a(1000001);
  int x = 1001001001, n, o = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    x = min(x, t);
    a[t]++;
  }
  while(x <= 1000000) {
    for(int i = x * 2; i <= 1000000; i += x) a[i] = 0;
    do
      x++;
    while(!a[x]);
  }
  for(int i = 1; i <= 1000000; i++)
    if(a[i] == 1) o++;
  printf("%d\n", o);
}

Measured memory_bytes: 7032
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

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

    float bills = ceil(n / 1000.0);
    
    int change = bills * 1000 - n;
    cout << change << endl;
}

Measured memory_bytes: 3720
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int n;
    scan(n);

    auto x = new long[](n + 1);
    auto s = new int[](n + 1);

    foreach (i ; 1 .. n + 1) {
        scan(x[i], s[i]);
    }

    auto p = new long[](n + 1);
    p[1] = s[1];
    foreach (i ; 2 .. n + 1) {
        p[i] = p[i-1] + s[i] - (x[i] - x[i-1]);
    }
    auto pm = new long[](n + 1);
    pm[n] = p[n];
    foreach_reverse (i ; 1 .. n) {
        pm[i] = max(p[i], pm[i+1]);
    }

    long ans = pm[1];
    long d;

    foreach (i ; 2 .. n+1) {
        d += (x[i]-x[i-1]) - s[i-1];
        ans = max(ans, pm[i] + d);
    }

    writeln(ans);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 8828
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  vector<vector<vector<int64_t>>> lunlun(19, vector<vector<int64_t>>(10));

  int cnt = 0;
  for (int p = 1; p <= 9; p++) {
    int64_t result = p;
    cnt++;
    if (cnt == K) {
      cout << result << endl;
      return 0;
    }
    lunlun[0][p].push_back(result);
  }

  int64_t shift = 1;
  for (int d = 1; d <= 18; d++) {
    shift *= 10;
    for (int64_t p = 1; p <= 9; p++) {
      for (int64_t delta = -1; delta <= 1; delta++) {
        int64_t q = p + delta;
        if (q < 0 || q > 9) {
          continue;
        }

        if (q == 0) {
          int64_t result = p * shift;
          // cerr << result << "\n";
          cnt++;
          if (cnt == K) {
            cout << result << endl;
            return 0;
          }
          lunlun[d][p].push_back(result);
          rep(e, d - 1) {
            for (auto& l : lunlun[e][1]) {
              int64_t result = p * shift + l;
              // cerr << result << "\n";
              cnt++;
              if (cnt == K) {
                cout << result << endl;
                return 0;
              }
              lunlun[d][p].push_back(result);
            }
          }
        } else {
          for (auto& l : lunlun[d - 1][q]) {
            int64_t result = p * shift + l;
            // cerr << result << "\n";
            cnt++;
            if (cnt == K) {
              cout << result << endl;
              return 0;
            }
            lunlun[d][p].push_back(result);
          }
        }
      }
    }
  }
  return 0;
}

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

using namespace std;

int main(){
	long long n,m;
	cin>>n>>m;
	long long inf=1000000007;

	if(abs(n-m)>=2){
		cout<<0<<endl;
		return 0;
	}

	long long ans=1;

	for(long long i=1;i<=n;i++){
		ans=(ans*i)%inf;
	}

	for(long long i=1;i<=m;i++){
		ans=(ans*i)%inf;
	}

	cout<<(n==m ? (ans*2)%inf : ans)<<endl;

	return 0;
}


Measured memory_bytes: 256
def prime_factorize(n):
    a = [1]
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
def gcd(x,y):
    if y == 0:
       return x
    else:
       return gcd(y, x % y)
 
A,B = [int(x) for x in input().split()]
koyaku = gcd(A,B)
 
koyaku_insu = list(set(prime_factorize(koyaku)))
 
 
print(len(koyaku_insu))

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

#define endl "\n"
#define si(a) scanf("%d ",&a);
#define si2(a,b) scanf("%d %d ",&a,&b);
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sll(a) scanf("%lld ",&a);
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sf(a) scanf("%f ",&a);
#define sd(a) scanf("%lf ",&a);
#define sc(a) scanf("%c ",&a);
#define ss(a) scanf("%s ",a);
#define sf2(a,b) scanf("%f %f ",&a,&b);
#define sd2(a,b) scanf("%lf %lf ",&a,&b);
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<n;i++)
#define forq(i,q,n) for(int i=q;i<n;i++)
#define form(i,n) for(int i=n;i>=0;i--)
#define forp(i,q,n) for(int i=q;i>=n;i--)
#define fi first
#define se second
#define INF 1000000010
#define MOD 1000000007
#define MAXN
#define LL long long int


using namespace std;

string a, b, c;

void init(){
	cin >> a >> b >> c;
	printf("%c", (char)a[0] - 32);
	printf("%c", (char)b[0] - 32);
	printf("%c\n", (char)c[0] - 32);

}

int main(){
	
	init();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
using namespace std;

double triangle(double p1x,double p1y,double p2x,double p2y, double p3x, double p3y);

struct Point{
  double x;
  double y;
}typedef point;

int main(void){
  double x,y;
  vector<point> v;
  while(scanf("%lf,%lf",&x,&y)!=EOF){
    point p;
    p.x=x;
    p.y=y;
    v.push_back(p);
  }
  int n=v.size();
  double area=0;
  for(int i=1;i<n-1;i++){
    area+=triangle(v[0].x,v[0].y,v[i].x,v[i].y,v[i+1].x,v[i+1].y);
  }
  cout<<abs(area)<<endl;
  return 0;
}


double triangle(double p1x,double p1y,double p2x,double p2y, double p3x, double p3y){
  p2x-=p1x;
  p3x-=p1x;
  p2y-=p1y;
  p3y-=p1y;
  return -1*((double)(p2x*p3y-p3x*p2y))/2;
}



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

int main(void) {
	string s;
    cin >> s;
    

    if (s == "Sunny") {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy") {
        cout << "Rainy" << endl;
    }
    else {
        cout << "Sunny" << endl;
    }

	return 0;
}


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

using namespace std;

void dfs(int index, vector<vector<int>> &graph, vector<int> &stack, vector<bool> &visited)
{
  while(true)
  {
	bool selected = false;
	for(auto next : graph[index])
	{
	  if(!visited[next])
	  {
		selected = true;
		stack.push_back(next);
		index = next;
		visited[next] = true;
		break;
	  }
	}
	if(!selected)
	{
	  return;
	}		
  }	  
}

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

  vector<vector<int>> graph(n + 1);

  for(int i = 0; i < m; i++)
  {
	int a, b;
	cin >> a >> b;
	graph[a].push_back(b);
	graph[b].push_back(a);
  }

  if(n == 2)
  {
	cout << 2 << endl;
	cout << "1 2" << endl;
  }
  else
  {
	vector<bool> visited(n + 1);
	fill(visited.begin(), visited.end(), false);

	vector<int> front;
	int selected = -1;
	vector<int> back;

	for(int i = 1; i <= n; i++)
	{
	  if(graph[i].size() >= 2)
	  {
		selected = i;
		visited[i] = true;
		dfs(i, graph, front, visited);
		dfs(i, graph, back, visited);
		break;
	  }
	}

	reverse(front.begin(), front.end());
	front.push_back(selected);
	for(auto v : back)
	{
	  front.push_back(v);
	}

	cout << front.size() << endl;
	bool is_front = true;
	for(auto v : front)
	{
	  if(!is_front) cout << " ";
	  cout << v;
	  is_front = false;
	}
	cout << endl;
  }
}


Measured memory_bytes: 6776
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}//standard output
        static void myerr(Object t){System.err.println(t);}//standard error
        static String getStr(){return sc.next();}
        static int getInt(){return Integer.parseInt(getStr());}
        static long getLong(){return Long.parseLong(getStr());}
        static boolean hasNext(){return sc.hasNext();}
        static char[] mySplit(String str){return str.toCharArray();}
        public static void main(String[] args){
          long N = getLong();
          long A = getLong();
          long B = getLong();
          if(A == 0){
            myout(0);
            return;
          }
          if(B == 0){
            myout(N);
            return;
          }
          long sum = 0;
          sum += (N / (A + B)) * A;
          long amari = N % (A + B);
          sum += Math.min(amari,A);
          myout(sum);
        }
        //Method addition frame start

        //Method addition frame end
}


Measured memory_bytes: 23636