akhauriyash/Code-Regression huggingface dataset:
import java.awt.geom.*;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

import javax.naming.BinaryRefAddr;

public class Main {
	int k, ans;
	boolean [] used;
	
	private void dfs(int deep){
		if(deep == k){
			ans++;
		}
		
		for(int i = 0 ; i <k; i++){
			if(deep == i) continue;
			if(used[i] ) continue;
			used[i] = true;
			dfs(deep + 1);
			used[i] = false;
		}
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String []  s = sc.next().split("[\\+=]");
			BigInteger [] b = new BigInteger[s.length];
			boolean flg = true;
			for(int num = 0; num <= 9; num++){
				if(num == 0){
					boolean f = true;
					for(int i = 0 ; i < s.length; i++){
						if(s[i].length() > 1 && s[i].charAt(0) == 'X'){
							f = false;
							break;
						}
					}
					if(! f) continue;
				}
				
				for(int i = 0 ; i < s.length;i++){
					b[i] = new BigInteger(s[i].replaceAll("X", num + ""));
				}
				if(b[2].compareTo(b[1].add(b[0])) == 0){
					System.out.println(num);
					flg = false;
					break;
				}
			}
			if(flg){
				System.out.println("NA");
			}
		}
	}
	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 13000
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <memory>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <string>
#include <unordered_map>
#include <iomanip>
#include <sstream>  
#include <deque>
#include <unordered_set>
#include <stack>
#include <functional>

using namespace std;


//#define int long long


