akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(){
    ll n;
    cin >> n;
    ll m = n;
    vector<pp> v;
    for (ll i = 2; i * i < n+1; i++)
    {
        int j = 0;
        while (n % i == 0)
        {
            n /= i;
            j++;
        }
        if(j!=0)
        {
            v.emplace_back(i, j);
        }
    }
    if(n!=1)v.emplace_back(n, 1);
    int ans = 0;
    for (auto p : v)
    {
        int i = 1;
        while (i<=p.second)
        {
            p.second -= i;
            i++;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
n, a, b = map(int, input().split())
mod = 10**9 + 7


def neko(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    k = min(n - k, k)
    ans = 1
    inv = [1] * (k + 1)
    if k >= 1:
        ans *= (n - k + 1) % mod
    for i in range(2, k + 1):
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        ans = ans * (n - k + i) * inv[i] % mod
    return ans


print((pow(2, n, mod) - 1 - neko(n, a) - neko(n, b)) % mod)


Measured memory_bytes: 10932
import sys

A="A"
B="B"
AB=A+B
O="O"
N="\n"

b={A:0,B:0,AB:0,O:0}
for s in sys.stdin:
    i = s[s.index(',')+1:-1]
    b[i]+=1
print "%d\n%d\n%d\n%d" %(b[A],b[B],b[AB],b[O])

Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,int_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,int_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define M1 100000000000000000ll
#define PRECISE cout.precision(18);
#define BS(v,n) binary_search(v.begin(),v.end(),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater <int>())
#define F first
#define S second
 
bool comp(pair <ll,ll> &p1,pair <ll,ll> &p2){

if(p1.F<p2.F)
	return 1;
if(p1.F==p2.F){
	return p1.S>p2.S;
}
return 0;

}

 
 
int main(){
 

    FAST
//	PRECISE



ll n;
cin>>n;
ll z=0;
ll L=0,LL=0;
ll R=M,LR=0;
ll MA=0;
ve <pair <ll,ll> > dummy;
FOR(i,0,n){
	ll x,y;
	cin>>x>>y;
	y++;
	R=min(R,y);
	if(R==y)
		LR=max(LR,y-x);
	
	L=max(L,x);
	if(L==x)
		LL=max(LL,y-x);
	dummy.pb({x,y});
	MA=max(MA,y-x);
} 
ll ans=max(z,R-L)+MA;

ve <pair <ll,ll> > v;
FOR(i,0,n){
	ll a1=max(z,dummy[i].S-L);
	ll a2=max(z,R-dummy[i].F);
	v.pb({a1,a2});
} 
sort(v.begin(),v.end(),comp);
ll cm=LR;
FOR(i,0,v.size()){

	ll lans=0;
	ll a1=v[i].F;
	lans=a1+cm;
	ans=max(ans,lans);
	cm=min(cm,v[i].S);

}
ans=max(ans,cm+LL);
cout<<ans;






 
return 0;
 }	

Measured memory_bytes: 4848
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long k = sc.nextLong();

		if (k - a <= 0) {
			System.out.println(k);
		} else if (k - a - b <= 0) {
			System.out.println(a);
		} else {
			long n = k - a - b;
			long z = a - n;
			System.out.println(z);
		}

		sc.close();
	}
}

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

void fnInput(vector<int>& rvnLife)
{
  int nLiftSiz;
  cin >> nLiftSiz;
  rvnLife.resize(nLiftSiz);

  for (int& rnLife : rvnLife)
    cin >> rnLife;
}

int fnGcd(int nOne, int nOtr)
{
  if (nOtr == 0)
    return nOne;
  else
    return fnGcd(nOtr, nOne % nOtr);
}

int fnMinLife(const vector<int>& cnrvnLife)
{
  int nMinLife = cnrvnLife[0];

  for (int i = 1; i < cnrvnLife.size(); i++)
    nMinLife = fnGcd(nMinLife, cnrvnLife[i]);

  return nMinLife;
}
 
int main()
{
  vector<int> vnLife;

  fnInput(vnLife);
  cout << fnMinLife(vnLife) << endl;

  return 0;
}

Measured memory_bytes: 3780
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main()
{
    ll k;
    ll n;
    cin >> k >> n;

    vector<ll> a = {};

    ll tmp;
    while (cin >> tmp)
    {
        a.push_back(tmp);
    }

    sort(a.begin(), a.end());

    ll current_min = 1000000000;
    for (auto i = 0; i < a.size(); i++)
    {
        ll start = a.at(i);
        // 逆側
        ll end_index = i == 0 ? a.size() - 1 : i - 1;
        ll end = a.at(end_index);
        if (i == end_index)
        {
            continue;
        }

        ll d;
        if (start <= end)
        {
            d = end - start;
        }
        else
        {
            d = (k - start) + end;
        }

        if (d < current_min)
        {
            current_min = d;
        }
    }
    cout << current_min << endl;

    return 0;
}


Measured memory_bytes: 2420
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); } }_io;
typedef long long ll; typedef long double db;

