akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y


}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;


}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
 
}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

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

}


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

int main(){
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(),a.end());
  if(a[0]==5 && (a[1]==5 && a[2]==7)) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    if ((B - A) % 2 == 0) {
      System.out.println("Alice");
    } else {
      System.out.println("Borys");
    }
  }
}

Measured memory_bytes: 23636
x, y = map(int, input().split())

a = [1, 3, 5, 7, 8 , 10, 12]
b = [4, 6, 9, 11]

if x in a and y in a:
    print("Yes")
elif x in b and y in b:
    print("Yes")
elif x == y == 2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
using System;
namespace CodeIQ
{
    class Program
    {
        static int[] coins = { 500, 100, 50, 10, 5, 1 };
        static void Main(string[] args)
        {
            String line;
            for (; (line = Console.ReadLine()) != null;)
            {
                Console.Write(System.Text.RegularExpressions.Regex.Replace(
                    line, "FESTIVAL$", string.Empty));
            }
        }
    }
}


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

int main() {
ll x;cin>>x;
ll temp=100;
for(int i=1;i<4000;i++)
{
    temp=temp+temp/100;
    if(temp>=x)
    {
        cout<<i<<"\n";
        break;
    }
}


  return 0;

}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>


int main(){

	int a;

	char s[150]={0};
	char x[150]={0};
	char b[]="...";

	scanf("%d",&a);
	scanf("%s",s);


	if(strlen(s)<=a){
		printf("%s",s);
	}else{

		strncpy(x,s,a);
		strcat(x,b);
		x[a+3]='\0';
		
		printf("%s",x);
	}

	return 0;
}
	







	


Measured memory_bytes: 1732
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {

	string S,T;
	cin >> S >> T;
	cout << T << S;

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}

Measured memory_bytes: 3560
#include<stdio.h>
int main(void)
{
	int n,m,x;
	char s;
	scanf("%d",&n);
	x=n;
	while(1){
		scanf("%c",&s);
		if(s=='+'){
			scanf("%d",&m);
			x+=m;
		}
		if(s=='-'){
			scanf("%d",&m);
			x-=m;
		}
		if(s=='*'){
			scanf("%d",&m);
			x*=m;
		}
		if(s=='/'){
			scanf("%d",&m);
			x/=m;
		}
		if(s=='=')	break;
	}
	printf("%d\n",x);
	return 0;
}



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

using namespace std;

int main(){
	string s, t;

	cin >> s >> t;

	int a, b;

	cin >> a >> b;

	string u;

	cin >> u;

	if(u == s){
		a--;
	}else{
		b--;
	}

	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h> 
int main(void){ 
    int h,w,i,j; 
    while(scanf("%d %d",&h,&w),h+w){ 
        for(i=0;i<h;i++){ 
            for(j=0;j<w;j++) 
            printf("#"); 
            printf("\n"); } 
            printf("\n"); } 
            return 0; 
    
}   


Measured memory_bytes: 2040
def LI(): return list(map(int,input().split()))
A,B,C,X,Y = LI()
ans = float('INF')
for i in range(max(X,Y)+1):
    temp = A*max(X-i,0)+B*max(Y-i,0)+C*(2*i)
    ans = min(temp,ans)
print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
	int s_x[51], s_y[51], m_x[51], m_y[51], cur_dis;
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) scanf("%d%d", &s_x[i], &s_y[i]);
	for (int i = 0; i < m; i++) scanf("%d%d", &m_x[i], &m_y[i]);
	for (int i = 0; i < n; i++) {
		int update_dis = abs(s_x[i] - m_x[0]) + abs(s_y[i] - m_y[0]), checkpoint = 1;
		
			for (int j = 1; j < m; j++) {
				cur_dis = abs(s_x[i] - m_x[j]) + abs(s_y[i] - m_y[j]);
				if (update_dis > cur_dis) {
					update_dis = cur_dis;
					checkpoint = j + 1;
				}
			}
			printf("%d\n", checkpoint);
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=5003;
const ll INF=1LL<<60;
ll dp[MAX][MAX][2];//iの部分木でj個カットして(k=0のとき全部正,k=1のとき直近の最小の和)
ll cost[MAX];
int size[MAX];

vector<int> G[MAX];

void sizeDFS(int u,int p){
    size[u]=1;
    for(int to:G[u]){
        if(to==p) continue;
        sizeDFS(to,u);
        size[u]+=size[to];
    }
}

void DFS(int u,int p){
    int sizesum=0;
    dp[u][0][1]=cost[u];
    
    if(cost[u]>0){
        dp[u][0][0]=cost[u];
    }
    
    for(int to:G[u]){
        if(to==p) continue;
        
        DFS(to,u);
        
        ll subdp[sizesum+size[to]+2][2];
        
        for(int i=0;i<sizesum+size[to]+2;i++){
            subdp[i][0]=INF;
            subdp[i][1]=INF;
        }
        
        for(int i=0;i<=sizesum;i++){
            for(int j=0;j<=size[to];j++){
                if(dp[to][j][0]<INF) subdp[i+j][0]=min(subdp[i+j][0],dp[u][i][0]+dp[to][j][0]);//つなぐ
                if((0<=dp[to][j][0]&&dp[to][j][0]<INF)||dp[to][j][1]<0) subdp[i+j+1][0]=min(subdp[i+j+1][0],dp[u][i][0]);//きる
                
                for(int bit=0;bit<4;bit++){
                    subdp[i+j][1]=min(subdp[i+j][1],dp[u][i][bit/2]+dp[to][j][bit%2]);//つなぐ
                    
                    if(bit%2==0){
                        if(0<=dp[to][j][bit%2]&&dp[to][j][bit%2]<INF) subdp[i+j+1][1]=min(subdp[i+j+1][1],dp[u][i][bit/2]);//きる
                    }else{
                        if(dp[to][j][bit%2]<0) subdp[i+j+1][1]=min(subdp[i+j+1][1],dp[u][i][bit/2]);//きる
                    }
                }
                
            }
        }
        
        for(int i=0;i<sizesum+size[to]+2;i++){
            dp[u][i][0]=subdp[i][0];
            dp[u][i][1]=subdp[i][1];
        }
        
        sizesum+=size[to]+1;
    }
}

int main(){
    
    int N;cin>>N;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            dp[i][j][0]=INF;
            dp[i][j][1]=INF;
        }
    }
    
    for(int i=0;i<N;i++) cin>>cost[i];
    
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    sizeDFS(0,-1);
    
    DFS(0,-1);
    
    for(int j=0;j<=N+3;j++){
        if(dp[0][j][0]<INF||dp[0][j][1]<0){
            cout<<j<<endl;
            return 0;
        }
    }
    
}



