akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int a[maxn], b[maxn];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n + 1; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) cin >> b[i];
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] >= b[i]) {
			ans += b[i];
			a[i] -= b[i]; b[i] = 0;
		} else {
			ans += a[i]; 
			b[i] -= a[i];
			if (b[i] >= a[i + 1]) {
				ans += a[i + 1]; b[i] -= a[i + 1]; a[i + 1] = 0;
			} else {
				ans += b[i];
				a[i + 1] -= b[i];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#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
#define mp make_pair
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>>M;
    vec a(M+N), b(M+N);
    rep(i,M) cin>>a[i]>>b[i], --a[i], --b[i];
    rep(i,N) a[i+M] = b[i+M] = i;
    cin>>Q;
    mat dp(11,vec(N,-1));
    vec color(Q);
    rep(i,Q){
        cin>>A>>B>>K;
        --A;
        dp[B][A] = i;
        color[i] = K;
    }
    Rrep(i,10){
        rep(j,M + N){
            dp[i][b[j]] = max(dp[i][b[j]], dp[i+1][a[j]]);
            dp[i][a[j]] = max(dp[i][a[j]], dp[i+1][b[j]]);
        }
        //rep(j,N) cout<<dp[i][j]<<' ';
        //cout<<endl;
    }
    rep(i,N) cout<<(dp[0][i] == -1 ? 0 : color[dp[0][i]])<<endl;
}

Measured memory_bytes: 13168
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, m, ans;
bool g[100][100], d[100];

void dfs(int v) {
    d[v] = true;
    bool all_visited = true;
    rep(i, 0, n) {
        if (!d[i]) {
            all_visited = false;
            break;
        }
    }
    if (all_visited) {
        ans++;
        return;
    }

    rep(i, 0, n) {
        if (v == i) continue;
        if (!d[i] && g[v][i]) {
            d[i] = true;
            dfs(i);
            d[i] = false;
        }
    }
    return;
}

int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> m;
    rep(i, 0, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a][b] = g[b][a] = true;
    }
    dfs(0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue> 
#include<cstdlib> 
#include<cstring>
#include<climits>
#include<cstring>
#include<iostream>
#define MAX_M 2000
#define MAX_N 2000
using namespace std;

string field[200];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int INF = 0x3f3f3f3f;
int N, M, cnt;

void dfs(int x, int y, char c)
{
	field[x][y] = '.';
	for(int i = 0; i <= 3; i++)
	{
		int nx = x + dx[i], ny = y + dy[i];
		if(0 <= nx && nx < N && 0 <= ny && ny < M && field[nx][ny] == c){
			dfs(nx, ny, field[nx][ny]);
		}
	}
	return;
}



int main()
{
	ios::sync_with_stdio(false);
	while(cin >> N >> M && N && M){
		cnt = 0;
		for(int i = 0; i < N; i++)
			cin >> field[i];
		
		for(int i = 0; i < N; i++)
		{
			for(int j = 0; j < M; j++)
			{	
				if(field[i][j] != '.')
				{
					dfs(i, j, field[i][j]);
					cnt++;
				}
			}
		}
		cout << cnt << endl;	
	}		
	return 0;
} 

Measured memory_bytes: 2160
import sys 
input=sys.stdin.readline 
def main():
    n=int(input())
    L=list(map(int,input().split()))
    L.sort() 
    ans=0
    for i in range(n):
        ans+=L[i*2]
    else:
        print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int x,t,n;
    while(~scanf("%d%d",&x,&t))
    {
        if(x<t)
        printf("0\n");
        else
        {
             n=x-t;
             printf("%d\n",n);
        }

    }
}


