akhauriyash/Code-Regression huggingface dataset:
/** ２つの整数 a, b と１つの演算子 op を読み込んで、a op b を計算するプログラムを作成して下さい。
 * ただし、演算子 op は、"+"(和)、"-"(差)、"*"(積)、"/"(商)、のみとし、
 * 割り算で割り切れない場合は、小数点以下を切り捨てたものを計算結果とします。
 */

/*sucannerクラス使うためにインポート*/
import java.util.Scanner;
class Main{
	//プログラムのエントリポイント
	public static void main(String[] args){
		//入力ストリームの生成
		Scanner sc = new Scanner(System.in);


		//breakされるまでなんども処理を繰り返す
		while(true){
			//二つの数字と演算子を一つ受け取る
			int inta = sc.nextInt();
			String strop =  sc.next();
			int intb = sc.nextInt();


			//演算子に ? が入力されると処理を終了する
			if (strop.equals("?")){
				break;
			//演算子に＋が入った際、受け取った数字を＋して表示する
			}else if (strop.equals("+")) {
				System.out.println(inta + intb);
				//演算子に-が入った際、受け取った数字を-して表示する
			}else if (strop.equals("-")) {
				System.out.println(inta - intb);
				//演算子に*が入った際、受け取った数字を*して表示する
			}else if (strop.equals("*")) {
				System.out.println(inta * intb);
				//演算子に/が入った際、受け取った数字を/して表示する
			}else if (strop.equals("/")) {
				System.out.println(inta / intb);
			}

		}
	}
}

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

typedef long long ll;

