akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>

using namespace std;

void dice(){
        int d1,d2,d3,d4,d5,d6;
        cin >> d1 >> d2 >> d3 >> d4 >> d5 >> d6; 
    
        char dir;
        int tmp;
        while (true){
                cin >> dir;
                if (cin.eof()) break;   
                if (dir == 'E') {
                        tmp = d1; d1 = d4; d4 = d6; d6 = d3; d3 = tmp;    
                }else if (dir == 'N'){
                        tmp = d1; d1 = d2; d2 = d6; d6 = d5; d5 = tmp;
                }else if (dir == 'S'){
                        tmp = d1; d1 = d5; d5 = d6; d6 = d2; d2 = tmp;
                }else if (dir == 'W'){
                        tmp = d1; d1 = d3; d3 = d6; d6 = d4; d4 = tmp;
                }   
        }   
        cout << d1 << endl;
}

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

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

int main() {
    int N;
    cin >> N;
    vector<int> T(N);
    int sum = 0;
    for(int i=0; i<N; ++i) {
        cin >> T[i];
        sum += T[i];
    }
    int M;
    cin >> M;
    vector<int> P(M), X(M);
    for(int i=0; i<M; ++i) {
        cin >> P[i] >> X[i];
        P[i]--;
    }
    for(int i=0; i<M; ++i) {
        cout << sum - T[P[i]] + X[i] << endl;
    }
}


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

int main(){
    int h,w;
    while(1){
        cin>>h>>w;
        if(h==0 && w==0)break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cout<<"#";
            }cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3076
import math
a, b, h, m = map(int, input().split())

alpha = 60 * h + m
beta = m
base = abs(math.pi * alpha / 360 - math.pi * beta / 30)
th = min(base,2*math.pi - base)

print(math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(th)))

Measured memory_bytes: 9504
#include<stdio.h>
#include<string.h>
int main(){
int n,i,sum;
char s[100];
while(~scanf("%s",s)){
    sum=0;
    for(i=0;i<strlen(s)/2;i++){
        if(s[i]!=s[strlen(s)-i-1]){
            sum++;
        }
    }
printf("%d\n",sum);
}
return 0;
}


Measured memory_bytes: 128
fun main(args:Array<String>) {
    val abcde = (1..5).map { readLine()!!.toInt() }
    val fix = abcde.map { ((it + 9)/10)*10 }
    val ans = fix.sum() - abcde.indices.map { fix[it] - abcde[it] }.max()!!
    println(ans)
}


Measured memory_bytes: 33816
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000001

int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<vector<vector<long long>>> dp(M+1,vector(N+1,vector<long long>(N+1,0)));
	
	dp[0][N-1][1] = 1;
	
	for(int i=0;i<M;i++){
		for(int j=0;j<=N;j++){
			for(int k=0;k<=N;k++){
				if(dp[i][j][k]==0)continue;
				if(j!=0)dp[i+1][j-1][k] = mod(dp[i+1][j-1][k]+mod(dp[i][j][k]*j));
				dp[i+1][j][N-j] = mod(dp[i+1][j][N-j]+mod(dp[i][j][k]*k));
				if(N-j-k>=0)dp[i+1][j][k] = mod(dp[i+1][j][k]+mod(dp[i][j][k]*(N-j-k)));
			}
		}
	}
	
	long long ans = 0LL;
	
	cout<<dp.back()[0][N]<<endl;
	
	return 0;
}


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


int main()
{
  int n,i=3;
  cin>>n;
  vector<int>v(4);
  while(n){
    v[i]=n%10;
    n/=10;
    i--;
  }
  
  int f=(v[1]*1)+v[0]*10;
  int s=(v[3]*1)+v[2]*10;
  
  if(f<=12&&s>12)
  {
      if(f!=0)
     cout<<"MMYY"<<endl; 
     else cout<<"NA"<<endl;
  }
  
  else if(f>12&&s<=12)
  {
      if(s!=0)
      cout<<"YYMM"<<endl;
      else cout<<"NA"<<endl;
  }
  
  else if(f==0&&s!=0)
  {
      cout<<"YYMM"<<endl;}
      else if(f!=0&&s==0)
  {
      cout<<"MMYY"<<endl;}
      else if(f>12&&s>12)
      {
          cout<<"NA"<<endl;
      }
      
      else if(f<=12&&s<=12)
      {
          if(f==0&&s==0)
          cout<<"NA"<<endl;
          else cout<<"AMBIGUOUS"<<endl;
      }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int d;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if(a > b){
		d = a;
		a = b;
		b = d;
	}
	if (b > c){
		d = b;
		b = c;
		c = d;
	}
	if(a > b){
		d = a;
		a = b;
		b = d;
	}
	printf("%d %d %d\n", a, b, c);
	
	return (0);
}

Measured memory_bytes: 596
import bisect

A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]