Measured memory_bytes: 392448
#include <stdio.h>

int main(void){
    int H,W;
    int i, j;
    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++){
                printf("#");
            }
            printf("\n");
        }
    printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

enum Trend
{
  even,
  increase,
  decrease
};

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);

  for (int i = 0; i < N; i++)
    cin >> A[i];
  
  Trend trend = even;
  int count = 0;
  for (int i = 0; i < N-1; i++)
  {
    int diff = A[i+1] - A[i];
    Trend nTrend = diff > 0 ? increase : (diff < 0 ? decrease : even);

    switch (trend)
    {
    case even:
      trend = nTrend;
      break;
    case increase:
      if (nTrend == decrease)
      {
        count++;
        trend = even;
      }
      break;
    case decrease:
      if (nTrend == increase)
      {
        count++;
        trend = even;
      }
      break;
    default:
      break;
    }
    
  }

  cout << count + 1 << endl;
}


Measured memory_bytes: 640
while True:
  n,x = map(int,input().split())
  if n==x==0:
    break
  else:
    N=[]
    for n_1 in range(1,x//3+1):
      z=x-n_1
      for n_2 in range(n_1,n):
        n_3=z-n_2
        if n>=n_3 >n_2>n_1:
          N.append(n_3)
    print(len(N))


Measured memory_bytes: 5604
/*
 #pragma GCC target ("avx2")
 #pragma GCC optimize ("Ofast")
 #pragma GCC optimize ("unroll-loops")
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
#define F first
#define S second
#define pb push_back
using namespace std;
const long long N = 2e5 + 10;
long long n, k;
long long a[N],pref[N];
vector<long long> v;

long long ans;

long long t[N];

long long sum (long long r)
{
    long long result = 0;
    for (; r >= 0; r = (r & (r+1)) - 1)
        result += t[r];
    return result;
}

void inc (long long i, long long delta)
{
    for (; i <= N; i = (i | (i+1)))
        t[i] += delta;
}

long long sum (long long l, long long r)
{
    return sum (r) - sum (l-1);
}
vector<pair<long long,long long> > p;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(long long i=0;i<n;i++){
        cin>>a[i];
        //ans+=(a[i]>=k);
    }
    for(long long i=1;i<=n;i++){
        pref[i]=pref[i-1]+a[i-1];
    }
    for(long long i=0;i<=n;i++){
        pref[i]-=(i*k);
        //cout<<pref[i]<< ' ';
    }
    for(long long i=0;i<=n;i++){
        p.pb({pref[i],i});
    }
    sort(p.begin(),p.end());
    long long c=1;
    for(long long i=0;i<p.size();i++){
        if(i>0&&p[i].F>p[i-1].F)c++;
        pref[p[i].S]=c;
    }
    
    for(long long i=0;i<=n;i++){
        //cout<<ans<<' ';
        ans+=(sum(0,pref[i]));
        inc(pref[i],1);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 9584
#include <iostream>
#include <vector>
#include <limits.h>

using namespace std;

typedef long long ll;
ll MOD = 1000000007;

int main() {
    ll n,k;
    cin>>n>>k;
    vector<int> a(n);
    ll count1=0,count2=0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(a[i]>a[j]){
          count1++;
        }
      }
    }

    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        if(a[i]>a[j]){
          count2++;
        }
      }
    }
   ll ans=0;
   ans+=(k%MOD)*(count2%MOD)%MOD;
   ans+=(count1%MOD)*(((k*(k-1))/2)%MOD);
   ans=ans%MOD;
   cout<<ans<<endl;
   return 0;
 }


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    
    int a,b;
    while (1) {
        cin >> a >> b;
        if ((a ==0)and(b ==0))
            break;
        
        for (int i = 0; i<a ; i++) {
            for (int j = 0; j< b; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
   return 0;
}

Measured memory_bytes: 1152
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)

s=0
t=0
prev=-1
c=0
for a in A:
    if prev==a:
        c+=1
    else:
        prev=a
        c=1
    if c==2:
        if s==0:
            s=a
        elif t==0:
            t=a
            break
    if c==4 and t==0:
        t=a
        break
print(s*t)


Measured memory_bytes: 62832
s = gets.chomp

words  = ['dreamer', 'eraser', 'dream', 'erase']
tmp_s = s.dup

words.permutation(4) do |arr|
  s = tmp_s.dup
  arr.each do |word|
    while s.include?(word)
      s.gsub!(word, '')
    end
  end
  if s == ''
    puts 'YES'
    exit
  end
end

puts 'NO'


Measured memory_bytes: 7548
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<pair<int,int> >a(n);
  for(int i=0;i<n;i++)
  {
    int d;
    cin>>d;
    a[i]=make_pair(d,i);
  }
  sort(a.begin(),a.end());
  vector<int>m(n);
  for(int i=0;i<n;i++)
  {
	if(i<n/2)m[a[i].second]=a[n/2].first;
    else m[a[i].second]=a[(n/2)-1].first;
  }
  for(int i=0;i<n;i++)cout<<m[i]<<endl;
  
  return 0;
}

Measured memory_bytes: 4480
// Problem : B - Minor Change
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<int>
#define slli set<int>
#define mlli map<int,int>
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fint fast;test
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;

void solve(){
	string a,b;
	cin>>a>>b;
	int count=0;
	FOR(i,a.size()){
		if(a[i]!=b[i])count++;
	}	
	cout<<count<<endl;
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


Measured memory_bytes: 3864
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
string S;
int main() {
	cin>>S;

	S[3]='8';
	cout<<S<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
      int n,m;
      cin>>n>>m;
      if(m%2==1)
         cout<<"No"<<endl;
      else
      {
          if(m>4*n)
            cout<<"No"<<endl;
          else if(m<2*n)
             cout<<"No"<<endl;
          else
              cout<<"Yes"<<endl;

      }
}



Measured memory_bytes: 3624
/*      ###########################
        #  Author : Pranay Garg   #
        #  College : SGSITS       #
        ###########################
*/      
#include<bits/stdc++.h>
#define ll long long int
#define ironman ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD 1000000007
#define endl '\n'
#define INF 1e18L+1
#define mp make_pair
#define fi first
#define se second
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define pb push_back
#define pf push_front
using namespace std;
template<class T> T max(T a, T b, T c) {
    return max(a, max(b, c));
}
template<class T> T min(T a, T b, T c) {
    return min(a, min(b, c));
}
void fastio()
{
    ironman
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt","w",stderr);
    #endif
}
ll prime[100005];
void SieveOfEratosthenes(ll n)//O(nloglogn) 
{  
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}  
bool isPrime(ll n)//O(sqrt(n))
{
    if(n<2)
        return false;
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;
    return true;
}
std::vector<ll> factors(ll n)//O(sqrt(n))
{
    std::vector<ll> f;
    for(ll i=2;i*i<=n;i++)
    {
        while(n%i==0)
        {
            f.push_back(i);
            n = n/i;
        }
    }
    if(n>1) f.push_back(n);
    return f;
}
ll gcd(ll a,ll b)//O(logn)
{
    if(!b) return a;
    return gcd(b,a%b);
}
ll modpow(ll x,ll n,ll m)//O(logn)// used for calculating (x^n)%m
{
    if(n==0) return 1%m;
    ll u = modpow(x,n/2,m);
    u = (u%m * u%m)%m;
    if(n%2==1)
        u = (u%m * x%m)%m;
    return u%m;
}
ll eulerstotientfunction(ll n)//O(sqrt(n))
{
    ll ans = n;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            while(n%i==0)
                n = n/i;
            ans -= ans/i;
        }
    }
    if(n>1)
        ans -= ans/n;
    return ans;
}
ll modinverse(ll x,ll m)//O(logn)
{
    ll temp = eulerstotientfunction(m);
    return modpow(x,temp-1,m);
}
ll ncr(ll n,ll k)
{
    ll res = 1;
    k = min(k,n-k);
    for(ll i=0;i<k;i++)
    {
        res *= (n-i);
        res /= (i+1);
    }
    return res;
}
int main()
{
    //fastio();
    ll t=1;
    //cin >> t;
    while(t--)
    {
        ll n;
        cin >> n;
        std::vector<ll> a(n),b(n),c(n);
        ll co = 0;
        for(ll i=0;i<n;i++) cin >> a[i];
        for(ll i=0;i<n;i++) cin >> b[i];
        for(ll i=0;i<n-1;i++) cin >> c[i];
        for(ll i=0;i<n;i++)
        {
            co+=b[a[i]-1];
            if(i<n-1 && a[i+1]==a[i]+1)
                co+=c[a[i]-1];
        }
        cout << co << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int pos;
int main() {
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) if(a[i]==pos+1) pos++;
	if(pos==0) cout<<-1;
	else cout<<n-pos;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

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

long long lcm(long long a, long long b){
	return (a*b) / gcd(a, b);
}

int main(){
	long long a, b, c, d;
	long long ans;
	cin >> a >> b >> c >> d;
	a--;
	ans = (b - (b / c) - (b / d) + (b / lcm(c, d)) - (a - (a / c) - (a / d) + (a / lcm(c, d))));
	cout << ans << endl;

	return 0;
}

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

def prime_check(x):
    for i in range(2,x):
        if x%i==0:
            return False
    return True
ans=[]
for i in range(11,55555,10):
    if prime_check(i):
        ans.append(i)
        n-=1
    if n==0:
        break


print(*ans)


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        string a = Console.ReadLine();
        if (a.Length < 4) { Console.WriteLine("No"); }
        else if (a.Substring(0, 4) == "YAKI") { Console.WriteLine("Yes"); }
        else { Console.WriteLine("No"); }
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b)
    {
        return a / gcd(a, b) * b;
    }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;

        for (long i = 2; i < n; i++)
        {
            if (n % i == 0) return false;
        }
        return true;
    }

}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] longs()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
    public static int Int()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] ints()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {
	
	static int m = 1000003;
	static int[] T = new int[m];
	
	static int changeToInt(char c) {
		if(c == 'A') {
			return 1;
		}else if(c == 'C') {
			return 2;
		}else if(c == 'G') {
			return 3;
		}else {
			return 4;
		}
	}
	
	static int getKey(String str) {
		int sum = 0;
		int d = 1;
		int l = str.length();
		for(int i=0;i<l;i++) {
			d *= 5;
			char c = str.charAt(i);
			sum += d * changeToInt(c);
		}
		return sum;
	}
	
	static int h1(int key) {
		return key%m;
	}
	
	static int h2(int key) {
		return 1+(key%(m-1));
	}
	
	static int h(int key,int i) {
		return (h1(key) + i*h2(key)) %m;
	}
	
	static void insert(int key) {
		int i=0;
		boolean flag = true;
		while(flag) {
			int j = h(key,i);
			if(T[j] == 0) {
				T[j] = key;
				flag = false;
			}else {
				i += 1;
			}
		}
	}
	
	static void search(int key) {
		int i=0;
		boolean flag = true;
		while(flag) {
			int j = h(key,i);
			if(T[j] == key) {
				System.out.println("yes");
				flag = false;
			}else if(T[j] == 0 || i>=m) {
				System.out.println("no");
				flag = false;
			}else {
				i += 1;
			}
		}
	}
	
	void main() {
		for(int i=0;i<m;i++) {
			T[i] = 0;
		}
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0;i<n;i++) {
			String s = sc.next();
			String str = sc.next();
			//System.out.println(s +" "+ str);
			int key = getKey(str);
			//System.out.println(key);
			if(s.equals("insert")) {
				insert(key);
			}else {
				search(key);
			}
		}
		
	}

	public static void main(String[] args) {
		new Main().main();
	}

}