Measured memory_bytes: 256
/*
Author: CNYALI_LK
LANG: C++
PROG: D.cpp
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
typedef long long ll;
typedef pair<int,int> pii;
template<class T>int chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>int chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
#define min mmin
#define max mmax
#define abs aabs
int read(){
	int s=0,base=1;
	char c;
	while(!isdigit(c=getchar()))if(c=='-')base=-base;
	while(isdigit(c)){s=s*10+(c^48);c=getchar();}
	return s*base;
}
char WriteIntBuffer[1024];
template<class T>void write(T a,char end){
	int cnt=0,fu=1;
	if(a<0){putchar('-');fu=-1;}
	do{WriteIntBuffer[++cnt]=fu*(a%10)+'0';a/=10;}while(a);
	while(cnt){putchar(WriteIntBuffer[cnt]);--cnt;}
	putchar(end);
}
char s[102424];
int F[2][32768];
int *f[2]={F[0]+16384,F[1]+16384};
int a[2][102424],cnt[2];
void BL(char *s){
	cnt[1]=0;
	cnt[0]=0;
	int fx=0;
	while(*s){
		if(*s^'T')++a[fx][cnt[fx]];
		else ++cnt[fx^=1];
		++s;
	}
	/*
	for(int i=0;i<=cnt[0];++i)printf("%d%c",a[0][i],i==cnt[0]?'\n':' ');
	for(int i=0;i<=cnt[1];++i)printf("%d%c",a[1][i],i==cnt[1]?'\n':' ');
	*/
}
int ok(int len,int *s,int sl,int goal){
//	debug("SB");
	for(int i=-len;i<=len;++i)f[0][i]=0;
	f[0][*s]=1;
	for(int i=1;i<=sl;++i){
		for(int j=-len;j<=len;++j)f[i&1][j]=f[(i^1)&1][j-s[i]]||f[(i^1)&1][j+s[i]];
	}
	return f[sl&1][goal];
}
int main(){
#ifdef cnyali_lk
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
#endif
	int x,y;
	scanf("%s%d%d",s,&x,&y);
	BL(s);
	if(ok(strlen(s),a[0],cnt[0],x)&&ok(strlen(s),a[1],cnt[1],y))printf("Yes\n");
	else printf("No\n");
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

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

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
 
	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
 
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
 
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}
 
	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}
 
		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);
 
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;
 
		return true;
	}
};




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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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

  ll ans=3;

  if(N==K)ans--;
  if(N==X)ans--;
  if(K==X)ans--;
  if(ans==0)ans++;

  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int A , B;
    A>=-100;
    B<=100;
    cin>>A>>B;
    if ((A+B)>=(A-B) && (A+B)>=(A*B)) cout<<A+B;
    else if ((A-B)>=(A+B) && (A-B)>=(A*B)) cout<<A-B;
    else if ((A*B)>=(A+B)&&(A*B)>=(A-B))  cout<<A*B;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int n,ans=100;
    cin>>n;
    REP(i,n){
        int a,tmp=0;
        cin>>a;
        while(a%2==0){
            a=a/2;
            ++tmp;
        }
        ans=min(ans, tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
map<string,int> m;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;int n;
	cin>>n;
	int ans=0;
	FOR(i,1,n){
		cin>>s;
		if(!m.count(s)){
			m[s]=1;ans++;
		}
	}
	cout<<ans;
	RE 0;
}




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

int main(){
  int n,a[100010]={};
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>a[i];
  }
  sort(a,a+n);
  reverse(a,a+n);
  long long x,y;
  bool flag1=false,flag2=false;
  for(int i=1;i<n;++i){
    if(a[i]==a[i-1]&&!flag1){
        x=a[i];
        i++;
        flag1=true;
    }else if(a[i]==a[i-1]&&!flag2){
        y=a[i];
        flag2=true;
        break;
    }
  }
  if(flag1&&flag2)cout << x*y << endl;
  else cout << 0 << endl;
  return 0;
}


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

#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;

namespace modular {
    int MOD;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1) ans = mul(ans, x);
        return ans;
    }
};  // namespace modular
using namespace modular;

namespace Base {
    template <typename Tp>
    inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp>
    inline void read(Tp &x) {
        x = input<Tp>();
    }
    template <typename Tp>
    inline void chmax(Tp &x, Tp y) {
        x < y ? x = y : 0;
    }
    template <typename Tp>
    inline void chmin(Tp &x, Tp y) {
        x > y ? x = y : 0;
    }
};  // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/

#define MAX_N 3007

int N;
int C[MAX_N][MAX_N], S[MAX_N][MAX_N];

