akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair

int main(){

  SCIN(s);CIN(k);

  int n = s.size();
  set<string> se_;
  REP(i,n){
    string s_;
    FOR(j,i,n){
      s_+=s[j];
      se_.insert(s_);
      if(se_.size() > k)
        se_.erase(prev(se_.end()));
    }
  }
  COUT(*prev(se_.end()));

  

  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue> 
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
#define db double
#define int LL
using namespace std;
//const int N   = ;
//const int mod = ;
const int INF =numeric_limits<int >::max();

#define rep(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}

void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int A,B,C,K;
signed main()
{
	read(A);read(B);read(C);read(K);
	printf("%lld",K&1?B-A:A-B);
	return 0;
	
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
 
happiness = 0
 
for word in S.split("L"):
    happiness += max(0, len(word) - 1)
for word in S.split("R"):
    happiness += max(0, len(word) - 1)
 
res = happiness + 2 * K
print(min(res, N-1))

Measured memory_bytes: 4348
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
using namespace __gnu_pbds;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define uid uniform_int_distribution<lli>
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>
#define endl "\n"
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

template <class my>
inline my aabs (const my &a)   { return (a > 0)  ? a : -a;         }
inline lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
inline lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(lli o, int m = mod) {
  int b = m, u = 0, v = 1, t, a=o%m;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += m;
  return u;
}
inline int add(const int &a, const int &b, int m=mod) { return a + b >= m ? a + b - m : a + b; }
inline int sub(const int &a, const int &b, int m=mod) { return a - b < 0 ? a - b + m : a - b; }
inline int mul(const int &a, const int &b, int m=mod) { return int(a * 1ll * b % m); }
inline int pow(int a, int b, int m=mod) {
    int ans = 1;
    a=((a%m)+m)%m;
    while (b) {
        if (b & 1) ans = mul(ans, a, m);
        a = mul(a, a, m);
        b >>= 1;
    }
    return ans;
}

void solve()
{
    lli n, m, t, k=0, q, temp=0, u=0, v=0, ans1=0, ans2=0, val=0, sum=mod;
    cin>>u>>v;
    vi vect;
    for(lli i=u, j=0; i<=v&&j<2020; i++, j++)
    {
        temp=i%2019;
        vect.pb(i%2019);
    }
    sort(all(vect));
    fol(i,0,vect.size())
    {
        fol(j,i+1,vect.size())
        {
            temp=(vect[i]*vect[j])%2019;
            sum=min(sum,temp);
        }
    }
    cout<<sum<<endl;
}

int main()
{
    fastio cout<<endl;
    cout << fixed << setprecision(7);
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int n;
double xa, ya, ra, xb, yb, rb;
bool doswap = false;

double dist(double x1, double x2, double y1, double y2) {
	double dx = xa - xb;
	double dy = ya - yb;
	return sqrt(dx*dx + dy*dy);
}

void swap(double *arg1, double *arg2) {
	double tmp = *arg1;
	*arg1 = *arg2;
	*arg2 = tmp;
}

int main() {
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> xa >> ya >> ra >> xb >> yb >> rb;

		doswap = false;

		if (ra < rb) {
			swap(&xa, &xb);
			swap(&ya, &yb);
			swap(&ra, &rb);
			doswap = true;
		}

		double dist_ab = dist(xa, ya, xb, yb);

		if (dist_ab < ra) {
			if (dist_ab + rb < ra) {
				if (doswap) cout << "-2" << endl;
				else cout << "2" << endl;
			}
			else cout << "1" << endl;
		} else if (dist_ab <= ra + rb) cout << "1" << endl;
		else cout << "0" << endl;
	}

	return 0;
}

/*@@@@@@@@@@@@@@@@@@@@@@@@@*/
/*@                       @*/
/*@ debug output erased ? @*/
/*@                       @*/
/*@@@@@@@@@@@@@@@@@@@@@@@@@*/

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

int main()
{
    string s;
    cin >> s;
    int ans;
    if( s == "SUN" )
    {
        ans = 7;
    }
    else if( s == "MON" )
    {
        ans = 6;
    }
    else if( s == "TUE" )
    {
        ans = 5;
    }
    else if( s == "WED" )
    {
        ans = 4;
    }
    else if( s == "THU" )
    {
        ans = 3;
    }
    else if( s == "FRI" )
    {
        ans = 2;
    }
    else if( s == "SAT" )
    {
        ans = 1;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
struct edges
{
	int to,next;
}edge[808080];
int firstr[202020],firstb[202020],now;
void adde(int *first,int x,int y)
{
	now++;
	edge[now].to=y;
	edge[now].next=first[x];
	first[x]=now;
}
int dep[202020],fa[202020];
int dis[202020],mi[202020];
bool mk[202020];
void work(int p)
{
	for(int e=firstb[p];e;e=edge[e].next)
		if(edge[e].to!=fa[p])
		{
			dep[edge[e].to]=dep[p]+1;
			fa[edge[e].to]=p;
			work(edge[e].to);
		}
}
void finddis(int p,int fa1)
{
	for(int e=firstr[p];e;e=edge[e].next)
		if(edge[e].to!=fa1)
		{
			dis[edge[e].to]=dis[p]+1;
			mi[edge[e].to]=mi[p];
			if(dep[edge[e].to]<dep[mi[p]])
				mi[edge[e].to]=edge[e].to;
			finddis(edge[e].to,p);
		}
}
int getdis(int x,int y)
{
	int ret=0;
	while(ret<3&&x!=y)
	{
		if(dep[x]>=dep[y])
		{
			x=fa[x];
			ret++;
		}
		else
		{
			y=fa[y];
			ret++;
		}
	}
	return ret;
}
int main()
{
	int n,a,b,x,y;
	scanf("%d%d%d",&n,&x,&y);
	memset(mk,0,sizeof(mk));
	memset(firstr,0,sizeof(firstr));
	memset(firstb,0,sizeof(firstb));
	now=0;
	dep[0]=n+1;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&a,&b);
		adde(firstr,a,b);
		adde(firstr,b,a);
	}
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&a,&b);
		adde(firstb,a,b);
		adde(firstb,b,a);
	}
	dep[y]=fa[y]=0;
	work(y);
	dis[x]=0;
	memset(mi,0,sizeof(mi));
	finddis(x,0);
	for(int i=1;i<=n;i++)
		for(int e=firstr[i];e;e=edge[e].next)
			if(getdis(i,edge[e].to)>=3)
				mk[i]=mk[edge[e].to]=true;
	for(int i=1;i<=n;i++)
		if(mk[i]&&dis[mi[i]]<dep[mi[i]])
		{
			printf("-1");
			return 0;
		}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(dis[mi[i]]<dep[mi[i]])
			ans=max(ans,dep[i]);
	printf("%d",ans*2);
	return 0;
}

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

