akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    string ans = "";

    rep(i, n) {
        if(s[i] == '0') {
            ans += "0";
        }
        else if(s[i] == '1') {
            ans += "1";
        }
        else if(s[i] == 'B') {
            int m = ans.size();
            if(m <= 1) {
                ans = "";
            }
            else if(1 < m) {
                ans = ans.substr(0, m-1);
            }
        }
    }

    cout << ans;
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
#define S 1000000000
typedef struct{
  char pic;
  int num;
}CARD;

int n;

void merge(CARD *,int, int, int);
void mergeSort(CARD *,int ,int);
int partition(CARD *,int, int);
void quickSort(CARD *,int,int);

int main(){
  int i,judge=1;/*judgeが1だったらStable、0だったらNot stable*/
  char a[5];
  CARD merge[MAX],quick[MAX];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %d",a,&merge[i].num);
    quick[i].pic=merge[i].pic=a[0];
    quick[i].num=merge[i].num;
  }

  mergeSort(merge,0,n);
  quickSort(quick,0,n-1);

  for(i=0;i<n;i++){
    if(merge[i].pic!=quick[i].pic){
      judge=0;
    }
  }

  if(judge==1){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }

  for(i=0;i<n;i++){
    printf("%c %d\n",quick[i].pic,quick[i].num);
  }
  
  return 0;
}

void merge(CARD *A,int left,int mid,int right){
  int n1,n2,i,j,k;
  CARD L[MAX],R[MAX];
  n1 = mid - left;
  n2 = right - mid;
  for(i=0;i<=n1-1;i++){
    L[i]=A[left+i];
  }

  for(i=0;i<=n2-1;i++){
    R[i]=A[mid+i];
  }
  
  L[n1].num=S;
  R[n2].num=S;
  i=0;
  j=0;

  for(k=left;k<=right-1;k++){
    if(L[i].num<=R[j].num){
      A[k]=L[i];
      i=i+1;
    }else{
      A[k]=R[j];
      j=j+1;
    }
  }
}

void mergeSort(CARD *A,int left,int right){
  int mid;  
  if(left+1<right){
    mid = (left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}



int partition(CARD *A,int p,int r){
  int i,j;
  CARD x,s;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].num<=x.num){
      i=i+1;
      s=A[j];
      A[j]=A[i];
      A[i]=s;
    }
  }
  s=A[r];
  A[r]=A[i+1];
  A[i+1]=s;
  return i+1;
}


void quickSort(CARD *A,int p,int r){
  int q;
  if(p<r){
    q=partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}



Measured memory_bytes: 4120
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
#define int long long
int gcd(int a, int b) {
	if (!b)return a;
	return gcd(b, a%b);
}
signed main() {
	int n;
	cin >> n;
	int ans = 1;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		ans = ans / gcd(ans, t)*t;
	}
	cout << ans << endl;
}

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

int main()
{
	int k,n,m=-1,s;
	cin>>k>>n;
	int a[n+1],b[n+1]={0};
	
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	
	
	for(int i=1;i<n;i++)
	{
		s=0;
		s=a[i+1]-a[i];
		if(s>k/2)
			b[i]=k-s;
		else
			b[i]=s;
	}
	
	s=a[n]-a[1];
	if(s>k/2)
		b[n]=k-s;
	else
		b[n]=s;
	
	for(int i=1;i<=n;i++)
	{
		if(b[i]>m)
			m=b[i];
	}
	cout<<k-m;
	return 0;
}

Measured memory_bytes: 1792
/*ex4_1
  S_S_S*/

#include <stdio.h>
#include <math.h>
int main(void) {
    float wood,range;
    scanf("%f",&wood);
    scanf("%f",&range);
    range=range*2+1;/*観測範囲*/
    int ans=ceil(wood/range);/*本数<範囲*人数*/
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <bitset>
#include <iostream>
#include <stdio.h>
#include <vector>

#define MAX_M 10

using namespace std;

vector<int> V[MAX_M];
int P[MAX_M];

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int k;
    cin >> k;
    vector<int> v;
    for (int j = 0; j < k; ++j) {
      int s;
      cin >> s;
      v.push_back(s - 1);
    }
    V[i] = v;
  }
  for (int i = 0; i < M; ++i) {
    cin >> P[i];
  }
  int res = 0;
  for (int i = 0; i < 1 << N; ++i) {
    bitset<MAX_M> B(i);
    bool flg = true;
    for (int j = 0; j < M; ++j) {
      int cnt = 0;
      for (auto &s : V[j]) {
        if (B.test(s)) {
          ++cnt;
        }
      }
      if (cnt % 2 != P[j]) {
        flg = false;
      }
    }
    res += flg;
  }
  printf("%d\n", res);
}

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

