akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
/*
*/

using namespace std;


template<typename T>
class UF{
public:
	UF(){
		size = 0;
	}

	//値を挿入する
	void push(T a){
		M[a] = size;
		V.push_back(size);
		rank.push_back(0);
		C.push_back(1);
		size++;
	}

	//同じグループにする
	void unite(T a, T b){
		long long int x = find(M[a]);
		long long int y = find(M[b]);
		if( x == y )return;
		if( rank[x] < rank[y] ){
			V[x] = y;
			C[y] += C[x];
		} else{
			V[y] = x;
			C[x] += C[y];
			if( rank[x] == rank[y] )rank[x]++;
		}
	}

	void merge(T a, T b){
		unite(a, b);
	}

	//同じグループにいるかどうか判定する
	bool same(T a, T b){
		return find(M[a]) == find(M[b]);
	}

	//今何グループあるか数を返す
	long long int group(){
		set<long long int>S;
		for( long long int i = 0; i < V.size(); i++ ){
			S.insert(find(V[i]));
		}
		return S.size();
	}

	//グループに属している数を返す
	long long int count(T a){
		return C[find(M[a])];
	}

	//今属しているグループのIDを返す
	long long int groupID(T a){
		return find(M[a]);
	}

	//同じグループのメンバーを返す
	vector<T>friendList(T a){
		long long int inputID = find(M[a]);
		vector<T>ret;
		for( auto now : M ){
			if( find(now.second) == inputID ){
				ret.emplace_back(now.first);
			}
		}
		return ret;
	}

private:
	vector<long long int>C, V, rank;
	map < T, long long int>M;
	long long int size;

	//祖先までたどる
	long long int find(long long int x){
		if( V[x] == x )return x;
		else return V[x] = find(V[x]);
	}
};



int main(){
	long long int N, M;
	cin >> N >> M;
	UF<pair<long long int, bool>>uf;
	for( size_t i = 0; i < N; i++ ){
		uf.push(make_pair(i, true));
		uf.push(make_pair(i, false));
	}
	for( size_t i = 0; i < M; i++ ){
		long long int A, B;
		cin >> A >> B;
		A--; B--;
		uf.merge(make_pair(A, true), make_pair(B, false));
		uf.merge(make_pair(B, true), make_pair(A, false));
	}
	if( uf.group()==1 ){
		cout << N*( N - 1 ) / 2 - M << endl;
	} else{
	//	if( N%2 ){
	//		cout<<( N - 1 + 2 )*( N / 2 ) / 2 - M << endl;
	//	} else{
			long long int O = 0, P = 0;
			auto friendlist=uf.friendList(make_pair(0, true));
			for( auto now : friendlist ){
				if( now.second ){
					O++;
				}
			}
			P = N - O;
			cout << P*O - M << endl;
	//	}
	}
}



Measured memory_bytes: 20564
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n;
  cin >> n;
  vi w(n);
  rep(i,n) cin >> w[i];
  int ans = 10000000;
  rep(i,n){
    int sum1 = 0,sum2 = 0;
    rep(j,n){
      if(j<i) sum1 += w[j];
      else sum2 += w[j];
    }
    ans = min(ans, abs(sum1-sum2));
  }
  cout << ans << endl;
}


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

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

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[10];
	scanf("%s",s);
	if(s[0]=='S') cout << "Cloudy" << endl;
	else if(s[0]=='C') cout << "Rainy" << endl;
	else if(s[0]=='R')cout << "Sunny" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
 
//足したり引いたりすると勝手にmodをとってくれる
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;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
 
