akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<pair<int,int>> J(N);
    for (int i=0;i<N;i++) cin >> J[i].first >> J[i].second;

    sort(J.begin(), J.end(), [](pair<int,int> a, pair<int,int> b){
        return (a.first < b.first) || (a.first == b.first && a.second > b.second);
    });
    // sort(J.begin(), J.end(), [](pair<int,int> a, pair<int,int> b){
    //     return (a.second > b.second) || (a.second == b.second && a.first < b.first);
    // });
    // for (int i=0;i<N;i++) cout << J[i].first << "," << J[i].second << endl;

    priority_queue<int> Q;
    auto pitr = J.begin(), itr = J.begin();
    ll X = 0;
    for (int i=1;i<=M;i++) {
        itr = lower_bound(itr, J.end(), make_pair(i+1,0));
        for (auto citr = pitr; citr != itr; citr++) Q.push(citr->second);
        if (Q.size()) {
            X += Q.top();
            Q.pop();
        }
        pitr = itr;
    }
    cout << X << endl;

    return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    long long n,k;
    cin >> n >> k;
    long long tmp;
    vector<long long> h;
    for(long long i = 0; i< n; i++){
        cin >> tmp;
        h.push_back(tmp);
    }
    sort(h.begin(), h.end());
    // for(long i=0;i<n;i++){
    //     cout << h[i] << " ";
    // }
    // cout << endl;
    vector<long long> diff(n-k+1);
    for(long long i = 0; i<n-k+1;i++){
        diff[i] = h[i+k-1] - h[i];
    }
    // for(int i=0;i<n-k+1;i++){
    //     cout << diff[i] << " ";
    // }
    // cout << endl;
    sort(diff.begin(), diff.end());
    // for(int i=0;i<n-k+1;i++){
    //     cout << diff[i] << " ";
    // }
    // cout << endl;
    cout << diff[0] << endl;
}


Measured memory_bytes: 1908
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let s = read::<String>().chars().collect::<Vec<_>>();
    let mut zero_poses = vec![];
    for i in 0..n + 1 {
        if s[i] == '0' {
            zero_poses.push(i);
        }
    }
    let mut from = vec![std::usize::MAX; n + 1];
    for i in 1..n + 1 {
        let mut search_min = max(0, i as i64 - m as i64) as usize;
        let idx = zero_poses[zero_poses.lower_bound(&search_min)];
        if idx == zero_poses.len() {
            continue;
        }
        from[i] = idx;
    }
    if from[n] == std::usize::MAX {
        println!("-1");
        return;
    }
    let mut pointer = n;
    let mut answers = vec![];
    while pointer != 0 {
        let next = from[pointer];
        answers.push(pointer - next);
        if pointer == next {
            println!("-1");
            return;
        }
        pointer = next;
    }
    answers.reverse();
    print_array(&answers);
}

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }

    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}