Measured memory_bytes: 225836
import math
n = int(input())
p = [int(i) for i in input().split(' ')]
q = [int(i) for i in input().split(' ')]


def orders(l, n):
    ini = 0
    s = [int (i) for i in range(1, n+1)]#1 2 3 4 5
    for number in l:
        order = s.index(number)#数字の大きさ-1
        s.remove(number)
        l_num = math.factorial(len(s)) * order#桁数-1! * 大きさ-1
        ini = ini + l_num
    return ini

p_place = orders(p, n)
q_place = orders(q,n)

result = abs(p_place - q_place)
print(result)

Measured memory_bytes: 3064
#include <math.h>
#include <iostream>

int main()
{
	int A, B, C, D, T, K;
	std::cin >> A >> B >> C >> D;
	T = ceil((double)A / (double)D);
	K = ceil((double)C / (double)B);
	if (T < K) {
		std::cout << "No";
	}
	else {
		std::cout << "Yes";
	}
}

Measured memory_bytes: 3628
def main():
    import sys
    input = sys.stdin.readline

    N = input().rstrip('\n')
    L = len(N)
    K = int(input())

    dp0 = [[0] * (K+1) for _ in range(L+1)]
    dp1 = [[0] * (K+1) for _ in range(L+1)]
    dp0[0][0] = 1
    for i in range(L):
        for k in range(K+1):
            m = int(N[i])
            if m == 0:
                dp0[i+1][k] += dp0[i][k]
                dp1[i+1][k] += dp1[i][k]
            else:
                dp1[i+1][k] += dp0[i][k] + dp1[i][k]
            if k+1 <= K:
                if m != 0:
                    dp0[i+1][k+1] += dp0[i][k]
                    dp1[i+1][k+1] += dp0[i][k] * (m-1) + dp1[i][k] * 9
                else:
                    dp1[i + 1][k + 1] += dp1[i][k] * 9
    print(dp0[-1][-1] + dp1[-1][-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
bool sortbysec(const tuple<int, int, int> &a,
               const tuple<int, int, int> &b)
{
    return (get<1>(a) < get<1>(b));
}

int main()
{
    int n;
    cin >> n;
    if (n % 1000 != 0)
        cout << (1000 - n % 1000);
    else
    {
        cout << "0";
    }
}

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

int main(){
    string s; cin>>s;
    int n = s.size();
    bool ok = 1;
    
    for(int i=0;i<n;i++){
        if(s[i]!=s[n-i-1])ok=0;
    }
    
    if(!ok){
        cout<<"No"<<endl;
        return 0;
    }
    
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n/2-1-i])ok=0;
    }
    
    if(!ok){
        cout<<"No"<<endl;
        return 0;
    }
    
    cout<<"Yes"<<endl;
    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    if(a+b==15){
        cout << '+' << endl;
    }
    else if(a*b==15){
        cout << '*' << endl;
    }
    else{
        cout << 'x' << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
int m;
cin>>m;
int ans=0,d,c,ans2=0,t=0;
for(int i=0;i<m;i++){
    
    cin>>d>>c;
    ans+=d*c;
    ans2+=c;
    
}
cout<<ans2-1+(ans-1)/9;

return 0;
}


