akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define what_is(x) cout << #x << " is: " << x << endl;
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define ll long long int

#define vi vector<int>
#define pii pair<int,int>
#define vl vector<ll>
#define pll pair<ll, ll>

template<typename T>
T extgcd(T a, T b, T &x, T &y) { if (b == 0) {x = 1;y = 0;return b;}T x1, y1;T g = extgcd(b, a % b,x1, y1);x = y1; y = x1 - (a/b)*y1;return g;}
template<typename T>
T fast_power(T a, T b){T res = (T)1;while( b ){if( b & 1 ) res = res * a;b >>= 1;a *= a; } return res;}
template<typename T>
T fast_powerModulo( T a, T b, T M){T res = (T)1;a %= M;while( b ){if( b & 1 ) res = (res * a) % M;b >>= 1;a *= a;a %= M; }return res;}
template<typename T>
T LCM(T a, T b){ T gd = __gcd(a, b); T ml = a * b; return ml/ gd;}

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

const int INF = 1<<30;
const ll LINF = 1ll<<60;

int main(){
    FAST
    string s, t;
    cin >> s >> t;
    int n = sz(s);
    int m = sz(t);
    vector<vi> ids(26, vi());
    for(int i = 0; i < n; ++i){
        ids[s[i] - 'a'].push_back(i);
    }
    int poss = 1;
    int pos = 0;
    int lenid = 0;
    int cycle = 0;
    for(int i = 0; i < m; ++i){
        if( ids[t[i] - 'a'].empty() ){
            poss = 0;
            break;
        }
        //check if last char posn is < pos
        //than inc cycle and lowerbound on pos = 0;
        if( ids[t[i] - 'a'][sz(ids[t[i] - 'a']) - 1] < pos ){
            pos = 0;
            cycle++;
        } 
        auto it = lower_bound(all(ids[t[i] - 'a']), pos );
        pos = *it + 1;
        //cout << i << " " << pos << " " << cycle << '\n';
    }
    if( !poss ){
        cout << - 1 << '\n';
    } else {
        ll ans = 0;
        ans += 1LL *cycle * n;
        ans += 1LL *(pos);
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int a, b, c, d, e, f;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b >> c;
	if (b % a && c % a && (c / a) == (b / a))
	{
		cout << "NG";
	}
	else
		cout << "OK";
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(void) {
	int N, D;
	int count = 0;
	int a = 0;
	int b = 0;
	int c = 0;
	scanf("%d%d", &N, &D);

	for (int i = 1; i <= N; i++) {
		b += 1 + 2 * D;
		count++;
		if (b>=N) {
			break;
		}
	}
	printf("%d",  count);


	return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
vector <int> nums={6,9,36,81,216,729,1296,6561,7776,46656,59049};
int main(){
    int n; cin>>n;
    int dp[n]; 
    for(int i=0;i<=n;i++){
        dp[i]=i;
        for(int j=0;nums[j]<=i;j++){
            dp[i]=min(dp[i],dp[i-nums[j]]+1);
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

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

int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  if (N <= K)
    cout << N * X << endl;
  else
    cout << K * X + (N - K) * Y << endl;
  return 0;
}

Measured memory_bytes: 3584
from collections import deque
n=int(input())
d={}
for i in range(n-1):
    #a,b=map(int,input().split()) ?str spd?
    a,b=map(int,input().split())
    if a in d:
        d[a].append(b)
    else:
        d[a]=[b]
    if b in d:
        d[b].append(a)
    else:
        d[b]=[a]
f,s=set([1]),set([n])
e=deque([0,1])
u=deque([0,n])
x=0
while 1:
    if len(e)==len(u)==1: break

    if x%2==0 and len(e)>0:
        while e[-1]!=0:
            tmp=e.pop()
            for i in d[tmp]:
                if i not in f and i not in s:
                    f.add(i)
                    e.appendleft(i)
        e.rotate()
    elif x%2==1 and len(u)>0:
        while u[-1]!=0:
            tmp=u.pop()
            for i in d[tmp]:
                if i not in f and i not in s:
                    s.add(i)
                    u.appendleft(i)
        u.rotate()
    x+=1
print(["Fennec","Snuke"][len(f)<=len(s)])

Measured memory_bytes: 76376
#include<stdio.h>

int main()
{
  int a,b,c,x;
  int i,j;
  int t=0;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&x);
  for(i=0;i<=a;i++){
    for(j=0;j<=b;j++){
      if(0<=(x-500*i-100*j) && (x-500*i-100*j)<=50*c) t++;
    }
  }
  printf("%d",t);
  return 0;
}


Measured memory_bytes: 1732
N, A, B = list(map(int, input().split(' ')))

goodNumberSum = 0
goodNumbers = []

for n in range(1, N + 1):

    # 各桁の和を求める
    digitSum = 0    # 各桁の和
    initDigits = n  # まだ足されていない残りの桁
    while initDigits > 0:
        lastDigit = initDigits % 10                  # 末尾の桁
        initDigits = int((initDigits - lastDigit) / 10)   # 末尾の桁を取り除く
        digitSum += lastDigit # 末尾の桁を足す

    # 条件を満たせば足す
    if A <= digitSum <= B:
        goodNumberSum += n

print(goodNumberSum)

Measured memory_bytes: 8880
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a)  (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  string s; cin >> s;
  int n = s.size() + 1;

  vi zl(n);//zero list:zl[i]=1ならa[i]=0
  vi ml(n);//max list

  vi a(n), b(n,1e9), c(n,1e9);
  rep(i, n-1){
    if(i == 0 && s[i] == '<') zl[i]++;
    if(i == n-2 && s[i] == '>') zl[i+1]++;
    if(i+1 < n-1 && s[i] == '>' && s[i+1] == '<') zl[i+1]++;
    if(i+1 < n-1 && s[i] == '<' && s[i+1] == '>') ml[i+1]++;
  }
  //rep(i, n) std::cout << zl[i] << '\n';
  // b
  for (int i = 0; i < n; i++) {
    if(zl[i] == 1) b[i] = 0;
    if(i+1 < n && s[i] == '<') b[i+1] = b[i] + 1;
  }
  //rep(i, n) printf("b[%d]:%d\n",i, b[i] );
  //std::cout << '\n';

  for (int i = n-1; i >= 0; i--) {
    if(zl[i] == 1) c[i] = 0;
    if(i-1 >= 0 && s[i-1] == '>') c[i-1] = c[i] + 1;
  }
  //rep(i, n) printf("c[%d]:%d\n",i, c[i] );
  //std::cout << '\n';

  rep(i, n){
    if(ml[i] == 1){
      a[i] = max(b[i],c[i]);
    }
    else{
      a[i] = min(b[i],c[i]);
    }
  }

  //rep(i, n) printf("a[%d]:%d\n",i, a[i] );
  ll ans = 0;
  rep(i, n) ans += a[i];

  std::cout << ans << '\n';
}


Measured memory_bytes: 10628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
 
    // 集合をマージする
    // すでに同じ集合ならfalseが返る
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (data[y] < data[x]) swap(x, y);  // マージテク
        data[x] += data[y];
        data[y] = x;
        return true;
    }
 
    // ある要素がどの集合に属しているかを答える
    int root(int x) {
        // 根に直接つなぎ直す
        return data[x]<0 ? x : (data[x]=root(data[x]));
    }
 
    // ある集合の大きさを答える
    int size(int x) {
        return -data[root(x)];
    }
};
int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll>a(m),b(m),c(k),d(k),answer(n),number_of_friends(n);
    REP(i,n){
        answer[i]=0;
        number_of_friends[i]=0;
    }
    REP(i,m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        number_of_friends[a[i]]++;
        number_of_friends[b[i]]++;
    }
    REP(i,k){
        cin >> c[i] >> d[i];
        c[i]--;
        d[i]--;
    }

    
    UnionFind block(n);
    UnionFind fri(n);
    REP(i,m){
        fri.merge(a[i],b[i]);
    }

    REP(i,n){
        answer[i]=fri.size(i)-number_of_friends[i]-1;
    }
    REP(i,k){
        if(fri.root(c[i])==fri.root(d[i])){
            answer[c[i]]--;
            answer[d[i]]--;
        }
    }
    REP(i,n)cout << answer[i] << " ";
    cout << endl;
    return 0;
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int a=7;
	for(int i=1;i<=n;i++){
		if(a%n==0)
		{
		cout<<i;	
	 return 0;
		}
		else
		a=(a*10+7)%n;
	}
	cout<<"-1";
}

