akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, K;
    cin >> N >> K;

    vector<bool> s(N, false);

    REP(i, K) {
        int d; cin >> d;
        REP(j, d) {
            int a;
            cin >> a;
            a--;
            s[a] = true;
        }
    }

    int cnt = 0;
    REP(i, N) if (!s[i]) cnt++;

    cout << cnt << endl;
}


Measured memory_bytes: 3656
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<int> A, B, C;
	for (int i = 0; i < N; i++)
	{
		int x;
		cin >> x;
		A.push_back(x);
	}
	for (int i = 0; i < N; i++)
	{
		int x;
		cin >> x;
		B.push_back(x);
	}
	for (int i = 0; i < N - 1; i++)
	{
		int x;
		cin >> x;
		C.push_back(x);
	}
	int ans = 0;
	ans += B[0];
	int pre = A[0];
	for (int i = 1; i < N; i++)
	{
		ans += B[i];
		if (A[i] - pre == 1)
		{
			ans += C[pre - 1];
		}
		pre = A[i];
	}
	cout << ans << endl;
	return 0;
}

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

int main(){

    int n;
    cin >> n;
    int taro_point = 0;
    int hanako_point = 0;
    for(int i = 0; i < n; ++i){
        string taro_card, hanako_card;
        cin >> taro_card >> hanako_card;
        if(taro_card < hanako_card){
            hanako_point += 3;
        }
        else if(taro_card > hanako_card){
            taro_point += 3;
        }
        else{
            taro_point++;
            hanako_point++;
        }
    }

    cout << taro_point << " " << hanako_point << endl;

    return 0;
}


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

