akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n),ind(n);
	rep(i,n){
		cin>>a[i];
		a[i]--;
		ind[a[i]]=i;
	}
	ll ans=0;
	set<ll> st;
	rep(i,n){
		st.insert(ind[i]);
		auto itr1=st.lower_bound(ind[i]);
		auto itr2=st.upper_bound(ind[i]);
		ll l=-1,r=n;
		if(itr1!=st.begin()){
			itr1--;
			l=*itr1;
		}
		if(itr2!=st.end()){
			r=*itr2;
		}
		ans+=(i+1)*(ind[i]-l)*(r-ind[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 15856
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool bo[100];
int main()
{
	string s="",s1="",s2="";
	cin>>s;
	int c=0;
	for(int i=0;i<(int)s.size();i++)
	{
		if(s[i]=='B')
		{
			c++;
		}
	}
	//cout<<c<<endl;
	s1=s;
	//cout<<s1<<endl;
	for(int j=0;j<c;j++)
	{
		
		for(int i=0;i<(int)s1.size();i++)
		{
			if(s1[i]=='B')
			{
				//bo[i]=bo[i-1]=1;
				bo[i]=1;
				bo[i-1]=1;
				break;
			}
		}
		//cout<<s1<<endl;
		s2="";
		for(int i=0;i<(int)s1.size();i++)
		{
			if(bo[i]==0)
			{
				s2+=s1[i];
			}
		}
		//cout<<s2<<endl;
		s1=s2;
		for(int i=0;i<20;i++)
		{
			bo[i]=0;
		}
	}
	cout<<s1<<endl;
}

Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

void Sequence() {
	int n, k;
	cin >> n >> k;
	ll res = k;
	for (size_t i = 1; i < n; i++)
	{
		res *= k - 1;
	}
	cout << res << endl;
}
int main() {
	Sequence();
	return 0;
}



Measured memory_bytes: 256
open Printf open Scanf
module MyInt = struct
	let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v
	(* let input_int_array n = Array.init n (fun _ -> Scanf.scanf " %d" (fun v -> v))	
	let get_int () = Scanf.scanf " %d" (fun v -> v)
	let get_2_ints () = Scanf.scanf " %d %d" (fun u v -> u,v)
	let get_3_ints () = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w)
	let get_4_ints () = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x)
	let get_5_ints () = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)
	let print_int_endline n = n |> string_of_int |> print_endline *)
end
let char_list_of_string str = 
	let rec f0 i a =
		if i<0 then a else f0 (i-1) (str.[i]::a)
	in f0 (String.length str - 1) []
let string_of_list ?(separator=" ") f ls =
	let rec f0 a s = match a with
		| [] -> s
		| [h] -> s ^ (f h) ^ separator
		| h::t -> f0 t (s ^ (f h) ^ separator)
	in f0 ls ""
let () =
	let ls = scanf " %s" (fun v -> v) |> char_list_of_string
	in let lt = scanf " %s" (fun v -> v) |> char_list_of_string
	in
	let rec rot ls_ i = match ls_ with
	| [] -> failwith ""
	| h::t -> (
		(* string_of_list (String.make 1) ls_ |> printf "%s\n"; *)
		if ls_ = lt then true
		else if i>0 && ls_ = ls then false
		else rot (t@[h]) (i+1)
	)
	in
	rot ls 0 |> (fun v -> if v then "Yes" else "No") |> print_endline


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

// Begin Header {{{
using namespace std;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    var(intmax_t, N);

    reps(x, 1, 1e6) {
        if (intmax_t(x * 1.08) == N) {
            return output(x), 0;
        }
    }

    output(":(");

    return 0;
}


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

typedef int TInt;
typedef std::vector<TInt> TList;
bool IsPrime(TInt Value, const TList& Prime)
{
    TInt Max = std::sqrt(Value);
    for(TList::const_iterator It = Prime.begin();
        It != Prime.end() && *It <= Max;
        ++It)
    {
        if(Value % (*It) == 0) return false;
    }
    return true;
}
TList GetPrimeList(TInt Max)
{
    TList Prime;
    Prime.reserve(Max);
    Prime.push_back(2);
    for(TInt i = 3; i <= Max; i += 2){
        if(IsPrime(i, Prime)){
            Prime.push_back(i);
        }
    }
    return Prime;
}
int main()
{
    TList List = GetPrimeList(999999);
    while(true){
        int n;
        std::cin >> n;
        if(std::cin.eof()) break;
        TList::iterator It = std::upper_bound(List.begin(), List.end(), n);
        std::cout << std::distance(List.begin(), It) << std::endl;
        
    }
    return 0;
}

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