void init() {
    C[0][0] = 1;
    Rep(i, N) {
        C[i][0] = 1;
        Rep(j, i) C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
    }
    S[0][0] = 1;
    Rep(i, N + 1) {
        Rep(j, i) S[i][j] = add(S[i - 1][j - 1], mul(S[i - 1][j], j));
    }
}

void solve() {
    int res = 0;
    rep(i, 0, N) {
        int sum = 0, bs = qpow(2, N - i), now = 1;
        rep(j, 0, i) inc(sum, mul(S[i + 1][j + 1], now)), now = mul(now, bs);
        bs = 1;
        rep(j, 1, N - i) bs = 1LL * bs * 2 % (MOD - 1);
        if (i & 1)
            inc(res, MOD - mul(C[N][i], mul(qpow(2, bs), sum)));
        else
            inc(res, mul(C[N][i], mul(qpow(2, bs), sum)));
    }
    printf("%d\n", res);
}

int main() {
#ifdef LOCAL
    FIN("in");
#endif
    read(N), read(MOD);
    init();
    solve();
    return 0;
}


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

int main(void)
{
	char str[101];
	int i, j;
	
	while (scanf("%s", str) != EOF){
		for (i = 0; i < strlen(str); i++){
			if (str[i] == '@'){
				for (j = 0; j < str[i+1] - '0'; j++){
					printf("%c", str[i+2]);
				}
				i += 2;
			}
			else {
				printf("%c", str[i]);
			}
		}
		puts("");
	}
	
	return (0);
}

Measured memory_bytes: 524
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>
#include <map>
#include <stack>

struct max_min
{
    int64_t max = 0;
    int64_t min = 0;
};

const int64_t cc = pow( 10, 9 ) + 7;
//std::cout<< std::fixed << std::setprecision(10) << ( double )( max ) / 2;
bool sort_pair( std::pair< int64_t, int64_t > origin, std::pair< int64_t, int64_t > another )
{
    return origin.first < another.first;
}

int main()
{
    std::string word = "ABC";
    std::string w = "Yes";
    int64_t a,b,c,d,e,f;
    std::cin>> d;
    std::cin>> w;
    a = 0;
    c = 0;

    for( int i = 0; i < w.size(); i++ )
    {
        if( word[a] == w[i] )
        {
            a += 1;
        }
        else if( w[i] == 'A' )
        {
            a = 1;
        }
        else
        {
            a = 0;
        }

        if( a == 3 )
        {
            a = 0;
            c += 1;
        }
    }

    std::cout<< c;
}


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

int main(){
  string s;
  cin >> s;
  int u = s.size();
  if (s[0] == s[u-1]) u--;

  if (u % 2 == 1) cout << "First" << endl;
  else cout << "Second" << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
// ll fun(ll a[], ll n)
// {
//     if(n<=0)
//     return 0;
//     if(dp[n]!=-1)
//     return 0;
//     return min(fun(a,n-1)+abs(a[n]-a[n-1]),fun(a,n-2)+abs(a[n]-a[n-2]));
// }

int main() {
   
   ll i,n;
   cin>>n;
   ll a[n];
   for(i=0;i<n;i++)
    cin>>a[i];
    ll dp[n+1];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    
    cout<<dp[n-1];
   
    
}


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

using namespace std;
using ll = long long int;

struct Process {
  string name;
  int time;
};

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

  int n, q;
  cin >> n >> q;
  queue<Process> qu;
  for (int i = 0; i < n; i++) {
    string name;
    int time;
    cin >> name >> time;
    qu.push(Process{name, time});
  }

  int ms = 0;
  while (!qu.empty()) {
    auto p = qu.front();
    qu.pop();
    ms += min(p.time, q);
    p.time -= q;
    if (p.time <= 0) {
      cout << p.name << " " << ms << endl;
    } else {
      qu.push(p);
    }
  }

  return 0;
}