Measured memory_bytes: 3604
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::ops::*;
use std::slice::*;
use std::*;

const MOD: isize = 1000000007;
fn main() {
    let s: String = read();
    let q: usize = read();
    let mut que: VecDeque<char> = s.chars().collect();

    let mut state = true;
    for _ in 0..q {
        let mut s = String::new();
        stdin().read_line(&mut s).unwrap();
        let mut it = s.split_whitespace();
        let t: usize = it.next().unwrap().parse().unwrap();
        if t == 1 {
            state = !state;
        } else {
            let f: usize = it.next().unwrap().parse().unwrap();
            let cs: String = it.next().unwrap().parse().unwrap();
            let c: char = cs.chars().nth(0).unwrap();

            if state ^ (f == 2) {
                que.push_front(c);
            } else {
                que.push_back(c);
            }
        }
    }

    if state {
        for i in que.iter() {
            print!("{}", *i);
        }
    } else {
        for i in que.iter().rev() {
            print!("{}", *i);
        }
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace() // iter
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 6652
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,ans=0;
  set<ll>st;
  for(ll i=1;i<10;i++){
    for(ll j=1;j<10;j++){
      st.insert(i*j);
    }
  }
  cin>>n;
  if(st.count(n))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

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

    ll A,B,C;
    ll K;
    cin >> A >> B >> C >> K;
    if(A >= K){
        cout << K << endl;
    }else if(A+B >= K){
        cout << A << endl;
    }else{
        cout << A - (K - (A+B)) << endl;
    }
    return 0;
}


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

#define ll long long int

int cell[5][10] = {};

bool tune()
{
    int f = false;
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            if (cell[i][j] == 0)
            {
                for (int k = j; k < 10; k++)
                {
                    if (cell[i][k] != 0)
                    {
                        cell[i][j] = cell[i][k];
                        cell[i][k] = 0;
                        f = true;
                        break;
                    }
                }
            }
        }
    }
    return f;
}