signed main() {

    string s;
    cin >> s;
    int k;
    cin >> k;
    vector <string> v;
    for (int len = 1; len <= (min(int(s.size()), 6)); ++len) {
        for (int i = 0; i < int(s.size()) - len + 1; ++i) {
            v.push_back(s.substr(i, len));
        }
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    cout << v[k - 1] << endl;
}

Measured memory_bytes: 1916
import java.util.*;
import java.io.*;
import java.util.Collections;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        List<Integer> h = new ArrayList<>();
        for(int i=0; i<n; i++)
        {
            int g= sc.nextInt();
            h.add(g);
        }
        Collections.sort(h);
        int count=0;
        for(int s: h){
            if (s>=k)
            {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 60200
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
int main()
{
	
	int n,m;
	cin>>n>>m;
	ll fact[100005];
	fact[0]=1,fact[1]=1;
	for(int i=1;i<=100004;i++)
	{
		fact[i]=(fact[i-1]*i)%mod;
	}
	if((m>=n-1&&m<=n+1)||(n>=m-1&&n<=m+1))
	{
		ll res;
		if(n>m)
		{
			res=((fact[n]*fact[m])%mod)%mod;
		}
		else if(m>n)
		{
			res=((fact[m]*fact[n])%mod);
		}
		else 
		{
			res=2*(fact[m]*fact[n])%mod;
		}
		cout<<res;
	}
	else cout<<0;
}
	

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//累乗法
ll mod_pow(ll x,ll n,ll mod=1e18+7){
	ll res=1;
	while(n){
		if(n&1) (res*=x)%=mod;
		(x*=x)%=mod;
		n>>=1;
	}
	return res;
}

int main(void){
	ll n,m;
	cin>>n>>m;
	cout<<mod_pow(n,m,1e9+7)<<endl;
	return 0;
}


Measured memory_bytes: 3108
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll A,B,C; cin >> A >> B >> C;
    res = C - min(A-B,C);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.sort()
B.sort()
import bisect
ans=1
mod=10**9+7
start=0
if len(set(A))!=len(A) or len(set(B))!=len(B):
    ans=0
if A[-1]<N*M or B[-1]<N*M:
    ans=0
for k in range(N*M,0,-1):
    if ans==0:break
    Aidx=bisect.bisect_left(A,k)
    Bidx=bisect.bisect_left(B,k)
    if A[Aidx]==k and B[Bidx]==k:
        continue
    elif A[Aidx]==k:
        ans=(ans*(M-Bidx))%mod
    elif B[Bidx]==k:
        ans=(ans*(N-Aidx))%mod
    else:
        if (N-Aidx)*(M-Bidx)-(N*M-k)<=0:
            ans=0
        ans=(ans*((N-Aidx)*(M-Bidx)-(N*M-k)))%mod
    if Aidx==0 and Bidx==0:
        start=k
        break
for i in range(start-1,0,-1):
    ans=(ans*i)%mod
print(ans)

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int N, K, R, S, P;
int f(char t) {
	switch (t) {
	case 'r':
		return P;
	case 's':
		return R;
	case 'p':
		return S;
	}
}

int main()
{

	cin >> N >> K >> R >> S >> P;

	string T;
	cin >> T;

	int ans = 0;
	fx(N) {
		if (x<K) {
			ans += f(T[x]);
		}
		else {
			if (T[x]!=T[x-K]) {
				ans += f(T[x]);
			}
		}
	}
	bool flags[100000] = { false, };
	fx(N) {
		if (flags[x]) { continue; }
		//flags[x] = true;

		int i = 0;
		int sum = 0;
		while (x + K * i<N && T[x]==T[x+K*i]) {
			flags[x + K * i] = true;
			i++;
			sum++;
		}
		ans += f(T[x]) * ((sum-1) / 2);
	}
	ce(ans)

    return 0;
}



Measured memory_bytes: 512
#include <stdio.h>
long long s[100005];
int f(int low,int high,int key)  
{  
    if(low<=high)  
    {  
        int mid=(low+high)/2;  
        if(key==s[mid])
        return mid;  
        else if(key<s[mid]&&key>s[mid-1])  
        return mid-1;  
        else if(key<s[mid])  
        return f(low,mid-1,key);  
        else if(key>s[mid])  
        return f(mid+1,high,key);  
    }  
    else  
    return -1;  
}  
int main()
{
	int i,k=0,n;
	for(i=1;i<40005;i++)
	s[k++]=i*i;
	//for(i=1;i<40005;i++)
	//printf("%d**\n",s[i]);
	while(scanf("%d",&n)!=EOF)
	{
		if(n==1)
		printf("1\n");
		else
		printf("%lld\n",s[f(1,40005,n)]);
	}
} 

Measured memory_bytes: 512
from itertools import product


def read():
    N = int(input())
    happiness = list()
    for i in range(N):
        a, b, c = list(map(int, input().split()))
        happiness.append([a, b, c])
    return N, happiness

def solve(N, happiness):
    dp = [[0 for j in range(3)] for i in range(N+1)]
    for i, j in product(range(N), range(3)):
        dp[i+1][j] = max(dp[i][(j+1)%3], dp[i][(j+2)%3]) + happiness[i][j]
    return max(dp[N])

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


Measured memory_bytes: 48480
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        Strategy strategy = new MyStrategy();
        strategy.solve(out, sc);
        out.flush();
    }
}

class MyStrategy implements Strategy {
    @Override
    public void solve(PrintWriter out, FastScanner sc) {
        int M1 = sc.nextInt();
        int D1 = sc.nextInt();
        int M2 = sc.nextInt();
        int D2 = sc.nextInt();
        if(M1 == M2) {
            out.println(0);
        } else {
            out.println(1);
        }
    }
}

interface Strategy {
    void solve(PrintWriter out, FastScanner sc);
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}


using namespace std;


int main() {
	make2(n, m);
	if (n > m) swap(n, m);
	if (n == 1 && m == 1) {
		printf("1\n");
		return 0;
	}
	if (n == 1) {
		printf("%d\n", m-2);
		return 0;
	}
	lint ans = (n-2)*1LL*(m-2);
	printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int N;
    N = 0;
  	scanf("%d", &N);
    int V[N];
  	int C[N];
  int i;
  	int j;
  for(i=0;i<N;i++){
        scanf("%d", &V[i]);
    }
   for(j=0;j<N;j++){
        scanf("%d", &C[j]);
    }
  int count = 0;
  for(i=0;i<N;i++){
	if(V[i] -C[i] > 0){
      count  = count + (V[i] -C[i]);
    }
  }
  printf("%d", count);
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back

int N,K;
int ans=0;
signed main(){
    scanf("%lld %lld",&N,&K);
    if(K>1)ans=N-K;
    else ans=0;
    printf("%lld\n",ans);
}

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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    string s;
    cin >> n >> s >> k;
    char c = s[k - 1];
    REP(i, n)if(s[i] != c) s[i] = '*';
    cout << s << ln;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

    int a,b,c;
    cin >> a >> b >> c;
    int x = 0;

    if((a != b) && (a != c) && (b == c))
        x = 1;
    if((b != a) && (b != c) && (a == c))
        x = 1;
    if((c != a) && (c != b) && (b == a))
        x = 1;

    

    if(x){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

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

int main(){
    long L,R;
    cin >> L >> R;
    long ans = 2019;
    if(R - L + 1 >= 2019){
        cout << 0 << endl;
    }else{
        for(long i = L;i <= R - 1;i++){
            for(long j = i + 1;j <= R;j++){
                ans = min(ans,i * j % 2019);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int main(){
	ll n,m;
	cin>>n>>m;
	cout<<(n*(n-1)/2)+(m*(m-1)/2)<<endl;
	return 0;
}

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

using namespace std;

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

	bool flag = false;
	int size = s.size();
	sort(s.begin(), s.end());


	for (int i = 1; i < size; i++) {
		if (s[i] == s[i - 1]) {
			flag = true;
		}
	}

	if (flag) cout << "no" << endl;
	else cout << "yes" << endl;
}

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

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


// std::vector Declaration
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
   return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// std::vector Initialization
template<typename T>
void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U>
void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
   os << "[";
   bool a = 1;
   for (auto e : v ) {
      os << (a ? "" : " "); 
      os << e;
      a = 0;
   }
   os << "]";
   return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
   os << "(" << p.first << " " << p.second << ")";
   return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
   os << "{";
   bool a = 1;
   for (auto e : st) {
      os << (a ? "" : " ");
      os << e;
      a = 0;
   }
   os << "}";
   return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
   os << "{";
   bool a = 1;
   for (auto e : mp) {
      os << (a ? "" : " ");
      os << e.first << ":" << e.second;
      a = 0;
   }
   os << "}";
   return os;
}

// std::tuple Debug
template<int N,class Tuple>
void out(ostream &os,const Tuple &t){}
template<int N,class Tuple,class H,class ...Ts>
void out(ostream &os,const Tuple &t){
   if(N)os<<" ";
   os<<get<N>(t);
   out<N+1,Tuple,Ts...>(os,t);
}
template<class ...Ts>
ostream& operator<<(ostream &os, const tuple<Ts...> &t){
   os<<"(";
   out<0,tuple<Ts...>,Ts...>(os,t);
   os<<")";
   return os;
}

// Debug
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

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

   vector<int> a(n+1), b(n+1);

   for (int i = 0; i < n; ++i) {
      a[i+1] = a[i] + (s[i] == '#' ? 1 : 0);
      b[i+1] = b[i] + (s[n-1-i] == '.' ? 1 : 0);
   }

   int ans = n;
   for (int i = 0; i < n+1; ++i) {
      chmin(ans, a[i] + b[n-i]);
   }
   cout << ans << endl;


   return 0;
}


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

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

	long double h = x / a / a;

	if (0 <= 2 * h - b)
	{
		cout << fixed << setprecision(20) << asin(2 * (b - h) / sqrt(a * a + (2 * (b - h)) * (2 * (b - h)))) * 180 / acos(-1) << endl;
	}
	else
	{
		cout << fixed << setprecision(20) << asin(b / sqrt(b * b + (2 * x) * (2 * x) / ((a * b) * (a * b)))) * 180 / acos(-1) << endl;
	}

	return 0;
}

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

for i in range(n):
    if a[i] != n:
        x += b[a[i] - 1]
        if i != n -1:
            if a[i + 1] == a[i] + 1:
                x += c[a[i] - 1]
        
    else:
        x += b[a[i] - 1]


print(x)

Measured memory_bytes: 9120
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int N, M;
V<V<int>> v;

V<int> memo;
V<int> vis;
void dfs(int ni) {
    if(vis[ni]) return;
    vis[ni] = 1;
    REP(i,v[ni].size()) {
        dfs(v[ni][i]);
    }
}

int main(){
    INIT;
    cin >> N >> M;
    v.resize(N+1);
    memo.resize(N+1);
    REP(i,M) {
        int x, y, z;
        cin >> x >> y >> z;
        memo[x]++; memo[y]++;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    vis.resize(N+1,0);
    int cnt0 = 0, cnt1 = 0;
    FOR(i,1,N+1) {
        if(vis[i] == 0) {
            cnt1++;
            dfs(i);
        }
    }
    cout << cnt0+cnt1 << "\n";
}

Measured memory_bytes: 8448
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    string t;
    cin >> t;
    /*ector <int> dp(2, -1e9);
    if (t[0] == 'D')
        dp[1] = 1;
    if (t[0] == 'P')
        dp[0] = 0;
    if (t[0] == '?') {
        dp[0] = 0;
        dp[1] = 1;
    }
    forn (i, 1, sz(t)) {
        vector <int> new_dp(2, -1e9);
        if (t[i] == 'D' || t[i] == '?')
            chkmax(new_dp[1], max(dp[0] + 1, dp[1] + 1));
        if (t[i] == 'P' || t[i] == '?')
            chkmax(new_dp[0], max(dp[0], dp[1] + 1));
        dp = new_dp;
    }
    cout << *max_element(all(dp));*/
    forn (i, 0, sz(t)) {
        if (t[i] == '?')
            t[i] = 'D';
        cout << t[i];
    }
    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(auto _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa

using namespace std;

void f (int x) {
  cout << x;
}

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string s; cin >> s;
  if (s == "RRR") f(3);
  else if (s.substr(0, 2) == "RR" || s.substr(1, 3) == "RR") f(2);
  else if (s != "SSS") f(1);
  else f(0);
  return 0;
}

Measured memory_bytes: 3636
N,M=map(int,input().split())
LL=[]
LR=[]
for i in range(M):
    LLR=list(map(int,input().split()))
    LL.append(LLR[0])
    LR.append(LLR[1])
ans=max(min(LR)-max(LL)+1,0)
print(ans)

Measured memory_bytes: 11068
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  vector<ll> P(A),Q(B),R(C);
  rep(i,A) cin>>P[i];
  rep(i,B) cin>>Q[i];
  rep(i,C) cin>>R[i];

  sort(P.rbegin(),P.rend());
  sort(Q.rbegin(),Q.rend());
  sort(R.rbegin(),R.rend());

  priority_queue<ll,vector<ll>,greater<ll>> PQ;
  rep(i,B) PQ.push(Q[i]);

  int st=0;
  int pos=C-1;
  ll sum=0;
  rep(i,B) sum+=Q[i];
  if(X<=C){
    for(int i=X;i<C;i++){
      PQ.push(R[i]);
      sum+=R[i];
    }
    st=0;pos=X-1;
  }else{
    st=X-C;pos=C-1;
  }

  while(PQ.size()>Y){
    sum-=PQ.top();
    PQ.pop();
  }

  ll sa=0;
  for(int i=0;i<min(X,st);i++) sa+=P[i];
  ll sc=0;
  for(int i=0;i<X-st;i++) sc+=R[i];
  ll ans=0;
  for(int i=st;i<=X;i++){
    ll res=sa+sum+sc;
    chmax(ans,res);

    if(pos>=0){
      PQ.push(R[pos]);
      sum+=R[pos];
      sc-=R[pos];
      pos--;
      sum-=PQ.top();
      PQ.pop();
    }
    if(i<X) sa+=P[i];
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 4852
#include<iostream>
#include<algorithm>
#include<stack>
#include<vector>

using namespace std;

int N;
vector<int> A;

stack<int> s;
stack<int> rst;

int main() {
  cin >> N;
  for (int i = 0, a; i < N; i++) {
    cin >> a;
    A.push_back(a);
  }

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

  for (int i = 0; i < N; i++) {
    s.push(A[i]);
  }


  int tmp1 = -1, tmp2 = -1;
  while (!s.empty()) {
    if (tmp1 < 1) {
      tmp1 = s.top();
      s.pop();
      if (s.empty() || tmp1 != s.top()) {
        rst.push(tmp1);
        tmp1 = -1;
      } else if (!s.empty()) {
        s.pop();
      }
    } else if (tmp2 < 1) {
      tmp2 = s.top();
      s.pop();
    } else {
      if (tmp1 == tmp2 || tmp2 == s.top()) {
        s.push(tmp1);
        tmp1 = -1;
        tmp2 = -1;
      } else {
        rst.push(tmp2);
        tmp2 = -1;
      }
    }
//    cout << tmp1 << " " << tmp2 << endl;
  }

  if (tmp1 > 0 && tmp2 > 0) {
    rst.push(tmp1);
  } else if (tmp1 > 0) {
    rst.pop();
    rst.push(tmp1);
  } 

//  while (!rst.empty()) {
//    cout << rst.top() << endl;
//    rst.pop();
//  }
  cout << rst.size() << endl;

  return 0;
}


Measured memory_bytes: 1020
# -*- coding: utf-8 -*-
n = int(input())
a = input().split()
b = [a[0], []]
last = b[1]

for i in range(1,n):
    if i%2==0:
        last.append(a[i])
        last.append([])
        last = last[1]
    else:
        b = [a[i],b]

ret = []
for _ in range(n):
    ret.append(b[0])
    b = b[1]

if n%2==0:
    print(" ".join(ret))
else:

    print(" ".join(ret[::-1]))


Measured memory_bytes: 38564
#E
inf = float("inf")
N,W = map(int,input().split())
WV = [list(map(int,input().split())) for _ in range(N)]

dp = [[inf for j in range(10**5+1)] for i in range(N+1)] #dp[i][v] = W

for i in range(N):
    dp[i][0] = 0

for i in range(N):
    w,v = WV[i]
    for j in range(10**5+1):
        if j+v <= 10**5:
            dp[i+1][j+v] = min(dp[i][j]+w,dp[i][j+v])
        dp[i+1][j] = min(dp[i][j],dp[i+1][j])

#print(dp)
ans = 0
for j in range(10**5+1):
    w = dp[N][j]
    if w <= W:
        ans = j
        
print(ans)


Measured memory_bytes: 403896
//esAeñ²ÆÉª¯Äl¦é
//Åå³ª¶Ý·éA©ÂÅ¬pXí¢ª2Èº©Ç¤©ð»è·êÎÇ¢

#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAX_W = 1009;
const int INF = 1<<29;
int H, W;

const int MAX_V = 2003;
int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];
 
void add_edge(int u, int v){G[v].push_back(u);G[u].push_back(v);}
bool dfs(int v){used[v] = true;for(int i=0; i<G[v].size(); i++){int u = G[v][i], w = match[u];if(w<0 || !used[w] && dfs(w)){match[v] = u;match[u] = v;return true;}}return false;}
int bipartite_matching(){int ret = 0;memset(match, -1, sizeof(match));for(int v=0; v<V; v++)if(match[v] < 0){memset(used, 0, sizeof(used));if(dfs(v)) ret++;}return ret;}

bool graph[MAX_W][MAX_W];

int nums[MAX_W][MAX_W];
int tmp[MAX_W][MAX_W];
vector<int> X[MAX_W];

//A > B©Ç¤©
bool cmp_v(const vector<int>& a, const vector<int>& b){

	for(int i=0; i<W; i++){
		if(a[i] < b[i]) return false;
	}

	return true;
}

bool solve(){
	for(int i=0; i<H; i++){
		X[i].clear();
	}

	int maxi = -1, key = -1;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(maxi < nums[i][j]){
				maxi = nums[i][j];
				key = i;
			}
		}
	}

	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			X[i].push_back(nums[i][j]);
		}
	}

	vector<int> best_vec = X[key];

	sort(X, X+H);
	reverse(X, X+H);

	for(int j=1; j<H; j++){
		if( !cmp_v(X[0], X[j]) ){
			return false;
		}
	}

	//DAGðÂ­é
	V = 2*H;
	for(int i=0; i<V; i++){
		G[i].clear();
	}
	
	memset(graph, 0, sizeof(graph));
	for(int i=H-1; i>=0; i--){
		for(int j=i+1; j<H; j++)if( !graph[i][j] ){
			if( cmp_v(X[i], X[j]) ){
				graph[i][j] = true;
				add_edge(i, j+H);
				for(int k=0; k<H; k++){
					graph[i][k] |= graph[j][k];
				}
			}
		}
	}

	if(best_vec != X[0]){
		return false;
	}

	return (H - bipartite_matching()) <= 2;
}