Measured memory_bytes: 256
//Chandigarh University
//author:- shivamkr21
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=13)
    {
        cout<<b;
    }
    else if(a>=6 && a<=12)
    {
        cout<<b/2;
    }
    else if(a<=5)
    {
        cout<<0;
    }
    return 0;
}


Measured memory_bytes: 256
number = list(map(int,input().split()))
score = list(map(int,input().split()))
score.sort()
answer = 0
if number[1] > number [0]:
    number[1] = number[0]
for i in range(number[1]):
    score[number[0]-1-i] = 0
for j in range(number[0]):
    answer += score[j]
print(answer)

Measured memory_bytes: 105184
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        
        if (a == 0) {
            System.out.println(a);
            return;
        }
        if (n - (a + b) >= 0) {
            // 数える数がボール投入数より多い場合
            long c = n / (a + b);
            long d = n % (a + b);
            if (d - a > 0) {
                System.out.println((c * a) + a);
            } else {
                System.out.println((c * a) + d);
            }
        } else {
            // 数える数がボール投入数より少ない場合
            if (n - a >= 0) {
                System.out.println(a);
            } else {
                System.out.println(n);
            }

        }
        sc.close();
    }
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
int b[25],a[25];
int main()
{
    int n,m,c;
    cin>>n>>m>>c;
    for(int i=0;i<m;i++)
        cin>>b[i];
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
            cin>>a[j];
        int nam=0;
        for(int j=0;j<m;j++)
            nam+=a[j]*b[j];
        if(nam+c>0)
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stack>
#include<iostream>
#include<vector>
#include<map>
#include<unordered_map>
#include<string>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(int) (n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
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; }
using namespace std;
int main(){
int k;
string s;
cin >> k >> s;
if(k<s.size()) cout << s.substr(0,k) << "..." << endl;
else cout << s << endl;
return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(void){
    std::deque<char> deq1;
    std::deque<char> deq2;
    std::deque<char> deq3;
    string s;
    while(cin>>s) {
        if (s=="0") {
            break;
        } else {
            for (int i=0;i<3;i++) {
                deq1.emplace_back(s.at(i));
            }
            cin>>s;
            for (int j=0;j<3;j++) {
                deq2.emplace_back(s.at(j));
            }
            cin>>s;
            for (int k=0;k<3;k++) {
                deq3.emplace_back(s.at(k));
            }
            if (deq1[0]==deq2[0]&&deq2[0]==deq3[0]&&deq1[0]!='+'&&deq2[0]!='+'&&deq3[0]!='+') {
                cout<<deq1[0]<<endl;
            } else if (deq1[1]==deq2[1]&&deq2[1]==deq3[1]&&deq1[1]!='+'&&deq2[1]!='+'&&deq3[1]!='+') {
                cout<<deq1[1]<<endl;
            } else if (deq1[2]==deq2[2]&&deq2[2]==deq3[2]&&deq1[2]!='+'&&deq2[2]!='+'&&deq3[2]!='+') {
                cout<<deq1[2]<<endl;
            } else if (deq1[0]==deq1[1]&&deq1[1]==deq1[2]&&deq1[0]!='+'&&deq1[1]!='+'&&deq1[2]!='+') {
                cout<<deq1[0]<<endl;
            } else if (deq2[0]==deq2[1]&&deq2[1]==deq2[2]&&deq2[0]!='+'&&deq2[1]!='+'&&deq2[2]!='+') {
                cout<<deq2[0]<<endl;
            } else if (deq3[0]==deq3[1]&&deq3[1]==deq3[2]&&deq3[0]!='+'&&deq3[1]!='+'&&deq3[2]!='+') {
                cout<<deq3[0]<<endl;
            } else if (deq1[0]==deq2[1]&&deq2[1]==deq3[2]&&deq1[0]!='+'&&deq2[1]!='+'&&deq3[2]!='+') {
                cout<<deq1[0]<<endl;
            } else if (deq1[2]==deq2[1]&&deq2[1]==deq3[0]&&deq1[2]!='+'&&deq2[1]!='+'&&deq3[0]!='+') {
                cout<<deq1[2]<<endl;
            } else {
                cout<<"NA"<<endl;
            }
            deq1.clear();
            deq2.clear();
            deq3.clear();
        }
    }
}



Measured memory_bytes: 3176
def is_okay(A, B, C):
    sum = 0
    for i in range(len(B)):
        sum = sum + A[i] * B[i]

    return sum + C > 0

N, M, C = map(int, input().split())
B = tuple(map(int, input().split()))

answer = 0
for _ in range(N):
    A = tuple(map(int, input().split()))
    answer = answer + is_okay(A, B, C)

print(answer)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// 二項係数計算
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  int s;cin>>s;
  int n;n=s/3;
  ll cnt=0;
  int rest;
  for (int i=1;i<=n;i++) {
    rest = s - 3*i;
    cnt = (cnt + COM(rest+i-1, i-1)) % MOD;
  }
  cout<<cnt<<endl;
  
}


