akhauriyash/Code-Regression huggingface dataset:
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

N = read()
s = [0 if c == "o" else 1 for c in input()]

ans = [0] * N

for a, b in product([0, 1], [0, 1]):
  ans[0:2] = [a, b]
  for i in range(2, N):
    ans[i] = (ans[i-2] + ans[i-1] + s[i-1]) % 2
  b1 = (ans[N-2] + ans[N-1] + ans[0] + s[N-1]) % 2
  b2 = (ans[N-1] + ans[0] + ans[1] + s[0]) % 2
  if b1 == 0 and b2 == 0:
    print("".join("SW"[ans[i]] for i in range(N)))
    exit()


print(-1)


Measured memory_bytes: 6024
import java.util.Scanner;

public class Main {

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

		Integer coins500 = new Integer(scanner.next());
		Integer coins100 = new Integer(scanner.next());
		Integer coins50 = new Integer(scanner.next());
		Integer total = new Integer(scanner.next());

		for(int i = 0; i<= coins500;i++) {
			for(int j= 0;j<=coins100;j++) {
				for(int k = 0; k <=coins50;k++) {
					if(total == (i*500+j*100+k *50)) {
						output ++ ;
					}
				}
			}
		}
		System.out.println(output);
		scanner.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int n;
void solve()
{
    string str;
    cin>>str;
    int i,ans=0;
    for (i=0;i<n;i++)
    {
        int j,num=0;
        vector<int> tag1(26,0),tag2(26,0);
        for (j=0;j<=i;j++)
            tag1[str[j]-'a']++;
        for (j=i+1;j<n;j++)
            tag2[str[j]-'a']++;
        for (j=0;j<26;j++)
            if (tag1[j]&&tag2[j]) num++;
        ans=max(ans,num);
    }
    cout<<ans<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}

Measured memory_bytes: 256
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(Solve());
        Console.Out.Flush();
    }

    static string Solve() {
        var arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int a = arr[0], b = arr[1];
        return a * b % 2 == 0 ? "Even" : "Odd";
    }
}


Measured memory_bytes: 27528
a = int(input())
b = [input() for i in range(a)]
c = ['a']*a
for i in range(a):
    c[i] = b[i][0]
h = c.count('H')
m = c.count('M')
a = c.count('A')
r = c.count('R')
c1 = c.count('C')
ansm = m*a*h + m*a*c1 + m*a*r + m*r*h + m*r*c1 + m*c1*h
ansa = a*r*h + a*r*c1 + a*c1*h
ansr = r*c1*h
print(ansm+ansa+ansr)

Measured memory_bytes: 10540
#include<stdio.h>
int main()
{

    int N,K,s,diff;
    scanf("%d %d",&N,&K);
    if(K>1)
    {
        s=N-(K-1);

    }
    else
        s=1;

    diff=s-1;
    printf("%d",diff);

    return 0;
}


Measured memory_bytes: 128
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

x, n = map(int, input().split())
A = set(map(int, input().split()))
P = [i for i in range(102) if i not in A]
min_dif = (-1, float("inf"))
for i in range(len(P)):
    if abs(x-P[i]) < min_dif[1]:
        min_dif = (P[i], abs(x-P[i]))

print(min_dif[0])


Measured memory_bytes: 68108
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n, m, ans;

int main()
{
    scanf("%d %d", &n, &m);
    if (abs(n - m) > 1)
        printf("0\n");
    else
    {
        ans = 1;
        for (int i = 2; i <= n; ++ i)
            ans = (1LL * ans * i) % mod;
        for (int i = 2; i <= m; ++ i)
            ans = (1LL * ans * i) % mod;
        if (n == m)
            ans = (2LL * ans) % mod;
        printf("%d\n", ans);
    }
    return 0;
}


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

import sys
input = sys.stdin.readline

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(N)]

value = [[-1 for j in range(W + 1)] for i in range(N + 1)]

value[0] = [0 for j in range(W + 1)]
for i in range(1, N + 1):
    for j in range(W + 1):
        w, v = wv[i-1]
        if j >= w:
            value[i][j] = max(value[i-1][j], value[i-1][j-w] + v)
        else:
            value[i][j] = value[i-1][j]

ans = max(value[N])
print(ans)


Measured memory_bytes: 171808
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;

int main()
{
    ll N;
    string res;
    ll tmp;

    cin >> N;

    string S = "";

    while(N != 0)
    {
        //-2のためあまりは-1になることもある
        if(N % 2 != 0)
        {
            S = "1" + S;
            N--;
        }
        else
        {
            S = "0" + S;
        }

        N /= -2;
        
    }
    if(S == "")S = "0";
    cout << S << endl;

}



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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