int main()
{
    int h;

    while (cin >> h)
    {
        if (h == 0)
            break;
        int sum = 0;
        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                cell[i][j] = 0;
            }
        }
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                cin >> cell[j][i];
            }
        }
        for (int i = 0; i < 5; i++)
        {
            reverse(cell[i], cell[i] + h);
        }
        while (1)
        {
            for (int i = 0; i < h; i++)
            {
                bool row[3] = {};
                for (int j = 0; j < 3; j++)
                {
                    if (cell[j][i] == cell[j + 1][i] && cell[j + 2][i] == cell[j + 1][i])
                        row[j] = true;
                }
                for (int j = 0; j < 3; j++)
                {
                    if (row[j])
                    {
                        for (int k = 0; k < 3; k++)
                        {
                            sum += cell[j + k][i];
                            cell[j + k][i] = 0;
                        }
                    }
                }
            }
            if (!tune())
                break;
        }
        cout << sum << endl;
    }
}



Measured memory_bytes: 3052
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cassert>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i=0; i<n; i++)
        cin >> p[i];
    int ans = 0;
    for(int i=1; i<n-1; i++){
        if(p[i-1] < p[i] && p[i] < p[i+1]) ans++;
        if(p[i+1] < p[i] && p[i] < p[i-1]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; ++i) cin >> A[i];
  
  sort(A, A + N, greater<int>());
  cout << A[N/2 - 1] - A[N/2] << endl;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int a, b;
  cin >> a >> b;
  if (a + b == 15) {
    cout << "+" << '\n';
  } else if (a * b == 15) {
    cout << "*" << '\n';
  } else {
    cout << "x" << '\n';
  }
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int n,a[100005];
bool flag;
signed main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i]);
        if(a[i]-a[i-1]>0) a[i]--;
        if(a[i]<a[i-1]){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}


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




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


	int count = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s.at(i) == '1') {
			count++;
		} else {
			break;

		}
	}

	if (count >= n) {

		cout << '1' << endl;
	} else {
		cout << s.at(count) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second 

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}


constexpr int ms = 1e5 + 13;

map< pii, long long > dp;
vector<ll> v;
ll padding = -MOD;
ll safe_min = padding * 1ll * ms;
int n;

ll solve(int cur_index, int remaining) {
    if(cur_index >= n && remaining > 0) return safe_min;
    if(cur_index >= n && remaining == 0) return 0;
    if(dp[{cur_index, remaining}]) return dp[{cur_index, remaining}];
    
    int quantos_tem_faltando = (n - cur_index + 1);
    int quantos_precisa = (remaining);
    int quantos_posso_botar = quantos_tem_faltando / 2 + !!(quantos_tem_faltando % 2);
    if(quantos_posso_botar < quantos_precisa) return dp[{cur_index,remaining}] = safe_min; // garantindo que o processo para nesse cara
    
    if(remaining == 0) return dp[{cur_index, 0}] = 0;    
    // agora tenho que escolher entre usar ou nao 
    ll ans = max( solve(cur_index + 1, remaining), solve(cur_index + 2, remaining - 1) + v[cur_index] );
    return dp[{cur_index,remaining}] = ans;
}
// End of template code!
int main() 
{
    buff();
    cin >> n;
    v.resize(n);
    long long extra = MOD;
    for(int i = 0; i < n; ++i) {
        cin >> v[i];
        v[i] += extra; // garantindo que todo mundo esta positivo
    }

    cout << solve(0, n / 2) - (1ll * n / 2ll) * extra << '\n';
    return 0;
}



Measured memory_bytes: 43844
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	string S;
	cin >> S;
	if (S[2] == S[3] && S[4] == S[5])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Sockets;

namespace ALDS1_5_A
{
    class Program
    {
        static void Main(string[] args)
        {
            n = int.Parse(Console.ReadLine());
            A = ReadInt();
            int q = int.Parse(Console.ReadLine());
            int[] m = ReadInt();

            dp = new int[n + 1, 2001];
            for (int i = 0; i <= n; i++)
            {
                for (int j = 0; j <= 2000; j++)
                {
                    dp[i, j] = -1;
                }
            }

            for (int i = 0; i < q; i++)
            {
                bool ans = Solve(0, m[i]);
                if (ans) Console.WriteLine("yes");
                else Console.WriteLine("no");
            }

            Console.ReadKey();
        }

