akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var AP = Console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
            var A = AP[0];
            var P = AP[1];
            Console.WriteLine((A*3+P)/2);
        }
    }
}


Measured memory_bytes: 13268
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#include <cstdio>
using namespace std;
vector<ll>a;
int n,k;
ll hoge(int x){
    int y = x+k-1;
    if(a[y]<=0){
        return -a[x];
    }else{
        if(a[x] <=0){
            return a[y]-a[x]+min(a[y],-a[x]);
        }else{
            return a[y];
        }
    }
}
int main(){
    cin >> n >> k;
    a.resize(n);
    int id = -1;
    rep(i,n){
        cin >> a[i];
        if(id == -1 and a[i]>=0){
            id = i;
        }
    }
    ll ans = LONG_LONG_MAX;
    rep(i,n-k+1){
        ans = min(ans,hoge(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using ll = long long;
using  INT = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)

using namespace std;
/*........................................DEFINE FUNCTIONS.........................................*/


/*....................................DEFINE GLOBAL VARIABLES .....................................*/



/*.........................................kemkemG0................................................*/
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N, K;
	cin >> N >> K;
	REP(i, N) {int a; cin >> a;}
	int ans = (N - 1) / (K - 1);
 	cout << (((N - 1) % (K - 1) == 0) ? ans : ans + 1) << endl;




	return 0;
}








Measured memory_bytes: 3576
#include <stdio.h>
int main (){

int a,b,c,d,e,i,j,k;

scanf ("%d",&a);
scanf ("%d",&b);
scanf ("%d",&c);
scanf ("%d",&d);
scanf ("%d",&e);

if (a<=0){
	i=(-a)*c+d+b*e;
}
else {
	i=(b-a)*e;
}

printf ("%d\n",i);

return 0;
}

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

int main() {
  int N;
  cin >> N;
  double T,A;
  cin >> T >> A;
  
  vector<int> H(N);
  double min = 100000;
  int ans=-1;
  for(int i=0; i<N; i++){
    cin >> H.at(i);
    if(min*min>(A-(T-H.at(i)*0.006))*(A-(T-H.at(i)*0.006))){
      min = A-(T-H.at(i)*0.006);
      ans = i+1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S; cin >> S;
  int N = S.size();
  string ans = "";
  REP(i, N){
    ans += 'x';
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
 
        StringTokenizer st = new StringTokenizer(br.readLine());
        ArrayList<Integer> boxes = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            boxes.add(Integer.parseInt(st.nextToken()));
        }
 
        Collections.swap(boxes,0, 1);
        Collections.swap(boxes,0, 2);
 
        pw.println(boxes.get(0) + " " + boxes.get(1) + " " + boxes.get(2));
 
        pw.close();
 
    }
}

Measured memory_bytes: 21332
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)


function main()
N,M = parseMap(split(readline()))

H = parseMap(split(readline()))
ok_list = zeros(Int,N)
for i in 1:M
    a,b = parseMap(split(readline()))
    if H[a] == H[b]
        ok_list[a] = 1
        ok_list[b] = 1
    elseif  H[a] > H[b]
        ok_list[b] = 1
    else
        ok_list[a] = 1
    end
end




println(N - sum(ok_list))


end

main()

Measured memory_bytes: 201312
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    while(true){
      int a = sc.nextInt();
      String op = sc.next();
      int b = sc.nextInt();
      if(op.equals("?")){
        break;
      }else if(op.equals("+")){
        System.out.println(a + b);
      }else if(op.equals("-")){
        System.out.println(a - b);
      }else if(op.equals("*")){
        System.out.println(a * b);
      }else{
        System.out.println(a / b);
      }
    }
  }
}



Measured memory_bytes: 26236
/**
 * @author yuichirw
 *
 */
import java.util.*;
import static java.lang.Math.*;

public class Main {
	static int n;
	static Scanner sc = new Scanner(System.in);
	
	static boolean read() {
		n = sc.nextInt();
		return (n == 0) ? false : true;
	}
	
	static int solve() {
		int a,b,c,p,w,res;
		a = n / 200; b = n / 300; c = n / 500;
		res = 9999999;
		for(int i = 0; i <= a; i++) {
			for(int j = 0; j <= b; j++) {
				for(int k = 0; k <= c; k++) {
					w = 200 * i + 300 * j + 500 * k;
					if(w == n) {
						p = (int)(((i / 5) * 5 * 0.8  + (i % 5)) * 380 + 
								 ((j / 4) * 4 * 0.85 + (j % 4)) * 550 +
								 ((k / 3) * 3 * 0.88 + (k % 3)) * 850);
						res = min(res, p);
					}
				}
			}
		}
		return res;
	}
	