// 入力
int N, M;
int dp[100001];       // メモ化再帰
multimap<int, int> G; // グラフ

int rec(int v) {
    if (dp[v] != 0)
        return dp[v]; // 既に更新済み

    int res = 0;

    // キーを持つ値を列挙する
    auto p = G.equal_range(v);
    for (auto it = p.first; it != p.second; ++it) {
        res = max(res, rec(it->second) + 1);
    }
    return dp[v] = res; // メモしながらリターン
}

int main() {
    // 入力受け取り
    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y; // 0-indexed にする
        G.emplace(x, y);
    }

    // 全ノードを一通り更新しながら答えを求める
    int res = 0;
    for (int v = 0; v < N; ++v) {
        res = max(res, rec(v));
    }
    cout << res << endl;
}

Measured memory_bytes: 7424
let rec gcd aa bb =
  let a = abs aa
  and b = abs bb in
  if b = 0 then a else gcd b (a mod b);;
  
let solve x list =
  let org_adj_list = List.map (fun k -> k - x) list in
  let gcdes = List.rev_map2 gcd (List.rev org_adj_list) org_adj_list in
  List.fold_left min 10000000000 gcdes
          
let read_list_of_int () =
  let rec read_list_of_int_inner lst =
    try let ans = (Scanf.scanf "%d " (fun x->x)) in
        read_list_of_int_inner (ans::lst)
    with End_of_file ->
      List.rev lst
  in
  read_list_of_int_inner []

let () =
  try let n, x = (Scanf.scanf "%d %d\n" (fun a b -> (a, b))) in
      let list = read_list_of_int () in
      let ans = solve x list in
      Printf.printf "%d\n" ans
  with End_of_file -> ()
;;