        static int[,] dp;
        static int n;
        static int[] A;
        static bool Solve(int i, int m)
        {
            if (m == 0) return true;
            else if (m < 0) return false;
            if (i >= n) return false;
            if (dp[i, m] != -1) return dp[i, m] == 1 ? true : false;

            bool ret = Solve(i + 1, m) || Solve(i + 1, m - A[i]);
            
            if (ret) dp[i, m] = 1;
            else dp[i, m] = 0;
            return ret;
        }


        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}



Measured memory_bytes: 20420
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<vector<int>> open(n, vector<int>(10));
	vector<vector<ll>> p(n, vector<ll>(11));
	rep(i, n) {
		rep(j, 10) {
			cin >> open[i][j];
		}
	}
	rep(i, n) {
		rep(j, 11) {
			cin >> p[i][j];
		}
	}

	ll ans = -10000000000;
	for (int bit = 1; bit < (1 << 10); bit++) {
		ll ansi = 0;
		rep(i, n) {
			int cnt = 0;
			rep(j, 10) {
				if ((bit >> j) & open[i][j]) cnt++;
			}
			ansi += p[i][cnt];
		}
		ans = max(ans, ansi);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());//昇順ソート
#define usort(a) sort(a.rbegin(),a.rend());//降順ソート

using namespace::std;

int jo(ll int a, ll int b){//累乗
    ll int num=1;
    rep(i,0,b) num=num*a;
    return num;
}
char tobig(char s){//char大文字化
  return (s-0x20);
}
char tolow(char s){//char小文字化
  return (s+0x20);
}
int ctoi(char a){//char->int
  if('0'<=a&&a<='9') return (a-'0');
  return -1;
}

int gcd(ll int a,ll int b) {//最大公約数
  if(a<b) return gcd(b,a);
  int c;
  while ((c=a%b)) {
    a=b;
    b=c;
  }
  return b;
}
int lcm(ll int a,ll int b){//最小公倍数
 return (a*b)/gcd(a,b);
}


int main(){
  string A;cin>>A;
  if(A.length()==3){
    cout<<A[2]<<A[1]<<A[0];
  }else{
    cout<<A;
  }
    
}




// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順


Measured memory_bytes: 256
class Unionfind():

    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n

    def find(self,a):
        if self.parents[a]<0:
            return a
        else:
            self.parents[a]=self.find(self.parents[a])##事実上for文
            return self.parents[a]


    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        else:
            if self.parents[x]<self.parents[y]:
                x,y=y,x
            self.parents[y]+=self.parents[x]
            self.parents[x]=y

    def size(self,x):
        return -self.parents[self.find(x)]