int main() {
	int H[10010], W[10010];
	int n = 0;

	while (1) {
		cin >> H[n] >> W[n];
		if (!H[n] && !W[n]) break;
		++n;
	}

	for (int i = 0; i < n; ++i) {
		for (int h = 0; h < H[i]; ++h) {
			for (int w = 0; w < W[i]; ++w) {
				if (!h || h == (H[i] - 1)) cout << "#";
				else if (!w || w == (W[i] - 1)) cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3084
#include <iostream>
#include <cmath>
#include <complex>
using namespace std;

typedef complex<double> P;
#define X real()
#define Y imag()

#define PI 3.14159265358979


class Triangle{
    P a, b, c;
    double edgeA, edgeB, edgeC;
    double angleA, angleB, angleC;
    double LawOfCosines(double a, double b, double c){
        return acos((b*b+c*c-a*a) / (2.0*b*c));
    }

public:
    Triangle(P p1, P p2, P p3){
        a = p1;
        b = p2;
        c = p3;

        edgeB = abs(c-a);
        edgeA = abs(b-c);
        edgeC = abs(a-b);
        angleA = LawOfCosines(edgeA, edgeB, edgeC);
        angleB = LawOfCosines(edgeB, edgeC, edgeA);
        angleC = LawOfCosines(edgeC, edgeA, edgeB);
    }

    double circumscribedCircleRadius(){
        return (edgeA / sin(angleA) / 2.0);
    }

    double circumscribedCircleX(){
        double A = sin(2.0*angleA);
        double B = sin(2.0*angleB);
        double C = sin(2.0*angleC);

        return ((a.X*A + b.X*B + c.X*C) / (A+B+C));
    }
    double circumscribedCircleY(){
        double A = sin(2.0*angleA);
        double B = sin(2.0*angleB);
        double C = sin(2.0*angleC);

        return ((a.Y*A + b.Y*B + c.Y*C) / (A+B+C));
    }
};

int main(){
    int n;
    double x1, x2, x3;
    double y1, y2, y3;

    cin >> n;

    for(int i=1; i<=n; i++){
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

        P a(x1, y1);
        P b(x2, y2);
        P c(x3, y3);

        Triangle hoge(a, b, c);
        double r = hoge. circumscribedCircleRadius();

        printf("%.3f %.3f %.3f\n", hoge.circumscribedCircleX(), hoge.circumscribedCircleY(),hoge.circumscribedCircleRadius());
    }

    return 0;
}

Measured memory_bytes: 0
n, m = map(int, input().split())
submissions = [list(input().split()) for _ in range(m)]
count_penalty = [0] * (n + 1)
count_ac = [0] * (n + 1)

for i in range(m):
    ploblem = int(submissions[i][0])
    if submissions[i][1] == "AC":
        count_ac[ploblem] = 1

    elif count_ac[ploblem] != 1 and submissions[i][1] == "WA":
        count_penalty[ploblem] += 1

for i in range(n + 1):
    if count_ac[i] != 1:
        count_penalty[i] = 0

print("{} {}".format(count_ac.count(1), sum(count_penalty)))


Measured memory_bytes: 31892
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    string s; cin >> s;
    int z = 0, o = 0;
    rfor(c, s) {
        if(c == '0') z++;
        else o++;
    }
    if(z > o) swap(z, o);
    print(z * 2);

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    if (k > a + b)
        cout << "0 0";
    else if (k > a)
    {
        cout << "0 ";
        k -= a;
        cout << b - k;
    }
    else if (k == a)
    {
        cout << "0 " << b;
    }
    else
        cout << a - k << " " << b;
}

Measured memory_bytes: 3620
N=int(input())
A=list(map(int,input().split()))
num_list=[0]*(N+1)
num_list[0]=3
ans=1
for a in A:
  ans*=num_list[a]
  num_list[a]-=1
  num_list[a+1]+=1
print(ans%1000000007)

Measured memory_bytes: 14056
N,K=map(int,input().split())
h=list(map(int,input().split()))
h=sorted(h)
left=-1
right=len(h)
while right-left>1:
  mid=(right+left)//2
  if h[mid]>=K:
    right=mid
  else:
    left=mid
print(len(h)-left-1)

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

#define MOD 10000007
#define f first
#define s second
#define pb push_back
#define es " "
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main(){
    fastio;
    int n, a;
    cin >> n >> a;
    if(n%a==0){
        cout << n/a << endl;
    }else{
        cout << (n/a)+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def append_zero(x):
    if 0 in x:
        return
    if x[0] > 0:
        x.insert(0, 0)
        return
    if x[len(x)-1] < 0:
        x.append(0)
        return
    for i in range(1, len(x)):
        if x[i-1] < 0 and x[i] > 0:
            x.insert(i, 0)
            return


def solve(N, K, x):
    y = [0]
    append_zero(x)
    n = len(x)
    z = 0
    for i in range(1, n):
        y.append(y[i-1] + x[i] - x[i-1])
        if x[i] == 0:
            z = i
    # print(x)
    # print(y)
    if n == K:
        if n-1 == z or z == 0:
            return y[n-1]
        else:
            l = y[z] + y[n-1]
            r = y[n-1] - y[z] + y[n-1]
            return min(l, r)
    ans = 10e20
    for i in range(n - K):
        k = i + K
        if k <= z:
            ans = min(ans, y[z] - y[i])
        if z <= i:
            ans = min(ans, y[k] - y[z])
        if i <= z and z < k:
            l = y[z] - y[i] + y[k] - y[i]
            r = y[k] - y[z] + y[k] - y[i]
            ans = min(ans, l, r)
    return ans


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, K, x))


if __name__ == '__main__':
    main()


Measured memory_bytes: 19304
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, -1, sizeof(mat))
typedef long long ll;
int dp[11][2222];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  vector<vector<int> > book(10);
  FOR(i,0,N) {
    int c, g; cin >> c >> g;
    g--;
    book[g].push_back(c);
  }
  FOR(i,0,10) sort(book[i].rbegin(), book[i].rend());
  vector<vector<int> > book_sum(10);
  FOR(i,0,10) {
    book_sum[i].push_back(0);
    FOR(j,0,book[i].size()) {
      book_sum[i].push_back(book_sum[i][j] + book[i][j]);
    }
  }
  CLR(dp);
  dp[0][0] = 0;
  FOR(i,0,10) {
    FOR(j,0,K+1) {
      FOR(k,0,book[i].size()+1) {
        if(j < k || dp[i][j-k] == -1) continue;
        dp[i+1][j] = max(dp[i+1][j], dp[i][j-k] + book_sum[i][k] + k * (k - 1));
      }
    }
  }
  cout << dp[10][K] << endl;
  return 0;
}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
int h,w;
vector<vector<char>> f(105,vector<char>(105));
int bfs(){
    queue<pair<int,int>> q;
    vector<vector<int>> fn(105,vector<int>(105,inf));
    if(f[0][0] == '#')fn[0][0] = 1;
    else fn[0][0] = 0;
    q.push({0,0});
    while(!q.empty()){
        auto cur = q.front();q.pop();
        int i=cur.first;
        int j=cur.second;
        int n=fn[i][j];
        for(int x=0;x<=1;++x)for(int y=0;y<=1;++y)if((x== 1 and y==0)or(x==0 and y==1)){
            int dy = i + y;
            int dx = j + x;
            int tmp = n;
            if(dy >=h or dx >= w)continue;
            if(f[i][j] == '.' and  f[dy][dx] == '#')tmp++;
            if(fn[dy][dx] > tmp)q.push({dy,dx}),fn[dy][dx] = tmp;
        }
    }
    return fn[h-1][w-1];
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin>>h>>w;
    for(int i=0;i<h;++i)for(int j=0;j<w;++j){
        cin>>f[i][j];
    }
    cout << bfs() << endl;
    return 0;
}

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

public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn = null;
		List<int[]> data = new ArrayList<int[]>();
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			while( stdIn.hasNext() ){
				String str = stdIn.next();
				String[] s = str.split(",");
				int[] temp = new int[2];
				temp[0] = Integer.parseInt(s[0]);
				temp[1] = Integer.parseInt(s[1]);
				data.add(temp);
			}
			int sum = 0;
			int num = 0;
			for(int[] a : data){
				sum += a[0]*a[1];
				num += a[1];
			}
			double ave = (double)num/data.size();
			System.out.printf("%d%n%.0f%n", sum, ave);
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return result;
}



