akhauriyash/Code-Regression huggingface dataset:
n = gets.split("").map(&:to_i)
count = 0
if n[0]*10+n[1] == 0
elsif n[0]*10+n[1] > 12
else
  count += 1
end
if n[2]*10+n[3] == 0
elsif n[2]*10+n[3] > 12
else
  count += 2
end

if count == 0
  puts "NA"
elsif count == 1
  puts "MMYY"
elsif count == 2
  puts "YYMM"
elsif count == 3
  puts "AMBIGUOUS"
end


Measured memory_bytes: 1788
a, b, c = map(int, input().split())
if a > b:
    tmp = b
    b = a
    a = tmp
if b > c:
    tmp = c
    c = b
    b = tmp
if a > b:
    tmp = b
    b = a
    a = tmp
    
print("{} {} {}".format(a, b, c))


Measured memory_bytes: 5596
#include<iostream>
#include<string>
using namespace std;
struct dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(dice a,dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  dice d[2];
  for(int j=0;j<2;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
  bool f=false;
  
  
  for(int i=0;i<4;i++){
    d[1].roll('R');
    for(int j=0;j<4;j++){
      d[1].roll('N');
      if(same(d[0],d[1])) f=true;
    }
  }
  d[1].roll('E');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }

  d[1].roll('W');
  d[1].roll('W');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }
  if(f==true){
      cout << ("Yes") << endl;
  }
  else if(f==false){
      cout<<"No"<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3100
#include<iostream>

using namespace std;

int main(){
  string S;
  string weathers[3] = {"Sunny", "Cloudy", "Rainy"};
  
  cin >> S;
  
  for(int i=0; i<3; i++){
    if(S == weathers[i]){
      cout << weathers[(i+1)%3] << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    if (n < 10) {
        cout << n << endl;
    }
    else if (n>= 10 && n < 100) {
        cout << 9 << endl;
    }
    else if (n >= 100 && n < 1000) {
        cout << n - 90 << endl;
    }
    else if (n >= 1000 && n < 10000) {
        cout << 909 << endl;
    }
    else if (n >= 10000 && n < 100000) {
        cout << n - 9090 << endl;
    }
    else cout << 90909 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k;
  cin>>k;
  string s;
  cin>>s;
  if(s.size()<=k)
    cout<<s<<endl;
  else
  {
    string x=s.substr(0,k);
    cout<<(x+"...")<<endl;
    
    
  }
  
  
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ORDER 500000
#define MAX_PRINT 10

struct Node{
    int key;
    struct Node *left;
    struct Node *right;
    struct Node *parent;
};
struct Node *head,*NIL;

int Datanum = 0;
int count = 0;

void Insert(int in){
    struct Node *y = NIL;
    struct Node *x = head;
    struct Node *z = malloc(sizeof(struct Node));
    z->key = in;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL){
        y = x;
        if(z->key < x->key) x=x->left;
        else x = x->right;
    }
    z->parent = y;

    if(y==NIL){
        head = z;
    }else if(z->key < y->key){
        y->left = z;
    }else{
        y->right = z;
    }
    
}

void PrintPreorder(struct Node *u){
    if(u == NIL) return;
    printf(" %d",u->key);
    PrintPreorder(u->left);
    PrintPreorder(u->right);
}

void PrintInorder(struct Node *u){
    if(u == NIL) return;
    PrintInorder(u->left);
    printf(" %d",u->key);
    PrintInorder(u->right);
}

int main(){
    int n,i,innum;
    char order[7];

    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%s",order);
        if(order[0] == 'i'){
            scanf("%d",&innum);
            Insert(innum);
            Datanum++;
        }else if(order[0] == 'p'){
            PrintInorder(head);
            printf("\n");
            count = 0;
            PrintPreorder(head);
            printf("\n");
            count = 0;
        }else{
            printf("Invalid Order!!\n");
            exit(1);
        }
    }

    return 0;
}


Measured memory_bytes: 25168
#include <stdio.h>

int main(void)
{
	int a = 0;
	int b = 0;
	int c = 0;

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

	b = abs(a - b);
	c = abs(c - a);


	printf("%c",b > c ? 'B':'A');
}

Measured memory_bytes: 128
#include<iostream>
#include <string.h>
using namespace std;

int main(void)
{
    char str[] = "1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51";
    string line[32];
    char *temp;
    temp = strtok( str, "," );
    line[0] = temp;
    for(int i=1; i<32; i++)
    {
      temp = strtok( NULL,"," );
      if(temp!=NULL)
      {
         line[i] = temp;
      }
    }
      
    int input;
    cin >> input;
    cout << line[input-1];
      
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <algorithm>
#include <tuple>

// #define int long は変なところでハマる可能性がるのでやらない。

int main()
{
	int N;
	std::string A, B, C;
	std::cin >> N >> A >> B >> C;
	int result = 0;

	for (int i = 0; i < N; ++i) {
		if (A[i] == B[i] && A[i] == C[i]) {
			// NOTHING
		} else if (A[i] == B[i] || A[i] == C[i] || B[i] == C[i]) {
			result += 1;
		} else {
			result += 2;
		}
	}
	std::cout << result << "\n";
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String N = scan.next();
        int n = Integer.parseInt(N);

        int n1 = n % 10;

        if (n1 == 3) {
          System.out.println("bon");
        } else if (n1 == 0 || n1 == 1 || n1 == 6 || n1 == 8 ) {
          System.out.println("pon");
        } else {
          System.out.println("hon");
        }
    }
}

Measured memory_bytes: 35480
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
   long long int t,n,m,x,a,b,ans=0;
   vector<long long int> h;
   vector< pair <long long int,long long int> >p,p1,p2;
   set<long long int> st;
   priority_queue<long long int> pq[100003];
   priority_queue< long long int,vector<long long int>,greater<long long int> > lpq;
   priority_queue< pair<long long int,long long int>,vector< pair<long long int,long long int> >,greater< pair <long long int,long long int> > > plpq;
   string s;
   cin>>n>>m;
   for(int i=0;i<n;i++)
   {
      cin>>x;
      h.push_back(x);
   }
   for(int i=0;i<m;i++)
   {
      cin>>a>>b;
      pq[a].push(h[b-1]);
      pq[b].push(h[a-1]);
   }
   for(int i=1;i<=n;i++)
   {
      if(pq[i].size()==0)
      {
         ans++;
         //cout<<pq[i].top()<<" "<<i<<endl;
      }
      else if(pq[i].top()<h[i-1])
      {
         ans++;
         //cout<<pq[i].top()<<" "<<i<<endl;
      }
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 10480
N = int(input())
A = []
A = list (map(int, input().strip().split(' ')))
B = [0 for i in range(N)]

i = 0
while i < N:
    B[A[i] - 1] = i + 1
    i += 1
    
for i in B:
    print(i, end = ' ')

Measured memory_bytes: 13880
#include<stdio.h>
#include<string.h>
#include<map>
typedef long long lnt;
lnt ans[10];
std::map<lnt,bool>m;
int main(){
	lnt h,w,n,x,y,i,j,k,xx,yy,ii,jj,nx,ny,t;
	scanf("%lld%lld%lld",&h,&w,&n);
	ans[0]=(h-2)*(w-2);
	for(k=1;k<=n;k++){
		scanf("%lld%lld",&x,&y);
		for(i=0;i<=2;i++){
			for(j=0;j<=2;j++){
				xx=x-i;
				yy=y-j;
				if(xx<=0||yy<=0) continue;
				if((xx+2)>h||(yy+2)>w) continue;
				t=0;
				for(ii=0;ii<=2;ii++){
					for(jj=0;jj<=2;jj++){
						nx=xx+ii;
						ny=yy+jj;
						if(m[1000000000*nx+ny]){
							t++;
						}
					}
				}
				ans[t]--;
				ans[t+1]++;
			}
		}
		m[1000000000*x+y]=true;
	}
	for(k=0;k<=9;k++) printf("%lld\n",ans[k]);
}

Measured memory_bytes: 156544
#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string,getline
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt
#include <sstream>	//stringstream,getline
#include <cmath>	//ceil,M_PI
#include <numeric>	//gcd

using namespace std;

int main() {

	char S;
	cin >> S;

	cout << ++S << endl;

	return 0;

}

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

using namespace std;

int main(){
    string s, t;

    cin >> s >> t;

    vector<vector<int>> alphabet_index(26);

    for(int i = 0; i < s.size(); i ++){
        alphabet_index[s[i] - 'a'].push_back(i);
    }
    long long int ans = 0;
    int num = 0;

    for(int i = 0; i < t.size(); i ++){
        auto begin = alphabet_index[t[i] - 'a'].begin();
        auto end = alphabet_index[t[i] - 'a'].end();
        auto it = lower_bound(begin, end, num);

        if(it != end){
            num = *it + 1;
        }else{
            ans += s.size();
            it = lower_bound(begin, end, 0);

            if(it != end){
                num = *it + 1;
            }else{
                ans = -1;
                num = 0;

                break;
            }
        }
    }
    ans += num;
    
    cout << ans << endl;
}

Measured memory_bytes: 1216
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
    private long fac[];
    private long finv[];
    private long inv[];
    private static int MAX_LEN = 510000;
    private static int MOD = 998244353;
    public static void main(String[] args) {
        Main main = new Main();
        main.COMinit();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        int K = scan.nextInt();
        long ans = 0;
        for (int i = 0; i <= K; i++) {
            int group = N - i;
            long t = ((long) M) * pow(M - 1, group - 1);
            t %= MOD;
            t *= COM(N - 1, i);
            t %= MOD;
            ans += t;
            ans %= MOD;
        }
        System.out.println(ans);
    }
    private long pow(long base, long count) {
        if (count == 0) {
            return 1;
        }
        if (count % 2 == 1) {
            long x = base * pow(base, count - 1);
            x %= MOD;
            return x;
        }
        long x = pow(base, count / 2);
        x *= x;
        x %= MOD;
        return x;
    }
    void COMinit() {
        this.fac = new long[MAX_LEN];
        this.finv = new long[MAX_LEN];
        this.inv = new long[MAX_LEN];
        this.fac[0] = this.fac[1] = 1;
        this.finv[0] = this.finv[1] = 1;
        this.inv[1] = 1;
        for (int i = 2; i < MAX_LEN; i++) {
            fac[i] = fac[i-1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i-1] * inv[i] % MOD;
        }
    }
    long COM(int n, int k) {
        if (n < k) {
            return 0;
        };
        if (n <0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k]%MOD)%MOD;
    }
}


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

using ll = long long;
using VI = vector<ll>;
using VVI = vector<VI>;
using P = pair<ll, ll>;

namespace Mod {

using namespace std;
using i64 = long long;

const i64 kMod = 998244353;  // 1e9 + 7;
vector<i64> fac = {1LL};     // 0! = 1
i64 add(i64 n1, i64 n2) {
  n1 %= kMod;
  n2 %= kMod;
  return (n1 + n2) % kMod;
}

i64 sub(i64 n1, i64 n2) {
  n1 %= kMod;
  n2 %= kMod;
  return (n1 - n2 + kMod) % kMod;
}

i64 mul(i64 n1, i64 n2) {
  n1 %= kMod;
  n2 %= kMod;
  return (n1 * n2) % kMod;
}

i64 pow(i64 n, i64 m) {  // n^mを計算
  n %= kMod;
  if (n == 1 || m % (kMod - 1) == 0) {
    return 1;
  } else if (m < 0) {  // n^m * n^(-m) = 1 = n^k(kMod-1)
    m = (m % (kMod - 1)) + kMod - 1;
    return pow(n, m);
  } else if (m >= kMod - 1) {  // k ^ m = k ^ q(kMod-1) * k^r = k^r
    return pow(n, m % (kMod - 1));
  } else if (m % 2) {  // m is odd
    return mul(pow(n, m - 1), n);
  } else {  // m is evem
    i64 tmp = pow(n, m / 2);
    return mul(tmp, tmp);
  }
}

i64 div(i64 n1, i64 n2) {
  n1 %= kMod;
  n2 %= kMod;
  return mul(n1, pow(n2, -1));
}

i64 fact(i64 n) {
  // assert(n >= 0);
  if (n == 0) {
    return 1;
  } else if ((i64)fac.size() > n && fac[n] != 0) {
    return fac[n];
  }

  if ((i64)fac.size() <= n) {
    fac.resize(2 * n);
  }

  i64 i = 1;

  while (fac[i] != 0 && i <= n)  // i<= n is for avoiding infinite loop
    i++;
  while (i <= n) {
    fac[i] = (fac[i - 1] * (i % kMod)) % kMod;
    i++;
  }
  return fac[n];
}

i64 ifact(i64 n) { return pow(fact(n), -1); }

i64 comb(i64 n, i64 m) {
  i64 tmp = fact(n);
  i64 tmp2 = ifact(m);
  i64 tmp3 = ifact(n - m);
  tmp = (tmp * tmp2) % kMod;
  tmp = (tmp * tmp3) % kMod;
  return tmp;
}

i64 perm(i64 n, i64 m) { return (fact(n) * ifact(n - m)) % kMod; }

}  // namespace Mod
int main() {
  ll n, m, k, tmp;
  cin >> n >> m >> k;

  ll ret = 0;
  if (m == 1 & k < n - 1) {
    cout << 0 << endl;
    return 0;
  }

  for (ll i = 0; i <= k; i++) {
    tmp = Mod::pow(m - 1LL, n - i - 1LL);
    tmp = Mod::mul(tmp, m);
    tmp = Mod::mul(tmp, Mod::comb(n - 1, i));
    ret = Mod::add(tmp, ret);
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 6428
import           Control.Monad

readInt :: IO Int
readInt = do
  s <- getLine
  return $ read s

main = do
  n <- readInt
  a <- readInt
  b <- readInt
  c <- readInt
  d <- readInt
  e <- readInt

  let wb = minimum [a, b, c, d, e] -- wb: width of the bottleneck
      ans = (n + wb - 1) `div` wb + (4::Int)

  print ans


Measured memory_bytes: 508
class Scanner {
  private buffer = '';
  private stdinQueue: any = [];

  constructor() {
    process.stdin.resume();
    process.stdin.setEncoding('utf8');
    process.stdin.on(
      'data',
      (chunk): void => {
        this.buffer += chunk;
        while (this.stdinQueue.length > 0) {
          const i = this.buffer.indexOf('\n');
          if (i < 0) {
            break;
          }
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          this.stdinQueue.shift()(line);
        }
      },
    );
  }
  public getLine(): Promise<string> {
    return new Promise((resolve, reject) => {
      const i = this.buffer.indexOf('\n');
      if (i >= 0 && this.stdinQueue.length == 0) {
        let line = this.buffer.substr(0, i);
        if (line.endsWith('\r')) {
          line = line.slice(0, -1);
        }
        this.buffer = this.buffer.substr(i + 1);
        resolve(line);
      } else {
        this.stdinQueue.push(resolve);
      }
    });
  }

  public close(): void {
    process.stdin.pause();
  }
}

async function slove() {
  const sc = new Scanner();
  const x = +(await sc.getLine());
  const set = new Set<number>([1]);
  for (let b = 2; b <= x; b++) {
    for (let p = 2; p <= x; p++) {
      const t = Math.pow(b, p);
      if (t <= x) {
        set.add(t);
      }
      if (t >= x) {
        continue;
      }
    }
  }
  console.log(Math.max(...Array.from(set)));
  sc.close();
}

slove();


Measured memory_bytes: 10316
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long K = sc.nextLong();
    if(K == 0) {
      System.out.println(2);
      System.out.println(0 + " " + 0);
    } else if(K == 1) {
      System.out.println(2);
      System.out.println(0 + " " + 2);
    } else if(K == 2) {
      System.out.println(2);
      System.out.println(2 + " " + 2);
    } else {
      long r = K % (long)50;
      long s = (K - r) / (long)50;
      System.out.println(50);
      if(r == 0) {
        for(int i = 0; i < 50; i++) {
          System.out.print(s + i);
          if(i < 49) System.out.print(" ");
        }
      } else {
        for(int i = 0; i < 50; i++) {
          if(i < 50 - r) {
            System.out.print(s + i);
          } else {
            System.out.print(s + i + 1);
          }
          if(i < 49) System.out.print(" ");
        }
      }
      System.out.println();
    }
  }
}

Measured memory_bytes: 21844
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long  int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v])parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};

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

	cin >> N >> K;
	vector<vector<int>>uu(201, vector<int>(201));
	vector<vector<int>>us(201, vector<int>(201));
	vector<vector<int>>su(201, vector<int>(201));
	vector<vector<int>>ss(201, vector<int>(201));
	for (int i = 0; i < N; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		if (c&&d) {
			uu[c][d]++;
		}
		else if (c) {
			us[c][b]++;
		}
		else if (d) {
			su[a][d]++;
		}
		else {
			ss[a][b]++;
		}
	}
	//for (int i = 1; i <= 200; i++) {
	//	us[i][i] = min(us[i][i], 1);
	//	su[i][i] = min(su[i][i], 1);
	//}
	vector<int>lu(201);
	vector<int>ld(201);
	vector<int>ru(201);
	vector<int>rd(201);
	for (int i = 1; i <= 200; i++) {
		for (int j = 1; j <= 200; j++) {
			lu[i] += uu[i][j];
			lu[i] += us[i][j];
			ld[i] += su[i][j];
			ld[i] += ss[i][j];
			ru[j] += uu[i][j];
			ru[j] += su[i][j];
			rd[j] += ss[i][j];
			rd[j] += us[i][j];
		}
	}
	UnionFind uf(5000);
	for (int i = 1; i <= 200; i++) {
		for (int j = 1; j <= 200; j++) {
			if (uu[i][j])uf.Unite(i + 1000, j);
			if (us[i][j])uf.Unite(i + 1000, j + 1000);
			if (su[i][j])uf.Unite(i, j);
			if (ss[i][j])uf.Unite(i, j + 1000);
		}
	}
	for (int i = 1; i <= 200; i++) {
		if (ru[i] > ld[i]) {
			cout << "NO\n";
			return 0;
		}
		if (ru[i] < ld[i])uf.Unite(2000, i);
		if (lu[i] > rd[i]) {
			cout << "NO\n";
			return 0;
		}
		if (lu[i] < rd[i])uf.Unite(2000, i + 1000);
	}
	for (int i = 1; i <= 200; i++) {
		if ((lu[i] || rd[i]) && !uf.Check_Same(i + 1000, 2000)) {
			cout << "NO\n";
			return 0;
		}
		if ((ld[i] || ru[i]) && !uf.Check_Same(i, 2000)) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define M 1001

using namespace std;


int main()
{
	int A, B;
	cin >> A >> B;

	if (A - B * 2 <= 0)
		cout << 0 << endl;
	else
		cout << A - B * 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

const int INFT = 1000000000;

int N;
vector<int> graph[101010];
int X[101010];

int low[101010], hi[101010];
int dep[101010];

void dfs(int p, int rt, int d)
{
	dep[p] = d;
	for (int q : graph[p]) if (q != rt) {
		dfs(q, p, d + 1);
		low[p] = max(low[p], low[q] - 1);
		hi[p] = min(hi[p], hi[q] + 1);
	}
}
void dfs2(int p, int rt)
{
	for (int q : graph[p]) if (q != rt) {
		low[q] = max(low[q], low[p] - 1);
		hi[q] = min(hi[q], hi[p] + 1);
		dfs2(q, p);
	}
}
int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N - 1; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		--x; --y;
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	for (int i = 0; i < N; ++i) {
		X[i] = -INFT;
		low[i] = -INFT;
		hi[i] = INFT;
	}

	int K;
	scanf("%d", &K);
	for (; K--;) {
		int v, p;
		scanf("%d%d", &v, &p);
		--v;

		X[v] = low[v] = hi[v] = p;
	}
	dfs(0, -1, 0);
	dfs2(0, -1);

	int par = -1;
	for (int i = 0; i < N; ++i) {
		if (X[i] != -INFT) {
			int myp = (X[i] ^ dep[i]) & 1;
			if (par == -1) par = myp;
			if (par != myp) {
				puts("No");
				return 0;
			}
		}
		if (low[i] > hi[i]) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	for (int i = 0; i < N; ++i) printf("%d\n", low[i]);

	return 0;
}


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

int main()
{
    double ini;

    while( cin >> ini )
    {
        int n = 4;
        double sum = ini;
        while( n-- )
        {
            ini *= 2;
            sum += ini;
            ini /= 3;
            sum += ini;
        }
        ini *= 2;
        sum += ini;
        cout << fixed << setprecision(10) << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3248
function Main(input) {
	input = input.split("\n");
	input.shift();
	var arr = {};
	for(var i=0;i<input.length;i++){
		if(arr[input[i]]){
			arr[input[i]]++;
		}else{
			arr[input[i]] = 1;
		}
	}
  //console.log(arr)
  var max = [0,""];
   Object.keys(arr).forEach(function(key){
		 if(max[0]<=arr[key]){max[0]=arr[key]; max[1]=key;}
	 });
	 var ans = [];
	 Object.keys(arr).forEach(function(key){
		 if(max[0]==arr[key]){ans.push(key)}
	 });
	 ans = ans.sort();
	 console.log(ans.join("\n"))
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


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

#define pb push_back
#define pp pop_back
#define all(s) s.begin(), s.end()

const int inf = (int)1e9 + 7;

int d[55];
int ans, n;

void go (int in, vector < int > vec) {
    if (in == n + 1) {
        int dif = inf;
        sort(all(vec));
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j <= n; j++) {
                int q1 = vec[i];
                int q2 = vec[j];
                q2 -= q1;
                q1 = 0;
                dif = min(dif, min(q2, 24 - q2));
            }
        }
        ans = max(ans, dif);
        if (clock() > CLOCKS_PER_SEC * 1.5) {
            cout << ans;
            exit(0);
        }
        return ;
    }
    vec.pb(d[in]);
    go(in + 1, vec);
    vec.pp();

    vec.pb(24 - d[in]);
    go(in + 1, vec);
}

main() {
    scanf ("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf ("%d", d + i);
    }
    vector < int > vec;
    vec.pb(0);
    go(1, vec);
    cout << ans;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

  if (x - r < 0) {
    printf("No\n");
  }
  else if (x + r > W) {
    printf("No\n");
  }
  else if (y - r < 0) {
    printf("No\n");
  }
  else if (y + r > H) {
    printf("No\n");
  }
  else {
    printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define EACH( it, c ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int solve()
{
	VI pts( 10 );
	FOR( p, pts )
	{
		cin >> p;
	}
	sort( ALL( pts ), greater<int>() );
	return accumulate( pts.begin(), pts.begin() + 3, 0 );
}		

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

	cout << solve() << ' ';
	cout << solve() << endl;

	return 0;
}

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

/*
struct Edge
{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    int cnt = 0;
    bool ok = false;
    for (int i = 0; i < N; i++)
    {
        int D1, D2;
        cin >> D1 >> D2;
        if (D1 == D2)
        {
            cnt++;
            if (cnt >= 3)
                ok = true;
        }
        else
        {
            cnt = 0;
        }
    }
    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3648
/*i-=-1*/
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define in(n) for(int i=0;i<n;i++)
#define inj(n) for(int j=0;j<n;j++)
#define itn int
#define ll long long 
#define ull unsigned ll
#define int ll int
#define S second 
#define F first 
#define mod 1000000007
#define globalbool 2000000
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
using namespace std;
using namespace std::chrono;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	auto start = high_resolution_clock::now();
	int n,k;
	cin>>n>>k;
	if(n%k)
	{
		cout<<1+(n/k);
	}
	else
	{
		cout<<n/k;
	}

	auto stop = high_resolution_clock::now();
    //auto duration = duration_cast<microseconds>(stop - start); 
  
    //cout << "Time taken by function: "
    //<< duration.count() << " microseconds" << endl;
}

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

int main() {
    int n;
    scanf("%d", &n);
    // n = 3;
    vector<int> x(n);
    // x = {1,2,3};
    for (int i = 0; i < n; i++) {
        scanf("%d", &x.at(i));
    }
    vector<int> y(n);
    // y = {2,0,4};
    for (int i = 0; i < n; i++) {
        scanf("%d", &y.at(i));
    }
    vector<double> ans(4);
    for (int i = 0; i < n; i++) {
        int dis = abs(x.at(i)-y.at(i));
        ans.at(0) += dis;
        ans.at(1) += pow(dis,2);
        ans.at(2) += pow(dis,3);
        if (dis > ans.at(3)) {
            ans.at(3) = dis;
        }
    }
    ans.at(1) = sqrt(ans.at(1));
    ans.at(2) = cbrt(ans.at(2));
    for (double x : ans) {
        printf("%lf\n", x);
    }
}


Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner stdin = new Scanner(System.in);

		int a = stdin.nextInt();
		int b = stdin.nextInt();
		int c = stdin.nextInt();

		String reslut = "No";
		if ((a + b) >= c) {
			reslut = "Yes";
		}

		System.out.println(reslut);
	}

}


Measured memory_bytes: 21844
//   PIGMEISTER™   //

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

#define ll long long
#define ld long double
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD (ll)1000000007
//#define MOD (ll)998244353
#define PI (ld)3.141592653589793238
#define MAX 100005

int main()
{
    jaldi;
    
    ll n;
    cin >> n;
    ll a[n], b[n], c[n];
    sidha (i, 0, n) cin >> a[i] >> b[i] >> c[i];

    ll dp[n][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

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

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


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

int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int P1, P2, P3;
  P1 = A * X + B * Y;
  P2 = 2 * C * (max(X, Y));
  if (X > Y) P3 = 2 * C * Y + A * (X - Y);
  else P3 = 2 * C * X + B * (Y - X);
  cout << min(min(P1, P2), P3) << endl;
}


Measured memory_bytes: 256
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvvi = std::vector<vvi>;
using pii = std::pair<int, int>;
using D = double;
using P = std::complex<D>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, std::string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

signed main()
{
  int n = in(), m = in();
  vector<bool> a(n + 1, false);
  vi res;
  stack<int> chie;
  REP(i, m) {
    int e = in();
    chie.push(e);
  }

  while (!chie.empty()) {
    if (!a[chie.top()]) {
      print(chie.top());
    }
    a[chie.top()] = true;
    chie.pop();
  }
  RREP(i, n) {
    if (!a[i]) print(i);
  }

  return 0;
}

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

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

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans++;
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


int main() {
	string a, b;
	cin >> a >> b;
	int n = stoi(a+b);

	string ans = "No";
	rep(i, n) {
		if (n==i*i) {
			ans = "Yes";
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
if s == "SUN":
  print(7)
elif s == "MON":
  print(6)
elif s == "TUE":
  print(5)
elif s == "WED":
  print(4)
elif s == "THU":
  print(3)
elif s == "FRI":
  print(2)
elif s == "SAT":
  print(1)

Measured memory_bytes: 3060
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//                       _oo0oo_                         //
//                      o8888888o                        //
//                      88" . "88      ------ hzt1       //
//                      (| -_- |)                        //
//                      0\  =  /0                        //
//                    ___/`---'\___                      //
//                  .' \|     |// '.                     //
//                 / \|||  :  |||// \                    //
//                / _||||| -:- |||||- \                  //
//               |   | \  -  /// |     |                 //
//               | \_|  ''\---/''  |_/ |                 //
//               \  .-\__  '-'  ___/-. /                 //
//             ___'. .'  /--.--\  `. .'___               //
//          ."" '<  `.___\_<|>_/___.' >' "".             //
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |           //
//         \  \ `_.   \_ __\ /__ _/   .-` /  /           //
//     =====`-.____`.___ \_____/___.-`___.-'=====        //
//                       `=---='                         //
//                                                       //
//                                                       //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       //
//                                                       //
//                 God-He Bless All.                     //
//           This Code Will Never Explode.               //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,Size,stdin);
        tail=(head=buffer)+l;
    }
    if(head==tail) return -1;
    return *head++;
}
inline int read() {
    int x=0,f=1;char c=Getchar();
    for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
const int maxn=100010;
int n,A[maxn];
int main() {
	n=read();
	rep(i,1,n) A[i]=read();
	sort(A+1,A+n+1);
	if(A[n]-A[1]>1) puts("No");
	else {
		if(A[1]==A[n]) puts(A[n]<=n/2||A[n]==n-1?"Yes":"No");
		else {
			int x=0;
			rep(i,1,n) if(A[i]==A[n]) x++;
			puts((A[n]-(n-x)<=x/2)&&(A[n]-(n-x)>=1)?"Yes":"No");
		}
	}
	return 0;
}


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

int main(void){
  int i,j,k,n;
  char x[200000],y[200000];

  while(1){
    scanf("%d",&n);
    if(!n) break;
    scanf("%s",x);

    while(n--){
      for(i=k=0;x[i]!='\0';i++){
	for(j=1;x[i+1]==x[i];j++,i++);
	k += sprintf(&y[k],"%d%c",j,x[i]);
      }
      strcpy(x,y);
    }
    printf("%s\n",x);
  }

  return 0;
}

Measured memory_bytes: 0
N, M = map(int, input().split())
switches = [[] for _ in range(M)]
for i in range(M):
    sw = list(map(int, input().split()))
    switches[i] = sw[1:]
extras = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    is_correct = True
    for p in range(M):
        light = 0
        for sw in switches[p]:
            light += 1 if (i>>(sw-1)) & 1 else 0
        if light % 2 != extras[p]:
            is_correct = False
            break
    if is_correct:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    string S;
    cin>>N>>S;
    int check[26][N];
    for(int i=0;i<26;i++){
        for(int j=0;j<N;j++){
            if(S[j]=='a'+i){
                check[i][j]=1;
            }else{
                check[i][j]=0;
            }
        }
    }
    int num=0;
    int han[26];
    for(int i=0;i<N;i++){
        for(int j=0;j<26;j++){
            han[j]=0;
        }
        for(int j=0;j<26;j++){
            han[j]=0;
        }
        for(int j=0;j<=i;j++){
            char s=S[j];
            for(int k=i+1;k<N;k++){
                if(s==S[k]){han[s-'a']=1;}
            }
        }
        int sum=0;
        for(int j=0;j<26;j++){
            sum+=han[j];
        }
        num=max(num,sum);
    }
    cout<<num<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for

int main()
{
    int a,b;
    cin >> a >> b;
    cout << b + b - a << endl;
    return 0;
}

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

typedef pair<int,int> pii;

bool cek_bit(int id, int mask){
	return (1<<id) & mask;
}

int m,k;

bool isi[(1<<18)+10];

int main(){
	scanf("%d%d",&m,&k);
	
	if(k==0){
		for(int i=0;i<(1<<m);i++){
			if(i>0) printf(" ");
			printf("%d %d",i,i);
		}
		printf("\n");
	} else {
		if(m<=1) {
			printf("-1\n");
		} else  {
			for(int i=0;i<m;i++){
				if(cek_bit(i,k)){
					isi[(1<<i)] = 1;
					k^=(1<<i);
				}
			}
			if(k!=0){
				printf("-1\n");
				return 0;
			}
			bool spas = 0;
			for(int i=0;i<(1<<m);i++){
				if(isi[i]) continue;
				if(spas) printf(" ");
				spas = 1;
				printf("%d",i);
			}
			for(int i=0;i<(1<<m);i++){
				if(!isi[i]) continue;
				if(spas) printf(" ");
				spas = 1;
				printf("%d",i);
			}
			
			for(int i=(1<<m)-1;i>=0;i--){
				if(isi[i]) continue;
				if(spas) printf(" ");
				spas = 1;
				printf("%d",i);
			}
			for(int i=(1<<m)-1;i>=0;i--){
				if(!isi[i]) continue;
				if(spas) printf(" ");
				spas = 1;
				printf("%d",i);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1792
def main():
    N, K, Q = map(int, input().split())
    answer = [0]*N
    for _ in range(Q):
        ind = int(input())
        answer[ind-1] += 1
    for i in range(N):
        if answer[i] - Q + K > 0:
            print("Yes")
        else:
            print("No")
if __name__ == "__main__":
    main()

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

int main(){

	int a,b,c,d,p,x,y;
	cin >> a >> b >> c >> d >> p;

	x = p*a;

	if( p <= c ){
		y = b;
	}
	else{
		y = b+(p-c)*d;
	}
	if( x > y ){
		cout << y << endl;
	}
	else{
		cout << x << endl;
	}

	return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 10100;
const int WHITE = 0, GRAY = 1;

int indeg[MAX_N], color[MAX_N];
vector<int> adl[MAX_N], out;
int n;

void init(){
    rep(i,MAX_N){
        color[i] = WHITE;
        indeg[i] = 0;
    }
}

void bfs(int u){
    queue<int> Q;
    Q.push(u);
    color[u] = GRAY;

    while(!Q.empty()){
        u = Q.front(); Q.pop();
        out.push_back(u);
        for(auto v: adl[u]){
            indeg[v]--;
            if(indeg[v] == 0 && color[v] == WHITE){
                Q.push(v);
                color[v] = GRAY;
            }
        }
    }
}

void topologicalSort(){
    rep(u,n){
        if(indeg[u] == 0 && color[u] == WHITE){
            bfs(u);
        }
    }
}

int main()
{
    cin >> n;
    int e; cin >> e;
    init(); // 初期化
    rep(_,e){
        int u, v; cin >> u >> v;
        adl[u].push_back(v);
        indeg[v]++;
    }
    topologicalSort();
    rep(i,n) cout << out[i] << endl;
}


Measured memory_bytes: 3908
a,b,c,d=0,0,0,0
dic={}
def solve(n):
    if n not in dic.keys():
        if n%2:
            cand1=min(solve((n+1)//2),solve((n-1)//2))+a+d
        else:
            cand1=solve(n//2)+a
        if n%3==0:
            cand2=solve(n//3)+b
        elif n%3==1:
            cand2=solve((n-1)//3)+b+d
        elif n%3==2:
            cand2=solve((n+1)//3)+b+d
        if n%5==0:
            cand3=solve(n//5)+c
        elif n%5==1:
            cand3=solve((n-1)//5)+c+d
        elif n%5==2:
            cand3=solve((n-2)//5)+c+d*2
        elif n%5==3:
            cand3=solve((n+2)//5)+c+d*2
        elif n%5==4:
            cand3=solve((n+1)//5)+c+d
        dic[n]=min(cand1,cand2,cand3,n*d)
    return dic[n]


t=int(input())
for cas in range(t):
    n,a,b,c,d=map(int,input().split())
    dic={}
    dic[1] = d
    dic[2] = min(d*2,d+a)
    dic[3] = min(min(d*2,d+a)+d,d+b)
    dic[4] = min(min(d*2,d+a)+a,min(min(d*2,d+a)+d,d+b)+d)
    dic[5] = min(d+c,min(min(d*2,d+a)+a,min(min(d*2,d+a)+d,d+b)+d)+d)
    print(solve(n))



Measured memory_bytes: 94712
import java.util.*;

public class Main{

    static long gcd(long a,long b){
        if(b==0)return a;
        return gcd(b,a%b);
    }

    static long lcm(long a,long b){
        return a/gcd(a,b)*b;
    }
    public static void main(String[] srgs){
        Scanner sc=new Scanner(System.in);

        String s=sc.next();
        int c=0;
        for(int i=0;i<s.length();i++)if(s.charAt(i)!=s.charAt(s.length()-1-i))c+=1;
        System.out.println(c/2);

    }
}


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

const int N = 5e5 + 5;
int n,b[N],cnt;
long long ans;
char s[N],rec;
int main()
{
	scanf("%s",s+1);
	n = strlen(s+1);
	for(int i=1;i<=n;i++)
	{
		if(s[i]==rec)
		{
			b[cnt]++;
		}
		else b[++cnt]++,rec=s[i];
	}
	bool is_xiao=0;
	if(s[1]=='<') is_xiao=1;
	for(int i=1;i<=cnt;i++)
	{
		 if(is_xiao) for(int j=0;j<=b[i]-1;j++) ans+=j;
		 else
		 {
		 	ans+=max(b[i],b[i-1]);
		 	for(int j=1;j<=b[i]-1;j++) ans+=j;
		 }
		 is_xiao^=1;
	}
	if(s[n]=='<') ans+=b[cnt];
	cout<<ans;
}

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

int main() {
  int n = 3;
  unordered_set<int> colors;
  for (int i = 0; i < n; ++i) {
    int color;
    cin >> color;
    colors.insert(color);
  }
  cout << colors.size() << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		int sum = 0, items = 0, count = 0;
		while(stdIn.hasNext())
		{
			++count;
			String[] str = stdIn.next().split(",");
			int price = Integer.parseInt(str[0]);
			int num = Integer.parseInt(str[1]);
			sum += price * num;
			items += num;
		}
		System.out.println(sum);
		System.out.println((int)(items / (double)count + 0.5));
	}
}

Measured memory_bytes: 12000
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vvint nb(n);
    REP(i,n-1){
        int a,b;
        cin >> a >> b;
        a--; b--;
        nb[a].pb(b);
        nb[b].pb(a);
    }
    vvint cld(n);
    vint pt(n);
    pt[0]=k;
    int nk = k-1;
    stack<int> st;
    vint par(n);
    for(int i : nb[0]){
        pt[i] = nk;
        nk--;
        st.push(i);
        par[i]=0;
    }
    while(!st.empty()){
        int now = st.top();
        st.pop();
        nk = k-2;
        for(int i : nb[now]){
            if(i!=par[now]){
                pt[i] = nk;
                nk--;
                st.push(i);
                par[i]=now;
            }
        }
    }
    mint ans = 1;
    REP(i,n){
        ans *= (mint)pt[i];
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 9720
#include <bits/stdc++.h>
#define INF 100100100
#define MOD 1000000007

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

#define FOR(i,n) for(ll i=0;i<n;i++)

struct edge{ll to,cost;};

int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0); 
   int A,B;
   cin >> A >> B;
   if(A <= 8 && B <= 8)cout << "Yay!" << endl;
   else cout << ":(" << endl;
   return 0;
}


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

int main(){
	long long N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;
	long long ans = ceil((double)(N) / (double)(min({A, B, C, D, E}))) + 4;
	cout << ans << endl;
}

Measured memory_bytes: 256