    def same(self,x,y):
        if self.find(x)==self.find(y):
            return True
        else:
            return False
          
N,M,K=map(int,input().split())
uf=Unionfind(N)
friend=[list(map(int,input().split())) for i in range(M)]
block=[list(map(int,input().split())) for i in range(K)]
ff=[[] for i in range(N)]
bb=[[] for i in range(N)]
ans=[]
for i in range(M):
    uf.union(friend[i][0]-1,friend[i][1]-1)
    ff[friend[i][0]-1].append(friend[i][1]-1)
    ff[friend[i][1]-1].append(friend[i][0]-1)
for i in range(K):
    bb[block[i][0]-1].append(block[i][1]-1)
    bb[block[i][1]-1].append(block[i][0]-1)
for i in range(N):
    ans.append(uf.size(i)-1-(len(ff[i])))
    for j in bb[i]:
        if uf.same(j,i)==True:
            ans[i]-=1
answer=[str(ans[i]) for i in range(len(ans))]
print(" ".join(answer))

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

int main() {
  int n,ans = 0;
  cin >> n;
  vector<bool>s(1000000000+1,false);
  for(int i = 0;i < n;i++){
    long a;
    cin >> a;
    s[a] = true;
  }
  int q;
  cin >> q;
  for(int i = 0;i < q;i++){
    long a;
    cin >> a;
    if(s[a]) ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 124716
#include <stdio.h>
#include <limits.h>
#define N 100
#define LEN 1000

int Q[LEN];
int head = 0, tail = 0;
int n, M[N][N];
int d[N];


void enqueue(int x) {
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

int dequeue() {
	int x = Q[head];
	head = (head + 1) % LEN; 
	return x;
}

void bfs(int s) {
	int i,u, v;
	enqueue(s);
	for ( i = 0; i < n; i++) d[i] = INT_MAX;
	d[s] = 0;

	while ( head != tail) {
		u = Q[head];
		dequeue();
		for ( v = 0; v < n; v++) {
			if ( M[u][v] == 0 ) continue;
			if (d[v] != INT_MAX) continue;
			d[v] = d[u] + 1;
			enqueue(v);
		}
	}

	for ( i = 0; i < n; i++) {
		printf("%d %d\n",i + 1,(d[i] == INT_MAX ? (-1) : d[i]));
	}
}

int main() {
	int i, j,u, k, v;

	scanf("%d",&n);
	for ( i = 0; i < n; i++) {
		for ( j = 0; j < n; j++) M[i][j] = 0;
	}

	for ( i = 0; i < n; i++) {
		scanf("%d%d",&u,&k);
		u--;
		for (j = 0; j < k; j++) {
			scanf("%d",&v);
			v--;
			M[u][v] = 1;
		}
	}

	bfs(0);

	return 0;
}



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

const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

int main() {
	
	//vector<int> a(n);  sort(a.begin(),a.end());
	//cout << "test" << "\n";
	cin.tie(0);
	ios::sync_with_stdio(false);
	//string ans="YES";
	
	
	ll ans=0;
	
	int n;
	cin >> n;
	
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	sort(a.begin(),a.end());
	
	ans=a[n/2]-a[n/2-1];
	
	cout << ans << "\n";
	
	
	return 0;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))
a.sort()
box = [1] * (a[-1] + 1)
ans = 0
if n == 1:
    print(1)
else:
    for i in range(n):

        if i == 0:
            for j in range(a[-1] // a[i]):
                box[a[i] * (j + 1)] = 0
            if a[1] != a[0]:
                ans += 1
        elif i == n - 1:
            if box[-1] == 1:
                ans += 1
        else:
            if a[i] != a[i - 1] and a[i] != a[i + 1]:
                if box[a[i]] == 1:
                    ans += 1
                    for j in range(a[-1] // a[i]):
                        box[a[i] * (j + 1)] = 0
            elif a[i] == a[i + 1]:
                for j in range(a[-1] // a[i]):
                    box[a[i] * (j + 1)] = 0
    print(ans)

Measured memory_bytes: 32336
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef map<int,int> mii;
 
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define mem(a) memset(a , 0 ,sizeof a)
#define rep(i,a,b) for(int i=a ; i<b ; ++i)
#define deb(x) cout << #x << " - " << x << "\n";
#define deb2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define D2(x) { cerr << "[" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }
#define ps(x,y) fixed<<setprecision(y)<<x
#define clz(x) __builtin_clzll(x)
#define setbit(x) __builtin_popcount(x)
 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 10000005;
const ll MAX_N = 1e4 + 10;

int main() {
    IOS;
    int k ; cin>>k;
    string s; cin>>s;
    if(s.length()<=k) cout << s;
    else {
        for(int i=0;i<k;i++) cout << s[i];
        cout << "...";
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i;cin>>i;
    if (i<=599){
        cout << 8;
        return 0;
    }
    else if (i<=799){
        cout << 7;
        return 0;
    }
    else if (i<=999){
        cout << 6;
        return 0;
    }
    else if (i<=1199){
        cout << 5;
        return 0;
    }
    else if (i<=1399){
        cout << 4;
        return 0;
    }
    else if (i<=1599){
        cout << 3;
        return 0;
    }
    else if (i<=1799){
        cout << 2;
        return 0;
    }
    else if (i<=1999){
        cout << 1;
        return 0;
    }
}


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

int main() {
	int A, B, C, D, ans = 0;
	scanf("%d %d %d %d", &A, &B, &C, &D);
	if (A <= C && B >= C)
		if (B >= D)
			ans = D - C;
		else
			ans = B - C;
	
	if (C <= A && D >= A)
		if (D >= B)
			ans = B - A;
		else
			ans = D - A;

	printf("%d\n", ans);
	return 0; 
}

Measured memory_bytes: 128
import java.util.Scanner;

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

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    int N = scanner.nextInt();
    int sr = scanner.nextInt();
    int sc = scanner.nextInt();
    char[] s = scanner.next().toCharArray();
    char[] t = scanner.next().toCharArray();

    if (solve(H, W, N, sr, sc, s, t)) {
      System.out.println("NO");
    } else {
      System.out.println("YES");
    }
  }

  private static boolean solve(int H, int W, int N, int sr, int sc, char[] s, char[] t) {
    int left = 0;
    int right = W + 1;
    for (int i = N - 1; i >= 0; i--) {
      if (i < N - 1) {
        if (t[i] == 'L') right = Math.min(right + 1, W + 1);
        else if (t[i] == 'R') left = Math.max(left - 1, 0);
      }
      if (s[i] == 'L') left = Math.max(left + 1, 1);
      else if (s[i] == 'R') right = Math.min(right - 1, W);
      if (left + 1 >= right) return true;
    }
    if (sc <= left || sc >= right) return true;

    int top = 0;
    int bottom = H + 1;
    for (int i = N - 1; i >= 0; i--) {
      if (i < N - 1) {
        if (t[i] == 'U') bottom = Math.min(bottom + 1, H + 1);
        else if (t[i] == 'D') top = Math.max(top - 1, 0);
      }
      if (s[i] == 'U') top = Math.max(top + 1, 1);
      else if (s[i] == 'D') bottom = Math.min(bottom - 1, H);
      if (top + 1 >= bottom) return true;
    }
    if (sr <= top || sr >= bottom) return true;

    return false;
  }
}


Measured memory_bytes: 28964
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
ll qpow(ll x,ll k){return k==0?1:qpow(x*x%mod,k>>=1)*(k&1?x:1)%mod;}
int n,k;
ll fac[4000111],ifac[4000111];
ll dp[2011][2011];
ll C(ll x,ll y){return fac[x]*ifac[y]%mod*ifac[x-y]%mod;}
int main()
{
	fac[0]=1;
	for(int i=1;i<=4000005;i++)fac[i]=fac[i-1]*i%mod;
	ifac[4000005]=qpow(fac[4000005],mod-2);
	for(int i=4000004;i>=0;i--)ifac[i]=ifac[i+1]*(i+1)%mod;
	cin>>n>>k;
	if(k==1)
	{
		puts("1");
		return 0;
	}
	ll ans=1;
	int cur=0;
	dp[1][1]=1;
	for(int i=2;i<=n;i++)
	{
		for(int j=i;j>=1;j--)
		{
			ll &cur=dp[i][j];
			cur=(dp[i][j+1]+dp[i-1][max(1,j-1)]*C(k*i-j-1,k-2))%mod;
//			cout<<i<<" "<<j<<":"<<cur<<endl;
		}
	}
	cout<<dp[n][1]*fac[n]%mod;
	return 0;
}


Measured memory_bytes: 92928
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int A, B;
    cin >> A >> B;

    bool flag = false;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) flag = true;

    if (flag) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

#define m 101
int A[m][m],n;

int serch(int v)
{
  //printf("bb%dbb",v);
  int i;
  for(i = 0;i < n;i++)
    {
      if(v == A[i][0])
	{
	  return 1;
	}
    }
  return 0;
}

int main()
{
  int i,j;
  int P[m][m];
  scanf("%d",&n);
  for(i = 0;i < m;i++)
    {
      for(j = 0;j < m;j++)
	{
	  A[i][j] = 0;
	  P[i][j] = 0;
	}
    }
  for(i = 0;i < n;i++)
    {
      scanf("%d %d",&A[i][0],&A[i][1]);
      for(j = 2;j < 2+A[i][1];j++)
	{
	  scanf("%d",&A[i][j]);
	}
    }
  /*for(i = 0;i < n;i++)
    {
      for(j = 0;j < 4;j++)
	{
	  printf("%d",A[i][j]);
	}
      printf("\n");
      }*/  // test

  for(i = 0;i < n;i++)
    {
      for(j = 0;j < 2+A[i][1] ;j++)
	{
	  if(j != 0 && j != 1)
	    {
	      if(serch(A[i][j]) == 1)
		{
		  P[i][A[i][j]- 1] = 1;
		  //printf("test %d %d %daa ",A[i][j],i,j);
		}
	      
	    }
	}
    }

  for(i = 0;i < n;i++)
    {
      for(j = 0; j < n ;j++)
	{
	  printf("%d",P[i][j]);
	  if(j != n-1)
	    {
	      printf(" ");
	    }
	}
      printf("\n");
    }
  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#include<queue>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 1123456789012345
using namespace std;

int main(){
	ll n; cin >> n;
	vl count(4,0);
	rep(i, n){
		ll a; cin >> a;
		count[a % 4]++;
	}if (!count[2]){
		if (count[1] + count[3] - count[0] >= 2){
			cout << "No" << endl;
		}
		else{
			cout << "Yes" << endl;
		}
	}
	else{
		if (count[1] + count[3] > count[0]) cout << "No" << endl;
		else cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <vector>
    #include <cstdio>
    using namespace std;
     
    int n;
    long long e,t;
    long long x[100005];
    long long dp[100005];
     
    int main(){
      scanf("%d%lld%lld", &n,&e,&t);
      for(int i=0; i<n; ++i){
        scanf("%lld", &x[i]);
        x[i]<<=1;
      }
      x[n] = e<<1;
     
      long long w = 1ll<<57;
      for(int i=0, j=0; i<n; ++i){
        while(j<i && t < (x[i] - x[j]) ){
          w = min(w, dp[j] + (x[i] - x[j]) );
          j++;
        }
        dp[i+1] = min(w, dp[j] + max((x[i]-x[j]) ,t));
        w += (x[i+1] - x[i]);
      }
      printf("%lld\n", dp[n] + e);
      return 0;
    }

Measured memory_bytes: 1664
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll n;
    ll ans=0;
    cin>>n;
    vc a(n);
    for(int i=0;i<n;i++)
    cin>>a[i];
    sortall(a);
    reverse(all(a));
    ans+=a[0];
    ll flag=0;
    ll i=1;
    ll cnt=1;
    while(cnt<n-1)
    {
      if(flag==2)
      {
        flag=0;
        i++;
      }
      else{
        ans+=a[i];
        flag++;
        cnt++;
      }
    }
    cout<<ans;
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

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

int main(){
    int red, green, blue, k, i;
    cin >> red >> green >> blue >> k;
    for(i=0; i<k; i++){
        if(green <= red){
            green *= 2;
        }else if(green >= red && green >= blue){
            blue *= 2;
        }
    }

    if(red < green && green < blue){
        cout << "Yes" << '\n';
    }else{
        cout << "No" << '\n';    
    }
    return 0;
}

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

// E log V
const int MAXV = 2001;
const int INF = 1e8;
struct edge { int to, cost; edge(int t=0, int c=0):to(t), cost(c) {}  };
int V;
vector<edge> G[MAXV];
int d[MAXV];

// 経路復元
//int prev[MAXV];
int mp[MAXV];

void dijkstra(int s) {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(make_pair(0, s));

    while (!que.empty()) {
        pair<int, int> p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(make_pair(d[e.to], e.to));
                //prev[e.to] = v;
            }
        }
    }
}


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

    int N, X, Y;
    cin >> N >> X >> Y;
    V = N;

    rep(i, N-1) {
        G[i].emplace_back(i+1, 1);
        G[i+1].emplace_back(i, 1);
    }
    X--; Y--;
    G[X].emplace_back(Y, 1);
    G[Y].emplace_back(X, 1);

    rep(i, N) {
        dijkstra(i);
        rep(j, N) mp[d[j]]++;
    }

    for (int i=1; i<N; ++i) {
        cout << mp[i]/2 << endl;
    }

}


Measured memory_bytes: 384
use std::collections::BinaryHeap;
use std::cmp::Reverse;

fn main() {
    let (h, w, k) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse::<usize>().unwrap(),
            iter.next().unwrap().parse::<usize>().unwrap(),
            iter.next().unwrap().parse::<i32>().unwrap(),
        )
    };

    let (start, goal) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            [
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
            ],
            [
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
                iter.next().unwrap().parse::<usize>().unwrap() - 1,
            ],
        )
    };