Measured memory_bytes: 15584
main(a,b,i,x,y){char map[104][104];for(;scanf("%d%d",&a,&b),a+b;){for(b=x=y=0;a-b;)scanf("%s",map[b++]);for(;map[x][y]-46?i=map[a=x][b=y]:0;map[a][b]=0)i>93?i>95?x++:x--:i<63?y+=i-61:1;map[x][y]?printf("%d %d\n",y,x):puts("LOOP");}}

Measured memory_bytes: 624
fn main() {
    let v = read_vec::<u32>();
    let a = v[0];
    let b = v[1];
    let c = v[2];
    yn((a == b && a != c) || (b == c && b != a) || (a == c && a != b))
}

#[allow(dead_code)]
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()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main(){
  ll n,w;cin >> n >> w;
  vector<ll> dp(w+1);
  vector<ll> we(n);
  vector<ll> v(n);
  for(ll i=0;i<n;i++) cin >> we[i] >> v[i];

  for(ll i=0;i<n;i++){
    for(ll j=w-we[i];j>=0;j--){
      dp[j+we[i]] = max(dp[j+we[i]],dp[j]+v[i]);
    }
  }
  ll ans = INT_MIN;
  for(ll i=0;i<=w;i++){
    ans = max(ans,dp[i]);
  }
  cout << ans << endl;
  cin.get();cin.get();
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

using namespace std;
using ll = long long;

const int MAX_N = 1e5+1;
int par[MAX_N];
int treesize[MAX_N];

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

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

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

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    else {
        treesize[y] += treesize[x];
        par[x] = y;
        return;
    }
}

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

    init(n);

    int a[m],b[m];
    int c[k],d[k];
    int kouho[n+1] = {};
    int friendnum[n+1] = {};
    int blocknum[n+1] = {};

    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        unite(a[i],b[i]);
        friendnum[a[i]]++;
        friendnum[b[i]]++;
    }

    for(int i=0;i<=n;i++){
        kouho[i] = treesize[find(i)] - 1;
    }

    for(int i=0;i<k;i++){
        cin>>c[i]>>d[i];
        if(same(find(c[i]),find(d[i]))){
            blocknum[c[i]]++;
            blocknum[d[i]]++;
        }
    }

    for(int i=1;i<=n;i++){
        cout<<kouho[i] - friendnum[i] - blocknum[i]<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 4992
//Wrong answer on test inf.
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
#define y1 y1___
using namespace std;
char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
ll read(){
	char ch=gc();ll x=0;int op=1;
	for (;!isdigit(ch);ch=gc()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=gc()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
int len,ans;char op[5];
int init(){
    int k=10;
    for(int i=1;i<=9;i++){
        printf("? %lld\n",k);
        fflush(stdout);
        scanf("%s",op);
        if(op[0]=='N') return i;
        k=k*10;
    }
    k=9;
    for(int i=1;i<=9;i++){
        printf("? %lld\n",k);
        fflush(stdout);
        scanf("%s",op);
        if(op[0]=='Y') return i;
        k=k*10+9;
    }
    return 10;
}
int main(){
	int len=init();
    if(len==10)
    {
        printf("! %d\n",(int)1e9);
        return 0;
    }
	int ans=0;
    for(int i=1;i<len;i++)
    {
        int l=0,r=9,t=0;
        while(l<=r)
        {
            int mid=(l+r)/2;
            printf("? %d\n",ans*10+mid);
            fflush(stdout);
            scanf("%s",op);
            if(op[0]=='Y')
            {
                t=max(t,mid);
                l=mid+1;
            }
            else
                r=mid-1;
        }
        ans=ans*10+t;
    }
    for(int i=(len==1?1:0);i<=9;i++)
    {
        printf("? %lld\n",((ll)ans*10+i)*10);
        fflush(stdout);
        scanf("%s",op);
        if(op[0]=='Y')
        {
            ans=ans*10+i;
            break;
        }
    }
    printf("! %d\n",ans);
	return 0;
}

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

using namespace std;

const int INF = 1e9 + 5;

int n, m, l;
pair<int, int> dist[305][305];
vector<pair<int, int> > edge[305];

struct dat {
	int id;
	pair <int, int> v;
	bool operator < (const dat& T) const {
		return v > T.v;
	}
};

void dijk(int s) {
	dist[s][s] = make_pair(0, 0);
	priority_queue<dat> pq;
	pq.push({s, make_pair(0, 0)});	
	
	while (pq.size()) {
		dat tmp = pq.top();
		pq.pop();
		
		if (dist[s][tmp.id] < tmp.v) continue;
		
		dist[s][tmp.id] = tmp.v;
		
		for (int i = 0; i < edge[tmp.id].size(); i++) {
			int to = edge[tmp.id][i].first;
			int cost = edge[tmp.id][i].second;
			
			pair <int, int> tmpv = tmp.v;
			if (tmpv.second + cost <= l) tmpv.second += cost;
			else {
				tmpv.first++;
				tmpv.second = cost;
			}
			
			if (dist[s][to] > tmpv) {
				dist[s][to] = tmpv;
				pq.push({to, tmpv});
			}
		}
	}
}

int main() {
	scanf("%d%d%d", &n, &m, &l);
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) dist[i][j] = make_pair(INF, INF);
	}
	
	for (int i = 0; i < m; i++) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		x--;
		y--;
		if (z > l) continue;
		edge[x].push_back({y, z});
		edge[y].push_back({x, z});
	}
	
	for (int i = 0; i < n; i++) {
		dijk(i);
	}
	
	int q;
	scanf("%d", &q);
	
	while (q--) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;
		if (dist[x][y].first == INF) printf("-1\n");
		else printf("%d\n", dist[x][y].first);
	}
}


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