int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    IOS

    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll arr[n];
    for(int i=0;i<n;i++)
    	arr[i]=(ll)(s[i]=='W');

    for(int i=1;i<n;i++)
    	arr[i]+=arr[i-1];

    ll ans=(n-1)-(arr[n-1]-arr[0]);
    ans=min(ans,arr[n-2]);

    for(int i=1;i<n-1;i++)
    	ans=min(ans,max((n-i-1)-(arr[n-1]-arr[i]),arr[i-1]));

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

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

// NOTE TO SELF // try to simplyfy the problem

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

#define ll long long int

//const int mod=1000000007;

using namespace std;


const ll INF= 1e18L+5 ;

int main()
{

    ll n,W;
    cin>>n>>W;

    
    vector<int> weight(n),value(n);
    
    rep(i,n)
    cin>>weight[i]>>value[i];
    
    int sum_val=0;
    
    rep(i,n)
    sum_val+=value[i];
    
    
    vector<ll> dp(sum_val+1,INF);
    
    dp[0]=0;
    
    for(int item=0;item<n;++item )
    {
        
        for(int value_alread=sum_val-value[item];value_alread>=0;--value_alread)
        {
            dp[value_alread+value[item]]=min(dp[value_alread+value[item]],dp[value_alread]+weight[item]);
        }
        
    }

    
    ll ans=0;
    
    for(int i=0;i<=sum_val;i++)
    {
        if(dp[i]<=W)
            ans=max(ans,(ll) (i));
        
    }
    
    cout<<ans<<endl;
    
}


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

//.define
// #define FILE_IN_OUT
#define RET(_x)                       return cout << (_x) << '\n', 0;
#define all(_obj)                     (_obj).begin(), (_obj).end()
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define CeilDiv(_dividend, _divider)  (((_dividend) - 1LL + (_divider)) / (_divider))
#define sz(_obj)                      static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)                     std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)                     {}
#endif
#define endl "\n"
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int n;
    cin >> n;
    map<string, int> cnt;
    loop(n) {
        string s;
        cin >> s;
        ++cnt[s];
    }
    cout << "AC x " << cnt["AC"] << endl;
    cout << "WA x " << cnt["WA"] << endl;
    cout << "TLE x " << cnt["TLE"] << endl;
    cout << "RE x " << cnt["RE"] << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repv(i,a,b) for(ll i=b-1;i>=a;i--)

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;}

string s;
map<char,int> m;
vector<char> v;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>s;
    for(int i=0;i<4;i++)
    {
        if(m[s[i]]==0)
        { 
            v.pb(s[i]);
        }
        m[s[i]]++;
    }
    if(v.size()!=2) cout<<"No"<<endl;
    else
    {
        if(m[v[0]]==2 && m[v[1]]==2) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static public void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            int sum =0;
            if(n == 0 && x == 0) break;
            for(int i = 1; i<=n-2; i++){
                for(int j = i+1;j<=n-1;j++){
                    for(int k = j+1;k<=n;k++){
                        if(i+j+k == x) sum++;
                    }
                }
            }
            System.out.println(sum);
        }
        sc.close();
    }
}


Measured memory_bytes: 26636
// AOJ 1380 Medical Checkup
// 2018.2.6 bal4u

#include <stdio.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, t, h, p;
	long long a, b;

	n = in(), t = in();
	b = 0, p = 0;
	while (n--) {
		h = in();
		if (p < h) p = h;
		a = (t-b)/p + ((t-b)%p >= h);
		if (a < 0) a = 0;
		printf("%lld\n", a+1);
		b += h;
	}
	return 0;
}


Measured memory_bytes: 2104
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

namespace io
{
	const int maxb = 1 << 15;
	char b[maxb], *s = b, *t = b;
	bool Getchar(char &ch)
	{
		return ch = s == t && (t = (s = b) + fread(b, 1, maxb, stdin)) == b ? 0 : *s ++;
	}
}

int Getint()
{
	using namespace io;
	char ch;
	while (Getchar(ch) && (ch < '0' || ch > '9'));
	int s = ch - '0';
	while (Getchar(ch) && ch >= '0' && ch <= '9')
		s = s * 10 + ch - '0';
	return s;
}

const int maxn = 1e5 + 10;

struct Edge
{
	Edge *next;
	int to;
} pool[maxn * 2], *p = pool, *head[maxn];

void AddEdge(int fr, int to)
{
	p->to = to;
	p->next = head[fr];
	head[fr] = p ++;
}

int a[maxn], d[maxn], f[maxn];