for i in range(Q):
    x = X[i]
    s_index = bisect.bisect_left(s, x)
    t_index = bisect.bisect_left(t, x)

    if s_index == 0:
        s_left = -float("inf")
    else:
        s_left = s[s_index - 1]
    
    if s_index == A:
        s_right = float("inf")
    else:
        s_right = s[s_index]
        
    if t_index == 0:
        t_left = -float("inf")
    else:
        t_left = t[t_index - 1]

    if t_index == B:
        t_right = float("inf")
    else:
        t_right = t[t_index]

    ans = float("inf")

    if s_index != 0 and t_index != 0:
        ans = x - min(s_left, t_left)

    if s_index != 0 and t_index != B:
        temp = min(x - s_left, t_right - x)
        ans = min(ans, (x - s_left) + (t_right - x) + temp)

    if s_index != A and t_index != 0:
        temp = min(x - t_left, s_right - x)
        ans = min(ans, (x - t_left) + (s_right - x) + temp)

    if t_index != B and s_index != A:
        ans = min(ans, max(s_right, t_right) - x)

    print(ans)

Measured memory_bytes: 16152
import math
from collections import deque
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
S = np.sum(A)
cut = K*A//S

length = []
for k in range(N):
  length.append([A[k] / (cut[k]+1), k])

length.sort(key = lambda x: x[0], reverse=True)

def nibun_insert(lis, item):
  end = len(lis)
  start = 0
  now = (end+start)//2
  while end > start+1:
    if lis[now][0] > item[0]:
      start = 0 + now
      now = (now + end)//2
    else:
      end = 0 + now
      now = (now + start)//2
  lis.insert(now+1, item)
  return lis

C = np.sum(cut)
res = K - C
length = length[:res+1]
length = deque(length)
for _ in range(res):
  a = length.popleft()
  cut[a[1]] += 1
  a[0] = a[0]*cut[a[1]]/(cut[a[1]]+1)
  if a[0] <= length[-1][0]:
    continue
  elif a[0] >= length[0][0]:
    length.appendleft(a)
  else:
    length = nibun_insert(length, a)
  length.pop()

print(math.ceil(length.popleft()[0]))

Measured memory_bytes: 64408
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int x, y;
    cin >> x >> y;
    if ((y - 2 * x >= 0 && (y - 2 * x) % 2 == 0) &&
        (4 * x - y >= 0 && (4 * x - y) % 2 == 0)){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
      return 0;
}

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

#############
# Libraries #
#############

import math

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

#############
# Main Code #
#############

k,q = map(int, input().split())
d = list(map(int, input().split()))