int main() {
  ll N,M;
  cin >> N >> M;
  ll sum = 0;
  for (ll i = 0; i < M; i++) {
    int a;
    cin >> a;
    sum += a;
  }

  if (N >= sum) {
    cout << (N - sum) << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main() {
	int s, w;
	cin >> s >> w;
	if (s <= w)
		cout << "unsafe" << endl;
	else
		cout << "safe" << endl;
	return 0;
}


Measured memory_bytes: 3632
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	A := nextInt()
	B := nextInt()
	C := nextInt()
	x := C - (A - B)
	if x > 0 {
		fmt.Fprint(out, C-(A-B), "\n")
	} else {
		fmt.Fprint(out, 0, "\n")
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 640
from itertools import permutations
def chk(a,b):
    A,B=len(a),len(b)
    rt=[0]*A
    for i in range(A):
        f=1
        for j in range(min(A-i,B)):
            if a[i+j]!=b[j] and a[i+j]!='?' and b[j]!='?':
                f=0;break
        rt[i]=f
    return rt+[1]

def tri_chk(ix):
    i1,i2,i3=ix
    a,b,c=[S[i] for i in ix]
    ab,bc,ac=M[i1][i2],M[i2][i3],M[i1][i3]
    A,B,C=map(len,(a,b,c))
    rt=A+B+C
    for l in range(A+1):
        for r in range(l,A+B+1):
            if ab[l]==1 and (B<r-l or bc[r-l]==1) and ac[min(A,r)]==1:
                        alt=max(A,l+B,r+C)
                        if alt<rt:
                            rt=alt
    return rt

S=[input()for i in'abc']
A,B,C=map(len,S)
L=10**5
M=[[chk(S[i],S[j]) if i!=j else []for j in range(3)]for i in range(3)]

for i in permutations(range(3)):
    L=min(L,tri_chk(i))

print(L)

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

int main() {
	int n;
	while (cin >> n, n) {
		int ans = 0, b = 1;
		while (n) {
			int r = n % (-10);
			n /= (-10);
			if (r < 0) {
				++ n;
				r += 10;
			}
			ans += r * b;
			b *= 10;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
bool chmin(ll& a, ll& b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll& a, ll& b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n;
    inputv(A, n);
    sort(all(A));
    auto ite=unique(all(A));
    if (ite==A.end()) {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}


Measured memory_bytes: 2420
#include<cstdio>
#include<iostream>
using namespace std;
int a[100000],b[100000];
int main()
{
	int n,x=0;
	cin>>n;
	for(int i=0;i<n;i++)
	   cin>>a[i]>>b[i];
	for(int j=0;j<n;j++)
	{
		x+=b[j]-a[j];
	}
	cout<<x+n<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

string f(ll n) {
	if (n == 0)
		return "";
	if (n & 1) {
		return f((n - 1) / -2) + "1";
	}
	else {
		return f(n / -2) + "0";
	}
}

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

	ll n;
	cin >> n;
	if(n == 0) {
		cout << 0;
		return 0;
	}
	cout << f(n);
	return 0;
}

Measured memory_bytes: 256
import sys
import fractions
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
A, B, C, D = tuple(li())
def helper(A, B, C):
    return (B) // C - (A-1) // C
num1 = helper(A, B, C)
num2 = helper(A, B, D)
num3 = helper(A, B, C * D // fractions.gcd(C, D))
delta = num1 + num2 - num3
print(B - A + 1 - delta)


Measured memory_bytes: 5076
#include <map>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
    int n; cin >> n;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    map<long long, long long> m;
    long long s = 0;
    m[0] = 1;
    for (int i = 0; i < n; i++) {
        s += a[i];
        m[s]++;
    }
    long long ans = 0;
    for (auto x : m) {
        long long n = x.second;
        ans += n * (n-1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	int n;cin>>n;
	int Min=INT_MAX;
	for(int i=0;i<=n;i++){
		int a=i,b=n-i;
		int cnt=0;
		//int a=n;
		while(a){
			cnt+=a%9;
			a/=9;
		}
		int cnt2=0;
		//int b=n;
		while(b){
			cnt2+=b%6;
			b/=6;
		}
		Min=min(Min,cnt+cnt2);
	}
	cout<<Min<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int judge(int n, int k, int last, vector<int> a){
    int64_t sumb = 0 ; 
    vector<int> b(n,0) ;
    for (size_t i = 0; i < n; i++)
    {
        b.at(i) =  a.at(i) % last ;
        sumb += b.at(i) ;
    }
    sort(b.begin() , b.end()) ;
    int64_t numb = 0 ;
    for (int i = 0; i < (n- sumb/last); i++)
    {
        numb += b.at(i) ;
    }
    if (numb <= k)
    {
        return 1 ;
    }
return 0 ;
}

int main(){
    int64_t sum = 0 ;
    int n ;
    int64_t k ;
    cin >> n >> k ;
    vector<int> a(n) ;
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
        sum += a.at(i) ;
    }
    sort(a.begin() ,a.end() ) ;
    int64_t num = sum ;
    int64_t num2 = 0 ;
    int count2 = 0;
    int ans = 0 ;
    int p = n-1 ;
    for (int i = 0; i < n; i++)
    {
        if (sum % (i+1) == 0)
        {
            /* num -= a.at(n-1-i) ;
            while (a.at(p) > sum / (i+1))
            {
                num2 += a.at(p) ;
                count2 ++ ;
                p-- ;
            }
            
            if(num + (num2 - count2 * sum / (i+1)) <= k)
            {
                ans = sum / (i+1) ;
                break ;
            }*/
            if (judge(n,k,sum/(i+1),a) ==1 ){
                ans = sum / (i+1) ;
                break;
            }
        }
        
    }
    if (ans == 0)
    {
        int an= 0;
        int64_t last = sum /n;
        while (last > 0)
        {
            if (sum % last == 0)
            {
                an = judge(n,k,last,a) ;
                if (an == 1)
                {
                    ans = last ;
                    break ;
                }
                
            }
            last-- ;
        }
        
    }
    
    
    cout << ans << endl ;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	ll n;
	cin >> n;
	pair<ll,ll> arr[n];
	ll t1, t2;
	REP(i, 0, n){
		cin >> t1 >> t2;
		arr[i] = MK(t1, t2);
	}
	ll ans =0;
	for(int i = n-1; i >= 0; i--){
		ll a = arr[i].F;
		ll b = arr[i].S;
		a += ans;
		ans += (b - (a%b != 0? a%b:b));
	}
	cout << ans;

}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define long long long
#define LF '\n'
using namespace std;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;


signed main()
{
  cin.tie(nullptr), ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);

  for (int i= 0; i < n; ++i) cin >> a[i];

  a.erase(unique(a.begin(), a.end()), a.end());

  for (int i= 0; i < a.size(); ++i) {
    cout << a[i] << (i+1 < a.size() ? ' ' : LF);
  }

  return 0;
}




Measured memory_bytes: 3352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    ll a = abs(x) / d;
    if (k - a < 0) {
        cout << abs(x) - k * d << endl;
        return 0;
    }
    ll ev = abs(x) % d, od = d - abs(x) % d;
    cout << ((k - a) & 1 ? od : ev) << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n; cin >> n;
  vector<vector<int>> G(n);
  for(int i = 0; i < n-1; i++){
    int u, v; cin >> u >> v;
    u--, v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  static int dp[(int)1e5+10][2];
  function< void(int,int,int,int) > dfs =
  [&](int u, int pre, int t, int d){
    dp[u][t] = d;
    for(int v : G[u]){
      if(v == pre) continue;
      dfs(v, u, t, d+1);
    }
    return;
  };
  dfs(0, -1, 0, 0);
  dfs(n-1, -1, 1, 0);

  int f = 0, s = 0, eve = 0;
  for(int i = 0; i < n; i++){
    f += dp[i][0] < dp[i][1];
    s += dp[i][0] > dp[i][1];
    eve += dp[i][0] == dp[i][1];
  }
  f += eve;
  cout << (f > s ? "Fennec" : "Snuke") << endl;

  //cout << f << " " << s << " " << eve << endl;

  return 0;
}


Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n; 
	int a[102];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int cnt = 0;
	for(int i=0;i<n-1;i++){
		if(a[i]==a[i+1]){
			int c = (-1)*a[i];
			a[i+1] = c;
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

def main():
    N = int(input())
    A = list(map(int, input().split()))
    sumA = sum(A)//2
    B = A 
    odd = list(accumulate([0] + B[::2]+ B[1::2]))# 0+1, 2+3,...
    even = list(accumulate([0] + B[1::2]+ B[0::2]))# 1+2, 3+4,...

    # ans = [None] * N
    # for i in range(N):
    #     if i % 2 == 0:# evenから引く
    #         # print(even[N//2+i//2],even[i//2])
    #         ans[i] = 2*(sumA-(even[N//2+i//2]-even[i//2]))
    #     else:
    #         ans[i] = 2*(sumA-(odd[N//2+(i+1)//2]-odd[(i+1)//2]))
    # print(*ans)

    ## 別解 ##
    ans = [None] * N
    ans[0] = 2*(sumA - sum(A[1::2]))
    for i in range(N-1):
        ans[i+1] = 2*A[i] - ans[i]
    print(*ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 23620
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define _READ freopen("input.txt", "r", stdin);
#define _FAST                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
void solve()
{
    int n;
    cin>>n;
    set<string> s;
    for(int i=0;i<n;i++)
    {
        string s1;
        cin>>s1;
        s.insert(s1);
    }
    cout<<s.size();
}
int32_t main()
{
    _FAST

    int t;
    t=1;
    while (t--)
    {
        solve();
        //lb:;
    }

    return 0;
}

Measured memory_bytes: 19196
#include<stdio.h>
int main()
{
	int i,j,a[3][3],n,b[100],flag[3][3]={0},k=0;
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		scanf("%d",&a[i][j]);
	}
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&b[i]);
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			for(k=0;k<n;k++)
			{
				if(a[i][j]==b[k])
				flag[i][j]=1;
			}
		}
	}
	if((flag[0][0]+flag[0][1]+flag[0][2]==3)||(flag[1][0]+flag[1][1]+flag[1][2]==3)||(flag[2][0]+flag[2][1]+flag[2][2]==3)||(flag[0][0]+flag[1][0]+flag[2][0]==3)||(flag[0][1]+flag[1][1]+flag[2][1]==3)||(flag[0][2]+flag[1][2]+flag[2][2]==3)||(flag[0][0]+flag[1][1]+flag[2][2]==3)||(flag[0][2]+flag[1][1]+flag[2][0]==3))
	printf("Yes");
	else
	printf("No");
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<algorithm>
using namespace std;

int n;

int parent(int i) {return i/2;}
int left(int i) {return i*2;}
int right(int i) {return i*2+1;}

void maxheapify(int* A, int i){
    int l = left(i);
    int r = right(i);
    //左の子、自分、右の子で値が最大のを選ぶ
    int largest;
    if((l<=n)&&(A[l]>A[i])){
        largest = l;
    }else{
        largest = i;
    }if((r<=n)&&(A[r]>A[largest])){
        largest = r;
    }

    if(largest!=i){
        swap(A[i], A[largest]);
        maxheapify(A, largest); //下へ下へ向かっていく
    }
}

//buildmaxHeapはボトムアップにmaxheapifyを使うことで配列をヒープにする
void buildMaxHeap(int* A, int n){
    for(int i=n/2; i>0; i--){
        maxheapify(A, i);   //n/2 = nでぎりぎり
    }
}

int main(){

    scanf("%d", &n);

    int A[500000+1];
    for(int i=1; i<=n; i++){
        scanf("%d", &A[i]);
    }

    buildMaxHeap(A, n);

    for(int i=1; i<=n; i++){
        printf(" %d", A[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 4564
K, N = map(int, input().split())
A = list(map(int, input().split()))
 
max_distance = K + (A[0] - A[-1])
 
for i in range(1, N):
  max_distance = max(max_distance, A[i] - A[i - 1])
  
print(K - max_distance)

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

int main() {
    string s;
    cin >> s;
    if (s == "Sunny") cout << "Cloudy" << endl;
    else if (s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,i,j,f,x,y,z,ans = 0;scanf("%d%d",&n,&m);
  vector<int> v[n];bool g[n] = {};queue<int> q;
  for(i=0;i<m;i++){
    scanf("%d%d%d",&x,&y,&z);x--;y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for(i=0;i<n;i++){
    if(g[i]) continue;
    queue<int>().swap(q);q.push(i);
    while(!q.empty()){
      f = q.front();q.pop();g[f] = 1;
      for(j=0;j<v[f].size();j++){
        if(!g[v[f][j]]) q.push(v[f][j]);
      }
    }
    ans++;
  }
  printf("%d\n",ans);
}

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

int main(){
	int a, b;
	cin >> a >> b;
	
	if(a == 1) a=14;
	if(b == 1) b=14;
	
	if(a>b) printf("Alice\n");
	else if(a<b) printf("Bob\n");
	else printf("Draw\n");
	
	return 0;
}

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

int main(){
    bool ans = false;
    int a[3][3];
    rep(i,3)rep(j,3) cin >> a[i][j];
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i,n) cin >> b[i];
    rep(i,n){
        rep(j,3)rep(k,3){
            if(a[j][k] == b[i]){
                a[j][k] = -1;
            }
        }
    }

    rep(i,3){
        if(a[i][0] == a[i][1] && a[i][1] == a[i][2] && a[i][0] == -1) ans = true;
        if(a[0][i] == a[1][i] && a[1][i] == a[2][i] && a[0][i] == -1) ans = true;
        if(a[0][0] == a[1][1] && a[1][1] == a[2][2] && a[0][0] == -1) ans = true;
        if(a[0][2] == a[1][1] && a[1][1] == a[2][0] && a[1][1] == -1) ans = true;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

ll dp[51*51][51][51];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    dp[0][0][0] = 1;
    int n, A;
    cin >> n >> A;
    int sum = 0;
    vector<int> a(n);
    for(auto &el : a){
        cin >> el;
        sum += el;
    }
    for(int k = 0; k <= sum; ++k){
        for(int i = 1; i <= n; ++i){
            for(int j = 0; j <= n; ++j){
                dp[k][i][j] += dp[k][i-1][j];
                if(j-1 >= 0 and k-a[i-1] >= 0){
                    dp[k][i][j] += dp[k-a[i-1]][i-1][j-1];
                }
            }
        }
    }
    ll res = 0;
    for(int t = 1; t <= n; ++t){
        if(A*t <= sum){
            res += dp[A*t][n][t];
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 51456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

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

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		int m = fs.nextInt();
		
		Room[] roomArr = new Room[n];
		int[] visitedRoomArr = new int[n];
		
		for(int i = 0; i < n; i++) {
			roomArr[i] = new Room(i);
		}
		
		for(int i = 0; i < m; i++) {
			int a = fs.nextInt() - 1;
			int b = fs.nextInt() - 1;
			
			roomArr[a].pathList.add(b);
			roomArr[b].pathList.add(a);
		}
		
		ArrayDeque<Integer> queue = new ArrayDeque<>();
		for(int firstPath : roomArr[0].pathList) {
//			System.out.println(String.format("room id :%d", firstPath));
			queue.add(firstPath);
			visitedRoomArr[firstPath] = 1;
			roomArr[firstPath].nextPath = 0;
		}
		
		while(!queue.isEmpty()) {
			int roomId = queue.poll();
//			System.out.println(String.format("room id :%d", roomId));
			for(int path : roomArr[roomId].pathList) {
				if(visitedRoomArr[path] == 1) {
					continue;
				}
//				System.out.println(String.format("path id :%d", path));
				visitedRoomArr[path] = 1;
				roomArr[path].nextPath = roomId;
				queue.add(path);
			}
		}
		
		for(int i = 1; i < n; i++) {
			if(visitedRoomArr[i] == 0) {
				System.out.println("No");
				return;
			}
		}
		
		System.out.println("Yes");
		for(int i = 1; i < n; i++) {
			System.out.println(roomArr[i].nextPath + 1);
		}
	}
	
	class Room {
		int id;
		ArrayList<Integer> pathList;
		int nextPath;
		
		Room(int id) {
			this.id = id;
			pathList = new ArrayList<>();
		}
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 81556
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    int a, b;
    cin >> a >> b;
    
    if(a+b==15) cout << "+" << endl;
    else if(a*b==15) cout << "*" << endl;
    else cout << "x" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#define dout(i) //
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
const int maxn = 200000;

namespace graph {
	static vector<int> edge[maxn];
	int get_longest(int cur){
		static int dp[maxn];
		if(dp[cur])return dp[cur];
		for(int &i : edge[cur])dp[cur] = max(dp[cur], get_longest(i) + 1);
		return dp[cur];
	}
} // graph
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n, m;
	cin >> n >> m;
	for(int a, b, i = 0;i < m;++i){
		cin >> a >> b;
		graph::edge[a].emplace_back(b);
	}
	int res = 0;
	for(int i = 1;i <= n;++i)res = max(res, graph::get_longest(i));
	cout << res << '\n';
}

Measured memory_bytes: 9728
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<limits.h>

long max(long a, long b){
	if(a>b) return a;
	else return b;
}

int main(){
	long n;
	long tx, ty, th;
	long x[100], y[100], h[100], h_tmp;
	long ttx, tty, tth;
	bool isSet = false;
	int i;
	scanf("%d\n", &n);
	for(i=0; i<n; i++){
		scanf("%d %d %ld\n", &tx, &ty, &th);
		x[i] = tx;
		y[i] = ty;
		h[i] = th;
		if(!isSet && th != 0){
			ttx = tx;
			tty = ty;
			tth = th;
			isSet = true;
		}
	}
	for(int cx=0; cx<=100; cx++){
		for(int cy=0; cy<=100; cy++){
			h_tmp = abs(ttx - cx) + abs(tty - cy) + tth;
			for(i=0; i<n; i++){
				if (h[i] != max(h_tmp - abs(x[i] - cx) - abs(y[i] - cy), 0)) break;
			}
			if(i==n) {
				printf("%d %d %ld\n", cx, cy, h_tmp);
				return 0;
			}
		}
	}
	return 0;
}




Measured memory_bytes: 128
n=int(input())
li=list(map(int,input().split()))
dp=[0]*(n)
dp[0]=0
dp[1]=dp[1]+abs(li[1]-li[0])

for i in range(2,n):
  dp[i]=min((dp[i-1]+abs(li[i]-li[i-1])),dp[i-2]+abs(li[i]-li[i-2]))
print(dp[n-1])
  

Measured memory_bytes: 20536
#include <stdio.h>
int main (int argc, char * argv[])
{
    int n,m,a1,b1;
    int a[100][100];
    int b[100];
    int c[100];
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<1;j++){
        scanf("%d",&b[i]);
        }
        
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            c[i] += a[i][j]*b[j];
        }
        printf("%d\n",c[i]);
    }
    return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    ll n,m;
    cin>>n>>m;
    ll sum=0;
    rep(i,m){
        ll a;
        cin>>a;
        sum+=a;
    }

    if(sum>n) cout<<-1<<endl;
    else cout<<n-sum<<endl;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<pair<T, T>>& vp) {
	for (int i = 0; i < vp.size(); ++i) {
		s << "(" << vp[i].first << "," << vp[i].second << ")" << ( i+1 == vp.size() ? "" : ",\t" );
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	int n,m,X,Y;
	cin >>n >> m >> X >> Y;
	VL x(n),y(m);
	cin >>  x >> y;
	x.push_back(X);
	y.push_back(Y);
	SORT(x);
	SORT(y);
	if (x.back() < y.front()) {
		cout << "No War" << endl;
	} else {
		cout << "War" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
s=input()
while len(s)>7:
    if s[-5:]=='dream' or s[-5:]=='erase':
        s=s[:-5]
    elif s[-6:]=='eraser':
        s=s[:-6]
    elif s[-7:]=='dreamer':
        s=s[:-7]
    else:
        print('NO')
        exit()
print('YES' if s=='erase' or s=='dreamer' or s=='dream' or s=='eraser' or s=='' else 'NO')

Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////

struct quad {
	ll x;
	ll y;
	ll z;
	ll sum;
};



int main() {

	ll X, Y, Z, K;
	ll A[2000], B[2000], C[2000];
	cin >> X >> Y >> Z >> K;

	repn(i, X) { cin >> A[i]; }
	repn(i, Y) { cin >> B[i]; }
	repn(i, Z) { cin >> C[i]; }

	sort(C + 1, C + Z + 1);

	priority_queue<quad, vector<quad>, function<bool(quad, quad)>>q(
		[](quad a, quad b) {return a.sum < b.sum; }
	);

	repn(i, X) {
		repn(j, Y) {
			q.push({ i,j,Z,A[i] + B[j] + C[Z] });
		}
	}

	repn(i, K) {
		quad a = q.top();
		q.pop();
		cout << a.sum << endl;
		if (a.z > 1) {
			q.push({ a.x,a.y,a.z - 1,A[a.x] + B[a.y] + C[a.z - 1] }); }
	}



	system("PAUSE");
}

Measured memory_bytes: 34916
def main_v1():
    grade = ""
    while True:
        mid, final, re = map(int, input().split())
        if mid == -1 and final == -1 and re == -1:
            break
        if mid == -1 or final == -1:
            grade = "F"
        elif mid + final >= 80:
            grade = "A"
        elif mid + final >= 65:
            grade = "B"
        elif mid + final >= 50:
            grade = "C"
        elif mid + final >= 30:
            if re >= 50:
                grade = "C"
            else:
                grade = "D"
        else:
            grade = "F"
        print(grade)
    return 0

if __name__ == "__main__":
    main_v1()


Measured memory_bytes: 5600
from collections import deque
k = int(input())
queue = deque([1,2,3,4,5,6,7,8,9])
for _ in range(k-1):
    x = queue.popleft()
    if x % 10 != 0:
        queue.append(10*x+(x%10)-1)
    queue.append(10*x+(x%10))
    if x % 10 != 9:
        queue.append(10*x+(x%10)+1)
print(queue.popleft())

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)

int main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	return(0);
}

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

using namespace std;

const int N = 500;

int n;
int c;
long long res = 1e18;
int f[3][31];
int s[31][31];
int d[31][31];
int C[N + 1][N + 1];

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> c;
    for(int i = 1; i <= c; i++)
        for(int j = 1; j <= c; j++)
            cin >> d[i][j];
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++) {
            cin >> C[i][j];
            int k = (i + j) % 3;
            f[k][C[i][j]]++;
        }
    for(int i = 1; i <= c; i++)
        for(int j = 1; j <= c; j++)
            for(int k = 1; k <= c; k++)
                if(i != j && j != k && k != i) {
                    memset(s, 0, sizeof(s));
                    long long tot = 0;
                    for(int l = 1; l <= c; l++) {
                        if(l != i) tot += 1LL * f[0][l] * d[l][i];
                        if(l != j) tot += 1LL * f[1][l] * d[l][j];
                        if(l != k) tot += 1LL * f[2][l] * d[l][k];
                    }
                    res = min(res, tot);
                }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
int main(){
    int a,b,c,t;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
    t=a;
    a=b;
    b=t;
    }
    if(c<a){
    t=c;
    c=b;
    b=a;
    a=t;
    }
    else if(c>=a&&c<b){
    t=c;
    c=b;
    b=t;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}








Measured memory_bytes: 2044
#include <iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
vector<int>  foo,s;
typedef long long int ll;
int n;
ll k;
int main()
{
    cin >> n >> k;
    vector<bool> flag(n+1);
    int x, tail,hed;
    foo.push_back(-1);
    s.push_back(-1);
    for (int i = 1; i <=n; ++i) { cin >> x; foo.push_back(x); }
    for (int i = 1;;) {
        if (!flag[foo[i]]) {
            s.push_back(foo[i]);
            flag[foo[i]] = 1;
            i = foo[i];
        }
        else { 
           tail = s.size()-1;
           for (int j = 1; ; ++j) {
                if (s[j] == foo[i]) {
                    hed = j;
                    break;
                }
               
            }
            break;
        }
    }
    int loop = tail - hed+1;
    int ans;
    if (k > tail)
        ans = (k - hed ) % loop+hed;
    else ans = k;
    cout << s[ans] << endl;
    return 0;
}

Measured memory_bytes: 5644
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef double db; //
typedef string str; //
//
typedef pair<int,int> pi;
typedef pair<ll,ll> pl; //
typedef pair<db,db> pd; //
//
typedef vector<int> vi; 
typedef vector<ll> vl; //
typedef vector<db> vd; //
typedef vector<str> vs; //
typedef vector<pi> vpi;
typedef vector<pl> vpl; //
typedef vector<pd> vpd; //
 
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() //
#define rsz resize
#define ins insert //
#define ft front() //
#define bk back()
#define pf push_front //
#define pb push_back
#define eb emplace_back //
#define lb lower_bound //
#define ub upper_bound //
 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
 
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5; //
const ll INF = 1e18; //
const ld PI = acos((ld)-1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1}; //
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); //
//
template<class T> bool ckmin(T& a, const T& b) { 
	return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { //
	return a < b ? a = b, 1 : 0; } //
constexpr int pct(int x) { return __builtin_popcount(x); } //
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x)) //
constexpr int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0 //
// IGNORE
int fstTrue(function<bool(int)> f, int lo, int hi) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true 
		int mid = (lo+hi)/2; 
		f(mid) ? hi = mid : lo = mid+1; 
	} 
	return lo;
}
template<class T> void remDup(vector<T>& v) { 
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// IGNORE
//
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N;
	cin >> N;
	int cnt = 0;
	F0R(a, N){
		int temp;
		cin >> temp;
		if(a % 2 == 0 && temp % 2)
			cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3648
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))

n = int(input())

list_s = []
for i in range(n):
    list_s.append(int(input()))

# 該当箇所に-1を埋める
for i in list_s:
    for j in [list_a, list_b, list_c]:
        for k in range(3):
            if j[k] == i:
                j[k] = -1

# 判定
# 横の判定
for i in [list_a, list_b, list_c]:
    if i[0] == -1 and i[1] == -1 and i[2] == -1:
        print("Yes")
        exit()

# 縦の判定
for i in range(3):
    if list_a[i] == -1 and list_b[i] == -1 and list_c[i] == -1:
        print("Yes")
        exit()

# 斜め
if list_a[0] == -1 and list_b[1] == -1 and list_c[2] == -1:
    print("Yes")
    exit()

if list_a[2] == -1 and list_b[1] == -1 and list_c[0] == -1:
    print("Yes")
    exit()

print("No")

Measured memory_bytes: 3064
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
#include<time.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ")
#define pdd(a,n,m)for(int i=0;i<m;i++)pd(a,m)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

string s,t;

int main(){
  cin>>s>>t;
  cout<<t+s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY (1<<21)

int n,M[MAX][MAX];

int prim(){
  int u,minv;
  int i,j;
  int d[MAX],p[MAX],color[MAX];
  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i]!=BLACK){
        u=i;
        minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(j=0;j<n;j++){
      if(color[j]!=BLACK && M[u][j]!=INFTY){
        if(d[j]>M[u][j]){
          d[j]=M[u][j];
          p[j]=u;
          color[j]=GRAY;
        }
      }
    }
  }
  int sum=0;
  for(i=0;i<n;i++){
    if(p[i]!=-1)sum+=M[i][p[i]];
  }
  return sum;
}
int main(){
  int i,j,e;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      M[i][j]=(e==-1)?INFTY: e;
    }
  }
  printf("%d\n",prim());
  return 0;
}


Measured memory_bytes: 2060
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int a,b; cin >> a >> b;
  if(a <= 2*b){
    cout << 0 << endl;
  } else {
    cout << a-2*b << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

int D[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	ll N = 0, K = 0;
	char c;
	while ((c = getchar_unlocked()) >= '0') N = N * 10 + c - '0';
	while ((c = getchar_unlocked()) >= '0') K = K * 10 + c - '0';

	int A[200001];
	rep1(i, N) A[i] = getint();

	int d = 1;
	int p = 1;
	while (D[p] == 0) {
		D[p] = d++;
		p = A[p];
	}
	if (K > D[p]) {
		ll k = K - D[p];
		k %= d - D[p];
		K = D[p] + k;
	}
	p = 1;
	while (D[p] < K) p = A[p];
	printf("%d", A[p]);

	Would you please return 0;
}

Measured memory_bytes: 3288
#include <stdio.h>

int main(void){
    int num,i,x;

    scanf("%d",&num);
    for(i=1;i<=num;i++){
        x=i;
        if(x%3==0){
            printf(" %d",i);
        }else do{
            if(x%10==3){
                printf(" %d",i);
                break;
            }
            x/=10;
        }while(x);
    }
    puts("");
    return 0;
}

Measured memory_bytes: 608
n, t = map(int, input().split())
li = list(map(int, input().split()))
li = li[::-1]
ans = 0

for i in range(n):
  if i == 0:
    ans += t
  if i >= 1:
    if li[i-1]-li[i] >= t:
      ans += t
    else:
      ans += li[i-1]-li[i]
print(ans)

Measured memory_bytes: 25200
#include <iostream>
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

long long ncr(int n, int r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod(ll a,ll b,ll m){
    if(b==0)return 1;
    if(b%2==0){
        ll y =  mod(a,b/2,m);
        return (y*y)%m;
    }
    else{
        return ((a%m)*mod(a,b-1,m))%m;
    }
}

ll modinv(ll a,ll m){
return mod(a,m-2,m);
//works only for prime m.
//else calculate phi(m)-1.
}



int main()
{
    bool ok=true;
    string s;
    cin>>s;
    int n=s.length();
    for(int i=0;i<n;i++){
        if(i&1){
            if(s[i]=='R')ok=false;
        }
        else{
            if(s[i]=='L')ok=false;
        }

    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 3608
N = gets.to_i
S = gets.chomp

WOLF = 0
SHEEP = 1

def check(list, idx)
  N.times do |j|
    i = (idx + j) % N
    left = i - 1
    right = (i + 1) % N

    if list[i] == SHEEP
      if S[i] == 'o'
        return [false, list] if list[left] == WOLF && list[right] == SHEEP
        return [false, list] if list[left] == SHEEP && list[right] == WOLF

        if list[left] == WOLF
          list[right] = WOLF
        else
          list[right] = SHEEP
        end
      else
        return [false, list] if list[left] == WOLF && list[right] == WOLF
        return [false, list] if list[left] == SHEEP && list[right] == SHEEP

        if list[left] == WOLF
          list[right] = SHEEP
        else
          list[right] = WOLF
        end
      end
    else
      if S[i] == 'o'
        return [false, list] if list[left] == WOLF && list[right] == WOLF
        return [false, list] if list[left] == SHEEP && list[right] == SHEEP

        if list[left] == WOLF
          list[right] = SHEEP
        else
          list[right] = WOLF
        end
      else
        return [false, list] if list[left] == WOLF && list[right] == SHEEP
        return [false, list] if list[left] == SHEEP && list[right] == WOLF

        if list[left] == WOLF
          list[right] = WOLF
        else
          list[right] = SHEEP
        end
      end
    end
  end

  [true, list]
end

# case 1
list = Array.new(N, -1)
idx = S.index('o')

if idx.nil?
  puts 'S' * N
  exit
end

left = idx - 1
right = (idx + 1) % N

o_patterns = [
  [SHEEP, SHEEP, SHEEP],
  [WOLF, SHEEP, WOLF],
  [WOLF, WOLF, SHEEP],
  [SHEEP, WOLF, WOLF],
]

o_patterns.each do |p1, p2, p3|
  list = Array.new(N, -1)
  list[left] = p1
  list[idx] = p2
  list[right] = p3
  res, ans = check(list, right)

  if res
    puts ans.map { |v| ['W', 'S'][v] }.join
    exit
  end
end

idx = S.index('x')

if idx.nil?
  puts 'W' * N
  exit
end

left = idx - 1
right = (idx + 1) % N

x_patterns = [
  [SHEEP, SHEEP, WOLF],
  [WOLF, SHEEP, SHEEP],
  [WOLF, WOLF, WOLF],
  [SHEEP, WOLF, SHEEP],
]

x_patterns.each do |p1, p2, p3|
  list = Array.new(N, -1)
  list[left] = p1
  list[idx] = p2
  list[right] = p3
  res, ans = check(list, right)

  if res
    puts ans.map { |v| ['W', 'S'][v] }.join
    exit
  end
end

puts -1


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

const long long INF = 1LL << 60;

int main() {
    int N, K; cin >> N >> K;
    vector<long long> h(N); for (int i = 0; i < N; i++) cin >> h[i];

    sort(h.begin(), h.end());
    long long ans = INF;

    for (int i = 0; i <= N - K; i++){
        ans = min(ans, h[i + K - 1] - h[i]);
    }

    cout << ans << endl;
}

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

void call(int n)
{
    int i = 1;
CHECK_NUM:
    int x = i;
    if (x % 3 == 0)
    {
        cout << " " << i;
        goto END_CHECK_NUM;
    }
INCLUDE3:
    if (x % 10 == 3)
    {
        cout << " " << i;
        goto END_CHECK_NUM;
    }
    x /= 10;
    if (x)
        goto INCLUDE3;
END_CHECK_NUM:
    if (++i <= n)
        goto CHECK_NUM;

    cout << endl;
}
int main()
{
    int n;
    cin >> n;
    //call(n);

    for (int i = 1; i <= n; i++)
    {
        int x = i;
        if (i % 3 == 0)
        {
            cout << " " << i;
        }
        else
        {
            do
            {
                if (x % 10 == 3)
                {
                    cout << " " << i;
                    break;
                }
                x /= 10;
            } while (x);
        }
    }

    cout << endl;

    return 0;
}



Measured memory_bytes: 3096