bool Dfs(int u, int fa)
{
	if (d[u] == 1)
	{
		f[u] = a[u];
		return true;
	}
	int s = 0, cnt = 0, Mx = 0;
	for (Edge *t = head[u]; t; t = t->next)
	{
		int v = t->to;
		if (v == fa) continue;
		if (!Dfs(v, u)) return false;
		s += f[v];
		if (s > a[u] * 2) return false;
		Mx = max(Mx, f[v]);
	}
	int x = s - a[u];
	if (x < 0) return false;
	s = min(s - Mx, s / 2);
	if (x > s) return false;
	f[u] = a[u] - x;
	return true;
}

int main()
{
	int n = Getint();
	for (int i = 1; i <= n; ++ i) a[i] = Getint();
	if (n == 2)
	{
		if (a[1] == a[2]) puts("YES"); else puts("NO");
		return 0;
	}
	memset(head, 0, sizeof head);
	for (int i = 1; i < n; ++ i)
	{
		int u = Getint(), v = Getint();
		++ d[u], ++ d[v];
		AddEdge(u, v);
		AddEdge(v, u);
	}
	int root;
	for (root = 1; d[root] == 1; ++ root);
	if (!Dfs(root, 0) || f[root]) puts("NO"); else puts("YES");
	return 0;
}