//コンビネーションのライブラリ
struct combination {
    //factのなかに階乗を求めている
    //ifactのなかに階乗逆元を求めている
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int n;
vector<int> to[202020]; //隣接リスト

mint ans;

//v 今見てる頂点 p　親　
int dfs(int v, int p = -1){
    int res = 1;
    vector<int> ts; //部分木サイズのリスト
    
    for (int u : to[v]){
        if (u == p) continue; //親だったら無視する
        int t = dfs(u, v); //潜る
        res += t; //u以下の部分木のサイズを足す
        ts.push_back(t);
    }
    
    if (p != -1){
        ts.push_back(n-res); //親方向の部分木のサイズを求める
    }
    
    // mint(2).pow(n-1)　全事象
    
    mint now = mint(2).pow(n-1) - 1; //????
    
    for (int t : ts){
        //２の部分木サイズ-1
        now -= mint(2).pow(t)-1; //????
    }
    ans += now;
    return res; //その頂点v以下の部分木のサイズを返す
}

int main(){
    cin >> n;
    
    rep(i, n-1){
        int a, b;
        cin >> a >> b;
        
        a--, b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    
    dfs(0);
    ans /= mint(2).pow(n);
    cout << ans.x << endl;
}

Measured memory_bytes: 29312
#include<bits/stdc++.h>
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#define pb push_back
#define popb pop_back
#define popf pop_front
#define pf push_front
#define si size()
#define mp make_pair 
#define mt make_tuple
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound

#define ask(i,m,n) for(lli i=m;i<n;i++)
#define anket ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
 
#define endl "\n"
#define o0(a) cout<<a<<" "
#define o1(a) cout<<a<<"\n"
#define o2(a,b) cout<<a<<" "<<b<<"\n"
#define o3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define o4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"
using namespace std;

#define prime1 1000000007
#define prime2 998244353

lli modadd(lli n,lli m , lli mod){
    lli sum = ((n+m)%mod+mod)%mod;
    return sum;
}

lli modsub(lli n,lli m,lli mod){
    lli diff = ((n-m+mod)%mod+mod)%mod;
    return diff;
}

lli modpro(lli n,lli m, lli mod){
    lli pro = ((n*m)%mod+mod)%mod;
    return pro;
}

lli powmod(lli x,lli y,lli mod){
    x %= mod;
    y %= mod;
    lli res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}

lli moddiv(lli n,lli m,lli mod){
    //return n/m mod (mod) or n*(m)^-1 mod (mod)
    lli a = powmod(m,mod-2,mod);
    //this is because of fermats thm i.e. a^-1 = a^p-2 mod(p) check
    //multiplying p on both sides
    lli res = modpro(a,n,mod);
    return res;
}




int main() {
	anket;
	lli a[3][3],c[3][3];
	
	ask(i,0,3){
	    ask(j,0,3){
	        cin>>c[i][j];
	         a[i][j]=0;
	    }
	}
	lli n;
	cin>>n;
	ask(i,0,n){
	    lli b;
	    cin>>b;
	    ask(j,0,3){
	        ask(k,0,3){
	            if(c[j][k]==b){
	                a[j][k]=1;
	            }
	        }
	    };
	    
	}
	if((a[0][0]&&a[0][1]&&a[0][2]) || (a[1][0]&&a[1][1]&&a[1][2]) ||(a[2][0]&&a[2][1]&&a[2][2]) ||(a[0][0]&&a[1][0]&&a[2][0])||(a[0][1]&&a[1][1]&&a[2][1])||(a[0][2]&&a[1][2]&&a[2][2])||(a[0][0]&&a[1][1]&&a[2][2])||(a[0][2]&&a[1][1]&&a[2][0])){
	    o1("Yes");
	}
	else{
	    o1("No");
	}
	return 0;
}


Measured memory_bytes: 256
//orz
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e6+5;
int f[N],a[N],cnt[N],q[N],to[N],sum,h,t,n,m;
int main(){
	scanf("%d",&n);
	fp(i,1,n-1)scanf("%d",&a[i]);
	scanf("%d",&m);
	fp(i,3,n-1)sum+=a[i];
	h=1e6+5,t=h-1;
	fp(i,0,1e6)q[++t]=i;
	fp(i,3,n-1)for(R int j=h+1,s=h+a[i];j<=s;++j)q[--h]=q[j];
	fp(i,h,h+1e6)to[i-h]=q[i];
	while(m--){
		scanf("%d",&a[n]);
		printf("%d\n",(a[n]>=sum?a[n]-sum:to[a[n]])+a[1]-a[2]);
	}
	return 0;
}

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

int main(){
  string s;
  bool a=false,b=false,c=false;
  cin>>s;
  
  for(int i=0;i<s.size()/2;i++){
    if(s.at(i)==s.at(s.size()-i-1)){
      if(i==s.size()/2-1){a=true;}
    }
    else{break;}
  }
  
  for(int i=0;i<s.size()/4;i++){
    if(s.at(i)==s.at(s.size()/2-1-i)){
      if(i==s.size()/4-1){b=true;}
    }
    else{break;}
  }
  
  for(int i=0;i<s.size()/4;i++){
    if(s.at((s.size()+3)/2-1+i)==s.at(s.size()-1-i)){
      if(i==s.size()/4-1){c=true;}
    }
    else{break;}
  }
  
  if(a&&b&&c){cout<<"Yes";}
  else if(a&&s.size()==3){cout<<"Yes";}
  else{cout<<"No";}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int N; cin>>N;
  set<int> paper;
  for(int i = 0; i < N; i++) {
    int a; cin>>a;
    if(paper.find(a) != paper.end()) {
      paper.erase(a);
    } else {
      paper.insert(a);
    }
  }
  cout << paper.size() << endl;
}


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

int main() {
  int n;
  cin >> n;
  
  int ans = 0;
  for(int i = 0; i <= n; i++) {
    if(i * i <= n) { ans = i * i; } else { break; }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
import re
from collections import Counter
s = input()
k = int(input())
len_s = len(s)
res = re.findall(r"(.)(\1{0,})", s)
res = [i[0] + i[1] for i in res]

INF = 10**18
best = INF
ct = Counter(s)

if len(res) == 1:
    print(len_s * k // 2)
else:
    score = 0
    if res[0][0] == res[-1][0]:
        score += len(res[0] + res[-1]) // 2 * (k-1) + len(res[0]) // 2 + len(res[-1]) // 2
        res.pop(0)
        res.pop(-1)
    for r in res:
        score += k * (len(r) // 2)
    print(score)

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
       ans+=a[i]*a[j];
    } 
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int arra[m+5];
    map<int,int>mp;
    for(int i=0;i<m;i++) {
        cin>>arra[i];
        mp[arra[i]]++;
    }
    int fnd=0;
    int val=n;
    while(fnd!=1) {
        if(!mp[val]) {
            fnd=1;
        }
        else {
            val++;
        }
    }
    fnd=0;
    int a1=abs(n-val);
    int one=val;
    val=n;
    while(fnd!=1) {
        if(!mp[val]) {
            fnd=1;
        }
        else {
            val--;
        }
    }
    int a2=(n-val);
    int two=val;
    if(a1>=a2) {
        cout<<two<<endl;
    }
    else cout<<one<<endl;









}


Measured memory_bytes: 3572
/// hi_im_manh :D
#include <bits/stdc++.h>
#define reset(a,n) memset(a,0,(n+1)*sizeof(int))
#define endl "\n"
#define llmin LLONG_MIN
#define llmax LLONG_MAX
#define intmax INT_MAX
#define intmin INT_MIN
#define ll long long
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define duckman "TASK"

#define input freopen(duckman".inp", "r", stdin);
#define output freopen(duckman".out", "w", stdout);

#define nmax 22000
using namespace std;


int main()
{
    fast;
//    input;
//    output;

    ll a, b, n;
    cin >> n >> a >> b;
    ll s = (n/(a+b));
    cout << s*a + min(a, n-(s*(a+b)));
}
/*


*/


Measured memory_bytes: 256
class Node:
  def __init__(self, num):
    self.key = num
    self.p = None
    self.left = None
    self.right = None

class BinarySearchTree:
  def __init__(self):
    self.root = None

  def insert(self, z):
    y = None
    x = self.root
    while x != None:
      y = x
      if z.key < x.key:
        x = x.left
      else:
        x = x.right
    z.p = y

    if y is None:
      self.root = z
    elif z.key < y.key:
      y.left = z
    else:
      y.right = z

  def find(self, key):
    node = self.root
    while node:
      if node.key == key: return node
      if key < node.key:
        node = node.left
      else:
        node = node.right
    return None

  def find_minimum(self, node):
    while node.left: node = node.left
    return node

  def delete(self, node):
    if node.left and node.right:
      m = self.find_minimum(node.right)
      node.key = m.key
      self.delete(m)
    elif node.left:
      self.update(node, node.left)
    elif node.right:
      self.update(node, node.right)
    else:
      self.update(node, None)

  def update(self, node, new_node):
    if node.p is None:
      self.root = new_node
      if new_node: new_node.p = None
      return

    if node.key < node.p.key:
      node.p.left = new_node
    else:
      node.p.right = new_node
    if new_node:
      new_node.p = node.p

def print_inorder(node):
  if node is None: return
  print_inorder(node.left)
  print(" {}".format(node.key), end="")
  print_inorder(node.right)

def print_preorder(node):
  if node is None: return
  print(" {}".format(node.key), end="")
  print_preorder(node.left)
  print_preorder(node.right)

T = BinarySearchTree()
for i in range(int(input())):
  params = input().split()
  if params[0] == "insert":
    T.insert(Node(int(params[1])))
  elif params[0] == "find":
    if T.find(int(params[1])):
      print("yes")
    else:
      print("no")
  elif params[0] == "delete":
    node = T.find(int(params[1]))
    if node: T.delete(node)
  elif params[0] == "print":
    print_inorder(T.root)
    print("")
    print_preorder(T.root)
    print("")

Measured memory_bytes: 124428
import copy

N, K = map(int, input().split())
V = list(map(int, input().split()))

INF = 10 ** 8


# mode 0: can pop left, pop right, drop
#      1: can pop right, drop
#      2: can drop
#      3: can not do anything
def rec(rest_ope, now_d, now_hand, mode):

    if rest_ope == 0:
        return sum(now_hand)

    max_price = -INF

    if len(now_d) > 0:
        if mode == 0:
            left_d = copy.copy(now_d)
            left_hand = copy.copy(now_hand)
            left_hand.append(left_d.pop(0))

            max_price = max(max_price, rec(rest_ope - 1, left_d, left_hand, 0))

        if mode <= 1:
            right_d = copy.copy(now_d)
            right_hand = copy.copy(now_hand)
            right_hand.append(right_d.pop(-1))

            max_price = max(max_price, rec(rest_ope - 1, right_d, right_hand, 1))

    if len(now_hand) > 0:
        if mode <= 2:
            drop_hand = copy.copy(now_hand)
            drop_hand.pop(drop_hand.index(min(drop_hand)))  # 最小値を削除

            max_price = max(max_price, rec(rest_ope - 1, now_d, drop_hand, 2))

    # do nothing
    max_price = max(max_price, rec(rest_ope - 1, now_d, now_hand, 3))

    return max_price


print(rec(K, V, [], 0))


Measured memory_bytes: 55128
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
int n,sum[100005],m;
ll ans;
map<int,int>cnt;
int main() {
	read(n),read(m);
	for(int i=1,x;i<=n;++i)
		read(x),sum[i]=(sum[i-1]+x)%m;
	for(int i=0;i<=n;++i)
		ans+=cnt[sum[i]],cnt[sum[i]]++;
	writeln(ans);
}

Measured memory_bytes: 3584
#include <iostream>
#include <map>
using namespace std;
int main(){
  long long n;
  cin >> n;
  map<long long,int> cnt;
  
  for(long long i = 2; n >= i*i; i++){
    while(n%i == 0){
      cnt[i]++;
      n/=i;
    }
  }
  if(n>1)cnt[n]++;
  int ans = 0;
  for(auto& itr : cnt){
    for(int i = 1; itr.second >= i; i++){
      itr.second -= i;
      ans++;
    }
  }
  cout << ans <<endl;
  return 0;
}


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

long long int solve(long long int x, long long int y) {
  if (x==4 || x==2 || x==1) return y+3;
  if (x%2==0) return solve(x/2, y+1);
  return solve(3*x+1, y+1);
}

int main() {
  int s;
  bool found = false;
  cin >> s;
  cout << solve(s,1);
  return 0;
}

Measured memory_bytes: 256
from sys import stdin
import sys

n = int(stdin.readline().rstrip())

a=b=c=d=0
for i in range(n):
    s = stdin.readline().rstrip()
    if s == "AC":
        a = a + 1
    elif s == "WA":
        b = b + 1
    elif s == "TLE":
        c = c + 1
    elif s == "RE":
        d = d + 1

print ("AC x",a)
print ("WA x",b)
print ("TLE x",c)
print ("RE x",d)




Measured memory_bytes: 9092
/*      ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█  
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     */


// [abc046_b.cpp] => [27-07-2020 @ 21:34:47] 
// Author & Template by : Udit "luctivud" Gupta
// https://www.linkedin.com/in/udit-gupta-1b7863135/


#include <bits/stdc++.h>
// #include <iostream>
// #include <string>
// #include <vector>
// #include <algorithm>
// #include <sstream>
// #include <queue>
// #include <deque>
// #include <bitset>
// #include <iterator>
// #include <list>
// #include <stack>
// #include <map>
// #include <set>
// #include <functional>
// #include <numeric>
// #include <utility>
// #include <limits>
// #include <time.h>
// #include <math.h>
// #include <stdio.h>
// #include <string.h>
// #include <stdlib.h>
// #include <assert.h>

using namespace std;

typedef long long int lld;
typedef unsigned long long int llu;
typedef vector<int> v_int;
typedef vector<lld> v_lld;
typedef vector<llu> v_llu;
typedef pair<int, int> p_int;
typedef pair<lld, lld> p_lld;


#define   INDEPENDENT_CASES()  cin >> (T3X0); T353 = T3X0; while(T3X0--)
#define          _input(V3C0)  for(auto &V3C0_IT7 : (V3C0)) cin >> (V3C0_IT7)
#define     mems(A77AY, V4LU)  memset((A77AY), (V4LU), sizeof((A77AY)))
#define   CH3K(IT7, EN4, S7P)  (((S7P)<0) ? (IT7)>(EN4) : (IT7)<(EN4))
#define for4(IT7,ST4,EN4,S7P)  for(auto IT7=(ST4); CH3K(IT7,EN4,S7P); (IT7)+=(S7P))
#define    FORE4CH(IT7, V3C0)  for(auto IT7=(V3C0).begin(); IT7!=(V3C0).end(); IT7++)


// template<typename T> void _SC4N(T &x) { 
//     x = 0; bool neg = 0; 
//     register T c = getchar();
//     if (c == '-') neg = 1, c = getchar();
//     while ((c < 48) || (c > 57)) c = getchar();
//     for ( ; c < 48||c > 57 ; c = getchar());
//     for ( ; c > 47 && c < 58; c = getchar() ) x= (x << 3) + ( x << 1 ) + ( c & 15 );
//     if (neg) x *= -1;
// }





void solveEachTest(lld T35TC453N = 1) {
    // auto S34t = chrono:: high_resolution_clock::now(); 

    llu n, k; cin >> n  >> k;
    llu ans = k;

    for4(i, 0LL, n-1, 1LL) {
        ans *= (k-1);
    }
    
    cout << ans;
    cout << "\n"; 

    // auto S34p = chrono::high_resolution_clock::now(); 
    // auto D34n = chrono::duration_cast<chrono::microseconds>(S34p - S34t);
    // cout << "Time Elapsed: " << D34n.count() / (long double) 1e6 << " seconds" << endl; 
    return;
}


signed main() {

    // ios_base::sync_with_stdio(false); cin.tie(0);

    lld T3X0 = 0, T353 = 1;

    // INDEPENDENT_CASES()
        solveEachTest(T353 - T3X0);
    return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int X,Y,Q;
int x,y,a;
int ans=0;
int ma[111][111];

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("B.in","r",stdin);
    //freopen("B.out","w",stdout);
#endif
	cin >> X >> Y >> Q;
	memset(ma,0,sizeof(ma));
	for(int i=0;i<Q;i++)
	{
		cin >> x >> y>>a;
		if(a==1)
		{
			for(int i=1;i<=Y;i++)
				for(int j=1;j<=x;j++)
					ma[i][j]=1;
		}
		else if(a==2)
			for(int i=1;i<=Y;i++)
				for(int j=x+1;j<=X;j++)
					ma[i][j]=1;
		else if(a==3)
			for(int i=1;i<=y;i++)
				for(int j=1;j<=X;j++)
					ma[i][j]=1;
		else if(a==4)
			for(int i=y+1;i<=Y;i++)
				for(int j=1;j<=X;j++)
					ma[i][j]=1;
	}
	ans=0;
	for(int i=1;i<=Y;i++)
		for(int j=1;j<=X;j++)
			if(ma[i][j])
				ans++;
	cout <<X*Y-ans <<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second

int main() {

  int n;
  cin>>n;
  
  double d;
  string s;
  double ct = 0.0;
  for(int i=0;i<n;++i){
      
      cin>>d>>s;
      if(s=="JPY")
       ct+=d;
       else
       ct+= 380000.0*d;
  }
  cout<<fixed<<setprecision(8)<<ct;
  
  
  
	return 0;
}

Measured memory_bytes: 256
n = int(input())
for i in range(1,n+1):
    x = i
    if x%3 == 0:
        print(' ',i,sep='',end='')
    else:
        while x != 0:
            if(x % 10 == 3):
                print(' ',i,sep='',end='')
                break
            else:
                x //= 10
print()

Measured memory_bytes: 8176
n=int(input())
csf=[list(map(int,input().split())) for i in range(n-1)]
c=[csf[i][0] for i in range(n-1)]
s=[csf[i][1] for i in range(n-1)]
f=[csf[i][2] for i in range(n-1)]

for i in range(n-1):
  now=s[i]+c[i]
  for j in range(i+1,n-1):
    if now<=s[j]:
      now=s[j]+c[j]
    else:
      while (now-s[j])%f[j]!=0:
        now+=1
      now+=c[j] 
  print(now)
print(0)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){
    int N;cin>>N;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }

    if(N%3!=0){
        sort(all(A));
        if(A[N-1]!=0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }else{
        vector<int> S(34,0);
        for(int i=0;i<N;i++){
            for(int j=0;j<34;j++){
                if(A[i]&(1<<j)) S[j]++;
            }
        }

        bool flag=true;

        for(int i=0;i<34;i++){
            if(S[i]!=0&&S[i]!=N*2/3) flag=false;
        }

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

}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

const int N = 150000;
const int M = 500;
const int MOD = 1e9 + 7;
const int alpha = 26;
const double PI = acos(-1);
ll n, k;
ll ans = 0;
ll a[N];
ll b[N];

signed main()
{
    #ifdef ONLINE_JUDGE
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // ONLINE_JUDGE
    cin >> n;
    printf("%.9f", 2 * PI * n);
}


Measured memory_bytes: 3748
#include<stdio.h>
int d[30];
void f(int n,int r,int b){
  int i,j;
  for(i=n;i;i--){
    if(b<i)continue;
    d[r]=i;
    if(n-i)f(n-i,r+1,i);
    else{
      for(j=0;j<=r;j++){
	if(j)printf(" ");
	printf("%d",d[j]);
      }
      printf("\n");
    }
  }
}
int main(){
  int n,i;
  while(scanf("%d",&n),n){
    for(i=1;i<n;i++)d[i]=0;
    f(n,0,n);
  }
  return 0;
}

Measured memory_bytes: 604
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))

L.sort()

cnt = 0

# 2番目に長い棒bを固定
for b in range(N):
    # bより短い棒aを一つずつ探索
    for a in range(b):
        ab = L[a] + L[b]
        # 二分探索でa+bより短い棒（c<a+bが成り立つc）の範囲を求める
        r = bisect_left(L, ab)
        # cの範囲のうちbの範囲を除外して、cの本数を求める
        cnt += r - (b + 1)

print(cnt)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  string S;
  cin >> S;
  N = S.size();
  vec<int> prev(26, -1);
  vec<int> dis(26, 0);
  REP(i, N) {
    int val = S[i] - 'a';
    chmax(dis[val], i - prev[val] - 1);
    prev[val] = i;
  }
  REP(i, 26) chmax(dis[i], N - prev[i] - 1);
  print(*min_element(ALL(dis)));
}

Measured memory_bytes: 256
N=gets.to_i
as=gets.split.map(&:to_i)
bs=gets.split.map(&:to_i)

rest = as[-1]
ret = 0
(N-1).downto(0) do |i|
    x = [bs[i], rest+as[i]].min
    ret += x
    rest = as[i] - [x-rest,0].max
end

puts ret


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

using namespace std;

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

  vector<int> p(m);
  vector<int> y(m);
  map<int, vector<int>> city;
  for (int i=0; i<m; i++) {
    cin >> p[i] >> y[i];
    city[p[i]].push_back(y[i]);
  }

  for (auto& e : city) {
    sort(e.second.begin(), e.second.end());
  }

  for (int i=0; i<m; i++) {
    char num[13] = {};
    // auto val = find(city[p[i]].begin(), city[p[i]].end(), y[i]);
    auto val = lower_bound(city[p[i]].begin(), city[p[i]].end(), y[i]);
    sprintf(num, "%06d%06d", p[i], distance(city[p[i]].begin(), val) + 1);
    cout << num << endl;
  }

  return 0;
}


Measured memory_bytes: 13184
#include <iostream>
#include <map>
using namespace std;
int cnt=0;
int main(){
    int N;
    cin >> N;
    int p[N];
    for (int i=0;i<N;i++){
        cin >> p[i];
    }

    for(int i=1;i<N-1;i++){
        if((p[i-1] < p[i] && p[i] < p[i+1])||(p[i-1] > p[i] && p[i] > p[i+1])){
            cnt++;
        }

    }
    cout << cnt << endl;
     return 0;
}

Measured memory_bytes: 256
import math

# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d

# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0

# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)

# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[:A]
ave = sum(S) / A
print(ave)

Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか

if min(S) == max(S): # もしもA個選んだ中の商品価値が全て同じだったら
    i = A
    while i <= B and V[i-1] == min(S): # reverseしてるからこの[i-1]が決定打
        C = C + math.factorial(Vs) // ( math.factorial(Vs - i) * math.factorial(i))
        i += 1
    
else: # 商品価値が均一でなかったのなら
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) // (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(C)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;


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

    int ac=max(a,c);
    int bd=min(b,d);

    if(bd-ac >= 0 ) cout << bd-ac << endl;
    else cout << 0 << endl;

}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int q; cin >> q;
    rep(_, q) {
        int k; cin >> k;
        ll d = 0;
        ll m = 0;
        ll dm = 0;
        ll dmc = 0;
        rep(i, n) {
            if (i < k-1) {
                if (s[i] == 'D') {
                    ++d;
                } else if (s[i] == 'M') {
                    ++m;
                    dm += d;
                } else if (s[i] == 'C') {
                    dmc += dm;
                }
            } else {
                if (s[i] == 'D') {
                    ++d;
                } else if (s[i] == 'M') {
                    ++m;
                    dm += d;
                } else if (s[i] == 'C') {
                    dmc += dm;
                }

                if (s[i-k+1] == 'D') {
                    dm -= m;
                    --d;
                } else if (s[i-k+1] == 'M') {
                    --m;
                }
            }
        }
        cout << dmc << endl;
    }

    return 0;
}


    