bool sub_solve(){

	if(!solve()){
		return false;
	}

	//swap
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			tmp[j][i] = nums[i][j];
		}
	}

	swap(H, W);
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			nums[i][j] = tmp[i][j];
		}
	}

	return solve();

}

int main(){

	scanf("%d%d",&H, &W);
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			scanf("%d", nums[i]+j);
		}
	}

	bool ans = sub_solve();

	puts(ans?"YES":"NO");

	return 0;
}

Measured memory_bytes: 13000
import collections
N = int(input())
A = list(map(int, input().split()))
a = collections.Counter(A)
ans = [0, 0]
for i in a.keys():
    if a[i] >= 2:
        ans.append(i)
    if a[i] >= 4:
        ans.append(i)
ans.sort()
print(ans[-1]*ans[-2])

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

int main(){
    double n,ans;
    //vector<int> h(n);
    cin >> n;
    cout << pow(n,3) << endl;
    return 0;
}


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


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

Measured memory_bytes: 3072
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif 


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


    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    vl A(X); REP(i, X) cin >> A[i];
    vl B(Y); REP(i, Y) cin >> B[i];
    vl C(Z); REP(i, Z) cin >> C[i];
    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());
    sort(C.begin(), C.end(), greater<ll>());

    vl ab;
    REP(i,X) {
        REP(j,Y) {
            ab.push_back(A[i] + B[j]);
        }
    }    
    sort(ab.begin(), ab.end(), greater<ll>());

    vl ans;
    REP(i, min((int)ab.size(), K)) {
        REP(j,Z) {
            ans.push_back(ab[i] + C[j]);
        }
    }

    sort(ans.begin(), ans.end(), greater<ll>());
    REP(i,K) cout << ans[i] << endl;    

    return 0;
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const ll base = 10007;
const ll mod = (1ll << 52) - 1;