    let mut pond = Vec::with_capacity(h);
    for _ in 0..h {
        let s: Vec<char> = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            buf.chars().collect()
        };
        pond.push(s);
    }

    let mut heap = BinaryHeap::new();
    heap.push((Reverse(0), start, 0));
    heap.push((Reverse(0), start, 1));
    heap.push((Reverse(0), start, 2));
    heap.push((Reverse(0), start, 3));

    let mut dist = vec![vec![vec![std::i32::MAX; 4]; w]; h];
    dist[start[0]][start[1]][0] = 0;
    dist[start[0]][start[1]][1] = 0;
    dist[start[0]][start[1]][2] = 0;
    dist[start[0]][start[1]][3] = 0;

    let dx = [0, 0, 1, -1];
    let dy = [1, -1, 0, 0];

    while let Some((Reverse(d), [x, y], direction)) = heap.pop() {
        let straight = d + 1;
        let turn = (d + k - 1) / k * k + 1;

        for i in 0..4 {
            let x = x as i32 + dx[i];
            let y = y as i32 + dy[i];
            if x < 0 || y < 0 { continue; }
            let x = x as usize;
            let y = y as usize;
            if x < h && y < w && pond[x][y] == '.' {
                let next = if direction == i { straight } else { turn };
                if next < dist[x][y][i] {
                    dist[x][y][i] = next;
                    heap.push((Reverse(next), [x, y], i));
                }
            }
        }
    }

    let &ans = dist[goal[0]][goal[1]].iter().min().unwrap();
    let ans = if ans == std::i32::MAX { -1 } else { (ans + k - 1) / k };
    println!("{}", ans);
}

