akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
LL dp[3010][3010];
LL comb[3010][3010];
LL mod_pow(LL a, LL b,LL mod) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		LL t = mod_pow(a, b / 2, mod);
		return (t*t) % mod;
	}
	return (a*mod_pow(a, b - 1, mod)) % mod;
}
LL f(int N,int k,LL mod) {
	LL ans = 0;
	LL a = mod_pow(2, N - k, mod);
	LL b = 1;
	for (int i = 0; i <= k; i++) {
		LL t = (dp[k][i] * b) % mod;
		(b *= a) %= mod;
		(ans += t) %= mod;
	}
	(ans *= mod_pow(2, mod_pow(2, N - k, mod - 1), mod)) %= mod;
	return ans;
}
int main() {
	int N, M;
	cin >> N >> M;
	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		dp[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			(dp[i][j] += dp[i - 1][j]) %= M;
			(dp[i][j] += dp[i - 1][j] * j) %= M;
			(dp[i][j] += dp[i - 1][j - 1]) %= M;
		}
	}
	comb[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		comb[i][0] = comb[i][i] = 1;
		for (int j = 1; j < i; j++) {
			(comb[i][j] += comb[i - 1][j]) %= M;
			(comb[i][j] += comb[i - 1][j - 1]) %= M;
		}
	}
	LL ans = 0;
	LL minus = 0;
	for (int i = 0; i <= N; i++) {
		LL t = f(N, i, M);
		(t *= comb[N][i]) %= M;
		if (minus) (t *= M - 1) %= M;
		minus ^= 1;
		(ans += t) %= M;
	}
	cout << ans << endl;
}

