akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[222222];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,a[111111];
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	int x=a[n/2-1],y=a[n/2];
	cout<<y-x<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////



int main(){fastio
    string s;
    ll n,k;cin>>n>>s>>k;
    string t;
    rep(i,0,n-1){
        if(s[i]==s[k-1])t+=s[i];
        else t+='*';
    }
    cout<<t<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>


using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 M = 0;

	cin >> N;
	cin >> M;

	string s;
	cin >> s;

	vector<SINT32> DATA(N);
	
	rep(i,0,s.length()) {
		if (i == N) {
			if (s[i] != '-') {
				cout << "No" << endl;
				return 0;
			}
		} else {
			SINT32 buf;
			buf = s[i]-'0';
			if ((buf <=9) && (buf >=0)) {

			} else {
				cout << "No" << endl;
				return 0;
			}

		}
		
	}

	cout << "Yes" << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));	//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/
/* 文字列合成
	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;
	ans = stoi(N+M);
*/



/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

// change minimum change maximum
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

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

void solve()
{
  string S, T;
  cin >> S >> T;
  int N, M;
  N = S.size(), M = T.size();
  ll dp[N + 1][M + 1];
  for (int i = 0; i < N + 1; i++)
  {
    for (int j = 0; j < M + 1; j++)
    {
      dp[i][j] = 0;
    }
  }
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < M; j++)
    {
      if (S[i] == T[j])
      {
        dp[i + 1][j + 1] = dp[i][j] + 1;
      }
      else
      {
        dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
      }
    }
  }
  cout << dp[N][M] << endl;
}

int main()
{
  int q;
  cin >> q;
  for (int i = 0; i < q; i++)
    solve();
  return 0;
}



Measured memory_bytes: 10944
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
  ll n,m,k,i,j,result=0;
  int a[200010];
  string s;
  cin >> s;
  n = s.size();
  rep(i,n){
    result += (ll)(s[i]-'0');
    result %= 9;
  }
  cout << (result%9==0 ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3752
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int t;
		for(;;){
			int x=stdIn.nextInt();
			int y=stdIn.nextInt();
			if(x<1&&y<1)break;
			if(x>y){
				t=x;
				x=y;
				y=t;
			}
			System.out.println(x+" "+y);
		}
	}
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

	string s;
	cin>>s;
	
	int ans=0,count=0;
	rep(i,s.size()){
		switch(s[i]){
			case 'A':
			case 'C':
			case 'G':
			case 'T':
				count++;
				ans=max(ans,count);
				break;
			default:
				count=0;
				break;
		}
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3592
n, m, l = map(int, input().split())
a = []
b = []
for i in range(n):
    a_i = list(map(int, input().split()))
    a.append(a_i)
for i in range(m):
    b_i = list(map(int, input().split()))
    b.append(b_i)
c = []
for i in range(n):
    c_i = []
    for j in range(l):
        c_ij = 0
        for k in range(m):
            c_ij = c_ij + a[i][k]*b[k][j]
        c_i.append(c_ij)
    c.append(c_i)



for i in range(n):
    word = str(c[i][0])
    for k in range(1,l):
        if k < l:
            word = word +" "+str(c[i][k])
        else:
            word = word + str(c[i][k])
    print(word)



Measured memory_bytes: 6920
import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws Exception {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    // Your code here!
    Scanner scan = new Scanner(is);
    int X = scan.nextInt();
    int N = scan.nextInt();
    HashSet<Integer> set = new HashSet<>();
    for(int i = 0 ; i < N; i++) {
      set.add(scan.nextInt());
    }

    if(!set.contains(X)) {
      os.println(X);
      return;
    }

    int diff = 1;
    while(true) {
      if(!set.contains(X-diff)) {
        os.println(X-diff);
        return;
      }
      if(!set.contains(X+diff)) {
        os.println(X+diff);
        return;
      }
      diff++;
    }
  }
}