int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        int a;
        cin >> a;
        cout << "Case " << i << ":" << endl;
        for(int j=0;j<10;j++){
            a *= a;
            a = a/100;
            int tmp = a/10000*10000;
            a = a-tmp;
            cout << a << endl; 
        }
    }
    return 0;
}

Measured memory_bytes: 1160
# YouTube解説
N = int(input())
A = [int(a) for a in input().split()]

for n in range(N):
  A[n] -= (n+1)

A.sort()
b = A[len(A) // 2]

ans = 0
for n in range(N):
  ans += abs(A[n] - b)

print(ans)

Measured memory_bytes: 26020
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t,c,m;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++) cin>>arr[i];
    ll ans=LLONG_MAX;
    for(i=0;i<n;i++)
    {
        ll sum1=0,sum2=0;
        for(j=0;j<i;j++) sum1+=arr[j];
        for(j=i;j<n;j++) sum2+=arr[j];
        ans=min(abs(sum1-sum2),ans);
    }
    cout<<ans;
}

Measured memory_bytes: 3544
N, Q = map(int, input().split())
s = input()
ac_cum_list = []
ac_cum = 0
ex_a = False
for c in s:
    if ex_a and c == "C":
        ac_cum += 1
    if c == "A":
        ex_a = True
    else:
        ex_a = False
    ac_cum_list.append(ac_cum)