Measured memory_bytes: 139904
n=int(input())
p=list(map(float,input().split()))
P=[[0]*(n+3) for i in range((n+1)//2)]
P[0][2]=1-p[0]
P[0][3]=p[0]
for i in range(1,(n-1)//2+1):
  a=(1-p[2*i-1])*(1-p[2*i])
  b=(1-p[2*i-1])*p[2*i]+p[2*i-1]*(1-p[2*i])
  c=p[2*i-1]*p[2*i]
  for j in range(2,n+3):
    P[i][j]=P[i-1][j]*a+P[i-1][j-1]*b+P[i-1][j-2]*c
ans=0
for i in range((n+1)//2):
  ans=ans+P[-1][-1-i]
print(ans)

Measured memory_bytes: 146440
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;

int main (){
  int K;
  string S;
  cin>>K>>S;
  int n;
  n=S.length();
  if(n<=K) cout<<S;
  else{
    rep(i,K){
      cout<<S[i];
    }
    cout<<"...";
  }
}


Measured memory_bytes: 3620
n, k = map(int, input().split())
x = list(map(int, input().split()))

ans = 1000000000
for i in range(n - k + 1):
    if x[i] * x[i + k - 1] < 0:
        ans = min(ans, min(abs(x[i]), abs(x[i + k - 1])) * 2 + max(abs(x[i]), abs(x[i + k - 1])))
    else:
        ans = min(ans, max(abs(x[i]), abs(x[i + k - 1])))

print(ans)

Measured memory_bytes: 14384
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

#define T int

class Dijkstra {
public:
	struct edge{
		int to; T cost;
	};
	vector<vector<edge> > G;
	vector<T> d;
	int V;
	using pti = pair<T,int>;
	Dijkstra(int node_size){
		V = node_size;
		G.resize(V),d.resize(V,numeric_limits<T>::max());
	}
	//無向グラフの場合
	void add_edge(int u,int v,T cost){
		G[u].pb((edge){v,cost});
	}
	void solve(int s){
		priority_queue<pti> que;
		d[s] = 0;
		que.push(pti(0,s));
		while(!que.empty()){
			pti p = que.top();
			que.pop();
			int v = p.second;
			if(d[v] < -p.first) continue;
			for(auto& w : G[v]){
				if(d[w.to] > d[v] + w.cost){
					d[w.to] = d[v] + w.cost;
					que.push(pti(-d[w.to],w.to));
				}
			}
		}
	}
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, r;
    cin >> n >> m >> r;
	Dijkstra dj(n);
	rep(i,m){
		int a,b,c;
		cin >> a >> b >> c;
		dj.add_edge(a, b, c);
	}
	dj.solve(r);
	each(val,dj.d){
		if(val == numeric_limits<T>::max()){
			cout << "INF\n";
		}else{
			cout << val << "\n";
		}
	}
    return 0;
}



Measured memory_bytes: 12840
#include <stdio.h>

int main(){
  int A; scanf("%d", &A);
  int B; scanf("%d", &B);
  int K; scanf("%d", &K);

  int div[51] = {};
  int small, i;
  int count = 0;
  small = A <= B ? A : B;

  for(i = small; i > 0; i--){
    if(A % i == 0 && B % i == 0){
      count++;
      div[count] = i;
    }
  }

  printf("%d", div[K]);

  return 0;
}
  
  


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
int main(void){
	int x,a,b,aa,bb;
	cin>>x>>a>>b;
	aa=abs(x-a); bb=abs(x-b);
	if(aa<bb) cout<<"A"<<endl;
	else cout<<"B"<<endl;
	return 0;
}

Measured memory_bytes: 256
import heapq

N,M = map(int,input().split())

A = [int(i)*-1 for i in input().split()]
heapq.heapify(A)

for _ in range(M):
  max = heapq.heappop(A) * -1
  heapq.heappush(A,(max//2)*-1)





print(sum(A)*-1)  




Measured memory_bytes: 14184
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd1 = readln.split.to!(size_t[]), n = rd1[0], m = rd1[1];

  auto uf = new UnionFind!size_t(n);
  foreach (_1; m.iota) {
    auto rd2 = readln.chomp.splitter(' ');
    auto s = rd2.front.to!size_t; rd2.popFront;
    auto t = rd2.front.to!size_t;
    uf.unite(s, t);
  }

  auto q = readln.chomp.to!size_t;
  foreach (_2; q.iota) {
    auto rd2 = readln.chomp.splitter(' ');
    auto s = rd2.front.to!size_t; rd2.popFront;
    auto t = rd2.front.to!size_t;
    writeln(uf.find(s) == uf.find(t) ? "yes" : "no");
  }
}

class UnionFind(T)
{
  T[] p; // parent
  T s; // sentinel

  this(T n) {
    p = new T[](n);
    s = n + 1;
    p[] = s;
  }

  T find(T i) {
    if (p[i] == s) {
      return i;
    } else {
      p[i] = find(p[i]);
      return p[i];
    }
  }

  void unite(T i, T j) {
    auto pi = find(i), pj = find(j);
    if (pi != pj) p[pj] = pi;
  }
}

Measured memory_bytes: 3992
N = int(input())
T, A = map(int,input().split())
H = list(map(int,input().split()))
best = 1000.0
point = 0
ans = 0
for i in range(N):
    ans = abs(A - (T - H[i]*0.006))
    if best > ans:
        best = ans
        point = i + 1
print(point)


Measured memory_bytes: 9116
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy


if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    ans = 0
    for i in range(n):
        if i%2 == 0 and a[i]%2 == 1:
            ans+=1
    print(ans)

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


vector <ll> final;
void generate(ll m, ll num) {
	queue <ll> q;
	q.push(num);


	while (!q.empty()) {
		ll ind = q.front();
		q.pop();
		if (ind <= m)
			final.push_back(ind);
		if (num == 0 || ind > m)
			continue;

		ll lastdigit = ind % 10;
		ll up = ind * 10 + (lastdigit - 1);
		ll down = ind * 10 + (lastdigit + 1);
		ll right = ind * 10 + lastdigit;

		if (lastdigit == 0) {
			q.push(down);
			q.push(right);
		} else if (lastdigit == 9)  {
			q.push(up);
			q.push(right);
		} else {
			q.push(up);
			q.push(right);
			q.push(down);
		}
	}


}
int main() {
	ios::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);


	ll inf = 1e11;

	ll n;	cin >> n;

	for (int i = 0; i < 10; i++) {
		generate(inf, i);
	}
	sort(final.begin(), final.end());
	cout << final[n] << endl;

	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int n,a[2001];
int memo1[2001],memo2[2001];

int dfs2(int);

int dfs1(int i){
	if(~memo1[i]) return memo1[i];

	int res=abs(a[n-1]-a[i-1]);
	for(int j=i;j<n-1;j++) res=max(res,dfs2(j+1));
	return memo1[i]=res;
}

int dfs2(int i){
	if(~memo2[i]) return memo2[i];

	int res=abs(a[n-1]-a[i-1]);
	for(int j=i;j<n-1;j++) res=min(res,dfs1(j+1));
	return memo2[i]=res;
}

int main(){
	int dummy; scanf("%d%*d%d",&n,a);
	rep(i,n) scanf("%d",a+i+1);
	n++;

	memset(memo1,-1,sizeof memo1);
	memset(memo2,-1,sizeof memo2);

	cout<<dfs1(1)<<endl;

	return 0;
}


Measured memory_bytes: 384
using System;

class A{
	public static void Main(){

		int input = int.Parse(Console.ReadLine ());

		for (int i=1; i<=input; i++) {
			string s = i.ToString();
			if ((i % 3 == 0) || s.Contains("3") ) {
				Console.Write (" " + i);
			}

		}
		Console.WriteLine ();
	}

}

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

int main() {
    int n, m;
    cin >> n >> m;

    int x[m];
    int dx[m - 1];

    for (int i = 0; i < m; i++) cin >> x[i];
    sort(x, x + m);

    for (int i = 0; i < m - 1; i++) {
        dx[i] = abs(x[i + 1] - x[i]);
    }

    /*
    for (int i = 0; i < m; i++) {
        cout << x[i] << endl;
    }
        cout << "---" << endl;
    for (int i = 0; i < m - 1; i++) {
        cout << dx[i] << endl;
    }
    */

    sort(dx, dx + (m - 1), greater<int>());

    int ans = 0;
    for (int i = 0; i < m - 1; i++) {
        if (i < n - 1) {
            continue;
        }
        ans += dx[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
N, M, X = map(int, input().split())
C = [0] * N
A = [[0] * M] * N

for i in range(N):
    S = list(map(int, input().split()))
    C[i] = S[0]
    A[i] = S[1:]

smallest = None
for i in range(2 ** N):
    sum = 0
    Algo = [0] * M
    for j in range(N):
        if (i >> j) & 1:
            sum += C[j]
            for m in range(M):
                Algo[m] += A[j][m]
    if all(e >= X for e in Algo):
        if smallest == None:
            smallest = sum
        elif sum < smallest:
            smallest = sum

if smallest == None:
    print(-1)
else:
    print(smallest)


Measured memory_bytes: 9196
#coding:utf-8

S_1 = 0
S_2 = 0
S_min = 0

N = int(input())
W = list(map(int,input().split()))

for i in range(N):
    S_min += W[i]

for T in range(N):
    for i in range(0,T+1):
        S_1 += W[i]
    for j in range(T+1,N):
        S_2 += W[j]

    S = abs(S_2 - S_1)
    
    if S < S_min:
        S_min = S

    S_1 = 0
    S_2 = 0
    S = 0


print(S_min)

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int main(){
    fcin;
    char c;
    cin >> c;
    cout << char(c+1) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
string s;
vector<int> v;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0); 
  cin >> s;
  int len = s.length();
  int l, r;
  if(len % 2 == 0) {
    l = len / 2 - 1;
    r = len / 2;
  } else {
    l = len / 2;
    r = len / 2;
  }
  int ans = len / 2;
  char c = s[l];
  while(l >= 0 && r < len && s[l] == c && s[r] == c) {
    l--;
    r++;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T>
    inline std::vector<T> read(std::size_t n)
    {
        std::vector<T> res;
        res.reserve(n);

        for (std::size_t i = 0; i < n; ++i) {
            T tmp;
            cin >> tmp;
            res.emplace_back(tmp);
        }
        return res;
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

    template <class T, class... Args>
    void impl(T&& v, Args&&... args)
    {
        cout << std::forward<T>(v) << ' ';
        impl(std::forward<Args>(args)...);
    }
    template <class T>
    void impl(T&& v)
    {
        cout << std::forward<T>(v);
    }

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class... Args>
    void operator()(Args&&... args)
    {
        impl(std::forward<Args>(args)...);
        cout << '\n';
    }
    template <class... Args>
    void noreturn(Args&&... args)
    {
        impl(std::forward<Args>(args)...);
    }

    template <class T>
    void print(const T& container)
    {
        bool first = true;
        for (auto&& x : container) {
            if (!first) {
                cout << ' ';
            }
            cout << x;
            first = false;
        }
        cout << '\n';
    }
};

void prog()
{
    input in;
    output out;
    int a, b, c;
    in >> a, b, c;
    std::set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);

    out(s.size() == 2 ? "Yes" : "No");
}

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


Measured memory_bytes: 256
#dpより愚直に作るか
k = int(input())
lun = [i for i in range(10)]
while len(lun)<k+1:#正の整数
    lun2 = []
    for i in lun:
        lun2.append(i*10+(i%10))
        if i%10:
            lun2.append(i*10+(i%10)-1)
        if (i%10)<9:
            lun2.append(i*10+(i%10)+1)
    lun = list(set(lun+lun2))
lun.sort()
print(lun[k])

Measured memory_bytes: 88428
#include <iostream>
#include <string>

int main()
{
    int N;
    std::cin >> N;
    double res = 0;

    for (int i = 0; i < N; ++i)
    {
        double x;
        std::string u;

        std::cin >> x >> u;

        if (u == "JPY")
        {
            res += x;
        }
        else if (u == "BTC")
        {
            res += x * 380000;
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int X,A,B;cin >> X >> A >> B;
    X -= A;
    cout << X%B << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>

using namespace std;
using ll = long long int;

int main()
{
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i = 0; i < n; i++)
  {
    cin >> s[i];
  }
  int abnum = 0;
  int aend = 0;
  int bstart = 0;
  bool abonly = false;
  for(int i = 0; i < n; i++)
  {
    if(s[i].front() == 'B' && s[i].back() == 'A') abonly = true;
  }
  for(int i = 0; i < n; i++)
  {
    if(s[i].front() == 'B') bstart++;
    if(s[i].back() == 'A') aend++;
    if(s[i].front() == 'B' && s[i].back() != 'A')  abonly = false;
    if(s[i].front() != 'B' && s[i].back() == 'A')  abonly = false;
    for(int j = 0; j < s[i].size() - 1; j++)
    {
      if(s[i][j] == 'A')
      {
        if(s[i][j + 1] == 'B'){
          abnum++;
        }
      }
    }
  }
  if(abonly)
  {
    cout << abnum + min(aend, bstart) - 1 << endl;
  }else{
    cout << abnum + min(aend, bstart) << endl;
  }
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
  int n;
  int p, d1, d2;
  int i;
  int sum, max, mnum;

  while (1){
    scanf("%d", &n);

    if (n == 0){
      break;
    }

    for (i = 0;i < n;i++){
      scanf("%d %d %d", &p, &d1, &d2);

      // if (d1 != d2){
        sum = d1 + d2;
        if (i == 0){
          max = sum;
          mnum = p;
        }
        else {
          if (max < sum){
            max = sum;
            mnum = p;
          }
        }
    }

    printf("%d %d\n", mnum, max);
  }

  return 0;
}
            

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <ctime>
#include <sstream>
#include <fstream>
#include <bitset>
#include <iomanip>
#include <assert.h>

using namespace std;

typedef long long int64;
typedef long long LL;
typedef long double real;
typedef long double LD;

#define mp make_pair
#define PII pair<int, int>
#define pb push_back
#define sz(X) ((int)((X).size()))

#define x first
#define y second

const double eps = 1e-8;
const double PI = acos(0.) * 2;
const int lim = 1000000000;
const int inf = ~0U >> 1;

template<class T> T abs(T x){return x < 0 ? -x : x;}

const int N = 1005;

int x[N], y[N], r[N], c[N];
short f[1 << 24];
int ans, n, fail[N];
map<int, int> p;

int low(int i){return i & -i;}

int dfs(int state)
{
    if (f[state] != -1) return f[state];
    f[state] = 0;
    for (int s1 = state, ii = s1 & -s1; ii; s1 ^= ii, ii = s1 & -s1)
    {
        int i = p[ii];
        if (!(state & (1 << i))) continue;
        if (fail[i] & state) continue;
        for (int s2 = s1 ^ ii, jj = s2 & -s2; jj; s2 ^= jj, jj = s2 & -s2)
        {
            int j = p[jj];
            if (!(state & (1 << j))) continue;
            if (fail[j] & state) continue;
            if (c[i] != c[j]) continue;
            int t = dfs(state ^ (1 << i) ^ (1 << j)) + 2;
            if (t > f[state])
                f[state] = t;
        }
    }
    return f[state];
}

int main(){
    #ifdef edly
        freopen("input.txt", "r", stdin);
	#endif
    while (1)
    {
        scanf("%d", &n);
        if(n == 0) break;
        for (int i = 0; i <n; ++i)
            scanf("%d%d%d%d", &x[i], &y[i], &r[i], &c[i]);
        for(int i = 0; i < n; ++i)
        {
            fail[i] = 0;
            for (int j = 0; j < i; ++j)
            {
                int dx = abs(x[i] - x[j]);
                int dy = abs(y[i] - y[j]);
                int dis = dx * dx + dy * dy;
                int rr = r[i] + r[j];
                if (dis < rr * rr)
                    fail[i] |= (1 << j);
            }
            p[1 << i] = i;
        }
        ans = 0;
        for (int i = 0; i < (1 << n); ++i)
            f[i] = -1;
        ans = dfs((1 << n) - 1);
        printf("%d\n", ans);
    }
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  string s,t;
  cin >> s >> t;
  if(s.size() < t.size()){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  int t_ = t.size();
  for(int i = s.size()-1;i >= 0;i--){
    string k = s;
    bool is = true;
    for(int j = 0;j < t_;j++){
      if(i-j < 0){
        is = false;
        break;
      }
      if(k[i-j] == t[t_-j-1])continue;
      else if(k[i-j] == '?')k[i-j] = t[t_-j-1];
      else {
        is = false;
        break;
      }
    }
    if(is){
      rep(j,s.size())if(k[j] == '?')k[j] = 'a';
      cout << k << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;



  return 0;
}

Measured memory_bytes: 256
def solve():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())
                
    print(sum(X == (500*a)+(100*b)+(50*c) for a in range(0, A+1) for b in range(0, B+1) for c in range(0, C+1) if a+b+c >= 0))
    
solve()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
vector<long long> factors;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
vector<ll> a;
ll dp[3003][3003] = {-1};
int n;

ll count(ll l,ll r){
	if(dp[l][r] != -LL_INF){
		return dp[l][r];
	}else{
		if((r - l + 1)%2 == n % 2){
			if(l == r)
				dp[l][r] = a[l];
			else{
				dp[l][r] = max(count(l + 1,r) + a[l],count(l,r-1) + a[r]);
			}
		}else{
			if(l == r)
				dp[l][r] = -a[l];
			else{
				dp[l][r] = min(count(l + 1,r) - a[l],count(l,r-1) - a[r]);
			}
		}
	}
	return dp[l][r];
}

int main()
{
	IOS
	for(int i = 0 ;i < 3003; ++i){
		for(int j = 0;j < 3003; ++j){
			dp[i][j] = -LL_INF;
		}
	}
	cin >> n;
	a.resize(n + 1);
	for(int i = 1;i < n+1; ++i){
		cin>> a[i];
	}

	cout << count(1,n);

	return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int nex[N][30], n;
char s[N], t[N];
long long solve() {
  long long ans = 0, cnt = 0, las = -1;
  for (int i = 0, cur = -1; t[i]; i++) {
    cur = nex[(cur + 1) % n][t[i] - 'a'];
    if (cur >= 0) {
      if (cur <= las) cnt++;
      las = cur;
    } else return -1;
  }
  return cnt * n + las + 1;
}
int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> s >> t;
  n = strlen(s);
  memset(nex, -1, sizeof nex);
  for (int i = 2 * n - 1; i >= 0; i--) {
    int idx = i % n;
    for (int j = 0; j < 26; j++)
      nex[idx][j] = nex[(i + 1) % n][j];
    nex[idx][s[idx] - 'a'] = idx;
  }
  cout << solve() << endl;
}


Measured memory_bytes: 12160
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int unsigned long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2884&lang=jp


signed main(){
	cout<<fixed<<setprecision(10);
	
	while(true){
		int N;
		int d = 1, sum = 0;
		int fn = 1, sn = -1;
		
		string res;
		
		cin>>N;
		
		if(!N) break;
		
		for(;; d++){
			sum += 81ll * ((1ll<<(d-1)) - 1);
			
			if(sum >= N) {
				sum -= 81ll * ((1ll<<(d-1)) - 1);
				break;
			}
		}
		
		
		res.resize(d, '0');
		
		for(;;fn++){
			sum += 9 * ((1ll<<(d-1)) - 1);
			
			if(sum >= N) {
				res[0] = '0' + fn;
				sum -= 9 * ((1ll<<(d-1)) - 1);
				break;
			}
		}
		
		for(int i = 1; i < d; i++){
			if(sn == -1) {
				int j;
				for(j = 0; j < 10; j++){
					if(j != fn) {
						sum += ((1ll<<(d-i-1)));
					} else {
						sum += 9 * ((1ll<<(d-i-1)) - 1);
					}
					
					if(sum >= N) {
						res[i] = '0' + j;
						if(j != fn) {
							sum -= ((1ll<<(d-i-1)) );
						} else {
							sum -= 9 * ((1ll<<(d-i-1)) - 1);
						}
						
						break;
					}
					
					
				}
				
				if(j != fn) {
					sn = j;
					if(sn > fn) swap(fn, sn);
				}
			} else {
				
				int a = sum + ((1ll<<(d-i-1)));
				
				if(N <= a) {
					res[i] = '0' + sn;
				} else {
					sum = a;
					res[i] = '0' + fn;
				}
			}
		}
		
		cout<<res<<endl;
		
	}
	
	
	
	return 0;
}


Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;
struct xydata {
    int x; int y;
};

bool cmp(const xydata &l, const xydata &r) {
    return l.x == r.x ? l.y < r.y : l.x < r.x;
}

int main() {
    cin >> n;
    vector<xydata> abvec(n);
    vector<xydata> cdvec(n);
    for(int i = 0; i < n; ++i) cin >> abvec.at(i).x >> abvec.at(i).y;
    for(int i = 0; i < n; ++i) cin >> cdvec.at(i).x >> cdvec.at(i).y;

    sort(abvec.begin(), abvec.end(), cmp);
    sort(cdvec.begin(), cdvec.end(), cmp);

    int cnt = 0;
    vector<bool> abft(n, false);
    for(int i = 0; i < n; ++i) {
        int bmax = 0;
        int abno = -1;
        for(int j = 0; j < n; ++j) {
            if(abvec.at(j).x < cdvec.at(i).x && !abft.at(j)) {
                if(abvec.at(j).y < cdvec.at(i).y) {
                    if(abvec.at(j).y >= bmax) {
                        bmax = abvec.at(j).y;
                        abno = j;
                    }
                }
            }   
        }
        if(abno != -1) {
            cnt++;
            abft.at(abno) = true;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    x = A[0]
    y = sum(A[1:])
    diff_min = abs(x-y)

    for i in range(1, N-1):
        x += A[i]
        y -= A[i]
        diff_min = min(diff_min, abs(x-y))

    print(diff_min)

if __name__ == "__main__": main()


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

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

  vector<pair<int, int>> p(n);

  for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;

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

  double d = 0.0, m = 0.0;

  do {
    m++;
    for (int i = 0; i < n - 1; i++) {
      d += sqrt(pow(p[i].first - p[i + 1].first, 2) +
                pow(p[i].second - p[i + 1].second, 2));
    }
  } while (next_permutation(p.begin(), p.end()));

  cout << fixed << setprecision(7) << d / m << endl;
}

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      a: usize,
      b: usize,
      c: usize,
    }
    let mut ans = a-b;
    let d = min(a-b, c);
    puts!("{}\n", c-d);
}


Measured memory_bytes: 4352
import sys
from collections import namedtuple
from typing import List

sys.setrecursionlimit(2 ** 20)


R = namedtuple('R', 'a b c d')

N, M, Q = map(int, input().split())
requirements: List[R] = []

for _ in range(Q):
  a, b, c, d = map(int, input().split())
  requirements.append(R(a, b ,c, d))

max_score = 0

def dfs(A):
  global max_score
  if len(A) > N + 1:
    score = 0
    for a, b, c, d in requirements:
      if A[b] - A[a] == c:
        score += d
    max_score = max(max_score, score)
    return
  for i in range(A[-1], M + 1):
    dfs(A + [i])

dfs([1])
print(max_score)


Measured memory_bytes: 10168
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

char s[200010];
bool a[200010];

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,k;scanf("%d%d",&n,&k);
	scanf("%s",s);
	for (int i=0;i<n;i++) a[i]=(s[i]=='B');
	int x=0,st=a[0];
	while (x<n&&k)
	{
		k--;
		if (!st) {st=1;continue;}
		x++;
		if (x<n) st=a[x]^(x&1); else st=(n&1)^1;
	}
	if (k)
	{
		if (!st) st^=(k&1);
	}
	putchar(st+'A');
	for (int i=1;i<n;i++)
		if (i+x<n) putchar((a[i+x]^(x&1))+'A'); else putchar(((n-i+1)&1)+'A');
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5+7;
bool pal(string x, int l, int r){
    string t = x;
    reverse(&x[l], &x[r]+1);
    for(int i = l;i <= r;i++){
        if(x[i] != t[i]){
            return 0;
        }
    }
    return 1;
}

int main(){
    string x;
    cin >> x;
    int n = x.size();
    x.insert(0, "*");
    if(pal(x, 1, (n-1)/2) && pal(x, (n+3)/2, n) && pal(x,1, n)){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }

}
/*
akasaka


*/


Measured memory_bytes: 256
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    S = input()
    logging.info("Hello!")

    answer = ""
    for c in S:
        num = ord(c) + N
        if num <= 90:
            answer += chr(num)
        else:
            num = num - 90 + 64
            answer += chr(num)

    print(answer)
            
if __name__ == "__main__":
    main()


Measured memory_bytes: 4448
/*
   Author: Shivam Shukla
*/
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
 
const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string 
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >
 
template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow_mod(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}
 

int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock();
 
    int r; cin >> r;
    cout << (2.0 * PI * r) << endl;  
  
    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl; 
    return 0; 
}

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

#include <iostream>
#include <string>

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

#define PB push_back
#define MP make_pair

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

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

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

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

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

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

int N, K;

int main() {
    cin >> N >> K;
    int d = floor(log(N) / log(K)) + 1;
    cout << d << endl;
    return 0;
}


Measured memory_bytes: 384
n=int(input())
a=0
b=0
ab=0
ans=0
for i in range(n):
    s=input()
    m=len(s)
    m-=len(s.replace("AB",""))
    m//=2
    ans+=m
    if s[0]=="B" and s[-1]=="A":
        ab+=1
    elif s[0]=="B":
        b+=1
    elif s[-1]=="A":
        a+=1

if a+b>0:
    print(ans+min(a,b)+ab)
else:
    print(ans+max(0,ab-1))

Measured memory_bytes: 3064
/* Quick Note :
 * Jangan Mikir Lama - lama, sampahin dulu aja kalo OI
 * Always Try to reset
*/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll nax = 1e5 + 5;

ll n, a, b;
ll h[nax];

ll cek(ll x){
	ll dif = a - b;
	ll cnt = 0;
	for(ll i = 1; i <= n; i++){
		ll res = b * x;
		if(res >= h[i]){
			continue;
		}
		else{
			ll need = (h[i] - res + dif - 1) / dif;
			cnt += need;
		}
	}
	return cnt <= x;
}

int main(){ 
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    
    cin >> n >> a >> b;
    for(ll i = 1; i <= n; i++){
		cin >> h[i];
	}
	sort(h + 1, h + 1 + n);
	ll ans = inf;
	ll l = 1, r = 1e9;
	while(l <= r){
		ll mid = (l + r) / 2;
		if(cek(mid)){
			ans = min(ans, mid);
			r = mid - 1;
		}
		else{
			l = mid + 1;
		}
	}
	cout << ans << '\n';
}


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

using namespace std; 

int main() {
    int n,i,j,k,a;
    cin>>n;
    i=0,a=1000000000;
    int arr[n];
    while(i<n){
      cin>>arr[i];
      i++;
    }
    sort(arr,arr+n);
    i=0;
    k=arr[n-1];
    while(i<n-1){
      j=arr[i];
      if(__gcd(j,k)<a)
        a=__gcd(j,k);
      i++;
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(int argc, const char * argv[]){
    int i=1;
    int t;
    int x[10001]={};
    while(1){
        scanf("%d", &x[i]);
        if (x[i]==0) {
            break;
        }
        i++;
    }
    for(t=1;t<i;t++){
        printf("Case %d: %d\n", t,x[t]);
    }
    return 0;
}

Measured memory_bytes: 648
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt64(scanner)
	a := getNextInt64(scanner)
	b := getNextInt64(scanner)

	d := b - a
	if d%2 == 0 {
		fmt.Println(d >> 1)
		return
	}
	dd := a - 1
	if dd > n-b {
		dd = n - b
	}

	fmt.Println(dd + 1 + d>>1)

	writer.Flush()
}


Measured memory_bytes: 640
from itertools import permutations
from scipy.sparse.csgraph import floyd_warshall

n,m,R=map(int,input().split())
r=list(map(int,input().split()))
s=[[0]*n for i in range(n)]
for i in range(m):
    a, b, c = list(map(int, input().split()))
    a, b = a-1, b-1
    s[a][b] = c
    s[b][a] = c
s=floyd_warshall(s)   

ans=float('inf')
for i in permutations(r):
    an=0
    for j in range(R-1):
        an+=s[i[j]-1][i[j+1]-1]
    ans=min(ans,an)
print(int(ans))

Measured memory_bytes: 15380
#include <algorithm>
#include <iostream>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

const ll INF = LONG_LONG_MAX / 2;

vector<ll> A;
vector<vector<ll>> dp;

int main(void) {
    int N;
    cin >> N;
    A.resize(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }

    dp.resize(N + 1, vector<ll>(2, -INF));
    dp[0][0] = 0;

    for (int i = 1; i <= N; i++) {
        chmax(dp[i][0], dp[i - 1][0] + A[i]);
        chmax(dp[i][0], dp[i - 1][1] - A[i]);

        chmax(dp[i][1], dp[i - 1][0] - A[i]);
        chmax(dp[i][1], dp[i - 1][1] + A[i]);
    }

    // for (int i = 0; i <= N; i++) {
    //     for (int j = 0; j <= 1; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;

    cout << dp[N][0] << endl;

    return 0;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> bool chmax(T &a,T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int n,ans=INF;
    cin>>n;
    Vi a(n);
    REP(i,0,n) cin>>a[i];
    REP(i,0,n){
        int t=0;
        REP(j,0,n){
            if(j<=i) t+=a[j];
            else t-=a[j];
        }
        if(ans>abs(t)) ans=abs(t);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int	main(void)
{
  	int	x;
  	int	n;
  	int	p[102];
  	int	q[20004];
  	int	i;
  	int num;
   	int	tmp;
  
  	for (i=1; i<=100; i++)
    {
        p[i] = 0;
    }
    
    for (i=1; i<=20000; i++)
    {
        q[i] = i - 10000;
    }

  	scanf("%d %d\n", &x, &n);
  	for (i=1; i<=n; i++)
    {
      	scanf("%d", &p[i]);
    }
  	
  	for (i=1; i<=100; i++)
    {
      	if (p[i] > 0)
        {
          	q[ p[i] + 10000 ] = 10000;
        }
    }
  
  	num = 0;
  	tmp = 1000;
  	for (i=1; i<=20000; i++)
    {
      	if (tmp > abs( q[i] - x ) )
        {
          	tmp = abs( q[i] - x );
        	num = i - 10000;
 //       	printf("%d %d, ", num, tmp);
        }
    }
  
  	printf("%d", num);
  	return (0);
}

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

int mymin(int x, int y, int z){
  int p;
  int q;  
  p = min(x,y);
  q = min(p,z);  
  return q;
}
int main(){
  int n;
  int x;
  int y;

  cin >> n >> x >> y;

  vector<int> ans(n);

  for(int i = 1;i<n;i++){
    for(int j=i+1;j<=n;j++){
      int d = mymin(abs(j-i),abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x));
      ans.at(d)++;
    }  
  }

  for(int i=1;i<n;i++){
    cout << ans.at(i) << endl;
  }

}

Measured memory_bytes: 256
local n = io.read("*n")
local edge = {}
for i = 1, n do
  for j = 1, n do
    edge[(i - 1) * n + j] = io.read("*n")
  end
end
local totallen = 0
local err = false
for dst = 2, n do
  for src = 1, dst - 1 do
    local sdlen = edge[(src - 1) * n + dst]
    local shortest = true
    for mid = 1, n do
      if src ~= mid and dst ~= mid then
        local smlen, mdlen = edge[(src - 1) * n + mid], edge[(mid - 1) * n + dst]
        if smlen + mdlen < sdlen then
          err = true
        elseif smlen + mdlen == sdlen then
          shortest = false
        end
      end
    end
    if shortest then totallen = totallen + sdlen end
  end
end
print(err and -1 or totallen)


Measured memory_bytes: 1280
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cctype>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 1010, MAX = 1000001;
int a[N][N], isprime[MAX];

int main() {
    int i = 505, j = 505, x = 1;
    int di[] = {0,-1,0,1}, dj[] = {1,0,-1,0};
    a[i][j] = 1;
    for (int p = 0; x < 1000000; p++){
        REP(c,p/2+1){
            x++;
            i += di[p%4];
            j += dj[p%4];
            a[i][j] = x;
        }
    }

    FOR(i,2,MAX) isprime[i] = 1;
    FOR(i,2,MAX){
        if (!isprime[i]) continue;
        for (int x = 2*i; x <= MAX; x += i) isprime[x] = 0; 
    }

    int m, n;
    while (cin >> m >> n && m){
        VVI dp(N,VI(N,-1)), dpm(N,VI(N));
        REP(i,N) REP(j,N) if (a[i][j] == n) dp[i][j] = isprime[n], dpm[i][j] = n;
        REP(i,N) REP(j,N){
            if (dp[i][j] == -1 || a[i][j] == 0) continue;
            FOR(k,j-1,j+1){
                int p = a[i+1][k];
                if (p > m) continue;
                if (isprime[p]){
                    dp[i+1][k] = max(dp[i+1][k], dp[i][j] + 1);
                    dpm[i+1][k] = p;
                }else{
                    if (dp[i+1][k] < dp[i][j] || (dp[i+1][k] == dp[i][j] && dpm[i+1][k] < dpm[i][j])){
                        dp[i+1][k] = dp[i][j];
                        dpm[i+1][k] = dpm[i][j];
                    }
                }
            }
        }
        int x = 0, y = 0;
        REP(i,N) REP(j,N){
            if (x < dp[i][j] || (x == dp[i][j] && y < dpm[i][j])){
                x = dp[i][j];
                y = dpm[i][j];
            }
        }
        if (x == 0) y = 0;
        printf("%d %d\n", x, y);
    }
}

Measured memory_bytes: 18648
package main

import (
	"fmt"
	"os"
)

func main() {
	var n int
	fmt.Scan(&n)
	for i := 1; i <= 9; i++ {
		for j := 1; j <= 9; j++ {
			if n == i*j {
				fmt.Println("Yes")
				os.Exit(0)
			}
		}
	}
	fmt.Println("No")
}


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

int main() {
  string S;
  cin >> S;
  bool ans = S.at(0) == 'A';
  int count = 0;
  for (int i = 1; i < S.size(); i++){
    if (isupper(S.at(i))){
      ans = (S.at(i) == 'C') && (2 <= i) && ((i + 1) != S.size()) && ans;
      if(ans)
        count++;
    }
  }
  if (ans && (count == 1))
    cout << "AC";
  else 
    cout << "WA";
  cout << endl;
}

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

int main() {
    //string a,b;
    //if((s1.compare(s2)) < 0){
        
    //}
    int a,b;
    string s;
    cin>>a>>b;
    if(a>b){
        for(int i=0;i<a;i++){
            //s[i] =to_string(b);
            cout<<b;
        }
        cout<<"\n";
        //cout<<s;
    }
    else if(a==b){
        for(int i=0;i<a;i++){
            //s[i] =to_string(b);
            cout<<b;
        }
        cout<<"\n";
    }
    else {
        for(int i=0;i<b;i++){
            //s[i] =to_string(b);
            cout<<a;
        }
        cout<<"\n";
    }
	return 0;
}


Measured memory_bytes: 256