Measured memory_bytes: 14976
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll h,a;
    cin>>h>>a;
    if(a>h){
    	cout<<1<<endl;
    }
    else{
    	ll ans;
    	ans=h/a;
    	if(h%a!=0){
    		ans+=1;
    	}
    	cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
	long long n,m;
	scanf("%lld%lld",&n,&m);
	if (n==1&&m==1) printf("1\n");
	else if (n==1||m==1) printf("%lld\n",n*m-2);
	else printf("%lld\n",(n-2)*(m-2));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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() {
  string s;
  cin >> s;
  cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
}

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

int main() {
    int n, k; cin >> n >> k;
    vector<long long> v(n), p(n, 1e18);
    for (int i = 0; i < n; i++) cin >> v[i];
    p[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < k; j++) {
            if (i-j-1 < 0) break;
            p[i] = min(p[i], p[i-j-1]+abs(v[i]-v[i-j-1]));
        }
    }
    cout << p[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
/*
Author:Fuad Ashraful Mehmet
University of Asia Pacific
Date:23 Feb 2020
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N=1e5+5;
int n;

int main()
{
 ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    
  
  long long a,b;
  cin>>a>>b;
  long long lo=1,hi=1e18;


  long long ans=-1;

  for(int i=1;i<=1000;++i)
  {
      int r1=(i*8)/100;
      int r2=i/10;
      if(r1==a&&r2==b)
      {
          ans=i;
          break;
      }
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)

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

const ll MAX_N=131072;

int bit[MAX_N*2-1];
ll n;
vector<int> G[1000010];
vector<vector<int>> used(1000010,vector<int>(3,0));
vector<P> v;
bool cmp(P a,P b){
  if (a.second==b.second) return a.first<b.first;
  return a.second <b.second;
}
int main(){
  int N;cin>>N;
  rep(i,N){
    int a,b;
    cin>>a>>b;
    v.push_back(P(a,b));
  }
  sort(v.begin(),v.end(),cmp);
  int time=0;
  rep(i,N){
    P p=v[i];int a,b;
    a=p.first;b=p.second;
    time+=p.first;
    if (time>b){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 80500
h, w = map(int, input().split())
F = [[] for i in range(h)]
for i in range(h):
    a = list(input())
    F[i] = a

flag = True
for i in range(h):
    for j in range(w):
        if F[i][j] == "#":
            flag2 = False
            for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                nx, ny = i + dx, j + dy
                if 0 <= nx < h and 0 <= ny < w and F[nx][ny] == "#":
                    flag2 = True
            if not flag2:
                flag = False
                break

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
# coding: utf-8
# Your code here!

def main():
    n, k = map(int, input().split(' '))
    heights = list(map(int, input().split(' ')))
    
    print(len([i for i in heights if i >= k]))
    
    return 0
    
    
if __name__ == '__main__':
    main()

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

#define fi first
#define se second
#define sz(v) (int)((v).size())
#define pb push_back

typedef long long ll;

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

	string r, b; cin >> r >> b;
	int nr, nb; cin >> nr >> nb;
	string u; cin >> u;
	if (u==r) nr--;
	else nb--;
	cout << nr << " " << nb << "\n";
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lld long int
int main()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    string ans="";
    ans+=s[0];
    for(int i=1;s[i];i++){
        if(s[i]!=s[i-1])ans+=s[i];
    }
    cout<<ans.size()<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
  int A,B;
  scanf("%d%d", &A, &B);
  
  int count = 0;
  
  for(int i = A; i <= B; i++){
    if((i/10000) == (i%10)){ //万の位 = 一の位
      if((i/1000)%10 == (i/10)%10){ //千の位 = 十の位
        count++;
      }
    }
  }
  printf("%d",count);
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	a = a * b;
	c = c * d;
	if (a > c) cout << a << endl;
	else if (a = c)cout << a << endl;
	else if (a < c)cout << c << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main (){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(W<x+r || 0>x-r){
		cout<<"No"<<endl;
	}else if(H<y+r || 0>y-r){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
	return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
#define MOD 1000000007
#define PSET(x,y) fixed<<setprecision(y)<<x
#define ll long long
#define ld long double
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define lop(i,a,b) for(ll i=a;i<b;i++)
#define lopr(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define fi first
#define se second
#define pi pair<int,int>
#define pll pair<ll, ll>
#define si set<int>
#define sll set<ll>
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
#define state tuple<int,int,int>
#define graph map<ll,list<ll>>

inline int sbt(int x){return __builtin_popcount(x);} //returns number of set bits

using namespace std;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    
    fast_io()
    
    int n,k;
    cin>>n>>k;

    int ans=0;
    for(int i=1; i<=n; i+=2){
    	ans++;
    }

    if(ans>=k){
    	cout<<"YES";
    }
    else{
    	cout<<"NO";
    }

    return 0;
}

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

#define pb push_back
#define ff first
#define ss second

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

map<ll, ll> mp;
ll n, sum, ans, a;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	mp[0]++;
	for (int i = 1; i <= n; i++) cin >> a, sum += a, ans += mp[sum]++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n; cin>>n;
    int ans = 0;
    vector <int> a(3*n); 
    rep(i,3*n) cin>>a[i];
    sort(a.begin(),a.end(),greater<int>());
    itn cnt = 0;
    for(int i=0;i<3*n;i++){
        if(i%2==1) {ans += a[i]; cnt++;
        //cout<<a[i]<<endl;
        if(cnt == n) break;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2560
import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
seq = [x for x in range(1,N+1)]
L = list(itertools.permutations(seq))
for i in range(len(L)):
    X = list(L[i])
    if X == P:
        a = i + 1
    if X == Q:
        b = i + 1
ans = abs(a-b)
print(ans)

Measured memory_bytes: 46192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc135
{
    class D_FPS
    {
        private static readonly long mod = 1000000007;

        public static void Main()
        {
            var s = Console.ReadLine();
            var n = s.Length;

            var d = 1;
            var r = 0;

            var fCount = new int[6];

            for (int i = 0; i < s.Length; i++)
            {
                if (s[n - 1 - i] == '?')
                    fCount[i % 6]++;
                else
                {
                    int num = s[n - 1 - i] - '0';
                    r = (r + num * d) % 13;
                }
                d = d * 10 % 13;
            }

            var g = new long[13];
            g[0] = 1;
            d = 1;
            for (int i = 0; i < 6; i++)
            {
                var f = new long[13];
                for (int j = 0; j <= 9; j++)
                    f[j * d % 13]++;
                d = d * 10 % 13;
                f = Power(f, fCount[i]);
                g = Mul(g, f);
            }
            Console.WriteLine(g[(5 + 13 - r) % 13]);
        }

        private static long[] Power(long[] f, int n)
        {
            var g = new long[f.Length];
            g[0] = 1;
            while (n > 0)
            {
                if (n % 2 == 1)
                    g = Mul(f, g);
                f = Mul(f, f);
                n /= 2;
            }
            return g;
        }

        private static long[] Mul(long[] f, long[] g)
        {
            var ret = new long[f.Length];
            for (int i = 0; i < f.Length; i++)
            {
                for (int j = 0; j < f.Length; j++)
                {
                    var k = (i + j) % f.Length;
                    ret[k] = (ret[k] + f[i] % mod * g[j]) % mod;
                }
            }
            return ret;
        }
    }
}


Measured memory_bytes: 26184
import itertools

n, m = map(int, input().split())
h = [[0]*n for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    h[a-1][b-1] = 1
    h[b-1][a-1] = 1

ans = 0
x = list(itertools.permutations(range(1, n+1)))
for i in range(len(x)):
    flag = False
    if x[i][0] == 1:
        flag = True
        for j in range(n-1):
            if h[x[i][j]-1][x[i][j+1]-1] == 0:
                flag = False
                break
    if flag:
        ans += 1
print(ans)

Measured memory_bytes: 13900
n=int(input())

#データを並び替える
rowdata=[int(i) for i in input().split()]
rowdata.sort()

#nが偶数の時
if n%2==0:
    check=[]
    a=1
    for i in range(1,n,2):
        check.append(i)
        check.append(i)
    if check==rowdata:
        for i in range(int(n/2)):
            a*=2
            a=a%1000000007
        print(a)
    else:
        print(0)
        
#nが奇数の時
else:
    check=[]
    a=1
    if n==1:
        check=[0]
    else:
        for i in range(0,n,2):
            if i==0:
                check.append(i)
            else:
                check.append(i)
                check.append(i)
    if check==rowdata:
        for i in range(int((n-1)/2)):
            a*=2
            a=a%1000000007
        print(a)
    else:
        print(0)

Measured memory_bytes: 13880
//#include <bits/stdc++.h>/*
#include <unordered_map>
#include <functional> //greater
#include <algorithm> //sort
#include <iostream>
#include <iterator>
#include <utility> //pair
#include <sstream>
#include <cstring> //memset
#include <complex>
#include <cassert>
#include <random>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype> //isaplha, tolower
#include <deque>
#include <queue>
#include <stack>
#include <array>
#include <cmath> //sqrt, sin
#include <ctime>
#include <list>
#include <map>
#include <set>
//*/
 
#define int long long
#define uns unsigned
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define endl '\n'
using namespace std;
 
template<class T> ostream &operator<<(ostream &os, const pair<T,T> &p){
	return os<<"("<<p.fi<<","<<p.se<<")";}
template<class T> ostream &operator<<(ostream &os, const pair<const T,T> &p){
	return os<<"("<<p.fi<<","<<p.se<<")";}
template<class T> ostream &operator<<(ostream &os, const array<T,3> &p){
	return os<<"("<<p[0]<<","<<p[1]<<","<<p[2]<<")";}
template<class T> ostream &operator<<(ostream &os, const vector<T> &p){
	for(auto x: p) os<<x<<' '; return os;}
#define dbug(x) cerr<<">>>> "<<#x<<" = "<<x<<endl
#define _ <<", "<<
#define FOR(X,L,R) for(int X=L;X<R;X++)
#define FI(I,X) for(auto I=(X).begin();I!=(X).end();I++)
#define print(X) {cerr<<"{ ";FI(I,X)cerr<<*I<<' ';cerr<<"}"<<endl;}
#define mset(V,X) memset(V,X,sizeof(V))
#define all(X) (X).begin(),(X).end()
#define upperb(V,X) (int)(upper_bound(all(V),(X))-V.begin())
#define lowerb(V,X) (int)(lower_bound(all(V),(X))-V.begin())
 
const double EPS = 1e-9, PI = acos(-1);
const ll LINF = 0x3f3f3f3f3f3f3f3f, mod = 1e9+7;
const int INF = 0x3f3f3f3f, SZ = 2e5+20;
 
int n,c;
vector<pii> v;
int res,aux;
double c2,aux2;
void bt(int i){
	if(i == n) return;
 
	aux2 = 0; c2 = c;
	for(int j=i; j<n && c2; j++){
		if(v[j].fi <= c2){
			c2 -= v[j].fi; aux2 += v[j].se;
		} else {
			aux2 += (v[j].se*c2)/v[j].fi;
			c2 = 0;
		}
	}
	if(aux2 + aux <= res) return;
  
	if(v[i].fi <= c){
		c -= v[i].fi;
		aux += v[i].se;
		if(aux > res) res = aux;
		bt(i+1);
		aux -= v[i].se;
		c += v[i].fi;
	}
	bt(i+1);
}
 
int32_t main(){
	ios::sync_with_stdio(false);cin.tie(0);
	
	cin>>n>>c;
	FOR(i,0,n){
		int x,y; cin>>x>>y;
		v.pb({x,y});
	}
 
	sort(all(v),[](pii a, pii b){
		return (a.se+0.0)/a.fi > (b.se+0.0)/b.fi;
	});
	
	bt(0);
	cout<<res<<endl;
 
	return 0;
}

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


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>



int main() {
	ll a, b;
	cin >> a >> b;
	if (abs(a - b) % 2 == 1)cout << "IMPOSSIBLE" << endl;
	else cout << (a + b) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

const ll inf=9982443530;

inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

int p[5005];
ll c[5005];
ll ans=-inf;
int ma[5005], pa, n;

int main()
{
    int k;
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&p[i]);
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&c[i]);
    }
    for(int i=1;i<=n;i++)
    {
        memset(ma,0,sizeof(ma));
        pa=k;
        int w=i, flag=0;
        ll sum=0, pi=-inf;
        while(pa)
        {
            w=p[w];
            //printf("%d %d %d\n",w,pa,sum);
            if(ma[w]==1&&flag==0)
            {
                ll bi=k/(k-pa);
                //printf("%lld\n",bi);
                if(sum>=1)
                {
                    ans=max(sum*(bi-1)+pi,ans);
                    sum=sum*bi;
                }
                else
                {
                    break;
                }
                pa=k%(k-pa);
                flag=1;
            }
            if(pa==0)
            {
                break;
            }
            sum=sum+c[w];
            pa--;
            ma[w]++;
            ans=max(ans,sum);
            pi=max(sum,pi);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3808
#![allow(dead_code)]
use crate::scanner::Scanner;
use num_integer::gcd;
fn main() {
    let mut scan = Scanner::new();
    let k = scan.read::<i64>();
    let mut sum = 0;
    for a in 1..=k {
        for b in 1..=k {
            for c in 1..=k {
                let mut g = gcd(a, b);
                g = gcd(g, c);
                sum += g;
            }
        }
    }
    println!("{}", sum);
}
mod scanner {
    use std::io::{stdin, BufReader, Bytes, Read, Stdin};
    use std::str::FromStr;
    pub struct Scanner {
        buf: Bytes<BufReader<Stdin>>,
    }
    impl Scanner {
        pub fn new() -> Scanner {
            Scanner {
                buf: BufReader::new(stdin()).bytes(),
            }
        }
        pub fn read_next<T: FromStr>(&mut self) -> Option<T> {
            let token = self
                .buf
                .by_ref()
                .map(|c| c.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect::<String>();
            token.parse::<T>().ok()
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_next().unwrap()
        }
        pub fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read::<T>()).collect()
        }
        pub fn chars(&mut self) -> Vec<char> {
            self.read::<String>().chars().collect()
        }
        pub fn char(&mut self) -> char {
            self.read::<String>().chars().next().unwrap()
        }
    }
}



Measured memory_bytes: 2140
S = input()
T = input()
Sn = len(S)
Tn = len(T)
ans = 0

for i in range(Sn-Tn+1):
    M = 0
    for j, k in zip(S[i:], T):
        if j == k:
            M += 1
    
    if M > ans:
        ans = M

print(Tn - ans)

Measured memory_bytes: 67264
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
    long long int n;
    cin >> n;
    if(n==1)
        cout << "1";
    else
    {
    long long int ret=0;
    while(n>1)
    {
        n/=2;
        ret++;
    }
    long long int sum=1;
    for(int i=0;i<ret;i++)
        sum*=2;
    long long int c=1;
    long long int d=1;
    for(int i=0;i<ret-1;i++)
        {
            d*=2;
            c+=d;
        }
    sum+=c;
    cout << sum;}
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
 
#define numof(array)  (sizeof (array) / sizeof *(array))

const int INF = 1000000007;
const int MAX_V = 1000007;
 
typedef long long ll;
typedef pair<int, int> P; //first: ???????????¢???second: ??????????????? 

struct edge{
    int to;
    int cost;
};

int V=0;
vector<edge > G[MAX_V];
int d[MAX_V];

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > qu;
  fill(d, d + V, INF);
  d[s] = 0;
  qu.push(P(0,s));
  while(!qu.empty()){
    P p = qu.top(); qu.pop();
    int v = p.second;    
    if(d[v] < p.first) continue;
    for(int i = 0; i < G[v].size(); i++){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
	d[e.to] = d[v] + e.cost;
	qu.push(P( d[e.to], e.to ));
      }
    }
  }
}