int main()
{
	int N, X, T;
	cin >> N >> X >> T;
	if (N % X == 0)
	{
		cout << N / X * T << endl;
	}
	else
	{
		cout << N / X * T + T << endl;
	}

	return 0;
}

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

#define ll long long

using namespace std;

int main(void){
  int N,M,K;
  cin >> N >> M >> K;
  ll A[N+1],B[M+1];

  A[0] = B[0] = 0;

  for(ll i=1;i <= N;i++){
    cin >> A[i];
    A[i] += A[i-1];
  }

  for(ll i=1;i <= M;i++){
    cin >> B[i];
    B[i] += B[i-1];
  }

  ll ans = 0,j = M;

  for(ll i=0;i <= N;i++){
    if(A[i] > K) break;
    while(A[i] + B[j] > K){
      j--;
    }
    ans = max(i+j,ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6756
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        int N = NextInt();
        int C = NextInt();
        int[,] list = new int[C + 1, 2 * 100000 + 10];
        for (int i = 0; i < N; i++)
        {
            int s = NextInt() * 2 - 1;
            int t = NextInt() * 2;
            int c = NextInt();
            list[c, s] = 1;
            list[c, t] = -1;
        }
        for (int i = 1; i <= C; i++)
        {
            for (int j = 1; j <= 2 * 100000; j++) list[i, j] += list[i, j - 1];
        }
        int ans = 0;
        for (int i = 0; i <= 2 * 100000; i++)
        {
            int sc = 0;
            for (int j = 1; j <= C; j++) if (list[j, i] > 0) sc++;
            ans = Math.Max(ans, sc);
        }
        Console.WriteLine(ans);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

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

int N;
int a[100005], b[100005];
int c[100005];

vector<int> V;

int val[100005];

int id;

vector<int> Adj[100005];

int check[100005];

void dfs(int K) {
	check[K] = 1;
	val[K] = V[id]; id++;

	for (int j = 0; j<(int)Adj[K].size(); j++) {
		int y = Adj[K][j];
		if (check[y] == 0) { dfs(y); }
	}
}

int main(void) {

	cin >> N;

	for (int i = 1; i <= N - 1; i++) {
		cin >> a[i] >> b[i];
		Adj[a[i]].push_back(b[i]);
		Adj[b[i]].push_back(a[i]);
	}

	int num = 1;
	int max_deg = Adj[num].size();

	for (int i = 1; i <= N; i++) {
		if (max_deg < Adj[i].size()) { max_deg = Adj[i].size(); num = i; }
	}


	for (int i = 1; i <= N; i++) {
		cin >> c[i];
		V.push_back(c[i]);
	}

	sort(V.rbegin(), V.rend());

	dfs(num);

	long long int ans = 0;
	for (int i = 1; i <= N - 1; i++) { ans += V[i]; }

	cout << ans << endl;
	for (int i = 1; i <= N; i++) {
		if (i > 1) { cout << " "; }
		cout << val[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 4736
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		int n=scan.nextInt();
		
		for(int i=1;i<=n;i++){
			if(i%3==0)System.out.printf(" %d",i);
			
			else {
				int x=i;
				while(x>0){
					if(x%10==3){System.out.printf(" %d",i);break;}
					else x/=10;
				}
			}
		}
		System.out.println();
	}
}


Measured memory_bytes: 38908
#include <iostream>
#include <queue>


int main() {
    std::priority_queue<int> PQ;
    while (true) {
        std::string str;
        std::cin >> str;
        if (str == "extract") {
            std::cout << PQ.top() << std::endl;
            PQ.pop();
            continue;
        }
        if (str == "insert") {
            int k;
            std::cin >> k;
            PQ.push(k);
            continue;
        }
        break;
    }
    return 0;
}


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

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		String x;
		x=cin.next();
		for(int i=x.length();i>0;i--){
			char s=x.charAt(i-1);
			System.out.print(s);
		}
		System.out.println("");
	}

}

Measured memory_bytes: 17116
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
int fl;
int fie[11][11];

bool in(int i){
  return 0 <= i && i< 10;
}

int & f(int x, int y){
  if(in(x) && in(y)){
    return fie[x][y];
  } else {
    return fl;
  }
}

void disp(){
  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++){
      cout << f(i,j) << " ";
    }
    cout << endl;
  }
}