Measured memory_bytes: 6324
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
typedef long long ll;
vector<int> vec[4];
int n, W, w[maxn], v[maxn];
int ans;
int main()
{
	scanf("%d%d", &n, &W);
	for(int i = 0; i <= 3; ++i) vec[i].push_back(0);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d%d", &w[i], &v[i]);
		vec[w[i] - w[1]].push_back(v[i]);
	}
	for(int i = 0; i <= 3; ++i) 
	{
		sort(vec[i].begin() + 1, vec[i].end(), greater<int>());
		for(int j = 1; j < vec[i].size(); ++j)
			vec[i][j] += vec[i][j - 1];
	}
	for(ll i = 0; i < vec[0].size() && i * w[1] <= W; ++i)
		for(ll j = 0; j < vec[1].size() && i * w[1] + j * (w[1] + 1) <= W; ++j)
			for(ll k = 0; k < vec[2].size() && i * w[1] + j * (w[1] + 1) + k * (w[1] + 2) <= W; ++k)
			{
				ll h = min((ll)(vec[3].size() - 1), (W - (i * w[1] + j * (w[1] + 1) + k * (w[1] + 2))) / (w[1] + 3));
				ans = max(ans, vec[0][i] + vec[1][j] + vec[2][k] + vec[3][h]);
			}
	printf("%d\n", ans);
	return 0;
}
				
	

Measured memory_bytes: 256
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())

n,m=sep()
def f():
    return -1
ar=[]
for _ in range(m):
    ar.append(tuple(sep()))
t=0

def istrue(n):
    s=str(n)
    for i in ar:
        if i[0]>len(s):
            return 0
        if s[i[0]-1]!=str(i[1]):
            return 0
    return 1


if n==1:
    for i in range(0, 10):
        if istrue(i):
            print(i)
            quit()
    print(-1)
    quit()



for i in range(10**(n-1),10**n):
    if istrue(i):
        print(i)
        quit()
print(-1)




Measured memory_bytes: 62784
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#define INF 1000000009
#define LINF 1000000000000000009
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmax(T &a, const T&b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T&b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;

ll modpow(ll a, ll b) {
	ll ans = 1;
	a %= mod;
	while (b) {
		if (b & 1) ans = ans * a%mod;
		a = a * a%mod;
		b >>= 1;
	}
	return ans;
}

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(all(a)); reverse(all(a));
	ll ans = 0;
	ll base = modpow(2, n - 1);
	for (ll i = 0; i < n; i++) {
		ans += base * a[i] % mod; ans %= mod;
		if (i != n - 1)base += modpow(2, n - 2); base %= mod;
	}
	cout << ans * modpow(2, n) % mod << endl;
}

Measured memory_bytes: 1792
bingo1 = list(map(int,input().split()))
bingo2 = list(map(int,input().split()))
bingo3 = list(map(int,input().split()))

bingo_list = []
bingo_list.append(bingo1)
bingo_list.append(bingo2)
bingo_list.append(bingo3)
N = int(input())

bingo_flag = False

for i in range(N):
    b = int(input())
    for j in range(3):
        if b in bingo_list[j]:
            index = bingo_list[j].index(b)
            bingo_list[j][index] = -1


for i in range(3):
    cnt1 = 0
    cnt2 = 0
    for j in range(3):
        if bingo_list[i][j] == -1:
            cnt1 += 1
        if bingo_list[j][i] == -1:
            cnt2 += 1
    if cnt1 == 3 or cnt2 == 3:
        bingo_flag = True
        break

if bingo_list[0][0] == -1 and bingo_list[1][1] == -1 and bingo_list[2][2]:
    bingo_flag = True


if bingo_list[0][2] == -1 and bingo_list[1][1] == -1 and bingo_list[2][0]:
    bingo_flag = True

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


Measured memory_bytes: 3064
import java.util.Scanner;

import javax.sql.rowset.serial.SerialArray;

public class Main {

		public static void main(String[] args){
			
			Scanner sc = new Scanner(System.in);

			int N = sc.nextInt();
			int A = sc.nextInt();
			
			int men = N * N - A ;
		    System.out.println(men);

		}
}