bool mt[12][5005]; // match
bool dp[1 << 12][5005]; // dp...

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	// dp state: 0/i = 1 always as starting state
	rep(i, 0, 5005) dp[0][i] = 1;

	for (;;) {
		int n, m; cin >> n >> m; if (!n && !m) break;
		vector<string> elem(n);
		rep(i, 0, n) cin >> elem[i];
		string buf;
		rep(i, 0, m) { string s; cin >> s; buf += s; }
		// pad buf
		m = buf.size(); buf = " " + buf;
		// calculate each match
		rep(h, 0, n) rep(i, 1, m + 1) mt[h][i] = buf.substr(i, elem[h].size()) == elem[h]; 
		// reset dp from *1*
		rep(i, 1, (1 << n)) rep(j, 0, m + 2) dp[i][j] = 0;
		// start dp
		rep(i, 1, m + 1) rep(j, 0, (1 << n) - 1) rep(k, 0, n)
			if (dp[j][i] && mt[k][i] && !(j & (1 << k))) {
				//cout << "mark " << bitset<3>(j) << "->" << bitset<3>(j | (1 << k)) << ", " << i << "->" << (i + elem[k].size()) << endl;
				dp[j | (1 << k)][i + elem[k].size()] = 1;
			}
		// calc
		int a = 0;
		rep(i, 1, m + 2) if (dp[(1 << n) - 1][i]) a++;
		cout << a << endl;
		// test
		/*
		rep(i, 1, m + 1) {
			rep(j, 0, n) if (mt[j][i]) printf("Matches elem %d at %d\n", j, i);
		}
		*/
	}
}



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

