akhauriyash/Code-Regression huggingface dataset:
import math
from functools import lru_cache

@lru_cache(maxsize = None)
def count_change_point_min(r , c , current_color):
    min_values = list()
    if r != h-1:
        min_values.append(count_change_point_min(r+1, c, S[r][c]))
    if c != w-1:
        min_values.append(count_change_point_min(r, c+1, S[r][c]))
    if len(min_values) == 0:
        min_values.append(0)
        
    return min(min_values) + (0 if S[r][c] == current_color else 1)
    
    
h,w = map(int,input().split())
S = list()
for _ in range(h):
    S.append(list(input()))
    
if S[0][0] == ".":
    ceil_or_floor = math.floor
else:
    ceil_or_floor = math.ceil
    
print (ceil_or_floor((count_change_point_min(0, 0, S[0][0])+1) / 2))

Measured memory_bytes: 11284
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	ll x;cin >> x;
	ll now = 100;
	for(int i = 1;i < 100000;i++){
		now = now * 1.01;
		if(now >= x){
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 3648
import sys
import itertools
from scipy.sparse import csr_matrix, lil_matrix
from scipy.sparse.csgraph import maximum_flow

H, W = map(int, sys.stdin.buffer.readline().split())
S = b''.join(sys.stdin.buffer.read().split())

source = 2 * H * W
sink = source + 1

INF = source * 2

graph = lil_matrix((sink + 1, sink + 1), dtype=int)

for i in range(H * W):
    x, y = divmod(i, W)
    if S[i] == ord('.'):
        graph[2 * i, 2 * i + 1] = 1
    else:
        graph[source, 2 * i + 1] = INF
    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        x1, y1 = x + dx, y + dy
        if 0 <= x1 < H and 0 <= y1 < W:
            j = x1 * W + y1
            graph[2 * i + 1, 2 * j] = 1
        else:
            graph[2 * i + 1, sink] = INF
graph = graph.tocsr()
ans = maximum_flow(graph, source, sink).flow_value
ans = ans if ans < INF else -1
print(ans)


Measured memory_bytes: 45052
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, int num=0){
  if(num == 0) num = (int)v.size();
  if(is_reverse) for(int i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<" ";}
  else for(int i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<" ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
  if(num == 0) num = (int)v.size();
  for(int i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

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

  X = abs(X);

  ll sho = X / D;
  ll amari = X % D;

  if(sho < K){
    K -= sho;
    X = amari;
    if(K % 2 == 1) cout << abs(amari - D) << endl;
    else cout << amari << endl;
    return 0;
  }

  cout << abs(X - D * K ) << endl;


  return 0;
}



Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> state;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }
int ceil(int a,int b){
  // a/bの切り上げを考える
  return (a+b-1)/b;
}


int main(){ 
  int n;
  int cnt = 0;
  cin >> n;
  int a[n];
  rep(i,n)cin >> a[i];

  rep(i,n){
    if((a[i] % 2 == 1) && ((i+1) % 2 == 1))cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3672
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false



int main() {
	string S;
	cin >> S;


	bool appeared[26] = {};

	for (int i = 0; i < S.size(); i++) appeared[S[i] - 'a'] = true;
	for (int i = 0; i < 26; i++) {
		if (!appeared[i]) {
			cout << char('a' + i) << endl;
			return 0;
		}
	}
	cout << "None" << endl;	
	return 0;
}

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

using namespace std;

const int MAX = 300001;
bool data[MAX];
vector<int> MSPrime;


void make(){
  fill(data,data+MAX,false);
  for(int i = 0; i < MAX; i++){
    if(7*i+1 < MAX) data[7*i+1] = true;
    else break;
    if(7*i+6 < MAX) data[7*i+6] = true;
    else break;
  }

  for(int i = 5; i < sqrt(MAX); i++)
    if(data[i]) 
      for(int j = 2*i; j < MAX; j+=i) data[j] = false;

  for(int i = 2; i < MAX; i++)
    if(data[i])MSPrime.push_back(i);
}

void solve(int in){
  for(int i = 0; i < MSPrime.size(); i++)
    if(!(in%MSPrime[i])) cout << " " << MSPrime[i];				 
}
int main(){
  make();
  int in;
  while(cin >> in){
    if(in == 1) break;
    
    cout << in << ":";
    solve(in);
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1464
out=->*a{$>.<<("%s %d\n"%a).flush}
ask=->n{out[??,n];gets.chomp=='Y'}
put=->n{out[?!,n];exit}
ask[i=10**9]?(i=1;loop{ask[i*2]&&put[i];i*=10}):loop{ask[i]&&put[(i+1..i*10-1).bsearch{|e|ask[e*10+9]}];i/=10}

Measured memory_bytes: 4176
#include <iostream>
using namespace std;
int main()
{
  int N;
  cin >> N;
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    if (i%3!=0 && i%5!=0) ans += i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
package main 

import (
	"fmt"
)

type Rec struct {
	h int
	w int
}

func main() {
	var rec Rec
	var recs []Rec
	for {
		fmt.Scan(&rec.h, &rec.w)
		recs = append(recs, rec)
		if rec.h == 0 && rec.w == 0 {
			recs = recs[:len(recs) - 1]
			break
		}
	}

	for _,v := range recs{
		for i := 0; i < v.h; i++ {
			for j := 0; j < v.w - 1; j++ {
				fmt.Print("#")
			}
			fmt.Print("#\n")
		}
		fmt.Println()
	}
}


Measured memory_bytes: 1124
#include <iostream>
using namespace std;
int main()
{
  string N;
  cin >> N;
  int len = N.length();
  // （最上位の桁の数字-1） ＋ 9＊（桁数-1）
  int ans1 = N[0] - '0' - 1 + 9 * (len - 1);
  // そのまま
  int ans2 = 0;
  for (int i = 0; i < len; i++)
    ans2 += N[i] - '0';
  cout << max(ans1, ans2) << endl;
  return 0;
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  VI xs(3);
  REP(i,3) cin >> xs[i];
  SORT(xs);
  cout << (xs[0]+xs[1]==xs[2]? "Yes": "No") << endl;

  return 0;
}


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

int main() {
	string era[5] = { "pre-meiji","meiji","taisho","showa","heisei" };
	int y, m, d;
	while (cin >> y >> m >> d) {
		int flg = 0;
		if (y <= 1867) { flg = 0; }

		else if (y == 1868) {
			if (m <= 8) { flg = 0; }
			if (m == 9) {
				if (d <= 7) { flg = 0; }
				else { flg = 1; }
			}
			else { flg = 1; }
		}

		if (y >= 1869 && y <= 1911) { flg = 1; }
		if (y == 1912) {
			if (m <= 6) { flg = 1; }
			else if (m == 7) {
				if (d <= 29) { flg = 1; }
				else { flg = 2; }
			}
			else { flg = 2; }
		}

			if (y >= 1913 && y <= 1925) { flg = 2; }
			if (y == 1926) {
				if (m <= 11) { flg = 2; }
				else {
					if (d <= 24) { flg = 2; }
					else { flg = 3; }
				}
			}

			if (y >= 1927 && y <= 1988) { flg = 3; }
			if (y == 1989) {
				if (m == 1) {
					if (d <= 7) { flg = 3; }
					else { flg = 4; }
				}
				else { flg = 4; }
			}

			if (y >= 1990) { flg = 4; }

			if (flg == 0) { cout << era[0] << endl; }
			if (flg == 1) { cout << era[1] << ' ' << y-1868 + 1 << ' ' << m << ' ' << d << endl; }
			if (flg == 2) { cout << era[2] << ' ' << y-1912 + 1 << ' ' << m << ' ' << d << endl; }
			if (flg == 3) { cout << era[3] << ' ' << y-1926 + 1 << ' ' << m << ' ' << d << endl; }
			if (flg == 4) { cout << era[4] <<' '<< y-1989  + 1 << ' ' << m << ' ' << d << endl; }
	}
	return 0;
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 50, M = 500, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int n;
string  ss;

int nxt(int i){
    return i + 1 == n ? 0 : i + 1;
}

int prev(int i){
    return i - 1 == -1 ? n - 1 : i - 1;
}

char op(char c){
    return c == 'W' ? 'S' : 'W';
}

string check(int status){
    // 0 - SS, 1 - SW, 2 - WS, 3 - WW
    string s(n, '.');
    if(status == 0) s[0] = s[n - 1] = 'S';
    if(status == 1) s[0] = 'S', s[n - 1] = 'W';
    if(status == 2) s[0] = 'W', s[n - 1] = 'S';
    if(status == 3) s[0] = s[n - 1] = 'W';

    for(int i = 0;i < n;i++){
        if(s[i] == 'S'){
            if(ss[i] == 'o'){
                if(s[nxt(i)] == '.')    s[nxt(i)] = s[prev(i)];
                else if(s[nxt(i)] != s[prev(i)])    return "-1";
            }
            else{
                if(s[nxt(i)] == '.')    s[nxt(i)] = op(s[prev(i)]);
                else if(s[nxt(i)] == s[prev(i)])    return "-1";
           }
        }
        else{
            if(ss[i] == 'x'){
                if(s[nxt(i)] == '.')    s[nxt(i)] = s[prev(i)];
                else if(s[nxt(i)] != s[prev(i)])    return "-1";
            }
            else{
                if(s[nxt(i)] == '.')    s[nxt(i)] = op(s[prev(i)]);
                else if(s[nxt(i)] == s[prev(i)])    return "-1";
           }
        }
    }
    return s;
}

int main(){
    init();

    cin >> n >> ss;

    for(int i = 0;i <= 3;i++){
        string res = check(i);
        if(res != "-1")   return cout << res, 0;
    }

    cout << -1;
}

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

using namespace std;

int main()
{
    string s, s1;
    cin >> s;
    int ln = s.length();
    for(int i = 0; i < ln / 2; i++){
            s1 += "hi";
        }
    if(s == s1){
        cout << "Yes" << endl;
    }
        else{
            cout << "No" << endl;
        }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int sum,dif,cal;
  sum=a+b;
  dif=a-b;
  cal=a*b;
  int list[3],i;
  list[0]=sum, list[1]=dif, list[2]=cal;
  for(i=0;i<=2;i++){
    if(list[i]<list[i+1]) list[i]=list[i+1];
    if(list[i-1]<list[i+1]) list[i-1]=list[i+1];
  }
  printf("%d\n",list[0]);
  return 0;
}


Measured memory_bytes: 128
import java.util.*;
 
class Main {
    public static void main(String args[]) {
        try (Scanner sc = new Scanner(System.in)) {
            while (true) {
                String S = sc.next();
                if (S.equals("0")) {
                    break;
                }
                long ans = 0;
                for (int i = 0; i < S.length(); i++) {
                    ans += S.charAt(i) - '0';
                }
                System.out.println(ans);
            }
        }
    }
}



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

char print[8][8];
int board[8][8];

void put(int r, int c){

	print[r][c] = 'Q';
	board[r][c]++;

	int temp_x[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
	int temp_y[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
	
	int x = c, y = r;
	for (int i = 0; i < 8; i++){
		
		x = c, y = r;
		while (x + temp_x[i] >= 0 && y + temp_y[i] >= 0 && x + temp_x[i] < 8 && y + temp_y[i] < 8){
			
			x += temp_x[i]; y += temp_y[i];
			board[y][x]++;
		}
	}

	return;
}

void del(int r, int c){

	print[r][c] = '.';
	board[r][c]--;

	int temp_x[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
	int temp_y[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };

	int x = c, y = r;
	for (int i = 0; i < 8; i++){

		x = c, y = r;
		while (x + temp_x[i] >= 0 && y + temp_y[i] >= 0 && x + temp_x[i] < 8 && y + temp_y[i] < 8){

			x += temp_x[i]; y += temp_y[i];
			board[y][x]--;
		}
	}

	return;
}

int Backtrack(int i){

	if (i == 8)return 1;

	bool flg = true;
	int act = 0;
	for (int j = 0; j < 8; j++){

		if (print[i][j] == 'Q')
			flg = false;
	}

	if (flg){

		bool flg1 = true;
		for (int j = 0; j < 8; j++){
			flg1 = false;
			if (board[i][j] == 0){
				put(i, j);
				flg1 = true;
				act = Backtrack(i + 1);
				if (act == 1)
					break;
				else{
					del(i, j);
					flg1 = false;
				}
			}
		}

		if (!flg1) return 0;
	}

	else{
		act = Backtrack(i + 1);
		return act;
	}

	return 1;
}

int main(void){

	memset(board, 0, sizeof(board));
	memset(print, '.', sizeof(print));

	int k;

	cin >> k;


	for (int i = 0; i < k; i++){

		int  r, c;
		cin >> r >> c;
		put(r, c);
	}

	Backtrack(0);

	for (int i = 0; i < 8; i++){
		for (int j = 0; j < 8; j++){

			cout << print[i][j];
		}

		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int a,b;
    char op;

    while(1){
        cin >> a >> op >> b;
        if(op=='+'){
            cout << a+b << endl;
        }else if(op=='-'){
            cout << a-b << endl;
        }else if(op=='*'){
            cout << a*b << endl;
        }else if(op=='/'){
            cout << a/b << endl;
        }else{
            break;
        }
    }

    return 0;

}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

void solve(){
    ll n;
    read(n);
    ll min_cost = n;
    for(ll a = 1 ; a * a <= n ; a++){
        if( n % a == 0){
            ll b = n / a;
            ll cost = a + b - 2; 
            if( cost < min_cost) {
                min_cost = cost;
            }
        }
    }
    cout << min_cost << "\n";
} 

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//Thanks to CSES problemset
// I am trained with this kind of problem

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

int main()
{
    int n, input;
    vector<int> vec;
    int mn = 100;
    int mx = -100, sum = 0;
    int temp, min_sum = 0;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> input;
        vec.push_back(input);
        if(input>mx)
            mx = input;
        if(input<mn)
            mn = input;
    }
    sort(vec.begin(), vec.end());

    for(int i = mn; i <=mx; i++){
            sum = 0;
        for(int j = 0; j < n; j++){
            temp = (vec[j] - i)*(vec[j] - i);
            sum = sum + temp;
        }
        if(min_sum == 0)
            min_sum = sum;
        else if(min_sum > sum)
            min_sum = sum;
    }
    cout << min_sum;

    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    cout << a+(b/2) << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque

def dfs(si, ei):
  q = deque()
  q.append([si,0])
  done = set([si])
  ds = [0 for _ in range(N)]
  while len(q) > 0:
    prvi, d = q.pop()
    for i in g[prvi]:
      if i in done: continue
      ds[i] = d+1
      q.append([i,d+1])
      done.add(i)
  return ds

N = int(input())
g = {i:[] for i in range(N)}
for _ in range(N-1):
  a,b = map(int,input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)

dslist = dfs(0,N-1)
delist = dfs(N-1,0)

cntb, cntw = 0, 0
for ds, de in zip(dslist[1:N-1], delist[1:N-1]):
  if ds <= de: cntb += 1
  else: cntw += 1
print('Fennec' if cntb>cntw else 'Snuke')

Measured memory_bytes: 44772
function main(arg) {
	var arg = arg.split("\n")[0].split(" ")
	var a = Number(arg[0]) 
	var b = Number(arg[1])
	if (b % a === 0) {
		console.log(a + b)
	} else {
		console.log(b - a)
	}
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stdio.h>

using namespace std;
typedef long long ll;


#include <functional>
template <typename T>
struct SegTree{
  int n;
  vector<T> node;
  T maxval;
  function<T(T,T)> fn;
  
public:
  SegTree(const vector<T> &v, T maxval0, function<T(T,T)> fn0){
    n=1;
    while((1<<(n-1))<v.size()) n++;
    maxval=maxval0;
    fn=fn0;
    node.resize((1<<n)-1,maxval);
    for(int i=0;i<v.size();i++){
      node[(1<<(n-1))-1+i]=v[i];
    }
    for(int i=(1<<(n-1))-2;0<=i;i--){
      node[i]=fn(node[2*i+1], node[2*i+2]);
    }
  }

  T query(int a, int b){
    int l=(1<<(n-1))-1+a;
    int r=(1<<(n-1))-1+b;
    
    int m=0; 
    T ans=maxval;
    while(true){
      if(r<=(l+1)*(1<<m)-1){
        break;
      }else if(((l&1)==0) && ((l+2)*(1<<m)-1<=r)){
        ans=fn(ans,node[l]);
        ++l;
      }else if((l+3)*(1<<m)-1<=r){
        l/=2; ++m;
      }else if((l+2)*(1<<m)-1<=r){
        ans=fn(ans,node[l]);
        ++l;
      }else{
        l=l*2+1; --m;
      }
    }
    return ans;
  }

  T get(int p){
    return node[(1<<(n-1))-1+p];
  }
  
  int update(int p, T val){
    int cur=(1<<(n-1))-1+p;
    node[cur]=val;
    for(int i=0;i<n-1;i++){
      cur=(cur-1)/2;
      node[cur]=fn(node[2*cur+1],node[2*cur+2]);
    }
    return 0;
  }
    
};

int main(){
  int N;
  cin >> N;
  vector<ll> r(N,0);
  SegTree<ll> st(r,0,[](ll l, ll r){return max(l,r);});
  vector<int> h(N);

  for(int i=0;i<N;i++){
    cin >> h[i]; h[i]--;
  }
  
  for(int i=0;i<N;i++){
    ll a; cin >> a;
    a+=st.query(0,h[i]);
    st.update(h[i],a);
  }

  cout << st.node[0] << endl;

  return 0;
}



Measured memory_bytes: 6656
long long t[21][2],a,d;int main(b){
		scanf("%d%d",&a,&b),t[b][a&1]=1;
		for(;(d%=21)||(--a-1&&scanf("%d",&b));t[d++][a&1]=((b>d?0:t[d-b][!(a&1)])+((b<(21-d))?t[b+d][!(a&1)]:0)));
		scanf("%d",&b);
		a=!printf("%lld\n",t[b][0]);
	}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122


int main() {
    ll q, h, s, d;
    cin >> q >> h >> s >> d;
    ll n;
    cin >> n;

    s = min({s, 4 * q, 2 * h});
    d = min(d, 2 * s);
    ll ans = 0;
    if (n % 2 == 0) ans = (n / 2) * d;
    else ans = (n / 2) * d + s;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <cmath>

using namespace std;

#define FAST_IO() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define USE_DB() cout << fixed; cout.precision(10);

#define pqu priority_queue
#define que queue
#define stk stack
#define vec vector

typedef long long ll;
typedef double db;
typedef string str;

#define IN(x) cin >> x
#define INI(x) int x; cin >> x
#define INL(x) ll x; cin >> x
#define INS(x) str x; cin >> x

#define FI first
#define SE second
#define PB push_back
#define SZ(x) x.size()
#define ALL(x) x.begin(), x.end()

#define FORN(i, s, e) for (int i = s; i < e; i++)
#define FORR(i, s, e) for (int i = s; i >= e; i--)
#define FORD(i, s, e, d) for (int i = s; i < e; i += d)
#define FORS(i, n) for (int i = 1; i*i <= n; i++)

const int MAX = 509;
int a[MAX][MAX], d[MAX][MAX];

int main() {
	FAST_IO();

	INI(n); INI(m); INI(q);
	FORN(i, 0, m) {
		INI(ma); INI(mb);
		a[ma][mb]++;
	}
	FORN(i, 0, n+1) {
		FORN(j, 1, n+1) {
			d[i][j] = d[i][j-1] + a[i][j];
		}
	}
	FORR(i, n, 1) {
		FORN(j, 0, n+1) {
			d[i][j] += d[i+1][j];
		}
	}
	/*
	FORN(i, 0, n+1) {
		FORN(j, 0, n+1) {
			cout << a[i][j] << ' ';
		}
		cout << '\n';
	}
	cout << '\n';
	FORN(i, 0, n+1) {
		FORN(j, 0, n+1) {
			cout << d[i][j] << ' ';
		}
		cout << '\n';
	}
	cout << '\n';
	*/
	FORN(i, 0, q) {
		INI(qa); INI(qb);
		cout << d[qa][qb] << '\n';
	}
	return 0;	
}


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

int main()
{
	long long k;
	string s;
	cin >> s >> k;
	long long sum = 0;
	int slen,elen,len = s.length(),cha = 0,tmplen = 1;
	for(int i = 1;i < len;i++){
		if(s[i] == s[i - 1]){
			tmplen++;
		}
		else{
			if(cha == 0){
				slen = tmplen;
				tmplen = 1;
				cha++;
			}
			else{
				sum = sum + (tmplen / 2);
				tmplen = 1;
			}
		}
	}
	int tmp;
	long long ans = 0;
	if(s[len - 1] == s[0]){
		if(cha == 0){
			ans = (k / 2) * (tmplen) + k % 2 * (tmplen / 2);
		}
		else if(slen %  2 == 1 || tmplen % 2 == 1){
			ans = (k - 1) * ((slen + tmplen) / 2) + k * sum + slen / 2 + tmplen / 2;
		}
		else{
			ans = k * (sum + slen / 2 + tmplen / 2);
		}
	}
	else{
		ans = k * (sum + slen / 2 + tmplen / 2);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    s = input()
    if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
        print("Bad")
    else:
        print("Good")

main()

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

int main()
{
    int n; cin >> n;
    string ans = "No";

    for(int i = 1; i <= 9; i++){
        for (int j = 1; j <= 9; j++){
            if(n == i*j){
                ans = "Yes";
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")



#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include <ext/rope>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define Find order_of_key
// #define at find_by_order
#define x first
#define y second
#define ll long long
#define lll __int128
#define ull unsigned long long
#define ulll unsigned __int128
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define gu getchar_unlocked()
#define pu putchar_unlocked()
#define all(x) x.begin(),x.end()
#define endl '\n'


int main()
{
	ll a,b;
	cin>>a>>b;
	ll g=__gcd(a,b);
	ll c=1;
	for(ll i=2;i*i<=g;i++){
		if(g%i==0){
			while(g%i==0)g/=i;
			c++;
		}
	}
	if(g!=1)c++;
	cout<<c<<endl;
	return 0;
}

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

#define sc(x) scanf("%d",&x);
#define rep(x ,n) for(int x=0; x<n; x++)
#define ll long long
#define finish(x) return cout << x << endl,0;
#define scarr(a,n) for(int x=0; x<n; x++)scanf("%d",&a[x]);

int n ,d;
int a[11][11];

long long sqr(int num){
    return 1LL*num*num;
}

int main()
{
    sc(n)sc(d)
    for(int i=0; i<n; i++){
        for(int j=0; j<d; j++)
            sc(a[i][j]);
    }

    int ans = 0;
    for(int i=0; i<n; i++)
    for(int j=i+1; j<n; j++){
        long long sq = 0LL;
        for(int v=0; v<d; v++)
            sq+=sqr(a[i][v]-a[j][v]);
        if((long long)sqrt(sq)*(long long)sqrt(sq) == sq)
            ans++;
    }

    finish(ans);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int x,a,b;
    scanf("%d%d%d",&x,&a,&b);
    int dis1=abs(a-x);
    int dis2=abs(b-x);
    if(dis1<dis2)
        printf("A\n");
    else
        printf("B\n");
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

char G[105][105];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,w; cin>>h>>w;
  rep(i,h+2) rep(j,w+2) G[i][j]='#';
  irep(i,1,h+1) irep(j,1,w+1) cin>>G[i][j];
  
  rep(i,h+2){
    rep(j,w+2){
      cout<<G[i][j];
    }
    cout<<endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

// #include "competitive_helper.cpp"

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
const int mod = 998244353;

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

int a, b;


int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    cin >> a >> b;
    cout << (LL)a * b / __gcd(a, b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    long double a,b; cin>>a>>b;
    cout << fixed;
    cout << (ll)floorl(a*b) << '\n';
    return 0;
}

Measured memory_bytes: 3784
#include <iostream>
 
using namespace std;
 
int main() {
	int n, k;
	cin >> n >> k;
	long long a1 = 0, a2 = 0;
	for (int i = n; i > 0; i--) {
		if (k % 2 == 0) a1 += (i % k == k / 2 ? 1 : 0);
		a2 += (i % k == 0 ? 1 : 0);
	}
	long long ans = a1 * a1 * a1 + a2 * a2 * a2;
	cout << ans << endl;
 	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vaector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
ll pow(ll x, ll y,ll m) { ll res = 1;x=x%m; while (y > 0) { if (y & 1) res = ((res%m) * (x%m))%m; y = y >> 1; x = ((x%m) * (x%m))%m; } return res%m; }
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
const ll INF = 0xFFFFFFFFFFFFFFFL;
ll clz(unsigned long long N) { return N ? 64LL - __builtin_clzll(N) : -INF;}//may not work for some compiler returns position of msb; 
clock_t time_p=clock();
void abhigyan10()
{time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline ll rnd(ll l=0,ll r=INF){return uniform_int_distribution<ll>(l,r)(rng);}
#define clrbuf cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define preciset(x) cout<<setprecision(x)<<fixed;
const ll mod =1000000007;
ll modinv(ll x)
{
	return pow(x,mod-2,mod);
}
int main()
{
        FastIO

        ll A,t,b,d;
        //double b,c;
        char c;
        cin>>A>>b>>c>>t;
        d= A*(b*100+t);

        
        	cout<<d/100;;
        return 0;
    }

Measured memory_bytes: 3660
N,A,B=map(int,input().split())
M=N
if A==0:
    print(0)
    exit()
if A+B>=N:
    print(min(A,N))
    exit()
cnt=N//(A+B)
ans=cnt*A
N=N-cnt*(A+B)
if N<=A+B and N>A:
    ans+=A
    print(ans)
    exit()
elif N<=A:
    ans+=M-cnt*(A+B)
    print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

using namespace std;

class Katana{
public:
	int a, b, n;
	Katana(int n, int a, int b) : n(n), a(a), b(b) {}

};

bool th_sort(Katana &r, Katana &l) {
	if (r.b != l.b)
		return r.b < l.b;
	else
		return r.a < l.a;
}

bool cut_sort(Katana &r, Katana &l) {
	if (r.a != l.a)
		return r.a < l.a;
	else
		return r.b < l.b;
}

int solv(int N, int H, std::vector<Katana> &cut) {
	std::vector<Katana> th;
	std::vector<bool> throwed;
	for(int i=0; i<N; i++) {
		th.push_back(Katana(i, cut[i].a, cut[i].b));
		throwed.push_back(false);
	}

	sort(cut.begin(), cut.end(), cut_sort);
	sort(th.begin(), th.end(), th_sort);

	int turn = 0;
	int most_cut = cut[N-1].a;
	int total_dmg = 0;
	for(int i=N-1; 0 <= i; i--) {
		if (most_cut < th[i].b) {
			H -= th[i].b;
			turn++;

			if(H <= 0) {
				return turn;
			}
		}
	}

	turn += H / most_cut;
	if(H % most_cut != 0) turn++;

	return turn;
}

int main(void) {
/*
	std::vector<Katana> x;
	x.push_back(Katana(0, 3, 5));
	cout << solv(x.size(), 10, x) << endl;;

	x.clear();
	x.push_back(Katana(0, 3, 5));
	x.push_back(Katana(1, 2, 6));
	cout << solv(x.size(), 10, x) << endl;;

	x.clear();
	x.push_back(Katana(0, 1, 1));
	x.push_back(Katana(1, 1, 10000000));
	x.push_back(Katana(2, 1, 30000000));
	x.push_back(Katana(3, 1, 99999999));
	cout << solv(x.size(), 1000000000, x) << endl;;

	x.clear();
	x.push_back(Katana(0, 35, 44));
	x.push_back(Katana(1, 28, 83));
	x.push_back(Katana(2, 46, 62));
	x.push_back(Katana(3, 31, 79));
	x.push_back(Katana(4, 40, 43));
	cout << solv(x.size(), 500, x) << endl;
	return 0;
*/
	int N;
	int H;

	cin >> N;
	cin >> H;

	vector<Katana> a;
	for(int i=0; i<N; i++) {
		int x, y;
		cin >> x;
		cin >> y;
		a.push_back(Katana(i, x, y));
	}

	cout << solv(N, H, a) << endl;;

    return 0;
}




Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define BS binary_search
#define all(c) (c).begin(),(c).end()
#define deb(a) cout<<#a<<" "<<a<<endl
#define WW 100000
#define INF 1000000000000000000 //1e18
#define EPS 0.000000001 //1e-9
//get<a>(t) gives ath element of tuple named t, numbering starts from 0
//max({_,......,_}) can give maximum of any number of elements. Similarly min also.
//don't forget to initialise freq arrays
//reverse(all(v)) would reverse a vector  
//pow(10.0, 2.0) can give exactly 100.0, slightly greater, or slightly less. 
//Therefore use(int)(pow(10.0,zz)+EPS)
int32_t main()
{
    IOS;
    int n; cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    int dp[n+10]={};
    //memset(dp,INF,sizeof(dp));
    for(int&x:dp)
        x=INF;
    dp[0]=0;
    if(n==1)
        {cout<<"0"; return 0;}
    //dp[1]=abs(h[1]-h[0]);
    for(int i=0;i<n;i++)
    {
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));      
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
/*
 * atcoder/abc094/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

struct X {
  ll n, v;
  bool operator<(const X& a)const{
    return v < a.v;
  }
};
const int MAX = 200100;
int N;
vector<X> xs;
ll med[MAX] = {0};

void solve() {
  cin >> N;
  ll x;
  loop(n,0,N) {
    cin >> x;
    xs.push_back({ n, x });
  }
  sort(xs.begin(), xs.end());
  int idx = N/2;
  loop(i,0,N) {
    int idx_ = idx <= i ? idx - 1 : idx;
    med[xs[i].n] = xs[idx_].v;
  }

  loop(n,0,N) cout << med[n] << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 7660
import heapq


def prim(adj):
    INF = 3000
    n = len(adj)
    state, d, p = [False] * n, [INF] * n, [-1] * n
    d[0] = 0
    pq = [(d[0], 0)]
    while pq:
        f, u = heapq.heappop(pq)
        state[u] = True
        if d[u] < f:
            continue
        for v, c in adj[u]:
            if state[v]:
                continue
            if c < d[v]:
                d[v] = c
                p[v] = u
                heapq.heappush(pq, (d[v], v))
    return d


def adj_matrix_to_list(matrix):
    n = len(matrix)
    li = [[] for _ in range(n)]
    for u in range(n):
        for v in range(n):
            if matrix[u][v] != -1:
                li[u].append((v, matrix[u][v]))
    return li


def main():
    n = int(input())
    m = [list(map(int, input().split())) for _ in range(n)]
    adj = adj_matrix_to_list(m)
    print(sum(prim(adj)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 6292
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int a;
	cin>>a;
	cout << a*a*a << endl;
	return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int a, b, t;
    cin >> a >> b >> t;

    cout << t/a * b << endl;

    return 0;
}


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

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

  int x;
  int distance = 0;

  for (int i = 0; i < N; i++) {
	  cin >> x;
	  if (x <= K - x) {
		  distance += x;
	  } else {
		  distance += K - x;
	  }
  }

  cout << distance * 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YN YES else NO
#define yn Yes else No
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

struct UnionFind {
  vector<ll> d;
  ll connection_count;
  UnionFind(ll n = 0) : d(n, -1) {
    connection_count = n;
  }
  ll find(ll x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    connection_count--;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(ll x, ll y) {
    return find(x) == find(y);
  }
  ll size(ll x) {
    return -d[find(x)];
  }
};

signed main() {
  init();
  ll N, M;
  cin >> N >> M;
  UnionFind uf(N);
  rep(i, M) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }

  // debug(uf.connection_count);
  COUT(uf.connection_count - 1);

  return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++)
		cin >> p[i];
	sort(p.begin(), p.end());
	cout << p[n / 2] - p[n / 2 - 1] << endl;
	return 0;
}

Measured memory_bytes: 640
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define TO_STRING(x) #x
# define debug(x) {cerr<<#x<<": "<<(x)<<"\n";}
# define Nmax (100000)
using namespace std;
using lint = long long;
template<class T> using grid = vector<vector<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
static const lint MOD = (lint)1e9+7;


int main()
{
    lint N;
    cin >> N;
    vector<lint> A(N+1);
    vector<lint> B(N);

    rep (i, N+1)
    {
        cin >> A[i];
    }
    rep (i, N)
    {
        cin >> B[i];
    }

    lint cnt = 0;
    rep (i, N)
    {
        if (A[i] - B[i] == 0)
        {
            cerr << "root A" << endl;
            cnt += A[i];
            A[i] = 0;
        }
        else if (A[i] - B[i] < 0)
        {
            cerr << "root B" << endl;
            cnt += A[i];
            cerr << cnt << endl;
            B[i] = B[i] - A[i];
            A[i] = 0;
            if (A[i+1] - B[i] == 0)
            {
                cnt += A[i+1];
                A[i+1] = 0;
            }
            else if (A[i+1] - B[i] < 0)
            {
                cnt += A[i+1];
                A[i+1] = 0;
            }
            else
            {
                cnt += B[i];
                A[i+1] = A[i+1] - B[i];
            }
        }
        else // A[i] > B[i]
        {
            cerr << "root C" << endl;
            lint tmp = B[i];
            cnt += tmp;
            A[i] = tmp;
        }
    }

    cout << cnt << endl;

    return 0;
}


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

using namespace std;

const int N = 2e5 + 5 , MOD = 1e9 + 7;
long long fact[N] , fact_inv[N];

int mul(long long a , long long b) {
    return a * b % MOD;
}

long long power(long long a , long long b) {
    if (!b) return 1;
    long long r = power(a , b / 2);
    r = mul(r , r);
    if (b&1) return mul(r , a);
    return r;
}

long long mod_inv(long long x) {
    return power(x , MOD - 2);
}

long long nCr(long long n , long long r){
    if (!n) return !r;
    if(r>n) return  0;
    return mul(fact[n] , mul(fact_inv[n - r] , fact_inv[r]));
}

void pre() {
    fact[0] = fact_inv[0] = 1;
    for(int i = 1 ; i < N ;i++) {
        fact[i] = mul(fact[i - 1] , i);
        fact_inv[i] = mod_inv(fact[i]);
    }
}

int add (int a , int b) {
    a += b;
    while (a >= MOD) a -= MOD;
    while (a < 0) a += MOD;
    return a;
}

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

    int n , m , k;
    cin >> n >> m >> k;

    pre();

    int ans = 0;
    for (int i = 1 ;i <= n ;i++) {
        int ways = n - i + 1;
        ways = mul(ways , mul(m , m - (i == 1)));
        ways = mul(ways , nCr(n * 1ll * m - 2 , k - 2));
        ans = add(ans , mul(ways , i - 1));
    }

    for (int i = 1 ;i <= m ;i++) {
        int ways = m - i + 1;
        ways = mul(ways , mul(n , n - (i == 1)));
        ways = mul(ways , nCr(n * 1ll * m - 2 , k - 2));
        ans = add(ans , mul(ways , i - 1));
    }

    cout << ans;
}

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

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

  int d1,d2,d3;
  if (a<b) d1=b-a;
  else d1=a-b;

  if (b<c) d2=c-b;
  else d2=b-c;

  if (a<c) d3=c-a;
  else d3=a-c;

  bool dd=true;
  if (d1>d) dd=false;
  if (d2>d) dd=false;

  if (dd || d3<=d) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,n) for(int i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  
  int count = 0;
  for(int i = 0; i < n; i++){
    int p;
    cin >> p;
    if(i+1 != p){
      count ++;
    }
    
    
  }
  
  if(count == 0 || count == 2){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }



}



Measured memory_bytes: 256