Measured memory_bytes: 27180
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    string s;
    cin >> s;

    a--;
    b--;
    c--;
    d--;

    // a~cの間に二連続岩があるか？
    // b~dの間に二連続岩があるか？
    // D < Cの時にB～Dに二連続平地があるか？

    for (int i = a; i < c; i++) {
        if (s[i] == '#' && s[i + 1] == '#') {
            cout << "No" << endl;
            ret();
        }
    }

    for (int i = b; i < d; i++) {
        if (s[i] == '#' && s[i + 1] == '#') {
            cout << "No" << endl;
            ret();
        }
    }

    if (d < c) {
        for (int i = b; i <= d; i++) {
            if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
                cout << "Yes" << endl;
                ret();
            }
        }
        cout << "No" << endl;
        ret();
    } else {
        cout << "Yes" << endl;
    }


}


Measured memory_bytes: 3748
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n,p,bowl,i,ans;
		int mayor[];
		boolean flag;
		while(true){
			n=sc.nextInt();
			p=sc.nextInt();
			bowl=p;
			ans=-1;
			flag=false;
			if(n+p==0) break;
			mayor=new int[n];
			Arrays.fill(mayor, 0);

			while(true){
				for(i=0;i<n;i++){
					if(bowl==0){
						bowl=mayor[i];
						mayor[i]=0;
					}
					else{
						mayor[i]+=1;
						bowl--;
						if(mayor[i]==p){
							//finish
							ans=i;
							flag=true;
							break;
						}
					}
				}
				if(flag) break;
			}
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 12000
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Getting Difference
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  int g = 0, maxa = 0;
  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);

    g = (g == 0) ? ai : __gcd(g, ai);
    if (maxa < ai) maxa = ai;
  }

  if (k <= maxa && k % g == 0) puts("POSSIBLE");
  else puts("IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;
const int INF = 1000000000;

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<int> a(n), b(n), c(n);
    FOR(i, 0, n) {
        cin >> a[i] >> b[i] >> c[i];
    }

    vector<vector<int>> dp(401, vector<int>(401, INF));
    dp[0][0] = 0;
    IFOR(k, 1, n) {
        RFOR(i, 400, 0) {
            RFOR(j, 400, 0) {
                int idxa = i - a[k - 1], idxb = j - b[k - 1];
                if (idxa >= 0 && idxb >= 0)
                    dp[i][j] = min(dp[i][j], dp[idxa][idxb] + c[k - 1]);
            }
        }
    }
    int minn = INF;
    for (int i = 1; ma*i <= 400 && mb*i <= 400; i++) {
        int tma = ma*i, tmb = mb*i;
        minn = min(minn, dp[tma][tmb]);
    }
    cout << (minn == INF ? -1 : minn) << endl;
    return 0;
}

Measured memory_bytes: 896
#include <iostream>

const int MAXN = 50;

int a[MAXN];