Measured memory_bytes: 20948
import java.util.*;
public class Main{ 
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		boolean find = false;
		for(int i = 0; i < a.length(); i++) {
			if(a.charAt(i) != b.charAt(i)){
				System.out.println("No");
				find = true;
				break;
			}
		}
		if(!find)
			System.out.println("Yes");
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout<<setprecision(10)<<fixed;
	int n;
	double x;
	string u;
	cin>>n;
	double ans=0;
	double btc=380000;
	REP(i, n){
		cin>>x>>u;
		if(u=="JPY"){
			ans+=x;
		}
		else{
			ans+=btc*x;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



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

  int n;
  cin>>n;
  map<string,int> mp;
  rep(i,n){
    string s;
    cin>>s;
    sort(all(s));
    mp[s]++;
  }

  int ans=0;
  for(auto m:mp){
    ans+=(m.S)*(m.S-1)/2;
  }

  cout<<ans<<endl;


}

Measured memory_bytes: 11264
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	int N;
	cin >> N;
	int ans = N * (N + 1) / 2;
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct edge{ int to,cost; };
struct state{
  int cost,pos,last;
  bool operator < (const state &p)const{
    return cost > p.cost;
  }
};

int N,M,X;
vector<edge> G[10000];
int t[10000];

int D[10000][401];
int* d[10000];

int main(){
  scanf("%d %d %d",&N,&M,&X);
  for(int i=0;i<N;i++){
    scanf("%d",&t[i]);
  }
  for(int i=0;i<M;i++){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    a--,b--;
    G[a].push_back((edge){b,c});
    G[b].push_back((edge){a,c});
  }

  fill(D[0],D[10000],1e9);
  for(int i=0;i<N;i++){
    d[i]=&D[i][200];
  }
  

  priority_queue< state > Q;
  
  d[0][-X]=0;
  Q.push( (state){0,0,-X} );
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    
    if(s.pos==N-1){
      printf("%d\n",s.cost);
      break;
    }
    
    if(s.cost > d[s.pos][s.last])continue;
    
    for(int i=0;i<(int)G[s.pos].size();i++){
      edge e=G[s.pos][i];
      state next=s;
      next.pos=e.to;
      next.cost+=e.cost;
      if(next.last<0)next.last=min(0,next.last+e.cost);
      if(next.last>0)next.last=max(0,next.last-e.cost);

      if(next.last>0&&t[e.to]==0)continue;
      if(next.last<0&&t[e.to]==2)continue;

      if(t[e.to]==0)next.last=-X;
      if(t[e.to]==2)next.last=X;

      if( d[next.pos][next.last] > next.cost ){
        d[next.pos][next.last]=next.cost;
        Q.push( next );
      }
    }
  }

  return 0;
}

Measured memory_bytes: 19976
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int a[200010];
string s[200010];
int main()
{
	int n,m;
	string str;
	scanf("%d",&n);
	for(int i=0;i<n;++i)
		cin>>s[i];
	sort(s,s+n);
	str=s[0];
	m=a[0]=1;
	for(int i=1;i<=n;++i)
	{
		if(s[i]!=str)
		{
			if(a[i-1]>m)m=a[i-1];
			str=s[i];
			a[i]=1;
		}
		else a[i]=a[i-1]+1;
	}
	for(int i=0;i<n;++i)
		if(a[i]==m)cout<<s[i]<<endl;
	return 0;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int n;
    ll sum=0;
    cin >>n;
    vector<int>a;
    a.push_back(0);
    vector<ll>seg;
    int bef;
    rep(i,n){
        cin>>bef;
        a.push_back(bef);
        seg.push_back(abs(a[i] - a[i + 1]));
        sum+=seg[i];
    }
    a.push_back(0);
    seg.push_back(abs(a[n]-a[n+1]));
    sum+=seg.back();
    rep(i,n){
        cout <<(sum-seg[i]-seg[i+1]+abs(a[i]-a[i+2])) << endl;
    }
    
}

Measured memory_bytes: 2672
#include<iostream>
#include<algorithm>

inline bool isDTriangle(int edge[]){
    return edge[2]*edge[2]==edge[0]*edge[0]+edge[1]*edge[1]?true:false;
}

int main(void){
    int edge[3];
    int n;
    std::cin>>n;
    for(int i=0;i<n;i++){
        std::cin>>edge[0]>>edge[1]>>edge[2];
        std::sort(edge,edge+3);
        std::cout<<(isDTriangle(edge)?"YES":"NO")<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int rr = 998244353;

int main(){
    ll ans = 1;
    int n; cin >> n;
    vector<int> v(n,0);
    REP(i,n){
        int a;cin >> a;
      	if(i == 0 and a != 0){
        	cout << 0;
          	return 0;
        }
        v[a] += 1; 
    }
     if(v[0] != 1){
        cout << 0;
          return 0;
      }
    while(v[v.size()-1] == 0) {
        v.pop_back();
    }
	REP(i,v.size()){
    	if(v[i] == 0){
        	cout << 0;
       		return 0;
        }
    }
    for(int i = 1; i < v.size(); ++i){
      REP(j,v[i]) ans = ans*v[i-1]%rr;
    }
    cout << ans%rr;
    return 0;
 }



Measured memory_bytes: 640
import math

num = int(input())
tmp = {}
flg = 0
ans = 0
for i in range(num):
  inp = ''.join(sorted(input()))
  if inp not in tmp: tmp[inp]=1
  else: tmp[inp]+=1
for k, v in tmp.items():
  if v > 1:
    ans += v*(v-1)//2
    flg = 1
print(ans)

Measured memory_bytes: 17848
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int dp[111][11111];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, W;
  cin >> N >> W;
  int v[N], w[N];
  FOR(i,0,N) cin >> v[i] >> w[i];
  FOR(i,0,111)FOR(j,0,11111)dp[i][j]=2e9;
  dp[0][0] = 0;
  FOR(i,0,N){
    FOR(j,0,11111){
      if(dp[i][j]==2e9)continue;
      // 入れる
      dp[i+1][j+v[i]] = min(dp[i+1][j+v[i]], dp[i][j] + w[i]);
      // 入れない
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    }
  }
  for(int i = 11111; i >= 0; i--) {
    if(dp[N][i] <= W) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 8052
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

typedef long long ll;
const int maxn=2e5+10;
int a[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,k,d;
	cin>>n>>k>>d;
	if(k<=abs(n/d)) cout<<abs(n)-k*d<<endl;
	else{
		int cnt=abs(n/d);
		if((k-cnt)&1) cout<<min(abs(n%d-d),abs(n%d+d))<<endl;
		else cout<<abs(n)%d<<endl;
		//if(k&1) cout<<min(abs(n)%d,abs(abs(n)%d-d));
	}
	
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<ll> burger(51),pattys(51);
ll dfs(int n, ll x, int depth){
    if(depth==1){
        ll p = 0;
        if(x==1) p=0;
        else if(1<x&&x<5) p=x-1;
        else p=3;
        return p;
    }
    //b=第depth層にあるdepth-1バーガーの層数
    ll b=burger[depth-1];
    ll ans = 0;
    if(x==1){
        ans = 0;
    }else if(x<=1+b){
        ans += dfs(n,x-1,depth-1);
    }else if(x==2+b){
        ans += pattys[depth-1]+1;
    }else if(x<=2+2*b){
        ans += pattys[depth-1]+1;
        ans += dfs(n,x-2-b,depth-1);
    }else if(x==burger[depth]){
        ans += pattys[depth];
    }
    return ans;
}
int main(){
    int n;
    ll x;
    cin>>n>>x;
    burger[0]=1;
    pattys[0]=1;
    for(int i=0; i<50; i++){
        burger[i+1]=burger[i]*2+3;
        pattys[i+1]=pattys[i]*2+1;
    }
    cout<<dfs(n,x,n)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;



int main(int argc, char* argv[])
{
    char str0[12]={0};
    scanf("%s", str0);
    char str[1050]={0};
    int cnt=0;
    while(scanf("%s", str) && strcmp(str, "END_OF_TEXT")!=0 ) {
        if(strcasecmp(str0, str)==0) cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}



Measured memory_bytes: 2756
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		char op = sc.next().charAt(0);
		int b = sc.nextInt();
 
		switch(op) {
		case '+' :
			System.out.println(a + b);
			break;
		case '-' :
			System.out.println(a - b);
		}
	}
}

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

int n;
string f[100];

int main() {	
	while (cin >> n) {
		if (!n) break;
		int ans = 0;
		for (int i = 0; i < n; i++) cin >> f[i];
		for (int i = 0; i < n / 2; i++) {
			if (f[2 * i][0] != f[2 * i + 1][0]) { ans++; }
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>

using namespace std;
typedef long long ll;
const int maxn = 100005;

int n,m;
vector<int>e[maxn];
int d[maxn],ret[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "w", stdout);
#endif
  cin>>n>>m;
  for(int i=0;i<n-1+m;i++){
    int x,y;
    scanf("%d%d",&x,&y);
    e[x].push_back(y);
    d[y]++;
  }
  queue<int>q;
  for(int i=1;i<=n;i++) {
    if (d[i] == 0)q.push(i);
  }
  while(!q.empty()){
    int x = q.front();
    q.pop();
    for(int i=0;i<e[x].size();i++){
      int y = e[x][i];
      d[y]--;
      if(d[y]==0){
        ret[y]=x;
        q.push(y);
      }
    }
  }
  for(int i=1;i<=n;i++)printf("%d\n",ret[i]);
  return 0;
}

Measured memory_bytes: 7040
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void go()
{
    long long int n,k;
    cin>>n>>k;
    vector<long long int> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(k<=n)
    {
        int curr=1;
        while(k)
        {
            curr=a[curr-1];
            k--;
        }
        cout<<curr;
    }
    else
    {
        bool v[n+1]={0};
        int curr=1;
        int len=0;
        while(v[curr]!=1)
        {
            v[curr]=1;
            curr=a[curr-1];
            len++;
        }
        memset(v,0,sizeof(v));
        int cy_st=curr;
        int cy_len=0;
        while(v[curr]!=1)
        {
            v[curr]=1;
            curr=a[curr-1];
            cy_len++;
        }
        long long int z=(k-len)%cy_len;
        curr=cy_st;
        while(z--)
        {
            curr=a[curr-1];
        }
        cout<<curr;
    }
}
int main()
{
    FIO;
    go();
    return 0;
}



Measured memory_bytes: 5044
#include<stdio.h>
#include<stdlib.h>
#define N 10

typedef struct{
  int parent;
  int left;
  int right;
}Node;

int main(){
  int point,number,i,j,a,b,n,deep=0,place,count=0,k;
  int *Deep;
  int num[N];
  Node *Tree;

  scanf("%d",&n);
  Tree =  ( Node * )malloc( sizeof(Node) * n );
  Deep = ( int * )malloc( sizeof(int) * n );

  for( i = 0 ;i < n;i++ ){

    Tree[i].parent = -1;
    Tree[i].left = -1;
    Tree[i].right = -1;
  }

  for( i = 0; i < n ; i++ ){
    scanf("%d %d",&point,&number);

    for( j = 0 ; j < number ; j++ ){
      scanf("%d",&a);
      if( i == 0 ){
	num[j] = a;
	count++;
      } 
      Tree[a].parent = point;

      if( j == 0 ) Tree[point].left = a;
      else Tree[b].right = a;

      b = a;
    }
  }

  for( i = 0 ; i < n ; i++ ){
    place = i;
    while( Tree[place].parent != -1 ){
      deep++;
      place = Tree[place].parent;
    }
    Deep[i] = deep;
    deep = 0;
  }

  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i ,Tree[i].parent ,Deep[i]);
    if(Tree[i].parent==-1)printf("root, ");
    else if(Tree[i].left==-1)printf("leaf, ");
    else printf("internal node, ");

    printf("[");
    for(j=0,a = Tree[i].left; a!=-1;j++,a=Tree[a].right){
      if(j) printf(", ");
      printf("%d",a);
    }
    printf("]\n");
  }
  return 0;
}

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

using namespace std;

int main() {
	ll N; 
	cin >> N;
	vector<ll> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	vector<ll> d(N, 0);
	d[0] = a[0];
	for (int i = 1; i < N; i++) {
		d[i] += d[i - 1] + a[i];
	}

	ll res = 1e18;
	int l = 0, r = 2;
	for (int i = 2; i <= N - 2; i++) {
		while (abs(d[i - 1] - d[l]*2) >= abs(d[i - 1] - d[l + 1]*2)) {
			if (l + 1 >= i - 1) break;
			l++;
		}
		ll P = d[l];
		ll Q = d[i - 1] - d[l];

		if (r < i) r = i;
		while (abs(d[N - 1] - 2*d[r] + d[i - 1]) >= abs(d[N - 1] - 2*d[r + 1] + d[i - 1])) {
			if (r + 1 >= N - 1) break;
			r++;
		}
		ll R = d[r] - d[i - 1];
		ll S = d[N - 1] - d[r];

		ll max_num = max(P, max(Q, max(R, S)));
		ll min_num = min(P, min(Q, min(R, S)));
		res = min(res, abs(max_num- min_num));
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<string>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  string ans = "Yes";
  rep(i,0,S.size()-1) {
    if (S[i] != T[i]) ans = "No";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3552
import itertools

inf = 10 ** 12

n, m, r = map(int, input().split())
n += 1
rl = [int(i) for i in input().split()]
d = [[inf for _ in[0]*n] for _ in[0]*n]

for _ in[0]*m:
    f, t, c = map(int, input().split())
    d[f][t], d[t][f] = c, c

for i in range(n):
    for j in range(n):
        for k in range(n):
            d[j][k] = min(d[j][k], d[j][i] + d[i][k])

ans = inf
for arr in itertools.permutations(rl):
    ans = min(ans, sum([d[arr[i]][arr[i+1]] for i in range(0, r-1)]))
print(ans)

Measured memory_bytes: 47704
import java.util.*;
public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int a = Integer.parseInt(scan.next());
		int b = Integer.parseInt(scan.next());
		int c = Integer.parseInt(scan.next());
		int ans = 0;
		ans += Math.min(a+b,c);//毒入りを何枚食べれるか
		c -= ans;
		if(c == 0){//毒入りを全て食べられる
			int tmp = Math.min(b,ans);
			ans += Math.min(b,ans);
			ans += Math.max(0, b - tmp);
		}else{
			ans += b + 1;
		}
		System.out.println(ans);

	}

}
//end

Measured memory_bytes: 23252
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,a,b = LI()
ans = n//(a+b) * a + min(a, n % (a+b))
print(ans) 

Measured memory_bytes: 38384
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    P = LI()
    ans = 0
    for i, p in enumerate(P[1:-1], start=1):
        if (P[i - 1] - p) * (P[i + 1] - p) < 0:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 38576
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;
       
        static void SolveA()
        {
            string s = Console.ReadLine();
            string ans = "2018" + s.Substring(4);
            Console.WriteLine(ans);
        }
        
        
        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if( x == 2) { return true; }
            if( x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while( i * i <= x)
            {
                if( x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }

        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 11092
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);

        String a=scan.next();
        String b=scan.next();
        String c=scan.next();

        char s=a.charAt(a.length()-1);
        char t=b.charAt(0);
        char u=b.charAt(b.length()-1);
        char v=c.charAt(0);

        if(s==t && u==v){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21972
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> 
// using namespace __gnu_pbds;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MaX 300005
using namespace std;

 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
   	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
// typedef tree<int, null_type, less<int>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//     new_data_set; 
bool isprime(ll n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}
int main()
{
	fast();
	ll n;
	cin>>n;
	string ans="";
	while(n)
	{
		n--;
		ll rem=n%26;
		ans+=('a'+n%26);
		n/=26;
	}
	reverse(all(ans));
	cout<<ans;
}






/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀⠀⠀⠀
*/

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
  
  int n,W;cin>>n>>W;
  
  ll w[110];
  ll v[110];
  
  rep(i,n) cin>>w[i]>>v[i];
  
  ll dp[n+10][W+10];
  memset(dp,0,sizeof dp);
  
  for (int i=0;i<n;i++) {
    for (int j=1;j<=W;j++) {
      if (j-w[i]<0) {
        dp[i+1][j]=dp[i][j];
      }
      else {
        dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
      }
    }
  }
  
  cout<<dp[n][W]<<endl;
  
}

Measured memory_bytes: 86144
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	ll N, A, B;
	cin >> N >> A >> B;
	if (( B - A ) % 2 == 0){
		cout << ( B - A ) / 2 << endl;
	}
	else {
		cout << min( A - 1, N - B ) + 1 + ( B - A - 1 ) / 2 << endl;
	}
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256