akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

enum treeNums { Not, ANum, BNum, CNum};

int main() {
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> ls(N);
  for (int i = 0; i < N; i++) {
    cin >> ls[i];
  }

  int depth = pow(4, N);

  vector<vector<int>> base4_Array(pow(4, N), vector<int>(N));

  for (int i = 0; i < depth; i++) {
    int remainder = i;
    for(int j = 0; j < N; j++) {
      int quotient = (remainder / (pow(4, (N - 1) - j)));
      remainder %= (int)pow(4, (N - 1) - j);
      base4_Array[i][j] = quotient;
    }
  }

  vector<int> costList(depth);
  for (int i = 0; i < depth; i++) {
    int cost = 0;
    int connectLengthA = 0;
    int connectLengthB = 0;
    int connectLengthC = 0;
    for (int j = 0; j < N; j++) {
      int base4 = base4_Array[i][j];
      if (base4 == ANum) {
        connectLengthA += ls[j];
        cost += 10;
      } else if (base4 == BNum) {
        connectLengthB += ls[j];
        cost += 10;
      } else if (base4 == CNum) {
        connectLengthC += ls[j];
        cost += 10;
      }
    }
    if ((connectLengthA != 0) && (connectLengthB != 0) && (connectLengthC != 00)) {
      cost += (abs(connectLengthA - A) + abs(connectLengthB - B) + abs(connectLengthC - C) - 30);
    } else {
      cost = 1e9;
    }
    costList[i] = cost;
  }

  sort(costList.begin(), costList.end());
  cout << costList[0] << endl;
};

Measured memory_bytes: 5248
N,M,X = map(int, input().split())
C = [0]*N
A = [[[0]*M] for i in range(N)]
for i in range(N):
    C[i], *A[i] = map(int, input().split())
MAX = 10**5 * 12 + 1
minprice = MAX
for b in range(2**N):
    abilityList = [0]*M
    price = 0
    for i in range(N):
        if b >> i & 1 == 1:
            abilityList = [x+y for (x,y) in zip(abilityList, A[i])]
            price += C[i]
    judge = True
    for ability in abilityList:
        if ability < X:
            judge = False
    if judge:
        minprice = min(minprice, price)
ans = minprice if minprice != MAX else -1
print(ans)

Measured memory_bytes: 9276
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

long long calc(long long N, set<int> &st, long long A[3], long long B[3]){
    if(st.empty()) return N;
    if(st.size() == 1){
        int i = *st.begin();
        long long l = N / A[i];
        return N + l * (B[i]-A[i]);
    }else if(st.size() == 2){
        int i = *st.begin();
        st.erase(st.begin());
        int j = *st.begin();
        long long mx = 0;
        for(long long l=0; l<=N; l++){
            long long M = N - l * A[i];
            if(M < 0) break;
            long long m = M / A[j];
            mx = max(mx, l*(B[i]-A[i])+m*(B[j]-A[j]));
        }
        return N + mx;
    }else if(st.size() == 3){
        long long mx = 0;
        for(long long l=0; l<=N; l++){
            for(long long m=0; m<=N; m++){
                long long M = N - l * A[0] - m * A[1];
                if(M < 0) break;
                long long n = M / A[2];
                mx = max(mx, l*(B[0]-A[0])+m*(B[1]-A[1])+n*(B[2]-A[2]));
            }
        }
        return N + mx;
    }
}

int main(){
    long long N;
    cin >> N;
    long long A[3], B[3];
    for(int i=0; i<3; i++)
        cin >> A[i];
    for(int i=0; i<3; i++)
        cin >> B[i];

    set<int> st0, st1;
    for(int i=0; i<3; i++)
        if(A[i] < B[i])
            st0.insert(i);
        else if(A[i] > B[i])
            st1.insert(i);

    N = calc(N, st0, A, B);
    N = calc(N, st1, B, A);
    cout << N << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            boolean[] b = new boolean[n]; // AC
            int[] wCount = new int[n]; // WA count
            int ac = 0;
            for (int i = 0; i < m; i++) {
                int p = in.nextInt();
                String s = in.next();
                if (b[p - 1]) { // AC
                    continue;
                }
                if (s.equals("WA")) {
                    wCount[p - 1]++;
                } else {
                    b[p - 1] = true;
                    ac++;
                }
            }
            int totalWa = 0;
            for (int i = 0; i < n; i++) {
                if (b[i]) {
                    totalWa += wCount[i];
                }
            }
            out.println(ac + " " + totalWa);
        }

    }
}