int main() {
  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      ans += a[i] * a[j];
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


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

static const int MAX = 100000;
int T[MAX];

// 最大積載量Pのトラックk台で何個の荷物を積めるか
int check(int P, int n, int k) {
    int i = 0;
    for (int j = 0; j < k; j++) {
        int s = 0;
        while (s + T[i] <= P) {
            s += T[i];
            i++;
            if (i == n) return n;
        }
    }
    return i;
}

int solve(int n, int k) {
    int left = 0;
    int right = n * 10000; // 荷物の個数 x 1個あたりの最大重量
    int mid;
    while (left < right) {
        mid = (left + right) / 2;
        int v = check(mid, n, k);
        if (v >= n) right = mid;
        else left = mid + 1;
    }
    return right;
}

int main() {
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> T[i];
    cout << solve(n, k) << endl;
    
    return 0;
}



Measured memory_bytes: 3480
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=200010;
char s[N];
int n,ans,pre[N],suf[N];

int main(){
	scanf("%d%s",&n,s+1); ans=n+1;
	rep(i,1,n) pre[i]=pre[i-1]+(s[i]=='#');
	for (int i=n; i; i--) suf[i]=suf[i+1]+(s[i]=='.');
	rep(i,0,n) ans=min(ans,pre[i]+suf[i+1]);
	printf("%d\n",ans);
	return 0;
}

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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int main()
{
    int x;
    scanf("%d", &x );
    printf("%d\n", x * x * x );

    return 0;
}

ll gcd( ll x, ll y )
{
    if ( y == 0 ) return x;
    return gcd( y, x % y );
}

ll lcm( ll x, ll y )
{
    return x / gcd( x, y ) * y;
}




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

int main(){
  ll N,M;
  cin >> N >> M;
  vector<ll> H(N);
  set<int> s;
  vector<vector<int>> L(N);
  rep(i,N){
    cin >> H.at(i);
  }
  rep(i,M){
    int x,y;
    cin >> x >> y;
    s.insert(x-1); s.insert(y-1);
    L.at(x-1).push_back(y-1);
    L.at(y-1).push_back(x-1);
  }
  ll cnt=0;
  rep(i,N){
    bool b = 1;
    if(!(s.count(i))){
      ++cnt;
      continue;
    }
    rep(j,L.at(i).size()){
      if(H.at(i)<=H.at(L.at(i).at(j))){
        b=0;
        break;
      }
    }
    if(b){
      ++cnt;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 13292
N, M, K = list(map(int, input().split()))
L = [0 for i in range(N * M + 1)]
L[0] = 1

for x in range(M + 1):
	for y in range(N + 1):
		L[x * (N - y) + y * (M - x)] += 1

if L[K] >= 1: 
	print("Yes")
else:
	print("No")

Measured memory_bytes: 10904
#include <bits/stdc++.h>
#define  pb push_back
#define nl "\n"
#define fastScan ios_base::sync_with_stdio(0); cin.tie(NULL);
#define int long long int
using namespace std;
int BIT[234567];
int dp[234567];
int h[234567];
int a[234567];
int n;
void update(int x,int delta)
{
	for(;x<=n;x+=x&-x)
		BIT[x]=max(BIT[x],delta);
}
int query(int x)
{
	int maxval=0;
	for(;x>0;x-=x&-x)
		maxval=max(maxval,BIT[x]);
	return maxval;
}
signed main()
{
	fastScan;
	int ans=0;cin>>n;
	for(int i=0;i<n;i++)
		cin>>h[i];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
	{
		dp[i]=a[i]+query(h[i]-1);
		update(h[i],dp[i]);
		ans=max(ans,dp[i]);
	}
	cout<<ans<<nl;
}


Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
const int md=1e9+7;
int a[110];
int dp[110][110][110];
void Add(int &x,int y){
	x=(x+y)%md;
}
int main(){
//	freopen("F.in","r",stdin);
	int n;
	scanf("%d",&n);
	for(int i=1;i<2*n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n*2);
	dp[n][1][1]=1;
	int vl,vr;
	for(int i=n;i>1;i--){
		vl=a[n*2-i]!=a[n*2-i+1];
		vr=a[i]!=a[i-1];
		for(int l=1;l<n*2;l++)
			for(int r=1;r<n*2;r++){
				Add(dp[i-1][l+vl][r+vr],dp[i][l][r]);
				for(int j=1;j<l+vl;j++)
					Add(dp[i-1][j][r+vr+1],dp[i][l][r]);
				for(int j=1;j<r+vr;j++)
					Add(dp[i-1][l+vl+1][j],dp[i][l][r]);
			}
	}
	int ans=0;
	for(int l=1;l<n*2;l++)
		for(int r=1;r<n*2;r++)
			Add(ans,dp[1][l][r]);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4352
from collections import deque
N, L = map(int, input().split())
c = list(map(int, input().split()))
for i in range(len(c)-1):
  if c[i] + c[i+1] >= L:
    pos = i + 1
    break
else:
  print("Impossible")
  exit()

print("Possible")
for i in range(1,pos):
  print(i)
for i in range(len(c) -1, pos, -1):
  print(i)
print(pos)

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

void solver() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  ans += (n * (n - 1)) / 2;
  ans += (m * (m - 1)) / 2;

  cout << ans << "\n";
}

int main() {
  solver();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=998244353;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>kaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    //if(!kaijo[0])init_fact(2000010);
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int EditDistance(string s,string t){
    int n=s.size(),m=t.size();
    int dp[1010][1010];
    rep(i,n+1)rep(j,m+1)dp[i][j]=INF;
    rep(i,n+1)dp[i][0]=i;
    rep(j,m+1)dp[0][j]=j;
    rep(i,n+1){
        rep(j,m+1){
            if(j<m)chmin(dp[i][j+1],dp[i][j]+1);
            if(i<n)chmin(dp[i+1][j],dp[i][j]+1);
            if(i<n&&j<m)chmin(dp[i+1][j+1],dp[i][j]+(s[i]!=t[j]));
        }
    }
    return dp[n][m];
}
signed main(){
    string s,t;
    cin>>s>>t;
    cout<<EditDistance(s,t)<<endl;
    return 0;
}


Measured memory_bytes: 11124
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define inf 2e9
#define f first
#define s second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}speed;

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

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

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


int main (){
    int n,k;
    string  s;
    cin  >> n>> k >> s;
    s[k-1] +=  0x20; 
    cout << s << "\n";
}

Measured memory_bytes: 256
//
//  main.c
//  ITP1_3_C
//
//  Created by k16031kk on 2018/05/18.
//  Copyright © 2018年 AIT. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int x,y;
    scanf("%d %d", &x, &y);
    while(x!=0 || y!=0) {
        if(x>y) {
            int tmp;
            tmp=x;
            x=y;
            y=tmp;
        }
        printf("%d %d\n", x, y);
        scanf("%d %d", &x, &y);
    }
    
    return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod ll(1e9+7)
ll exp(ll a,ll b)
{
	if(b==0)
	 return 1;
	if(b%2==0){
		return exp(a*a%mod,b/2);
	}
	return a*exp(a*a%mod,(b-1)/2)%mod;
}
int main()
{
	int n;
	cin>>n;
	ll var1=exp(10,n);
	ll var2=(exp(9,n)+exp(9,n)-exp(8,n)+mod)%mod;
	ll ans=(var1-var2+mod)%mod;
	cout<<ans;
	return 0;
	
	
}

Measured memory_bytes: 3628
/*BY-ADITYA OJHA
  LEARN DSA SINCERELY*/
#include <bits/stdc++.h>
#define ll long long int
#define forin for(int i=0;i<n;i++)
#define forjn for(int j=0;j<n;j++)
#define pb push_back
#define vx vector<ll> x
#define fas1  ios_base::sync_with_stdio(false)
#define fas2   cin.tie(NULL)
using namespace std;


int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
        cout<<'x';



}



Measured memory_bytes: 256
import sys

sys.setrecursionlimit(200000)

n, m = map(int, input().split())

edges = [set() for _ in range(n)]

for _ in range(m):
    s, t = map(int, input().split())
    edges[s].add(t)
    edges[t].add(s)

prenum = [None] * n
parent = [None] * n
lowest = [None] * n
counter = 0
bridges = set()


def dfs(cur, prev):
    global counter
    prenum[cur] = lowest[cur] = counter
    counter += 1
    for edge in edges[cur]:
        if prenum[edge] is not None:
            if edge != prev:
                lowest[cur] = min(lowest[cur], prenum[edge])
            continue
        parent[edge] = cur
        dfs(edge, cur)
        lowest[cur] = min(lowest[cur], lowest[edge])
    if prenum[cur] == lowest[cur]:
        bridges.add((cur, prev) if cur < prev else (prev, cur))


dfs(0, -1)

for bridge in sorted(bridges)[1:]:
    print(*bridge)

Measured memory_bytes: 25200
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <stack>
using namespace std;

long long int a[300001]={};

int main()
{
  int i;
  int n;  cin >> n;
  long long int ans = 0;
  for(i=0;i<3*n;i++){
    cin >> a[i];
  }
  sort(a,a+3*n);
  for(i=n;i<3*n;i+=2)
    ans += a[i];

  cout << ans << endl;

  return 0;
}

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

int N;
int A[100005],B[100005];
int main()
{
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>A[i];
	}
	for(int i=1;i<=N;i++)
	{
		B[A[i]]=i;
	}
	for(int i=1;i<=N;i++)
	{
		cout<<B[i]<<" ";
	}
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> mp(n, 0);
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int a;
            cin >> a;
            a--;
            mp[a]++;
        }
    }
    int ans = 0;
    for (auto kv : mp) {
        if (kv == 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
import sys
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
x=read()
ls=[]
nums=10**3
ls2=[]
for i in range(nums+1):
  ls.append(i**5)
for i in range(nums,0,-1):
  ls.append(-i**5)
#print(ls)
for i in range(nums+1):
  for j in range(-nums,i):
    #print(ls[i],ls[j])
    if ls[i]-ls[j]==x:
      print("{} {}".format(i,j))
      exit()

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(std::string S){
    if (S.empty() || S.size() % 2 == 1) {
        cout << "No" << endl;
        return;
    }
    rep(i,0,S.size()/2) {
        if (S[2*i] != 'h' || S[2*i+1] != 'i') {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
    return;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import numpy as np
import itertools
N, M, X = map(int, input().split())
kumi = []
pat = list(range(N))
for _ in range(N):
    kumi.append(list(map(int, input().split())))
ans = 10 ** 5 * 12
kai = False
test = []
for i in range(N):
    for i2 in itertools.combinations(kumi,i+1):
        arr_i2 = np.array(i2)
        arr_i2_sum = arr_i2.sum(axis = 0)
        if np.all(arr_i2_sum[1:] >= X):
            if ans >= arr_i2_sum[0]:
                ans = arr_i2_sum[0]
                kai = True
if kai:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 27320
#include <bits/stdc++.h>
using namespace std;
#define mkp make_pair
#define pub push_back
typedef long long LL;
const int md = 1e9 + 7;
const int maxn = 1e5 + 5;

int main(){
    int n, x, p = 0;
    LL ans = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%d", &x);
        if(p && x){
            ans++;
            x--;
        }
        ans += x / 2;
        p = x & 1;
    }
    printf("%lld\n", ans);
    return 0;
}


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

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

	for(int n; cin >> n && n;) {
		long long x = 5;
		long long sum = 0;
		while(x <= n) {
			sum += n / x;
			x *= 5;
		}
		cout << sum << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1184
import fractions
a, b, c, d = map(int,input().split())
e = c*d//fractions.gcd(c,d)
l = [c,d,e]
l2 = [0,0,0]
for i in range(0,3):
    if a%l[i] == 0:
        l2[i] = b//l[i] - a//l[i] +1
    else:
        l2[i] = b//l[i] - a//l[i]
print(b-a+1 -l2[0] -l2[1] + l2[2])

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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int n = ri();
	
	int a[n];
	INPUT(a);
	int sum = 0;
	FOR(i,n) sum += a[i], a[i] *= n;
	
	int res = -1;
	int minn = INF;
	FOR(i,n) {
		if (minn > abs(sum-a[i])) minn = abs(sum-a[i]), res = i;
	}
	cout << res << endl;
    return 0;
}


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

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

  int N;
  cin >> N;
  bool checked[3][3] = {};
  for(int i = 0; i < N; i++){
    int b_;
    cin >> b_;
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        if(A[j][k] == b_){
          checked[j][k] = true;
        }
      }
    }
  }

  int indices[3] = {0, 1, 2};
  bool yoko = any_of(indices, indices + 3,
                     [&](int i){
                       return all_of(indices, indices + 3,
                              [&](int j){
                                return checked[i][j];
                              }
                              );
                         }
                     ),
    tate = any_of(indices, indices + 3,
                  [&](int j){
                    return all_of(indices, indices + 3,
                           [&](int i){
                             return checked[i][j];
                           }
                           );
                      }
                  ),
    naname = (all_of(indices, indices + 3, [&](int i){return checked[i][i];})) ||
              all_of(indices, indices + 3, [&](int i){return checked[i][2 - i];});

  if(yoko || tate || naname){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 888
#include <iostream>

using namespace std;

int main() {
    long long n;
    long long free[50];
    long long map[50];
    while (cin >> n, n) {
        fill_n((long long * )free, 50, 0);
        fill_n((long long *)map, 50, 0);
        for (long long i=0; i<n; i++) {
            long long m;
            cin >> m;
            map[i] |= (uint64_t)1<<i;
            for (long long j=0; j<m; j++) {
                long long day;
                cin >> day;
                free[i] |= (uint64_t)1<<day;
            }
        }
        long long ans = -1;
        for (long long i=1; i<=30; i++) {
            long long have = 0;
            for (long long j=0; j<n; j++) {
                if ((free[j]&((uint64_t)1<<i))!=0)
                    have |= map[j];
            }
            if (have==((uint64_t)1<<n)-1) {
                ans = i;
                break;
            }
            for (long long j=0; j<n; j++) {
                if ((free[j]&((uint64_t)1<<i))!=0)
                    map[j] = have;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    println!("{}",if a<=8&&b<=8{"Yay!"}else{":("})
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int n; cin >> n;
    int h[101];
    cin >> h[0];
    int ans = h[0];
    for(int i = 1; i < n; i++){
        cin >> h[i];
    }
    for(int i = 1; i < n; i++){
        if(h[i] >= h[i-1]){
            ans += (h[i] - h[i-1]);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace  std;

int main(){
    ios::sync_with_stdio(0);
    int x;cin>>x;
    if(x>=30){
        cout<<"Yes"<<'\n';
    }else{
        cout<<"No"<<'\n';
    }
}


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

const int INF = 1e9;
const int cost[] = {0,2,5,5,4,5,6,3,7,6};

bool comp(pair<int,string> a, pair<int,string> b){
    return a.second > b.second;
}

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i,m) cin >> a[i];

  vector<int> dp(n+1,-INF);
  dp[0] = 0;
  rep(i,n+1) {
    rep(j,m) {
      if (i - cost[a[j]] >= 0) dp[i] = max(dp[i], dp[i-cost[a[j]]] + 1);
    }
  }
  vector<pair<int,string>> p(m);
  rep(i,m) {
    string s = {char(a[i] + '0')};
    p[i] = {cost[a[i]], s};
  }

  sort(p.begin(), p.end(), comp);

  int N = dp[n];
  int match = n;
  string res = "";

  while (match > 0) {
    rep(i,m) {
      if (match - p[i].first >= 0 && dp[match - p[i].first] == N-1) {
        res += p[i].second;
        N--;
        match -= p[i].first;
        break;
      }
    }
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
int main(){
	ll n,m;
	cin>>n>>m;
	ll left=m-n+1;
	ll right=m+n-1;
	for(ll i=left;i<=right;i++){
		cout<<i<<" ";
	} 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(i,p,q) for(int i=p;i<q;i++)
using namespace std;
int gcd(int a,int b)
{  if(b==0)
   return a;
  else
     gcd(b,a%b);
}
int main()
{ int n;
 cin>>n;
 long long  int ar[n];
  for(int i=0;i<n;i++)
   cin>>ar[i];
   sort(ar,ar+n);
   int flag=ar[0];
  
   for(int i=1;i<n;i++)
     {  
     	flag=gcd(flag,ar[i]);
	 }
	 
	  cout<<flag; 
}

Measured memory_bytes: 1024
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let n: usize = s.trim().parse().ok().unwrap();

    s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let t: Vec<char> = s.trim().chars().collect();

    let mut ans: u32 = 0;
    for i in 0..10 {
        for j in 0..10 {
            for k in 0..10 {
                let mut c: Vec<bool> = vec![false; 3];
                for l in 0..n {
                    if k == (t[l] as u8 - '0' as u8) && c[0] && c[1] {
                        c[2] = true;
                    }
                    if j == (t[l] as u8 - '0' as u8) && c[0] {
                        c[1] = true;
                    }
                    if i == (t[l] as u8 - '0' as u8) {
                        c[0] = true;
                    }
                }
                if c[0] && c[1] && c[2] {
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}

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

using LL = long long;
int n;
vector<int> a;
signed main() {
  // freopen("in", "r", stdin);
  while(cin >> n) {
    a.resize(n);
    for(int i = 0; i < n; i++) {
      cin >> a[i]; a[i] -= (i + 1);
    }
    sort(a.begin(), a.end());
    int b = a[n/2];
    LL ret = 0;
    for(int i = 0; i < n; i++) {
      ret += (LL)abs(a[i] - b);
    }
    cout << ret << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=0;i<=n;++i)
#define INF 100000000
#define MOD 1000000009
#define ll long long

using namespace std;

typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int N, K;
int tmp;
map<int, int> mp;
vector<int> v;

int main(){
    cin >> N >> K;
    REP(i, N){
        cin >> tmp;
        if(mp.count(tmp)){
            ++mp[tmp];
        } else {
            mp[tmp] = 1;
        }
    }

    int m = mp.size();

    if(m <= K){
        cout << 0 << endl;
    } else {
        for(auto itr=mp.begin();itr!=mp.end();++itr){
            v.push_back(itr->second);
        }

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

        int ans = 0;
        REP(i, m-K){
            ans += v[i];
        }

        cout << ans << endl;
    }

	return 0;
}

Measured memory_bytes: 10748
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
const int inf=0x3f3f3f3f;
int n,m,r,ans,end;
int map[250][250],dr[10];
int main(){
	int i,j,k;
	memset(map,inf,sizeof(map));
	scanf("%d%d%d",&n,&m,&r);
	for(i=0;i<r;i++)
		scanf("%d",&dr[i]);
		sort(dr,dr+r);
	for(i=0;i<m;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		if(map[a][b]>c)
			map[a][b]=map[b][a]=c;
	}
	for(k=1;k<=n;k++){
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				if(map[i][j]>map[i][k]+map[k][j])
					map[i][j]=map[i][k]+map[k][j];
			}
		}
	}
	int ans=inf;
	do{
		int cnt=0;
		for(i=1;i<r;i++)
			cnt+=map[dr[i]][dr[i-1]];
		if(cnt<ans)
			ans=cnt;
	}while(next_permutation(dr,dr+r));
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 384
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int target = sc.nextInt();
            int sheet = sc.nextInt();
            if(target==0 && sheet==0) break;

            int n = 0;
            while(sheet>Math.pow(10,n+1)) n++;
            n++;

            int[] list = new int[n];
            int sheet2 = sheet;
            for(int i=n-1; i>=0; i--){
                list[i] = sheet2%10;
                sheet2 /= 10;
            }

            int max = -1;
            int part = -1;
            for(int mask=1; mask<1<<n; mask+=2){
                int sum = 0;
                int num = 0;
                for(int j=0; j<n; j++){
                    if((mask&(1<<j))>0){
                        sum += num;
                        num = list[j];
                    }else{
                        num *= 10;
                        num += list[j];
                    }
                }
                sum += num;

                if(sum==max){
                    part = -1;
                }
                if(sum>max && sum<=target){
                    max = sum;
                    part = mask;
                }

            }

            if(max==-1) System.out.println("error");
            else if(part==-1) System.out.println("rejected");
            else{
                System.out.print(max);
                int num = -1;
                for(int i=0; i<n; i++){
                    if((part&(1<<i))>0){
                        if(num!=-1) System.out.print(" "+num);
                        num = list[i];
                    }else{
                        num *= 10;
                        num += list[i];
                    }
                }
                System.out.println(" "+num);
            }
        }
    }

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

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

int main(){
  string s;
  int k, is;
  cin >> k >> s;
  is = s.size();
  if(k >= is){
    cout << s << endl;
  }
  else{
    for(int i = 0; i < k; i++){
      cout << s.at(i);
    }
    cout << "..." << endl;
  }
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI;typedef pair<ll,ll> pii;
const int mod = (int)1e9 + 7;

int n,m;
bool r[10][10];

int rec(int s, int u){
	
	int rtn =0;
	u |= 1<<s;
	if(u == (1<<n) - 1) return 1;
	rep(i,n) if(r[s][i] && !(u>>i &1)) rtn += rec(i, u);
	
	return rtn;
}


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

	cin >>n >>m;
	rep(i,m){
		int a,b;
		cin >>a >>b;
		r[a-1][b-1]=r[b-1][a-1]=1;
	}
	
	cout << rec(0,0) <<endl;
	return 0;

}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n, m;
  cin >> n >> m;
  if (n > m) {
    ll tmp = n;
    n = m;
    m = tmp;
  }
  ll ans = 0;
  for (ll i = n; i >= 0; i -= 2) {
    ll j = (n-i)/2;
    if (m == i*2+j) {
      ll x = 1, y = 1;
      rep(l, min(i, j)) {
        x *= (i+j)-l;
        y *= 1+l;
        x %= mod;
        y %= mod;
      }
      ans += (x*RepeatSquaring(y, mod-2, mod))%mod;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def mod_cmb(n, r, mod=10 ** 9 + 7):
	assert n >= r >= 0

	def ex_euclid(x, y):
		a, b = 1, 0
		while y != 0:
			a, b = b, (a - x // y * b)
			x, y = y, x % y
		return a

	p = q = 1
	for i in range(n - r + 1, n + 1):
		p *= i
		p %= mod
	for i in range(2, r + 1):
		q *= i
		q %= mod
	p *= ex_euclid(q, mod)
	p %= mod
	return p

x,y=map(int,input().split())
mod=10 ** 9 + 7
if x>2*y or y>2*x or (x+y)%3:
	print(0)
	exit()
print(mod_cmb((x+y)//3,(2*x-y)//3))

Measured memory_bytes: 3064
def main():
    import collections

    N = int(input())
    A_s = list(map(int, input().split()))
    Q = int(input())

    summ = sum(A_s)
    CNT_A = collections.Counter(A_s)


    for i in range(Q):
        before, after = map(int, input().split())
        
        tmp_cnt = CNT_A[before]
        
        if (tmp_cnt > 0):
            tmp_before = CNT_A[before] * (after - before)
            summ += tmp_before

            N_before=CNT_A[before]

            del CNT_A[before]
            N_after = CNT_A[after]
            
            if (N_after > 0):
                CNT_A[after] = N_after + N_before
            else:
                CNT_A[after] = N_before
            
        
        print(summ)


if __name__ == '__main__':
    main()

Measured memory_bytes: 21408
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>

using namespace std;
const long long int MOD=1e9+7;

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

int main(){
  long long a, b;
  cin >> a >> b;
  cout << a*b/gcd(a, b) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
using namespace std;


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

    int d[N];
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }
    sort(d, d+N);
    
    int result = 0;
    int motchi = 0;
    for (int i = 0; i < N; i++) {
        if (motchi < d[i]) {
            motchi = d[i];
            result++;
        }
    }
    
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {


	string str;
	
	int n;
	cin >> n;
	cin >> str;
	
	if (n >= str.length()) {
		cout << str << endl;
	}
	else {
		str = str.substr(0, n);
		
		str = str.append("...");
		cout << str << endl;
	}
	return 0;
}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int n;
    cin >> n;

    vector<int> nums(n);
    rep(i, n) cin >> nums[i];

    int cnt = 1, max_val = nums[0];
    repi(i, 1, n){
        cnt += (int)(max_val <= nums[i]);
        max_val = max(max_val, nums[i]);
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256