int main(){
  int N,M,K; cin >> N >> M >> K;
  bool flag = false;
  for(int m = 0; m <= M; m++){
    for(int n = 0; n <= N; n++){
      if(K == m * N + n * M - 2 * m * n){
        flag = true;
      }
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m,x,p;
    cin >> n >> m;
    x=100*(n-m)+1900*m;
    p=pow(2,m);
    cout << x*p << "\n";
    return 0;
}   

Measured memory_bytes: 4068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
bool check(ll i,ll j) { // iを jで割り切れるかチェック
    if ( i%j == 0) return true;
    if ( i%j != 0) return false;
}


    
int main(void){
    //ll l = 1;
    ll r; // r>= 1000000000000
    cin >> r;
    //r = r+1;
    ll ans = 0;
    ll i=(sqrt(r));
    
    //cout << i << endl;
    
    for (i; i>=1; i--) {
        if (i == 1) {
            ans = r-1;
            break;
        } else if (check (r, i)){
            ans = (i-1) + (r/i-1);
            break;
        }
    //cout << "i = " << i << endl;
    //cout << "r = " << r << endl;
    //cout << "r/i = " << r/i << endl;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> Int -> [(Int, Int)]
solve !n !k | k > n1C2  = []
            | otherwise = scatterTo1 ++ drop k edges
 where
  n1C2       = (n - 1) * (n - 2) `div` 2
  edges      = [ (x, y) | x <- [2 .. n - 1], y <- [x + 1 .. n] ]
  scatterTo1 = [ (1, n) | n <- [2 .. n] ]

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, k) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  let xs = solve n k

  if null xs
    then print (-1)
    else do
      print $ length xs
      forM_ xs $ \(x, y) -> putStrLn $ show x ++ " " ++ show y


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
using ull = unsigned long long;
const int nax = 1e9;
int ff(int xorr, int num) {
	return (xorr^num);
}
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	int xorr = 0;
	for(int i=0;i<n;i++) {
		cin >> a[i];
		xorr^=a[i];
	}
	debug()<<imie(xorr);
	vector<int> ans(n);
	for(int i=0;i<n;i++) {
		ans[i] = ff(xorr,a[i]);
		assert((xorr ^ a[i]) == ans[i]);
	}
	for(auto it:ans) {
		cout<<it<< " ";
	}
}


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

int N, A[200000];

bool check(int k){
    bitset<200000> large;
    for(int i=1; i<=2*N-1; i++) large[i] = (A[i] >= k);

    int lsign = -1, ldist, rsign = -1, rdist;
    for(int i=N; i+1<=2*N-1; i++){
        if(large[i] == large[i+1]){
            rdist = i - N;
            rsign = large[i];
            break;
        }
    }
    for(int i=N; i-1>=1; i--){
        if(large[i] == large[i-1]){
            ldist = N - i;
            lsign = large[i];
            break;
        }
    }
    
    if(lsign == -1 && rsign == -1){
        return (large[N] + N + 1) % 2;
    }else if(lsign == -1 || rsign == -1){
        return max(lsign, rsign);
    }else{
        return (ldist < rdist ? lsign : rsign);
    }
}

int main(){
    cin >> N;
    for(int i=1; i<=2*N-1; i++) cin >> A[i];

    int ok = 1, ng = 2*N;
    while(ng-ok>1){
        int mid = (ok+ng)/2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int k,n;
  cin >> k >> n;
  int u[n];
  rep(i,n){
    cin >> u[i];
  }
  int m=u[0]+k-u[n-1];
  rep(i,n-1) m=max(m,u[i+1]-u[i]);
  cout << k-m << endl;  
}


Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#define LL long long
#define FIO ios_base::sync_with_stdio(false), cin.tie(0)
using namespace std;

int main()
{
	LL n, k; cin>>n>>k;
	if(n%k==0) { cout<<0<<endl; return 0; }

	LL a=n%k, b=abs(k-a);
	if(a<b) cout<<a<<endl;
	else cout<<b<<endl;
}


Measured memory_bytes: 3624
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			list.add(scanner.nextInt());
		}
		//listを降順で並び替え
		Collections.sort(list, Collections.reverseOrder());

		//K個足し合わせる
		int sum = 0;
		for (int i = 0; i < K; i++) {
			sum += list.get(i);
		}

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

		System.out.println(sum);

	}

}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
char s[101];
int main(){
	cin>>s;
	int n=strlen(s),pos=-1;
	for(int i=0;i<n;++i){
		if(s[i]=='C'){
			pos=i;break;
		}
	}
	if(pos==-1){
		puts("No");
		return 0;
	}
	for(int i=pos;i<n;++i){
		if(s[i]=='F'){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = sum(A)//2
d = 0
for i in range(0,N-1,2):
    d += A[i]
X = [B-d]
for i in range(N-2,-1,-1):
    x = A[i]-X[-1]
    X.append(x)
X = X[::-1]
for i in range(N):
    X[i] = 2*X[i]
print(*X)

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

using namespace std;
typedef long long ll;

int main(){
    
    ios_base::sync_with_stdio(0);
    int a,b;
    char c;
    cin>>a>>c>>b;
    while(c!='?'){
        if(c=='+')  cout<<a+b<<endl;
        else if(c=='-') cout<<a-b<<endl;
        else if(c=='*') cout<<a*b<<endl;
        else if(c=='/') cout<<a/b<<endl;
        
        cin>>a>>c>>b;
    }
    return 0;
}




Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;

int main(){
  long long X;
  cin >>X;

  int ans=0;
  long long mon = 100;
  while(mon < X){
    mon=mon+mon/100;
    ans++;

  }

  cout<<ans << endl;

  return 0;
}


Measured memory_bytes: 3632
x, y, tx, ty = map(int, input().split())

x_diff = tx - x
y_diff = ty - y

first_x_diff = "R" * abs(x_diff) if x_diff > 0 else "L" * abs(x_diff)
first_y_diff = "U" * abs(y_diff) if y_diff > 0 else "D" * abs(y_diff)

first_diff = first_x_diff + first_y_diff
tmp_diff = first_diff.replace("R", "L")
tmp_diff = tmp_diff.replace("U", "D")
first_diff = first_diff + tmp_diff

second_x_diff = "R" * abs(x_diff + 1) if x_diff > 0 else "L" * abs(x_diff + 1)
second_y_diff = "U" * abs(y_diff + 1) if y_diff > 0 else "D" * abs(y_diff + 1)

second_diff = second_x_diff + second_y_diff
tmp_diff = second_diff.replace("R", "L")
tmp_diff = tmp_diff.replace("U", "D")
second_diff = "D" + second_diff + "L" + "U" + tmp_diff + "R"

res = first_diff + second_diff
print(res)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[33]={0,1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,1,1,15,2,2,5,4,1,4,1,51};
	int k;
	cin>>k;
	cout<<a[k];
	return 0;
 } 

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };
 
typedef long long ll;
using namespace std;
 
int main() {
  int a,b;
 
  while(cin >> a >> b){
    int g = __gcd(a,b);
    cout << g << " " << a/g*b << endl;
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  if(n==2) {
    cout << -1 << endl;
    return 0;
  }
  for(int i=0; i<n; i++) {
    int a[n];
    for(int j=0; j<n; j++) a[j]=(i+j+1)%n+1;
    if(n%2==0&&i>=n/2) swap(a[n/2-1],a[n/2]);
    for(int j=0; j<n-1; j++) {
      if(j) cout << " ";
      cout << a[j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define endl '\n'

using namespace std; 

vector<int> a;

void CountTriangles()
{
    int i,l,r,cnt=0;
    for(i=a.size()-1;i>0;i--)
    {
        l=0;
        r=i-1;
        while (l<r)
        {
            if (a[l]+a[r]>a[i])
            {
                cnt+=r-l;
                r--;
            }
            else
                l++;
        }
    }
    cout<<cnt;
} 

main()
{ 
	fast;
	int n,l,i;
	cin>>n;
	for (i=0;i<n;i++)
	{
		cin>>l;
		a.pb(l);
	}
	sort(a.begin(),a.end());
    CountTriangles();
} 

Measured memory_bytes: 256
def ceil(x,y):
    if x%y==0:
        return x//y
    else:
        return (x//y)+1
N=int(input())
T,A=1,1
for _ in range(N):
    t,a=map(int,input().split())
    x=max(ceil(T,t),ceil(A,a))
    if x==0:x=1
    T,A=t*x,a*x
print(T+A)

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

int main()
{

int l,r,d,e=0;
cin>>l>>r>>d;

for (int i=l;i<=r;i++){

    if(i%d==0)
        e++;




}

cout<<e<<endl;




}

Measured memory_bytes: 3628
use std::io;
fn main(){
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut token = buf.trim().split_whitespace();
    let n:usize = token.next().unwrap().parse().unwrap();
    let a:i32 = token.next().unwrap().parse().unwrap();
    let b:i32 = token.next().unwrap().parse().unwrap();
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let s:Vec<char> = buf.trim().chars().collect();

    let mut cnt_a:i32 = 0;
    let mut cnt_b:i32 = 0;
    let mut cnt:i32 = 0;
    
    for (_i, x) in s.iter().enumerate() {
        if *x == 'a' {
            cnt_a+=1;
            if cnt < a + b {
                cnt+=1;
                println!("Yes");
            } else {
                println!("No");
            }
        } else if *x == 'b' {
            cnt_b+=1;
            if cnt < a + b && cnt_b <= b {
                cnt += 1;
                println!("Yes");
            } else{
                println!("No");
            }
        } else {
            println!("No");
        }
    }
 
}

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

/* MACROS SAMPAH */
#define Jehian using
#define Norman namespace
#define Saviero std
#define cepet {ios_base::sync_with_stdio(0);cin.tie(0);}

Jehian Norman Saviero;

/* MACROS FOR TYPE */
typedef long l;
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

/* MACROS FOR PRINT */
#define nl printf("\n");
#define sp printf(" ");

/* MACROS FOR FUNCTION AND METHOD */
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define eb emplace_back
#define RESET(x) memset((x), 0, sizeof(x))
#define SET(x,y) for(int _je = sizeof(x)/sizeof(x[0]); _je--;) x[_je] = y
#define SQR(x) (x)*(x)
#define CUBE(x) SQR(x)*(x)

/* MACROS FOR ATTRIBUTE */
#define fi first
#define se second

/* MACROS FOR SCAN */
#define scc(x) scanf("%c", &x)
#define scd(x) scanf("%Lf", &x)
#define scf(x) scanf("%f", &x)
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scld(x) scanf("%Lf", &x)
#define scui(x) sci(x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main(){
	ll T;
	scll(T);
	vll idx;
	ll tmp = T;
	while (T){
		idx.pb(T%10);
		T /= 10;
	}
	ll sum = 0;
	for (auto it : idx){
		sum += it;
	}
	if (tmp%sum){
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"bufio"
	"os"
	"strings"
	"strconv"
	"math"
)

var INF int32 = math.MaxInt32
var INF64 int64 = math.MaxInt64

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

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

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

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

func readLineNums(bf *bufio.Reader) []int {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int{}
	for _, field := range fields {
		num, _ := strconv.Atoi(field)
		nums = append(nums, num)
	}
	return nums
}

func readLineNum64s(bf *bufio.Reader) []int64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []int64{}
	for _, field := range fields {
		num, _ := strconv.ParseInt(field, 10, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineFloats(bf *bufio.Reader) []float64 {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	fields := strings.Split(line, " ")
	nums := []float64{}
	for _, field := range fields {
		num, _ := strconv.ParseFloat(field, 64)
		nums = append(nums, num)
	}
	return nums
}

func readLineStrs(bf *bufio.Reader) []string {
	line, _ := bf.ReadString('\n')
	line = strings.Trim(line, "\n")
	return strings.Split(line, " ")
}

// 实现一个线段数, 保存的是最大值
// 查询, 从节点n(范围是tl~tr), 查询线段(l~r)之间的最大值
func query(A []int, n int, tl int, tr int, l int, r int) int {
	if tl == l && tr == r {
		return A[n]
	}
	if tl > tr {
		return 0
	}
	if l > r {
		return 0
	}

	mid := tl+(tr-tl)/2
	if r <= mid {
		// 左侧分支
		return query(A, 2*n, tl, mid, l, r)
	}
	if l > mid {
		// 右侧分支
		return query(A, 2*n+1, mid+1, tr, l, r)
	}

	// r>mid && l<=mid
	n1 := query(A, 2*n, tl, mid, l, mid)
	n2 := query(A, 2*n+1, mid+1, tr, mid+1, r)
	return max(n1, n2)
}

// 更新
func update(A []int, n int, tl int, tr int, idx int, val int) {
	if tl == tr && tl == idx {
		A[n] = val
		return
	}

	mid := tl+(tr-tl)/2
	if idx <= mid {
		update(A, 2*n, tl, mid, idx, val)
	} else {
		update(A, 2*n+1, mid+1, tr, idx, val)
	}

	A[n] = max(A[2*n], A[2*n+1])
}

func main() {
	bf := bufio.NewReader(os.Stdin)

	N := readLineNums(bf)[0]
	H := readLineNums(bf)
	A := readLineNums(bf)

	// 线段数
	tree := make([]int, 4*(N+1)+1) // 保存的范围是1~N

	dp := make([]int, N+1)
	for i:=0; i<N; i++ {
		hi := H[i]
		ai := A[i]
		best := query(tree, 1, 1, N, 1, hi-1)
		dp[hi] = best+ai
		update(tree, 1, 1, N, hi, dp[hi])
	}

	ans := 0
	for _, ai := range dp {
		ans = max(ans, ai)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
typedef vector<long long> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;

inline bool valid(int x, int n) {
    return 0 <= x && x < n;
}

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

template <typename T>
inline T pop(queue<T>& q) {
    T front = q.front();
    q.pop();
    return front;
}

template <typename T>
inline T gcd(T a, T b) {
    for (; b; a %= b, swap(a, b));
    return a; 
}

template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
    if (b == 0) return {1, 0, a};
    T x, y, g;
    tie(x, y, g) = xgcd(b, a%b);
    return {y, x-(a/b)*y, g};
}

typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

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

    vvi A(3, vi(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> A[i][j];
        }
    }

    int N; cin >> N;
    vvb rst(3, vb(3, 0));
    while (N--) {
        int b; cin >> b;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (A[i][j] == b) rst[i][j] = 1;
            }
        }
    }

    for (int i = 0; i < 3; i++) {
        bool flag = true;
        for (int j = 0; j < 3; j++) {
            if (rst[i][j] == 0) {
                flag = false;
                break;
            }
        }

        if (flag) {
            cout << "Yes";
            return 0;
        }

        flag = true;
        for (int j = 0; j < 3; j++) {
            if (rst[j][i] == 0) {
                flag = false;
                break;
            }
        }

        if (flag) {
            cout << "Yes";
            return 0;
        }
    }

    if (rst[0][0] && rst[1][1] && rst[2][2]) {
        cout << "Yes";
        return 0;
    }

    if (rst[2][0] && rst[1][1] && rst[0][2]) {
        cout << "Yes";
        return 0;
    }

    cout << "No";
}

Measured memory_bytes: 256
/*input
10000000000 10 99959
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, x, m;
  cin >> n >> x >> m;
  const int MX = 100005;
  vector<ll> a(MX);
  a[0] = x;
  map<ll, int> mp;
  mp[a[0]] = 0;
  int s, t;
  rep(i, MX) {
    ll na = (a[i]*a[i])%m;
    // cout << a[0] << " " << na << endl;
    if (mp.count(na)) {
      s = mp[na];
      t = i+1;
      break;
    }
    a[i+1] = na;
    mp[na] = i+1;
  }
  ll ans = 0;
  if (n < t) {
    rep(i, n) ans += a[i];
  }
  else {
    rep(i, s) ans += a[i];
    n -= s;
    ll sum = 0;
    for (int i = s; i < t; ++i) sum += a[i];
    ans += n/(t-s)*sum;
    for (int i = s; i < s+n%(t-s); ++i) ans += a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 7148
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
int n,A[110000];
long long get(long long m){
	for (int i=1;i<=n;i++) m-=(m%A[i]);
	return m;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&A[i]);
	long long l=2,r=1e18,ans=0;
	while (l<r){
		long long mid=l+r>>1;
		if (get(mid)>=2) ans=mid,r=mid; else l=mid+1;
	}
	if (get(ans)!=2){
		printf("-1\n"); return 0;
	}
	cout<<ans<<" ";
	l=2,r=1e18;
	while (l<r){
		long long mid=l+r>>1;
		if (get(mid)<=2) ans=mid,l=mid+1; else r=mid;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

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

    int sumAA = 0;
    int sumAB = 0;
    int sumBB = 0;

    sumAA += a;
    sumAA += a - 1;

    sumAB += a;
    sumAB += b;

    sumBB += b;
    sumBB += b - 1;

    int max = sumAA;
    if(sumAA < sumAB) max = sumAB;
    if(sumAA < sumBB) max = sumBB;

    cout << max << endl;
    
    return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i, h) cin >> s[i];

    REP(i, h){
        REP(j, w){
            int n = (i > 0 && s[i-1][j] == '#' ? 1 : 0) + 
                (i > 0 && j > 0 && s[i-1][j-1] == '#' ? 1 : 0) +
                (j > 0 && s[i][j-1] == '#' ? 1 : 0) +
                (i < h-1 && s[i+1][j] == '#' ? 1 : 0) +
                (i < h-1 && j < w-1 && s[i+1][j+1] == '#' ? 1 : 0) +
                (j < w-1 && s[i][j+1] == '#' ? 1 : 0) +
                (i > 0 && j < w-1 && s[i-1][j+1] == '#' ? 1 : 0) +
                (i < h-1 && j > 0 && s[i+1][j-1] == '#' ? 1 : 0);

            cout << (s[i][j] == '#' ? "#" : to_string(n));
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int main()
{
	int n;
	while(cin>>n,n)
	{
		vector<pair<int,int>> v;
		REP(i,n)
		{
			int a,b,c,t;
			scanf("%d:%d:%d",&a,&b,&c);
			t = 3600*a+60*b+c;
			v.push_back(make_pair(t,1));
			scanf("%d:%d:%d",&a,&b,&c);
			t = 3600*a+60*b+c;
			v.push_back(make_pair(t,-1));
		}
		sort(v.begin(),v.end());
		int cnt = 0;int train = 0;
		REP(i,2*n)
		{
		if(train==0&&v[i].second == 1)
		{
		cnt++;
		}
		else train-=v[i].second;
		}
		cout<<cnt<<endl;
	}
}

Measured memory_bytes: 1492
prime = [True] * 100001
cnt_list = [0] * 100002

for i in range(2, 100001):
    if prime[i]:
        for j in range(i+i, 100001, i):
            prime[j] = False

for i in range(3, 100001, 2):
    if prime[i] and prime[(i+1)//2]:
        cnt_list[i] += 1

for i in range(3, 100001):
    cnt_list[i] += cnt_list[i-1]

N = int(input())

for i in range(N):
    L, R = map(int,input().split())
    print(cnt_list[R] - cnt_list[L-1])


Measured memory_bytes: 7156
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    long a[n],i,max,min;
    long long sum=0;
    for(i=0;i<n;i++){
        scanf("%ld",&a[i]);
        sum+=a[i];
        if(i==0||a[i]<min){
            min=a[i];
        }
        if(i==0||a[i]>max){
            max=a[i];
        }
    }
    printf("%ld %ld %lld\n",min,max,sum);
}


Measured memory_bytes: 2140
type BITDataType=Longint;
type BinaryIndexedTree=record n:Longint;bit:Array of BITDataType;end;
procedure init(var bit:BinaryIndexedTree;N:Longint);
var i:Longint;
begin
	bit.n:=N;
	setlength(bit.bit,N+1);
	for i:=1 to N do bit.bit[i]:=0;
end;
function sum(var bit:BinaryIndexedTree;i:Longint):BITDataType;
var ans:BITDataType;
begin
	ans:=0;
	while i>0 do begin
		inc(ans,bit.bit[i]);
		dec(i,i and-i);
	end;
	sum:=ans;
end;
procedure add(var bit:BinaryIndexedTree;i:Longint;a:BITDataType);
begin
	while i<=bit.n do begin
		inc(bit.bit[i],a);
		inc(i,i and-i);
	end;
end;

var
	N,Q,i,qt,id,l,r,cnt:Longint;
	S:String;
	c:Char;
	bit:Array['a'..'z']of BinaryIndexedTree;
begin
	readln(N);
	readln(S);
	readln(Q);
	for c:='a' to 'z' do init(bit[c],N);
	for i:=1 to N do add(bit[S[i]],i,1);
	for i:=1 to Q do begin
		read(qt);
		if qt=1 then begin
			read(id);
			read(c);
			read(c);
			add(bit[S[id]],id,-1);
			S[id]:=c;
			add(bit[S[id]],id,1);
		end else begin
			read(l,r);
			cnt:=0;
			for c:='a' to 'z' do if sum(bit[c],r)>sum(bit[c],l-1) then inc(cnt);
			writeln(cnt);
		end;
	end;
end.


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

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

  ll N; cin >> N;
  ll M; cin >> M;
  vector<ll> H(N); for (ll i = 0; i < N; i++) cin >> H[i];
  vector<ll> cnt(N, 0);

  for (ll i = 0; i < M; i++) {
    ll a, b; cin >> a >> b;
    a--, b--;
    if (H[a] == H[b]) {
      cnt[a]++;
      cnt[b]++;
    } else if (H[a] > H[b]) {
      cnt[b]++;
    } else {
      cnt[a]++;
    }
  }

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    if (cnt[i] == 0) ans++;
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 4768
//ProblemB.cpp

#include <iostream>

static std::istream & ip = std::cin;
static std::ostream & op = std::cout;

#if OJ_MYPC
#include <ojio.h>
#endif

#ifndef OPENOJIO
#define OPENOJIO
#endif

#if 1 || DEFINE
/***************************************************************/
typedef unsigned long long u64;
typedef long long s64;

typedef unsigned uint;

#define ABS(x) ((x) > 0 ? (x) : -(x))

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define MIN3(x, y, z) MIN(x, MIN(y, z))
#define MAX3(x, y, z) MAX(x, MAX(y, z))

#define FillZero(arr) memset(arr, 0, sizeof(arr));

/***************************************************************/
#endif //1 || DEFINE

#include <string>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>

//001
//op << setfill('0') << setw(3) << setiosflags(ios::right) << 1;

//op << fixed << setprecision(20);

using namespace std;

//ProblemB.cpp

#define MAXN 2010
#define INF 0x1FFFFFFFFFFFL
int main(int argc, char* argv[])
{
	OPENOJIO;

	int n;
	s64 a[MAXN + 1];
	s64 x;

	s64 b[MAXN + 1];
	ip >> n >> x;
	for (int i = 0; i < n; ++i) {
		ip >> a[i];
		b[i] = a[i];
	}
	s64 rst = INF;
	for (int i = 0; i < n; ++i) {
		s64 trst = 0;

		for (int j = 0; j < n; ++j) {
			b[j] = MIN(b[j], a[(j - i + n) % n]);
			trst += b[j];
		}

		trst += i * x;
		if (trst < rst) rst = trst;
	}

	cout << rst << endl;

	return 0;
}
/***************************************************************/


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

#include <vector>
#include <algorithm>
int main(){
    int n; cin >> n;
    vector<int> L(n);
    for(int i=0; i<n; i++) cin >> L[i];
    sort(L.begin(),L.end());
    long long ans = 0;
    for(int i=0; i<n-2; i++) {
        for(int j=i+1; j<n-1; j++){
            for(int k=j+1; k<n; k++) {
                if(L[i]!=L[j]&&L[j]!=L[k]&&L[i]+L[j]>L[k])ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>

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

using namespace std;

int main() {
    int a, b, c, d, left, right;
    cin >> a >> b >> c >> d;
    left = a+b;
    right = c+d;
    if (left > right) {
        cout << "Left" << endl;
    } else if (left < right) {
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const ll inf=1e18;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c=0,i,n,r;
    cin>>n;
    ll arr[n+1];
    a=1;
    for(i=1;i<=n;i++)cin>>arr[i];
    for(i=1;i<=n;i++)
    {
        if(arr[i]==a)a++;
        else
            c++;
    }
    if(c==n)cout<<-1<<endl;
    else
        cout<<c<<endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long k = Long.parseLong(sc.next());
        long num = a + b;
        if (num >= k) {
            System.out.println(Math.min(a, k));
        } else {
            long num2 = k - num >= c ? c : k - num;
            System.out.println(a - num2);
        }
    }
}

Measured memory_bytes: 35700
#include<bits/stdc++.h>
#define LL long long
#define MOD (1000000007)
using namespace std;

LL n;
map<pair<LL,LL>,int>f;

int DFS(LL u,LL v)
{
	if (!v) return 1;
	if (f[make_pair(u,v)]) return f[make_pair(u,v)];
	int ans=0;
	(ans+=DFS(u>>1,v>>1))%=MOD;
	(ans+=DFS((u-1)>>1,(v-1)>>1))%=MOD;
	if (v>=2) (ans+=DFS(u>>1,(v-2)>>1))%=MOD;
	return f[make_pair(u,v)]=ans;
}

int main()
{
	cin>>n;
	cout<<DFS(n,n)<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < 101; i++) {
            for (int j = 0; j < 101; j++) {
                ans = i * 4 + j * 7;
                if(ans == n) {
                    System.out.println("Yes");
                    return;
                }
                if(ans > n) {
                    break;
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 35648
import numpy as np
N = int(input())
pos = []
for i in range(N):
    pos.append(list(map(int, input().strip().split())))
pos = np.array(pos)
tmp_index = np.arange(N)
xx, yy = np.meshgrid(tmp_index, tmp_index)
distances = np.linalg.norm(pos[xx]-pos[yy], axis=2)

print(distances.mean()*N)

Measured memory_bytes: 12740
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	long double a,b,c;
	cin>>a>>b>>c;
	if(a+2*sqrt(a*b)+b<c) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

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

int main(){

    int cnt=0;
    string s;
    cin>>s;
    
    for(int i=0;i<s.size()/2;i++){
        if(s.at(i)!=s.at(s.size()-1-i)) cnt++;
    }
    cout<<cnt<<endl;



    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    int a,b;
    cin>>a>>b;
    if( 1<= a && a <= 9 && 1<= b && b <= 9){
        cout<<a*b<<endl;
    } else {
        cout<<-1<<endl;
    }

    // cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define debug(x_) cerr << #x_ << ":" << x_ << endl;
#define debug2(x__) for(auto a__ : x__) cerr << a__ << " "; cerr << endl;
#define debug3(x___ , sx___) rep(i, sx___) cerr << x___[i] << " "; cerr << endl;

vector<pii> around = {MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1)};

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    for (auto&& c : s) {
        if (c == '1') c = '9';
        else if (c == '9') c = '1';
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    Rep (i, N) {
        cin >> A[i];
        A[i] %= M;
    }

    vector<ll> s(N+1, 0);
    Rep (i, N) {
        s[i+1] = s[i] + A[i];
        s[i+1] %= M;
    }

    // for (auto e : s) cout << e << "\n";

    map<ll, ll> num;
    for (auto e : s) {
        if (num.find(e) == num.end()) num[e] = 0;
        num[e]++;
    }

    ll ans = 0;
    for (auto e : num) {
        ll value = e.second;
        // cout << value << endl;
        ans += value * (value - 1) / 2;
    }

    cout << ans << "\n";

}

Measured memory_bytes: 5760
N=int(input())
values=input().split()
for i in range(N):
  values[i]=int(values[i])
day=0
yen=1000
while day<N-1:
  if values[day+1]>values[day]:
    stocksbuyable=yen//values[day]
    yen+=stocksbuyable*(values[day+1]-values[day])
  day+=1
print(yen)

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

int A, B, C, D, P;

int main() {
    cin >> A >> B >> C >> D >> P;
    int X = A * P;
    int Y = B;
    if (P > C) Y += (P - C) * D;
    cout << min(X, Y) << endl;
}


Measured memory_bytes: 1164
#pragma GCC target("avx2")  // CPU 処理並列化
#pragma GCC optimize("O3")  // CPU 処理並列化
#pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> lp;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end

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

    ll n;
    in >> n;
    ll a[n];
    ll b[n];
    REP(i, n){
        in >> a[i];
    }
    REP(i, n){
        in >> b[i];
    }
    priority_queue<pair<ll, ll> > q;
    ll cnt = 0;
    REP(i, n){
        q.push(lp(b[i], i));
    }

    ll idx, p_idx, n_idx;
    ll minus, times;
    ll pre_idx = -1;
    while(!q.empty()){
        idx = q.top().second;
        q.pop();

        if(b[idx] == a[idx]) continue;
        p_idx = idx - 1;
        n_idx = idx + 1;
        if(p_idx == -1) p_idx = n - 1;
        if(n_idx == n) n_idx = 0;

        times = 1;
        minus = b[p_idx] + b[n_idx];
        if(b[idx] - minus <= 0 or pre_idx == idx){
            out << "-1" << endl;
            return 0;
        }
        times = min((b[idx] - a[idx]) / minus, ll(ceil((b[idx] - minus) / double(minus))));

        b[idx] -= minus * times;
        // out << idx << " " << b[idx] << endl;
        cnt += times;
        pre_idx = idx;
        if(b[idx] == a[idx]){
            continue;
        }else{
            q.push(lp(b[idx], idx));
        }
    }
    out << cnt << endl;
}


Measured memory_bytes: 9328
def main():
    n=int(input())
    s=input()
    ans=[]
    # print(ord('A'))
    # print(ord('Z'))
    # print(chr(90))
    for i in range(0,len(s)):
        if ord(s[i])+n <= 90:
            tmp=int(ord(s[i]) + n)
            ans.append(chr(tmp))
        else:
            tmp=int(90-ord(s[i])-n)
            tmp2=-1*tmp+64
            ans.append(chr(tmp2))
    for i in range(0,len(ans)):
        print(ans[i],end='')
    print('\n')

if __name__=='__main__':
    main()


Measured memory_bytes: 44656
#include<bits/stdc++.h>
#define dro first
#define adg second.first
#define mog second.second
#define ll long long
using namespace std;

const int N = 500001;

int n,r,pos,l,x,U,D,S;
 
long long ans;
int K;

string s;

int fix[100],fix1[100],A[100],B[100];

int dp[305][305][305];

int main(){
    
    cin>>s;
    
    n=s.size();
    
    cin>>K;
    
    for(int j=0;j<n;j++)
    for(int l=0;l+j<n;l++)
    for(int k=0;k<=K;k++){
        
        int r = l+j;
        
        if(l==r){
            dp[l][r][k] = 1;
            continue;
            //dp[l][r][1] = 1
        }

        if(l+1==r){
            if(k==0){
                dp[l][r][k] = 1;
                if(s[l] == s[r]) dp[l][r][k] = 2;
            } else {
                dp[l][r][k] = 2;
            }
            
            continue;
        }
        
        dp[l][r][k] = max( dp[l+1][r][k], dp[l][r-1][k]);
        //cout<<dp[l+1][r][k]<<" "<<l<<" "<<r<<" "<<k<<endl;
        //cout<<dp[l][r-1][k]<<" "<<l<<" "<<r<<" "<<k<<endl;
        if(s[l]==s[r])
            dp[l][r][k] = max( dp[l][r][k], dp[l+1][r-1][k] + 2);
        else {
            if(k-1>=0)
            dp[l][r][k] = max( dp[l][r][k], dp[l+1][r-1][k-1] + 2);
        }

        //cout<<dp[l][r][k]<<" "<<l<<" "<<r<<" "<<k<<endl;
    }
    
    cout<<dp[0][n-1][K]<<endl;
}





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

public class Main {
  private static boolean solve(int n, char[] cs) {
    if (n % 2 != 0) {
      return false;
    }
    for (int i = 0; i < n / 2; i++) {
      if (cs[i] != cs[n / 2 + i]) {
        return false;
      }
    }
    return true;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    char[] cs = reader.nextCharArray();
    out.println(solve(n, cs) ? "Yes" : "No");
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 22740
result = []
n, x = map(int, input().split())

while (n or x):
    count = 0
    for i in range(n, 0, -1):
        for j in range(1, i):
            k = x - i - j
            if (k > j and k < i):
                count += 1
    result.append(count)
    n, x = map(int, input().split())

for i in result:
    print(i)


Measured memory_bytes: 5596