akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	static int [] namber = new int[200];
	public static int[] syokika(int[]namber){
		for(int i = 0; i < namber.length; i++){
			namber[i] = 0;
		}
		return namber;
	}
	public static int[][] hantei(int[][]array, int n, int j){
		int count = 1;
		namber = syokika(namber);
		for(int k = 1; k < n; k++) {
			for(int i = k + 1; i <= n; i++) {
				if(array[k][j] == array[i][j]) {
					namber[count] = array[k][j];
					count++;
				}
			}
		}
        for(int k = 1; k < namber.length;k++){
            for(int i = 1; i <= n; i++) {
            	if(namber[k] == array[i][j]){
            		array[i][j] = 0;
                }
            }
        }
         return array;
	}
 
    public static void main(String[] args) {
        Scanner sc = new Scanner (System.in);
        int n = sc.nextInt();
        int [][] array = new int [n+1][4];
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= 3; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        for(int j = 1; j <= 3; j++){
        	array = hantei(array, n , j);
        }
        for(int i = 1; i <= n; i++) {
            int answer = 0;
            for(int j = 1; j <= 3; j++) {
                answer += array[i][j];
            }
            System.out.println(answer);
        }
    }
}

Measured memory_bytes: 20808
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


alias Tuple!(int, "to", BigInt, "cost") Node;
Node[][] edges;

immutable BigInt INF = "10000000000000000000000000000000000000000000000000000000000000000000".to!BigInt;


BigInt bellman_ford(int N, int s) {
    auto dist = new BigInt[](N);
    fill(dist, INF);
    dist[s] = 0;
    foreach (i; 0..N) {
        foreach (v; 0..N) {
            foreach (k; 0..edges[v].length) {
                int to = edges[v][k].to;
                BigInt cost = edges[v][k].cost;
                if (dist[v] != INF && dist[to] > dist[v] + cost) {
                    dist[to] = dist[v] + cost;
                    if (i == N - 1) dist[to] = -INF;
                }
            }
        }
    }

    return -dist[N-1];
}


void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    edges = new Node[][](N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        int a = s[0] - 1;
        int b = s[1] - 1;
        BigInt c = s[2].to!BigInt;
        edges[a] ~= Node(b, -c);
    }

    BigInt ans = bellman_ford(N, 0);
    writeln(ans == INF || ans == -INF ? "inf" : ans.to!string);
}


Measured memory_bytes: 8916
//
// ~oisín~ C++ Template
//

#include                <bits/stdc++.h>
#define MX_N            5001
#define INF             100000000
#define mod7            1000000007
#define modpi           314159
#define pb              push_back
#define FastIO          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define All(a)          a.begin(),a.end()
#define fi              first
#define se              second
#define ll              long long int
#define ull             unsigned long long int

int kx[8]  =            {+2, +2, -2, -2, +1, +1, -1, -1};
int ky[8]  =            {+1, -1, +1, -1, +2, -2, +2, -2};
int d9x[9] =            {+1, +1, +1, +0, +0, +0, -1, -1, -1};
int d9y[9] =            {+1, +0, -1, +1, +0, -1, +1, +0, -1};
int dx4[4] =            {+0, +0, +1, -1};
int dy4[4] =            {+1, -1, +0, +0};

ll gcd(ull a, ull b){
    return (a==0)?b:gcd(b%a,a);
}

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

using namespace std;