int main(){
  memset(fie,0,sizeof(fie));
  int x,y,s;
  char a;
  while(cin >> x >> a >> y >> a >> s){
    f(x,y)++;
    for(int i=0; i<4; i++){
      f(x+dx[i],y+dy[i])++;
      if(s >= 2)
	f(x + dx[i] + dx[(i+1)%4], y + dy[i] + dy[(i+1)%4])++;
	if(s >= 3)
	  f(x+dx[i]*2,y+dy[i]*2)++;
    }
  }
  
  int c = 0, m = 0;
  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++){
      if(!f(i,j)) c++;
      m = max(m,f(i,j));
    }
  }
  cout << c << endl;
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main() {
int M, D; cin >> M >> D;
int ans = 0;
for (int m = 1; m <= M; ++m) {
for (int d = 10; d <= D; ++d) {
int d_1 = d % 10, d_10 = d / 10;
if (d_1 >= 2 && d_10 >= 2 && d_1 * d_10 == m) {
++ans; }
} }
cout << ans << endl; }

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
struct point {
    double x;
    double y;
};
vector<point> vec;
point computeS(point p1, point p2) {
    point p;
    p.x = (p2.x - p1.x) / 3 + p1.x;
    p.y = (p2.y - p1.y) / 3 + p1.y;
    return p;
}
point computeT(point p1, point p2) {
    point p;
    p.x = (p2.x - p1.x) / 3 * 2 + p1.x;
    p.y = (p2.y - p1.y) / 3 * 2 + p1.y;
    return p;
}
point computeU(point s, point t) {
    point vec;
    vec.x = t.x - s.x;
    vec.y = t.y - s.y;
    point vec60;
    vec60.x = vec.x * cos(M_PI / 3) - vec.y * sin(M_PI / 3) + s.x;
    vec60.y = vec.x * sin(M_PI / 3) + vec.y * cos(M_PI / 3) + s.y;
    return vec60;
}
void koch(int n, point p1, point p2) {
    if(n == 0) {
        printf("%lf %lf\n", p1.x, p1.y);
        if(p2.x == 100.0 && p2.y == 0.0)
            printf("%lf %lf\n", p2.x, p2.y);
        return;
    }
    point s = computeS(p1, p2);
    point t = computeT(p1, p2);
    point u = computeU(s, t);

    koch(n - 1, p1, s);
    koch(n - 1, s, u);
    koch(n - 1, u, t);
    koch(n - 1, t, p2);
}
int main() {
    int n;
    cin >> n;
    point p1, p2;
    p1.x = 0.0;
    p1.y = 0.0;
    p2.x = 100.0;
    p2.y = 0.0;

    koch(n, p1, p2);
}


Measured memory_bytes: 3196
#if defined(__GNUC__)
#include <bits/stdc++.h>
#define __int32 __int32_t
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x) std::sort(ALL(x), greater<decltype(x)::value_type>())
#define RSORT2(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)
#define FCT(x) [](int a) -> int {int r = 1; REP(i, a){r *= i;} return r;}(x)

itn main() {
	std::ios::sync_with_stdio(false);

	vector<int> v(3);

	REP(i, 3) {
		cin >> v[i];
	}

	RSORT(v);

	v[1] = v[0] - v[1];
	v[2] = v[0] - v[2];

	int res = v[1];

	v[2] = v[2] - v[1];

	res += v[2] / 2;

	if (v[2] & 0x1) {
		res += 2;
	}

	cout << res << '\n';

	return 0;
}


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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "YES"
#define NO "NO"
#define MOD 1000000000 + 7
#define forit(v) for (auto it = v.begin(); it != v.end(); ++it)

using namespace std;

map<int, int> mem;

// int f(int n) {
//   if (n == 0)
//     return 2;
//   else if (n == 1)
//     return 1;
//   else
//     return f(n - 1) + f(n - 2);
// }

int f(int n) {
  int key = n;
  int val;
  if (mem.count(n)) {
    val = mem.at(n);
  }
  else {
    val = f(n - 1) + f(n - 2);
    mem.insert(make_pair(key, val));
  }

  return val;
}

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int n;
  cin >> n;

  mem.insert(make_pair(0, 2));
  mem.insert(make_pair(1, 1));

  cout << f(n) << endl;

  // cout << num << endl;
  // cout << (flag ? YES : NO) << endl;

  return 0;
}


Measured memory_bytes: 256
# AOJ ITP2_4_A: Reverse
# Python3 2018.6.24 bal4u

n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
	b, e = map(int, input().split())
	s = a[b:e]
	s = s[::-1]
	for j in range(e-b): a[b+j] = s[j]
print(*a)