int main() {
    int y=1;
    string s;
    cin>>s;
    int i=0;
    while (s[i]!=0) {
        if(s.compare(i,5,"dream")==0){
            if(s.compare(i+5,2,"er")==0&&s.compare(i+7,3,"ase")!=0){
                i+=2;
            }
            i+=5;
        }else if(s.compare(i,5,"erase")==0){
            if(s.compare(i+5,1,"r")==0){
                i++;
            }
            i+=5;
        }else{
            cout<<"NO\n";
            y=0;
            break;
        }
    }
    if(y)
        cout<<"YES\n";    
    return 0;
}


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

// 配列の出力
void trace(int A[], int n) {
  for (int i=0; i<n; i++) {
    if (i != n-1) {
      cout << A[i] << " ";  
    } else {
      cout << A[i] << endl;
    }
  }
}

// 挿入ソート(0オリジン配列)
void insertionSort(int A[], int n) {
  for (int i=1; i<n; i++) {
    int v = A[i];
    int j = i-1;
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A, n);
  }
}

int main() {
  int n;
  cin >> n;
  int A[n];
  for (int i=0; i<n; i++) cin >> A[i];

  trace(A, n);
  insertionSort(A, n);

  return 0;
}


Measured memory_bytes: 3080
#include<iostream>