Measured memory_bytes: 1412
N, W = gets.split.map(&:to_i)
d = [[0, 0]]

(0..(N-1)).each do
  w, v = gets.split.map(&:to_i)
  next if w > W

  (0..(d.size - 1)).each do |i|
    d << [d[i][0] + w, d[i][1] + v] if d[i][0] + w <= W
  end

  d.sort!

  idx = 1
  while idx < d.size do
    if d[idx-1][1] >= d[idx][1]
      d.delete_at(idx)
    else
      idx += 1
    end
  end
end

puts d[-1][1]

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

using namespace std;
typedef long long ll;

int main(void) {
    int q;
    ll a, b;
    scanf("%d", &q);
    for(int i=0; i<q; i++) {
        scanf("%lld%lld", &a, &b);
        ll x = a*b;
        
        ll r = (ll)sqrt(x);
        ll ans = r*2 - 1;
        if(r * (r+1) >= x) ans--;
        if(r * r == x && a != b) ans--;

        printf("%lld\n", ans);
    }

    return 0;
}

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

ll n;
ll cnt = 0;

void dfs(ll x, bool f1, bool f2, bool f3){
    if(x > n) return;
    if(f1&&f2&&f3)cnt++;
    dfs(x*10+3, true, f2, f3);
    dfs(x*10+5, f1, true, f3);
    dfs(x*10+7, f1, f2, true);
}