Measured memory_bytes: 11904
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    string str, order, p;
    cin >> str;
    int q, a, b;
    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> order;
        if(order == "replace"){
            cin >> a >> b;
            cin >> p;
            for(int j = a; j<=b; j++){
                str.at(j) = p.at(j - a);
            }
        }
        else if(order == "reverse"){
            cin >> a >> b;
            reverse(str.begin() + a, str.end() - (str.size() - 1 - b));
        }
        else if(order == "print"){
            cin >> a >> b;
            for(int j = a; j <= b; j++){
                cout << str.at(j);
            }
            cout << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3200
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
long long c[110000];
long long d[110000];

long long ret[110000];
map<long long,long long>M[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	d[0]=a;
	for(int i=0;i<b;i++){
		scanf("%lld",d+i+1);
	}
	b++;
	int n=0;
	for(int i=b-1;i>=0;i--){
		if(i==b-1||c[n-1]>d[i]){
			c[n++]=d[i];
	//		printf("%lld\n",d[i]);
		}
	}

	M[0][c[0]]=1;
	for(int i=0;i<n;i++)c[i]=-c[i];
	for(int i=0;i<n;i++){
		if(i==n-1){
			for(map<long long,long long>::iterator it=M[i].begin();it!=M[i].end();it++){
				long long L=it->first;
				long long R=it->second;
				ret[0]+=R;
				ret[L]-=R;
			}
			continue;
		}
		long long nx=-c[i+1];
		for(map<long long,long long>::iterator it=M[i].begin();it!=M[i].end();it++){
			long long L=it->first;
			long long R=it->second;
			long long SH=L/nx;
			long long AM=L%nx;
			if(SH){
				M[i+1][nx]+=R*SH;
			}
			if(AM){
				int to=upper_bound(c,c+n,-AM)-c-1;
			//	printf("%d %lld %d\n",i,AM,to);
				M[to][AM]+=R;
			}
		}
	}
	long long cur=0;
	for(int i=0;i<a;i++){
		cur+=ret[i];
		printf("%lld\n",cur);
	}
}

Measured memory_bytes: 31616
#include <iostream>
#include <string>

enum {
	S = 0,
	H,
	C,
	D
};

int main(int argc, char const* argv[])
{
	int card[4][52] = {};
	char output_mark[5] = "SHCD";
	int len, num;
	std::string str;

	std::cin >> len;

	for (size_t i = 0; i < len; i++)
	{
		std::cin >> str >> num;

		if(str == "S")
			card[S][num] = 1;
		else if (str == "H")
			card[H][num] = 1;
		else if (str == "C")
			card[C][num] = 1;
		else if (str == "D")
			card[D][num] = 1;
	}

	for (size_t i = 0; i < 4; i++)
		for (size_t j = 0; j < 13; j++)
			if(card[i][j + 1] != 1)
				std::cout << output_mark[i] << " " << j + 1 << std::endl;

	return 0;
}

Measured memory_bytes: 1200
# https://atcoder.jp/contests/abc141/tasks/abc141_d
from copy import deepcopy
from heapq import heappop, heappush, heapify
n, m = map(int, input().split())

items = [-int(i) for i in input().split()]
heapify(items)
while m:
    m -= 1
    item = -1 * heappop(items)
    item //= 2
    heappush(items, -1 * item)
pay = 0
for i in items:
    pay += -1 * i
print(pay)

Measured memory_bytes: 76780
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

char a[100];
int main()
{
	scanf("%s", a + 1);
	int len = strlen(a + 1);
	for(int i = 1; i <= len - 8; i++) printf("%c", a[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<stack>
using namespace std;

int main() {
	string s;
	while (getline(cin, s)) {
		if (s == ".")break;

		int flg = 1;
		stack<char>st;
		for (int i = 0;i < s.size();i++) {
			if (s[i] == '(') {
				st.push(s[i]);
			}
			else if (s[i] == '[') {
				st.push(s[i]);
			}
			else if (s[i] == ')') {
				if (!st.empty()&&st.top() == '(')st.pop();
				else {
					flg = 0;
					break;
				}
			}
			else if (s[i] == ']'){
				if(!st.empty()&&st.top()=='[') st.pop();
				else {
					flg = 0;
					break;
				}
			}
		}

		if (!st.empty())flg = 0;

		if (flg == 1)cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;
const long long MOD = 1000000007;

int N, K;
int a[100100];
ll dp[110][100100];
ll sum[110][100100];

int main(){
  cin >> N >> K;
  a[0] = 0;
  REP(i, 1, N) cin >> a[i];

  REP(i, 0, N){
    dp[i][0] = 1;
    sum[i][0] = 1;
  }
  REP(j, 0, K){
    sum[0][j] = 1;
  }

  REP(i, 1, N){
    REP(j, 1, K){
      if(j <= a[i]) dp[i][j] = sum[i-1][j];
      else dp[i][j] = sum[i-1][j] - sum[i-1][j-a[i]-1];
      dp[i][j] %= MOD;
      sum[i][j] = sum[i][j-1] + dp[i][j];
    }
  }

  cout << dp[N][K] << endl;

  return 0;
}


Measured memory_bytes: 160000
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		/*1 時間は 60 分、1 分は 60 秒なので、1 時間は 3600 秒になります。
		これらの定数 3600、60 を基に剰余算（%）や割り算を使って、
		秒の単位から時間、分の単位に変換してみましょう。 */
		Scanner sc = new Scanner(System.in);
		int watchstyle_hms  = sc.nextInt();
		int h = watchstyle_hms / 3600;
        int m = (watchstyle_hms % 3600) / 60;
        int s = ((watchstyle_hms % 3600) % 60);
        System.out.println(h+":"+m+":"+s);
	}
}


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

int main(){
    string s,t;
    cin>>s>>t;
    int a[26]={0},b[26]={0};
    for(int i=0;i<s.length();i++){
        a[s[i]-'a']++;
    }
    for(int i=0;i<t.length();i++){
        b[t[i]-'a']++;
    }
    vector<int>v1,v2;
    for(int i=0;i<26;i++){
        if(a[i]>0)v1.push_back(a[i]);
        if(b[i]>0)v2.push_back(b[i]);
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    int f=0;
    for(int i=0;i<v1.size();i++){
        if(v1[i]!=v2[i]){
            f=1;
            break;
        }
    }
    if(f==1)cout<<"No";
    else cout<<"Yes";
}


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

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

int main() {
  ll n;
  cin >> n;
  vector<ll> p(n), q(n), v(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  rep(i, n) v[i] = i+1;
  int a, b;
  int count = 0;
  do {
    bool a_match = true;
    bool b_match = true;
    rep(i, v.size()) {
      if (p[i] != v[i]) {
        a_match = false;
        continue;
      }
    }
    if (a_match) {
      a = count;
      //cout << "a: " << a << endl;
    }

    rep(i, v.size()) {
      if (q[i] != v[i]) {
        b_match = false;
        continue;
      }
    }
    if (b_match) {
      b = count;
      //cout << "b: " << b << endl;
    }

    count++;
  } while(next_permutation(v.begin(), v.end()));//順列全探索
  cout << abs(a-b) << endl;
  return 0;
}

Measured memory_bytes: 256
=begin
=end
include Math

while(n = gets.to_f) != 0
  s = gets.split.map(&:to_f)
  m = s.sum / n

  ans = 0.0
  s.each{|v|
    ans += (v - m)**2
  }

  puts sprintf("%.5f", sqrt(ans/n))
end


Measured memory_bytes: 6944
#include <bits/stdc++.h>
#define ll long long
#define PRIME 1000000007
using namespace std;
vector<bool> isprime(1000001, true);
void sieve()
{
	for(int i=2;i*i<=1000001;i++)
	{
		if(isprime[i]==true)
		{
			for(int j=(i+i);j<=1000001;j=j+i)
			{
				isprime[j]=false;
			}
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int a,b;
	cin>>a>>b;
	if(a==1)
	{
		a=14;
	}
	if(b==1)
	{
		b=14;
	}
	if(a>b)
	{
		cout<<"Alice";
	}
	else if(a<b)
	{
		cout<<"Bob";
	}
	else
	{
		cout<<"Draw";
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int main()
{
	fast;
	long long int x;
	cin>>x;
	long long int step=0, p=100;
	while(p<x){
		++step;
		p += p/100;
	}
	cout << step << endl;
    return 0;
}


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

int main(){
    int a, b, d;
    while(cin >> a >> b >> d, a+b+d){
        int ansx = 1<<20, ansy = 1<<20;
        for(int x = -10000; x <= 10000; x++){
            if(abs(d-a*x)%b)    continue;
            int tmpx = abs(x), tmpy = abs(d-a*x)/b;
            if(tmpx+tmpy < ansx+ansy || (tmpx+tmpy==ansx+ansy && a*tmpx+b*tmpy < a*ansx+b*ansy)){
                ansx = tmpx, ansy = tmpy;
            }
        }
        cout << ansx << " " << ansy << endl;
    }
    return 0;
}


Measured memory_bytes: 3012
#include<iostream>
using namespace std;
int main(){
  int N, M;
  cin >> N;
  string blue[N];
  for (int i = 0; i < N;i++){
    cin >> blue[i];
  }
  
  cin >> M;
  string red[M];
  for (int i = 0; i < M;i++){
    cin >> red[i];
  }
  
  int cnt_2 = 0;
 
  for (int i = 0; i < N; i++)
  { int cnt = 1;
    string tmp = blue[i];
    for (int j = i + 1; j < N;j++){
      if(blue[j]==tmp){
        cnt++;
        //cout << "+tmp "<<blue[j] << endl;
      }
    }
    
    for (int j = 0; j < M;j++){
      if(red[j]==tmp){
        cnt--;
        //cout << "-tmp " << red[j];
      }
        if(cnt==0)
          break;
      
    }
    if(cnt_2<cnt){
      cnt_2 = cnt;
    }
  }
   cout << cnt_2 << endl;
}


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

int main() {
	string s;
	cin>>s;
	int i=0, j=s.size();
	for(; i<s.size(); i++){
		if (s[i]=='A') break;
	}
	
	for(; j>=0; j--){
		if (s[j]=='Z') break;
	}
	
	cout<<j-i+1;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)

#define MAX 7368791
int m,n;
bool flag[MAX];

int main(){
  while(cin>>m>>n,m||n){
    rep(i,MAX+1){
    flag[i]=false;
  }
    for(int i=m;;i++){
      if(!flag[i]){
	  if(n==0){
	    cout<<i<<endl;
	    break;
	  }
	  else{
	    n--;
	    for(int j=i;j<=MAX;j+=i){
	      flag[j]=true;
	    }
	  }
	}
    }
  }
  
	  
  return 0;
}

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

#define   M             100005
#define   ll            long long
#define   PI            atan(1.0)*4
#define   mst(x,v)      memset(x,v,sizeof(x))
#define   inf           1e9
#define   rush()        int T;scanf("%d",&T);while(T--)

typedef   pair<int,int> P;

int n,m,l,r,dis,flag;
int f[M],d[M];

int ff(int x) {
	if (f[x] == x) return x;
	int a=f[x];
	int b=ff(a);
	
	d[x]+=d[a];
	f[x]=b;
	
	return b;
}


//          bi - ai = dis              a 接在 b下面 
int mix(int a,int b,int dis) {
	int fa=ff(a);
	int fb=ff(b);
	
	if(fa==fb)
		return d[b]-d[a]==dis;
	
	f[fb]=fa; // fb 的父亲变成了 fa
	d[fb]=d[a] - d[b] + dis;
	
	return 1;
}



int main() {

	scanf("%d %d",&n,&m);
	flag=0;
	
	for(int i=0;i<=n;i++) f[i]=i; 
	
	while(m--) {
		scanf("%d %d %d",&l,&r,&dis);
		if(!mix(l,r,dis))
			flag=1;
	}
	
	puts(flag?"No":"Yes");
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int x, y;
    cin >> x >> y;
    int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    cout << ( a[x] == a[y] ? " Yes " : " No ") << endl ;

}

Measured memory_bytes: 256
import std.stdio, std.math, std.conv;

void main() {
  for(int a, b; readf("%d %d\n", &a, &b);) {
    int[int] used;
    int len = 0;
    int c;
    bool first = true;

    // a *= 10;
    // writeln(a);
  
    do {
      c = a % b;
      if (first && a / b == 0) first = false;
      else write(a / b);
      if (c == 0) break;      
      if (c in used) break;
      else {
        used[c] = len;
        a = c * 10;
      }
      len++;
    } while(true);
    writeln;
    if (c != 0) {
      for(int i = 0; i <= used[c] - 1; i++) write(" ");
      for(int i = used[c] + 1; i <= len; i++) write("^");
      writeln;
    }
  }
}

Measured memory_bytes: 1224
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

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

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	char s; cin >> s;

	int n = (int)'A'+26;

	bool f = false;
	for (int i = (int)'A'; i < n; i++) {
		if ((int)s == i) {
			f = true;
		}
	}

	if (f) {
		cout << "A" << endl;
	}
	else {
		cout << "a" << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

bool array_equal(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return false;
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return false;
    }
  }
  return true;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

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;
}

int main() {
  std::cout << std::setprecision(9);
  int n, m;
  long k;
  cin >> n >> m >> k;
  vector<long> a_sum(n);
  for(int i=0; i<n; i++) {
    long a;
    cin >> a;
    if(i == 0) {
      a_sum.at(i) = a;
    }
    else {
      a_sum.at(i) = a_sum.at(i - 1) + a;
    }
  }
  vector<long> b_sum(m);
  for(int i=0; i<m; i++) {
    long b;
    cin >> b;
    if(i == 0) {
      b_sum.at(i) = b;
    }
    else {
      b_sum.at(i) = b_sum.at(i - 1) + b;
    }
  }

  int ans = 0;
  int a_num = 0;
  while(a_sum.at(a_num) <= k) {
    a_num++;
    if(a_num == n) {
      break;
    }
  }
  ans = a_num;

  for(int i=0; i<m; i++) {
    if(b_sum.at(i) > k) {
      break;
    }
    if(a_num > 0) {
      while(a_sum.at(a_num - 1) + b_sum.at(i) > k) {
        a_num--;
        if(a_num == 0) {
          break;
        }
      }
    }
    if(ans < a_num + i + 1) {
      ans = a_num + i + 1;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 6428
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&a!=c||a==c&&a!=b||b==c&&b!=a)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    sort(rall(a));
    ll ans = a[0], j = 1;
    for(int i = 2; i < n; i++){
        ans += a[j];
        if(i % 2 == 1)j++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4840
n,m,x=map(int,input().split())

A=[[] for _ in range(n)] #Aでn個
c=[0]*n #c={0,0,...,0(n個)}

for i in range(n):
    c_as=list(map(int,input().split()))
    c[i],A[i]=c_as[0],c_as[1:]

INF=10**9
ans=INF

for s in range(0,1<<n):
    smart=[0]*m
    cost_sum=0
    for i in range(n):
        if (s>>i)%2==0:
            continue
        cost_sum+=c[i]
        for j in range(m):
            smart[j]+=A[i][j]#
    ok=True
    for j in range(m):
        if smart[j]<x:#アルゴリズムxに到達していない
            ok=False
    if ok:
        ans=min(ans,cost_sum)
if ans==INF:
    ans=-1

print(ans)

Measured memory_bytes: 9092
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
	int i,n;
  	cin >> n;
  	int ans = 0;
  	int m;
  	int a[n];
  	int b[n];
  	int c[n-1];
  	
  	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];
 
  	for(i=0; i<n; i++){
      ans = ans + b[a[i]-1];
      if (i != 0 && a[i-1] + 1 == a[i])
        ans = ans + c[a[i-1]-1];
    }
  
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=998244353;
constexpr int N=200000;
mt19937 mt;

int D,c[26],s[200000][26],t[200000],T[200000],v,V,l[26];

int main(){
	scanf("%d",&D);
	for(int i=0;i<26;i++){
		scanf("%d",&c[i]);
	}
	for(int i=0;i<D;i++){
		for(int j=0;j<26;j++){
			scanf("%d",&s[i][j]);
		}
	}
	for(int i=0;i<D;i++){
		t[i]=uniform_int_distribution<int>(0,25)(mt);
	}
	for(int i=0;i<26;i++){
		l[i]=-1;
	}
	for(int i=0;i<D;i++){
		l[t[i]]=i;
		v+=s[i][t[i]];
		for(int j=0;j<26;j++){
			v-=c[j]*(i-l[j]);
		}
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<D;j++){
			if(uniform_int_distribution<int>(0,N*100)(mt)<=N-i){
				T[j]=uniform_int_distribution<int>(0,25)(mt);
			}
			else{
				T[j]=t[j];
			}
		}
		for(int j=0;j<26;j++){
			l[j]=-1;
		}
		V=0;
		for(int j=0;j<D;j++){
			V-=c[T[j]]*(j-l[T[j]]-1)*(j-l[T[j]])/2;
			l[T[j]]=j;
			V+=s[j][T[j]];
		}
		for(int j=0;j<26;j++){
			V-=c[j]*(D-l[j]-1)*(D-l[j])/2;
		}
		if(V>v){
			v=V;
			for(int j=0;j<D;j++){
				t[j]=T[j];
			}
		}
	}
	for(int i=0;i<D;i++){
		printf("%d\n",t[i]+1);
	}
}


Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
#define MAX 10000;
typedef long long int ll;
int main(){
    int n;
    int i, j;
    cin>>n;
    int ara[n];
    for(i=0; i<n; i++){
        cin>>ara[i];
    }
    ll sum=0;
    for(i=0; i<n; i++){
        for(j=i+1; j<n; j++){
            sum += ara[i] * ara[j];
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    int S, W;
    cin >> S >> W;

    cout << (S <= W ? "unsafe" : "safe") << endl;

    return 0;
}


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

def main():
    l = int(input())
    r = len(bin(l)[2:]) - 1
    n = r + 1
    edges = []
    for i in range(1, n):
        edges.append((i, i + 1, 0))
        edges.append((i, i + 1, 2 ** (i - 1)))

    for t in reversed(range(1, n)):
        if l - 2 ** (t - 1) >= 2 ** r:
            edges.append((t, n, l - 2 ** (t - 1)))
            l -= 2 ** (t - 1)
    print(n, len(edges))
    for u, v, w in edges:
        print(u, v, w)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
  ll A,B,C,D;
  cin >> A >> B >> C >> D;
  ll CD_LCM = C * D/__gcd(C,D);
  ll B_kosu = B - (B/C) - (B/D) + B/CD_LCM;
  ll A_kosu = A - (A/C) - (A/D) + A/CD_LCM;

  if(A % C != 0 && A % D != 0)cout << B_kosu - A_kosu + 1 << endl;
  else cout << B_kosu - A_kosu << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int a,b,c;
  a=n/100;
  b=(n/10)%10;
  c=n%10;
  if(a==1){a=9;}
  else{a=1;}
  if(b==1){b=9;}
  else{b=1;}
  if(c==1){c=9;}
  else{c=1;}
  cout << 100*a+10*b+c << endl;
}

Measured memory_bytes: 256
def inpl(): return list(map(int, input().split()))
N, M = inpl()
a1, aN, b1, bN = set(), set(), set(), set()
for i in range(M):
    temp_a, temp_b = inpl()
    if temp_a == 1:
        a1.add(temp_b)
    elif temp_a == N:
        aN.add(temp_b)
    
    if temp_b == 1:
        b1.add(temp_a)
    elif temp_b == N:
        bN.add(temp_a)

if len(a1&bN)!=0 or len(aN&b1)!=0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 19008
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

struct matrix {
	int r, c;
	matrix(int r_ = 0, int c_ = 0) : r(r_), c(c_) {}
};

const int INF = 100000000;
vector<vector<int>> dp;

int mul(int r1, int rm, int c2) { return r1 * c2 * rm; }

int main() {
	int N;
	cin >> N;
	int R, C;
	vector<matrix> mats(N);	
	dp.assign(N+1, vector<int>(N+1, INF)); //[l, r)
	rep(i, N) {
		cin >> R >> C;
		mats[i] = matrix(R, C);
	}

	for(int len = 1; len < N+1; ++len) {
		for(int l = 0; l <= N-len; ++l) {
			int r = l + len;	
			if(l+1 == r) {
				dp[l][r] = 0;	
				continue;	
			}		
			for(int m = l+1; m < r; ++m) {	
				int r1 = mats[l].r;
				int rm = mats[m].r;
				int c2 = mats[r-1].c;
				dp[l][r] = min(dp[l][m] + dp[m][r] + mul(r1, rm, c2), dp[l][r]);
			}
		}
	}
	cout << dp[0][N] << endl;
	return 0;
}

Measured memory_bytes: 1260
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x=sc.nextInt();
		long count = 1;
		for(int i=0;i<3;i++) {
			count *=x;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 26268
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
int main(){
	int n;
	cin >> n;
	while(n--){
		string a,b;
		cin >> a >> b;
		int asize = a.size(),bsize = b.size();
		vector<vector<int> > dp(asize+1,vector<int>(bsize+1,0));
		for(int i=1;i<asize+1;i++){
			for(int j=1;j<bsize+1;j++){
				if(a[i-1] == b[j-1]){
					dp[i][j] = dp[i-1][j-1] + 1;
				}else{
					dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
				}
			}
		}
		/*				for(int i = 0;i<asize+1;i++){
		copy(dp[i].cbegin(),dp[i].cend(),ostream_iterator<int>(cout, " ") );
		cout << endl;
		}*/
				
		cout << dp[asize][bsize] << endl;
	}
}

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

ll binpow(ll a, ll b){
	ll res = 1;
	while(b){
		if(b&1)
			res = (res * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}


signed main() { 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, k; 
	cin>>n>>k;
	ll sum = 0;
	map<ll, ll> m;
	for(int i = k; i >= 1; i--){
		ll cnt = 1;
		ll succ = 0;
		for(int j = 2; j*i <= k; j++){
			cnt++;
			succ += m[i*j];
		}

		ll num = ((binpow(cnt, n) - succ) % MOD + MOD) % MOD;
		m[ll(i)] = num;
		sum = (sum + (num * i) % MOD) % MOD;
	}
	cout << sum;
}


Measured memory_bytes: 9864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;

const int mod = 1000000007;

ll f(ll a, ll b, ll x){
  ll ret = (a * x) / b - a * (x / b);
  return ret;
}

int main(){
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans;
  if (b - 1 >= n){
    ll x = n;
    ans = f(a, b, x);
  } else {
    ll x = b-1;
    ans = f(a, b, x);
  }
  cout << ans << endl;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    vector<int> ans;
    int temp = 1;
    rep(i,n){
        if (a[i] == a[i+1]){
            temp++;
        }
        else{
            ans.push_back(temp);
            temp = 1;
        }
    }
    sort(ans.begin(),ans.end());
    int res = 0;
    int range = ans.size();
    for (int i = 0 ;range > k;i++){
        res += ans[i];
        range--;
    }
    cout << res << endl;
}

Measured memory_bytes: 2168