for i in range(Q):
    l, r = map(int, input().split())
    print(ac_cum_list[r - 1] - ac_cum_list[l - 1])

Measured memory_bytes: 6152
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        String S = sc.next();
        sc.close();
        int n = S.length();

        for(int i = 0; i <= n ; i++){
            for(int j = i; j <= n; j++){
                String sub1 = S.substring(0, i);
                String sub2 = S.substring(j, n);
                if((sub1+sub2).equals("keyence")){
                    System.out.println("YES");
                    return;
                }
            }
        }
        System.out.println("NO");
    }
}

Measured memory_bytes: 22736
import sys
input=sys.stdin.readline

S = input().rstrip()
T = input().rstrip()
DP = [[0]*(len(T)+1) for i in range(len(S)+1)]
for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            DP[i+1][j+1] = DP[i][j]+1
        else:
            DP[i+1][j+1] = max(DP[i+1][j],DP[i][j+1])

m,n = len(S),len(T)
ans = ''
while m>0 and n>0:
    if DP[m][n] == DP[m][n-1]:
        n-=1
    elif DP[m][n] == DP[m-1][n]:
        m -= 1
    else:
        m,n = m-1,n-1
        ans = T[n]+ans
print(ans)

Measured memory_bytes: 112220
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <math.h>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <utility>
#include <vector>
#include <stdio.h>
#include <numeric>
#include <array>