Measured memory_bytes: 68880
from collections import deque
import itertools
from scipy.sparse.csgraph import floyd_warshall as wf
import sys


MAX = 1e9


def main():
    n, m, r = map(int, input().split())
    R = list(map(int, input().split()))
    link = [[MAX if j != i else 0 for j in range(n+1)] for i in range(n+1)]
    for i in range(m):
        a, b, c = map(int, input().split())
        link[a][b] = c
        link[b][a] = c
    link = wf(link)
    ans = MAX
    for per in list(itertools.permutations(R)):
        tmp = 0
        for i in range(r-1):
            tmp += link[per[i]][per[i+1]]
        ans = min(ans, tmp)
    print(int(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 19480
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a.sort()
b = sorted([int(str(a[0])+str(a[1])), int(str(a[1])+str(a[0])), int(str(a[0])+str(a[2])), int(str(a[2])+str(a[0])), int(str(a[3])+str(a[0])), int(str(a[0])+str(a[3]))])
print(b[2])


Measured memory_bytes: 5924
import re


def match(s, t):
    pat = "".join(map(lambda x: "({0}|[?])".format(x), list(t)))
    r = re.compile(pat)

    for pos in range(len(s) - len(t), -1, -1):
        m = r.match(s[pos:])
        if m:
            start, end = m.span()
            return (pos+start, pos+end)
    return None

def foo(s, t):
    m = match(s, t)
    if m is None:
        return "UNRESTORABLE"
    start, end = m
    r = s[:start] + t + s[end:]
    return r.replace("?", "a")


if __name__ =="__main__":
    s = input()
    t = input()
    print(foo(s, t))


    


Measured memory_bytes: 3188
file = File.exist?('in.in') ? File.new('in.in','r') : STDIN
n, k = file.gets.chomp.split.map(&:to_i)
vec = file.gets.chomp.split.map(&:to_i)

INF = 4611686018427387903
dp = Array.new(n, INF)

dp[0] = 0

for i in 1...vec.size
  j=1
  while(j<=k && i-j >= 0)
    c = dp[i-j]+(vec[i-j]- vec[i]).abs
    dp[i] = c if c < dp[i]
    j+=1
  end
end

puts dp.last


Measured memory_bytes: 11148
#include "bits/stdc++.h"
using namespace std;

const int INF=1e9+5;

int main()
{
    int n;
    cin>>n;
    vector<int>dp(3,0);
    for(int i=0;i<n;i++)
    {
        vector<int>new_dp(3);
        vector<int>c(3);
        for(int j=0;j<3;j++)
        {
            cin>>c[j];
        }
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<3;j++)
            {
                if(i!=j)
                new_dp[j]=max(new_dp[j],dp[i]+c[j]);
            }
        }
        dp=new_dp;
    }
    cout<<max({dp[0],dp[1],dp[2]});
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


struct Node{
    int val;
    Node *lch, *rch;
    Node(int x = 0) : val(x),lch(nullptr), rch(nullptr){}
};

Node* add(Node* l,Node* r){
    Node* ret = new Node;
    ret->val = l->val + r->val;
    if(l->lch&&r->lch){
        ret->lch = add(l->lch, r->lch);
    }
    if(l->rch&&r->rch){
        ret->rch = add(l->rch, r->rch);
    }
    return ret;
}

Node* ston(string& s,int& idx){
    if(s[idx]==')'){
        idx++;
        return nullptr;
    }
    ++idx;
    auto lch = ston(s,idx);
    ++idx;
    int val=0;
    while(s[idx]!=']'){
        val=10*val+s[idx]-'0';
        ++idx;
    }
    ++idx;
    ++idx;
    auto rch = ston(s,idx);
    ++idx;
    Node* ret = new Node(val);
    if(lch)ret->lch = lch;
    if(rch)ret->rch = rch;

    return ret;
}
string itos(int a){
    if(a==0)return "0";
    string res="";
    while(a){
        res=char(a%10+'0')+res;
        a/=10;
    }
    return res;
}
string ntos(Node* t){
    string ret;
    ret+='(';
    if(t->lch)ret+=ntos(t->lch);
    ret+=")[";
    ret+=itos(t->val);
    ret+="](";
    if(t->rch)ret+=ntos(t->rch);
    ret+=')';
    return ret;
}
int main(){
    string s,t;
    cin>>s>>t;
    int is=0,it=0;
    auto ss = ston(s,is);
    auto tt = ston(t,it);
    auto uu = add(ss,tt);
    auto ans = ntos(uu);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3228
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int e = sc.nextInt();
			if (e == 0)
				break;
			int m = Integer.MAX_VALUE;
			double sq = Math.sqrt(e);
			double tr = Math.pow(e, 1.0 / 3);
			for (int y = 0; y <= sq + 1; y++) {
				for (int z = 0; z <= tr + 1; z++) {
					if (y * y + z * z * z > e)
						break;
					int tmp = e - (y * (y - 1) + z * (z * z - 1));
					if (tmp > 0)
						m = Math.min(m, tmp);
				}
			}
			System.out.println(m);
		}
	}
}

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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n;