const ll MOD = 1000000007;
ll prod[500005];

ll powMod(ll n, ll p, ll mod)
{
    ll res = 1;
    while (p)
    {
        if (p & 1)
            (res *= n) %= mod;
        (n *= n) %= mod;
        p >>= 1;
    }
    return res;
}
ll invMod(ll n, ll mod)
{
    return powMod(n, mod - 2, mod);
}

const signed FACT_MAX_N = 2000006;
signed fact[FACT_MAX_N];
signed factInv[FACT_MAX_N];
struct INIT_FACT
{
    INIT_FACT()
    {
        fact[0] = 1;
        for (int i = 1; i < FACT_MAX_N; ++i)
            fact[i] = (long long)i * fact[i - 1] % MOD;
        factInv[FACT_MAX_N - 1] = powMod(fact[FACT_MAX_N - 1], MOD - 2, MOD);
        for (int i = FACT_MAX_N - 2; i >= 0; --i)
            factInv[i] = (long long)(i + 1) * factInv[i + 1] % MOD;
    }
} init_fact;

/* n,r<=10^6, query O(1)*/
ll Permutation(int n, int r)
{
    if (r == 0)
        return 1;
    if (n < r)
        return 0;
    return (long long)fact[n] * factInv[n - r] % MOD;
}
ll Combination(int n, int r)
{
    if (r == 0)
        return 1;
    if (n < r)
        return 0;
    return (long long)fact[n] * factInv[n - r] % MOD * factInv[r] % MOD;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n, m;
    cin >> n >> m;
    prod[m+1] = 1LL;
    prod[m] = m;
    for(ll i=m-1; i>=1; i--)
    {
        prod[i] = (prod[i+1] * i) % MOD;
    }

    ll sum = 0;
    for(int i=0; i<=n; i++)
    {
        ll mult = (i%2 == 0) ? 1LL : MOD-1;
        ll t = (Combination(n, i) * prod[m-i+1]) % MOD;
        t = (t * Permutation(m-i, n-i)) % MOD;
        t = (t * Permutation(m-i, n-i)) % MOD;
        t = (t * mult) % MOD;
        sum = (sum + t) % MOD;
        //cout << sum << "\n";
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 23048
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int n,l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  sort(all(s));
    string t;
    rep(i,n) t+=s[i];
    cout << t << endl;
}


Measured memory_bytes: 256
class itp1_6a:
    def reverse(self,n,a):
        s=""
        for i in range(1,n+1):
            if i==n:
                s+=str(a[-1*i])
            else:
                s+=str(a[-1*i])+" "
        print s
if __name__=="__main__":
    n=input()
    a=map(int,raw_input().split(" "))
    run=itp1_6a()
    run.reverse(n,a)

Measured memory_bytes: 4228
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from collections import deque
from operator import itemgetter

N,M = map(int,input().split())
A = [int(i) for i in input().split()]
A.sort()
BC = [[int(i) for i in input().split()] for _ in range(M)]
BC.sort(reverse=True, key=itemgetter(1))

tmp = deque()
index = 0
# O(N)
for B,C in BC:
    for _ in range(B):
        tmp.append(C)
        index += 1
        if index == N:
            break
    else:
        continue
    break
len_tmp = len(tmp)

for i in range(len_tmp):
    num = tmp.popleft()
    if num > A[i]:
        A[i] = num
    else:
        break

print(sum(A))

Measured memory_bytes: 27292
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
long long dp[110][10][10][2];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	dp[0][0][0][0]=1;
	for(int i=0;i<a;i++){
		for(int j=0;j<b-1;j++){
			for(int k=0;k<b;k++){
				dp[i][j+1][k][0]=(dp[i][j+1][k][0]+dp[i][j][k][0]+dp[i][j][k][1])%mod;
				int to=k;
				if(j+1==to)to--;
				else if(j==to)to++;
				dp[i][j+1][to][1]=(dp[i][j+1][to][1]+dp[i][j][k][0])%mod;
			}
		}
		for(int j=0;j<b;j++){
			dp[i+1][0][j][0]=(dp[i][b-1][j][0]+dp[i][b-1][j][1])%mod;
		}
	}
	printf("%lld\n",dp[a][0][c-1][0]);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split("");
    for(int i=0; i<3; i++) {
      if(str[i].equals("1"))
        str[i]="9";
      else
        str[i]="1";
      System.out.print(str[i]);
    }
  }
}

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

