akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<bits/stdc++.h>
#include <stdio.h>
#include<unordered_map>
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define vvll vector<vector<ll> >
#define vpll vector<pair<ll,ll> >
#define P complex<ld>
#define X real()
#define Y imag()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i,n)   for(int i=0;i<n;i++)
#define repp(i,s,n)   for(int i=s;i<=n;i++)
#define print(v) {for(auto i:v)cout<<i<<" ";cout<<"\n";}
#define mkp make_pair
#define clr(ar,v) memset(ar,v,sizeof(ar));
#define TC ll amr_abdelazim;cin>>amr_abdelazim;while(amr_abdelazim--)
#define popcnt(x) __builtin_popcount(x)
#define EPS 1e-9
#define INF 1000000000000000009
using namespace std;
//freopen("output.txt", "w", stdout);
//freopen("input.txt", "r", stdin);
const int mod = 1000000007;
const int N = 2 * 100000 + 9;
const double pi = acos(-1);
class cmp{
public:
	bool operator() (ll &A, ll &B){
		return A > B;
	}
};
bool by_sec(const pll &a, const pll &b){
	if ((abs(a.first) == abs(b.first)))
		return (abs(a.second) < abs(b.second));
	return (abs(a.first) < abs(b.first));
}
bool byth(const tuple<ll, ll, ld>& a, const tuple<ll, ll, ld>& b){
	return (get<2>(a) < get<2>(b));
}
ld dist(P a, P b){
	return (ld)abs(a - b);
}
ll fact[1000009], inv[1000009];
ll fp(ll a, ll b){
	if (b == 0)
		return 1;
	ll ans = fp(a, b / 2);
	ans = (ans * ans) % mod;
	if (b % 2 != 0)
		ans = (ans * (a % mod)) % mod;
	return ans;
}
void FacInv(ll n){
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = ((i%mod) * fact[i - 1] % mod) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}
ll ncr(ll n, ll r){
	return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;
}
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a%b);
}
ll max(ll a, ll b){
	if (a >= b)return a;
	else return b;
}
ll min(ll a, ll b){
	if (a <= b)return a;
	else return b;
}



int main()
{
	Amr_Abdelazim

		ll n, ans = 0, k, mn = INF, c = 0;
	cin >> n >> k;
	vll a(n);
	rep(i, n)cin >> a[i];
	rep(i, n)mn = min(a[i], mn);
	rep(i, n){
		if (a[i] != mn)c++;
		else{
			ans += max((c + (k - 2)) / (k - 1),c>0?1:0);
			if (c % (k - 1) != 0){
				ll qq = c % (k - 1);				
				ll cc = (k - 1) - qq;
				if (k - 1 > c){
					cc = (k - 1) - c;
				}
				i++;
				while (i < n&&cc--){
					a[i] = mn;
					i++;
				}
			}
			break;
		}
	}
	reverse(all(a));
	c = 0;
	rep(i, n){
		if (a[i] != mn)c++;
		else{
			ans += (c + (k - 2)) / (k - 1);
			break;
		}
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3924
import itertools
import numpy as np

N_book, M_algo, X_skill = map(int, input().split())  

A = []
for _ in range(N_book):
    a = list(map(int, input().split()))
    A.append(a)

flg = False
ans = float('inf')
for selector in list(itertools.product([1, 0], repeat=N_book))[:-1]:
    C = []
    for i in range(N_book):
        if selector[i] == 1:
            C.append(A[i])
    
    D = list(np.array(C).sum(axis=0))
    if (False in [i >= X_skill for i in D[1:]]):
        continue
    else:
        flg = True
        ans = min(ans, D[0])

if flg:
    print(ans)
else:
    print(-1)

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

class Main{
	public static void main(String args[])throws IOException{
	 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	 int num[]=new int[10];	 
	for(int i=0;i<10;i++){
	  num[i]=Integer.parseInt(br.readLine());
	}
	Arrays.sort(num);
	for(int j=9;j>6;j--){
	System.out.println(num[j]);
	}
}}

Measured memory_bytes: 24264
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//struct area

//function area

//main area
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> cities(n, 0);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        cities[a]++; cities[b]++;
    }
    rep(i,n){
        cout << cities[i] << endl;
    }
}
/*

1と2を結んでいるなら、city1とcity2につながる道路も1つずつ増えるはず
なので、countして出力のみでオーケー

*/

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c;
    d = a*100 + b*10 + c;
    if(d%4 == 0) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
v = list(map(int,input().split()))

ans = 0

for l in range(n):
    for r in range(n-l+1):
        if l+r >k:
            break
        nv = v[:l] + v[n-r:]
        nv.sort()
        for i in range(k-l-r):
            if not nv or nv[0] >= 0:
                break
            nv.pop(0)
        ans = max(ans,sum(nv))
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;