Measured memory_bytes: 65764
from heapq import heapify, heappush, heappop

n, m = map(int, input().split())
e = []
for _ in range(m):
    a, b = map(int, input().split())
    e.append((a - 1, b - 1))
    e.append((b - 1, a - 1))


class Graph:
    def __init__(self, n, e, wv=None, we=None):
        self.n = n
        self.e = list(map(tuple, e))
        self.wv = wv
        self.we = we

        self.adjlist = self.__get_adjlist()
        self.wedict = self.__get_wedict()

    def __get_adjlist(self):
        adjlist = [[] for _ in range(self.n)]

        for v0, v1 in self.e:
            adjlist[v0].append(v1)

        return adjlist

    def __get_wedict(self):
        return dict(zip(self.e, self.we))


def dijkstra(graph, s):
    INF = float('inf')

    d = [INF for _ in range(graph.n)]
    d[s] = 0
    prev = [None for _ in range(graph.n)]

    queue = []
    heappush(queue, (0, s))

    while queue:
        di, v = heappop(queue)
        for neighbor in graph.adjlist[v]:
            dtmp = d[v] + graph.wedict[(v, neighbor)]
            if dtmp < d[neighbor]:
                d[neighbor] = dtmp
                prev[neighbor] = v
                heappush(queue, (dtmp, neighbor))

    return d, prev


graph = Graph(n=n, e=e, we=[1] * (2 * m))

_, prev = dijkstra(graph, 0)

print('Yes')
for p in prev[1:]:
    print(p + 1)


Measured memory_bytes: 110472
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    res = [None] * n
    x = (sum(a[::2]) - sum(a[1::2])) // 2
    for i in range(n):
        res[i] = x * 2
        x = a[i] - x
    
    return res

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

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

#define ll          long long
#define mp	    make_pair
#define pb          push_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 all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
void solve(){
	string s;
	 cin>>s;
	 int mini =INT_MAX;
	 rep(i,0,s.length()){
		 string asn = s.substr(i, 3);
		 int p = stoi(asn);
		 mini = min(mini, abs(753-p));
	}
	cout<<mini<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 1000010;
const int mod = 998244353;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,m;

int fac[maxn],inv[maxn];

int C(int n,int m){
	return 1ll*fac[n+m]*inv[n]%mod*inv[m]%mod;
}

void Work(){
	int ans=n;
	int t=fexp(2ll*C(n,m)%mod,mod-2);
	REP(i,1,m)ans=(1ll*C(i,i)*C(n-i,m-i)%mod*t+ans)%mod;
	iout(ans);
}

void Init(){
	read(n,m);
	if(n<m)swap(n,m);
	fac[0]=1;REP(i,1,n+m)fac[i]=1ll*fac[i-1]*i%mod;
	inv[n+m]=fexp(fac[n+m],mod-2);RREP(i,n+m,1)inv[i-1]=1ll*inv[i]*i%mod;
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 8064
def divisors(x):
    c = 0
    for i in range(1, x+1):
        if x % i == 0:
            c += 1

    return c


n = int(input())
count = 0
for m in range(1, n+1):
    if m % 2 == 0:
        continue

    if divisors(m) == 8:
        count += 1

print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i = 0;i<n;++i)
#define fri(i,a,b) for(int i= a;i<=b;++i)
#define fro(i,a,b) for(int i= a;i>=b;--i)
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define fi first
#define se second
#define pb(x) push_back(x)
#define  mp(x,y) make_pair(x,y)
#define endl  "\n"
#define  ii  pair<int,int>
#define  LL  long long
#define  maxm(a,b,c)  max(a,max(b,c))
int q1,q2,a[100010],dp[100010];
int yo(int n)
{	
	dp[1]=0;
	dp[2]=abs(a[1]-a[2]);
	fri(i,3,n)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	
	return dp[n];
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<n+1;++i)cin>>a[i];
	cout<<yo(n);
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var h = double.Parse(Console.ReadLine());
            var cnt = Math.Floor(Math.Log2(h)) + 1;
            Console.WriteLine((long) Math.Pow(2, cnt) - 1);
        }

    }
}

Measured memory_bytes: 27800
import Control.Applicative
import Control.Monad