int main(void){
    int N; cin >> N;
    set<int> mochi;

    REP(i, N){
        int tmp; cin >> tmp;
        mochi.insert(tmp);
    }

    cout << mochi.size() << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long N,K;
    cin >> N >> K;
    if(K%2==1){
        cout << (N/K)*(N/K)*(N/K) << endl;
    }else{
        long long n,m;
        n=N/K;
        m=N/(K/2)-n;
        cout << n*n*n+m*m*m << endl;
    }
}


Measured memory_bytes: 256
N = int(input())

dp = [[[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)] for _ in range(N+1)]
# print(dp)

# dp[i][j][k][l]
# iは文字列の長さ
# j,k,lは最後から1,2,3文字目の文字に対応(A,G,C,Tを0,1,2,3にあてた)

# 長さ0の文字列は1通り
dp[0][3][3][3] = 1
MOD = 10**9 + 7

for i in range(N):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                #if dp[i][j][k][l] == 0: # 条件に当てはまるものがない場合はcontinue(これはなくてもok)
                    #continue
                for add in range(4): # (i+1)文字目として新しく追加する文字
                    # ダメな5つの条件を捨てる
                    if add == 2 and j == 1 and k == 0:
                        continue
                    if add == 2 and j == 0 and k == 1:
                        continue
                    if add == 1 and j == 2 and k == 0:
                        continue
                    if add == 2 and j == 1 and l == 0:
                        continue
                    if add == 2 and k == 1 and l == 0:
                        continue
                    # ダメな条件を抜けたらaddをi+1番目に足した文字列の個数として数える
                    # S = ...j,k,l から S = ...j,k,l,add へ
                    dp[i+1][add][j][k] += dp[i][j][k][l]
                    dp[i+1][add][j][k] %= MOD

ans = 0
for j in range(4):
    for k in range(4):
        for l in range(4):
            ans += dp[N][j][k][l]
            ans %= MOD

print(ans)

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

typedef long long ll;
typedef pair<int, int> ii;

const int N = 200001;
int n, tmp;
ll k;
int neg[N];
int pos[N];
int ncnt;
int pcnt;
int zero;

int bs(int *v, int size, ll t) {
    int l = 0, r = size - 1;
    if (v[0] > t) return -1;
    while (l < r) {
        int m = (r - l + 1) / 2 + l;
        if (v[m] > t) {
            r = m - 1;
        } else {
            l = m;
        }
    }
    return l;
}

// find >= t
int bs2(int *v, int size, ll t) {
    int l = 0, r = size - 1;
    if (v[size - 1] < t) return -1;
    while (l < r) {
        int m = (r - l) / 2 + l;
        if (v[m] < t) {
            l = m + 1;
        } else {
            r = m;
        }
    }
    return l;
}

ll count_neg(ll num) {
    ll cnt = 0;
    for (int i = 0; i < ncnt; ++i) {
        ll a = neg[i];
        ll b = num / a;
        if (a * b < num) b++;
        int j = bs2(pos, pcnt, b); // >= b
        if (j != -1) {
            cnt += pcnt - j;
        }
    }
    return cnt;
}

ll count_pos(ll num) {
    ll cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < ncnt; ++i) {
        ll a = neg[i];
        ll b = num / a;
        int j = bs(neg, ncnt, b);
        if (j != -1) {
            cnt1 += j + 1;
            if (a <= b)
                cnt1 --;
        }
    }
    for (int i = 0; i < pcnt; ++i) {
        ll a = pos[i];
        ll b = num / a;
        int j = bs(pos, pcnt, b);
        if (j != -1) {
            cnt2 += j + 1;
            if (a <= b)
                cnt2 --;
        }
    }

    return (cnt1 + cnt2) / 2;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> tmp;
        if (tmp < 0) {
            neg[ncnt++] = -tmp;
        } else if (tmp == 0) {
            ++zero;
        } else {
            pos[pcnt++] = tmp;
        }
    }
    // (n - 1) + (n - 2) + (n - 3) + ... (n - k) zero count
    ll zcnt = 1LL * ((n - 1) + (n - zero)) * zero / 2;
    sort(neg, neg + ncnt);
    sort(pos, pos + pcnt);
    ll nrcnt = 1LL * ncnt * pcnt; // count of negative pair
    if (k <= nrcnt) { // neg
        ll l = 1;
        ll r = 1e18;
        while (l < r) {
            ll m = (r - l + 1) / 2 + l;
            if (count_neg(m) < k) { // find num ge than m
                r = m - 1;
            } else {
                l = m;
            }
        }
        cout << -l << endl;
    } else if (k <= nrcnt + zcnt) {
        cout << 0 << endl;
    } else { // pos
        k -= nrcnt + zcnt;
        ll l = 1;
        ll r = 1e18;
        while (l < r) {
            ll m = (r - l) / 2 + l;
            if (count_pos(m) < k) {
                l = m + 1;
            } else {
                r = m;
            }
        }
        cout << l << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
def main():
  import sys
  import numpy as np
  input=sys.stdin.readline
  h,w=map(int,input().split())
  meize=[list(input()) for i in range(h)]
  mod=10**9+7

  dp=[[0]*(1+w) for i in range(1+h)]

  dp[0][1]=1
  for i in range(h):
    for j in range(w):
      if meize[i][j]=='#':
        dp[i+1][j+1]=0
      else:
        dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]
        dp[i+1][j+1]%=mod

  print(dp[h][w]%mod)
  