int main(){
    cin >> n;
    dfs(0, 0, 0, 0);
    cout << cnt << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cstring>

using namespace std;

int main(){

    int t,num;
    string digs;
    while(cin>>t>>digs&&!(t==0&&digs=="0")){
        num=atoi(digs.c_str());
        int len=digs.size();
        int maxCloseNum=-1;
        vector<int> cand;
        bool isRej=false;
        bool isErr=false;
        int cnt=0;
        for(int s = 0; s < (1<<(len-1)); s++){
            vector<int> cuts;
            int start=0;
            for(int j = 0; j < len-1; j++){
                if((s>>j)&1){
                    int a=atoi(digs.substr(start,j+1-start).c_str());
                    start=j+1;
                    cuts.push_back(a);
                }
            }
            cuts.push_back(atoi(digs.substr(start).c_str()));
            int sum=0;
            for(int i = 0; i < cuts.size(); i++){
                sum+=cuts[i];
            }
            if(sum<=t){
                if(maxCloseNum<sum){
                    maxCloseNum=sum;
                    cand=cuts;
                    cnt=0;
                }
                else if(maxCloseNum==sum){
                    cnt++;
                }
            }
        }
        if(maxCloseNum==-1)
            cout<<"error"<<endl;
        else if(cnt!=0)
            cout<<"rejected"<<endl;
        else{
            cout<<maxCloseNum<<" ";
            for(int i = 0; i < cand.size(); i++){
                cout<<cand[i];
                if(cand.size()-1==i)cout<<endl;
                else cout<<" ";
            }
        }
    }

    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdbool.h>

int A[110];
int cnt = 0;

void swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void bubbleSort(int *A, int N) {
	bool flag = true;
	while (flag) {
		flag = false;
		for (int j = N - 1; j >= 1; --j) {
			if (A[j] < A[j - 1]) {
				int tmp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = tmp;
				flag = 1;
				cnt++;
			}
		}
	}
}

int main(void){
	int n;
	scanf("%i", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%i", &A[i]);
	}
	bubbleSort(A, n);
	for (int i = 0; i < n; ++i) {
		if (i != n - 1) printf("%i ", A[i]);
		else printf("%i\n", A[i]);
	}
	printf("%i\n", cnt);
}



Measured memory_bytes: 2732
import java.util.Scanner;

public class Main {
	public static void main(String []args){
		// ????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		int count =0;
		String W="";
		String word ="";
		//??????????????? W
		W = sc.next();
		while(true){
			//?????????????????? ???????????????
			word = sc.next();

			if(word.equals("END_OF_TEXT")){
				break;
			}
			//??????W????????????????????????????????????
			if(W.equalsIgnoreCase(word)){
				//W?????????????????°count
				count ++;
			}
		}
			//??¨???
			System.out.println(count);
	}
}

Measured memory_bytes: 26052
from operator import itemgetter
n = int(input())
t, a = list(map(int, input().split()))
hl = list(map(int, input().split()))
dil = [[abs(t-hl[i]*0.006-a),i] for i in range(n)]
dil.sort(key=itemgetter(0))
print(dil[0][1]+1)

Measured memory_bytes: 3188
//   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;
    n %= 1000;
    ll ans = 0;
    if (n) ans = 1000-n;
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define li long long
#define gc getchar()
#define pc putchar
int read(){
	int x = 0;
	char c;
	c = gc;
	while(!isdigit(c)) c = gc;
	while(isdigit(c)){
		x = (x << 1) + (x << 3) + c - '0';
		c = gc;
	}
	return x;
}
void print(int q){
	if(q >= 10) print(q / 10);
	pc(q % 10 + '0');
}
int n,a[200010],b[200010];
int q2[31];
bool an[31];
li s1 = 19260817,s2 = 33554431,s3 = 998244353,srd;
li rd(){
    srd = (srd * s1 + s2 + rand()) % s3;
    return srd;
}
int ct,t[5000010],ls[5000010],rs[5000010];
int rt;
#define ln ls[q],l,mid
#define rn rs[q],mid + 1,r
#define md int mid = l + r >> 1
void ins(int &q,int l,int r,int x){
	if(!x) return;
	//cout<<"*"<<q<<" "<<l<<" "<<r<<" "<<x<<endl;
	if(!q) q = ++ct;
	++t[q];
	if(l == r) return;
	md;
	if(mid >= x) ins(ln,x);
	else ins(rn,x);
}
int que(int q,int l,int r,int x){
	//cout<<q<<" "<<l<<" "<<r<<" "<<x<<endl;
	if(!q) return 0;
	if(l == r) return t[q];
	md;
	if(mid >= x) return t[rs[q]] + que(ln,x);
	else return que(rn,x);
}
int main(){
	srand(time(0));
	srd = rand();
	srd = rd();
	int i,j;
	n = read();
	for(i = 1;i <= n;++i){
		a[i] = read();
	} 
	for(i = 1;i <= n;++i){
		b[i] = read();
		for(j = 29;j >= 0;--j){
			if(b[i] & (1 << j)) ++q2[j];
		}
	} 
	int as = 0,tp;
	for(i = 0;i <= 28;++i){
		memset(t,0,ct * 4 + 8);
		memset(ls,0,ct * 4 + 8);
		memset(rs,0,ct * 4 + 8);
		ct = rt = 0;
		tp = 1 << i;
		for(j = 1;j <= n;++j) ins(rt,1,tp,b[j] & (tp - 1));
		for(j = 1;j <= n;++j){
			if(a[j] & tp) an[i] ^= (n - q2[i]) & 1;
			else an[i] ^= q2[i] & 1;
			an[i] ^= que(rt,1,tp,tp - (a[j] & tp - 1)) & 1; 
		}
	}
	for(i = 28;i >= 0;--i) as += (1 << i) * an[i];
	print(as);
	return 0;
}

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


void solve(long long N, long long D, std::vector<std::vector<long long>> X){
    int cnt = 0;
    for (int i = 0; i < (int)N; ++i) {
        for (int j = 0; j < (int)N; ++j) {
            if(i <= j) break;
            int val = 0;
            for (int k = 0; k < (int)D; ++k) val += pow((X[i][k] - X[j][k]), 2);
            //cout << val << endl;
            for (int k = 1; k <= 1000; ++k) {
                if (val == pow(k, 2)) {
                    cnt++;
                    break;
                }
            }
        }
    }
    cout << cnt << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long D;
    scanf("%lld",&D);
    std::vector<std::vector<long long>> X(N, std::vector<long long>(D));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < D ; j++){
            scanf("%lld",&X[i][j]);
        }
    }
    solve(N, D, std::move(X));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class I,class V=typename I::value_type>V sum_up(const I&l,const I&r){V v;for(I i=l;i!=r;i++)v=i==l?*i:v+*i;return v;}
template<class I,class T=iterator_traits<I>>I operator+(I it,int n){for(int i=0;i<n;i++)it++;return it;}
template<class I,class T=iterator_traits<I>>I operator-(I it,int n){for(int i=0;i<n;i++)it--;return it;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
void R_YESNO(bool p){cout<<(p?"YES":"NO")<<endl;}
void R_YesNo(bool p){cout<<(p?"Yes":"No")<<endl;}

/*!* [intutil] *!*/
/*+* 整数演算いろいろ *+*/
i64 divceil(i64 a, i64 b) {
    return a / b + (a > 0 && a % b ? 1 : 0);
}
i64 logceil(i64 a, i64 b) {
    for(i64 i = 0, x = 1; a >= 2; x *= a, i++) if(x <= b) return i; return 0;
}
i64 gcd(i64 a, i64 b) {
    for (i64 c; a;) c = a, a = b % a, b = c; return b;
}
i64 lcm(i64 a, i64 b) {
    return (a / gcd(a, b) * b);
}

int main() {
    int K;
    cin >> K;
    i64 ans = 0;
    for(int a = 1; a <= K; a++) {
        for(int b = 1; b <= K; b++) {
            for(int c = 1; c <= K; c++) {
                ans += gcd(gcd(a, b), c);
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3636
'use strict';

const main = arg => {
  const [a, b, c, d] = arg.trim().split(' ').map(x => BigInt(x));
  var ans = a*c;
  if (ans < a*d) ans = a*d;
  if (ans < b*c) ans = b*c;
  if (ans < b*d) ans = b*d;
  console.log(ans.toString());
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 30564
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


int N;
vector<vector<int>> adj;
vector<int> depth;

void dfs(int node, int parent) {
    depth[node] = parent < 0 ? 0 : depth[parent] + 1;

    for (int neighbor : adj[node])
        if (neighbor != parent)
            dfs(neighbor, node);
}

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

    cin >> N;
    adj.assign(N, {});

    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    depth.assign(N, -1);
    dfs(0, -1);
    vector<int> half[2];

    for (int i = 0; i < N; i++)
        half[depth[i] % 2].push_back(i);

    if (half[0].size() > half[1].size())
        swap(half[0], half[1]);

    int counts[4] = {0, (N + 2) / 3, (N + 1) / 3, N / 3};
    vector<int> color(N, -1);
    vector<bool> used(N + 1, false);
    int next_color = 1;

    auto &&assign = [&](int index, int c) {
        assert(!used[c]);
        color[index] = c;
        used[c] = true;
    };

    auto &&assign_next = [&](int index) {
        while (used[next_color])
            next_color++;

        assign(index, next_color++);
    };

    if ((int) half[0].size() <= counts[3]) {
        int c = 0;

        for (int x : half[0]) {
            c += 3;
            assign(x, c);
        }

        for (int x : half[1])
            assign_next(x);
    } else {
        assert((int) half[0].size() >= counts[1]);
        assert((int) half[1].size() >= counts[2]);

        for (int i = 0; i < counts[1]; i++)
            assign(half[0][i], 3 * i + 1);

        for (int i = 0; i < counts[2]; i++)
            assign(half[1][i], 3 * i + 2);

        for (int x = 0; x < N; x++)
            if (color[x] < 0)
                assign_next(x);
    }

    for (int i = 0; i < N; i++)
        cout << color[i] << (i < N - 1 ? ' ' : '\n');
}


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

long long xorsum(long long x){//0からｘまでの排他的論理和を求める関数
    if(x%4 == 3){return 0;}//０になる
    else if(x%4 == 1){return 1;}//１になる
    else if(x%4 == 2){return (x^1);}//x+1ならＡの場合分け不要、x^1は要る
    else if(x%4 == 0){return x;}//０とｘの排他的論理和になる
    else{return 0;}
    }
//A==0のときA-1==-1よりxorsumは何も返さない（0を返す）
//よって0^xorsum(B)を出力するのでＯＫ（以上x+1の場合）

//xorsum(-1)はx%4 == -1よりreturnはなし（０）
//同様にxorsum(0-1)もreturnはなし
//A == 0 でxorsum(A-1)==-1なぜ？
int main (){
    long long A,B;
    cin >> A >> B;
   
    cout << (xorsum(A-1) ^ xorsum(B)) << endl;

    //x^yは（）で囲うこと
    //A-1とBの排他的論理和
    //A==0の場合分け？
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    int a, b, k, n, i, j, ans=0, usiro=0, mae=0;
    char s[5];
    scanf("%s", s);
    if((s[0]=='0'&&s[1]!='0') || (s[0]=='1'&&(s[1]=='0'||s[1]=='1'||s[1]=='2'))) mae++;
    if((s[2]=='0'&&s[3]!='0') || (s[2]=='1'&&(s[3]=='0'||s[3]=='1'||s[3]=='2'))) usiro++;

    if(mae&&usiro) printf("AMBIGUOUS");
    else if(mae) printf("MMYY");
    else if(usiro) printf("YYMM");
    else printf("NA");

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
const int maxn = 1e5 + 5;
int main()
{
    ios::sync_with_stdio(false);
    ll a , b , c , d; cin >> a >> b >> c >> d;
    cout << max (max(a * c , a * d) , max (b * c , b * d)) << endl;
    return 0;
}


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

//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long

struct cmp {
	bool operator()(int a, int b) {
		return a > b;
	}
};

int main() {
	int n;
	cin >> n;
	vector<int> inp(n);
	for(int i=0;i<n;i++) {
		cin >> inp[i];
	}
	sort(inp.begin(), inp.end(), cmp());

	LL ans = inp[0];
	int rem = n-2;

	for(int i=1;i<inp.size();i++) {
		if(rem == 0)
			break;
		if(rem >= 2) {
			ans = ans + 2ll * inp[i];
			rem = rem - 2;
		} else {
			ans = ans + 1ll * inp[i];
			rem = rem - 1;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0;i <n;i++)
#define RFOR(i, n) for(int i = n;i >= 0;i--)
#define REP(i, m, n) for(int i = m;i < n;i++)
#define RREP(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999

using namespace std;
int main(int argc, char const *argv[])
{
 int temp,n,t = 0;
 cin >>n;
 temp = n;
 while(n > 0)
 {
   t += n%10;
   n /= 10;
 }

 if(temp % t == 0)
 {
   cout<<"Yes"<<endl;
   return 0;
 }
 else
 {
   cout<<"No"<<endl;
   return 0;
 }



return 0;

}


Measured memory_bytes: 256
def fun(a)
  s = a[0] - 1
  i = 1
  while i < a.length
    s -= a[i]
    i += 1
  end
  if s < 0 then s = 0 end
  return s
end

k, t = gets.split().map(&:to_i)
a = gets.split().map(&:to_i)
a.sort! {|ar, b| b <=> ar}
sum = a.inject {|s, n| s + n}
day = fun(a)
puts day


Measured memory_bytes: 1788