main :: IO ()
main = do
  m <- readLn
  unless (m == 0) $ do
    us <- replicateM (m - 1) readLn
    n <- readLn
    vs <- replicateM (n - 1) readLn
    print $ solve us vs
    main

solve :: [Int] -> [Int] -> Int
solve us vs
  | abs (su - sv) < eps = 0
  | su > sv = 1
  | otherwise = 2
  where
    toRad x = pi * x / 180.0
    f xs = let ts = (360 - sum xs) : xs
           in sum . map (sin . toRad . fromIntegral) $ ts
    su = f us
    sv = f vs

eps :: Double
eps = 1e-9



Measured memory_bytes: 4420
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n;
int a[10000],b[10000];

void solve(){
    cin >> n;
    rep(i,n-1){
        cin >> b[i];
    }
    int ans=0;
    rep(i,n){
        if (i==0) a[i]=b[i];
        else if (i==n-1) a[i]=b[i-1];
        else a[i]=min(b[i],b[i-1]);
        ans+=a[i];
    }
    cout << ans << endl;

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const long long INF = 100000000;
using namespace std;

int main(){
    int e;
    while(cin >> e, e){
        long long ans = INF;
        for(long long y = 0; y * y <= 1000000; y++){
            for(long long z = 0; z * z <= 1000000; z++){
                if(e - y * y - z * z * z < 0) continue;
                ans = min(ans, y + z + (e - y * y - z * z * z));
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3076
fun main(args: Array<String>) {
    val cList = mutableListOf<List<Int>>()
    var result = "No"
    for(i in 0 until 3){
        cList.add(readLine()!!.split(" ").map(String::toInt))
    }


val sumA = cList[0][0] + cList[1][1] + cList[2][2]
val sumB = cList[0][1] + cList[1][2] + cList[2][0]
val sumC = cList[0][2] + cList[1][0] + cList[2][1]

val judgeSum = (cList[0].sum() + cList[1].sum() + cList[2].sum()) / 3

if(sumA == judgeSum && sumB == judgeSum && sumC == judgeSum){
    result = "Yes"
}

println(result)

}

Measured memory_bytes: 38428
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
string S,T;

bool solve(){
    cin >> S >> T;
    REP(i, S.size()){
        if(S[i] != T[i]) return false;
    }
    return true;
}

int main() {
    cout << (solve() ? "Yes" : "No") << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin >> s.at(i);
    }
    bool ans = true;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(s.at(i)==s.at(j)&&i!=j){
                ans = false;
            }
        }
    }
    for(int i=0;i<n-1;i++){
        char b[2];
        b[0] = s.at(i).back();
        b[1] = s.at(i+1).front();
        if(b[0]!=b[1]){
            ans = false;
        }
    }
    if(ans){
    cout <<"Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, r;
  cin >> n >> r;
  if(n >= 10) {
    cout << r << endl;
  } else {
    cout << r + 100 * (10 - n) << endl;
  }
  return 0;
}


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

long long n, k;
string s, lr = "LR";

long long solve();

int main() {
  cin >> n >> k >> s;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  vector<long long> v;
  bool ch = lr[1] == s[0];
  long long cnt = 0;
  for(int i = 0; i < n;) {
    while(i < n && s[i] == lr[ch]) ++i, ++cnt;
    ch = 1 - ch;
    v.push_back(cnt);
    cnt = 0;
  }
  long long ans = n - v.size();
  return ans + min(k * 2, (long long)v.size() - 1);
}

Measured memory_bytes: 1528
#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 2e5 + 5, S = 2e3 + 5, MOD = 1e9 + 7;

int add(int x, int y) {
    return (x += y) >= MOD ? x - MOD : x;
}

int n, a[N], b[N], dp[S + S + 500][S + S + 400], inv[S * 5], fac[S * 5], ifac[S * 5];

int C(int x, int y) {
    return 1LL * fac[x] * ifac[y] % MOD * ifac[x - y] % MOD;
}

int main() {
    inv[0] = inv[1] = fac[0] = ifac[0] = 1;
    for (int i = 2; i <= S * 4; ++i) inv[i] = 1LL * inv[MOD % i] * (MOD - MOD / i) % MOD;
    for (int i = 1; i <= S * 4; ++i) fac[i] = 1LL * fac[i - 1] * i % MOD;
    for (int i = 1; i <= S * 4; ++i) ifac[i] = 1LL * ifac[i - 1] * inv[i] % MOD;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &a[i], &b[i]);
        dp[S - a[i]][S - b[i]]++;
    }
    for (int i = 1; i <= S + S; ++i) {
        for (int j = 1; j <= S + S; ++j) {
            dp[i][j] = add(dp[i][j], add(dp[i][j - 1], dp[i - 1][j]));
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans = add(ans, dp[S + a[i]][S + b[i]]);
        ans = add(ans, MOD - C(a[i] + a[i] + b[i] + b[i], a[i] + a[i]));
    }
    printf("%d\n", 1LL * ans * inv[2] % MOD);
    return 0;
}

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

int main()
{
	int r, g, b, n;
	cin >> r >> g >> b >> n;

	int cnt = 0;

	for(int i=0;i<=n/r;i++){
		int rest = n - i*r;
		for(int j=0;j<=rest/g;j++){
			int rest2 = rest - j*g;
			if(rest2 % b == 0){
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

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

int a[22], b[22], c[22];


int main(void) {
	
	int n; cin >> n;
	int ans = 0;
	int pre = -1;
	for (int i = 0; i < n; i++)
	{	
		int  x;
		cin >> x;
		a[i] = --x;
	}
	for (int i = 0; i < n; i++)
	{
		int  x;
		cin >> x;
		b[i] = x;
		ans += x;
	}
	for (int i = 0; i < n - 1; i++)
	{
		int  x;
		cin >> x;
		c[i] = x;
	}
	for (int i = 0; i < n-1; i++)
	{
		if (a[i] == a[i + 1] - 1) ans += c[a[i]];
	}

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

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


int main()
{
    int N, L;
    std::cin >> N >> L;
    std::vector<std::string> a(N);
    for(int i = 0; i < N; i++){
        std::cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    for(int i = 0; i < N; i++){
        std::cout << a.at(i);
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
const int vx[4]={0,1,0,-1},vy[4]={1,0,-1,0};
using namespace std;

int main(){
  string T;
  cin>>T;
  int N=0,W=0,S=0,E=0;
  
  REP(i,T.size()){
    if(T.at(i)=='N') N++;
    if(T.at(i)=='W') W++;
    if(T.at(i)=='S') S++;
    if(T.at(i)=='E') E++;
  }
  
  bool CAN=true;
  if(N>0&&S==0) CAN=false;
  if(S>0&&N==0) CAN=false;
  if(W>0&&E==0) CAN=false;
  if(E>0&&W==0) CAN=false;
  
  if(CAN) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define MaxN 300+10
using namespace std;
typedef long long LL;
LL roads[MaxN][MaxN]; 
LL next_roads[MaxN][MaxN];
LL min(LL a,LL b)
{
	return a<b ? a:b;
}
int main()
{
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		for(int k=1;k<=N;k++)
		{
			scanf("%lld",&roads[i][k]);
			next_roads[i][k]=roads[i][k];
		}
	for(int k=1;k<=N;k++)
		for(int p=1;p<=N;p++)
			for(int q=1;q<=N;q++)
				next_roads[p][q]=min(next_roads[p][q],next_roads[p][k]+next_roads[k][q]);
	int row,colomn;
	for(row=1;row<=N;row++)
	{
		for(colomn=1;colomn<=N;colomn++)
			if(roads[row][colomn]!=next_roads[row][colomn])
				break;
		if(colomn<=N)
			break;
	}
	if(!(row==N+1 && colomn==N+1))
		printf("-1\n");
	else
	{
		LL total=0;
		for(int i=1;i<N;i++)
			for(int k=i+1;k<=N;k++)
			{
				int zhan;
				for(zhan=1;zhan<=N;zhan++)
				{
					if(zhan==i || zhan==k)
						continue;
					if(next_roads[i][k]==next_roads[i][zhan]+next_roads[zhan][k])
						break;
				}
				if(zhan==N+1)
					total+=next_roads[i][k];
			}
		printf("%lld\n",total);
	}
	
	return 0;
}

Measured memory_bytes: 1664
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var: ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        c: i64,
        b: [i64; m],
        a: [[i64;m]; n],
    }
    let mut ans = 0;
    for a_ in a {
        let res: i64 = a_
            .into_iter()
            .zip(b.iter())
            .map(|(x1, x2)| x1 * x2)
            .sum::<i64>();
        ans += if res + c > 0 { 1 } else { 0 };
    }
    println!("{}", ans);
}


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

typedef long long ll;

// 小数の丸め誤差を無視するために小さな数を足す。
/*
int main() {
  ll a;
  double b;
  cin >> a >> b;
  // 0.01 * 100 = 0.9999999...
  // 0.01 * 100 = 1.0000000...
  // のどちらかに誤差が出る
  // 0.5を足すことで1.05..., 1.05....になって切り捨てで1.00になる。
  ll b_ll = b * 100 + 0.5;
  a *= b_ll;
  a /= 100;
  cout << a << endl;
}*/

// 浮動点小数に100をかけると誤差が出るのでbを文字列として受け取って'.'を消した後、整数としてパースする。
int main() {
  string s;
  ll a;
  cin >> a >> s;
  auto b = [](string s) {
    auto sz = s.find('.');
    auto t = s.erase(sz, 1);
    return stoll(t);
  };

  auto t = b(s);
  cout << a * t / 100 << endl;
}

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

int main() {
	int a, b;
	cin >> a >> b;/*二つの整数*/



	if ((a *b)%2 == 0) {/**/
		cout << "Even" << endl;
	}
	else  {
		cout << "Odd" << endl;
	}
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL N;
  cin >> N;
  VL xs(100);
  xs[0] = 2;
  xs[1] = 1;
  FOR(i,2,100)
	xs[i] = xs[i-1] + xs[i-2];

  cout << xs[N] << endl;

  return 0;
}


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

using namespace std;

const int MOD = 100000;

int main() {
    while (true) {
        int n, numLimit, sum;
        cin >> n >> numLimit >> sum;
        if (n == 0)break;
        n *= n;

        vector<vector<int>> dp(n + 1, vector<int>(sum + 1));
        dp[0][0] = 1;

        for (int nowNum = 1; nowNum <= numLimit; nowNum++) {
            for (int backCount = n - 1; backCount >= 0; backCount--) {
                for (int backSum = sum - nowNum; backSum >= 0; backSum--) {
                    dp[backCount + 1][backSum + nowNum] += dp[backCount][backSum];
                    dp[backCount + 1][backSum + nowNum] %= MOD;
                }
            }

        }

        cout << dp[n][sum] << endl;
    }
    return 0;
}


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

void NA();

int main(){
	double n,nd;
	int ni;
	int inte[8],dec[4];
	
	while (cin >> n,n > 0){
		//初期化
		for ( int i = 0; i < 8; i++ ){
			inte[i] = 0;
			if ( i < 4 )
				dec[i] = 0;
		}
		
		ni = (int) n;
		nd = n - (int)n;
		
		for ( int i = 0; i < 8; i++ ) {
			inte[i] = ni % 2;
			ni = ni / 2;
		}
		if ( ni > 1 ) {
			NA ();
			continue;
		}
		
		for ( int i = 0; i < 4; i++ ) {
			dec[i] = (int)(nd * 2);
			if ( !dec[i] )	nd = nd * 2;
			else	nd = nd * 2 - 1;
		}
		if ( nd ) {
			NA ();
			continue;
		}
		
		for ( int i = 7; i >= 0; i-- ) {
			cout << inte[i];
		}
		cout << ".";
		for ( int i = 0; i < 4; i++ ) {
			cout << dec[i];
		}
		cout << endl;
	}
	return 0;
}

void NA () {
	cout << "NA" << endl;
}

Measured memory_bytes: 1224
using System;
using System.Linq;

public static class abc119b
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var y = 0.0;
        const double r = 380000.0;
        for (var i = 0; i != n; ++i)
        {
            var t = Console.ReadLine().Split();
            if (t[1] == "JPY") y += double.Parse(t[0]);
            else y += double.Parse(t[0]) * r;
        }
        System.Console.WriteLine($"{y:f5}");
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller(char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int H,W;
    scanf("%d%d",&H,&W);
    vector<vc> S(H,vc(W));
    rep(i,H) {
        rep(j,W) {
            cin>>S[i][j];
        }
    }
    vii v(H,vi(W,0));
    rep(i,H) {
        rep(j,W) {
            if(S[i][j]=='#') v[i][j]=9;
        }
    }
    rep(i,H) {
        rep(j,W) {
            if(i-1>=0&&S[i-1][j]=='#') v[i][j]++;
            if(i+1<H&&S[i+1][j]=='#') v[i][j]++;
            if(j-1>=0&&S[i][j-1]=='#') v[i][j]++;
            if(j+1<W&&S[i][j+1]=='#') v[i][j]++;
            if(i-1>=0&&j-1>=0&&S[i-1][j-1]=='#') v[i][j]++;
            if(i-1>=0&&j+1<W&&S[i-1][j+1]=='#') v[i][j]++;
            if(i+1<H&&j-1>=0&&S[i+1][j-1]=='#') v[i][j]++;
            if(i+1<H&&j+1<W&&S[i+1][j+1]=='#') v[i][j]++;
        }
    }
    rep(i,H) {
        rep(j,W) {
            if(v[i][j]>=9) cout<<"#";
            else cout<<v[i][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    
    int n,x,c;
    for(int l=0;;l++){
        c=0;
        scanf("%d%d",&n,&x);
        if(n==0 && x==0){
            break;
        }else{
            for(int i=1;i<=n;i++){
                for(int j=1;j<=n;j++){
                    for(int k=1;k<=n;k++){
                        if(i+j+k==x && i!=j && j!=k && k!=i){
                            c++;
                        }else{}
                    }
                }
                
            }}
        c=c/6;
        printf("%d\n",c);
    }
    return 0;
}



Measured memory_bytes: 2088
import java.util.Scanner;

public class Main {
    public static void main(String[] args ){
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int y = scanner.nextInt();

        System.out.println(gcd(x, y));
    }

    public static int gcd(int x, int y){
        int X = x, Y = y;
        if(X < Y) {
            X = y;
            Y = x;
        }
        if(X % Y == 0)
            return Y;
        else
            return gcd(Y, X % Y);
    }

}


Measured memory_bytes: 26316
import itertools

N = int(input())

for h, n in itertools.product(range(1, 3501), range(1, 3501)):
    if (4*n*h-N*(n+h)) == 0:
        continue
    elif N*h*n % (4*n*h-N*(n+h)) == 0 and N*h*n // (4*n*h-N*(n+h)) > 0:
        break

print(h, n, N*h*n // (4*n*h-N*(n+h)))

Measured memory_bytes: 40940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


string S;
int K;

int main() {
  cin >> S >> K;
  vector<string> vec;
  for (int i = 0; i < S.size(); i++) {
    for (int j = 1; j <= K; j++) {
      string tmp = S.substr(i, j);
      vec.pb(tmp);
    }
  }
  sort(all(vec));
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << vec[K-1] << endl;
}


Measured memory_bytes: 1660
rolls = []
for _ in range(int(input())):
    a, b = [int(x) for x in input().split()]
    rolls.append([a, b])
has = 0
for i in rolls:
    if i[0] == i[1]:
        has += 1
        #print(has, i)
        if has == 3:
            break
    else:
        has = 0
print("Yes" if has == 3 else "No")

Measured memory_bytes: 9216
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int N, M, x[12], y[12], a1[12], a2[12];
int dp[1 << 12];
int main() {
	while (true) {
		cin >> N >> M; if (N == 0 && M == 0)break;
		for (int i = 0; i < N; i++)cin >> x[i];
		for (int i = 0; i < M; i++)cin >> y[i];
		if (N <= M) {
			for (int i = 0; i < N; i++)a1[i] = x[i];
			for (int i = 0; i < M; i++)a2[i] = y[i];
		}
		if (N > M) {
			for (int i = 0; i < N; i++)a2[i] = x[i];
			for (int i = 0; i < M; i++)a1[i] = y[i];
			swap(N, M);
		}
		for (int i = 0; i < (1 << 12); i++)dp[i] = 0;
		int maxn = 0;
		for (int i = 0; i < (1 << M); i++) {
			int bit[12], cnt = 0;
			for (int j = 0; j < M; j++) { bit[j] = (i / (1 << j)) % 2; cnt += bit[j]; }
			if (cnt >= N)continue;
			for (int j = 0; j < M; j++) {
				if (bit[j] == 1)continue;
				int Q = abs(a1[cnt] - a2[j])*(abs(a1[cnt] - a2[j]) - 30)*(abs(a1[cnt] - a2[j]) - 30);
				dp[i + (1 << j)] = max(dp[i + (1 << j)], dp[i] + Q); maxn = max(maxn, dp[i + (1 << j)]);
			}
		}
		cout << maxn << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin>>s;
    int a=700;
    for(int i=0;i<3;i++){
        if(s[i]=='o'){
            a+=100;
        }
    }
    cout<<a<<endl;
        return 0;
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<vector>

using namespace std;


int main(){
    int N;
    scanf("%d",&N);
    vector<int> v(N);
    
    double ans;
    for(int i=0;i<N;i++){
        scanf("%d",&v[i]);
    }

        
    sort(v.begin(),v.end());
    
    double sum=v[0];
    for(int i=1;i<N;i++){
        sum = (sum + (double)v[i]) / 2;
    }
    
    printf("%lf",sum);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
#define NINF -1e9

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int N, M;
    cin >> N >> M;
    vector<pii> as;
    vector<int> costs = {2, 5, 5, 4, 5, 6, 3, 7, 6};
    rep(i, M){
        pii a;
        cin >> a.first;
        a.second = costs[a.first - 1];
        as.push_back(a);
    }
    sort(as.begin(), as.end(), greater<pii>());

    vector<int> dp(5e4 + 1, NINF);
    dp[0] = 0;

    rep(i, N){
        for(auto a : as){
            dp[i + a.second] = max(dp[i] + 1, dp[i + a.second]);
        }
    }
    // dp[cost] = max(ketasuu)
    int keta = dp[N];

    int cost = N;
    string ans;
    for(int i = keta; i > 0; i --){
        for(auto a : as){
            if(cost - a.second >= 0 && dp[cost - a.second] == i - 1){
                ans += to_string(a.first);
                cost -= a.second;
                break;
            }
        }
    }
    if(ans.size() == 0){
        ans = "0";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

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

	public void solve(Scanner sc) {
		String n = sc.next();
		char first = n.charAt(0);
		char second = n.charAt(1);
		char third = n.charAt(2);
		
		if(first == second && second == third) {
			System.out.println(n);
			return;
		}
		
		StringBuilder answerBuilder = new StringBuilder();
		if(first < second) {
			int answerNum = Character.getNumericValue(first) + 1;
			answerBuilder.append(answerNum).append(answerNum).append(answerNum);
			System.out.println(answerBuilder.toString());
			return;
		} else if(first == second) {
			if(second < third) {
				int answerNum = Character.getNumericValue(first) + 1;
				answerBuilder.append(answerNum).append(answerNum).append(answerNum);
				System.out.println(answerBuilder.toString());
				return;
			} else {
				answerBuilder.append(first).append(first).append(first);
				System.out.println(answerBuilder.toString());
				return;
			}
		} else {
			answerBuilder.append(first).append(first).append(first);
			System.out.println(answerBuilder.toString());
			return;
		}
	}
}


Measured memory_bytes: 21844
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

H, = map(int, input().split())

ans = 0
c = 0
while H != 0:
    H = int(H / 2)
    if c == 0:
        ans += 1
    else:
        ans += 2 ** c
    c += 1

print(ans)


Measured memory_bytes: 3444
if __name__ == '__main__':
    n = int(input())
    s = list(input())
    right_parentheses = 0
    needed_right_parentheses = 0
    for i in s:
        if i == '(':
            right_parentheses += 1
        else:
            if right_parentheses > 0:
                right_parentheses -= 1
            else:
                needed_right_parentheses += 1

    ans = ['('] * needed_right_parentheses + s + [')'] * right_parentheses
    print(''.join(ans))


Measured memory_bytes: 2940
data = [[[0 for i in range(10)] for j in range(3)] for h in range(4)]
n = int(input())
for o in range(n):
    a = input().split()
    b = int(a[0])
    f = int(a[1])
    r = int(a[2])
    v = int(a[3])
    data[b - 1][f - 1][r - 1] += v

for b in range(4):
    for f in range(3):
        for r in range(10):
            print('',data[b][f][r],end='')
        print()
    if b<3:
        print('#'*20)

Measured memory_bytes: 7732
def main():
  N, K = map(int, input().split())
  A = list(map(int, input().split()))
  flag = [False] * N
  flag[0] = True
  move = [0]
  num = 0
  while True:
    num += 1
    c_next =  A[move[-1]]-1
    move.append(c_next)
    if flag[c_next]:
      break
    else:
      flag[c_next] = True
  for i, j in enumerate(move):
    if j == c_next:
      if c_next == 0:
        key = 0
      else:
        key = i
      c_cycle = num-key
      break
  if K < key:
    print(move[K]+1)
  else:
    K -= key
    K %= c_cycle
    print(move[key + K]+1)

if __name__  == "__main__":
  main()

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

public class Main{
    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String h[]=new String[11];
        int a[][] = new int[10][100];
        int i=0;
        int j;

        try {
        while(!(h[i] = br.readLine()).equals("-")){
        	j = Integer.parseInt(br.readLine());
        	for(int m=0; m < j; m++){
        		a[i][m] = Integer.parseInt(br.readLine());
        	}
        	i++;
        }

        } catch (IOException e) {
        	e.printStackTrace();
        }
        for(int k=0; k<i; k++){
        	for(int l=0; l < 100; l++) {
        		if(a[k][l]==0) break;
        		String first = h[k].substring(0, a[k][l]);
        		String last = h[k].substring(a[k][l]);
        		h[k] = last + first;
        	}
        	System.out.println(h[k]);
        }

    }
}


Measured memory_bytes: 24464
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;

int matrix[1005][1005];
int main(){
  int R, C, A, B;
  cin >> R >> C >> A >> B;

  for(int i=1; i<=B; i++){
    for(int j=A+1; j<=C; j++)
      matrix[i][j] = 1;
  }

  for(int i=B+1; i<=R; i++){
    for(int j=1; j<=A; j++){
      matrix[i][j] = 1;
    }
  }

  for(int i=1; i<=R; i++){
    for(int j=1; j<=C; j++){
      cout << matrix[i][j];
    }
    cout << endl;
  }
} 

Measured memory_bytes: 7388
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  string s[n];
  rep(i,n) R s[i];
  set<string> se;
  rep(i,n) {
    if(se.count(s[i])) {
      pr("No");
      return;
    }
    se.in(s[i]);
  }
  rep(i,n-1) {
    if(s[i].back()!=s[i+1][0]) {
      pr("No");
      return;
    }
  }
  pr("Yes");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 892
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
x = int(input())
#n, m = map(int, sys.stdin.readline().split())
#s = input()
#h = list(map(int, sys.stdin.readline().split()))

for i in range(1, 1000):
    for j in range(-1000, 1000):
        if i ** 5 - j ** 5 == x:
            print(i, j)
            sys.exit()


Measured memory_bytes: 9564
def is_primt(x):
    if x == 2:
        return True

    if x < 2 or x % 2 == 0:
        return False

    for i in range(3, int(x**0.5)+1, 2):
        if x % i == 0:
            return False

    return True


N = int(input())
cnt = 0
for _ in range(N):
    i = int(input())
    cnt += is_primt(i)
print(cnt)


Measured memory_bytes: 5668
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;
 
 
 
int main() {
    int n;
    scanf("%d",&n);

    int a[101] = {};

    if(n<=9){
        puts("0"); return 0;
    }
  
    for (int i=2;i<=n;i++){
        int i_dash = i;
        int j = 2;
        while(i_dash > 1){
            if(i_dash % j == 0){
                a[j]++;
                i_dash = i_dash / j;
                continue;
            }else{
                j++;
            }
        }
    }

    int c74 = 0;
    int c24 = 0;
    int c14 = 0;
    int c4 = 0;
    int c2 = 0;

    for(int i=2;i<101;i++){
        if(a[i] >= 74){
            c74++; c24++; c14++; c4++; c2++;
        }else if(a[i] >= 24){
            c24++; c14++; c4++; c2++;
        }else if(a[i] >= 14){
            c14++; c4++; c2++;
        }else if(a[i] >= 4){
            c4++; c2++;
        }else if(a[i] >= 2){
            c2++;
        }
    }

    int ans = 0;

    ans += c74;
    ans += c24 * (c2 - 1);
    ans += c14 * (c4 - 1);
    ans += c4 * (c4 - 1) * (c2 - 2) / 2;

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

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

const long long int MOD=1e9+7;

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    int cnt=0, total=1;
    while(total<b){
        cnt++;
        total--;
        total+=a;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 256
# https://atcoder.jp/contests/abc079/tasks/abc079_d

from collections import Counter
from functools import reduce

def warshall(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][k] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j]

h,w = map(int,input().split())
magic = []
for i in range(10):
    magic.append(list(map(int,input().split())))

counter = Counter()
for _ in range(h):
    counter.update(Counter(map(int, input().split())))
warshall(magic, 10)
print(reduce(lambda x,y:x+y, [magic[k][1] * v for k,v in counter.items() if k > -1]))


Measured memory_bytes: 3564