if __name__=='__main__':
  main()

Measured memory_bytes: 60524
#include <iostream>
#include <string>
#include <vector>

int main()
{
    int N, Q;
    std::cin >> N >> Q;
    std::string S;
    std::cin >> S;

    std::vector<int> C(S.size()+1);
    C[0] = 0;
    C[1] = 0;
    for (int i = 1; i < S.size(); i++) {
        C[i+1] = (S[i-1] == 'A' && S[i] == 'C') ? C[i]+1 : C[i];
    }

    int l, r;
    for (int i = 0; i < Q; i++) {
        std::cin >> l >> r;
        int num = C[r] - C[l];
        std::cout << num << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main()
{
    int N;
    int temp;
    int temp2;
    int ans;

    scanf("%d\n",&N);

    ans=0;
    temp=N/1000;

    if(temp==2){
        ans++;
    }    

    temp2=N%1000;
    temp=temp2/100;

    if(temp==2){
        ans++;
    }    

    temp2=temp2%100;
    temp=temp2/10;

    if(temp==2){
        ans++;
    }    

    temp2=N%10;

    if(temp2==2){
        ans++;
    }    

    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cmath>
#include<cstring>
#include<map>
#include<queue>
#include<iostream>
#include<algorithm>
int main(){ 
    int a,b,t;
    scanf("%d %d",&a,&b);
    t = a + b;
        printf("%d",t % 24);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;





int main(){

	int table[26];
	for(int i = 0; i < 26; i++){

		table[i] = BIG_NUM;
	}

	int N;
	scanf("%d",&N);

	char buf[55];
	int work[26];

	for(int i = 0; i < N; i++){

		scanf("%s",buf);
		for(int k = 0; k < 26; k++){

			work[k] = 0;
		}
		for(int k = 0; buf[k] != '\0'; k++){

			work[buf[k]-'a']++;
		}
		for(int k = 0; k < 26; k++){

			table[k] = min(table[k],work[k]);
		}
	}

	for(int i = 0; i < 26; i++){
		if(table[i] == 0)continue;

		for(int k = 0; k < table[i]; k++){

			printf("%c",'a'+i);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

//問題文より、入力される表の最大の大きさ(100)+1の大きさを要素数とする
#define MAX_ROW 101
#define MAX_COLUMN 101

//関数プロトタイプ宣言
void set_sum(long int body[MAX_ROW][MAX_COLUMN], int row, int column);

//表の構造体
typedef struct{
	int row;
	int column;
	long int body[MAX_ROW][MAX_COLUMN];
}Table;

int main(void)
{
	//メンバーを0で初期化
	Table new_table = {0, 0, 0};

	//ループ変数
	int i, j;

	//表の大きさを入力
	scanf("%d %d", &new_table.row, &new_table.column);

	//表のデータを入力
	for(i = 0; i < new_table.row; i++){
		for(j = 0; j < new_table.column; j++){
			scanf("%ld", &(new_table.body[i][j]));
		}
	}
	//各行列の合計値をセット
	set_sum(new_table.body, new_table.row, new_table.column);

	//表のデータを出力
	for(i = 0; i < (new_table.row + 1); i++){
		for(j = 0; j < new_table.column; j++){
			printf("%ld ", new_table.body[i][j]);
		}
		//最後の数値の後にスペースがある場合はエラーとなる
		printf("%ld\n", new_table.body[i][j]);
	}

	return 0;
}

//表に合計値を挿入する関数
void set_sum(long int body[MAX_ROW][MAX_COLUMN], int row, int column)
{
	//ループ変数
	int i, j;

	for(i = 0; i < row; i++){
		for(j = 0; j < column; j++){
			//行の合計値
			body[i][column] += body[i][j];
			//列の合計値
			body[row][j] += body[i][j];
		}
		//行列全体の合計値
		body[row][column] += body[i][column];
	}
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

vector<vector<int>> dis(2,vector<int>(100010));
vector<vector<int>> to(100010);

void memo_depth(int a,int b,int d,int p = -1){
    dis[b][a] = d;
    for(auto r:to[a]){
        if(r == p) continue;
        memo_depth(r,b,d+1,a);
    }
}

int main(){
    int n,u,v;
    cin >> n >> u >> v;
    u--;v--;
    int ans = 0;
    for(int i = 0; i < n-1; i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    memo_depth(u,0,0);
    memo_depth(v,1,0);
    if(to[u].size() == 1){
        for(auto p:to[v]){
            if(p == to[u][0]){
                cout << 1 << endl;
                return 0;
            }
        }
    }
    for(int i = 0; i< n; i++){
        if(dis[0][i] < dis[1][i]) ans = max(ans,dis[1][i]-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11640
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define MOD 100000
typedef long long ll;
typedef pair < int , int > Pii;
int main(){
	string want;
	cin >> want;
	int n;
	scanf("%d",&n);
	int ans = 0;
	rep(i,n){
		string str;
		cin >> str;
		str += str;
		int len = str.size();
		rep(j,len){
			bool flg = false;
			if(str[j] == want[0]){
				reps(k,j,j+want.size()){
					if(str[k] != want[k-j])flg = true;
				}
				if(!flg){
					ans++;
					break;
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 2003;
//#define int long long
const ll INF = 1e18;

ll dp[MAXN][MAXN];

void solve(){
  int n, x;
  cin >> n >> x;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  ll mn = INF;
  int ind = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < mn) {
      mn = a[i];
      ind = i;
    }
  }

  memset(dp, 0x3f3f3f, sizeof dp);
  for (int i = 0; i < n; i++){
    dp[ind][i] = mn;
  }

  auto next = [&](int i){
    return (i + 1) % n;
  };

  auto prev = [&](int i){
    return (i - 1 + n) % n;
  };

  int i = next(ind);
  while (i != ind){
    ll mnv = INF;
    for (int k = 0; k < n; k++){
      mnv = min(mnv, a[(i - k + n) % n]);
      dp[i][k] = dp[prev(i)][k] + mnv;
    }
    i = next(i);
  }

  ll ans = INF;
  for (int i = 0; i < n; i++){
    ans = min(ans, dp[prev(ind)][i] + (ll)x * (ll)i);
  }

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

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

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

    solve();

    return 0;
}


Measured memory_bytes: 35016
class WeighttedUnionFind:
	def __init__(self, n):
		self.par = [i for i in range(n+1)]
		self.rank = [0] * (n+1)
		#根への距離を管理
		self.weight = [0] * (n+1)

	#検索
	def find(self, x):
		if self.par[x] ==x:
			return x
		else:
			y = self.find(self.par[x])
			#根への重みを追加しながら根まで走査
			self.weight[x] +=self.weight[self.par[x]]
			self.par[x] = y
			return y

	def union(self, x, y, w):
		rx = self.find(x)
		ry = self.find(y)

		#xの木の高さ < yの木の高さ
		if self.rank[rx] < self.rank[ry]:
			self.par[rx] = ry
			self.weight[rx] = w - self.weight[x] + self.weight[y]

		#xの木の高さ>=yの木の高さ
		else:
			self.par[ry] = rx
			self.weight[ry] = -w - self.weight[y] + self.weight[x]
			#木の高さが同じだった場合の処理
			if self.rank[rx] == self.rank[ry]:
				self.rank[rx] +=1
	#同じ集合に属するか
	def same(self, x, y):
		return self.find(x) == self.find(y)
	#xからyへのコスト
	def diff(self, x, y):
		return self.weight[x] - self.weight[y]

N, M = map(int, input().split())
wuf = WeighttedUnionFind(N)

for _ in range(M):
	l, r, d = map(int, input().split())

	if not wuf.same(l, r):
		wuf.union(l, r, d)

	else:
		if wuf.diff(l, r) !=d:
			print("No")
			exit()
print("Yes") 


Measured memory_bytes: 84264
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	int N;	cin >> N;
	vector<pair<int,int>> place(N);
	REP(i, N){
	 int x, y;	cin >> x >> y;
	 place[i].first = x;  place[i].second = y;
	}

	// mod = N!
	int mod = 1;
	for(int i = 2 ; i <= N ; i++)  mod *= i;
	
	long double ans = 0;
	for(int i = 0 ; i < N - 1 ; i++){
	 for(int j = i + 1 ; j < N ; j++){
	  long double x = (place[i].first - place[j].first) * (place[i].first - place[j].first);
	  long double y = (place[i].second - place[j].second) * (place[i].second - place[j].second);

		ans += 2 * (mod / N) * sqrt(x + y);
	 }
	}

	printf("%.7lf\n", (double)(ans/mod));

	return 0;
}

Measured memory_bytes: 256
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         fozubaoyou    pass System Test!
*/


//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int r;
    cin >> r;
    double ans = 2*r*PI;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3760
s= input()
if len("".join(set(s)))==2 :
  if s[0]==s[1]:
    if s[2]==s[3]:
      print("Yes")
    else:
      print("No")
  elif s[0]==s[2]:
    if s[1]==s[3]:
      print("Yes")
    else:
      print("No")
  elif s[0]==s[3]:
    if s[1]==s[2]:
      print("Yes")
    else:
      print("No")
else:
  print("No")

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

using LL = long long;

const int N = 100000;

struct Info
{
    LL sum, need;
};

int n, m, a[N], b[N], ord[N], par[N];
Info info[N];
std::vector<int> graph[N];

bool by_a(int i, int j)
{
    return std::max(a[i] - b[i], 0) < std::max(a[j] - b[j], 0);
}

int find(int u)
{
    if (par[u] != u) {
        par[u] = find(par[u]);
    }
    return par[u];
}

int main()
{
#ifdef LOCAL_JUDGE
    freopen("D.in", "r", stdin);
#endif
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++ i) {
        scanf("%d%d", a + i, b + i);
        ord[i] = i;
    }
    for (int i = 0; i < m; ++ i) {
        int u, v;
        scanf("%d%d", &u, &v);
        u --;
        v --;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    std::sort(ord, ord + n, by_a);
    LL need = 0;
    memset(par, -1, sizeof(par));
    for (int idx = 0; idx < n; ++ idx) {
        int r = ord[idx];
        par[r] = r;
        std::vector<Info> sons;
        LL tot_sum = 0;
        for (int v : graph[r]) {
            if (~par[v] && find(r) != find(v)) {
                int u = find(v);
                sons.push_back(info[u]);
                tot_sum += info[u].sum;
                par[u] = r;
            }
        }
        need = tot_sum + std::max(a[r], b[r]);
        for (auto s : sons) {
            need = std::min(need, tot_sum - s.sum + std::max((LL)a[r], s.need + b[r]));
        }
        info[r].sum = tot_sum + b[r];
        info[r].need = need;
    }
    printf("%lld\n", need);
}

Measured memory_bytes: 10228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if(d2==1) cout<<1;
    else cout<<0;
}



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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }

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

    int N, K;
    std::cin >> N >> K;

    std::vector<int> H(N);
    REP(i, N) {
        std::cin >> H[i];
    }

    int ans = 0;
    REP(i, N) {
        if(K <= H[i]) ans++;
    }

    std::cout << ans << std::endl;

    return 0;
}


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

int main() {
  long long a,b,c;
  cin>>a>>b>>c;
  if((a%2==0 || b%2==0) || c%2==0) cout<<0<<endl;
  else{
    long long ans=min({a*b,b*c,c*a});
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 256
import java.util.*

val limit = 100010


class Connection(connect: Int, distance: Long) {
    val connect = connect
    val distance = distance
}

//val connect = Array<MutableList<Int>>(limit, { mutableListOf() })
//val distance = Array<MutableList<Long>>(limit, { mutableListOf() })

val connections = Array<MutableList<Connection>>(limit, { mutableListOf() })

val distanceFromRoot = Array<Long>(limit, { 0 })

fun getDistanceFromRoot(now: Int, parent: Int, nowDistance: Long) {
    distanceFromRoot[now] = nowDistance
    for (i in 0..connections[now].size - 1) {
        if (connections[now][i].connect == parent) {
            continue
        }
        getDistanceFromRoot(connections[now][i].connect, now, nowDistance + connections[now][i].distance)
    }
}

fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    
    for (i in 1..n-1) {
        val a = cin.nextInt() - 1
        val b = cin.nextInt() - 1
        val c = cin.nextLong()

        //connect[a].add(b)
        //connect[b].add(a)
        //distance[a].add(c)
        //distance[b].add(c)
        connections[a].add(Connection(b, c))
        connections[b].add(Connection(a, c))
    }

    val q = cin.nextInt()
    val k = cin.nextInt() - 1

    getDistanceFromRoot(k, -1, 0)

    /* 幅優先の木の構築
    val parent = Array<Int>(n, { -1 })
    val queue: MutableList<Int> = mutableListOf(k)

    while (queue.size != 0) {
        val now = queue.removeAt(0)
        for (i in 0..connect[now].size - 1) {
            val children = connect[now]
            if (children[i] != parent[now]) {
                distanceFromRoot[children[i]] = distanceFromRoot[now] + distance[now][i]
                queue.add(children[i])
                parent[children[i]] = now
            }
        }
    }
    */

    for (i in 0..q-1) {
        val x = cin.nextInt() - 1
        val y = cin.nextInt() - 1
        println(distanceFromRoot[x]+distanceFromRoot[y])
    }
}

Measured memory_bytes: 139424
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size(), r[n], l[n], ans[n] = {};
  r[0] = 0;
  l[n - 1] = n - 1;
  FOR(i, 1, n) r[i] = s[i] == 'R' ? i : r[i - 1];
  for(int i = n - 2; i > -1; i--) l[i] = s[i] == 'L' ? i : l[i + 1];
  REP(i, n) s[i] == 'R'
    ? (l[i] - i) % 2 == 0 ? ans[l[i]]++ : ans[l[i] - 1]++
    : (i - r[i]) % 2 == 0 ? ans[r[i]]++ : ans[r[i] + 1]++;
  REP(i, n) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<vector>
#include<tuple>
using namespace std;
//アイデア　多重配列にしてソート、番号抜いて最大値取得
int main(){
  int n;
  cin >> n;

  vector<int> a(n+1);
  vector<int> b(n+1);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  b=a;
  sort(b.begin(),b.end(),greater<int>());
  if(b.at(0) == b.at(1)){
    for(int i=0;i<n;i++){
      cout << b.at(0) << endl;
    }
  }
    else{
      for(int i=0;i<n;i++){
        if(a.at(i) == b.at(0)){
        cout << b.at(1) << endl;
      }else{
        cout << b.at(0) << endl;
      }
    }
  }
}


Measured memory_bytes: 3200
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            HashSet<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                if (set.contains(a))
                    set.remove(a);
                else
                    set.add(a);
            }
            out.println(set.size());
        }

    }

    static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream is) {
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            this.br = br;
        }

        public String next() {
            if (st == null || !st.hasMoreTokens()) {
                String nextLine = null;
                try {
                    nextLine = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (nextLine == null)
                    return null;
                st = new StringTokenizer(nextLine);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 42720
n = gets.chomp.to_i
v_arr = gets.chomp.split(" ").map(&:to_i).sort

(1..n-1).each do |t|
  v1 = v_arr.shift
  v2 = v_arr.shift
  v_arr.unshift((v1 + v2) / 2.to_f)
end

puts v_arr[0]


Measured memory_bytes: 1788
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int n;
    cin >> n;
    if(n%2==0) cout << n << endl;
    else cout << n*2 << endl;
}

Measured memory_bytes: 256
def solve(n, a_list):
    numbers_map = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
    usable_map = {}
    for a in a_list:
        usable_map[a] = numbers_map[a]

    # 1-origin 桁数を保存 -infで初期化
    inf = 1000
    dp = [0] + [-inf for _ in range(n)]
    for value in usable_map.values():
        if value <= n:
            dp[value] = 1

    # time O(NM)
    for cost in range(1, n + 1):
        for value in usable_map.values():
            if cost - value < 0 or dp[cost - value] == 0:
                continue
            dp[cost] = max(
                dp[cost],
                dp[cost - value] + 1
            )

    # time O(M log(M))
    buff = []
    digit = n
    reverse_usable_list = sorted(usable_map.items(), reverse=True)
    while True:
        for num, value in reverse_usable_list:
            if digit - value < 0 or dp[digit] - 1 != dp[digit - value]:
                continue
            buff.append(str(num))
            digit -= value
            break
        if digit <= 0:
            break

    return "".join(buff)


def main():
    n, m = map(int, input().split())
    a_list = list(map(int, input().split()))

    ans = solve(n, a_list)
    print(ans)


main()


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int n;cin>>n;
    vector<string> v1,v2;
    for(int i=0;i<n;i++){
        string s;cin>>s;
        string t="";
        string t2="";
        for(auto c:s){
            if(c=='?'){
                t.push_back('a');
                t2.push_back('z');
            }else{
                t.push_back(c);
                t2.push_back(c);
            }
        }
        v1.push_back(t);
        v2.push_back(t2);
    }
    string t;cin>>t;
    sort(all(v1));
    sort(all(v2));
    int a=0,b=0;
    for(auto s:v1){
        if(s>=t){
            break;
        }
        a++;
    }
    for(auto s:v2){
        if(s>t){
            break;
        }
        b++;
    }
    for(int i=min(a,b);i<=max(a,b);i++){
        cout<<i+1;
        if(i!=max(a,b))cout<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  int n;cin>>n;
  int p[n+10];
  REP(i,n) cin>>p[i];
  int cnt = 0;
  for(int j=0;j<n-2;++j) {
    if(p[j]<p[j+1]&&p[j+1]<p[j+2]) cnt += 1;
    else if(p[j]>p[j+1]&&p[j+1]>p[j+2]) cnt += 1;
  }
  pr(cnt);
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
    ll n;
    cin >> n;
    vi a(n+1),b(n+1);
    rep(i,n+1){
        ll nn;
        cin >> nn;
        a[i] = nn;
    }
    rep(i,n){
        ll nn;
        cin >> nn;
        b[i+1] = nn;
    }
    ll count = 0;
    for(int i = 1; i <= n;i++){
        count += min(a[i-1],b[i]);
        b[i] -= min(a[i-1],b[i]);
        count += min(a[i],b[i]);
        a[i] -= min(a[i],b[i]);
    }
    cout << count << endl;
}

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


Measured memory_bytes: 1024
n = STDIN.gets.chomp.to_i
ci = STDIN.gets.chomp.split(" ").map{ |c| c.to_i }
vi = STDIN.gets.chomp.split(" ").map{ |v| v.to_i }

sum = 0

ci.each_with_index{ |c, idx| sum += (c - vi[idx]) if (c - vi[idx] > 0) }
p sum

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


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

    ll ans = 0,n;
    cin>>n;
    rep(i,n+1){
        if(i%3 != 0 && i%5 != 0){
            ans += i;
        }
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 3636
import java.util.Scanner;



public class Main {

	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i=1;i<=n-1;i++) {
			String[] str = new String[n-i];
			for (int j=i+1;j<=n;j++) {
				for (int k=0;k<10;k++) {
					if (((i^j)>>k)%2 != 0) {
						str[j-i-1]=Integer.toString(k+1);
						break;
					}
				}
			}
			System.out.println(String.join(" ", str));
		}
		
		
	}

	
}







Measured memory_bytes: 32428
#include <stdio.h>
int main() {
  int n;
  int i;
  int flag = 1;

  scanf ("%d", &n);


  for (i = 9; i > 1; i--) {
    if (n % i == 0 && flag == 1){
      n = n / i;
      flag = 0;
    }
  }

  if (0 < n && n < 10) printf ("Yes\n");
  else printf ("No\n");

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 30;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  map<ll, int> mp;
  rep(i, n) {
    ll a; cin >> a;
    ++mp[a];
  }
  int ans = 0;

  for(int k = 40; k > 0; --k) {
    ll sum = 1ll<<k;
    for(auto x : mp) {
      if(x.second == 0) continue;
      if(x.first*2 == sum) {
        int add = x.second/2;
        ans += add;
        mp[x.first] -= add*2;
      }
      else {
        if(mp.find(sum-x.first) != mp.end()) {
          auto p = *mp.find(sum-x.first);
          int add = min(x.second, p.second);
          ans += add;
          mp[x.first] -= add;
          mp[p.first] -= add;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 16060
import numpy as np
n, k = (int(x) for x in input().split())
d = np.zeros(k)
a = np.zeros(n)
for i in range(k):
    d[i] = int(input())
    a_s = (int(x) for x in input().split())
    for i_a, a_ss in enumerate(a_s):
        a[a_ss-1] += 1

print(np.count_nonzero(a == 0))

Measured memory_bytes: 27136
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define SWAP(type,a,b) { type temp = a; a = b; b = temp; }

int main(void) {
	// your code goes here
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(c>=a&&c<=b) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 200001
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        int n,x;
        cin>>n>>x;
        cout<<min(x-n%x,n%x);
    }
}

Measured memory_bytes: 256
from sys import stdin

def readString() :
    return  stdin.readline().rstrip()

def solve() :
    S = "CODEFESTIVAL2016"
    T = stdin.readline().rstrip()
    ans = 0 
    for x in range(len(S)):
        if(S[x] != T[x]) :
            ans += 1

    print(ans)

solve()

Measured memory_bytes: 38256