bool is_prime(int x)
{
	if (x < 2) return false;
	if (x == 2) return true;
	for (int i = 2; i <= x / i; i ++ )
		if (x % i == 0)
			return false;
	return true;
}

int main()
{
	cin >> n;
	for (int i = 2; i; i ++ )
		if (i % 5 == 1 && is_prime(i))
		{
			cout << i << ' ';
			if ( -- n == 0) return 0;
		}
    return 0;
}

Measured memory_bytes: 3584
n,m = map(int,input().split())
s = [[int(i) for i in input().split()] for i in range(m)]
d = {}

for i in range(m):
    if s[i][0] == 1:
        d[s[i][1]] = 1
    
for i in range(m):
    if s[i][1] == n and s[i][0] in d:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")

Measured memory_bytes: 45456
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

import random


def main():
    n = int(input().strip())
    s = input().strip()
    max_cnt=0
    for i in range(1,n):
        s1=set(s[0:i])
        s2=set(s[i:n])
        ss = s1 & s2
        cnt=len(ss)
        max_cnt=max(max_cnt,cnt)
    print(max_cnt)
    return

if __name__ == '__main__':
    main()


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve(){
    int n;
    cin >> n;
    int res=1;
    rep(i,0,n){
        int a;
        cin >> a;
        res=lcm(res,a);
    }
    cout << res << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 3208