using namespace std;

int main(void) {
	bool flg[30];
	int in;
	int i;

	for(i = 0; i < 30; i++) { flg[i] = true; }
	for(i = 0; i < 28; i++) {
		cin >> in;
		flg[in - 1] = false;
	}
	for(i = 0; i < 30; i++) {
		if(flg[i]) { cout << i + 1 << endl; }
	}

	return 0;
}

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

using namespace std;

typedef long long ll;

const int MAX_N = 2005;

int n, a[MAX_N], order[MAX_N];
ll dp[MAX_N][MAX_N];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	iota(order + 1, order + n + 1, 1);
	sort(order + 1, order + n + 1, [&](int i, int j) {
		return a[i] > a[j];
	});
	for (int k = 1; k <= n; ++k) {
		int i = order[k];
		for (int l = 1; l <= k; ++l) {
			int r = n - (k - l);
			dp[k][l + 1] = max(dp[k][l + 1], dp[k - 1][l] + 1ll * a[i] * abs(i - l));
			dp[k][l] = max(dp[k][l], dp[k - 1][l] + 1ll * a[i] * abs(i - r));
		}
	}
	ll ans = 0;
	for (int l = 1; l <= n + 1; ++l) {
		ans = max(ans, dp[n][l]);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 26236
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

using System.IO;

class _Class
{
	
	void _Do()
  { 
    //
    var NCK = _int();
    var N = NCK[0];
    var C = NCK[1];
    var K = NCK[2];
    var a = new List<int>();
    for(int i=0; i<N;i++)
    {
      a.Add(_int()[0]);
    }
    a.Sort();

    int b = 0;
    int? sento = null;
    int kyaku = 0;
    for (int i = 0; i < N; i++)
    {
      if (sento == null)
      {
        sento = a[i];
        kyaku = 1;
        if (C == 1)
        {
          b++;
          sento = null;
          kyaku = 0;
        }
      }
      else if (a[i] - sento > K)
      {
        b++;
        sento = a[i];
        kyaku = 1;
        if (C == 1)
        {
          b++;
          sento = null;
          kyaku = 0;
        }
      }
      else if (kyaku+1 == C)
      {
        b++;
        sento = null;
        kyaku = 0;
      }
      else
      {
        kyaku++;
      }

 
    }
    if (kyaku>0)
      b++;
    Console.WriteLine(b);
	}



	static void Main(string[] args)
  {
    new _Class()._Do();
  }

#region

  string _string()
  {
    return Console.ReadLine();
  }

	//
	string[] _strings()
  {
    return Console.ReadLine().Split();
  }

  int[] _int(int n)
  {
    var x = new int[n];
    for (var i = 0; i < n; i++)
    {
      x[i] = int.Parse(Console.ReadLine());
    }
    return x;
  }

	//
	int[] _int()
  {
    var ss = Console.ReadLine().Split();

    var x = new int[ss.Length];
    for (var i = 0; i < ss.Length; i++)
      x[i] = int.Parse(ss[i]);

    return x;
  }

	long[] _long()
	{
		var ss = Console.ReadLine().Split();

		var x = new long[ss.Length];
		for (var i = 0; i < ss.Length; i++)
			x[i] = long.Parse(ss[i]);

		return x;
	}
#endregion

}


Measured memory_bytes: 17312
// 連結成分
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>
#include<stack>

using namespace std;

#define MAX_N 100000

// 値の定義
const int INV = -1;

// 友達関係を保持するための構造体
typedef struct
{
    // 友達関係の個数
    int relation_num;
    // 関係を格納するための vector 配列
    vector<int> v_relation;
}st_Relation;

// 友達関係を保持する配列
st_Relation ary_Link[MAX_N + 1];

// 連結情報を保持する配列
int ary_connection[MAX_N + 1];

void search_relation(int u_ID, int id, int user_num);

int main(void)
{
    int n, m, q, s, t;

    for(int i = 0; i < MAX_N + 1; i++)
    {
        // 配列の初期化
        ary_Link[i].relation_num = 0;
        ary_connection[i] = INV;
    }

    cin >> n >> m;

    for(int i = 0; i < m; i++)
    {
        cin >> s >> t;

        // 友達関係を双方向に設定する
        ary_Link[s].relation_num++;
        ary_Link[s].v_relation.push_back(t);

        ary_Link[t].relation_num++;
        ary_Link[t].v_relation.push_back(s);
    }

    int id = 1;

    for(int u = 0; u < n; u++)
    {
        if( ary_connection[u] == INV )
        {
            // 友達関係の検索を実施
            search_relation(u, id++, n);
        }
    }

    cin >> q;

    for(int i = 0; i < q; i++)
    {
        cin >> s >> t;

        if( ary_connection[s] == ary_connection[t] )
        {
            // 友達関係が存在するなら, 同じ値になる
            printf("yes\n");
        }
        else
        {
            printf("no\n");
        }
    }

    return 0;
}

// 友達関係を検索するための関数
// u_ID : 友達関係を検索する最初のユーザーID
// id   : ary_connection[]に設定する, 関係を区別するためのID値
// user_num : 全ユーザー数
void search_relation(int u_ID, int id, int user_num)
{

    int user_id;

    queue<int> Q;

    // 開始点をキューにプッシュする
    Q.push(u_ID);
    // 友達関係を保存する
    ary_connection[u_ID] = id;

    while( !Q.empty() )
    {
        // キューの先頭要素を取得して, 削除する
        // ( 一人のユーザーの巡回は1回だけ )
        int u = Q.front();
        Q.pop();

        for(int v = 0; v < ary_Link[u].relation_num; v++)
        {
            // 友達関係にあるユーザーの検索
            user_id = ary_Link[u].v_relation[v];

            if( ary_connection[user_id] == INV )
            {
                // ----- 繋がっている頂点が見つかった -----

                // 友達関係を保存する
                ary_connection[user_id] = id;

                // キューにプッシュして, 検索を継続する
                Q.push(user_id);
            }
        }
    }

    return;
}



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

int main(){
	int n,q;
	int taskTime=0;
	
	cin>>n>>q;
	queue< pair<string, int> > set;
	
	for(int i=0;i<n;i++){
		string name;int time;
		cin>>name>>time;
		set.push(make_pair(name, time));
	}
	
	while(!set.empty()){
		int tmpT;
		tmpT=set.front().second-q;
		if(tmpT<=0){
			taskTime += q+tmpT;
			cout<<set.front().first<<" "<<taskTime<<endl;
			set.pop();
		}else{
			taskTime += q;
			set.front().second=tmpT;
			set.push(set.front());
			set.pop();
		}
	}
	
	return 0;
}

Measured memory_bytes: 4404
from collections import Counter

def get_prime_factors(x):
    out = []
    if x < 1:
        return out
    while not x%2:
        out.append(2)
        x //= 2
    i = 3
    while i*i <= x:
        if not x%i:
            out.append(i)
            x //= i
        else:
            i += 2
    if x != 1:
        out.append(x)
    return out

def main():
    n = int(input())
    primes = Counter(get_prime_factors(n))
    ans = 0
    for prime, num in primes.items():
        i = 1
        while num >= i:
            ans += 1
            num -= i
            i += 1
    print(ans)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 9344
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,sum,cnt;
int a[100010];
int b[100010];
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],sum+=a[i];
	sum/=2;
	for(int i=1;i<=n;i+=2)cnt+=a[i];
	b[1]=2*(cnt-sum);
	for(int i=2;i<=n;i++)b[i]=2*(a[i-1]-b[i-1]/2);
	for(int i=1;i<=n;i++)cout<<b[i]<<' ';
	puts("");
	return 0;
}