int main(){
    string alph = "abcdefghijklmnopqrstuvwxyz";
    string bad = alph;
    reverse(bad.begin(), bad.end());
    string s;
    cin >> s;
    if(s==bad){
        cout << "-1\n";
        return 0;
    }
    bool b[26];
    memset(b, 0, sizeof(b));
    for(char c : s)
        b[(int)c-(int)'a'] = 1;
    for(int i=0;i<26;++i)
        if(!b[i]){
            s += (char)(i+(int)'a');
            cout << s << endl;
            return 0;
        }
    string v = s;
    next_permutation(v.begin(), v.end());
    for(int i=0;i<v.size();++i){
        if(v[i] != s[i]){
            cout << v[i] << endl;
            return 0;
        }else{
            cout << v[i];
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a[1000000],b[1000000],i,j;
    for(i=0;i<200;i++){
        cin>>a[i]>>b[i];
        if(a[i]+b[i]<=0){
            break;
        }
        if(a[i]+b[i]<10){
            cout<<"1"<<endl;
        }
        else if(a[i]+b[i]<100){
            cout<<"2"<<endl;
        }
        else if(a[i]+b[i]<1000){
            cout<<"3"<<endl;
        }
        else if(a[i]+b[i]<10000){
            cout<<"4"<<endl;
        }
        else if(a[i]+b[i]<100000){
            cout<<"5"<<endl;
        }
        else if(a[i]+b[i]<1000000){
            cout<<"6"<<endl;
        }
        else if(a[i]+b[i]<=1999999){
            cout<<"7"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3104
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>
#include <array>

using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mn(x) *min_element((x).begin(),(x).end())
#define mx(x) *max_element((x).begin(),(x).end())
//#define sum(x) accumulate((x).begin(),(x).end(),0ll)
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ld pi=acos(-1);
const ll inf=(ll)1e9+1;
const int mod=1000000007;
//const int mod=998244353;

int n,m,k;
const int N=1e3+10;





int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int q,t,u,v,h;
    ll x,a,b,c,d,y,z;
    cin >> n;
    vll vv(n+1), sm(n+1);
    for(int i=1; i<=n; i++){
        cin >> vv[i];
        sm[i]=vv[i]+sm[i-1];
        sm[i]%=mod;
    }
    a=0;
    for(int i=1; i<n; i++){
        a+=vv[i]*(sm[n]-sm[i]+mod);
        a%=mod;
    }
    cout << a << el;
    
    return 0;
}







Measured memory_bytes: 6364
n = int(input())
info = []
for _ in range(n):
    temp = [int(x) for x in input().split( )]
    info.append(temp)
state = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for a in info:
    state[a[0]-1][a[1]-1][a[2]-1] += a[3]
for b in range(4):
    for f in range(3):
        string = ''
        for k in range(10):
            string += ' ' + str(state[b][f][k])
        print(string)
    if b < 3:
        print('#'*20)



Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repbtw(i, a, b) for (int i = a; i <= (int)(b); i++)
#define all(v) v.begin(), v.end()
#define pr(x) cout << x << endl


int main()
{
    int k;
    string s;
    cin >> k >> s;
    if(s.size() <= k) pr(s);
    else{
        pr(s.substr(0, k) + "...");
    }
    return 0;
}



Measured memory_bytes: 3552
/*
 *  author : Atul Anand   
 *  created on : Wed Apr 01 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int K = in.nextInt();
        int X = in.nextInt();
        if(K * 500 >= X){
            println("Yes");
        }
        else{
            println("No");
        }
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

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

int main(int argc, char* argv[]){
    int n;
    int tmp, sum;
    vector<int> s;

    while(true) {
        cin >> n;
        if(n == 0) return 0;
        sum = 0;
        s.clear();
        for(int i = 0; i < n; i++) {
            cin >> tmp;
            s.push_back(tmp);
        }

        sort(s.begin(), s.end());
        for(int i = 1; i < n-1; i++){
            sum += s[i];
        }
        cout << floor(sum * 1.0 / (n-2)) << endl;
    }
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  long ans=0;
  for(int i =1 ; i<=N; i++){
    if(i%3!=0 && i%5 != 0) ans= ans +i; 
  }
 cout << ans << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(a+b>c+d)puts("Left");
  if(a+b==c+d)puts("Balanced");
  if(a+b<c+d)puts("Right");
  return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

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

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

int dp[4002][4002],q[4002][4002],cmb[4001][4001];
const int mod=1000000007;

int main(){
	FOR(i,0,4001)
		FOR(j,0,4001)
			cmb[i][j]=(i&&j)?(cmb[i][j-1]+cmb[i-1][j])%mod:1;
	int n=read(),ans=0;
	REP(i,n){
		int a=read(),b=read();
		q[a+2000][b+2000]++;
		dp[-a+2000][-b+2000]++;
		ans-=cmb[a*2][b*2];
		if(ans<0)
			ans+=mod;
	}
	REP(i,4001)
		REP(j,4001){
			dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
			dp[i][j+1]=(dp[i][j+1]+dp[i][j])%mod;
			ans=((ll)dp[i][j]*q[i][j]+ans)%mod;
		}
	printf("%lld\n",(ll)ans*(mod+1)/2%mod);
}

Measured memory_bytes: 148608
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define int long long
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define bitcnt(n) __builtin_popcountll(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c , s , e ) for(int pos=s; pos<e ; pos++)cout << c[pos] << " ";
#define PI acos(-1)
const int M = 1000000007;
const int N=3e5 + 7;

#ifdef LOCAL
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__)
#endif

void solve(){
    int i , j , n ;

}
signed main()
{
    int tc , i ,j;
    int n;
    cin >> n;
    int sum=0;
    for(i=1 ; i<=n ; i++)
    {
        for(j=1 ; j<=n ; j++)
        {
            for(int k=1 ; k<=n ; k++){
                sum+=__gcd(__gcd(i , j ) , k);
            }
        }

    }
    cout << sum << endl;

}

Measured memory_bytes: 3632
from collections import defaultdict
import queue

def dfs(P,V,s,cnt):
    V[s] = 1
    # print(V)
    # 全部辿ったらインクリメント
    if len(V) == sum(V):
        cnt += 1
        # print('count',str(cnt))

    for t in P[s]:
        if V[t] > 0:
            continue
        # print(s,t)
        V,cnt = dfs(P,V,t,cnt)
    V[s] = 0
    return V,cnt

def main():
    N,M = [int(x) for x in input().split()]
    paths = []
    for _ in range(M):
        a,b = [int(x) for x in input().split()]
        paths.append((a,b))

    # 隣接リスト
    P = defaultdict(list)
    for a,b in paths:
        P[a-1].append(b-1)
        P[b-1].append(a-1)

    V = [0]*N
    s = 0
    cnt = 0
    # print(P)
    V,cnt = dfs(P,V,s,cnt)
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42968
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main() {
    long int n;
    cin >> n;
    long int min = 0xfffffffff;
    long int c,counter = 0;
    for (long int i = 0; i < n; i++)
    {
        cin >> c;
        if (c < min)
        {
            counter++;
            min = c;
        }
        
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
ans=10**10
if H>2:
    S=[(H//3),((H-H//3)//2),H-(H//3)-((H-H//3)//2)]
    ans=min(ans,max(S)*W-min(S)*W)
if W>2:
    S=[(W//3),((W-W//3)//2),W-(W//3)-((W-W//3)//2)]
    ans=min(ans,max(S)*H-min(S)*H)
for w in range(1,W):
    S=[w*H,(W-w)*(H//2),(W-w)*(H-H//2)]
    ans=min(ans,max(S)-min(S))
for h in range(1,H):
    S=[h*W,(H-h)*(W//2),(H-h)*(W-W//2)]
    ans=min(ans,max(S)-min(S))
print(ans)


Measured memory_bytes: 41180
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int l=s.size(), count=0;
  for(int i=0;i<l/2;i++){
  if(s[i]!=s[l-i-1])
    count++;
  }
  cout<<count<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvl vector<vector<long long>>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define vpli vector<pair<long long, int>>
#define vs vector<string>
#define deb(x) cout << x << endl;
#define all(x) x.begin(), x.end()
const int MOD = 1e9+7;

void add(int &a,int b)
{
    a = a+b;
    if(a>MOD)
        a-=MOD;
}

void solve()
{
    //dp[i][j] = number of length i string with i-1 inequalities satisfied with number at index i = j.
    int n;
    string s;
    cin>>n>>s;
    vvi dp(n+1,vi(n+1,0));
    dp[1][1] = 1;
    int L,R;
    for(int len=2;len<=n;len++)
    {
        vi pref(n+1,0);
        for(int i=1;i<=n;i++)
        {
            pref[i] = (pref[i-1]+dp[len-1][i])%MOD;
        }
        for(int numberAtEnd = 1;numberAtEnd<=len;numberAtEnd++)
        {
            if(s[len-2] == '<')
            {
                L=1;
                R=numberAtEnd-1;
            }
            else   // s[len-2] == '>'
            {
                L=numberAtEnd;
                R=len-1;
            }
            if(L<=R)
            {
                add(dp[len][numberAtEnd],(pref[R]-pref[L-1]+MOD)%MOD);
            }
        }
    }
    int  ans = 0;
    for(int i=1;i<=n;i++)
    {
        add(ans,dp[n][i]);
    }
    cout<<ans;
}

int main()
{
    int t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 38520
import java.util.*;
import java.io.*;
import java.math.BigInteger;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        if(N >= 1000) {
            N -= 999;
            System.out.printf("ABD\n");
        } else {
            System.out.printf("ABC\n");
        }





    }
}

Measured memory_bytes: 21844
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n,m;
    while(cin>>n>>m,n+m){
        vector<vector<pii>>d(m+1,vector<pii>(m+1,pii(INF,INF)));
        for(int i=0;i<m;i++)d[i][i]=pii(0,0);
        rep(i,n){
            int a = 0,b = 0;pii hoge; cin>>a>>b>>hoge.first>>hoge.second;
            --a,--b;
            d[a][b]=hoge;
            d[b][a]=hoge;
        }
        rep(k,m)rep(i,m)rep(j,m)cmin(d[i][j].first,d[i][k].first+d[k][j].first);
        rep(k,m)rep(i,m)rep(j,m)cmin(d[i][j].second,d[i][k].second+d[k][j].second);
        int k; cin>>k;
        rep(i,k){
            int to,from,q; cin>>to>>from>>q;
            to--,from--;
            if(q)cout<<d[to][from].second<<endl;
            else cout<<d[to][from].first<<endl;
        }
    }
}

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

int main() {
  int N, K;
  cin >> N >> K;

  int middle = K / 2;
  int distance = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;

    if (x <= middle) {
      distance += x * 2;
    } else {
      distance += (K - x) * 2;
    }
  }

  cout << distance << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof a) ;
#define vi vector<int>
#define ull unsigned long long
#define ll long long 
#define db double 
#define fl float
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lrep(i,a,b) for(ll i=a;i<b;i++)
#define mod 1000000007
#define mpr make_pair
#define pb push_back
#define fr first
#define sn second
#define bpp(x) __builtin_popcountll(x)
/*
double squareRoot(long long number, int precision) 
{ 
    long long start = 0, end = number; 
    long long mid; 
    double ans; 
    while (start <= end) { 
        mid = (start + end) / 2; 
        if (mid * mid == number) { 
            ans = mid; 
            break; 
        }  
        if (mid * mid < number) { 
            start = mid + 1; 
            ans = mid; 
        } 
        else { 
            end = mid - 1; 
        } 
    } 
    double increment = 0.1; 
    for (long long i = 0; i < precision; i++) { 
        while (ans * ans <= number) { 
            ans += increment; 
        } 
        ans = ans - increment; 
        increment = increment / 10; 
    } 
    return ans; 
} 
*/
bool ispalin(string str)
{
	int i = 0, j = str.length() - 1;
	while (i < j)
	{
		if (str[i] != str[j]) return false;
		i++, j--;
	}
	return true;
}
void solve()
{
int n; cin>>n;
int a[n];
int sum=0,ans=0,as=0;
for(int i=0;i<n;i++)
{ cin>>a[i]; sum+=a[i]; }
//cout<<sum<<"\n";
sum/=n;
for(int i=0;i<n;i++)
{
ans+=(sum-a[i])*(sum-a[i]);
as+=(sum-a[i]+1)*(sum-a[i]+1);
}
//cout<<min()<<"\n";
cout<<min(as,ans); return;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t =1;
	//cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
# define ll long long
int n,arr[100005],ans[100005],k;
vector <ll> v={100000000};
int calc(int i)
{
    if(ans[i]!=-1)
        return ans[i];
    if(i==n-1)
        return 0;
    int aa=INT_MAX;
    for(int j=i+1;j<=i+k;j++)
    {
        int x=abs(arr[i]-arr[j]);
        int z2=10000000;
        if(j<n)
        {
            z2=calc(j);
        }
        aa=min(x+z2,aa);
    }
    ans[i]=aa;
    return aa;

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    cin>>n>>k;
    //int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    memset(ans,-1,sizeof(ans));

    int sum=calc(0);
    cout<<sum;
    //code goes here
	return 0;
}



Measured memory_bytes: 5760
import scala.math._
import scala.annotation._
import scala.collection._
import scala.collection.{mutable => mut}
import scala.util.control.Breaks.{breakable,break}

object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)

    val n, m = sc.nextInt

    var xs = (1 to m).toSet
    (0 until n).foreach { i =>
      val k = sc.nextInt
      xs = xs intersect List.fill(k)(sc.nextInt).toSet
    }

    println(xs.size)
  }
}

Measured memory_bytes: 29628
N = int(input().strip())
A = [int(i) for i in input().strip().split(" ")]

count = 1
prev = A[0]
up = False
down = False
for a in A[1:]:
    if prev < a:
        if up:
            count += 1
            up = False
        elif down:
            pass
        else: # 初回
            down = True
    elif prev > a:
        if up:
           pass
        elif down:
            count += 1
            down = False
        else: # 初回
            up = True
    else:
        pass
    prev = a

print(count)


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

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

    for(int i = 0; i < a; i++){
        if(!('0' <= s[i] && s[i] <= '9')){
            cout << "No" <<endl;
            return 0;
        }
    }
    if(s[a] != '-'){
        cout << "No" << endl;
        return 0;
    }
    for(int i = a + 1; i <= a + b; i++){
        if(!('0' <= s[i] && s[i] <= '9')){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# n,m = map(int,sys.stdin.readline().split())
# a = list(map(int,sys.stdin.readline().split()))
# a = [sys.stdin.readline() for _ in range(n)]
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
import sys,bisect
sys.setrecursionlimit(15000)

n = int(sys.stdin.readline())
a = [sys.stdin.readline() for _ in range(n)]

import collections
c = collections.Counter(a)
print(len(c))


Measured memory_bytes: 38620
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    cin>>N;
    queue<string> que;
    que.push("a");
    while(true){
        string s = que.front();
        if(s.size() == N) break;
        que.pop();
        char m = 'a';
        for(char c : s) m = max(c, m);
        int t = m - 'a';
        rep(i,t + 2) que.push(s + char('a' + i));
        //cout<<s + char('a')<<endl;
    }
    vector<string> ans(0);
    while(!que.empty()){
        ans.push_back(que.front());
        que.pop();
    }
    sort(ALL(ans));
    for(string a : ans) cout<<a<<endl;
}

Measured memory_bytes: 10744
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,m;cin>>n>>m;
    if(n==m)cout<<"Yes"<<endl;
    else cout<<"No"<<Endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 896
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define INF (1<<29)
using namespace std;
typedef long long ll;
int main(){
      int p[100];
      int n;
      cin>>n;
      memset(p,0,sizeof(p));
      REP(i,n*(n-1)/2){
            int a,b,c,d;
            cin>>a>>b>>c>>d;a--;b--;
            if(c>d)p[a]+=3;
            else if(d>c)p[b]+=3;
            else{
                  p[a]++;
                  p[b]++;
            }
      }
      int r[100];
      int k=1;
      for(int i=300;i>=0;i--){
            int cnt=0;
            REP(j,n){
                  if(p[j]==i)cnt++;
            }
            if(cnt==0)continue;
            REP(j,n){
                  if(p[j]==i)r[j]=k;
            }
            k+=cnt;
      }
      REP(i,n){
            cout<<r[i]<<endl;
      }
}

Measured memory_bytes: 1164
n, k = map(int, input().split(' '))
wi = list(map(int, [input() for i in range(n)]))

def isAllocatable(p):
  kw, ki = 0, 1
  for w in wi:
    if w > p: return False
    kw += w
    if kw <= p: continue
    kw = w
    ki += 1
    if k < ki: return False
  return True

l, r = 0, sum(wi)
while l + 1 < r:
  p = int((l + r) / 2)
  if isAllocatable(p): r = p
  else: l = p

print(r)



Measured memory_bytes: 15828
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back

using namespace std;

int k;

string s;

vector<ll>v;

ll toll(string x)
{
    ll ret=0;
    for (int i=0;i<x.length();i++)
    {
        ret*=10;
        ret+=x[i]-'0';
    }
    return ret;
}

void f(int len,int last)
{
    if (len==0)
    {
        v.pb(toll(s));
        return;
    }
    for (int i=max(0,last-1);i<=min(9,last+1);i++)
    {
        s.pb(i+'0');
        f(len-1,i);
        s.pop_back();
    }
}

int main()
{
    cin >> k;
    for (int i=1;i<11;i++)
    {
        for (int j=1;j<10;j++)
        {
            s.pb(j+'0');
            f(i-1,j);
            s.pop_back();
        }
    }
    sort(v.begin(),v.end());
    cout << v[k-1] << endl;
}


Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
using namespace std;
struct point{
  int x,y;
  point(){}
  point(int x,int y):x(x),y(y){}
};

int main(){
  int R,C,sx,sy,gx,gy,i,j,white=0;
  int dx[] = {0,1,0,-1};
  int dy[] = {1,0,-1,0};
  point now;
  queue<point> que;
  cin >> R >> C;
  char c[R][C];
  int cnt[R][C];
  for(i=0;i<R;i++){
    for(j=0;j<C;j++){
      cin >> c[i][j];
      if(c[i][j]=='.')white++;
      cnt[i][j] = -1;
    }
  }
  cnt[0][0] = 1;
  que.push(point(0,0));
  while(!que.empty()){
    now = que.front();
    //cout << now.x << " " << now.y << " " << cnt[now.x][now.y] << endl;
    que.pop();
    for(i=0;i<4;i++){
      int ddx,ddy;
      ddx = now.x+dx[i];
      ddy = now.y+dy[i];
      if(ddx>-1 && ddx<R && ddy>-1 && ddy<C && c[ddx][ddy]=='.' && cnt[ddx][ddy] == -1){
        que.push(point(ddx,ddy));
        cnt[ddx][ddy] = cnt[now.x][now.y]+1;
      }
    }
  }
  //cout << R << C << endl;
  //cout << cnt[R-1][C-1] << endl;
  if(cnt[R-1][C-1]!=-1)cout << white-cnt[R-1][C-1] << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
def p_e():
    N, M = map(int, input().split())
    max_value = (10 ** 5) * 12 + 1
    dp_len = 2 ** N
    dp = [max_value] * dp_len
    dp[0] = 0
    for _ in range(M):
        a, b = map(int, input().split())
        keys = list(map(int, input().split()))
        index = 0
        for key in keys:
            index += 2 ** (key - 1)

        for i in range(dp_len):
            if dp[i] == max_value:
                continue
            dp_index = i | index
            dp[dp_index] = min(dp[dp_index], dp[i] + a)

    print(dp[-1] if dp[-1] != max_value else -1)


if __name__ == '__main__':
    p_e()


Measured memory_bytes: 46936
from collections import defaultdict

d = defaultdict(int)

N = int(input())

for i in range(1,N+1):
    i = str(i)
    H = i[0]
    T = i[-1]
    d[H,T]+=1

o = 0
for i in "0123456789":
    for j in "0123456789":
        o += d[i,j] * d[j,i]

print(o)




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

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

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

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

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, m1, d1, m2, d2);

    output(m1 != m2 ? 1 : 0);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[4][3][10] = {}, b, f, r, v, n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        a[b-1][f-1][r-1] += v;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                cout << " " << a[i][j][k];
            }
            cout << endl;
        }
        if(i < 3){
        cout << "####################" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3108
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<map>
#define ran(x) (x).begin(),(x).end()
using namespace std;
int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	vector<int> a(h,0), b(w,0);
	for(int i = 0; i < h; ++i) {
		cin >> s[i];
		int cou = 0;
		for(int j = 0; j < w; ++j) {
			if(s[i][j] == '.')
				++cou;
		}
		if(cou == w)
			a[i] = 1;;
	}
	for(int j = 0; j < w; ++j) {
		int cou = 0;
		for(int i = 0; i < h; ++i) {
			if(s[i][j] == '.')
				++cou;
		}
		if(cou == h)
			b[j] = 1;
	}
	for(int i = 0; i < h; ++i) {
		if(!a[i]) {
			for(int j = 0; j < w; ++j) {
				if(!b[j])
					cout << s[i][j];
			}
			cout << endl;
		}
	}

}

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll n;
  string s, t;
  cin >> n >> s >> t;
  rep(i, n) cout << s[i] << t[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <map>

using namespace std;

int main() {
  int n;
  cin >> n;
  map<int, int> m;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    m[a]++;
  }
  int ans = 0;
  for (auto p : m) {
    ans += p.second;
    if (p.second >= p.first)
      ans -= p.first;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4736
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  string result = (a == b && b == c) ? "Yes" : "No";
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
_ = gets.to_i
monsters = gets.split.map(&:to_i)

def get_gcd(a, b)
  smaller, bigger = [a, b].sort
  if bigger % smaller == 0
    smaller
  else
    get_gcd(bigger-(bigger/smaller*smaller), smaller)
  end
end

current = monsters.shift
monsters.each do |monster|
  current = get_gcd(current, monster)
end
puts current


Measured memory_bytes: 11012
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
  int N, M;
  cin >> N >> M;

  vector<int> x(M);
  for (int i = 0; i < M; ++i)
    cin >> x[i];

  if (N >= M) {
    cout << 0 << endl;
    return 0;
  }

  sort(x.begin(), x.end());
  vector<int> diff(M);
  for (int i = 0; i < M; ++i) {
    if (i == 0)
      diff[i] = 0;
    else
      diff[i] = x[i] - x[i - 1];
  }

  int len = x[M - 1] - x[0];

  sort(diff.begin(), diff.end(), greater<int>());
  for (int i = 0; i < N - 1; ++i)
    len -= diff[i];

  cout << len << endl;

  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		//test
		Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());

		System.out.println(((N % 1000) == 0) ? 0 : 1000 - (N % 1000));
	}

}