	public static void main(String[] args) {
		while(read()) {
			System.out.println(solve());
		}
	}

}

Measured memory_bytes: 12000
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

typedef long long ll;

const ll MOD = 1e9 + 7;

class EWhoSaysAPun {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N;
	    string S;
	    in >> N >> S;

	    int answer = 0;
	    // interval == l2 - l1
	    REP(interval,1,N) {
	        int len = 0;
	        REP(l1,0,N-interval) {
	            int l2 = l1 + interval;
	            if (S[l1] != S[l2]) {
	                len = 0;
	                continue;
	            }
	            len = min(len+1,interval);
	            answer = max(answer, len);
	        }
	    }
	    out << answer << "\n";
	}
};


int main() {
	EWhoSaysAPun solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define ll long long int
int compare_longlong(const void *a, const void *b) {long long *A = (long long *)a;long long *B = (long long *)b;if (*A > *B) return -1;if (*A < *B) return 1;return 0;}
int main(void){
	int n;
	scanf("%d",&n);
	ll a[3*n];
	for(int i=0;i<3*n;i++)scanf("%lld",&a[i]);
	qsort(a,3*n,sizeof(ll),compare_longlong);
	ll ans=0;
	for(int i=1;i<=2*n;i+=2){
		ans += a[i];
	}
	printf("%lld",ans);
	
	
	
	return 0;
}

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

int main() {
  int i = 1;
  int x;
  while (1) {

    cin >> x;
    if (x == 0) {
      /* code */
      break;
    }

    cout << "Case "<< i << ": " << x << '\n';
    i++;


  }

  return 0;
}



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

int main(){

    int N;
    string S,Q;
    cin >> N;
    cin >> S;

    Q = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";

    for(int i=0; i<S.size(); i++){
        for(int j=0; j<27; j++){
            if(Q[j]==S[i]){
                S[i] = Q[j+N];
                break;
            }
        }
    }

    cout << S << endl;
}

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

using namespace std;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()

#define MAX_LOG_N 17

int main() {
  int N; cin >> N;
  vector<vector<int>> hotels(2, vector<int>(N));
  REP(i, N) cin >> hotels[0][i];
  REP(i, N) hotels[1][i] = hotels[0][N-1] - hotels[0][N-1-i];

  int L, Q; cin >> L >> Q;
  vector<int> A(Q), B(Q); REP(i, Q) cin >> A[i] >> B[i], A[i]--, B[i]--;

  // doubling
  vector<vector<vector<int>>> doubling(2, vector<vector<int>>(MAX_LOG_N, vector<int>(N)));
  REP(k, 2) REP(i, N) {
    doubling[k][0][i] = upper_bound(ALL(hotels[k]), hotels[k][i] + L) - hotels[k].begin() - 1;
  }
  REP(k, 2) REP(i, MAX_LOG_N-1) REP(j, N) {
    doubling[k][i+1][j] = doubling[k][i][doubling[k][i][j]];
  }

  REP(q, Q) {
    int k = A[q] > B[q], a = A[q], b = B[q];
    if (a > b) a = N-1 - a, b = N-1 - b;
    assert(a < b);

    int ans = 0;
    for (int i = MAX_LOG_N-1; i >= 0; i--) {
      if (doubling[k][i][a] < b) ans += 1 << i, a = doubling[k][i][a];
    }
    cout << ans+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 22648
#include<iostream>
using namespace std;
int main(){
	string str;
	char a[20];
	cin>>str;
	for(int i=0;i<str.size();i++){
		a[str.size()-i-1]=str[i];
	}
	for(int i=0;i<=str.size();i++){
		str[i]=a[i];
	}
	cout<<str<<endl;
	return 0;
}		


Measured memory_bytes: 3040
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;

map<string, int> dp;
int dir[4]={1,-1,4,-4};

void bfs()
{
    queue<string> q;
    q.push("01234567");
    dp["01234567"]=0;
    while(!q.empty())
    {
      string now = q.front();
      q.pop();
      int p=0;
      for(int j=0; j<8; j++)
      {
          if(now[j]=='0')
          {
              p=j; break;
          }
      }
      for(int i=0; i<4; i++)
      {
          int n=p+dir[i];
          if(n>=0 &&n<8 && !(p==3&&i==0)&&!(p==4&&i==1))
          {
              string next = now;
              swap(next[p], next[n]);
              if(dp.find(next)==dp.end())
              {
                  dp[next]=dp[now]+1;
                  q.push(next);
              }
          }
      }
    }
}


int main()
{
    bfs();
    string s;
    while(getline(cin, s))
    {
        s.erase(remove(s.begin(), s.end(), ' '), s.end());
        cout<<dp[s]<<endl;
    }

}

Measured memory_bytes: 3436
import java.util.*;
import java.io.*;

public class Main {

    FastReader in = new FastReader();
    PrintWriter out = new PrintWriter(System.out);
    int N = (int)1e5+1, mod = (int)1e9+7,n,m; 


    void solve(){
        int n = in.ni(), k = in.ni();
        long[] dp = new long[n];
        int[] h = new int[n];
        for(int i=0;i<n;i++){
            h[i] = in.ni();
            dp[i] = (int)1e10;
        }
        dp[0] = 0L;
        for(int i=1;i<n;i++)
            for(int j=Math.max(0,i-k);j<i;j++)
                dp[i] = Math.min(dp[i],dp[j]+Math.abs(h[i]-h[j]));
        out.println(dp[n-1]);
    }

    void run(){
        solve();
        // out.flush();
        out.close();
    }
    public static void main(String[] args) {
        boolean memory = false;
        Thread t=new Thread(null, null, "T", 1<<28) {
            public void run() {
                new Main().run();
            }
        };
        if(memory) t.start();
        else new Main().run();
    }
    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next(){
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine(){
            String str = "";
            try{   
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }  
            return str;
        }
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}
    }
    class Edges{
        int u,v,w;
        public Edges(int u,int v,int w){
            this.u = u;
            this.v = v;
            this.w = w;
        }
    }
    void pn(Object o){out.println(o);out.flush();}
    long inv(long a, long b){return 1<a ? b - inv(b%a,a)*b/a : 1;}//a^(-1)%b
    long fe(long a,long b){
        long ans = 1L;
        while(b>0){
            if((b&1)>0)ans=ans*a%mod;
            a = a%mod*a%mod;
            b>>=1;
        }
        // pn("ans = "+ans);
        return ans;
    }
    long gcd(long a,long b){
        if(a==0)return b;
        return gcd(b%a,a);
    }
    class pair{
        int x,y;
        public pair(int f,int s){
            this.x = f;
            this.y = s;
        }
    }
    class triple{
        int i,l,r;
        public triple(int i,int l,int r){
            this.i = i;
            this.l = l;
            this.r = r;
        }
    }
}

Measured memory_bytes: 32640
package main

import "fmt"

func main() {
	var N, M, w int
	MOD := 1000000007
	fmt.Scan(&N, &M)
	a := make([]int, N+2)
	ng := make([]bool, N+2)
	for i := 0; i < M; i++ {
		fmt.Scan(&w)
		ng[w] = true
	}
	a[0] = 1
	for i := 0; i < N; i++ {
		if !ng[i+1] {
			a[i+1] += a[i]
			a[i+1] %= MOD
		}
		if !ng[i+2] {
			a[i+2] += a[i]
			a[i+2] %= MOD
		}
	}
	fmt.Println(a[N])
}

Measured memory_bytes: 5504
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            String T = Console.ReadLine();
            String answer = "No";
            String Tdash = T.Substring(0, T.Length - 1);
            if(Tdash == S){
                answer = "Yes";
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 25892
import copy
from itertools import permutations, product

n = int(input())
al = []
xyl = []
for i in range(n):
    a = int(input())
    al.append(a)
    tl = []
    for j in range(a):
        t = [int(i) for i in input().split()]
        tl.append(t)
    xyl.append(tl)

l = [i for i in product([0, 1], repeat=n)]

ans_list = []

for ll in l:
    ans_flag = 1
    for i in range(n):
        flag = 1
        for j in range(al[i]):
            if ll[xyl[i][j][0]-1] != xyl[i][j][1]:
                flag = 0
        if flag != ll[i]:
            ans_flag = 0
    if ans_flag == 1:
        ans_list.append(copy.deepcopy(ll))

ans = 0
for i in ans_list:
    k = i.count(1)
    if ans < k:
        ans = k

print(ans)

Measured memory_bytes: 48876
#include <iostream>
#include <vector>

int main () {
  std::vector<int> x, y;
  while (1)
  {
    int a, b;
    std::cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    x.push_back(a);
    y.push_back(b);
  }
  for (int i = 0; i < x.size(); i++)
  {
    if (x[i] < y[i]) {
      std::cout << x[i] << " " << y[i] << std::endl;
    } else {
      std::cout << y[i] << " " << x[i] << std::endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3068
n = int(input())
a = list(map(int, input().split()))

nums = [0] * (max(a) + 1)
for i in range(len(a)):
    nums[a[i]] += 1

from scipy.special import comb

all = 0
for i in range(len(nums)):
    all += comb(nums[i], 2, exact=True)

for k in range(n):
    print(all - (nums[a[k]] - 1))


Measured memory_bytes: 51356
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n;
int cnt[10][10];

int main(){
    cin >> n;
    int ans = 0;
    for(int i = 1;i <= n;i++){
        int a = i;
        while(a >= 10)a /= 10;
        int b = i % 10;
        cnt[a][b]++;
    }
    for(int i = 1;i <= n;i++){
        int a = i;
        while(a >= 10)a /= 10;
        int b = i % 10;
        ans += cnt[b][a];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>

using namespace std;

int main()
{
	string s, t;
	
	cin >> s;
	cin >> t;
	
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
		
	if (s < t){
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}
	
	return (0);
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x"=" << x <<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 100001

vector<vector<int>> alphabet;

int main(){
	cin.sync_with_stdio(false);
	string s;
	cin >> s;

	alphabet.resize(26);

	alphabet[s[0] - 'a'].pb(0);
	int b = -1, e = -1;
	repl(i, 1, s.size()) {
		int a = s[i] - 'a';
		alphabet[a].pb(i);

		int last = alphabet[a].size() - 1;
		repr(j, last) {
			if (alphabet[a][last] - alphabet[a][j] + 1 < 2 * (last - j + 1)) {
				b = alphabet[a][j] + 1;
				e = alphabet[a][last] + 1;
				break;
			}
		}
		if (b != -1) break;
	}

	cout << b << " " << e << endl;

	return 0;
}

Measured memory_bytes: 1104
//b
#include <iostream>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <functional>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>

#define REP(i,b,n) for(int i=b;i<n;i++)
#define REPR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PB push_back
#define MP make_pair

using namespace std;

static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;	

int main(){
	
	ll e;
	
	while(cin>>e, e){
	
		ll mn = LLONG_MAX/2 - 1;
		
		for(ll y=0; e - y*y >= 0; ++y){
			for(ll z=0; e - z*z*z >= 0; ++z){
				
				// x = e - y*y - z*z*z
				// m = e - y*y - z*z*z + y + z
				
				if( e - y*y - z*z*z >= 0){
					mn = min(mn, e - y*y - z*z*z + y + z);
				}
			}
		}
		
		cout << mn << endl;
	}
	
	return 0;	
}

Measured memory_bytes: 1156
#!/usr/bin/env python

visited = []

def dfs(adjacent_matrix, current_node, num_nodes):
    for next_node in range(num_nodes):
        if adjacent_matrix[current_node][next_node] == False:
            continue
        if visited[next_node] == True:
            continue
        visited[next_node] = True
        dfs(adjacent_matrix, next_node, num_nodes)

def main():
    num_nodes, num_edges = map(int, input().split(" "))
    
    edges = []
    for _ in range(num_edges):
        start_node, end_node = map(int, input().split(" "))
        edges.append([start_node - 1, end_node - 1])

    adjacent_matrix = [[False for _ in range(num_nodes)] for _ in range(num_nodes)]
    for e in edges:
        adjacent_matrix[e[0]][e[1]] = adjacent_matrix[e[1]][e[0]] = True

    num_bridges = 0
    global visited
    visited = [False] * num_nodes
    for e in edges:
        adjacent_matrix[e[0]][e[1]] = adjacent_matrix[e[1]][e[0]] = False

        dfs(adjacent_matrix, 0, num_nodes)
        
        is_connected = True
        for v in visited:
            if v == False:
                is_connected = False
        
        for i in range(num_nodes):
            visited[i] = False

        if is_connected == False:
            num_bridges += 1

        adjacent_matrix[e[0]][e[1]] = adjacent_matrix[e[1]][e[0]] = True

    print(num_bridges)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 100000

int parent(int);
int left(int);
int right(int);

int main(){
  int H,i,A[MAX+1];

  scanf("%d",&H);

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

  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=H)printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}
int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

Measured memory_bytes: 608
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        ll n, m; cin >> n >> m;
        if (n == 0 && m == 0) break;
        vll cb(m);
        for (ll i = 0; i < m; i++) cin >> cb[i];
        vvll dp(256, vll(n + 1, HIGHINF));
        dp[128][0] = 0;
        ll x;
        for (ll i = 0; i < n; i++) {
            cin >> x;
            for (ll j = 0; j < 256; j++) {
                for (ll k = 0; k < m; k++) {
                    ll nxt = min(max(0LL, j + cb[k]), 255LL);
                    chmin(dp[nxt][i + 1], dp[j][i] + (x - nxt) * (x - nxt));
                }
            }
        }
        
        ll ans = HIGHINF;
        for (ll i = 0; i < 256; i++) chmin(ans, dp[i][n]);
        cout << ans << '\n';
    }
    return 0;
}



Measured memory_bytes: 43948
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int x,n;
  cin >> x>> n;
  vi p(n);
  vi check(200,0);
  rep(i,n){
    cin >> p[i];
    check[p[i]] = 1;
  }
  int diff = 100000000;
  int ans = 100000000;
  rep(i,102){
    if(check[i])continue;
    if(diff == abs(x-i)){
      ans = min(ans,i);
    }
    else if(abs(x-i) < diff){
      ans = i;
      diff = abs(x-i);
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define inf (1e9)
#define eps (1e-9)

template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S,T,U> t) {
  return os << '('
    << get<0>(t) << ", "
    << get<1>(t) << ", "
    << get<2>(t) << ')';
}

template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
  if (v.size() == 0) { return os << "(empty)"; }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

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

typedef vector<int> vi;
typedef vector<vi> vvi;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  random_device dev;
  mt19937 rand(dev());

  bool of = false;
  vi coins = { 10, 50, 100, 500 };
  loop {
    int C; cin >> C;
    if (C == 0) break;

    if (of) cout << endl;
    of = true;

    int a,b,c,d; cin >> a >> b >> c >> d;

    int ac = 10000000;
    vi ans;

    rep (ai, a + 1) {
      rep (bi, b + 1) {
        rep (ci, c + 1) {
          rep (di, d + 1) {
            int sum = 10 * ai + 50 * bi + 100 * ci + 500 * di;
            if (sum < C) continue;
            int ar = 0,
                br = 0,
                cr = 0,
                dr = 0;
            int rest = sum - C;
            while (rest >= 500) { dr++; rest -= 500; }
            while (rest >= 100) { cr++; rest -= 100; }
            while (rest >= 50) { br++; rest -= 50; }
            while (rest >= 10) { ar++; rest -= 10; }
            if (ai * ar > 0) continue;
            if (bi * br > 0) continue;
            if (ci * cr > 0) continue;
            if (di * dr > 0) continue;
            int sc = -ai-bi-ci-di+ar+br+cr+dr;
            if (sc < ac) {
              ac = sc;
              ans = {ai, bi, ci, di};
            }
          }}}}

    rep (k, 4) {
      if (ans[k] > 0) {
        cout << coins[k] << ' ' << ans[k] << endl;
      }}
  }

  return 0;
}

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

int main() {
  int a,b;
  char o;
  cin >> a >> o >> b;
  cout << (o=='+' ? a+b : a-b) << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()

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

#include <bits/stdc++.h>
using namespace std;

int main() {
  int l,r;
  int min=1000000000;
  cin>>l>>r;
  
  if(r-l>2017) cout << 0 <<endl;
  else{
  for(int i=l;i<r;i++){
    int x=i%2019;
    for(int j=i+1;j<=r;j++){
      int y=j%2019;
      chmin(min,(x*y)%2019); 
    }
  }
  cout << min <<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
V = list(map(int,input().split(" ")))

V1 = V[::2]
V2 = V[1::2]
ans = 0
d1 = Counter(V1)
d2 = Counter(V2)
if len(d1) == 1 and V1 == V2:
    print(N//2)
    exit()
m1 = max(d1.items(), key = lambda x:x[1])
m2 = max(d2.items(), key = lambda x:x[1])
d1.pop(m1[0])
d2.pop(m2[0])
a = m1[1]
b = m2[1]
if m1[0] != m2[0]:
    if d1:
      ans += sum(d1.values())
    if d2:
      ans += sum(d2.values())
else:
    c = 0
    d = 0
    if d1:
	    c = max(d1.values())
    if d2:
	    d = max(d2.values())
    if c != 0:
        tmp = N-b-c
    if c == 0:
        tmp = N-b-a
    if d != 0:
        ttmp = N-a-d
    if d == 0:
        ttmp = N-a-b
    
    ans = min(tmp,ttmp)
print(ans)

Measured memory_bytes: 19040
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL h,w,k;
    cin >> h >> w >> k;

    vector<LL> chose(w,1);
    for(int i = 1; i < w; i++){
        LL x = (1 << i);
        for(int j = 1; j < x; j++){
            bitset<8> y(j);
            bool t = true;
            for(int l = 0; l < i-1; l++){
                if(y[l] && y[l+1]){
                    t = false;
                }
            }
            if(t){
                chose[i]++;
            }
        }
    }

    vector<vector<LL>> dp(h+1,vector<LL>(w,0));

    dp[0][k-1] = 1;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
                if(j-1 >= 0){
                    LL tmp = dp[i][j];
                    if(j-2 >= 0){
                        tmp*=chose[j-2];
                    }
                    if(w-j-2 >= 0){
                        tmp*=chose[w-j-2];
                    }                    
                    dp[i+1][j-1] += tmp;
                    dp[i+1][j-1] %= MOD;
                }                
                if(j+1 < w){
                    LL tmp = dp[i][j];
                    if(j-1 >= 0){
                        tmp*=chose[j-1];
                    }
                    if(w-j-3 >= 0){
                        tmp*=chose[w-j-3];
                    }
                    dp[i+1][j+1] += tmp;
                    dp[i+1][j+1] %= MOD;
                }
                LL tmp = dp[i][j];
                if(j-1 >= 0){
                    tmp*=chose[j-1];
                }
                if(w-j-2 >= 0){
                    tmp*=chose[w-j-2];
                }
                dp[i+1][j] += tmp;
                dp[i+1][j] %= MOD;
        }
    }

    cout << dp[h][0] << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int digCount (long long N) {
	return floor(log10(N)) + 1;
}

int main() {
	long long N;
	scanf("%lld", &N);

	int minF = 100;
	for (int divisor = 1; divisor <= sqrt(N); ++divisor) {
		if (N % divisor > 0) {
			continue;
		}
		minF = min(minF, max(digCount(divisor), digCount(N / divisor)));
	}

	printf("%d", minF);
	return 0;
}

Measured memory_bytes: 512
class Node:
    def __init__(self,key,pri,left=None,right=None):
        self.left = left
        self.right = right
        self.key = key
        self.pri = pri
 
def insert(t,key,pri):
    if t == None :
        return Node(key,pri)
    if key == t.key :
        return t
    if key < t.key :
        t.left = insert(t.left, key, pri)
        if t.pri < t.left.pri :
            t = rrotate(t)
    else:
        t.right = insert(t.right, key, pri)
        if t.pri < t.right.pri :
            t = lrotate(t)
    return t
 
 
def rrotate(t):
    s = t.left
    t.left = s.right
    s.right = t
    return s

 
def lrotate(t):
    s= t.right
    t.right = s.left
    s.left = t
    return s

 
def find(t,key):
    if t == None: return None
    elif t.key == key:return t
    elif t.key > key :return find(t.left,key)
    else: return find(t.right,key)
 
def erase(t, key):
    if t == None : return None
    if key == t.key: 
        if t.left == None and t.right == None:return None
        elif t.left == None : t = lrotate(t)
        elif t.right == None : t = rrotate(t)
        else:
            if t.left.pri > t.right.pri:t = rrotate(t)
            else: t = lrotate(t)
        return erase(t, key)
    elif key < t.key : t.left = erase(t.left, key)
    else : t.right = erase(t.right, key)
    return t
 
def inorder(t):
    if t.left != None:inorder(t.left)
    print(" "+str(t.key), end='')
    if t.right != None: inorder(t.right)
 
def preorder(t):
    print(" "+str(t.key), end='')
    if t.left != None :preorder(t.left)
    if t.right != None : preorder(t.right)

if __name__=="__main__": 
        m=(int)(input())
        root = None
        for i in range(m):
            order = input().split()
            if order[0] == "insert" :root = insert(root,(int)(order[1]),(int)(order[2]))
            elif order[0] == "delete" :root = erase(root,(int)(order[1]))
            elif order[0] == "find" :
                res = find(root,(int)(order[1]))
                if res == None :print("no")
                else:print("yes")
            else:
                inorder(root)
                print()
                preorder(root)
                print()



Measured memory_bytes: 52020
def main():
    n, m  = [int(x) for x in input().split(" ")]

    arr = [int(x) for x in input().split(" ")]

    sum = 0

    for i in arr:
        sum += i

    arr.sort()

    if (arr[n-m] < sum/(4*m)):
        print("No")
    else:
        print("Yes")

main()


Measured memory_bytes: 38384
#include <stdio.h>
int main(void){
    // Your code here!
   
 int date[10000],i=1;

 while(1){
 if(i>10000)break;
 scanf("%d",&date[i]);
 if(date[i]==0)break;
 printf("Case %d: %d\n",i,date[i]);
 i++;
 }
 i=1;
 while(1){
 if(date[i]==0)break;
 if(date[i]!=0){
 i++;
 }
 return 0;
 }
}



Measured memory_bytes: 2044
package main

import "fmt"

func main() {
	var k, s int
	fmt.Scan(&k, &s)

	ans := 0
	for x := 0; x <= k; x++ {
		for y := 0; y <= k; y++ {
			z := s - (x + y)
			if 0 <= z && z <= k {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
while True:
    x=int(input())
    if x==0:
        break
    a=1000-x
    b=a//500
    c=a%500
    d=c//100
    e=c%100
    f=e//50
    g=e%50
    h=g//10
    i=g%10
    j=i//5
    k=i%5
    print(b+d+f+h+j+k)
	


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int bit = 0; bit < 60; ++bit) {
        ll cnt0 = 0,cnt1 = 0;
        ll tmp = (1LL<<bit)%mod;
        for (int i = 0; i < n; ++i) {
            if(a[i] & 1LL<<bit) cnt1++;
            else cnt0++;
        }
        tmp = (tmp*cnt0)%mod;
        tmp = (tmp*cnt1)%mod;
        ans = (ans+tmp)%mod;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);//スイッチ
    for (int i = 0; i < m; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int s;
            cin >> s;
            s--;
            a[s] = a[s] | (1 << i);
        }
    }
    int p = 0;
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        p = p | (x << i);
    }
    int ans = 0;
    /*
    for (int i = 0; i < a.size(); i++) {
        if (i) {
            cout << " ";
        }
        cout << a[i];
    }
    cout << endl;
    */

    //すべての状態を列挙
    for (int s = 0; s < (1 << n); s++) {
        int t = 0;//どの電球がつくかを確かめる
        for (int i = 0; i < n; i++) {
            if (s >> i & 1) {//状態sにおいてi番目のスイッチが立ってるかどうか
                t = t ^ a[i];
            }
        }
        if (t == p) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int sum[100010];

long long mod_pow(long long x, long long n){
	if(n == 0) return 1;
	long long res = mod_pow(x*x % mod, n / 2);
	if(n & 1) res = res*x % mod;
	return res;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= k; ++i){
		sum[i] = mod_pow(k / i, n);
	}
	for(int i = k; i >= 1; --i){
		for(int j = 2 * i; j <= k; j += i){
			sum[i] = (sum[i] - sum[j] + mod) % mod;
		}
	}
	int ans = 0;
	for(int i = 1; i <= k; ++i){
		(ans += i * sum[i] % mod) %= mod;
		// cout << sum[i] << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4416
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 100000
int n;
long long ans=0;
int vis[MAXN+5];
int a[MAXN+5];
int read()
{
	int x=0,f=1;
	char c=getchar();
	while('0'>c||c>'9') {if(c=='-') f=-1;c=getchar();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		if(a[i]) vis[i]=1;
		ans+=a[i]/2;
		a[i]%=2;
	}
	for(int i=2;i<=n;i++)
	{
		if(a[i]&&a[i-1])
		{
			a[i]=0;
			a[i-1]=0;
			ans++;
		}
		else if(a[i]==0&&a[i-1])
		{
			if(vis[i])
			{
				a[i]++;
				a[i-1]--;
			}
		}
	}
	printf("%lld",ans);
}

//

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

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

    pair <pair<string,int>,int> p[n];

    for (int i=0;i<n;i++){
        string s;
        int t;
        cin >> s >> t;
        p[i] = make_pair(make_pair(s,-t),i+1);
    }
    sort(p,p+n);
    for (int i=0;i<n;i++){
        cout << p[i].second << endl;
    }
}

Measured memory_bytes: 256
import sys,heapq,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7
def ddprint(x):
  if DBG:
    print(x)

def perm(k,d):
    x = k
    for i in range(1,d):
        x = (x * (k-i)) % R
    return x

def dfs(prev, cur):
    d = len(dst[cur])-1
    if d==0:
        return 1
    x = perm(k-2,d)
    for nd in dst[cur]:
        if nd==prev:
            continue
        x = (x * dfs(cur,nd)) % R
    return x

sys.setrecursionlimit(250000)
soft,hard = resource.getrlimit(resource.RLIMIT_STACK)
resource.setrlimit(resource.RLIMIT_STACK,(128*1024*1024,hard))
n,k = inm()
dst = [ [] for i in range(n) ]
for i in range(n-1):
    a,b = inm()
    a -= 1
    b -= 1
    dst[a].append(b)
    dst[b].append(a)

for i in range(n):
    if len(dst[i]) >= k:
        print(0)
        exit()

d = len(dst[0])
x = perm(k,d+1)
for nd in dst[0]:
    x = (x * dfs(0,nd)) % R
print(x)


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

// #define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vin(v,n) copy_n(istream_iterator<int>(cin),n,back_inserter(v));
#define all(v) v.begin(),v.end()
#define INF 2000000000
#define MOD 1000000007
#define ll long long 
#define vi vector<int>
#define ii pair<int,int>
#define si set<int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define f1(i,a,b) for(int i = a;i<b;i++)
#define f2(i,a,b) for(int i = a;i<=b;i++)

using namespace std;

int32_t main() 
{
	IOS;
	int n;
	cin >> n;
	vi a,b,c;
	f1(i,0,n)
	{
		int q,w,e;
		cin >> q >> w >> e;
		a.pb(q);
		b.pb(w);
		c.pb(e);
	}
	vector<vi> dp(n, vi(3,0));
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	f1(i,1,n)
	{
		dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = c[i] + max(dp[i-1][1], dp[i-1][0]);
	}

	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
}


Measured memory_bytes: 6892
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Scanner;

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

	void run() throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		int[] b = new int[m];
		for (int i = 0; i < m; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			--a[i];
			--b[i];
		}

		ArrayList<Integer>[] g = new ArrayList[n];
		for (int i = 0; i < n; ++i) {
			g[i] = new ArrayList<>();
		}

		for (int i = 0; i < m; ++i) {
			g[a[i]].add(b[i]);
			g[b[i]].add(a[i]);
		}

		boolean[] vis = new boolean[n];

		int s = 0;
		int t = 0;
		ArrayDeque<Integer> que = new ArrayDeque<>();
		que.add(0);
		vis[0] = true;
		for (boolean update = true; update;) {
			update = false;
			for (int dst : g[s]) {
				if (vis[dst])
					continue;
				que.addFirst(dst);
				vis[dst] = true;
				s = dst;
				update = true;
				break;
			}
			for (int dst : g[t]) {
				if (vis[dst])
					continue;
				que.addLast(dst);
				vis[dst] = true;
				t = dst;
				update = true;
				break;
			}
		}
		System.out.println(que.size());
		while (!que.isEmpty()) {
			System.out.print(que.pollFirst() + 1);
			if (!que.isEmpty()) {
				System.out.print(" ");
			} else {
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 93976
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
   int a[101],n,i,j;
   	cin>>n;
   	for(i=1;i<=n;i++){
   		cin>>a[i];
   	}for(j=n;j>1;j--){
   		cout<<a[j]<<" ";
   	}cout<<a[1]<<endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    long long c[600], s[600], f[600];
    for (int i = 0; i < n; i++) cin >> c[i] >> s[i] >> f[i];

    for (int i = 0; i < n; i++) {
        long long t = 0;
        for (int j = i; j < n - 1; j++) {
            if (t < s[j]) {
                t += s[j] - t;
                t += c[j];
            }
            else {
                if (t % f[j] == 0) {
                    t += c[j];
                }
                else {
                    t = t + (f[j] - t % f[j]);
                    t += c[j];
                }
            }
        }
        cout << t << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque

N = int(input())
ad = [[] for _ in range(N)]
for _ in range(N-1):
    a,b,c = map(int,input().split())
    a -= 1; b -= 1
    ad[a].append((b,c))
    ad[b].append((a,c))

Q,K = map(int,input().split())
K -= 1
query = [[int(e)-1 for e in input().split()] for _ in range(Q)]
dis = [0]*N

def bfs(sv=K):
    dq = deque()
    dq.append((sv,0,-1))
    while dq:
        v,d,pv = dq.pop()
        for nv,nd in ad[v]:
            if nv == pv:
                continue
            dis[nv] = d+nd
            dq.append((nv,d+nd,v))

bfs()
for x,y in query:
    ans = dis[x] + dis[y]
    print(ans)

Measured memory_bytes: 69292
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            if(str[0] + str[1] < str[2])
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
    }
}


Measured memory_bytes: 11092
// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define in(x) 		scanf("%d", &x)
#define echo(x)		printf("%d", x)
#define inf 		(int)(1e18)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "Yes" : "No")<<endl;
using namespace std;

#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}

// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };


// Code from Here -------------------------------------------------------------------------------


signed main() {
	tezz


	int n,k;
	cin >> n >> k;
	if(k&1){
		output(0);
		return 0;
	}
	int mini = 2*n;
	int maxx = 4*n;
	if(k>=mini && k<=maxx){
		output(1);
	}
	else{
		output(0);
	}

	return 0;
}  


Measured memory_bytes: 3680