int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
ll n;
cin >> n;
float arr[n];
for(int i =0; i<n; i++){
	cin >> arr[i];
}
float sum =0.0;
for(int i =0; i<n; i++){
	float a = 1/arr[i];
	sum+=a;
}
float ans = 1/sum;
cout << ans << endl;

return 0;
}



Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res = 0;

	long N; cin >> N;

	long C[100], V[100];
	for (int i = 0; i < N; i++) cin >> V[i];
	for (int i = 0; i < N; i++) cin >> C[i];

	for (int i = 0; i < N; i++) if (V[i] > C[i]) res += V[i] - C[i];

	cout << res << endl;
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;

  int ans;
  for (int i = N; i > 0; i--) {
    int sq = sqrt(i);
    if (i == sq * sq) {
      ans = i;
      break;
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
function main(input) {
  input = input.trim().split("\n");
  const n = Number(input[0]);
  const as = input[1].split(" ").map(n => Number(n));
  const result = as.reduce((a, b) => a + b) - n;
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
n = int(input())
array = list(map(int, input().split()))


def cal(value):
    return value / 2


def odd_even_cal(value):
    return value % 2


flug, counter = -1, 0
while flug < 0:
    if 1 in list(map(odd_even_cal, array)) or 0 in array:
        flug = 1
        break
    counter += 1
    array = list(map(cal, array))

print(counter)


Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A;
  cin >> A;
  int tv = -1;
  int fv = 100000;
  while (fv - tv > 1){
    int mid = (tv + fv) / 2;
    if ((long long) mid * (mid + 1) / 2 < A){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  string ans = ")(";
  for (int i = 0; i < tv; i++){
    ans += ")";
  }
  for (int i = 0; i < tv; i++){
    ans += "(";
  }
  int r = A - tv * (tv + 1) / 2 - 1;
  for (int i = 1; i <= r; i++){
    swap(ans[i], ans[i + 1]);
  }
  cout << ans << endl;
}


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

void solve(long long r)
{
    cout << (3 * r * r) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long r;
    scanf("%lld", &r);
    solve(r);
    return 0;
}


Measured memory_bytes: 256
def test():
    n,m,x = map(int,input().split())
    a = list(map(int,input().split()))
    count1 = 0
    count2 = 0
    for i in range(x):
        if i in a:
            count1 += 1
    for i in range(x,n+1):
        if i in a:
            count2 += 1
    print(min(count1,count2))


if __name__ == "__main__":
    test()


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    double xa, ya, ra, xb, yb, rb;
    int n;

    cin >> n;
    while(n--) {
        int ret = 1;
        double d;

        cin >> xa >> ya >> ra >> xb >> yb >> rb;
        d = sqrt(pow(xb-xa, 2) + pow(yb-ya, 2));
        if (ra + rb < d) {
            ret = 0;
        }else if (ra - rb > d) {
            ret = 2;
        }else if (rb - ra > d) {
            ret = -2;
        }

        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>
#define N 200000
int main(void){

  int i,j,n,f[N];
  long minv,maxv=-1000000000;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&f[i]);
  }
  
  minv = f[0];

  for(j=1;j<n;j++){
    
    if(maxv<f[j]-minv) maxv = f[j]-minv;
    
    if(minv>f[j]) minv = f[j];

  }
 
  printf("%d\n",maxv);

  return 0;
}
  
    

Measured memory_bytes: 1376
#include <algorithm>
#include <queue>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define ll long long
#define N 1000000005
using namespace std;
int main()
{
   int n,a[200005];
   scanf("%d",&n);
   for(int i=0;i<n;i++)
   {
       scanf("%d",&a[i]);
   }
   sort(a,a+n);
   for(int i=0;i<n;i++)
   {
       if(a[i]==a[i+1])
       {
           printf("NO\n");
           return 0;
       }
   }
   printf("YES\n");
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 505;

char a[MAX_N][MAX_N];
int t[MAX_N][MAX_N];
deque<P> deq;

int main()
{
	while(1){
	int h,w;
	cin >> h >> w;
	if(h==0&&w==0){
		break;
	}
	int ans=0;
	char s;
	rep(i,h){
		scanf("%c",&s);
		rep(j,w){
			scanf("%c",&a[i][j]);
		}
	}
	rep(i,h){
		t[i][w] = 0;
	}
	rep(j,w){
		if(a[0][j] == '.'){
			t[0][j] = 1;
		}else{
			t[0][j] = 0;
		}
	}
	for(int i=1;i<h;i++){
		rep(j,w){
			if(a[i][j]=='.'){
				t[i][j] = t[i-1][j] + 1;
			}else{
				t[i][j] = 0;
			}
		}
	}
	int pos;
	rep(i,h){
		rep(j,w+1){
			if(deq.empty()){
				deq.push_back(P(t[i][j],j));
				continue;
			}
			deque<P>::iterator it = deq.end()-1;
			if((*it).first < t[i][j]){
				deq.push_back(P(t[i][j],j));
			}else if((*it).first > t[i][j]){
				while(!deq.empty() && (*it).first > t[i][j]){
					int S = (*it).first*(j-(*it).second);
					pos = (*it).second;
					ans = max(S,ans);
					deq.pop_back();
					it = deq.end()-1;
				}
				deq.push_back(P(t[i][j],pos));
			}
		}
	}
	printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string N;
    cin >> N;
    
    if ((N[0] == N[1] && N[1] == N[2]) || (N[1] == N[2] && N[2] == N[3])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

using namespace std;
const int N=3e5+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int n;
db a,b,ans,na,nb;

int main()
{
/// /bb
	n=rd(),b=rd(),a=rd(),b-=a;
	for(int i=n;i;--i) ans+=a*(i+i+1)/(db)2+b,na=a+(4*a)/(db)(2*i),nb=b+(3*a+2*b)/(db)(2*i),a=na,b=nb;
	printf("%.10lf\n",ans);
    return 0;
}




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

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

  int N;
  string S;
  cin >> N >> S;


  if (N % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }

  bool judge = false;
  for (int i = 0; i < N / 2; ++i) {
    if (S.at(i) == S.at(i + (N / 2))) {
      judge = true;
    }
    else {
      judge = false;
      break;
    }
  }

  if (judge) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}


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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    string S;
    cin >> S;
    i64 r = 0, g = 0, b = 0;
    for (i32 i = 0; i < N; i++) {
        if (S[i] == 'R') r++;
        else if (S[i] == 'G') g++;
        else if (S[i] == 'B') b++;
    }
    i64 sum = r * g * b;
    for (i32 i = 0; i < N - 1; i++) {
        for (i32 j = i + 1; j < N; j++) {
            i32 k = (2 * j - i);
            if (k >= N) continue;
            if (S[i] != S[j] && S[i] != S[k] && S[j] != S[k])
                sum--;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3604
import qualified Data.Vector.Unboxed as V
import Data.Array.IArray (listArray, accumArray, (!))
import Data.Array.MArray
import Data.Array.ST (STUArray, runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.List (sortOn, sortBy, unfoldr, partition)
import Data.Char (isSpace)
import Control.Monad.ST (ST, runST)
import Control.Monad.Trans.State (StateT(..))
import qualified Data.ByteString.Char8 as B
import qualified  Data.Set as S
import Control.Arrow (first)

import Debug.Trace (trace)

-- utility functions

--tr x = trace (show x) x
tr = id

--   Input functions
readInt = B.readInt . B.dropWhile isSpace

readInts :: Int -> B.ByteString -> [Int]
readInts n = take n . unfoldr readInt

readIntsV :: Int -> B.ByteString -> V.Vector Int
readIntsV n = V.unfoldrN n readInt

readIntsA :: Int -> B.ByteString -> UArray Int Int
readIntsA n bs = runSTUArray $ do
  arr <- newArray_ (0,n-1)
  go arr 0 bs
  return arr
  where
    go :: STUArray s Int Int -> Int -> B.ByteString -> ST s ()
    go arr i bs
      | i==n = return ()
      | otherwise = do
        let Just (x,bs') = readInt bs
        writeArray arr i x
        go arr (i+1) bs'

readTsV :: Int -> B.ByteString -> V.Vector (Int,Int)
readTsV n = V.unfoldrN n $ runStateT ((,) <$> StateT readInt <*> StateT readInt)

readTs :: Int -> B.ByteString -> [(Int,Int)]
readTs n = take n . unfoldr readT where
  readT = runStateT ((,) <$> StateT readInt <*> StateT readInt)

-- main

modular = 10^9 + 7

count "" arr = return ()
count (x:xs) arr = do
  c <- readArray arr x
  writeArray arr x (c+1)
  count xs arr

sub x arr = readArray arr x >>= writeArray arr x . pred

productm m [] = 1
productm m (x:xs) = (x * productm m xs) `mod` m

solv s = runST $ do
  alphanum <- newArray ('a','z') 0 :: ST s (STUArray s Char Int)
  count s alphanum
  go s alphanum
  where
    p c v = fst v/=c && snd v > 0
    go "" alphanum = return 0
    go (x:xs) alphanum = do
      sub x alphanum
      counts <- map snd . filter (p x) <$> getAssocs alphanum
      r <- go xs alphanum
      let choice = productm modular $  map succ counts
      return $ (r + choice) `mod` modular

main = do
  getLine
  s <- getLine
  print $ solv s


Measured memory_bytes: 266364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const double pi = 3.141592653589793;



int main(){
    ll N;
    cin>>N;
    vector<ll> A(N), B(N);
    rep(i, N){
        cin>>A[i]>>B[i];
    }
    sort(ALL(A));
    sort(ALL(B));
    if(N%2){
        ll Ans=B[N/2]-A[N/2]+1;
        cout<<Ans<<endl;
    }
    else{
        ll BB=(B[N/2]+B[N/2-1]);
        ll AA=(A[N/2]+A[N/2-1]);
        ll Ans=BB-AA+1;
      	//cout<<BB<<" "<<AA<<endl;
        cout<<Ans<<endl;
    }
}

Measured memory_bytes: 6420
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <queue>
#include <string>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll          = long long;
using db          = double;
using ld          = long double;
using uint        = unsigned int;
using ull         = unsigned long long;

using pii         = pair<int, int>;
using pll         = pair<ll, ll>;
using tiii        = tuple<int, int, int>;

#define mod7        1000000007
#define mod9        1000000009

#define forall(v)   v.begin(), v.end()
#define prec(x)     setprecision(x) << fixed

/* [💭] [💡] [🎈] */

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

    int n, m;
    cin >> n >> m;

    vector<int> x(m);
    for (int i = 0; i < m; i++) {
        cin >> x[i];
    }

    sort(forall(x));

    vector<int> d;
    for (int i = 0; i < m - 1; i++) {
        d.push_back(x[i + 1] - x[i]);
    }

    sort(forall(d));

    ll s = 0;
    for (int i = 0; i < m - n; i++) {
        s += d[i];
    }

    cout << s;

    return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  string S; cin >> S;
  if (S.size() < 26) {
    bool alf[26] = { };
    for (auto c : S) alf[c - 'a'] = true;
    for (int i = 0; i < 26; i++) {
      if (!alf[i]) {
        cout << S << (char)(i + 'a') << endl;
        return 0;
      }
    }
  } else {
    int idx = S.size() - 1;
    while (idx > 0 && S[idx - 1] > S[idx]) idx--;
    if (idx == 0) cout << -1 << endl;
    else {
      for (int i = 0; i < idx - 1; i++) cout << S[i];
      for (int i = S.size() - 1; i >= 0; i--) {
        if (S[i] > S[idx-1]) {
          cout << S[i] << endl;
          break;
        }
      }
    }
  }

	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 = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        Dijkstra d = new Dijkstra(n);
        for(int i=1; i<n; i++){
            d.addEdge(i, i-1, 0);
        }
        for(int i=0; i<m; i++){
            int l = Integer.parseInt(sc.next())-1;
            int r = Integer.parseInt(sc.next())-1;
            int c = Integer.parseInt(sc.next());
            d.addEdge(l, r, c);
        }
        
        long[] cost = d.dijkstra(0);
        if(cost[n-1]!=Dijkstra.INF){
            System.out.println(cost[n-1]);
        }else{
            System.out.println(-1);
        }
    }
}

class Dijkstra{
    
    public static final long INF = (long)1e18;
    private int n;
    private List<Edge>[] edge;
    
    public Dijkstra(int n){
        this.n = n;
        edge = new List[n];
        for(int i=0; i<n; i++){
            edge[i] = new ArrayList<>();
        }
    }
    
    public void addEdge(int from, int to, int cost){
        edge[from].add(new Edge(from, to, cost));
        //edge[to].add(new Edge(to, from, cost));
    }
    
    public long[] dijkstra(int from){
        long[] dist = new long[n];
        Arrays.fill(dist, INF);
        dist[from] = 0;
        
        PriorityQueue<Vertex> q = new PriorityQueue<>();
        q.add(new Vertex(from, 0));
        while(q.size() != 0){
            int u = q.poll().ver;
            
            for(Edge ne : edge[u]){
                int v = ne.to;
                long weight = ne.cost;
                if(dist[v] > dist[u]+weight){
                    dist[v] = dist[u]+weight;
                    q.add(new Vertex(v, dist[v]));
                }
            }
        }
        
        return dist;
    }
}

class Edge implements Comparable<Edge>{
    public int from = 0;
    public int to = 0;
    public int cost = 0;
    
    public Edge(int from, int to, int cost) {
        this.from = from;
        this.to = to;
        this.cost = cost;
    }
    
    @Override
    public int compareTo(Edge o) {
        return this.cost - o.cost;
    }
}

class Vertex implements Comparable<Vertex>{
    public int ver = 0;
    public long cost = 0;
    
    public Vertex(int ver, long cost) {
        this.ver = ver;
        this.cost = cost;
    }
    
    @Override
    public int compareTo(Vertex o) {
        long tmp = this.cost - o.cost;
        if(tmp == 0) return 0;
        return (int)(tmp/Math.abs(tmp));
    }
}

Measured memory_bytes: 74680
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
map<ll,ll>v;
ll n,m,ans,a[200005],sum[200005];
int main(){
	in(n);in(m);
	for(int i=1;i<=n;i++)in(a[i]);
	for(int i=1;i<=n;i++)sum[i]=(sum[i-1]+a[i]-1)%m;
	v[0]=1;
    int l=0,r=1;
    while(r<=n){
        if(r-l==m){
            v[sum[l]]--;
            l++;
        }
        ans+=v[sum[r]];
        v[sum[r]]++;
        r++;
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

#define ll long long
#define vi vector<int>

ll N, D, X, ans = 0;
int A[105];

void solve(){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < D; j++){
            int buff = A[i];
            if(j%buff==0) ans++;
        }        
    }
    cout << ans + X << endl;
}

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

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

    solve();
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H, W, A):
    cost = [[-1] * W for _ in range(H)]
    bq = deque()
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                bq.append((i, j))
                cost[i][j] = 0

    while bq:
        i, j = bq.popleft()
        c = cost[i][j]
        if i > 0 and cost[i-1][j] == -1:
            cost[i-1][j] = c + 1
            bq.append((i-1, j))

        if i < H-1 and cost[i+1][j] == -1:
            cost[i+1][j] = c + 1
            bq.append((i+1, j))

        if j > 0 and cost[i][j-1] == -1:
            cost[i][j-1] = c + 1
            bq.append((i, j-1))

        if j < W-1 and cost[i][j+1] == -1:
            cost[i][j+1] = c + 1
            bq.append((i, j+1))

    return max(map(max, cost))


def main():
    H, W = read_int_n()
    A = [read_str() for _ in range(H)]
    print(slv(H, W, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 117612
import std.conv;
import std.stdio;
import std.string;

void main()
{
	auto nk = readln.split.to!( int[] );
	auto as = readln.split.to!( int[] );
	writeln( solve( nk[ 1 ], as ) );
}

auto solve( in int k, in int[] as )
{
	auto as_r = as.length - k;
	auto k_r = k - 1;
	auto c = 1 + as_r / k_r;
	auto re = ( as_r % k_r == 0 ) ? 0 : 1;

	return c + re;
}

unittest
{
	assert( solve( 3, [ 2, 3, 1, 4 ] ) == 2 );
	assert( solve( 3, [ 1, 2, 3 ] ) == 1 );
	assert( solve( 3, [ 7, 3, 1, 8, 4, 6, 2, 5 ] ) == 4 );

	assert( solve( 3, [ 7, 3, 6, 8, 4, 1, 2, 5 ] ) == 4 );
	assert( solve( 3, [ 7, 3, 6, 1, 4, 8, 2, 5 ] ) == 4 );
	assert( solve( 3, [ 7, 3, 6, 4, 1, 8, 2, 5 ] ) == 4 );

	assert( solve( 3, [ 7, 3, 8, 1, 4, 6, 2, 5, 9 ] ) == 4 );
	assert( solve( 3, [ 7, 3, 8, 4, 6, 1, 2, 5, 9 ] ) == 4 );
	assert( solve( 3, [ 7, 3, 8, 4, 1, 6, 2, 5, 9 ] ) == 4 );
}


Measured memory_bytes: 4160
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

#define mod 1000000007;

using namespace std;

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

    if (N % 2 == 1) cout << N / 2 + 1;
    else cout << N / 2;
}

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

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

int main(){
    char s[10];
    cin >> s;

    string y(s, 4);
    string m(s+5, 2);
    string d(s+8, 2);

    string ans = "Heisei";
    if (stoi(y)>2019){
        ans = "TBD";
    }
    else if (stoi(y)==2019 && stoi(m) > 4){
        ans = "TBD";
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split(' '))
input_lists = [input() for _ in range(K*2)]
sweets = []*K
counts = [0]*(N+1)
counts[0] = -1
for i in range(0, len(input_lists), 2):
    tmp = []
    tmp.append(int(input_lists[i]))
    tmp.append(list(map(int, input_lists[i+1].split(' '))))
    sweets.append(tmp)
for sweet in sweets:
    for n in sweet[1]:
        # print(counts[n])
        counts[n] += 1

print(sum(count == 0 for count in counts))

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<bool> ok(n, true);
    vector<int> dp(n+1, 0);

    int a;
    for (int i = 0; i < m; i++) {
        cin >> a;
        ok[a] = false;
    }
    dp[0] = 1;
    if (ok[1]) dp[1] = 1;
    for (int i = 2; i < n+1; i++) {
        if (ok[i]) {
            dp[i] = dp[i-1] + dp[i-2];
            dp[i] %= MOD;
        }
    }
    cout << dp[n] << endl;
}


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

int main() {
  int n,q;
  cin >>n;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
  	cin >> a[i];
  }
  cin >> q;
  vector<ll> b(q);
  vector<ll> c(q);
  for(int i=0;i<q;i++){
  	cin >> b[i] >> c[i];
  }
  
  vector<ll> num(100001,0);
  ll su=0;
  for(int i=0;i<n;i++){
  	num[a[i]]++;
    su+=a[i];
  }
  
  
  for(int i=0;i<q;i++){
    su+=(c[i]-b[i])*num[b[i]];
	num[c[i]]+=num[b[i]];
    num[b[i]]=0;
    cout << su << endl;
  }

}



Measured memory_bytes: 6388
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int main() {
  int n;
  S(n);
  if(n == 0) {
    P(0);
    return 0;
  }
  string s = "";
  while(n) {
    if(n > 0) {
      if(n % 2) s += '1';
      else s += '0';
      n /= 2;
      n = -n;
    } else {
      n = -n;
      if(n % 2) s += '1';
      else s += '0';
      n = (n + 1) / 2;
    }
  }
  reverse(all(s));
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 256
w = gets.chomp
w_list = []

(w.size).times do |i|
  w_list.push(w[i])
end

w_list.sort!
w_list.push("A")

tmp = ""
cnt = 0
h_flag = true
w_list.each do |c|
  #p c
  if(tmp!=c)then
    if(!h_flag)then
      if(cnt%2!=0)then
        puts "No"
        exit
      end
    else
      h_flag = false
    end
    cnt  = 1
  else
    cnt += 1
  end
  tmp = c
end

puts "Yes"

Measured memory_bytes: 1788
import collections

n = int(input())
A = list(map(int, input().split()))

A_plus = [x+1 for x in A]
A_minus = [x-1 for x in A]

A_all = A_minus + A_plus + A

Count = collections.Counter(A_all)
ans = Count.most_common()[0][1]

print(ans)

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

const int N = 200233;
int n, p[N], sufMaxCnt[N], sufEvenScore[N], sufOddScore[N];
bool isPreMax[N];

vector<pair<int*, int>> undoStack;
int tOdd[N], tEven[N], undoSize[N];
void add(int *t, int x, int y) {
  for (x = n + 1 - x; x <= n; x += x & -x) {
    if (t[x] < y) {
      undoStack.emplace_back(&t[x], t[x]);
      t[x] = y;
    }
  }
}
int ask(int *t, int x) {
  int r = 0xc0c0c0c0;
  for (x = n + 1 - x; x; x -= x & -x) {
    r = max(r, t[x]);
  }
  return r;
}
bool check(int mx, int req) {
  if (req < 0) return false;
  return ask(req & 1 ? tOdd : tEven, mx) >= req;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    mx = max(mx, p[i]);
    if (p[i] == mx) {
      isPreMax[i] = true;
    }
  }
  for (int i = n; i; i--) {
    sufMaxCnt[i] = sufMaxCnt[i + 1] + (int) isPreMax[i];
  }
  memset(tOdd, 0xc0, sizeof tOdd);
  for (int i = n; i; i--) {
    int sOdd = ask(tOdd, p[i]), sEven = ask(tEven, p[i]);
    undoSize[i] = (int) undoStack.size();
    if (isPreMax[i]) {
      sufEvenScore[i] = sEven + 2;
      sufOddScore[i] = sOdd < 0 ? 0xc0c0c0c0 : sOdd + 2;
    } else {
      sufEvenScore[i] = sOdd < 0 ? 0xc0c0c0c0 : sOdd + 1;
      sufOddScore[i] = sEven + 1;
    }
    if (sufOddScore[i] > 0) add(tOdd, p[i], sufOddScore[i]);
    add(tEven, p[i], sufEvenScore[i]);
  }
  if (!check(1, sufMaxCnt[1])) {
    puts("-1");
    return 0;
  }
  int max0 = 1, max1 = 1, diff = 0;
  for (int i = 1; i <= n; i++) {
    while ((int) undoStack.size() > undoSize[i]) {
      *undoStack.back().first = undoStack.back().second;
      undoStack.pop_back();
    }
    if (max0 <= p[i]) {
      if (check(max1, diff + 1 + sufMaxCnt[i + 1]) || check(p[i], sufMaxCnt[i + 1] - diff - 1)) {
        putchar('0');
        max0 = p[i];
        diff++;
      } else {
        putchar('1');
        if (max1 <= p[i]) {
          max1 = p[i];
          diff--;
        }
      }
    } else {
      if (check(max1, diff + sufMaxCnt[i + 1]) || check(max0, sufMaxCnt[i + 1] - diff)) {
        putchar('0');
      } else {
        putchar('1');
        if (max1 <= p[i]) {
          max1 = p[i];
          diff--;
        }
      }
    }
  }
}


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

public class Main {

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

		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		for (int i = 0; i < n; i++) {
			int out = 0, score = 0;
			boolean first = false, second = false, third = false;
			while (out != 3) {
				String res = br.readLine();
				if (res.equals("OUT"))
					out++;
				else if (res.equals("HOMERUN")) {
					score++;
					if (first) score++;
					if (second) score++;
					if (third) score++;
					first = second = third = false;
				} else {
					if (third) score++;
					third = second;
					second = first;
					first = true;
				}
			}
			System.out.println(score);
		}

	}

}

Measured memory_bytes: 16876
#include<stdio.h>
int main(){
  int N,a,b,c,d,count=0;
  scanf("%d",&N);
  a=N/1000; b=(N-(a*1000))/100; c=(N-(a*1000)-(b*100))/10; 
  d=N-(a*1000)-(b*100)-(c*10);
  if(a==2)count+=1;
  if(b==2)count+=1;
  if(c==2)count+=1;
  if(d==2)count+=1;
  printf("%d",count);
  return 0;
}
  

Measured memory_bytes: 128
// Problem : C - Count Order
// Contest : AtCoder - AtCoder Beginner Contest 150
// URL : https://atcoder.jp/contests/abc150/tasks/abc150_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n;
    cin>>n;
    vi a(n), b(n), v;
    int id1,id2;
    for(int &i : a) cin>>i;
    for(int &i : b) cin>>i;
    for(int i=1;i<=n;i++) v.pb(i);
    int cnt = 0;
    do{
        cnt++;
        if(v == a) id1 = cnt;
        if(v == b) id2 = cnt;
    } while(next_permutation(all(v)));
    cout<<abs(id1-id2)<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int A, B , C, K; cin >> A >> B >> C >> K;
    if(K > A+B) cout << A-(K-A-B) << endl;
    else if(K < A) cout << K << endl;
    else cout << A << endl;
}

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

vector<P>E[100000];
ll d[100000];

struct st {
	ll a, b, d;
};
st v[200000];
int main() {
	ll n, m, c; scanf("%lld%lld%lld", &n, &m, &c);
	rep(i, m) {
		ll a, b, d; scanf("%lld%lld%lld", &a, &b, &d); a--; b--;
		E[a].push_back(P(d, b)); E[b].push_back(P(d, a));
		v[i] = { a,b,d };
	}
	memset(d, 0x3f, sizeof(d));
	priority_queue<P, vector<P>, greater<P>>que;
	d[0] = 0;
	que.push(P(0, 0));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (p.first != d[p.second])continue;
		for (P v : E[p.second]) {
			if (d[v.second] > p.first + v.first) {
				d[v.second] = p.first + v.first;
				que.push(P(d[v.second], v.second));
			}
		}
	}
	sort(v, v + m, [&](st a, st b) {return max(d[a.a], d[a.b]) < max(d[b.a], d[b.b]); });
	ll sum = 0; rep(i, m)sum += v[i].d;
	ll Min = sum;
	rep(i, m) {
		sum -= v[i].d;
		Min = min(Min, sum + max(d[v[i].a], d[v[i].b])*c);
	}
	printf("%lld\n", Min);
}

Measured memory_bytes: 21984
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 1; i <= n; i++)
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
#define int long long
signed main(){
  int N;
  cin >> N;
  int A[100010];
  int sum = 0;
  rep(i,N){cin>>A[i];}

  int X[100010];
  X[0] = A[0];

  rep(i,N-2)X[0] = A[i+1] - X[0];
  X[0] = (A[N-1] - X[0]) / 2;
  rep(i,N-1)X[i+1] = A[i] - X[i];

  rep(i,N) cout << X[i]*2 << " ";
}

Measured memory_bytes: 2816
//Author - Soumik Roy
//Date & Time - September 19, 2020 6:03 PM
//Problem name - B - Go to Jail
//Problem url - https://atcoder.jp/contests/abc179/tasks/abc179_b
//Time limit - 2000 ms
//Memory Limit - 1024 MB    
//Parsed with ai-virtual-assistant https://github.com/Saurav-Paul/AI-virtual-assistant-python
#include<bits/stdc++.h>
#define ll                    long long int
#define pb                    push_back
#define F                     first
#define S                     second
#define mp                    make_pair
#define MOD                   1000000007
#define vi                    vector<int>
#define vll                   vector<ll>
#define pll                   pair<ll,ll>
#define pii                   pair<int,int>
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define eb                    emplace_back
#define ull                   unsigned long long
#define bug(x)				  cout<<"  [ "#x<<" = "<<x<<" ]"<<endl;
#define KAMEHAMEHA            ios_base::sync_with_stdio(0);
#define RASENGAN              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int dir[]={0,1,0,-1,1,0,-1,0};
void solve()
{
	int n;
	cin>>n;
	vector<pii> l;
	for(int i=0;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		l.eb(a,b);
	}
	bool check=false;
	for(int i=0;i<n-2;i++)
	{
		
		if(l[i].F==l[i].S && l[i+1].F==l[i+1].S && l[i+2].F==l[i+2].S)
		{
			check=true;
			break;
		}
	}
	if(check) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
int main()
{
    KAMEHAMEHA
	int t=1;
	//cin>>t;
	for(int cn=1;cn<=t;cn++)
	{
		solve();
	}
    return 0;
}



Measured memory_bytes: 3656
#include<fstream>
#include<string>
#include<iostream>
#include<sstream>
#include<iterator>
#include<cmath>

using namespace std;


int main(){
 int N;
 cin >> N;
 int a[N];
 int b[N];
 int c[N-1];
 int i;
 for(i=0;i<N;++i){
     cin >> a[i];
   }
 for(i=0;i<N;++i){
     cin >> b[i];
   }
 for(i=0;i<N-1;++i){
     cin >> c[i];
   }
  int sum = 0;
 for(i=0;i<N;++i){
   sum += b[a[i]-1];
   if(i>0){
    if(a[i-1] == a[i]-1){
       sum += c[a[i-1]-1];
       }}
 }
        cout << sum << endl;
 return 0;
}

Measured memory_bytes: 256
x = gets.to_i
if 400 <= x && x <= 599
  puts 8
elsif 600 <= x && x <= 799
  puts 7
elsif 800 <= x && x <= 999
  puts 6
elsif 1000 <= x && x <= 1199
  puts 5
elsif 1200 <= x && x <= 1399
  puts 4
elsif 1400 <= x && x <= 1599
  puts 3
elsif 1600 <= x && x <= 1799
  puts 2
elsif 1800 <= x && x <= 1999
  puts 1
end


Measured memory_bytes: 14324
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

N, K = list(map(int, sys.stdin.readline().split()))
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

AB.sort()
A, B = list(zip(*AB))

print(A[np.searchsorted(np.array(B).cumsum(), K)])


Measured memory_bytes: 45180
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll n;
    cin>>n;
    string s;
    vll a(n);
    rep(i,0,n)cin>>a[i];
    ll r=0;
    vb digit(n,0);
    ll res=0;
    rep(l,0,n){
        while(r<n){
        bool check=true;
        vi keep;
        rep(i,0,20){
            if((a[r]>>i)&1){
                if(digit[i]){
                    check=false;
                    break;
                }
                else{
                    keep.push_back(i);
                }
            }
        }
            if(check){
                r++;
                for(int c:keep){
                    digit[c]=true;
                }
            }
            else break;
        }
        res+=(r-l);

        if(r==l)r++;
        else{
            rep(i,0,20){
                if((a[l]>>i)&1)digit[i]=false;
            }
        }
    }
    cout<<res<<endl;
    return 0;
}




Measured memory_bytes: 1792
n = int(input())
s = []
res = "Yes"
for i in range(n):
  s.append(input())
  for j in range(i):
    if s[i] == s[j]:
      res = "No"
  if i != 0:
    if s[i][0] != s[i-1][len(s[i-1])-1]:
      res = "No"
print(res)      

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");

int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}

vi vis(100001,0);
vi adj[100001];

int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    ll n;cin>>n;
 	ll sum = (n*(n+1))/2;
 	sum-=n;
 	cout<<sum<<"\n";

}

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

#define int long long 
#define boost ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100000 + 10;

int ans;
int32_t main(){

	boost;
	int n , mn = 1e18 , temp , neg = 0;
	cin >> n;

	for(int i = 0 ; i < n ; ++i){
		cin >> temp;
		if(temp < 0){
			temp = -temp;
			neg++;
		}
		ans += temp;
		mn = min(temp , mn);
	}
	
	if(mn == 0 or neg%2 == 0)
		cout << ans;
	else{
		cout << ans - 2*mn;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a[10010],b[510];
int main()
{
    int n,m,h=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    scanf("%d",&m);
    for(int i=0;i<m;i++)
        scanf("%d",&b[i]);
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
            if(b[i]==a[j]){h++;break;}
    }
    printf("%d\n",h);
    return 0;
}

Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	map<int, int>m;
	rep(i, 2, n)
	{
		int x = i;
		while (x % 2 == 0)
		{
			x /= 2;
			m[2]++;
		}
		for (int j = 3; j <= sqrt(x); j += 2)
		{
			while (x % j == 0)
			{
				x /= j;
				m[j]++;
			}

		}
		if (x > 2)
			m[x]++;
	}
	int ans = 1;
	for (auto itr = m.begin(); itr != m.end(); itr++)
	{
		ans *= (itr->ss + 1) ;
		ans = ans % mod;
	}
	cout << ans << en;


	return 0;
}



Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	if(s.substr(0, 4) == "YAKI"){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 764