int main()
{
  ll n;
  cin>>n;
  
  
  set<ll>s;
  for(ll i=0,a;i<n;i++)cin>>a,s.insert(a);
  
  cout<<(s.size()==n?"YES":"NO");
  
  
 
  
  
  
  
}


Measured memory_bytes: 9600
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    ll n,x;
    cin >> n >> x;
    vector<ll> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(all(a));
    int num = 0;
    for (int i = 0; i < n; i++){
        if (x >= a[i]){
            num++;
            x -= a[i];
        }
    }
    if (x > 0 && num == n){
        num--;
    }
    cout << num << endl;



    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
string s;

int main(){
  cin >> s;
  for(int i=s.size()-2;i>=0;i=i-2){
    if(s.substr(0,i/2) == s.substr(i/2,i/2)){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define lf long double
#define INF 1000000000
#define MAX 200001
#define M 1000000007
using namespace std;
 
int main() {
    string s;
    cin >> s;
    int l = s.length();
    int c = 0;
    for (int i=0;i<l/2;i++) {
        if (s[i]!=s[l-i-1]) c++;
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int N;
  scanf("%d",&N);
  int a[N];
  int i;
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  int min=a[0];
  int max=a[0];
  for(i=0;i<N;i++){
    if(max<a[i]){
      max=a[i];
    }
    if(min>a[i]){
      min=a[i];
    }
  }
  printf("%d",max-min);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
ull gcd(ull a,ull b){
	return b?gcd(b,a%b):a;
}
ull lcm(ull a,ull b){ 
	ull x=a/gcd(a,b);
	return x*b; 
}
int main()
{
	ull n;cin>>n;
	ull a;cin>>a;
	ull ans=a;
	for(int i=1;i<n;i++){
		cin>>a;
		ans=lcm(ans,a);
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 3608
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a<c ; a--)


inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(long int &a,long int &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(long long int &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int index=0 ; index<b ; index++)scanf("%d",&a[index])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int prime(int a)
{
	if(a<2)
	return 1;

	for(int i=2 ; (i*i)<=a ; i++)
	{
		if(a%i==0)
		return 0;
	}
	
	return 1;
}

int main()
{
	int a;
	int pm[200005];
	int z=0;
	forin(i,2,2000000)
	{
		if(prime(i)==1)
		{
			pm[z]=i;
			z++;
		}
	}
	
	
	while(scanf("%d",&a)!=EOF)
	{
		int d=0;
		forin(i,0,z)
		{
			if(pm[i]>a)
			{
				d=i;
				printf("%d\n",d);
				break;		
			}
		}
	}
	return 0;
}

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

int main (void){
    int cnt = 0;
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == t[i]){
            cnt++;
        }else{
            
        }
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3624
from collections import deque

N = int(input())
edge = []
for i in range(N-1):
    edge.append(list(map(int, input().split())))
    
neighbor = [[] for i in range(N)]
for node1, node2 in edge:
    neighbor[node1-1].append([node1-1, node2-1])
    neighbor[node2-1].append([node2-1, node1-1])
    
def bfs(node):
    hasVisited = [0]*N
    que = deque([])
    
    que.extend(neighbor[node])
    
    while len(que)!=0:
        prev_node, nex_node = que.popleft()
        if nex_node == node:
            pass
        elif hasVisited[nex_node]:
            pass
        elif not hasVisited[nex_node]:
            hasVisited[nex_node] = hasVisited[prev_node]+1
            que.extend(neighbor[nex_node])

    
    return hasVisited

node_B = 1
node_W = N
dist_B = bfs(node_B-1)
dist_W = bfs(node_W-1)

b_win = 0
w_win = 0
for i in range(N):
    if dist_B[i] > dist_W[i]:
        w_win += 1
    else:
        b_win += 1
        
if b_win > w_win:
    print("Fennec")
else:
    print("Snuke")

Measured memory_bytes: 73632
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

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

    std::cout << (n + 1) / 2 << std::endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
L = [0]*N
P = [-1]*(2*10**5+1)
for i in range(2*N):
    j = i%N
    a = A[j]
    if P[a] == -1:
        P[a] = i
    else:
        L[P[a]] = j
        P[a] = j
s = 0
start = 0
v = [True]*N
h = [(0, 0)]
h_app = h.append
while v[start]:
    v[start] = False
    if start < L[start]:
        s += (L[start] - start +1)
    else:
        s += (L[start] - start +N +1)
    start = (L[start]+1)%N
    h_app((s, start))

r = (N*K)%s
import bisect
if r == 0:
    print("")
else:
    res = bisect.bisect(h, (r, 10**10))-1
    s, start = h[res]
    s = r-s
    ans = []
    P = [-1]*(2*10**5+1)
    if s:
        cou = 0
        for i in range(s):
            if P[A[(start+i)%N]] == -1:
                P[A[(start+i)%N]] = cou
                ans.append(str(A[(start+i)%N]))
            else:
                sr = P[A[(start+i)%N]]
                P[A[(start+i)%N]] = -1
                for j in range(cou-sr):
                    a = ans.pop()
                    P[int(a)] = -1
                cou = sr-1
            cou += 1
    print(" ".join(ans))


Measured memory_bytes: 103856
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using BigInt = long long;
using BigFloat = long double;
#define ALL(a)  (a).begin(),(a).end()

int main(){
    BigFloat W,H,x,y;
    cin >> W >> H >> x >> y;
    if (W / 2 == x && H / 2 == y){
        cout << W * H / 2 << " " << 1 << endl;
    } else {
        cout << W * H / 2 << " " << 0 << endl;
    }
}

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

int main() {
	
	vector<int> a(3);

	cin >> a[0] >> a[1] >> a[2];

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

	cout << (a[2] - a[1]) + (a[1] - a[0]) << endl;

}

Measured memory_bytes: 256
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

int n,k,x[100010];

int main(){
    I(n); I(k);
    k--;
    REP(i,n) I(x[i]);

    int res = INT_MAX;
    REP(i,n-k){
        int cand;
        if (x[i] > 0) { cand = x[i+k]; } 
        else if (x[i+k] < 0) { cand = -x[i]; }
        else {cand = x[i+k] - x[i] + min(x[i+k], -x[i]); }
        res = min(res,cand); 
    }
    cout << res << endl;
}

Measured memory_bytes: 640
A=[]
A.append(list(map(int,input().split())))
A.append(list(map(int,input().split())))
A.append(list(map(int,input().split())))
N=int(input())
ans='No'
for _ in range(N):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                A[i][j]=0
for a in A:
    if a.count(0)==3:
        ans='Yes'
for a in zip(*A):
    if a.count(0)==3:
        ans='Yes'
if A[0][0]==0 and A[1][1]==0 and A[2][2]==0:
    ans='Yes'
elif A[0][2]==0 and A[1][1]==0 and A[2][0]==0:
    ans='Yes'
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }

ll n, a, b, c; 
vector<ll> l;

ll dfs(ll now,ll A, ll B, ll C,ll cost){
    if(now == n){
        if(!A || !B || !C) return LLONG_MAX;
        else return abs(A - a) + abs(B - b) + abs(C - c) + cost;
    }

    ll ret0 = dfs(now + 1, A, B, C, cost);
    ll ret1 = dfs(now + 1, A + l[now], B, C, cost + ((A == 0) ? 0 : 10));
    ll ret2 = dfs(now + 1, A, B + l[now], C, cost + ((B == 0) ? 0 : 10));
    ll ret3 = dfs(now + 1, A, B, C + l[now], cost + ((C == 0) ? 0 : 10));

    return min({ret0, ret1, ret2, ret3});
}

int main(){
    cin >> n >> a >> b >> c;
    l.resize(n);
    for(ll i = 0; i < n; i++) cin >> l[i];
    cout << dfs(0, 0, 0, 0, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
/*

Coded by peyha X

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int NMAX=100+1,WMAX=1e5+1,AUCUN=-1;

int n,w,poids[NMAX],value[NMAX];
ll accessible[WMAX];


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> w;
	
	for(int i=1;i<=n;i++){
		cin >> poids[i] >> value[i];
	}
	
	for(int p=0;p<WMAX;p++){
		accessible[p]=AUCUN;
	}
	ll ans=0;
	
	accessible[0]=0;
	
	for(int id=1;id<=n;id++){
		
		for(int weight=w;weight>=0;weight--){
			
			if(accessible[weight]!=AUCUN && weight+poids[id]<=w){
				
				accessible[weight+poids[id]]=max(accessible[weight+poids[id]],accessible[weight]+value[id]);
				ans=max(ans,accessible[weight+poids[id]]);
			}
		}
	}
	cout << ans << '\n';
	
	
}


Measured memory_bytes: 1024
import heapq
n = int(raw_input())
ais = [int(raw_input()) for _ in range(n)]
heap = []
for ai in ais:
	heapq.heappush(heap, ai)
	if len(heap) == 3: 
		heapq.heappop(heap)

u,v = heapq.heappop(heap),heapq.heappop(heap)
for ai in ais:
	if ai == v:
		print u
	else:
		print v


Measured memory_bytes: 37532
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
  int p;
  int r;
  int l;
  int s;
} Node;
int hfunc(Node *,int,int);

int main(){
  int n,i,j,degree,num,point,c1,c2,temp,a,depth=0,sum=0,height;
 
  Node T[25];
  for(i=0;i<25;i++){
    T[i].p=T[i].r=T[i].l=T[i].s=-1;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d%d",&point,&c1,&c2);
    if(c1!=-1)sum++;
    if(c2!=-1)sum++;
    T[point].l=c1;
    T[point].r=c2;
    if(c1!=-1){
    T[c1].s=c2;
    T[c1].p=point;
    }
    if(c2!=-1){
    T[c2].s=c1;
    T[c2].p=point;
    }
  
  }
    
    

  
  for(i=0;i<=sum;i++){
    depth=height=degree=0;
    j=i;
    while(T[j].p!=-1){
      depth++;
      j=T[j].p;
    }
    j=i;
    height=hfunc(T,i,0);

    
     if(T[i].l!=-1)
       degree++;
     
     if(T[i].r!=-1)
	  degree++;
    
     
     
   
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,T[i].p,T[i].s,degree,depth,height);
    if(T[i].p==-1) printf("root");
    else if(T[i].l==-1&&T[i].r==-1)printf("leaf"); 
  else printf("internal node");
   
    printf("\n");
  }
  return 0;
}
int hfunc(Node T[],int i,int height){
  int lh=0,rh=0;
  if(T[i].l==-1 &&T[i].r==-1)
    return height;
  if(T[i].l!=-1)
    lh=hfunc(T,T[i].l,height+1);
  if(T[i].r!=-1)
    rh=hfunc(T,T[i].r,height+1);
  if(lh>rh)
    return lh;
  else
    return rh;
}
    
  
  
   
    
      
    
  
	   



Measured memory_bytes: 2108
#include <cstdio>
#include <stack>
using namespace std;

int main()
{
	int n;
	stack<int> car;
	while(scanf("%d",&n)!=EOF) {
		if(n != 0) car.push(n);
		else{
			printf("%d\n",car.top());
			car.pop();
		}
	}	
	return 0;
}

Measured memory_bytes: 1036
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      int d = sc.nextInt();
      int x = d;
      int sum = 0;
      while(x < 600) {
        sum += x * x * d;
        x += d;
      }
      System.out.println(sum);
    }
  }
}

Measured memory_bytes: 25900
#include<iostream>
#include<algorithm>
using namespace std;
  
int selectionSort(int A[],int N){
   int i,j,minj,count;
   count = 0;
   for(i=0;i<N;i++){
     minj = i;
     for(j=i;j<N;j++){
       if(A[j]<A[minj])minj = j;
     }
     if(i!=minj){
       swap(A[i],A[minj]);
       count++;
     }
   }
   return count;
}
  
int main(){
   int A[100],N,count,i;
   cin >> N;
   for(i=0;i<N;i++)cin >> A[i];
     
   count = selectionSort(A,N);
     
   for(i=0;i<N;i++){
     if(i)cout << " ";
     cout << A[i];
   }
   cout << endl;
   cout << count << endl;
  
   return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 4e5 + 5;

char s[MAXN];

void solve(){
	int n, k;
	scanf("%d%d%s", &n, &k, &s[0]);
	int i;
	for(i = 0; i < n && k; k--){
		if (i % 2 == 0 && s[i] == 'A' || i % 2 == 1 && s[i] == 'B'){
			s[i] = 'B' - s[i] + 'A';
		} else {
			i++;
		}
	}
	for(int j = i + n - 1; j >= n; j--){
		s[j] = ((i + n - 1 - j) % 2 == 0 ? 'A' : 'B');
	}
	if (k % 2 == 1 && n % 2 == 1){
		s[i] = 'B';
	}
	if (i < n && i % 2 == 1){
		REP(j, i, n){
			s[j] = 'B' - s[j] + 'A';
		}
	}
	printf("%s\n", &s[i]);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 768
'''A - AtCoder Crackers
https://atcoder.jp/contests/abc105/tasks/abc105_a

>>> main(7, 3)
1
>>> main(100, 10)
0
>>> main(1, 1)
0

>> main(78, 25)
1'''


def main(n, k):
    if n % k != 0:
        print(1)
    else:
        print(0)


if __name__ == "__main__":
    n, k = map(int, input().split(' '))
    main(n, k)


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());

      StringBuilder buf = new StringBuilder();
      while(n != 0) {
        if((n & 1) != 0) {
          n--;
          buf.append(1);
        }
        else {
          buf.append(0);
        }

       n /= -2;
      }

      if(buf.length() == 0)
        buf.append('0');
      else
        buf.reverse();
      
      System.out.println(buf);
    }
    catch(IOException e){
      System.err.println(e);
    }
  }
}

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

using namespace std;

constexpr int MAX_V = 1000;
constexpr int INF = (1 << 29);

struct edge {
    int to, cap, cost, rev;
    edge(int to, int cap, int cost, int rev) :
        to{to}, cap{cap}, cost{cost}, rev{rev} {}
};

int V;
vector<edge> G[MAX_V];
int dist[MAX_V], prevv[MAX_V], preve[MAX_V];

void add_edge(int from, int to, int cap, int cost)
{
    G[from].emplace_back(to, cap, cost, G[to].size());
    G[to].emplace_back(from, 0, -cost, G[from].size() - 1);
}

int min_cost_flow(int s, int t, int f)
{
    int res = 0;
    while (f > 0) {
        fill(dist, dist + V, INF);
        dist[s] = 0;
        bool update = true;
        while (update) {
            update = false;
            for (int v = 0; v < V; v++) {
                if (dist[v] == INF) continue;
                for (int i = 0; i < (int)G[v].size(); i++) {
                    edge& e = G[v][i];
                    if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
                        dist[e.to] = dist[v] + e.cost;
                        prevv[e.to] = v;
                        preve[e.to] = i;
                        update = true;
                    }
                }
            }
        }
        if (dist[t] == INF) return -1;
        int d = f;
        for (int v = t; v != s; v = prevv[v]) {
            d = min(d, G[prevv[v]][preve[v]].cap);
        }
        f -= d;
        res += d * dist[t];
        for (int v = t; v != s; v = prevv[v]) {
            edge& e = G[prevv[v]][preve[v]];
            e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}

int main()
{
    int N, M, K;
    cin >> N >> M >> K;
    
    int S = N + (M + 1) + 1, T = S + 1;
    V = T + 1;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        
        add_edge(S, i, 1, 0);
        add_edge(i, N, 1, -a);
    }
    

    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            int b;
            cin >> b;
            add_edge(j, N + i + 1, 1, -b);
        }
    }    
    
    for (int i = 0; i < M; i++) {
        int Ti;
        cin >> Ti;
        add_edge(N + i + 1, N + (M + 1), Ti, 0);
    }

    add_edge(N, T, INF, 0);
    add_edge(N + (M + 1), T, N - K, 0);

    cout << -min_cost_flow(S, T, N) << endl;    
    return 0;
}

Measured memory_bytes: 3396
#include<bits/stdc++.h>
#define int         int long long
    
using namespace std;

signed main()
{	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int test=1;
    //cin>>test;
    while(test--){
        int n,k;
        double sum[1001];
        sum[0]=0;
        for(int i=1;i<1001;i++) sum[i]=sum[i-1]+i;
        cin>>n>>k;
    	int p;
    	cin>>p;
        double a[n],b[n];
        a[0]=(sum[p]/p);
        b[0]=a[0];
        for(int i=1;i<n;i++){
        	cin>>p;
        	a[i]=sum[p]/p;
        	b[i]=b[i-1]+a[i];
        }
        
        int ind=k-1;
        double s=b[k-1];
        for(int i=k;i<n;i++){
        	if(b[i]-b[i-k]>s){
        		s=b[i]-b[i-k];
        		ind=i;
        	}
        }
        
        printf("%.12f\n",s );



    }
    return 0;
}  



Measured memory_bytes: 3456
N = int(input())
S = input()
A = Z = a = z = 0
for c in S:
    c = ord(c)
    if c <= 77:
        A += 1
    elif c <= 90:
        Z += 1
    elif c <= 109:
        a += 1
    else:
        z += 1
ans = "A"*(A-Z)+"Z"*(Z-A)+"a"*(a-z)+"z"*(z-a)
print(len(ans))
print(ans)



Measured memory_bytes: 5784
s = input()

print("0 0 ", end = "")

if int(s) <= 10**9:
  print(s + " 0 0 1")
else:
  #10**9より上の位
  u = int(s[0:len(s)-9])
  
  if u*10**9 == int(s):
    print(str(u) + " 0 0 " + str(10**9), end = "")
  else:
    print(str(u+1) + " 1 ", end = "")
    nokori = (u+1)*(10**9) - int(s)
    print(str(nokori) + " " + str(10**9))

Measured memory_bytes: 3064
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

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

  vll ss(m);
  vll cs(m);
  rep(i, m) {
    cin >> ss[i] >> cs[i];
    ss[i]--;
  }

  rep(ii, 1000) {
    ll i = ii;
    vll ids(1, i % 10);
    i /= 10;
    while(i){
      ids.push_back(i % 10);
      i /= 10;
    }
    ll keta = (ll)ids.size();
    if (keta != n) continue;
    Reverse(ids);
    bool ok = true;
    rep(j, m) {
      bool cond = ids[ss[j]] == cs[j];
      if (!cond) ok = false;
    }
    if (!ok) continue;
    cout << ii << endl;
    return 0;
  }
  puts("-1");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	char a, b, c;

	cin >> a >> b >> c;
	char d, e, f;
	cin >> d>> e>> f;
	int count=0;
	if (a == d) {
		count++;
	}
	if (b == e) {
		count++;
	}
	if (c == f) {
		count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;

Node treeMinimum(Node x){
  while(x->left != NIL)
    {
      x = x->left;
    }
  return x;
}
 
Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key)
    {
      return u;
    }
 
  if(k < u->key)
    {
      return treeSearch(u->left, k);
    }
  else
    {
      return treeSearch(u->right, k);
    }
}
 
Node treeSuccessor(Node x){
  Node y;
 
  if(x->right != NIL)
    {
      return treeMinimum(x->right);
    }
  y = x->parent;

  while(y != NIL && x == y->right)
    {
      x = y;
      y = y->parent;
    }

  return y;
}
 
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
 
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
 
  if(y->left != NIL) x = y->left;
  else x = y->right;
 
  if(x != NIL) x->parent = y->parent;
 
  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z)
    {
      z->key = y->key;
    }

}
 
void insert(int k){
  Node y = NIL; // parent of x
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x != NIL)
    {
      y = x;
      if(z->key < x->key) x = x->left;
      else x = x->right;
    }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z; 
}
 
void inorder(Node u){
  if(u != NIL)
    {
      inorder(u->left);
      printf(" %d", u->key);
      inorder(u->right);
    }
}
 
void preorder(Node u){
  if(u != NIL)
    {
      printf(" %d", u->key);
      preorder(u->left);
      preorder(u->right);
    }
} 
 
int main()
{
  int n, i, x;
  char com[20];
  scanf("%d", &n);
   
  for ( i = 0; i < n; i++ )
    {
      scanf("%s", com);
      if ( com[0] == 'f' )
	{
	  scanf("%d", &x);
	  Node t = treeSearch(root, x);
	  if ( t != NIL ) printf("yes\n");
	  else printf("no\n");
	}
      else if ( com[0] == 'i' )
	{
	  scanf("%d", &x);
	  insert(x);
	} 
      else if ( com[0] == 'p' )
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
      else if ( com[0] == 'd' )
	{
	  scanf("%d", &x);
	  treeDelete(treeSearch(root, x));
	}
    }
   
  return 0;
}

Measured memory_bytes: 19364
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,k,i,sum=0;
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(i=0;i<k;i++)
        sum+=a[i];
    cout<<sum;
    return 0;
}


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

int n;
char S[11234][6];
int dice[6] = { 1,2,3,5,4,6 }, tmp = 0, ans = 0;

int main(void) {
	while (true) {
		ans = 0;
		dice[0] = 1;
		dice[1] = 2;
		dice[2] = 3;
		dice[3] = 5;
		dice[4] = 4;
		dice[5] = 6;
		scanf("%d", &n);
		if (n == 0) { break; }
		for (int i = 0; i < n; ++i) { scanf("%s", &S[i]); }

		for (int i = 0; i < n; ++i) {
			if (strcmp(S[i], "North") == 0) {
				tmp = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[3];
				dice[3] = tmp;
				ans += dice[0];
			}
			else if (strcmp(S[i], "East") == 0) {
				tmp = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[2];
				dice[2] = tmp;
				ans += dice[0];
			}
			else if (strcmp(S[i], "South") == 0) {
				tmp = dice[0];
				dice[0] = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[1];
				dice[1] = tmp;
				ans += dice[0];
			}
			else if (strcmp(S[i], "West") == 0) {
				tmp = dice[0];
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = dice[4];
				dice[4] = tmp;
				ans += dice[0];
			}
			else if (strcmp(S[i], "Right") == 0) {
				tmp = dice[1];
				dice[1] = dice[2];
				dice[2] = dice[3];
				dice[3] = dice[4];
				dice[4] = tmp;
				ans += dice[0];
			}
			else if (strcmp(S[i], "Left") == 0) {
				tmp = dice[1];
				dice[1] = dice[4];
				dice[4] = dice[3];
				dice[3] = dice[2];
				dice[2] = tmp;
				ans += dice[0];
			}
		}
		printf("%d\n", ans + 1);
	}
	return 0;
}

Measured memory_bytes: 2784
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

// Union-Find 木 (Verified: AtCoder Typical Contest 001 B)
struct UnionFind {
private:
    const int n;
    int __size;
    vector<int> uf;
public:
    // 初期化 UnionFind uni(n) のように宣言すれば良い
    UnionFind(int _n) : n(_n), __size(_n), uf(_n, -1) {}
    // find (木の根を求める)
    int find(int x) {return (uf[x] < 0) ? x : uf[x] = find(uf[x]);}
    // x と y が同じ集合に属するかどうか
    bool same(int x, int y) {return find(x) == find(y);}
    // x が属する集合の要素数
    int size(int x) {return -uf[find(x)];}
    // 集合はいくつあるか
    int size()      {return __size;}
    // x と y の属する集合を併合
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return;
        __size--;
        if(uf[y] < uf[x]) swap(x, y);
        uf[x] += uf[y]; uf[y] = x;
    }
};

struct Edge {
    int from, to;
    double cost;
    Edge(int a, int b, double c) : from(a), to(b), cost(c) {}
    bool operator<(const Edge &x) const {
        return cost > x.cost;
    }
};

int x[10010], y[10010];
signed main() {
    int N, M; scanf("%lld%lld", &N, &M);
    rep(i,0,N) {
        scanf("%lld%lld", &x[i], &y[i]);
    }

    vector<Edge> edges;
    double ans = 0;
    rep(i,0,M) {
        int u, v; scanf("%lld%lld", &u, &v);
        u--; v--;
        int x_diff = x[u] - x[v];
        int y_diff = y[u] - y[v];
        double cost = sqrt(x_diff*x_diff + y_diff*y_diff);
        edges.push_back(Edge(u, v, cost));
        ans += cost;
    }

    sort(edges.begin(), edges.end());
    UnionFind uf(N);
    rep(i,0,M) {
        int u = edges[i].from, v = edges[i].to;
        if(uf.same(u, v)) continue;
        uf.unite(u, v);
        ans -= edges[i].cost;
    }
    printf("%.12f\n", ans);
    return 0;
}


Measured memory_bytes: 3904
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7; 

fn main(){
    let n: usize = read();
    let ans = n * n * n;
    println!("{}", ans);
}

fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int main() {
  int A;
  int B;
  cin >> A >> B;
  
  if ((A + B) % 2 == 1) {
    cout << "IMPOSSIBLE" << endl;
  }
  
  else {
    cout << (A + B)/2 << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
    int n; cin >> n;
    int A[100];
    for (int i=0; i<n; ++i) {
        cin >> A[i];
    }

    int num = 0;
    for (int i=0; i<n-1; ++i) {
        int mini = i;
        for (int j=i+1; j<n; ++j) {
            if (A[mini] > A[j]) {
                mini = j;
            }
        }
        if (mini != i) {
            swap(A[i], A[mini]);
            num ++;
        }
    }

    for (int i=0; i<n; ++i) {
        if (i == 0)
            cout << A[i];
        else 
            cout << " " << A[i];
    }
    cout << "\n";
    cout << num << "\n";

    return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

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

	string s; cin >> s;

	int count[26] = { 0 };
	FOR_LT(i, 0, s.size()) {
		count[s[i] - 'A']++;
	}

	FOR_LT(i, 0, 26) {
		if (count[i] != 0 && count[i] != 2) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
struct Element{
    long long c,w;
    long long cnt;
    bool operator < (const Element &other)const{
        if(w*other.c!=other.w*c) return w*other.c>other.w*c;
        else return c<other.c;
    }
};
std::vector<int>g[55];
long long m[55];
long long sumM[55],sonSize[55];
Element e[55];
long long optC[55], optW[55], optCnt[55];
long long f[55][150000];

void dfs(int u){
    sumM[u] = m[u], sonSize[u] = 1;
    for(int v: g[u]){
        dfs(v);
        sumM[u] += sumM[v];
        sonSize[u] += sonSize[v];
    }
}

long long min(long long a,long long b){ return a>b?b:a; }

int preWork(int n,long long d){
    dfs(1);
    int sum = 0;
    for(int i = 1; i <= n; i++){
        long long have = d;
        if(i==1) have = 1e13+7;
        long long used = min(have,50);
        sum += used*sonSize[i];
        optC[i] = sumM[i], optW[i] = sonSize[i], optCnt[i] = used;
        e[i].c = sumM[i], e[i].w = sonSize[i], e[i].cnt = have-used;
    }
    return sum;
}

long long getMaxn(long long x,int n){
    long long res = 0;
    for(int i = 1; i <= n; i++){
        if(x==0) break;
        long long cnt = min(e[i].cnt,x/e[i].c);
        res += cnt*e[i].w;
        x -= cnt*e[i].c; 
    }
    return res;
}

int main(){
    //printf("%d\n",50*50*50*50);
    //printf("%d\n",50*50*50);
    int n; long long x,d;
    scanf("%d%lld%lld",&n,&x,&d);
    for(int i = 1; i <= n; i++){
        scanf("%lld",&m[i]);
        if(i!=1){
            int parent;
            scanf("%d",&parent);
            g[parent].push_back(i);
        }
    }
    int upper = preWork(n,d);
    //printf("upper = %d\n",upper);
    std::sort(e+1,e+1+n);
    long long inf = 2e18;
    f[0][0] = 0;
    for(int i = 1; i <= upper; i++) f[0][i] = inf;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= upper; j++){
            f[i][j] = f[i-1][j];
            for(int k = 1; k <= optCnt[i] && k*optW[i]<=j; k++){
                int last = j-k*optW[i];
                f[i][j] = min(f[i][j],f[i-1][last]+optC[i]*k);
            }
        }
    }
    //for(int i = 1; i <= n; i++) printf("%lld %lld %lld\n",e[i].w,e[i].c,e[i].cnt);
    long long ans = 0;
    for(int i = 0; i <= upper; i++){
        if(f[n][i]<=x){ 
            long long cur = (long long)i+getMaxn(x-f[n][i],n);
            if(cur>ans) ans = cur;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 28848
#include <stdio.h>
#include <math.h>
int isprime(int n) {
	int i;
	if(n<=1){
		return 0;
	}
	for(i = 2; i*i<=n; i++) {
		if(n % i == 0){
			return 0;
		}
	}
	return 1;
}

int main(){
	int n,i;
	
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i = n;i>=2;i--){
			if(isprime(i)&&isprime(i-2)){
				printf("%d %d\n",i-2,i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 600
from collections import deque

n = int(input())
u = [[] for i in range(n+1)] #隣接リスト
for i in range(n):
    v = list(map(int, input().split()))
    u[v[0]] = v[1:] #v = [次数, 頂点...]

d = [-1] * (n+1)
visited = [False] * (n+1)

d[1] = 0
visited[1] = True
que = deque([1])
while len(que) > 0:
    c = que.popleft()
    for i in range(1, u[c][0]+1):
        if not visited[u[c][i]]:
            que.append(u[c][i])
            visited[u[c][i]] = True
            d[u[c][i]] = d[c] + 1

for i in range(1, n+1):
    print(i, d[i])


Measured memory_bytes: 6044
#-*-coding:utf-8-*-

def main():
    s = input()

    string_list=list(str(s))

    if string_list[0]==string_list[1]==string_list[2]:
        print("Yes")
    elif string_list[1]==string_list[2]==string_list[3]:
        print("Yes")
    else:
        print("No")
    
if __name__=="__main__":
    main()

Measured memory_bytes: 9112