Measured memory_bytes: 2816
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 12 22:49:54 2020

@author: liang
"""

""" 
【小さいものから探索　⇒　キューを用いる】
【幅優先探索の応用】
     10 + 1 + 1
1 => 10 + 1 + 0
     10 + 1 - 1

10 => 100 + 0 + 1
      100 + 0 + 0
      100 + 0 - 1 *
"""

from collections import deque

K = int(input())

q = deque()
for i in range(1,10):
    q.append(i)
    
cnt = 0
while cnt  != K:
    cnt += 1
    ans = q.popleft()
    #print(ans)
    if ans % 10 != 0:
        q.append(10*ans + ans%10 - 1)
    q.append(10*ans + ans%10 )
    if ans % 10 != 9:
        q.append(10*ans + ans%10 + 1)
print(ans)

Measured memory_bytes: 18900
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CRally {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<int> X(N);
        REP(i, N) {
            cin >> X[i];
        }
        int res = INF;
        FOR(mid, 1, 100) {
            int tmp = 0;
            REP(i, N) {
                tmp += (mid - X[i]) * (mid - X[i]);
            }
            res = min(tmp, res);
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CRally solver;
    solver.solve(in, out);
    return 0;
}


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

int N, res;
vector<pair<int, int> > v;
vector<int> L, R;

int main()
{
	scanf("%d", &N);
	for(int i=0; i<N; i++)
	{
		int l, r;
		scanf("%d %d", &l, &r);
		v.push_back({l, 1});
		v.push_back({r+1, -1});
		L.push_back(l); R.push_back(r);
	}
	v.push_back({(int)1e9+1, 0});
	sort(v.begin(), v.end());
	sort(L.begin(), L.end());
	sort(R.begin(), R.end());

	if (N%2)
	{
		int m = 0, u = N, d = 0;
		for(int i=0; i+1<v.size(); i++)
		{
			if (v[i].second == 1) u--, m++;
			else if (v[i].second == -1) m--, d++;

			int sz = v[i+1].first-v[i].first;
			if (m >= 1 && ((u < d && u+(m-1) >= d) || (u > d && u-(m-1) <= d) || (u == d)))
			{
				res += sz;
			}
		}
	}
	else
	{
		vector<pair<int, int> > w;
		int m = 0, u = N, d = 0;
		for(int i=0; i+1<v.size(); i++)
		{
			if (v[i].second == 1) u--, m++;
			else if (v[i].second == -1) m--, d++;

			if ((u < d && u+m >= d) || (u > d && u-m <= d) || (u == d))
			{
				int sz = (R[N/2-1]+R[N/2]) - (L[N/2-1]+L[N/2]) + 1;
				w.push_back({L[N/2-1]+L[N/2], 1});
				w.push_back({R[N/2-1]+R[N/2]+1, -1});
			}
		}
		sort(w.begin(), w.end());
		int cnt = 0;
		for(int i=0; i+1<w.size(); i++)
		{
			if (w[i].second == 1) cnt++;
			else cnt--;
			int sz = w[i+1].first-w[i].first;
			//printf("[%d, %d]\n", w[i].first, w[i+1].first);
			if (cnt) res += sz;
		}
	}
	printf("%d", res);
	return 0;
}

Measured memory_bytes: 15624
def extgcd(a, b)
    x, y = 1, 0
    g, e = 1, 0
    while b != 0
        q, r = a/b, a%b
        m = x-q*e
        n = y-q*g
        a, b = b, r
        x, e = e, m
        y, g = g, n
    end
    return [x, y, g]
end

a, b = gets.chomp.split.map(&:to_i)
x, y, g = extgcd(a, b)

puts( [x, y].join(" ") )




Measured memory_bytes: 8884
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
struct ti{
long n;
double t;
} tti;
bool operator<(const ti& l,const ti& r){return l.t<r.t;}
int main(){
long f,i;
vector<ti> vt,vt2;
for(i=0;i<8;i++){cin>>tti.n>>tti.t;vt.push_back(tti);}
sort(vt.begin(),vt.end());
for(f=0,i=0;i<8;i++){
if(f<2){printf("%d %.2f\n",vt[i].n,vt[i].t);f++;}
else vt2.push_back(vt[i]);
}
vt.clear();
for(i=0;i<8;i++){cin>>tti.n>>tti.t;vt.push_back(tti);}
sort(vt.begin(),vt.end());
for(f=0,i=0;i<8;i++){
if(f<2){printf("%d %.2f\n",vt[i].n,vt[i].t);f++;}
else vt2.push_back(vt[i]);
}
vt.clear();
for(i=0;i<8;i++){cin>>tti.n>>tti.t;vt.push_back(tti);}
sort(vt.begin(),vt.end());
for(f=0,i=0;i<8;i++){
if(f<2){printf("%d %.2f\n",vt[i].n,vt[i].t);f++;}
else vt2.push_back(vt[i]);
}
sort(vt2.begin(),vt2.end());
for(f=0,i=0;i<18;i++){
if(f<2){printf("%d %.2f\n",vt2[i].n,vt2[i].t);f++;}
}
return 0;
}

Measured memory_bytes: 1268