fn print_array<T: std::string::ToString>(array: &Vec<T>) {
    println!(
        "{}",
        array
            .iter()
            .map(|ref x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 12668
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=250000;
const int HMOD=1000000007;
const int NHASH=2;
int HMLT[NHASH];
int HINV[NHASH];
struct Op { int a[NHASH],b[NHASH]; };
int pw(int x,int n) { int ret=1; while(true) { if(n&1) ret=(ll)ret*x%HMOD; if((n>>=1)==0) return ret; x=(ll)x*x%HMOD; } }

Op combine(const Op &p,const Op &q) { Op ret; REP(i,NHASH) { ret.a[i]=(ll)p.a[i]*q.a[i]%HMOD; ret.b[i]=((ll)p.a[i]*q.b[i]+p.b[i])%HMOD; } return ret; }
void eval(const Op &p,const int q[NHASH],int ret[NHASH]) { REP(i,NHASH) ret[i]=((ll)p.a[i]*q[i]+p.b[i])%HMOD; }

int n; char s[MAXN+1];

Op opid;
Op opgt,iopgt;
Op oplt,ioplt;
Op oppl,ioppl;
Op opmn,iopmn;
Op f[MAXN];
Op g[MAXN];

Op ff[MAXN+1]; // ff[i] is composition of f for suffix starting at i
Op gg[MAXN+1]; // gg[i] is composition of g for suffix starting at i

int id[NHASH];
int fx[NHASH];
int gx[MAXN+1][NHASH];
int hx[MAXN+1][NHASH];

map<vector<int>,int> mp;

void run() {
	scanf("%d%s",&n,s);

	REP(i,n) switch(s[i]) {
		case '>': f[i]=opgt,g[i]=iopgt; break;
		case '<': f[i]=oplt,g[i]=ioplt; break;
		case '+': f[i]=oppl,g[i]=ioppl; break;
		case '-': f[i]=opmn,g[i]=iopmn; break;
		default: assert(false);
	}

	ff[n]=opid; for(int i=n-1;i>=0;--i) ff[i]=combine(f[i],ff[i+1]);
	gg[n]=opid; for(int i=n-1;i>=0;--i) gg[i]=combine(gg[i+1],g[i]);
	
	memset(id,0,sizeof(id));
	eval(ff[0],id,fx);
	REPE(i,n) eval(gg[i],id,gx[i]);
	REPE(i,n) eval(gg[i],fx,hx[i]);

	//printf("fx:"); printf(" %d\n",fx[0]);
	//printf("gx:"); REPE(i,n) printf(" %10d",gx[i][0]); puts("");
	//printf("hx:"); REPE(i,n) printf(" %10d",hx[i][0]); puts("");

	ll ret=0;
	for(int i=n;i>=0;--i) {
		vector<int> vg(NHASH),vh(NHASH); REP(j,NHASH) vg[j]=gx[i][j],vh[j]=hx[i][j];
		ret+=mp[vh]; ++mp[vg];
	}
	printf("%lld\n",ret);
}

void init() {
	REP(i,NHASH) { int x=0; REP(j,100) x=((ll)x*1000+rand()%1000)%HMOD; HMLT[i]=x; HINV[i]=pw(x,HMOD-2); }
	//printf("HMLT:"); REP(i,NHASH) printf(" %d",HMLT[i]); puts("");
	REP(i,NHASH) {
		opid.a[i]=1,opid.b[i]=0;
		opgt.a[i]=HMLT[i],opgt.b[i]=0;
		oplt.a[i]=HINV[i],oplt.b[i]=0;
		oppl.a[i]=1,oppl.b[i]=1;
		opmn.a[i]=1,opmn.b[i]=HMOD-1;
		iopgt=oplt,ioplt=opgt,ioppl=opmn,iopmn=oppl;
	}
}

int main() {
	init();
	run();
	return 0;
}


Measured memory_bytes: 74752
N = int(input())
L = ["".join(sorted(list(input()))) for i in range(N)]
D = {}
for s in L :
    if s not in D :
        D[s] = 1
    else :
        D[s] += 1
ans = 0
for n in D.values() :
    ans += (n-1)*n//2
print(ans)

Measured memory_bytes: 66776
#include <iostream>

#include <vector>

using namespace std;

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

int main() {
  string s;
  cin >> s;
  vector<int> a(26), b(10);
  REP(i, s.size()) {
    if (isalpha(s[i])) {
      a[s[i] - 'a']++;
    } else {
      b[s[i] - '0']++;
    }
  }

  int ans = 0;
  REP(i, 26) {
    if (a[i] == 0)
      continue;
    int j = i + 1;
    while (j < 26) {
      if (a[j] == 0)
        break;
      j++;
    }
    int cnt = j - i;
    if (cnt >= 3) {
      ans += 3;
      for (int k = i; k < j; ++k) {
        a[k]--;
      }
    } else {
      ans++;
      a[i]--;
    }
    if (a[i] > 0)
      i--;
  }
  REP(i, 10) {
    if (b[i] == 0)
      continue;
    int j = i + 1;
    while (j < 10) {
      if (b[j] == 0)
        break;
      j++;
    }
    int cnt = j - i;
    if (cnt >= 3) {
      ans += 3;
      for (int k = i; k < j; ++k) {
        b[k]--;
      }
    } else {
      ans++;
      b[i]--;
    }
    if (b[i] > 0)
      i--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3192
A,B,K = [int(x) for x in input().split()]

if B-A<=K*2-2:
    for i in range(A,B+1):
        print(i)
else:
    for i in range(A,A+K):
        print(i)
    for i in range(B-K+1,B+1):
        print(i)


Measured memory_bytes: 3060
/*  "Sahand Alitanloo"  */
#include <bits/stdc++.h>
#define F first
#define S second
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per(i) cout<<fixed<<setprecision(i)
#define pb push_back
#define all(v) begin(v),end(v)
#define endl '\n'
using namespace std;
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
const int MAX_N = 1e5+10;
const ll mod = 1e9+7;
const ll INF = 1e9;
inline ll bpow(ll t,ll n){ll ans=1;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}
/*
ll fact[MAX_N],ifact[MAX_N];
inline ll c(ll n,ll k){if(k>n||k<0)return 0;return (fact[n]*ifact[k]%mod*ifact[n-k])%mod;}
inline void get_fact(){fact[0]=1;ifact[0]=1;for(ll i=1;i<MAX_N;i++)fact[i]=(fact[i-1]*i)%mod,ifact[i]=bpow(fact[i],mod-2);}
*/

#define int ll
pair<ll,ll> a[MAX_N];
int psum[MAX_N];
main(){
    fast();per(0);
    //get_fact();
    int n,h;cin>>n>>h;
    int maxx=0;
    for(int i=1;i<=n;i++)
        cin>>a[i].S>>a[i].F,maxx=max(maxx,a[i].S);
    sort(a+1,a+n+1);
    for(int i=n;i>=1;i--)
        psum[i]=psum[i+1]+a[i].F;
    int anss=INF;
    set<int> st;
    for(int i=n;i>=0;i--){
        int pow=psum[n-i+1];
        int t=h;
        int ans=i;
        //cout<<pow<<endl;
        t-=pow;
        t=max(t,0ll);
        if(t>0){
            ans+=ceil(t/ld(maxx));
            t=0;
        }
        if(t==0)
            anss=min(anss,ans);
        st.insert(a[i].S);
    }
    cout<<anss;
}


Measured memory_bytes: 3072
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		String line=new Scanner(System.in).nextLine();
		String abc="abcdefghijklmnopqrstuvwxyz";
		Character result = null;
		for(char a:abc.toCharArray()) {
			if(line.indexOf(a)<0) {
				result=a;
				break;
			}
		}
		System.out.println(result==null?"None":result);
	}
}

Measured memory_bytes: 26172
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;

int N;
vector<int> C;
map<string, int> M;

void input_data(void) {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		C.clear();
		C.resize(26, 0);
		string s;
		cin >> s;
		for (int p = 0; p < 10; ++p) {
			int id = (int)(s[p] - 'a');
			++C[id];
		}
		string str = string(26, '@');
		for (int q = 0; q < 26; ++q)
			str[q] = (char)(C[q] + 0x30);
		if (M.find(str) == M.end())
			M[str] = 1;
		else
			++M[str];
	}
}

ll solve(void) {
	ll res = (ll)0;
	map<string, int>::iterator itr;
	for (itr = M.begin(); itr != M.end(); ++itr) {
		int cnt = itr->second;
		if (cnt != 1)
			res += (ll)cnt * (cnt - 1) / 2;
	}
	return res;
}

int main(void) {
	input_data();
	ll ans = solve();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 12800
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
//////////////
class UnionFind {
public:
	int cNum;//要素数
	vector<int> parent;
	vector<int> count;
	vector< vector<int> > GList;
	UnionFind(int n) {
		cNum = n;
		parent = vector<int>(n);
		count = vector<int>(n, 1);
		GList.resize(n);
		for (int i = 0; i < n; ++i) {
			parent[i] = i;
			GList[i].push_back(i);
		}
	}
	int find(int x) {
		if (parent[x] == x) { return x; }
		return parent[x] = find(parent[x]);
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int Count(int x) { return count[find(x)]; }
	void add(int x, int y) {//union
		x = find(x);
		y = find(y);
		if (x == y)return;
		parent[x] = y;

		count[y] += count[x];
		if (GList[y].size() < GList[x].size()) {
			swap(GList[x], GList[y]);
		}
		GList[y].insert(GList[y].end(),
			GList[x].begin(), GList[x].end());
	}
};

void solve() {
	LL N, M;
	cin >> N >> M;
	vector<pair<int, int>> E(M);
	for (int i = 0; i < M; ++i) {
		cin >> E[i].first >> E[i].second;
		E[i].first--;
		E[i].second--;
	}
	reverse(E.begin(), E.end());
	vector<LL> ans;
	UnionFind uf(N);
	LL now = N * (N - 1) / 2;////////////////////////////////
	ans.push_back(now);
	for (int i = 0; i < M; ++i) {
		int a = E[i].first;
		int b = E[i].second;
		if (uf.same(a, b)) {
			ans.push_back(now-0);
			continue;
		}
		LL aC = uf.Count(a);
		LL bC = uf.Count(b);
		now -= aC * bC;
		ans.push_back(now);
		uf.add(a, b);
	}
	reverse(ans.begin(), ans.end());
	int len = ans.size();
	for (int i = 1; i < len; ++i) {
		cout << ans[i] << endl;
	}
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 13044
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if x == 500*i+100*j+50*k:
                ans+=1
print(ans)

Measured memory_bytes: 39536
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <string.h>
#include <math.h>
typedef long long ll;
#define INF			100000
#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REP(i,x,y)	for (int (i)=(x);(i)<(y);(i)++)
#define REP_(i,x,y)	for ((i)=(x);(i)<(y);(i)++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef pair<int, int> Point;
typedef vector<vector<Point>> Graph;

int A,B,C;
int cnt;

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

	while ( A > B || B > C ) {
		if ( A > B ) A^=B,B^=A,A^=B;
		if ( B > C ) B^=C,C^=B,B^=C;
	}
	
	if ( C == B && B == A) cnt = 0;
	else if ( C == B ) cnt = ((B-A)%2)? ((B-A)/2+2):(B-A)/2;
	else if ( B == A ) cnt = C - B;
	else {
		int aa=A%2,bb=B%2,cc=C%2;
		
		if ( aa == bb && bb == cc ) cnt = (C-A)/2+(C-B)/2;
		else if ( aa == bb ) cnt = (C-A)/2+(C-B)/2+1;
		else cnt = (C-A)/2+(C-B)/2+2;
	}

	cout << cnt;

	return 0;
}


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

using namespace std;

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

    int n, k;
    cin >> n >> k;

    double sum = 0;
    double temp;
    double p;
    for (int i = 1; i <= n; i++) {
        temp = 1.0 / n;
        p = i;
        while (p < k) {
            p *= 2;
            temp /= 2;
        }
        sum += temp;
    }

    printf("%.12f\n", sum);

    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

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

void solve() {

}

int main() {
  vector<ii> vec(2);
  rep(i,2) {
    cin >> vec[i].fst >> vec[i].snd;
  }
  int cur = 0;
  while(1) {
    vec[(cur+1)%2].fst -= vec[cur].snd;
    if(vec[(cur+1)%2].fst <= 0 ) {
      if( cur == 0 ) puts("Yes");
      else puts("No");
      return 0;
    }
    ++cur;
    cur %= 2;
  }
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define in(a, n) for(int i=0;i<n;i++)
#define oo 1e18
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
void flush(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
//28 problems
//2*(900,1000,1100)
//6*30=180
//98:74:da:c0:ca:49
int a[100009];
ll n;
int q=0;
void solve(ll c,bool n7,bool n3,bool n5)
{
    if(c>n)
        return;
    if(n7&&n3&&n5)
        q++;
    solve(c*10+3,n7,1,n5);
    solve(c*10+7,1,n3,n5);
    solve(c*10+5,n7,n3,1);
}
int main()
{

    flush();
    cin>>n;
    solve(0,0,0,0);
    cout<<q;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int d;
  cin>>d;

  vector<ll> p(26);
  rep(i,26) {
    cin>>p[i];
  }


  vector<vector<ll>> q(d,vector<ll>(26));
  rep(i,d) {
    rep(j,26) {
      cin>>q[i][j];
    }
  }

  ll pre=0;
  vector<int> r(26,0);
  rep(i,d-5){
    ll ans=-INF;
    ll memo;
    rep(j,26){
      ll sum=pre;
      auto last=r;
      sum+=q[i][j];
      last[j]=i+1;
      rep(k,26){
        sum-=9*p[k]*(i+1-last[k])/2;
      }
      if(sum>ans) {
        memo=j;
        chmax(ans,sum);
      }
    }
    cout << memo+1 << endl;
    pre=ans;
    r[memo]=i+1;
  }

  ll answer=-INF;
  ll A,B,C,D,E;
  vector<int> zen(5);
  rep(i,26){
    rep(j,26){
      rep(k,26){
        rep(l,26){
          rep(m,26){
            zen[0]=i;
            zen[1]=j;
            zen[2]=k;
            zen[3]=l;
            zen[4]=m;

            ll sum=0;
            auto last=r;
            rep(n,5){
              sum+=q[d-5+n][zen[n]];
              last[zen[n]]=d-5+n+1;
              rep(o,26){
                sum-=p[o]*(d-5+n+1-last[o]);
              }
            }

            if(sum>answer) {
              A=zen[0];
              B=zen[1];
              C=zen[2];
              D=zen[3];
              E=zen[4];
            }
            chmax(answer,sum);

          }
        }
      }
    }
  }

  cout << A+1 << endl;
  cout << B+1 << endl;
  cout << C+1 << endl;
  cout << D+1 << endl;
  cout << E+1 << endl;
  
}

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

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

    return gcd(y, x%y);
}

int main(){
    long long n, m;
    cin >> n >> m;

    long long l = n*(m/gcd(n ,m));
    string s, t;
    cin >> s >> t;

    
    map<long long, char> ans;

   
    for(long long i = 0; i < n; i++){
        ans[i*(l/n)+1] = s[i];
    }


    bool flag = true;
    for(long long i = 0; i < m; i++){
        if(ans.find(i*(l/m)+1) != ans.end() and t[i] != ans[i*(l/m)+1]){
            flag = false;
            break;
        }
    }

    if(flag == true){
        printf("%lld\n", l);
    }
    else{
        printf("-1\n");
    }

    return 0;
}

Measured memory_bytes: 6144
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<string>
#include<map>
#include<set>
#include<math.h>

using namespace std;
#define ll long long
#define ull unsigned long long
#define INF 1e9
#define eps 1e-6
#define PI acos(-1.0)
#define M 10010
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef pair<int, int>P;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;

int n , k;
int a[maxn],b[maxn];

int gcd(int a,int b)
{
    return b>0?gcd(b,a%b):a;
}

int main() {
    IOS;
  //freopen("in.txt", "r", stdin);
  //freopen("out.txt","w",stdout);
  cin >> n >> k;
  for(int i = 0 ; i < n ; ++i)
    cin >> a[i];
  if(n == 1){
    cout << abs(a[0]-k);
    return 0;
  }
  a[n] = k;
  sort(a,a+n+1);
  //for(int i = 0 ; i <= n ; ++i)
   // cout << a[i] <<" ";
  for(int i = 1; i <= n ; ++i)
    b[i] = a[i] - a[i-1];
  //for(int i = 1 ; i <= n ; ++i)
    //cout << b[i] <<" ";
  int t = gcd(b[1],b[2]);
  for(int i = 3; i <= n; ++i)
    t = gcd(t,b[i]);
  cout << t;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#define rep(i, s, g) for (i = s; i <= g; i++)
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

int main(void)
{
    int a, b;
    int i;

    cin >> a >> b;

    if (a < b)
    {
        rep(i, 1, b)
        {
            cout << a;
        }
        cout << endl;
    }
    else
    {
        rep(i, 1, a)
        {
            cout << b;
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
# C - Daydream
s = gets.strip
words = ['dream', 'dreamer', 'erase', 'eraser']

until s.empty? do
    reduced = false
    words.map do |w|
        if s[-w.size, w.size] == w
            s = s[0..-w.size - 1]
            reduced = true
            break
        end
    end
    unless reduced
        puts 'NO'
        exit 0
    end
end

puts 'YES'

Measured memory_bytes: 56292
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

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

template <typename T>
using V = std::vector<T>;
template <typename T>
vector<T> make_vec(size_t n, T a) {
  return vector<T>(n, a);
}
template <typename... Ts>
auto make_vec(size_t n, Ts... ts) {
  return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  string s;
  cin >> n >> s;

  int ans = 0;
  auto dp = make_vec(n + 1, 0);
  for (int i = n - 2; i >= 0; --i) {
    auto dp_next = make_vec(n + 1, 0);
    for (int j = i + 1; j < n; ++j) {
      if (s[i] == s[j]) {
        dp_next[j] = dp[j + 1] + 1;
        chmax(ans, min(dp_next[j], j - i));
      }
    }
    swap(dp, dp_next);
  }
  cout << ans << endl;
}


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

using namespace std;

int main() {

	double w, h, x, y;
	cin >> w >> h >> x >> y;

	double mw, mh;
	mw = w / 2.0;
	mh = h / 2.0;

	double scale = w * h / 2.0;

	int judge = 0;

	if (mw == x && mh == y)judge = 1;

	printf("%.9lf %d", scale, judge);

}



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

int main(void){
    int n;
    cin >> n;
    int d[n];
    for(int i=0;i<n;i++){
        cin >> d[i];
    }
    int s=0; // 体力の回復量
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i!=j) s+=d[i]*d[j];
        }
    }
    // 出力
    cout << s/2 << endl;

    return 0;
}

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

int f(int x)
{
  return (x * x);
}

int main()
{
  int d;

  while (cin >> d){
    int num = 600;
    long long res = 0;
    for (int i = 1; i * d != 600; i++){
      res += f(d * i) * d;
    }
    cout << res << endl;
  }
  return (0);
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define MAXN 110
#define MAXW 100010
#define ll long long

using namespace std;

ll n, W, ans, w[MAXN], v[MAXN], dp[MAXW];
bool mk[MAXW];

void init(){
    mk[0]=true;
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>W;

    for(int i=1; i<=n; i++){
        cin>>w[i]>>v[i];
    }

    init();

    for(int i=1; i<=n; i++){
        for(int j=W-w[i]; j>=0; j--){
            if(mk[j]&&dp[j]+v[i]>dp[j+w[i]]){
                mk[j+w[i]]=true;
                dp[j+w[i]]=dp[j]+v[i];
            }
        }
    }

    for(int i=0; i<=W; i++) ans=max(ans, dp[i]);

    cout<<ans;

return 0;
}


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

int N, M;

int par[55];  //親の番号

void init(int n) {
    for (int i = 0; i < n; ++i) par[i] = i;
}

int root(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = root(par[x]);
    }
}

bool same(int x, int y) { return root(x) == root(y); }

void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;

    par[x] = y;
}

int main() {
    cin >> N >> M;
    vector<int> A(M), B(M);
    rep(i, M) {
        cin >> A[i] >> B[i];
        --A[i];
        --B[i];
    }

    int ans = 0;
    rep(i, M) {
        init(N);
        rep(j, M) if (i != j) unite(A[j], B[j]);
        rep(j, N) if (!same(par[0], par[j])) {
            ++ans;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt() - 1;
    int y = sc.nextInt() - 1;
    List<List<Integer>> nodes = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      List<Integer> node = new ArrayList<>();
      if (i + 1 < n) node.add(i + 1);
      if (i - 1 >= 0) node.add(i - 1);
      nodes.add(node);
    }
    nodes.get(x).add(y);
    nodes.get(y).add(x);
    int[] result = new int[n];
    for (int i = 0; i < n; i++) {
      int[] mins = new int[n];
      Arrays.fill(mins, n);
      mins[i] = 0;
      Deque<Integer> queue = new ArrayDeque<>();
      queue.add(i);
      while (!queue.isEmpty()) {
        int id = queue.poll();
        for (int j : nodes.get(id)) {
          if (mins[j] > mins[id] + 1) {
            mins[j] = mins[id] + 1;
            queue.add(j);
          }
        }
      }
      for (int j = i + 1; j < n; j++) {
        result[mins[j]]++;
      }
    }
    StringBuilder sb = new StringBuilder();
    for (int k = 1; k < n; k++) {
      if (sb.length() > 0) sb.append("\n");
      sb.append(result[k]);
    }
    System.out.println(sb.toString());
  }
}

Measured memory_bytes: 86488
N,S = map(int,input().split())
A = list(map(int,input().split()))
#%%
# b = [[0]*(S+1) for _ in range(N+1)]
# b[0][0] = int(S==0)
MOD = 998244353

# for r in range(N):
#     for s in range(S+1):
#         b[r+1][s] += b[r][s]
#         if s-A[r]>=0:
#             b[r+1][s] += b[r][s-A[r]]
#         if s==A[r] or s==0:
#             b[r+1][s] += 1
#         b[r+1][s] %= MOD

# ans = 0
# for i in range(N):  
#     ans += b[i+1][S]
#     ans %= MOD
    
# print(ans)

dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += 2*dp[i][j]
        if j-A[i]>=0:
            dp[i+1][j] += dp[i][j-A[i]]
        dp[i+1][j] %= MOD

print(dp[N][S])

Measured memory_bytes: 135364
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    int N, M, A, B;
    string str1, str2;
    cin >> N >> M;
    vector<int> a(N);
    int sum = 0;
    rep(i, N){
        cin >> a[i];
        sum += a[i];
    }
    int ans = 0;
    rep(i, N){
        if(a[i] * 4 * M >= sum)ans++;
    }
    if(ans >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, X;
  std::cin >> N >> X;
  std::vector<ll> A(N);
  vvl dp = vv(N, 2, 0, ll);
  for(int i=0;i<N;i++) std::cin >> A[i];

  for(int i=0;i<N;i++){
    if(i==0) dp[0][0] = (A[0]<=X?0:A[0]-X), dp[0][1]=(A[0]<=X?A[0]:X);
    else {
      dp[i][0] = (A[i]+dp[i-1][1]<=X?dp[i-1][0]:dp[i-1][0]+A[i]+dp[i-1][1]-X);
      dp[i][1] = (A[i]+dp[i-1][1]<=X?A[i]:X-dp[i-1][1]);
    }
    //std::cout << dp[i].first  << " " << dp[i].second<< '\n';
  }
  std::cout << dp[N-1][0] << '\n';
  return 0;
}


Measured memory_bytes: 6528
s=list(input())
if s[0]=="R":
  if s[1]=="R":
    if s[2]=="R":
      print(3)
    else:
      print(2)
  else:
    print(1)
else:
  if s[1]=="R":
    if s[2]=="R":
      print(2)
    else:
      print(1)
  else:
    if s[2]=="R":
      print(1)
    else:
      print(0)
      

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

int main(){
    int N, M;
    int K[31] = {0};
    int A = 0;

    int bkt[31] = {0};
    cin >> N >> M;
    for (int i = 0; i < N; ++i) {
        cin >> K[i];
        for (int j = 0; j < K[i]; ++j) {
            cin >> A;
            ++bkt[A];
        }
    }
    int res = 0;
    for (int i = 0; i < 31; ++i) {
        if (bkt[i]==N) ++res;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve(){
	ll i, j, k, a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=max(a*c,max(a*d,max(b*c,b*d)));
    cout<<ans<<endl;



}

int main() {
	ios_base::sync_with_stdio(0);
	int i,t=1;
	//cin>>t;
	for(i=1;i<=t;i++){
		solve();
	}
	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = ((ll)result * base) % mod;
		base = ((ll)base * base) % mod;
		exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}




Measured memory_bytes: 10676
#include <iostream>

int main()
{
  int a, b;

  std::cin >> a >> b;

  if (a < b)
  {
    std::cout << "a < b" << '\n';
  }
  else if (a > b)
  {
    std::cout << "a > b" << '\n';
  }
  else
  {
    std::cout << "a == b" << '\n';
  }
}



Measured memory_bytes: 3032
# -*- coding: utf-8 -*-
N = int(input())

if N != int((N // 1.08) * 1.08 // 1):
    if N != int((N // 1.08 + 1) * 1.08 // 1):
        print(":(")
    else:
        print(int((N // 1.08 + 1)))
else:
    print(int((N // 1.08)))

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

int main() {
  int n,m;
  cin >> n;
  for(int i= 1;i<=n;i++){
    if(i%3 == 0){
      cout << " " << i;
    }else{
      m = i;
      while(m>1){
	if(m%10 == 3){
	  cout << " " << i;
	  break;
	}else{m /= 10;}
      }
    }
  }
  cout << endl;
    return 0;
}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
#include<numeric>
#define int long long
#define ld long double
#define all(x) x.begin(),x.end()
const int maxn=1000000;
#define what_is(x) cerr << #x << " is " << x << endl;
const int MOD = 1e9 + 7;
using namespace std;
string abc="abcdefghijklmnopqrstuvwxyz";
int powmod(int a, int b, int MOD = MOD){
    if(!a and !b)    return 1ll;
    if(!a)    return a;
    int res = 1ll;
    b %= (MOD - 1ll), a %= MOD;
    while(b){
        if(b%2 == 1)    res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}
int popcount(uint32_t n)
{
    n = n - ((n >> 1) & 0x55555555);
    n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
    return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
bool check(int n) {return (((double)sqrt(n)-floor((double)sqrt(n)))==0);}
vector<bool> sieve(maxn + 1, true);
void fillprime() {
    sieve[0] = sieve[1] = false;
    for (int i = 2; i <= maxn; ++i) {
        if (sieve[i] && (int) i * i <= maxn) {
            for (int j = i * i; j <= maxn; j += i) {
                sieve[j] = false;
            }
        }
    }
}
const int nn=1e5+5;
void solve() {
    string s,t;
    cin>>s>>t;
    int sum=0;
    for(int i=0;i<s.size();++i)
    {
        if(s[i]!=t[i]) sum++;
    }
    cout<<sum;
}
int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    //fillprime();
    //int t;cin>>t;while(t--)
        solve();
}

Measured memory_bytes: 3928
#include <stdio.h>

int main(void) {
    long n, i;
    scanf("%ld", &n);
    long a[n + 1], b[n];
    for ( i = 0; i <= n; i++ ) {
        scanf("%ld", &a[i]);
    }
    for ( i = 0; i < n; i++ ) {
        scanf("%ld", &b[i]);
    }

    long ans = 0, remain_a = 0, remain_b = 0;
    /* 1 番目の街から n 番目の街までを考える */
    for ( i = 0; i < n; i++ ) {
        /* (i - 1) 番目の街の残り戦力を使う */
        remain_a = a[i] - remain_b;
        /* 残り戦力で倒しきれていたら i 番目の街の戦力は残る */
        if ( remain_a <= 0 ) {
            ans += a[i];
            remain_b = b[i];
        }
        /* 倒しきれなかったら i 番目の街の戦力を使用する */
        else {
            remain_a -= b[i];
            /* i 番目の街の戦力で倒しきれていたら余りを持ち越す */
            if ( remain_a <= 0 ) {
                ans += a[i];
                remain_b = 0 - remain_a;
            }
            /* i 番目の街の戦力でも倒しきれなかったら余りはなし */
            else {
                ans += (remain_b + b[i]);
                remain_b = 0;
            }
        }
    }
    /* (n + 1) 番目の街は n 番目の街の残り戦力しかない */
    if ( a[n] > remain_b ) {
        ans += remain_b;
    }
    else {
        ans += a[n];
    }
    printf("%ld\n", ans);
    return 0;
}

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

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

     int ans = 700;
     for (int i = 0; i < 3; i++) {
         if (s[i] == 'o') {
             ans += 100;
         }
     }
     
     cout << ans << endl;
}

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

using namespace std;
const int maxn = 1e4 + 5;

bool c[maxn];
int a[maxn];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        if (c[i - 1] == 0 && a[i] == a[i - 1]) {
            ++cnt;
            c[i] = 1;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  ll  a,b,c;
  cin >> a >> b >> c;
  rep(i,10){
    c *= a;
    c -= b;
    cout << c << endl;
  }
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  /* code */
  int n ;
  int ans=0;
  vector<int> A(n) ;
  vector<int> B(n) ;
  vector<int> C(n-1) ;
  
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < n-1; i++) {
    cin >> C[i];
  }


  ans += B[A[0]-1];
  
  for (int i = 1; i < n; i++) {
    ans += B[A[i]-1];
    if (A[i] == A[i-1]+1) {
      ans += C[A[i]-2];
    }
  }
  
  cout << ans << "\n" ;
  return 0;
}

Measured memory_bytes: 640
from collections import defaultdict
s = input()
t = input()
d1 = defaultdict(set)
d2 = defaultdict(set)
for i in range(len(s)):
  d1[t[i]].add(s[i])
  d2[s[i]].add(t[i])
  if len(d1[t[i]])>1 or len(d2[s[i]])>1:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 4144
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val S = input.next()
    var maxRainyDay = 0
    var currRainyDay = 0
    
    for (c in S) {
      if (c == 'R') {
        ++currRainyDay
      } else {
        maxRainyDay = Math.max(currRainyDay, maxRainyDay)
        currRainyDay = 0
      }
    }
    
    maxRainyDay = Math.max(currRainyDay, maxRainyDay)
    
    println(maxRainyDay)
  }
}

Measured memory_bytes: 36316
N, M = map(int, input().split())

l = [0] * N

for i in range(M):
    # 0-indexed
    a, b = [int(i) - 1 for i in input().split()]

    l[a] += 1
    l[b] += 1

for i in range(N):
    print(l[i])


Measured memory_bytes: 2940
#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <queue>


using namespace std;

std::priority_queue <int> a;


int main() {
    int n, m, p;
    long long ans=0;
    cin >> n >> m;
    for (int i=0; i<n; i++) {
        cin >> p;
        a.push(p);
    }
    while (m--) {
        p=a.top()/2;
        a.pop();
        a.push(p);
    }
    while (!a.empty()) {
        ans+=a.top();
        a.pop();
    }
    cout << ans;
    
    
    
    
    return 0;
}


Measured memory_bytes: 892
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                long a = sc.nextLong();
                long b = sc.nextLong();
                if(a == 1 || b == 1){
                        System.out.println(1);
                }else{
                        System.out.println((a * b + 1) / 2);
                }
        }
}
//お腹が痛いです
//コーナーケースの見落としほど悲しいものはないですよね

Measured memory_bytes: 35960
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int>> V(m);
  vector<int> P(m);
  for (int i=0;i<m;i++){
    int k;
    cin >> k;
    V[i].resize(k);
    for (int j=0;j<k;j++){
      cin >> V[i][j];
      V[i][j]--;
    }
  }
  for (int i=0;i<m;i++) cin >> P[i];
  int ans = 0;
  for (int bit=0;bit<(1<<n);++bit){
    bool ok = true;
    for (int i=0;i<m;i++){
      int light=0;
      for (int v : V[i]){
        if ((1 << v) & bit) light ++;
      }
      light %= 2;
      if (light != P[i]) ok = false;
    }
    if (ok) ans++;
  }
  cout << ans << endl; 
}

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

int main(){
  int n,i;
  int mx = -9999;
  int f = -1;
  int e = -1;
  char s[200006];
  scanf("%s", s);
  n = strlen(s);
  for(i = 0;i < n;i++){
    if(f == -1 && s[i] == 'A') f = i;
    if(s[i] == 'Z') e = i;
  }

  printf("%d\n", e - f + 1);

  return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

struct UF {
	vector<ll> par, sz, rank;
	UF(ll n) : par(n), sz(n), rank(n) {
		REP(i, n) {
			par[i] = i;
			sz[i] = 1;
			rank[i] = 0;
		}
	}
	ll find(ll x) {
		return par[x] == x ? x : par[x] = find(par[x]);
	}
	void unite(ll x, ll y) {
		x = find(x);
		y = find(y);
		if (x != y) {
			if (rank[x] < rank[y]) {
				par[x] = y;
				sz[y] += sz[x];
			} else {
				par[y] = x;
				sz[x] += sz[y];
				if (rank[x] == rank[y]) {
					rank[x]++;
				}
			}
		}
	}
	bool same(ll x, ll y) {
		return find(x) == find(y);
	}
	ll size(ll n) {
		return sz[find(n)];
	}
};

using cood = pair<ll, ll>;
using coid = pair<cood, ll>;
using edge = pair<coid, coid>;
ll cost(const edge&e) {
	cood beg = e.first.first, end = e.second.first;
	return min(abs(beg.first - end.first), abs(beg.second - end.second));
}
signed main() {
	ll n = in();
	vector<coid>c(n);
	REP(i, n) {
		ll x = in(), y = in();
		c[i] = make_pair(make_pair(x, y), i);
	}
	vector<edge>e(2 * (n - 1));
	sort(ALL(c), [](const coid&c1, const coid&c2) {return c1.first.first < c2.first.first; });
	REP(i, n - 1)e[i] = make_pair(c[i], c[i + 1]);
	sort(ALL(c), [](const coid&c1, const coid&c2) {return c1.first.second < c2.first.second; });
	REP(i, n - 1)e[i + n - 1] = make_pair(c[i], c[i + 1]);
	sort(ALL(e), [](const edge&e1, const edge&e2) {return  cost(e1) < cost(e2); });
	ll ans = 0;
	UF uf(n);
	REPC(i, e) {
		ll idx_b = i.first.second, idx_e = i.second.second;
		if (!uf.same(idx_b, idx_e)) {
			ans += cost(i);
			uf.unite(idx_b, idx_e);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

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

int dy[5] = {-1, 0, 1, 0, 0};
int dx[5] = {0, -1, 0, 1, 0};

int main(void) {
    long long int n,m;
    int now=1;

    cin>>n>>m;
    vector<long long int> a(m+1);
    FOR(i,1,m){
        cin>>a[i];
    }
    vector<long long int> dp(n+1,0);
    dp[0]=1;
    FOR(i,0,n-1){
        if(a[now]==i&&now<=m){
            dp[i]=0;
            now++;
        }

        if(i==n-1){
            dp[n]+=dp[n-1];
            dp[n]%=MOD;
        }else{
            dp[i+1]+=dp[i];
            dp[i+2]+=dp[i];
            dp[i+1]%=MOD;
            dp[i+2]%=MOD;
        }
    }
    /*
    FOR(i,0,n){
        cout<<i<<" "<<dp[i]<<endl;
    }
    */
    cout<<dp[n]%MOD<<endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
double dist(int x[], int y[], int n, int p)
{
    if (p <= 3)
    {
        double sum = 0;
        for (int i = 0; i < n; i++)
        {
            sum = sum + pow(abs(x[i] - y[i]), p);
        }
        return pow(sum, 1.0 / p);
    }
    else
    {
        double max = 0;
        for (int i = 0; i < n; i++)
        {
            int d = abs(x[i] - y[i]);
            if (d > max)
            {
                max = d;
            }
        }
        return max;
    }
}
int main()
{

    int n, x[100], y[100];
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &x[i]);
    }
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &y[i]);
    }
    printf("%.6lf\n", dist(x, y, n, 1));
    printf("%.6lf\n", dist(x, y, n, 2));
    printf("%.6lf\n", dist(x, y, n, 3));
    printf("%.6lf\n", dist(x, y, n, 4));
    return 0;
}



Measured memory_bytes: 2100
n=int(input())
lst=[int(input()) for i in range(n)]

lst = list(map(lambda x: x-1, lst))
lst_p = [0]
tmp = 0
flag =True
for i in range(n+1):
    tmp = lst[tmp]
    if tmp == 1:
        print(i+1)
        flag = False
        break
if flag:
    print(-1)

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

int main(){
	int n,k;cin>>n>>k;
	int ans=0;
	vector<int> a(k);
	for(auto&& w:a)cin>>w;
	sort(begin(a),end(a),greater<int>());
	if(a[0]*2< n)ans=0;
	else ans=a[0]-(n-a[0])-1;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    if ((r * 100 + g * 10 + b) % 4 == 0)
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}


Measured memory_bytes: 764