Measured memory_bytes: 5816
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
int main(){
    int k;
    cin>>k;
    string s1;
    cin>>s1;
    int n=s1.size();
    if(k<n){
        string s2;
        for(int i=0;i<k;i++){
            s2.push_back(s1[i]);
        }
        cout<<s2<<"...";
    }
    else{
        cout<<s1;
    }
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#define int long long
using namespace std;
int aa[123456];
signed main() {
	int n, d; cin >> n >> d;
	aa[n] = 1; aa[d] = 1;
	for (int h = 1; h <= 3; h++) {
		if (aa[h] == 0) {
			cout << h << endl; return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set =
tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    set<string>se;
    while(n--){
        string a;
        cin>>a;
        se.insert(a);
    }
    cout<<se.size();
}

Measured memory_bytes: 19244
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    ll n;
    cin >> n;
    ll copy = n;
    map<ll,int> mii;
    for(ll i=2;i*i<=copy;i++){
        int cnt;
        if(n%i==0){
            cnt = 0;
            while(n%i==0){
                cnt++;
                n/=i;
            }
            mii[i]=cnt;
        }
    }
    if(n!=1){
        mii[n]=1;
    }
    int ans = 0;
    for(auto u : mii){
        int now = 0;
        while(u.second-now-1>=0){
            now++;
            u.second -= now;
        }
        ans += now;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        int reader = int.Parse(ReadLine());
        int[,] map = new int[10,10];

        for(int i=1;i<=reader;i++){
            int tempi = i;
            while(tempi >= 10){
                tempi /= 10;
            }
            int end = i%10;
            int fir = tempi;
            map[fir,end]++;
        }
        
        long ans = 0;
        for(int i=1;i<=9;i++){
            for(int j=1;j<=9;j++){
                ans += map[i,j]*map[j,i];
            }
        }
        
        WriteLine(ans);
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
struct st{int p,b,c;};
bool operator<(st a, st b){return a.c>b.c;}
map<int,vector<int> >e[100000];
vector<int>g[100000];
map<int,int>d[100000];
priority_queue<st>pq;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int p,q,c;
		scanf("%d%d%d",&p,&q,&c);
		p--;q--;
		e[p][c].push_back(q);e[q][c].push_back(p);
		g[p].push_back(c);g[q].push_back(c);
	}
	d[0][0]=0;
	pq.push({0,0,0});
	while(!pq.empty())
	{
		st p=pq.top();pq.pop();
		if(d[p.p][p.b]!=p.c)continue;
		if(d[p.p].find(0)==d[p.p].end()||d[p.p][0]>p.c)
		{
			d[p.p][0]=p.c;
			pq.push({p.p,0,p.c});
		}
		if(p.b==0)
		{
			for(int i=0;i<g[p.p].size();i++)
			{
				int v=g[p.p][i];
				if(d[p.p].find(v)==d[p.p].end()||d[p.p][v]>p.c+1)
				{
					d[p.p][v]=p.c+1;
					pq.push({p.p,v,p.c+1});
				}
			}
			continue;
		}
		for(int i=0;i<e[p.p][p.b].size();i++)
		{
			int v=e[p.p][p.b][i];
			if(d[v].find(p.b)==d[v].end()||d[v][p.b]>p.c)
			{
				d[v][p.b]=p.c;
				pq.push({v,p.b,p.c});
			}
		}
	}
	if(d[n-1].find(0)==d[n-1].end())puts("-1");else printf("%d\n",d[n-1][0]);
	return 0;
}

Measured memory_bytes: 84460
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int M;
    cin >> M;
    cout << 48 - M << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
 
dicS = {}
dicT = {}

alphabet = "abcdefghijklmnopqrstuvwxyz"

for _a in alphabet:
    dicS[_a] = []
    dicT[_a] = []

for i,_s_ in enumerate(S):
    dicS[_s_].append(i)
   
for i,_t_ in enumerate(T):
    dicT[_t_].append(i)

for _s in dicS:
    dicS[_s] = tuple(dicS[_s])

for _t in dicT:
    dicT[_t] = tuple(dicT[_t])

flg = True
for t in dicS.values():
    if not t in dicT.values():
        flg = False
        
if flg:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 20528
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    long long sum = 0;
    int a[n];
    int cnt[100001] = {};
    for(int i = 0; i < n; i++){
        cin >> a[i];
        cnt[a[i]]++;
        sum += a[i];
    }

    int q;
    cin >> q;
    int b[q],c[q];
    for(int i = 0; i < q; i++){
        cin >> b[i] >> c[i];
    }
    for(int i = 0; i < q; i++){
        sum += (c[i]-b[i]) * cnt[b[i]];
        cout << sum << endl;
        cnt[c[i]] += cnt[b[i]];
        cnt[b[i]] = 0;
        
    }
    return 0;
}


Measured memory_bytes: 5148
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;


ll gcd(ll x, ll y){
    if(y==0)return x;
    return gcd(y,x%y);
}

ll gcd(vector<ll> a){
    ll ans = a[0];
    rrep(i,a.size()-1){
        ans = gcd(ans,a[i]);
    }
    return ans;
}

int main(){
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    rep(i,n)a[i] = abs(a[i]-x);
    cout << gcd(a)<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;






int main() {
    string s;
    cin >> s;
    if (s.size() == 2) {
        cout << s << endl;
    }
    else cout << s[2] << s[1] << s[0] << endl;


    




    return 0;
}

Measured memory_bytes: 768
all_even = lambda ys: not any(map(lambda y: y % 2, ys))
div_2 = lambda ys: list(map(lambda y: y // 2, ys))

input()
xs = [int(x) for x in input().split()]
count = 0
while all_even(xs):
  count += 1
  xs = div_2(xs)

print(count)


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vector< bool > isprime(100001, true);

bool ok(int x)
{
    if (x % 2 == 0) return false;
    return isprime[x] && isprime[(x + 1) / 2];
}

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

    isprime[0] = isprime[1] = false;
    for (int i = 2; i * i <= 100000; ++i)
    {
        if (isprime[i])
        {
            for (int j = i + i; j <= 100000; j += i)
            {
                isprime[j] = false;
            }
        }
    }

    vs32 s(100001);
    s[0] = 0;
    rep (i, 100000)
    {
        s[i + 1] = s[i] + (ok(i + 1) ? 1 : 0);
    }

    int q;
    cin >> q;
    int l, r;
    rep (i, q)
    {
        cin >> l >> r;
        cout << s[r] - s[l - 1] << "\n";
    }

    return 0;
}



Measured memory_bytes: 1024
a,b=gets.split
a=a.to_i
b=b.to_i

i=a
ans=0
(b-a+1).times{
    k=i.to_s
    s=k.split("")
    t=s.reverse
    
    if s==t
        ans+=1
    end
    
    
  i+=1  
}

puts ans

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

using namespace std;

int main(){
  int n,a[100000]={0},ancer=0;
  cin>>n;
  for(int i=0;i<n;i++){
  	cin>>a[i];
  }
  sort(a,a+n);
  a[n]=-1;
  int tmp=0,count=0;
  for(int i=0;i<=n;i++){
  	/*
  	cout<<a[i]<<endl;
  	cout<<"count:"<<count<<" tmp:"<<tmp<<endl;
  	*/
  	if(i==n){
  		if(tmp>count){
  			ancer+=count;
  		}
  		else if(tmp<count){
  			ancer+=(count-tmp);
  		}
  		tmp=count=0;
  	}
  	else{
  		if(tmp!=a[i]){
	  		if(tmp>count){
	  			ancer+=count;
	  		}
	  		else if(tmp<count){
	  			ancer+=(count-tmp);
	  		}
	  		tmp=count=0;
  		}
  		else{
  			count++;
  		}
	  	if(tmp==0){
	  		tmp=a[i];
	  		++count;
	  	}
//  		cout<<"count:"<<count<<" tmp:"<<tmp<<endl;
  	}
//  	cout<<"ancer:"<<ancer<<endl;
  }
  /*
  for(int i=0;i<n;i++){
  	cout<<a[i]<<" ";
  }
  cout<<endl;
  */
  cout<<ancer<<endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i) >> b.at(i);
    }
    for(int i=0; i<n-2; i++){
        if(a.at(i)==b.at(i) && a.at(i+1)==b.at(i+1) && a.at(i+2)==b.at(i+2)){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int N;
bool check(vector<string>& S, int A, int B){
  REP(i, N){
    REP(j, N){
      if(S[(i+A)%N][(j+B)%N] != S[(j+A)%N][(i+B)%N]) return false;
    }
  }
  return true;
}
int main(){
  cin >> N;
  vector<string> S(N);
  REP(i, N){
    cin >> S[i];
  }
  int ans = 0;
  REP(i, N){
    if(check(S, i, 0)){
      ans++;
    }
  }
  cout << ans * N << endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
using namespace std;
int a[20];
int main()
{
    int n,k;
    while(~scanf("%d%d",&n,&k))
    {
        memset(a,0,sizeof(a));
        for(int i=0; i<k; i++)
        {
            int q;
            scanf("%d",&q);
            a[q]=1;
        }
        int ans=9;
        int f1=0,sum=0;
        for(int l=0;l<=9;l++){
        for(int i=0; i<=9; i++)
        {
            for(int j=0; j<=9; j++)
            {
                for(int k=0; k<=9; k++)
                {
                    for(int r=0; r<=9; r++)
                    {
                        sum=l*10000+i*1000+j*100+k*10+r;
                         int fa=0;
                          if(sum>=n)
                          {
                             ans=sum;
                              int r=0;
                              int s[20];
                              while(ans)
                              {
                                  s[r++]=ans%10;
                                  ans/=10;
                              }
                              for(int i=0;i<r;i++)
                              {
                                  if(a[s[i]]==1)
                                  {
                                      fa=1;
                                      break;
                                  }
                              }
                             if(fa==0)
                             {
                              f1=1;

                              break;
                             }
                          }
                    }
            if(f1==1) break;
                }
        if(f1==1) break;
            }
    if(f1==1)break;
    }
    if(f1==1) break;
    }
    if(f1==1)
    printf("%d\n",sum);
    else printf("0\n");
    }
}


Measured memory_bytes: 256
n, k = gets.chomp.split(' ').map(&:to_i)

ans = 0
1.upto(n).each do |i|
  # 最初に i が出た
  tmp = 1
  loop do
    if k <= i * tmp
      break
    end
    tmp *= 2
  end
  ans += 1r / n / tmp
end

printf("%.11f\n", ans)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define int long long 
int nb[11];
int32_t main()
{
	int nbDifferents;
	cin >> nbDifferents;
	for (int i = 0 ; i < nbDifferents ; i++)
	{
		int A , B;
		cin >> A >> B;
		nb[A] += B;
	}
	int nbOk = 0;
	bool ok = true;
	while (ok)
	{
		ok = false;
		for (int i = 0 ; i <= 9 ; i++)
		{
			if (nb[i] >= 2)
			{
				ok = true;
				int s = i * 2;
				int t = nb[i] / 2;
				nb[i] %= 2;
				if (s < 10)
				{
					nb[s] += t;
				}
				else
				{
					nb[s%10] += t;
					nb[s/10] += t;
				}
				nbOk += t;
			}
		}
	}
	//cout<<nbOk<<endl;
	int somme = 0;
	for (int i = 9 ; i >=0 ; i--)
	{
		if (nb[i]) somme *= 10;
		somme += i * nb[i];
	}
	//cout<<somme<<endl;
	while (somme >= 10)
	{
		nbOk++;
		int a = somme % 10;
		int b = (somme / 10) % 10;
		somme /= 100;
		if (a + b >= 10) somme *= 10;
		somme *= 10;
		somme += a + b;
		//cout<<somme<<endl;
	}
	cout<<nbOk<<endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "CODEFESTIVAL" ].parse.expand.solve == "Yes" );
	assert( [ "FESTIVALCODE" ].parse.expand.solve == "No" );
	assert( [ "CF" ].parse.expand.solve == "Yes" );
	assert( [ "FCF" ].parse.expand.solve == "Yes" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	return !s.find( 'C' ).find( 'F' ).empty ? "Yes" : "No";
}


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

void solve(long long A, long long B, long long N)
{
    long long x = 0;
    if (N / B >= 1)
    {
        x = B - 1;
    }
    else
    {
        x = N;
    }
    cout << static_cast<long long>(floor(A * (x % B) / B)) << endl;
}

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


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    map<int,int> ocnt, ecnt;
    for(int i=0; i<n; i++){
        if(i%2==0){
            ecnt[v[i]]++;
        }else{
            ocnt[v[i]]++;
        }
    }
    P o1,o2,e1,e2;
    int nax = 0;
    for(auto a : ocnt){
        if(a.second > nax){
            o1 = a;
            nax = a.second;
        }
    }
    nax = 0;
    for(auto a : ocnt){
        if(a.second > nax && o1.first != a.first){
            o2 = a;
            nax = a.second;
        }
    }
    nax = 0;
    for(auto a : ecnt){
        if(a.second > nax){
            e1 = a;
            nax = a.second;
        }
    }
    nax = 0;
    for(auto a : ecnt){
        if(a.second > nax && e1.first != a.first){
            e2 = a;
            nax = a.second;
        }
    }
    if(o1.first != e1.first){
        cout<<n-o1.second-e1.second<<endl;
    } else{
        int t = max(o1.second+e2.second, o2.second+e1.second);
        cout<<n-t<<endl;
    }
    return 0;

}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int s[310][310];

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

  int n;
  cin >> n;
  
  rep(i, n){
    string t;
    cin >> t;
    rep(j, n){
      s[i][j] = int(t[j] - 'a');
    }
  }

  int ans = 0;

  rep(k, n){

    bool ok = true;
    rep(i, n){
      rep(j, i+1, n){

        int i1 = (i + k) % n;
        int j1 = j;

        int i2 = (j + k) % n;
        int j2 = i;

        if(s[i1][j1] != s[i2][j2]){
          ok= false;
        }

      }
    }
    if(ok){
      ans += n;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define deb(x) cout << #x << "=" << x << endl;
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   

int main() {
    fastio
    int n;
    cin>>n;
    ll arr[n] = {0};
    for(int i = 0; i<n; ++i)
        cin>>arr[i];

    sort(arr, arr+n);
    ll ans = 0;
    for(int i = 0; i<n; ++i) {
        for(int j = i+1; j<n; ++j) {
            for(int k = j+1; k<n; ++k) {
                if(arr[i]!=arr[j] && arr[i]!=arr[k] && arr[j]!=arr[k]) {
                    if(arr[i]+arr[j] > arr[k])
                        ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3640
N,M = [int(x) for x in input().split(' ')]
id = [1,N]
ans = -1
for i in range(M):
    L,R = [int(x) for x in input().split(' ')]
    if id[1] < L:
        ans = 0
        break
    elif id[0] > R:
        ans = 0
        break
    if id[0] < L:
        id[0] = L
    if id[1] > R:
        id[1] = R

if ans == -1:
    print(id[1]-id[0]+1)
else:
    print(ans)

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

using namespace std;
int N;
int main() {
  cin >> N;
  
  int sum = 0;
  int i;
  for(i = 1; sum < N; ++i) {
    sum += i;
  }
  
  int iranai = sum - N;
  for(int j = 1; j < i; ++j) {
    if(j == iranai) continue;
    cout << j << endl;
  }
  return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <stdint.h>
# include <stdio.h>
# include <math.h>
using namespace std;


int main(){
	int z;
	int  x[26]={};
	string ch ;
	while(getline(cin,ch)){
		for(int j=0; j<(int)ch.size();j++)
			 {if(ch[j]>=65 && ch[j] <=90){
			 				z = ch[j] - 'A';
			 				x[z]++;
			 			}	
			 			else if(ch[j] >=97 && ch[j] <=122){
			 				z = ch[j] -'a';
			 				x[z]++;
			 			}}

	} 
	for(int i =0; i<26;i++){
			printf("%c",97 +i);
			cout <<" " <<":" <<" "<<x[i] <<"\n";
	}
	return 0;
}



Measured memory_bytes: 3180
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
using namespace std;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <bitset>

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	if ((A + B) > (C + D)) {
		cout << "Left" << endl;
	}
	else if ((A + B) < (C + D)) {
		cout << "Right" << endl;	
	}
	else {
		cout << "Balanced" << endl;	
	}
}

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

vector <int> arr;
int n;
long long dp[MAX];

long long minOper(int falta){

    if(falta < 0) return 100000000000000LL;
    if(falta < 6) return dp[falta] = falta;

    if(dp[falta] != -1) return dp[falta];

    long long prov = 100000000000000LL;
    for(int l = 0; l < arr.size(); l++){

        prov = min(prov, 1 + minOper(falta - arr[l]));
    }
    return dp[falta] = prov;
}

int main(){

    cin>>n;

    if(n < 6){

        cout<<n<<endl;
        return 0;
    }

    memset(dp, -1, sizeof dp);

    int pot = 1;
    while(pot * 6 < MAX){

        arr.push_back(pot * 6);
        pot *= 6;
    }
    pot = 1;
    while(pot * 9 < MAX){

        arr.push_back(pot * 9);
        pot *= 9;
    }
    sort(arr.begin(), arr.end());

    cout<<minOper(n)<<endl;

    return 0;
}


Measured memory_bytes: 16640
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;

const long long mod1=1000000000007ll,A1=26,mod2=1145141919810ll,A2=931;

int main()
{
  static char T[100010];
  scanf("%s",T);
  int n=strlen(T);
  static int a[100010];
  for(int i=0;i<n;i++){
    a[i]=T[i]-'a';
  }
  int L=0,R=n;
  while(L+1<R){
    int d=(L+R)/2;
    long long p1=1ll,p2=1ll;
    for(int t=0;t<d;t++){
      p1=p1*A1%mod1;
      p2=p2*A2%mod2;
    }
    long long D1=0,D2=0;
    for(int i=0;i<d;i++){
      D1=(A1*D1+a[i])%mod1;
      D2=(A2*D2+a[i])%mod2;
    }
    bool F=0;
    set<long long> S1,S2;
    for(int i=d;i<=n;i++){
      if(S1.find(D1)!=S1.end()&&S2.find(D2)!=S2.end()){
	F=1;
	break;
      }
      S1.insert(D1);
      S2.insert(D2);
      if(i<n){
	D1=(A1*D1+a[i]+mod1-p1*a[i-d]%mod1)%mod1;
	D2=(A2*D2+a[i]+mod2-p2*a[i-d]%mod2)%mod2;
      }
    }
    if(F){
      L=d;
    }
    else{
      R=d;
    }
  }
  printf("%d\n",n-R+1);
  return 0;
}


Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
  	cin>>s;
  	int wins = 0;
  	for (int i = 0; i < s.size(); i++)
    {
      	if (s[i] == 'o')
        	wins++;
    }
  	wins += (15 - s.size());
  	cout<<(wins >= 8 ? "YES\n" : "NO\n");
}


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

int main() {

    int N;
    std::cin >> N;
    std::vector<int64_t> A(N);
    for (auto& v : A)std::cin >> v;

    int64_t sum = 0;
    for (int i = 0; i < N; ++i)sum += A[i];

    std::vector<int64_t> ans(N, 0);

    ans[0] = sum;
    for (int i = 1; i < N - 1; i+=2)ans[0] -= 2 * A[i];
    for (int i = 0; i < N - 1; ++i)ans[i + 1] = 2 * A[i] - ans[i];
    for (auto& v : ans)std::cout << v << " ";
    std::cout << std::endl;
}

Measured memory_bytes: 2944
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  REP(i, n) {
    cin >> a[i]; --a[i];
  }
  REP(i, n) cin >> b[i];
  REP(i, n - 1) cin >> c[i];
  long long ans = 0;
  REP(i, n) {
    ans += b[a[i]];
    if (i > 0 && a[i - 1] + 1 == a[i]) ans += c[a[i - 1]];
  }
  cout << ans << '\n';
  return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int k,x;

signed main() {
    cin >> k >> x;
    if (k*500 >= x) cout << "Yes" << endl;
    else cout << "No" << endl; 
}















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;
 
template <typename T> T inf;
template <> constexpr int inf<int> = 1e9;
template <> constexpr ll inf<ll> = 1e18;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> c(10, vector<int>(10));
    for(int i = 0; i < 10; ++i) {
        for(int j = 0; j < 10; ++j) {
            cin >> c[i][j];
        }
    }
    for(int k = 0; k < 10; ++k) {
        for(int i = 0; i < 10; ++i) {
            for(int j = 0; j < 10; ++j) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }

    int res = 0;
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            int a;
            cin >> a;
            if(a != -1) {
                res += c[a][1];
            }
        }
    }
    cout << res << endl;
}


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

int main(){
 
  int n;
  while(cin >> n && n){

 string name[40];
  int m[40]={};
  int d[40][40]={};

    // input
    for(int i = 0; i < n; i++){
      cin >> name[i] >> m[i];
      for(int j = 0; j < m[i] ; j++){
	int tmp;
	cin >> tmp;
	d[i][tmp] = 1;
      }
    }

    // point 
    int sum[40]={};
    for(int i = 0; i < 40; i++){
      for(int j = 0; j < n; j++){
	sum[i] += d[j][i];
      }
    }
    /*
    for(int i =0; i < 15; i++){
      cout << sum[i] << " "; 
    }
    cout << endl;
    */
    int pt[40]={};
    for(int j = 0; j < 40; j++){
      for(int i = 0; i < n; i++){
	if(d[i][j] == 1){
	  pt[i] += n+1 - sum[j];
	}
      }
    }
    /*
    for(int i =0; i < n; i++){
      cout << pt[i] << " "; 
    }
    */
    //min
    int min = 0;
    for(int i =0; i < n; i++){
      if(pt[i] < pt[min]) min = i;
    }
    for(int i = 0; i < n; i++){
      if(pt[i] == pt[min])
	if(name[i] < name[min]) min = i;
    }
    cout << pt[min] << " " << name[min] << endl;
  }

  return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

constexpr long long mod = 1000000007;
constexpr double eps = 0.00001;

int main() {
    int n;
    scanf("%d",&n);
    vector<pair<int,int>> b(n);
    set<pair<int,int>> r;
    for(int i = 0;i < n;i++) {
        int s,t;
        scanf("%d %d",&s,&t);
        r.insert(make_pair(s,t));
    }
    for(int i = 0;i < n;i++) scanf("%d %d",&b[i].first,&b[i].second);
    sort(b.begin(),b.end());
    int c = 0;
    for(auto& e:b) {
        pair<int,int> p;
        bool u = false;
        for(auto f:r) {
            if(f.first < e.first && f.second < e.second) {
                u = true;
                p = f;
            }
        }
        if(!u) continue;
        for(auto f:r) if(f.first < e.first && f.second < e.second && p.second < f.second) p = f;
        r.erase(p);
        c++;
    }
    printf("%d",c);
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main(){
int K, A, B;
cin >> K;
cin >> A >> B;

int count;
int fail = 1;
int countA;
int countB;


for (int i = A; i < B+1; i++)
{
    if( i % K == 0){
        cout << "OK" <<endl;
        fail = 0;
        break;
    }
    else{
        fail = 1;
    }
}

if(fail==1){
    cout <<"NG" <<endl;
}

return 0;
}

Measured memory_bytes: 3636
def max_exponent(a, n):
    # calculate k s.t. a**k <= n < a**(k+1)
    ret, v = 0, 1
    while a * v <= n:
        ret += 1
        v *= a
    return ret


def main():
    N = int(input())
    if N % 2 == 1:
        print(0)
        return
    # N is even
    count_5_in_even, pow_5 = 0, 5
    for k in range(1, max_exponent(5, N) + 1):
        count_5_in_even += (N // pow_5) // 2
        pow_5 *= 5
    count_2_in_even, pow_2 = 0, 2
    for k in range(1, max_exponent(2, N) + 1):
        count_2_in_even += N // k
        pow_2 *= 2
    print(min(count_5_in_even, count_2_in_even))


if __name__ == '__main__':
    main()

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

typedef long long ll;
#define pb push_back
#define mp make_pair
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main(){
	fast_io;
	ll n, l, t;
	cin >> n >> l >> t;
	ll cnt = 0;
	
	vector <ll> v;
	
	for(ll i = 0; i < n; i ++){
		ll x, w;
		cin >> x >> w;
		if(w == 1){
			v.pb((x + t) % l);
			if(l - x <= t){
				cnt += (t - l + x - 1) / l + 1;
			}
		}else{
			if(t > x)
				cnt -= (1 + (t - x - 1) / l);
				
			ll ind = (x - t) % l;
			
			while(ind < 0){
				ind += l;
			}
			v.pb(ind);
		}
	}
	
//	cout << cnt << endl;
	cnt %= n;
	sort(v.begin(), v.end());
	
	while(cnt < 0)
		cnt += n;
	
	for(ll i = cnt; i < n; i ++){
		cout << v[i] << endl;
	}
	for(ll i = 0; i < cnt; i ++){
		cout << v[i] << endl;
	}
	
	return 0;
}



Measured memory_bytes: 4196
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		
		System.out.println((A-1) * (B-1));
		
		
		scanner.close();
	}
}


Measured memory_bytes: 20948
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
constexpr int mod = 1000000007;
using namespace std;
int d, c[30], l[30], s[400][30];
signed main() {
	cin >> d;
	for1(i, 26)cin >> c[i];
	for1(i, d)for1(j, 26)cin >> s[i][j];
	for1(i, d) {
		int p = 0, k = -mod;
		for1(j, 26) {
			int kj = s[i][j] + c[j] * (i - l[j]) * 1.10;
			if (kj > k) { p = j; k = kj; }
			else if (kj == k && c[j] > c[p])p = j;
		}
		puts(p); l[p] = i;
	}
}

Measured memory_bytes: 3684