Measured memory_bytes: 35716
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

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

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

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

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

int main() {
    int A, B;
    cin >> A >> B;
    FOR (i, 1, 10000) {
        if ((int)(i * 0.08) == A && (int)(i * 0.1) == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
X = int(input())
last2 = int(str(X)[-2:])
XX_n = int((X - last2)/100)
n5 = int(last2/5)
n4 = int(last2%5/4)
n3 = int(last2%5%4/3)
n2 = int(last2%5%4%3/2)
n1 = int(last2%5%4%3%2)
if XX_n>=n1+n2+n3+n4+n5:
    print(1)
else:
    print(0)


Measured memory_bytes: 38296
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if(n == 0) break;

			String[][] tk = new String[n][5]; int p = 0;
			for(int i=0;i<n;i++) for(int j=0;j<5;j++)
				tk[i][j] = sc.next();

			HashMap<String, Integer> map = new HashMap<String, Integer>();
			for(int i=0;i<n;i++) {
				if(!map.containsKey(tk[i][1])) map.put(tk[i][1], p++);
				if(!map.containsKey(tk[i][4])) map.put(tk[i][4], p++);
			}

			int[][] d = new int[p][p]; for(int[] a: d) fill(a, INF);
			for(int i=0;i<n;i++) {
				d[map.get(tk[i][1])][map.get(tk[i][4])] = Integer.parseInt(tk[i][3].substring(3));
				d[map.get(tk[i][4])][map.get(tk[i][1])] = -Integer.parseInt(tk[i][3].substring(3));
			}

			for(int i=0;i<p;i++) d[i][i] = 0;

			for(int k=0;k<p;k++) for(int i=0;i<p;i++) for(int j=0;j<p;j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}

			boolean flg = false;
			for(int i=0;i<p;i++) flg |= d[i][i] < 0;

			System.out.println((flg? "No": "Yes"));
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

Measured memory_bytes: 40156
#include <iostream>
using namespace std;
 
int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	if (b - a <= 0) {
		cout << "delicious" << endl;
	}
	else if (b - a < x+1) {
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
using namespace std;
#define U(v) \
cerr << #v << ": " << (v) << endl

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int& i : A)
        cin >> i;
    map<int, int> m;
    for (int i = 0; i < N; ++i)
        m[A[i]] = i;
    sort(A.begin(), A.end());
    int ct1 = 0, ct2 = 0;
    for (int i = 0; i < N; ++i) {
        if (i % 2 != m[A[i]] % 2) {
            if (m[A[i]] % 2) {
                ++ct1;
            } else {
                ++ct2;
            }
        }
    }
    cout << ct1 << endl;
    return 0;
}


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


int main(void)
{
    int x,n;
    cin >> x >> n;
    vector<int> a(102,0);
    for (int i = 0;i < n;i++)
    {
        int b;
        cin >> b;
        a[b] = 1;
    }
    
    int ans = x,diff = 1000;
    for (int i = 0;i <= 101;i++)
    {
        if (a[i]) continue;
        int d = abs(x-i);
        if (diff > d)
        {
            ans = i;
            diff = d;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>
using namespace std;


#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(ll i = 0;i < n;i++)
#define FOR(i,a,b) for(ll i = a;i < b;i++)
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll digitsum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int getdigit(ll a) {
	return to_string(a).size();
}
int countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}



int main() {
	IOS;
	const ll INF = 1e14 + 514;
	int n, m, r;
	cin >> n >> m >> r;
	vector<int> R(r);
	REP(i, r)cin >> R[i];
	sort(ALL(R));
	vector<vector<ll>> v(n + 1, vector<ll>(n + 1, INF));
	FOR(i, 1, n + 1)v[i][i] = 0;
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		v[a][b] = v[b][a] = c;
	}
	FOR(k, 1, n + 1) {
		FOR(i, 1, n + 1) {
			FOR(j, 1, n + 1) {
				v[i][j] = min(v[i][j],v[i][k] + v[k][j]);
			}
		}
	}
	ll ans = LMAX;
	do {
		ll tmp = 0;
		REP(i, r - 1) {
			tmp += v[R[i]][R[i + 1]];
		}
		if (tmp < ans)ans = tmp;
	} while (next_permutation(ALL(R)));
	dump(ans);
}




Measured memory_bytes: 768
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

///
/// # Examples
///
/// # integers
/// input! { n: usize, m: usize, ... }
///
/// # array
/// input! { n: usize, v: [i32; n], }
///
/// # matrix
/// input! { n: usize, m: usize, mat: [[]] }
///
/// # string
/// input! { s: chars }

// https://practice.contest.atcoder.jp/tasks/practice_1
fn main() {
    input!{
        n: usize, ws: [chars; n]
    }
    let mut acc = Vec::new();
    let mut last = ' ';
    let mut cnt = 0;
    for w in &ws {
        if (cnt > 0 && last != w[0]) || acc.contains(&w) {
            println!("No");
            return;
        }
        cnt += 1;
        acc.push(w);
        last = w[w.len()-1];
    }
    println!("{}", "Yes");
}


Measured memory_bytes: 4352
import sys
import itertools
from collections import deque
from operator import itemgetter

def find(x):
    if parent[x] == x:
        return x
    else:
        return find(parent[x])

def unite(x, y):
    x = find(x)
    y = find(y)

    if x != y:
        if rank[x] < rank[y]:
            parent[x] = y
            size[y] += size[x]
        else:
            parent[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1

def same(x, y):
    return find(x) == find(y)

input = sys.stdin.readline
N, M = map(int, input().split())

parent = [0]*N
for i in range(N):
    parent[i] = i
rank = [1]*N
size = [1]*N

edge = [tuple(map(int, input().split())) for i in range(M)]
edge = edge[::-1]
for i in range(M):
    edge[i] = (edge[i][0]-1, edge[i][1]-1)

res = deque()
for i in range(M):
    start = find(edge[i][0])
    end = find(edge[i][1])
    if start == end:
        res.append(0)
    else:
        res.append(size[start]*size[end])
        unite(start, end)

ans = 0
for i in range(M):
    ans += res[M-1-i]
    print(ans)

Measured memory_bytes: 24424
#include<stdio.h>
int a[300];
int main()
{
	int i,n,d,x,choc=0,dt;
	while(scanf("%d%d%d",&n,&d,&x)==3)
	{
		choc=x+n;
		for( i=0;i<n;i++)
		scanf("%d",&a[i]);
		for( i=0;i<n;i++)
			choc+=(int)((d-1)/a[i]);
	    printf("%d\n",choc);
	}
	return 0;
}
  

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int a,b,c; cin >> a >> b >> c;
  if(a % (b+c) >= c) cout << a/(b+c) << endl;
  else{
    cout << a/(b+c)-1 << endl;
  }
  system("pause");
}

Measured memory_bytes: 504
cnt = 0
N,D = map(int,input().split())
x = [list(map(int,input().split())) for i in range(N)]
ans = 0
for i in range(N):
	for j in range(i+1,N):
		num = 0
		for k in range(D):
			num += (x[i][k] - x[j][k])**2
		num = num**0.5
		if num.is_integer():
			ans+=1
print(ans)

Measured memory_bytes: 3064