using namespace std;

#define REP(i, from, to) for (long long int i = (from); i < (to); i++)
#define REV(v) for (auto itr = v.rbegin(); itr != v.rend(); itr++)
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort(ALL(v));
#define LAST(v) v[v.size() - 1]
#define ZERO(a) memset(a, 0, sizeof(a));
#define MINUS(a) memset(a, -1, sizeof(a));
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define IIN(a) \
    int a;     \
    cin >> a;
#define LIN(a) \
    ll a;      \
    cin >> a;
#define SIN(a) \
    string a;  \
    cin >> a;
#define EPS (1e-10)
#define INF 1000000000000LL

typedef long long ll;
typedef unsigned long long ull;

void YN(bool b) { cout << (b ? "YES" : "NO") << "\n"; }
void Yn(bool b) { cout << (b ? "Yes" : "No") << "\n"; }
void yn(bool b) { cout << (b ? "yes" : "no") << "\n"; }

template <class S>
S max(vector<S> &a) { return *max_element(all(a)); }
template <class S>
S min(vector<S> &a) { return *min_element(all(a)); }

template <class T>
void puta(T &&t) { cout << t << "\n"; }
template <class H, class... T>
void puta(H &&h, T &&... t)
{
    cout << h << ' ';
    puta(t...);
}

template <typename ELEMENT_TYPE>
struct _setfillw
{
    ELEMENT_TYPE c;
    std::streamsize w;
    _setfillw(ELEMENT_TYPE c, std::streamsize w) : w(w), c(c) {}
};

template <typename ELEMENT_TYPE>
inline _setfillw<ELEMENT_TYPE> setfillw(ELEMENT_TYPE c, std::streamsize w)
{
    return _setfillw<ELEMENT_TYPE>(c, w);
}

template <typename ELEMENT_TYPE>
inline std::ostream &operator<<(std::ostream &os, const _setfillw<ELEMENT_TYPE> &manip)
{
    return os << std::setw(manip.w) << std::setfill(manip.c);
}

bool length_cmp(string &a, string &b)
{
    return a.size() < b.size();
}

ll StoLL(string s)
{
    ll num = 0;
    REP(i, 0, s.size())
    {
        num = num * 10 + (s[i] ^ 48);
    }
    return num;
}

ll CtoLL(char c)
{
    if ('a' <= c && c <= 'z')
    {
        return (ll)(c ^ 96);
    }
    else if ('A' <= c && c <= 'Z')
    {
        return (ll)(c ^ 64);
    }
    return 0;
}

const ll MAX = 1e9;
const ll MOD = 1000000007;
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    LIN(n) LIN(k) 
    vector<ll> a(1000000);
    REP( i, 0, n){
        cin >> a[i];
    }
    if( n == 1 ){
        puta( 1 );
        return 0;
    }
    puta( ceil(( double ) ( n - k ) / ( k - 1 ) ) + 1  );
    return 0;
}


Measured memory_bytes: 8064