def query(n,x,m):
  x %= m
  ans = n-1
  n -= 1
  s1 = 0
  t1 = 0
  for i in range(k):
    s1 += d[i] % m
    if d[i] % m == 0:
      t1 += 1
  s2 = 0
  t2 = 0
  for i in range(n%k):
    s2 += d[i] % m
    if d[i] % m == 0:
      t2 += 1
  x += s1 * (n//k) + s2
  ans -= x//m
  ans -= t1 * (n//k) + t2
  
  print(ans)
  
    

for _ in range(q):
  n,x,m = map(int, input().split())
  query(n,x,m)


Measured memory_bytes: 49116
#include <iostream>
#include <vector>
#include <algorithm>
#define FIN freopen("inputs.txt", "r", stdin)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int main(){
// FIN;
    int n, k;
    cin>>n>>k;
    ll hp[200009];
    if(k >= n){
        cout<<"0\n";
        return 0;
    }
    for (int i = 0; i < n; i++)
        cin>>hp[i];
    sort(hp, hp + n, greater<long long>());
    ll ans = 0;
    for (int i = k; i < n; i++)
    {
        ans += hp[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int N;
int A[200];
int ans;
bool check() {
	for (int n = 0; n < N; ++n) {
		if (A[n] % 2 == 1) return false;
		A[n] >>= 1;
	}
	return true;
}
int main(void) {
	cin >> N;
	for (int n = 0; n < N; ++n) cin >> A[n];
	while (check()) ++ans;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
d = list(int(i) for i in input().split())
ans = 0

for i in range(n-2):
  if d[i] < d[i+1] and d[i+1] < d[i+2]:
      ans += 1
  elif d[i] > d[i+1] and d[i+1] > d[i+2]:
      ans += 1


print(ans)

Measured memory_bytes: 3060
n,k = map(int,input().split())
cnt = 0
snuke = [0]*n
for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    for j in a:
        snuke[j-1] += 1
for i in snuke:
    if i == 0:
        cnt += 1
print(cnt)
        

Measured memory_bytes: 67824
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
LL a[SIZE];
int main(){
    LL N,M;
    R(N,M);
    LL x=1;
    REP(i,N){
        LL v;
        R(v);
        a[i]=v/2;
        x=x/__gcd(x,v/2)*v/2;
        if(x>M){
            W(0);
            return 0;
        }
    }
    REP(i,N){
        if(x/a[i]%2==0){
            W(0);
            return 0;
        }
    }
    W(((M/x)+1)/2);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
#include<string>
#define int long long
#define ll long long
#define vel vector<long long>
#define veb vector<bool>
#define vvel vector<vel>
#define pin pair<int,int>
#define ppin pair<pin,int>
#define qin pair<ll,pin>
#define mkp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define V vector
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
using namespace std;
vel pa;
int INF = 1000000000 + 1;
vel hpn;
int mx1 = 0;
vel num; vel x;
ll p = 998244353;
ll th = 3;
void ref(int &n) { n = n % p; n = (n + p) % p; }
int rui(int n, int ru) {
	if (ru == 0) { return 1; }
	int qans = rui(n, ru / 2);
	qans *= qans; ref(qans);
	int bai = 1;
	if (ru % 2 == 1) { bai = n; }
	return (qans*bai) % p;
}
signed main() {
	int n; cin >> n;
	vel a(n); int sum = 0;
	rep(i, n) { cin >> a[i]; sum += a[i]; }
	int qans = 0;
	int mx = n * 300;
	vvel dp(n + 1, vel(n * 300 + 1, 0)); dp[0][0] = 1;
	vvel qdp = dp;
	for (int i = 1; i <= n; i++) {
		rep(j,mx+1){
			dp[i][j] = dp[i - 1][j] * 2;
			if (j >= a[i - 1]) { dp[i][j] += dp[i - 1][j - a[i - 1]]; }
			ref(dp[i][j]);
			qdp[i][j] = qdp[i - 1][j];
			if (j >= a[i - 1]) { qdp[i][j] += qdp[i - 1][j - a[i - 1]]; }
			ref(qdp[i][j]);
		}
	}
	for (int i = (sum + 1) / 2; i <= mx; i++) { qans += th*dp[n][i]; ref(qans); }
	if (sum % 2 == 0) {
		qans -= th * qdp[n][sum / 2];
		ref(qans);
	}
	int ans = rui(3, n);
	ans -= qans; ref(ans);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 423872
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

ll lcm(ll a, ll b){
    return a*b / gcd(a,b);
}

int main() {
    ll A, B; cin >> A >> B;
    cout << lcm(A, B) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int q;
    cin >> q;
    long long l = 0, r = 0;
    while(q--){
        int p, n; char c;
        cin >> p >> c >> n;
        (c == '('? l: r) += n;
        cout << (l == r? "Yes\n": "No\n");
    }
    return 0;
}

Measured memory_bytes: 1120
#include<iostream>
#include<string>
using namespace std;
bool check(string s){
    int n = s.size();
    if(s[0] == '0'){
        if(n > 1)return false;
        else return true;
    }
    int num = 0;
    for(int i = 0; i < n; i++){
        num *= 10;
        num += s[i]-'0';
    }
    if(num > 255)return false;
    return true;
}
int main(){
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    for(int i = 1; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                //[0,i)[i,j)[j,k)[k,n)
                if(check(s.substr(0,i)) && check(s.substr(i,j-i))
                    && check(s.substr(j,k-j)) && check(s.substr(k))){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3216
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    string s; cin >> s;
    if (s == "AAA" || s == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    string s;
    cin >> s;
    stack<char> st;
    int ans = 0;
    for(auto c: s){
        if(c == ')'){
            if(st.top() == '*'){
                ++ans;
                st.pop();
                st.pop();
                st.push('*');
            }
            else st.pop();
        }
        else st.push(c);
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3344
#include <stdio.h>
#include <string.h>

#define MAX_N 100

const int INF = 1000000000;

typedef struct card_tbl
{
	int a;
	int b;
	int cost;
} card_t;

int n;
int a[MAX_N];
int b[MAX_N];
card_t dp[MAX_N][MAX_N];

card_t
dfs(int l, int r)
{
	if (dp[l][r].cost >= 0)
		return dp[l][r];

	card_t res = {0, 0, INF};
	if (r - l == 0)
	{
		res.a = a[l];
		res.b = b[l];
		res.cost = 0;
	}
	else
	{
		for (int i = l; i < r; i++)
		{
			card_t t;
			card_t o = dfs(l, i);
			card_t p = dfs(i + 1, r);
			t.a = o.a;
			t.b = p.b;
			t.cost = p.cost + o.cost + (p.a * p.b * o.a * o.b);
			if (t.cost < res.cost)
				res = t;
		}
	}

	return dp[l][r] = res;
}

int
solve()
{
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
			dp[i][j].cost = -1;
	}

	return dfs(0, n - 1).cost;
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d%d", &a[i], &b[i]);

	printf("%d\n", solve());
	return 0;
}

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

int main() {
  int s, s1, s2, s3;
  cin >> s;
  s1 = s / 100;
  s2 = s % 100 / 10;
  s3 = s % 100 % 10;
  cout << s1 + s2 + s3 << endl;
}

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

int main(){
  vector<int> answer;
  string s;
  cin >> s;
  for (long unsigned int i = 0; i < s.size(); i++){
    if(s.at(i)=='0'){
      answer.push_back(0);
    }
    else if(s.at(i)=='1'){
      answer.push_back(1);
    }
    else if((s.at(i)=='B')&&(answer.size()>0)){
      answer.pop_back();
    }
  }
  for (long unsigned int i = 0; i < answer.size(); i++){
    cout << answer.at(i);
  }
}

Measured memory_bytes: 3608
// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long N = sc.nextLong();
        // long K = sc.nextLong();
        int[] A = new int[(int)N];
        int[] B = new int[(int)N];
        int[] C = new int[(int)N];

        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        for (int i = 0; i < N; i++) {
            B[i] = sc.nextInt();
        }

        for (int i = 0; i < N - 1; i++) {
            C[i] = sc.nextInt();
        }

        int score = 0;
        for (int i = 0; i < N; i++) {
            score += B[A[i] - 1];

            if (i > 0 && A[i] - 1 == A[i - 1]) {
                score += C[A[i - 1] - 1];
            }
        }

        System.out.println(score);
    }
}

Measured memory_bytes: 22612
<?php
while(1){
    fscanf(STDIN,"%d\n",$n);
    if($n==0)
        break;
    else{
        $a = array();
        $sum=0;
        for($i=0;$i<$n;$i++){
            fscanf(STDIN,"%d\n",$a[$i]);            
        }
        sort($a);
        for($i=1;$i<$n-1;$i++){
            $sum+=$a[$i];
        }
        echo floor($sum/($n-2))."\n";
    }
}
?>

Measured memory_bytes: 6620
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, i, j, k, ans = 0;
	cin >> n;
	vector<int> a(n * 2);
	for (i = 0; i < n * 2; i++) cin >> a[i];
	sort(a.rbegin(), a.rend());
	for (i = 0; i < n; i++) ans += min(a[i * 2], a[i * 2 + 1]);
	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<ld> p(N);
  REP(i, N) cin >> p[i];

  // dp[i][j]: iまで見て表の枚数がjの時の確率
  vector<vector<ld>> dp(N+1, vector<ld>(N+1, 0.0));
  dp[0][0] = 1.0;

  REP(i, N) REP(j, N){
    dp[i+1][j] += dp[i][j]*(1-p[i]);
    dp[i+1][j+1] += dp[i][j]*p[i];
  }

  ld ans = 0;
  FOR(i, N/2+1, N+1){
    ans += dp[N][i];
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 141056
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_multiset;
#define all(x) (x).begin(),(x).end()
#define endl '\n'
//#define int long long

const int N = (int) 2e3 + 5;
vector<int> adj[N];
int dist[N][N];
bitset<N> vis;

void bfs(int x) {
        queue<int> q;
        vis[x] = true;
        dist[x][x] = 0;
        q.push(x);
        while (!q.empty()) {
                int s = q.front(); q.pop();
                for (auto u : adj[s]) {
                        if (vis[u]) continue;
                        vis[u] = true;
                        int a = dist[x][u], b = dist[u][x];
                        dist[x][u] = min({a, b, dist[x][s] + 1});
                        dist[u][x] = dist[x][u];
                        q.push(u);
                }
        }

}


signed main() { //[J][O][L][S][K][E][Y]
        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int n, x, y; cin >> n >> x >> y;

        for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                        dist[i][j] = INT_MAX;

        for (int i = 1; i <= n; i++) {
                if (i - 1 >= 1) adj[i].emplace_back(i - 1);
                if (i + 1 <= n) adj[i].emplace_back(i + 1);
        }

        adj[x].emplace_back(y);
        adj[y].emplace_back(x);

        for (int i = 1; i <= n; i++) {
                dist[i][i] = 0;
                bfs(i);
                vis.reset();
        }

        map<int,int> cnt;
        for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                        cnt[dist[i][j]]++;

        for (int i = 1; i <= n - 1; i++)
                cout << cnt[i] / 2 << endl;
        return 0;

}

/*

*/

Measured memory_bytes: 16128
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n,m;
    R(n,m);
    REP(i,m){
        int x;
        R(x);
        n-=x;
    }
    W(max(-1,n));
    return 0;
}


Measured memory_bytes: 3812
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;


#define MAX 500000
#define SENTINEL 2000000000
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2


int main(){
  int a, b;
  cin >> a >> b;
  if (a*b % 2 == 0) cout << "Even";
  else cout << "Odd";
  return 0;
}

Measured memory_bytes: 256
A, B, C = map(int, input().split())

if A == B == C and A % 2 == 0:
    print(-1)
    exit()

ans = 0
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
    A, B, C = (B + C) // 2, (A + C) // 2, (A + B) // 2
    ans += 1

print(ans)

Measured memory_bytes: 38256
#include<iostream>
using namespace std;
int main(){
int n,i,p=0;
cin>>n;
for(i=9;i>=1;i--){
    if(n%i==0){
        if((n/i)<=9){
            p=1;
            break;

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


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll unsigned long long int 
using namespace std;

int main(){
	
	ll N,K,i;
	cin>>N>>K;
	vector <ll> v;
	for(i=0;i<N;i++){
		int a;
		cin>>a;
		v.push_back(a);
	}
	sort(v.begin(),v.end(),greater<ll>());
	
	ll sum=0;
	for(i=K;i<N;i++){
		sum+=v[i];
	}
	cout<<sum;
	
	return 0;
}

Measured memory_bytes: 2420
#!/usr/bin/env python3

def main():
    n = int(input())
    cnt = 0
    ans = 'No'
    for i in range(n):
        a, b = map(int, input().split())
        if a == b:
            cnt += 1
        else:
            cnt = 0
        if cnt >= 3:
            ans = 'Yes'
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9164
#include<iostream>
#include<iomanip>
using namespace std;
int n,m,L;
double p[100];
int t[100],v[100];
double c[51][100];
main()
{
	cin>>n>>m>>L;
	for(int i=0;i<n;i++)
	{
		cin>>p[i]>>t[i]>>v[i];
		p[i]/=100;
		if(p[i]==1)
		{
			c[m][i]=1;
		}
		else if(p[i]==0)
		{
			c[0][i]=1;
		}
		else
		{
			c[0][i]=1;
			for(int j=0;j<m;j++)c[0][i]*=1-p[i];
			for(int j=0;j<m;j++)c[j+1][i]=c[j][i]*(m-j)/(j+1)/(1/p[i]-1);
		}
	}
	for(int i=0;i<n;i++)
	{
		double ans=0;
		for(int j=0;j<=m;j++)
		{
			double np=c[j][i];
			for(int k=0;k<n;k++)
			{
				if(i==k)continue;
				int cnt=0;
				double P=1;
				while(cnt<=m&&L*v[k]+j*t[i]*v[i]*v[k]>=L*v[i]+cnt*t[k]*v[i]*v[k])
				{
					P-=c[cnt][k];
					cnt++;
				}
				np*=P;
			}
			ans+=np;
		}
		cout<<fixed<<setprecision(9)<<ans<<endl;
	}
}


Measured memory_bytes: 3316
using System;

namespace abc114_b
{
	class Program
	{
		static void Main(string[] args)
		{
			string s = Console.ReadLine();
			int ret = 9999;
			for (int i = 0; i <= s.Length - 3; i++)
			{
				ret = Math.Min(ret, Math.Abs(753 - int.Parse(s.Substring(i, 3))));
			}
			Console.WriteLine(ret);
		}
	}
}

Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int n[4];

int main(){
  REP(i, 4) cin >> n[i];

  sort(n, n+4);
  if(n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


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

using namespace std;

struct team{
  int id;
  int ac;
  int tm;
  int wa[10];
  bool operator < (const team &right) const {
    if(ac != right.ac) return ac > right.ac;
    if(tm != right.tm) return tm < right.tm;
    return id > right.id;
  }
  bool operator == (const team &right) const {
    return ac == right.ac && tm == right.tm;
  }
};

int main()
{
  int M, T, P, R;
  while(cin >> M >> T >> P >> R, M || T || P || R){
    team te[50];
    for(int i = 0; i < T; i++){
      te[i].id = i + 1;
      te[i].ac = 0;
      te[i].tm = 0;
      memset(te[i].wa, 0, sizeof(te[i].wa));
    }
    while(R--){
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--, p--;
      if(j == 0){
	te[t].ac++;
	te[t].tm += m + te[t].wa[p]*20;
      } else {
	te[t].wa[p]++;
      }
    }
    sort(te, te + T);
    cout << te[0].id;
    for(int i = 1; i < T; i++){
      cout << (te[i] == te[i-1] ? "=":",") << te[i].id;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
int a, b, k;

int32_t main()
{	
	ios_base::sync_with_stdio(0);   cin.tie(0);     cout.tie(0);
	cin >> a >> b >> k;
	int cur = min(a, k);
	a -= cur, k -= cur;
	b = max((int64_t)0, b - k);
	cout << a << " " << b << "\n";
	return 0; 
}

Measured memory_bytes: 256
import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i<n;i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[n-1]-a[0]);
    }
}




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

int main() {
    long N, K;
    cin >> N >> K;
    long long ans = 0;

    for(int i=K+1;i<=N;i++){
        //cout << "i" << i <<"\n";
        int a = N/i;
        //cout << a <<"\n";

        int b = i - K;
        //cout << b  <<"\n";
        int c = N % i;
        //cout <<c <<"\n";
        int add;

        if(c<K) add = 0;
        else if(c>=K){
            if(K==0) add = c - K;
            else add = c - K + 1;
        }
        //cout << add << "\n";
        ans += (a)*b + add;
        //cout <<ans <<"\n";
    }
    cout << ans << "\n";
}

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

int n;
int main()
{
	int i, j, k;
	cin >> n;
	for (i = 1; i <= n; i++) {
		for (j = i + 1; j <= n; j++) {
			for (k = 0; ; k++) {
				if (((i ^ j) >> k) & 1) break;
			}
			printf("%d ", k + 1);
		}
		puts("");
	}
    return 0;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<int> h(N);
  for(int i=0; i<N; i++){
    cin >> h.at(i);
  }
  int cnt=0;
  
  for(int j=0; j<N; j++){
    if(h.at(j)>=K){
      cnt++;
    }
  }
  cout << cnt << endl;
  
  return 0;
}

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

using ll = long long;
const ll mod = LLONG_MAX;

string s;
ll l,r;
int main(){
cin>>s;

  REP(i,s.size()){
    if(s[i]=='Z'){
      r=i;
    }
  }

  for(int i=s.size()-1;i>=0;i--){
    if(s[i]=='A'){
      l=i;
    }
  }
  cout<<r-l+1<<endl;
}


Measured memory_bytes: 640
//Tariquzzaman Faisal
//_Faisal101_
//IUT_CSE'19
//190041101

#include<iostream>
#include<stdio.h>
#include<vector>
#include<deque>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<cstring>
#include<climits>
#include<cmath>
#include<iterator>
#include<set>
#define mp make_pair
#define pb push_back
#define pb push_back
#define fileOut freopen("out.txt","w",stdout)
#define fileIn freopen("in.txt","r",stdout)
#define testcases ll tc,t; cin >> tc; for(t=1; t<=tc; t++)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define INFLL 9223372036854775807
#define INF 2147483647
#define ff first
#define ss second
#define pi acos(-1.0)
#define ll long long
#define endll printf("\n")

using namespace std;


int main(){
    string s;
    cin >> s;
    ll len = s.size();
    ll counter = 0, temp = 0;;
    for (ll i = 0; i < len; i++)
    {
        if(s[i] == 'A'){
            temp ++;
        }
        else if(s[i] == 'B'){
            if(i+1<len && s[i+1] =='C'){
                counter += temp;
                i++;
            }
            else{
                temp = 0;
            }
        }
        else{
            temp = 0;
        }
    }
    cout<<counter<<endl;
    
return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 1000000100000000000
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define st size_t
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=300005;
const int NN=1000001;
const ll md=998244353;



int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    int x,y,a,b,c;
    cin >> x >>y >> a >> b >> c;
    ll A[N]={0};
    ll B[N]={0};
    ll C[N]={0};
    for (int i=1;i<=a;i++){
        cin >> A[i];
    }
    for (int i=1;i<=b;i++){
        cin >> B[i];
    }
    for (int i=1;i<=c;i++){
        cin >> C[i];
    }
    sort(A+1,A+a+1);
    sort(B+1,B+b+1);
    sort(C+1,C+c+1);

    vii all;

    for (int i=1;i<=x;i++){
        all.pb(A[a-i+1]);
    }
    for (int i=1;i<=y;i++){
        all.pb(B[b-i+1]);
    }
    for (int i=1;i<=min(c,x+y);i++){
        all.pb(C[c-i+1]);
    }
    sort(all.rbegin(),all.rend());
    ll s=0;
    for (int i=0;i<x+y;i++){
        s+=all[i];
    }
    cout << s << E;



    r0;
}


Measured memory_bytes: 13552
x,y,a,b,c,*pqr = map(int,open(0).read().split())
tag = ['a']*a + ['b']*b + ['c']*c
pqr_tag = [[pqr,tag] for pqr,tag in zip(pqr,tag)]
pqr_tag.sort(key = lambda x:x[0],reverse = True)

eat = {'a':0,'b':0,'c':0}
eat_max = {'a':x,'b':y}
eat_sum = 0
ans = 0
for taste,tag in pqr_tag:
    
    if tag=='c':
        ans += taste
        eat_sum += 1
    elif eat[tag]<eat_max[tag]:
        eat[tag] += 1
        ans += taste
        eat_sum += 1
    
    if eat_sum == x+y:break
        
print(ans)
    

Measured memory_bytes: 55788
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<=n-1;i++)scanf("%d",&a[i]);
    
    long long int ans=0,sum=0;
    for(int i=0;i<=n-1;i++){
        if(i%2==0){
            if(sum+a[i]<=0){
                ans+=1-sum-a[i];
                sum=1;
            }else{
                sum+=a[i];
            }
        }else{
            if(sum+a[i]>=0){
                ans+=sum+a[i]+1;
                sum=-1;
            }else{
                sum+=a[i];
            }
        }
    }
    
    long long int ans2=0,sum2=0;
    for(int i=0;i<=n-1;i++){
        if(i%2==1){
            if(sum2+a[i]<=0){
                ans2+=1-sum2-a[i];
                sum2=1;
            }else{
                sum2+=a[i];
            }
        }else{
            if(sum2+a[i]>=0){
                ans2+=sum2+a[i]+1;
                sum2=-1;
            }else{
                sum2+=a[i];
            }
        }
    }
    if(ans2<ans)ans=ans2;
    printf("%lld",ans);
    
    return 0;
}

Measured memory_bytes: 512
def resolve():
  A, B, C, D = map(int, input().split(" "))
  Takahashi = {
    "attack": B,
    "HP": A
  }

  Aoki = {
    "attack": D,
    "HP": C
  }
  # print("resolve", A, B, C, D)
  winner = True
  while True:
    Aoki["HP"] -= Takahashi["attack"]
    if (Aoki["HP"] <= 0):
      winner = True
      break

    Takahashi["HP"] -= Aoki["attack"]
    if (Takahashi["HP"] <= 0):
      winner = False
      break

  print("Yes" if winner else "No")

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 61904
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

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

int main(){
  int n;
  int x,y,xn,yn,t,tn;
  bool flg=true;
  x=y=t=0;

  cin>>n;
  for(int i=0;i<n;i++){
    int res;
    cin>>tn>>xn>>yn;
    res = tn-t-abs(xn-x)-abs(yn-y);
    if(res<0 || (res%2>0)){
      flg=false;break;
    }
    t=tn;x=xn;y=yn;
  }
  cout<<(flg?"Yes":"No")<<endl;
  return 0;
}


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

typedef long long ll;
// typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

void warshall_floyd(int n, vector<vector<int>> &d) {
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        d.at(i).at(j) = min(d.at(i).at(j), d.at(i).at(k) + d.at(k).at(j));
      }
    }
  }
}

void printVV(vector<vector<int>> &vv) {
  cout << "{" << endl;
  for(int i = 0; i < (int)vv.size(); i++) {
    cout << "  [ ";
    for(int j = 0; j < (int)vv.at(i).size(); j++) {
      cout << vv.at(i).at(j) << " ";
    }
    cout << "]," << endl;
  }
  cout << "}" << endl;
}

int H, W;
vector<vector<int>> COST(10, vector<int>(10));

int main() {
  cin >> H >> W;

  for(int i = 0; i < 10; i++) {
    for(int j = 0; j < 10; j++) {
      cin >> COST.at(i).at(j);
    }
  }

  // printVV(COST);
  warshall_floyd(10, COST);
  // printVV(COST);

  map<int, int>exist;
  for(int i = 0; i < H*W; i++) {
    int a;
    cin >> a;
    if(a == -1) continue; // -1 はカウントしない
    if(exist.count(a) > 0) {
      exist.at(a)++;
    } else {
      exist.emplace(a, 1);
    }
  }

  int64_t sum = 0;
  for(auto i = exist.begin(); i != exist.end() ; ++i) {
    int key = i->first, value = i->second;
    sum += COST.at(key).at(1) * value;
    // cout << key << ":" << value << endl;
  }

  cout << sum << endl;

}


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

using namespace std;
#define ll long long
#define ld long double

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int k, n;
    cin >> k >> n;
    vector<int> a;
    int sum = 0;
    int ans = INT_MAX / 2;
    for(int i=0;i<n;i++) {
        int x;
        cin >> x;
        a.push_back(x);
    }
    for(int i=1;i<n;i++) {
        sum += abs(a[i] - a[i-1]);
    }
    sum += a[0] + k - a[n-1];
    //cout << sum << endl;
    for(int i=0;i<n;i++) {
        int leftIdx = i - 1;
        int rightIdx = i + 1;
        int temp = sum;
        if(leftIdx >= 0 && rightIdx < n) temp -= max(abs(a[i] - a[leftIdx]), abs(a[i] - a[rightIdx]));
        else if(leftIdx < 0) temp -= max(abs(a[i]), abs(a[i] - a[rightIdx]));
        else if(rightIdx >= n) temp -= max(abs(a[i] - a[leftIdx]), abs(k - a[i] + a[0]));
        ans = min(ans, temp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    int a[4][13] = {};
    int n;
    cin >> n;
    string ch;
    int x;
    for (int i = 0; i < n; i++){
        cin >> ch >> x;
        if (ch == "S"){
            a[0][x-1] = 1;
        }
        else if (ch == "H"){
            a[1][x-1] = 1;
        }
        else if (ch == "C"){
            a[2][x-1] = 1;
        }
        else if (ch == "D"){
            a[3][x-1] = 1;
        }
    }
    for (int j = 0; j < 4; j++){
        for (int k = 0;  k < 13; k++){
            if (a[j][k] == 0){
                if (j == 0){
                    cout << "S " << k + 1 << endl;
                }
                else if (j == 1){
                    cout << "H " << k + 1 << endl;
                }
                else if (j == 2){
                    cout << "C " << k + 1 << endl;
                }
                else if (j == 3){
                    cout << "D " << k + 1 << endl;
                }
            }
        }
    }
}


Measured memory_bytes: 3160
import numpy as np
N = int(input())
a = list(map(int, input().split()))

mean_a = np.mean(a)
cnt = 0
num = 0
for i in range(N):
    if abs(a[i] - mean_a) < abs(cnt - mean_a):
        cnt = a[i]
        num = i
print(num)


Measured memory_bytes: 12508
n = int(input())
s = input()
ans = []
for c in s:
  c_code = (ord(c) + n) % 90
  if(c_code == 0):
    ans.append("Z")
  elif(c_code < 65):
    ans.append(chr(c_code + 64))
  else:
    ans.append(chr(c_code))
print("".join(ans))

Measured memory_bytes: 3060
#include <cstdio>
#include <vector>

using namespace std;

int n;
int a[5000];
long long dp[5000][2][5000][2];
vector <int> v[5000];

int dfs(int x, int y) {
    int c = 1, i, j, k, l, r;
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < 2; j++) {
            dp[x][0][i][j] = dp[x][1][i][j] = 1e18;
        }
    }
    
    if (a[x] > 0) {
        dp[x][0][0][1] = a[x];
    } else {
        dp[x][0][0][0] = a[x];
    }
    
    for (i = 0; i < v[x].size(); i++) {
        int nx = v[x][i], p;
        
        if (nx == y) continue;
        
        p = dfs(nx, x);
        
        for (j = 0; j < c; j++) {
            for (k = 0; k < 2; k++) {
                if (dp[x][0][j][k] == 1e18) continue;
                
                for (l = 0; l < p; l++) {
                    for (r = 0; r < 2; r++) {
                        if (dp[nx][0][l][r] == 1e18) continue;
                        
                        if (r == 1 || dp[nx][0][l][r] < 0) dp[x][1][j + l + 1][k] = min(dp[x][1][j + l + 1][k], dp[x][0][j][k]);
                        dp[x][1][j + l][k & r] = min(dp[x][1][j + l][k & r], dp[x][0][j][k] + dp[nx][0][l][r]);
                    }
                }
            }
        }
        
        c += p;
        
        for (j = 0; j < c; j++) {
            for (k = 0; k < 2; k++) {
                dp[x][0][j][k] = dp[x][1][j][k];
                dp[x][1][j][k] = 1e18;
            }
        }
    }
    
    return c;
}

int main() {
    int i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    for (i = 0; i < n - 1; i++) {
        int x, y;
        
        scanf("%d %d", &x, &y);
        
        x--;
        y--;
        
        v[x].push_back(y);
        v[y].push_back(x);
    }
    
    dfs(0, -1);
    
    for (i = 0; i < n; i++) {
        if (dp[0][0][i][0] < 0 || dp[0][0][i][1] < 1e18) {
            printf("%d\n", i);
            
            break;
        }
    }
    
    return 0;
}


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

main() {
  double a, mina, maxa;
  mina = 99999999;
  maxa = -99999999;
  while(cin >> a) {
    mina = min(mina, a);
    maxa = max(maxa, a);
  }
  cout << maxa - mina << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(int32_t argc, char const *argv[])
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int low = 1, high = a[n - 1], ans = a[n - 1];
	while (low <= high)
	{
		int mid = (low + high) / 2;
		int x = 0;
		for (int i = 0; i < n; ++i)
		{
			int prts = a[i] / mid;
			if (a[i] % mid)
				prts ++;
			x += max(0LL, prts - 1);
		}
		
		if (x <= k)
		{
			ans = mid;
			high = mid - 1;
		}
		else
			low = mid + 1;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 4648
#include<cstdio>
#include<algorithm>
using namespace std;
int main() {
   int abc[3];
   
   scanf("%d %d %d", &abc[0], &abc[1], &abc[2]);

   sort(abc, abc+3);

   printf("%d %d %d\n", abc[0], abc[1], abc[2]);

   return 0;
}


Measured memory_bytes: 2760
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    int c[3][3];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
        }
    }
    bool flag = true;
    if(c[1][0] != c[1][1] + c[0][0] - c[0][1]) flag = false;
    else if(c[1][2] != c[1][1] - c[0][1] + c[0][2]) flag = false;
    else if(c[2][0] != c[2][2] - c[0][2] + c[0][0]) flag = false;
    else if(c[2][1] != c[2][2] - c[0][2] + c[0][1]) flag = false;
    if(flag) cout << "Yes";
    else cout << "No";
    cout << endl;
}

Measured memory_bytes: 256