int main(){

  int E,r;
  cin >> V >> E >> r;
  for(int i = 0 ; i < E; i++){
    int s , t , d;
    cin >> s >> t >> d;
    edge e = {t,d};
    //    e.to = t; e.cost = d;
    G[s].push_back(e);
  }
  dijkstra(r);
  for(int i = 0; i < V ; i++){
    if (d[i] == INF) cout << "INF" << endl;
    else cout << d[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 34260
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> P;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;
const double PI = acos(-1);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    cout<<(a*b)<<endl;
}

Measured memory_bytes: 3648
n=int(input())
S=input().split()
S=[int(s) for s in S]

q=int(input())
T=input().split()
T=[int(t) for t in T]

#線型探索　計算時間O(qn)
def lineresearch(key):
    i = 0
    while S[i]!=key:
        i = i+1
        if i==n:
            #result = 0
            return 0
    #result = 1
    return 1

count = 0

for i in range(q):
    S.append(0)
    S[n]=T[i]   #Tの要素を番兵としておく
    count += lineresearch(S[n])
print(count)

        
        
        
        


Measured memory_bytes: 6556
#include<stdio.h>
#include<algorithm>
int main()
{
	int N,Q,M,i;
	while(scanf("%d%d",&N,&Q),N)
	{
		int*p,a[100]={};
		while(N--)for(scanf("%d",&M);M--;)scanf("%d",&i),++a[i];
		p=std::max_element(a,a+100);
		printf("%d\n",*p<Q?0:p-a);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 405;
int a[maxn], b[maxn];
int d[maxn][maxn];
int pw[maxn][maxn];
int psum[maxn][maxn];

const int mod = 1e9 + 7;
int sum(int a, int b) { return (a + b) % mod; }
int mul(ll a, ll b) { return (a * b) % mod; }
void add(int &a, int b) { a += b; if (a >= mod) a -= mod; }
int sub(int a, int b) { return sum(a, mod - b); }

int prog(int l, int r, int deg) {
    return sub(psum[deg][r + 1], psum[deg][l]);
    int res = 0;
    for (int i = l; i <= r; ++i)
        add(res, pw[i][deg]);
    return res;
}

int main() {
    #ifdef LOCAL
    assert(freopen("e.in", "r", stdin));
    #else
    #endif
    forn (i, maxn)
        pw[i][0] = 1;
    forn (i, maxn)
        forn (j, maxn - 1)
            pw[i][j + 1] = mul(pw[i][j], i);
    forn (deg, maxn) {
        forn (i, maxn - 1)
            psum[deg][i + 1] = sum(psum[deg][i], pw[i][deg]);
    }
    int n, c;
    cin >> n >> c;
    forn (i, n)
        cin >> a[i];
    forn (i, n)
        cin >> b[i];
    d[0][0] = 1;
    forn (i, n)
        forn (j, c + 1) {
            for (int k = j; k <= c; ++k)
                add(d[i + 1][k], mul(d[i][j], prog(a[i], b[i], k - j)));
        }
    cout << d[n][c] << '\n';
}

Measured memory_bytes: 2176
#include<stdio.h>
int main(void)
{
    int a,i,n;
    int x=100000;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        x=x*105/100;
        if(x%1000 != 0){
            a=x/1000+1;
            x=a*1000;
        }
    }
    printf("%d\n",x);
    return 0;
}

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

int main(){
    int N,K; cin >> N >> K;
    vector<int> h(N);
    for(int i = 0; i < N; i++) cin >> h.at(i);
    int count = 0;
    for(int i =0; i < N; i++){
        if(h.at(i) >= K){
            count++;
        }
    }
    cout << count << endl;

}

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

int main() {
	int n, m ,sum=0;
	cin >> n;

	for (int i = 1;; ++i) {
		sum += i;
		if (sum == n) {
			for (int j = 1; j <= i; ++j) {
				cout << j << endl;
			}
			return 0;
		}
		if (sum > n) {
			m = sum - n;
			for (int j = 1; j <= i; ++j) {
				if (j != m) cout << j << endl;
			}
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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

int main(){
	int K;
	cin >> K;
	string S;
	cin >> S;
	int N=S.size();
	if(N<=K) cout << S << endl;
	else{
		rep(i,K) cout << S[i];
		cout << "..." << endl;
	}

	return 0;
}

Measured memory_bytes: 3616
import sys
H, N = map(int, sys.stdin.readline().split())
m = map(int, sys.stdin.read().split())
AB = zip(m, m)
INF = 10**20
dp = [INF]*(H+10**4)
dp[0] = 0
for a, b in AB:
    for j in range(H+10**4):
        dp[j] = min(dp[j], dp[j-a] + b if j-a >= 0 else INF)
print(min(dp[H:]))


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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator*(long long y,const mint& m){ return m*y; }

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

mint fact_inverse(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		memo[n]=inverse(fact(n));
		for(int i=n;i>k;i--) memo[i-1]=memo[i]*i;
	}
	return memo[n];
}

mint choose(int n,int k,int type=0){
	if(k<0 || n<k) return 0;
	if(type==0){
		return fact(n)*fact_inverse(k)*fact_inverse(n-k);
	}
	else{
		if(k>n-k) k=n-k;
		mint res=fact_inverse(k);
		rep(i,k) res*=n-i;
		return res;
	}
}

int main(){
	int n,a,b; cin>>n>>a>>b;
	cout<<pow(mint(2),n)-1-choose(n,a,1)-choose(n,b,1)<<'\n';
	return 0;
}


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

int main(void) {
  string s, t, u;
  int a, b;
  cin >> s;
  cin >> t;
  cin >> a;
  cin >> b;
  cin >> u;

  if (u == s){
    cout << a - 1 << " " << b;
  }
  if (u == t){
    cout << a << " " << b - 1;
  }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int K,A,B;
  cin>>K>>A>>B;
  if(A<=B){
    if(A>=K)
      puts("1");
    else
      puts("-1");
  }else
    cout<<max((K-B-1)/(A-B)*2,0LL)+1<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb(t) push_back(t)
#define pt(num) cout << num << "\n"
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;


int main(void) {
    ll N, L;
    cin >> N >> L;
    ll a[MAX];
    ll i;
    
    for(i=0; i<N; i++)
        cin >> a[i];
    
    ll key=-1;
    for(i=0; i<N-1; i++) {
        if(a[i]+a[i+1]>=L) key=i;
    }
    
    if(key==-1) {
        pt("Impossible");
        return 0;
    }
    
    vector<ll> vc;
    vc.pb(key);
    for(i=key-1; i>=0; i--) vc.pb(i);
    for(i=key+1; i<N-1; i++) vc.pb(i);
    
    pt("Possible");
    for(i=N-2; i>=0; i--) pt(vc[i]+1);
    
}


Measured memory_bytes: 2548
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

for i in range(len(a)):
    if i == 0:
        scr = b[a[i] - 1]
    else:
        scr += b[a[i] - 1]
        if a[i] == a[i-1] + 1:
            scr += c[a[i-1] - 1]

print(scr)

Measured memory_bytes: 3064
N = int(input())
a = list(map(int, input().strip().split()))

for j in range (1,N):
    for i in range(0, N-1):
        print(a[i], end=" ")
    print(a[N-1])
    temp = a[j]
    for k in range(0,j):
        if(temp<a[k]):
          a.pop(j)
          a.insert(k,temp)
          break
for l in range(0, N-1):
  print(a[l], end=" ")
print(a[N-1])


Measured memory_bytes: 5976
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Comparator;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
        // write your code here
        int [] nl = inputval();
        int n = nl[0];
        List<String> sl = new ArrayList<String>();
        for (int i=0; i<n; i++){
            sl.add(br.readLine().trim());
        }
        Collections.sort(sl);
        String ans = String.join("",sl);
        System.out.println(ans);

    }

}



Measured memory_bytes: 32612
#include<stdio.h>
#include<stdlib.h>

int main(void){

  int i, j, H, W;

  while(1){
    scanf("%d %d", &H, &W);
    if(H == 0 && W == 0){
      break;
    }
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
        if(i==0 || i==H-1){
          printf("#");
        }else if(j==0 || j==W-1){
          printf("#");
        }else{
          printf(".");
        }
      }
      printf("\n");
    }
    printf("\n");
  }


  return 0;

}



Measured memory_bytes: 2032
var
	N,i,j:Longint;
	ans:int64;
begin
	read(N);
	j:=round(sqrt(N));
	if j*j>N then dec(j);
	for i:=1 to j do inc(ans,(N div i)*(N div i+1)*i-i*i*i);
	writeln(ans);
end.

Measured memory_bytes: 1372
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    string S;
    cin >> S;
    int count = 0;
    int maxCount = 0;
    rep(i, S.size()) {
        if(S[i] == 'R') {
            count++;
        } else {
            count = 0;
        }
        maxCount = max(count, maxCount);
    }
    cout << maxCount << endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<cmath>
#include<unordered_set>
#define int long long
using namespace std;

signed main(){
	int a; cin >> a;
	int ans = 0;
	while (a > 1) {
		ans++;
		a /= 2;
	}
	cout << pow(2,ans) << endl;
}

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

int main() {
	int k,n,l[60],sum=0,i;
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin>>l[i];
	}
	sort(l, l + n, greater<int>());
	for(i=0;i<k;i++){
		sum+=l[i];
	}
	cout<<sum<<endl;
}


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

int main() {
  int N, K, i, x;
  i = 0;
  x = 1;
  cin >> N >> K;
  while(x < K && i < N){
    x *= 2;
    i++;
  }
  while(i < N){
    x += K;
    i++;
  }
  cout << x << endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
void North(int *a,int *b,int *e,int *f){
  int x;
  x = *a;
  *a = *b;
  *b = *f;
  *f = *e;
  *e = x;
}

void East(int *a,int *c,int *d,int *f){
  int x;
  x = *a;
  *a = *d;
  *d = *f;
  *f = *c;
  *c = x;
}

void West(int *a,int *c,int *d,int *f){
  int x;
  x = *a;
  *a = *c;
  *c = *f;
  *f = *d;
  *d = x;
}

void South(int *a,int *b,int *e,int *f){
  int x;
  x = *a;
  *a = *e;
  *e = *f;
  *f = *b;
  *b = x;
}

void Right(int *b,int *c,int *d,int *e){
  int x;
  x = *b;
  *b = *c;
  *c = *e;
  *e = *d;
  *d = x;
}

void Left(int *b,int *c,int *d,int *e){
  int x;
  x = *b;
  *b = *d;
  *d = *e;
  *e = *c;
  *c =x;
}



int main(void){
  int n,i,a[7],sum;
  char text[10];
  while(1){
    for(i=1;i<7;i++){
      a[i] = i;
    }
    sum = 1;
    scanf("%d",&n);
    if(n==0)return(0);
    for(i=0;i<n;i++){
      scanf("%s",text);
      if(strcmp(text,"North")==0){
	North(&a[1],&a[2],&a[5],&a[6]);
	sum += a[1];
      }
      else if(strcmp(text,"East")==0){
	East(&a[1],&a[3],&a[4],&a[6]);
	sum += a[1];
      }
      else if(strcmp(text,"West")==0){
	West(&a[1],&a[3],&a[4],&a[6]);
	sum += a[1];
      }
      else if(strcmp(text,"South")==0){
	South(&a[1],&a[2],&a[5],&a[6]);
	sum += a[1];
      }
      else if(strcmp(text,"Right")==0){
	Right(&a[2],&a[3],&a[4],&a[5]);
	sum += a[1];
      }
      else if(strcmp(text,"Left")==0){
	Left(&a[2],&a[3],&a[4],&a[5]);
	sum += a[1];
      }
    }
    printf("%d\n",sum);
  }
  
  return(0);
}

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

int main(){
    int n,m;
    cin >> n >> m;
    set<int> from,to;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        if(a == 1) from.insert(b);
        if(b == n) to.insert(a);
    }

    bool flag = false;
    for(auto x : from){
        if(to.count(x)) flag = true;
    }

    if(flag) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 9600
def rolling_hash(s):
    l = len(s)
    h = [0]*(l + 1)
    v = 0
    for i in range(l):
        h[i+1] = v = (v * base + ord(s[i])) % mod
    return h
def setup_pw(l):
    pw = [1]*(l + 1)
    v = 1
    for i in range(l):
        pw[i+1] = v = v * base % mod
    return pw
def get(h, b, l, r):
    return (h[r] - h[l] * b[r-l]) % mod

def check_bisect(l,h1,b1,h2,b2):
    for j in range(N-2*l+1):
        a1 = get(h1,b1,j,l+j)
        a2 = get(h2,b2,j,l+j)
        for k in range(N-2*l-j+1):
            if a1 == get(h1,b1,j+l+k,2*l+j+k) and a2 == get(h2,b2,j+l+k,2*l+j+k):
                return True
    return False

N = int(input())
S = input()
mod = 1000000007
base = 37
h1 = rolling_hash(S)
b1 = setup_pw(N)
base = 401
h2 = rolling_hash(S)
b2 = setup_pw(N)
left = 1
right = N // 2
finish = False
if N <= 26:
    s = set(list(S))
    if N <= 3:
        if len(s) < N:
            print('1')
        else:
            print('0')
        finish = True
    else:
        if len(s) == N:
            print('0')
            finish = True
while finish == False:
    if left == right:
        print(left)
        finish = True
    elif right - left == 1:
        if check_bisect(right,h1,b1,h2,b2):
            print(right)
        else:
            print(left)
        finish = True
    else:
        mid = (left+right) // 2
        if check_bisect(mid,h1,b1,h2,b2):
            left = mid
        else:
            right = mid - 1

Measured memory_bytes: 42864