akhauriyash/Code-Regression huggingface dataset:
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void print(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

signed main (){
    string s;
    rep(i,0,4){
        string t;cin>>t;
        s+=t;
    }
    Sort(s);
    if(s=="1479")cout<<"YES"<<endl;
    else cout<<"NO"<<endl;


    

    

    
}
    
/*
*/


Measured memory_bytes: 256
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, beg, end) for (int i = (beg); i < (end); i++)

int main()
{
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double min = h * 60 + m;
    double m_cycle = min / 60 - floor(min / 60);
    double hou = h + m / 60;
    double h_cycle = hou / 12 - floor(hou / 12);
    double mx = b * cos(M_PI / 2 - m_cycle * 2 * M_PI);
    double my = b * sin(M_PI / 2 - m_cycle * 2 * M_PI);
    double hx = a * cos(M_PI / 2 - h_cycle * 2 * M_PI);
    double hy = a * sin(M_PI / 2 - h_cycle * 2 * M_PI);
    double ans = sqrt((mx - hx) * (mx - hx) + (my - hy) * (my - hy));
    cout << std::setprecision(15) << ans << endl;
    return 0;
}

Measured memory_bytes: 4124
import copy
def magic(arr,i,k):
  if(k==0):
    if(arr[0] < arr[1] and arr[1] < arr[2]):
      return True
    else:
      return False
  k-=1
  arr[i]*=2
  return magic(arr.copy(),0,k) or magic(arr.copy(),1,k) or magic(arr.copy(),2,k)
  
if __name__ == "__main__":
  arr = list(map(int,input().split()))
  k = int(input())
  if(magic(arr.copy(),0,k) or magic(arr.copy(),1,k) or magic(arr.copy(),2,k)):
    print("Yes")
    exit()
  else:
    print("No")

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

using namespace std;

main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	string s;
	cin >> s;
	
	string a;
	string b;
	
	s = ' ' + s;
	
	for(int i = 1; i <= n / 2; i++)
		a += s[i];
	
	for(int i = n / 2 + 1; i <= n; i++)
		b += s[i];
	
	if(a == b)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<list>
#include<utility>
#include<tuple>
#include<map>
#include<unordered_map>
#include<complex>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
int main() {
	int A;
	cin >> A;
	cout << A * A * A << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    string A;
    cin >> A;
    int N = sz(A);
    ll cnt[26];
    fill(cnt, cnt+26, 0);
    ll ans = 1;
    rep(i, N){
        int j = A[i]-'a';
        ans += i-(cnt[j]++);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#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;

char S[1010101];
int sums[101010];

int main()
{
	scanf("%s", S);
	int N = strlen(S);

	for (int i = 0; i < N; ++i) {
		if (i > 0 && S[i] == S[i - 1]) {
			printf("%d %d\n", i, i + 1);
			return 0;
		}
		if (i > 1 && S[i] == S[i - 2]) {
			printf("%d %d\n", i - 1, i + 1);
			return 0;
		}
	}
	puts("-1 -1");

	return 0;
}


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

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) {
        ll o;
        cin >> o;
        o--;
        i++;
        a[o] = i;
        i--;
    }
    rep(i,n) cout << a[i] << ' ';
    return 0;
}


Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> hyo(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> hyo.at(i).at(j);
    }
  }
  int count = 0;
  for (int i = 0; i < W; i++) {
    bool tate_check = true;
    for (int j = 0; j < H; j++) {
      if (hyo.at(j).at(i - count) != '.') {
         tate_check = false;
        break;
      }
    }
    if (tate_check == true){
      for(int k = 0; k < H; k++){
        for (int l = i - count; l < W - 1;l++){
          hyo.at(k).at(l) = hyo.at(k).at(l + 1);
        }
      }
      count++;
    }
  }
  for (int i = 0; i < H; i++) {
    bool yoko_check = false;
    for (int j = 0; j < W; j++) {
      if (hyo.at(i).at(j) != '.') {
         yoko_check = true;
         break;
      }
    }
  if (yoko_check == true){
    for (int j = 0; j < W - count; j++){
      cout << hyo.at(i).at(j);
    }
    cout << endl;
  }
  }
}

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 500010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll fs[MAX];

void precomp()
{
    fs[0] = fs[1] = 1;

    for (ll i = 2; i < MAX; ++i)
        fs[i] = (fs[i - 1] * i) % MOD;
}

ll mod_pow(ll a, ll n)
{
    ll res = 1, base = a;

    while (n)
    {
        if (n & 1)
            res = (res * base) % MOD;

        base = (base * base) % MOD;
        n >>= 1;
    }

    return res;
}

ll inv(ll N)
{
    return mod_pow(N, MOD - 2);
}

ll A(ll N, ll M)
{
    return (fs[N] * inv(fs[N - M])) % MOD;
}

ll C(ll N, ll M)
{
    auto res = (fs[N] * inv(fs[N - M])) % MOD;
    res = (res * inv(fs[M]) % MOD);

    return res;
}

ll mod(ll a)
{
    return ((a % MOD) + MOD) % MOD;
}

ll solve(ll N, ll M)
{
    ll as = A(M, N);
    ll bs = as;

    for (ll i = 1, signal = -1; i <= N; ++i, signal *= -1)
    {
        bs = mod(bs + signal * mod(C(N, i)*A(M - i, N - i)));
    }
    
    return (as * bs) % MOD;
}

int main()
{
    ios::sync_with_stdio(false);
    precomp();

    ll N, M;
    cin >> N >> M;

    auto ans = solve(N, M);

    cout << ans << '\n';

    return 0;
}


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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n, m;
    cin >> n >> m;
    Int odd = (m + 1) / 2;
    Int even = m - odd;
    Int odd_n = 2 * odd;
    Int even_n = 2 * even;
    for (Int i = 0; i < (Int)odd; i++) {
        print(i + 1, odd_n - i);
    }
    for (Int i = 0; i < (Int)even; i++) {
        print(odd_n + i + 1, odd_n + even_n - i + 1);
    }
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      vector<int> m;
      for(int i=0;i<n;i++)
	{
	  int t;
	  cin>>t;
	  m.push_back(t);
	}
      sort(m.begin(),m.end());
     long long int ans=0;
      for(int i=1;i<n;i++)
	ans+=m[i-1]*(n-i);
      cout<<ans<<endl;
    }
}

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

bool func(vector<int>& A,int N,int M) {
  if(A[0] == M)return false;
  else {
    int i,j;
    bool f = true;
    for(i=N-1;i>=0&&f;i--) {
      if(A[i]<M) {
        A[i]++;
        f = false;
        for(j=N-1;j>i;j--)A[j] = A[i];
      }
    }
    return true;
  }
}

int main() {
  int N,M,Q;
  cin >> N >> M >> Q;
  vector<vector<int>> d(Q,vector<int>(4));
  int i,j;
  for(i=0;i<Q;i++)cin >> d[i][0] >> d[i][1] >> d[i][2] >> d[i][3];
  vector<int> A(N,1);
  int ans = 0,temp;
  i = 0;
  do {
    temp = 0;
    for(j=0;j<Q;j++) {
      if(A[d[j][1]-1]-A[d[j][0]-1] == d[j][2])temp += d[j][3];
    }
    ans = max(ans,temp);
  } while(func(A,N,M));
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  long long max = 0; 
  long long c1, c2, c3; 
  c1 = 0; c2 = 0; c3 = 0;
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
    c2 += X.at(i); 
    c3 += X.at(i) * X.at(i); 
    if (max < X.at(i)) {
      max = X.at(i);
    }
  }
  long long min = (max - 1)*(max -1) * N; 
  for (int P = 1; P <= max; P++) {
    long long tmp = P * P * N - c2 * P * 2 ;
    if (min > tmp) {
      min = tmp;
    }
  }
  
  cout << min + c3; 
  return 0; 
}

Measured memory_bytes: 3540
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <ctype.h>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
//整形Shift + alt + f 
int n;
int a[3];

int main(){
    cin >> n;

    for(int i = n; i<=999; i++){
        int b = i;    
        a[0] = b % 10;
        b = b /10;
        a[1] = b % 10;
        b = b / 10;
        a[2] = b % 10;
        if(a[2] == a[1] && a[1] == a[0]){
            cout << i;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define ll long long int
#define lli long long int
#define fw(i, s, e) for (ll i = s; i < e; ++i)
#define fe(i, s, e) for (ll i = s; i <= e; ++i)
#define fb(i, e, s) for (ll i = e; i >= s; --i)
#define L(T)  \
    ll T;     \
    cin >> T; \
    while (T--)
#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr);
#define mem(a, i) memset(a, i, sizeof(a))
#define ld long double
#define endl "\n"
#define in(P) \
    ll P;     \
    cin >> P;
int main()
{
    FASTIO
    {
        ll ans = 0;
        in(n);
        in(p);
        string s;
        cin >> s;
        vector<ll> cnt(p + 90);
        ll l = s.length();

        if (p == 2)
        {
            fw(i, 0, n)
            {
                if ((s[i] - '0') % 2 == 0)
                {
                    ans += i + 1;
                }
            }
        }
        else if (p == 5)
        {
            fw(i, 0, n)
            {
                if ((s[i] - '0') % 5 == 0)
                    ans += i + 1;
            }
        }
        else
        {
            ll suf = 0;
            cnt[suf]++;
            ll pot = 1;
            fb(i, l - 1, 0)
            {
                ll dig = s[i] - '0';
                suf = (suf + dig * pot) % p;
                pot = 10 * pot % p;
                ans += cnt[suf];
                cnt[suf]++;
            }
                }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3784
#include <iostream>
using namespace std;
/*
Ö±½Ó°ÑAB²¢ÆðÀ´£¬ÉèÖÃÍ·Î²Ö¸Õë 
´Ó×óÍùÓÒ±éÀú£¬Óöµ½²»ºÏÀíµÄ¾Í´ÓÍ·Î²½»»»¼´¿É 
Ò»Ð©Ð¡ÓÅ»¯£º
¸ù¾Ý³éÌëÔ­ÀíÈç¹ûÒ»¸öÊýÔÚabÖÐ×Ü¹²³öÏÖ³¬¹ýn´Î¾Í¿Ï¶¨ÎÞ½â 
ÓÉÓÚÒ»¿ªÊ¼¶¼ÊÇÉýÐò£¬°Ñ³õÊ¼µÄbÊ×Î²µ÷»»Ò»ÏÂ¿ÉÄÜ»á¸ü¿ì 
*/
int n;
int a[200005],b[200005],cnt[200005];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }
    for(int i=n;i>=1;i--)
    {
        cin>>b[i];
        cnt[b[i]]++;
        if(cnt[b[i]]>n)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    int top=1,end=n;
    for(int i=1;i<=n;i++)
    {
        while(a[i]==b[i])
        {
        	if(b[top]!=a[i]&&a[top]!=b[i])
        		swap(b[top],b[i]);
        	else if(b[end]!=a[i]&&a[top]!=b[i])
        		swap(b[i],b[end]);
        	else
        	{
        		top++;
        		end--;
			}
		}
    }
    for(int i=1;i<=n;i++)
    	cout<<b[i]<<' ';
    cout<<endl;
    return 0;
}

Measured memory_bytes: 5936
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define lol long long

int main()
{
	int N;
	cin >> N;
	vector<int> b(N);
	vector<int> S(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}
	bool C = true;
	for (int i = 0; i < N; i++) {
		if (b[i] > i + 1) {
			C = false;
		}
	}

	for (int i = 0; i < N; i++) {
		int can = -1;
		for (int j = 0; j < N - i; j++) {
			if (b[j] == j + 1) {
				can = j + 1;
			}
		}
		if (can == -1) {
			cout << -1 << endl;
			break;
		}
		else {
			for (int k = 0; k < N - i; k++) {
				if (k >= can) {
					b[k - 1] = b[k];
				}
				else if (k == N - i - 1) {
					b[k] = 0;
				}
			}
		}
		S[i] = can;
	}

	if (C) {
		for (int i = N - 1; i >= 0; i--) {
			cout << S[i] << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }


int main() {
  double A, B, H, M; cin>>A>>B>>H>>M;
  double angm = (6 * M) / 180.0 * M_PI;
  double angh = (30 * H + 0.5 * M) / 180.0 * M_PI;
  double xh = A * cos(angh);
  double yh = A * sin(angh);
  double xm = B * cos(angm);
  double ym = B * sin(angm);
  //  cout << xh << endl;
  //  cout << yh << endl;
  //  cout << xm << endl;
  //  cout << ym << endl;
  double ans = sqrt((xh-xm)*(xh-xm) + (yh-ym)*(yh-ym));
  printf("%0.11f", ans);
  puts("");
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define REP(i,n) for (int i=0;i<(n);i++)
#define PII pair<int,int>
#define LL long long

int main(){
  int sx,sy,tx,ty;
  int x,y;
  cin>>sx>>sy>>tx>>ty;
  x=tx-sx;
  y=ty-sy;

  //1
  REP(i,x){
    cout<<"R";
  }
  REP(i,y){
    cout<<"U";
  }
  //2
  REP(i,x){
    cout<<"L";
  }
  REP(i,y){
    cout<<"D";
  }
  //3
  cout<<"D";
  REP(i,x+1){
    cout<<"R";
  }
  REP(i,y+1){
    cout<<"U";
  }
  cout<<"L";
  //4
  cout<<"U";
  REP(i,x+1){
    cout<<"L";
  }
  REP(i,y+1){
    cout<<"D";
  }
  cout<<"R"<<endl;

  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int n;
int main() {
    cin >> n;
    if (n >= 1000)
        cout << "ABD" << endl;
    else
        cout << "ABC" << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	int c = 0;
	function<int(int,int)> f = [&](int N,int K){
		c++;
		if(N%K == 0) return N/K;
		if(N<K) return 0;
		int q = N/K, r = N%K;
		int skip = r/(q+1);
		if(skip) return f(N-skip*(q+1),K);
		return f(N/K*(K-1)+(N%K-1),K);
	};

	while(false){
		int n,k; cin >> n >> k;
		c=0;
		show(f(n,k));
		show(c);
	}

	int Q; cin >> Q;
	int s = 0;
	while(Q--){
		int n,k; cin >> n >> k;
		s ^= f(n,k);
	}
	if(s) cout << "Takahashi" << endl;
	else cout << "Aoki" << endl;

	// int N = 100;
	// int K; cin >> K;
	// V<int> g(N);
	// rep(i,N){
	// 	V<bool> is(N+2);
	// 	for(int j=1;j<=i/K;j++) is[g[i-j]] = true;
	// 	rep(j,N+2) if(!is[j]){
	// 		g[i] = j;
	// 		break;
	// 	}
	// }
	// VV<int> g2is(N+2);
	// rep(i,N){
	// 	printf("%3d : %d\n",i,g[i]);
	// 	assert(g[i] == f(i,K));
	// 	g2is[g[i]].pb(i);
	// }
	// rep(j,N+2) if(g2is[j].size()){
	// 	cout << j << " ";
	// 	show(g2is[j]);
	// }
}


Measured memory_bytes: 1920
n, m, k = map(int, input().split())
MOD = 998244353
ans = 0
c = 1

for i in range(k + 1):
    ans += (((m * pow(m - 1, n - i - 1, MOD)) % MOD) * c) % MOD
    ans %= MOD
    c = (c * (n - 1 - i) * pow(i + 1, MOD - 2, MOD)) % MOD
    
    
print(ans%MOD)

Measured memory_bytes: 9156
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inS = Console.ReadLine().Split(' ');
            int N = int.Parse(inS[0]);
            int K = int.Parse(inS[1]);

            double total = 0;

            for (int i = 1; i <= N; i++)
            {
                int value = i;
                int time = 1;

                double kak = 1 / (double)N;

                while(value < K)
                {
                    value *= 2;
                    kak *= 0.5;
                }

                total += kak;
            }

            Console.WriteLine("{0}", total);
        }
    }
}


Measured memory_bytes: 13268
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      float weight = sc.nextFloat();
      if(weight <= 48.00) {
        System.out.println("light fly");
      }
      else if(48.00 < weight && weight <= 51.00) {
	System.out.println("fly");
      }
      else if(51.00 < weight && weight <= 54.00) {
	System.out.println("bantam");
      }
      else if(54.00 < weight && weight <= 57.00) {
	System.out.println("feather");
      }
      else if(57.00 < weight && weight <= 60.00) { 
	System.out.println("light");
      }
      else if(60.00 < weight && weight <= 64.00) {
	System.out.println("light welter");
      }
      else if(64.00 < weight && weight <= 69.00) {
	System.out.println("welter");
      }
      else if(69.00 < weight && weight <= 75.00) {
	System.out.println("light middle");
      }
      else if(75.00 < weight && weight <= 81.00) {
	System.out.println("middle");
      }
      else if(81.00 < weight && weight <= 91.00) {
	System.out.println("light heavy");
      }
      else if(91.00 < weight) {
	System.out.println("heavy");
      }
    }    
  }
}

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

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int x, y;
	vector<int> a(n, 0);
	a[0] = 1;
	vector<int> b(n, 1);
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		b[x]--;
		b[y]++;
		if (a[x] == 1) {
			a[y] = 1;
		}
		if (b[x] == 0) {
			a[x] = 0;
		}
	}
	int d = 0;
	for (int i = 0; i < n; i++) {
		d += a[i];
	}
	cout << d << endl;
	return 0;
}

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

#define LOCAL 0

#define lli long long int
#define llu unsigned long long int
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define slli(n) scanf("%lld",&n);
#define ss(n) scanf("%s",n);

const long double EPS = 1e-10;
const int MOD = 1000000007ll;
const int mod1 = 1000000009ll;
const int mod2 = 1100000009ll;
int INF = (int)1e9;
lli INFINF = (lli)1e18;
int debug = 0;
long double PI = acos(-1.0);

using namespace std;

int bit_count(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
int bit(lli _mask,int _i){return (_mask&(1ll<<_i))==0?0:1;}
int add(int a,int b,int m=MOD){int x=a+b;while(x>=m)x-=m;while(x<0)x+=m;return x;}
int sub(int a,int b,int m=MOD){int x=a-b;while(x<0)x+=m;while(x>=m)x-=m;return x;}
int mul(int a,int b,int m=MOD){lli x=a*1ll*b;x%=m;while(x<0)x+=m;return (int)x;}
int ldtoint(ld x){return (int)(x+0.5);}lli ldtolli(ld x){return (lli)(x+0.5);}
int powermod(lli _a,lli _b,int _m=MOD){lli _r=1;while(_b){if(_b%2==1)_r=mul(_r,_a,_m);_b>>=1;_a=mul(_a,_a,_m);}return _r;}

template<class T1,class T2>ostream&operator<<(ostream& os,const pair<T1,T2>&p){os<<"["<<p.first<<","<<p.second<<"]";return os;}
template<class T>ostream&operator<<(ostream& os,const vector<T>&v){os << "[";bool first=true;for (T it:v){if (!first)os<<", ";first = false;os<<it;}os<<"]";return os;}
template<class T>ostream&operator<<(ostream& os,set<T>&v){os<<"[";bool first=true;for (T it:v){if(!first)os<<", ";first=false;os<<it;}os<<"]";return os;}
template<class T1,class T2>ostream&operator<<(ostream& os,map<T1,T2>&v){os<<"[";bool first=true;for(pair<T1,T2> it:v){if(!first)os<<", ";first=false;os<<"("<<it.F<<","<<it.S<<")";}os<<"]";return os;}
template<class T>void parr(T a[],int s,int e){cout<<"[";for(int i=s;i<e;i++)cout<<a[i]<<", ";cout<<a[e]<<"]\n";}

lli N,M;
lli X[100010],Y[100010];

int main()
{
if(LOCAL){
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    debug = 1;
}
    srand (time(NULL));
    //ios::sync_with_stdio(0);cin.tie(0);

    slli(N);slli(M);
    for(int i=1;i<=N;i++) slli(X[i]);
    for(int i=1;i<=M;i++) slli(Y[i]);
    sort(X+1,X+N+1);
    sort(Y+1,Y+M+1);

    lli tot = 0;
    lli ans = 0;
    for(int j=1;j<M;j++)
        tot = add(tot,mul(mul(j,M-j),Y[j+1]-Y[j]));
    for(int i=1;i<N;i++){
        lli temp = mul(mul(i,N-i),X[i+1]-X[i]);
        temp = mul(temp,tot);
        ans = add(ans,temp);
    }

    cout<<ans;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  int H, N; cin >> H >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  int sum = accumulate(a.begin(), a.end(), 0);
  if (sum >= H) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

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

	if (a == "H" && b == "H") {
		cout << "H" << endl;
	}
	else if (a == "D" && b == "D") {
		cout << "H" << endl;
	}
	else {
		cout << "D" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
from fractions import gcd

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

gl = [0]*(N-1)
gr = [0]*(N-1)
gl[0] = A[0]
gr[0] = A[-1]
for i in range(1, N-1):
    gl[i] = gcd(gl[i-1], A[i])
    gr[i] = gcd(gr[i-1], A[-i-1])
ans = gr[-1]
for i in range(1, N-1):
    ans = max(ans, gcd(gl[i-1], gr[-i-1]))
ans = max(ans, gl[-1])
print(ans)

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

const int MAX = 10000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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 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;
}


int main(){
        ll x, y;
        scanf("%lld %lld", &x, &y);

        if((x+y)%3){
                puts("0");
                return 0;
        }

        COMinit();
        ll n = (x+y)/3; ll k = (2*y-x)/3;
        printf("%lld\n", COM(n, k));
        return 0;
}

Measured memory_bytes: 234624
H, W = map(int, input().split())
dstr = '.' * (W + 2)
b1 = []
b1.append(dstr)
for h in range(H):
  str1 = '.' + input() + '.'
  b1.append(str1)
b1.append(dstr)

for i in range(1, H - 1):
  for j in range(1, W - 1):
    if b1[i][j] == '#' and b1[i-1][j] == '.' and b1[i+1][j] == '.' and b1[i][j-1] == '.' and b1[i][j+1] == '.':
      print('No')
      exit()
print('Yes')

Measured memory_bytes: 9212
'use strict'
function main(input) {
  input = input.trim().split('\n')
  const k = input[0].split(' ')[1]
  let s = input[1].split('')
  let nums = []
  let current = s.shift()
  if (current === '0') nums.push(0)
 
  s.forEach(val => {
    if (val === current[0]) {
      current += val 
    } else {
      nums.push(current.length)
      current = val
    }
  })
  nums.push(current.length)
  if(nums.length % 2 === 0) nums.push(0)

  let add = 2 * k + 1
  let ans = 0

  let left = 0
  let right = 0
  let tmp = 0

  for (let i = 0; i < nums.length; i += 2) {
    while (i > left) {
      tmp -= nums[left]
      left++
    }
    while (Math.min(i + add, nums.length) > right) {
      tmp += nums[right]
      right++
    }
    ans = Math.max(tmp, ans)
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;

typedef long long ll;

int main() 
{
    int n, q;
    ll x, y, z;
    scanf("%d %d", &n, &q);
    
    vector<queue<ll> > v(n);
    
    for(int i = 0; i < q; i++)
    {
        scanf("%lld %lld", &x, &y);
        
        if(x == 0)
        {
            scanf("%lld", &z);
            v[y].push(z);
        }
        else if(x == 1)
        {
            if(v[y].size() > 0)
            {
                printf("%lld\n", v[y].front());
            }
        }
        else if(x == 2)
        {
            if(v[y].size() > 0)
            {
                v[y].pop();
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 5108
#include<iostream>

using namespace std; 

int denominations[] = {500, 100, 50, 10, 5, 1};

int main() {
    int n;
    int count = 0;
    while (cin >> n && n != 0) {
        n = 1000-n;
        for (int i = 0; i < 6; i++) {
            count += n/denominations[i];
            n -= denominations[i]*(n/denominations[i]);
        }
        cout << count << endl;
        count = 0; 
    }
}


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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int n;
	cin >> n;
	set<string> see;
	M00(i, n) {
		string s;
		cin >> s;
		see.insert(s);
	}
	finish(see.size());
}


Measured memory_bytes: 19208
import sys

n = int(sys.stdin.buffer.readline())
mp = map(int, sys.stdin.buffer.read().split())
links = [set() for _ in range(n)]
for x, y in zip(mp, mp):
    x -= 1
    y -= 1
    links[x].add(y)
    links[y].add(x)

stack = [(0, -2)]
grundy = [0] * n
while stack:
    v, p = stack.pop()
    if p == -1:
        g = 0
        # second visit (aggregate children and calculate self grundy)
        for u in links[v]:
            g ^= grundy[u] + 1
        grundy[v] = g
    else:
        # first visit (stack children and remove parent)
        links[v].discard(p)
        stack.append((v, -1))
        for u in links[v]:
            stack.append((u, v))

if grundy[0] == 0:
    print('Bob')
else:
    print('Alice')


Measured memory_bytes: 43392
n, m = map(int,input().split())
a = [0] * m
b = [0] * m
c = [0] * m

for i in range(m):
    a[i], b[i], c[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1

d = [[float('inf') for i in range(n)] for j in range(n)]

for i in range(n):
    d[i][i] = 0

for i in range(m):
    d[a[i]][b[i]] = c[i]
    d[b[i]][a[i]] = c[i]

for k in range(n):
    for i in range(n):
        for j in range(n):
            d[j][i] = min(d[j][i], d[k][i] + d[j][k])

ans = m
for i in range(m):
    f = False
    for j in range(n):
        if d[j][b[i]] == c[i] + d[j][a[i]]:
            f = True

    if f:
        ans -= 1

print(ans)


Measured memory_bytes: 47708
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define endl '\n'
using ll = long long;
#define int ll
using db = long double;
using ii = pair<int, int>;

const int N = 1e5 + 5, LG = 19, MOD = 998244353;
const int SQ =320;
const long double EPS = 1e-7;
int g[3][3];
set<int>st;
bool check(){
  f(i,0,3){
    if(st.count(g[i][0])&&st.count(g[i][1])&&st.count(g[i][2]))return true;
    if(st.count(g[0][i])&&st.count(g[1][i])&&st.count(g[2][i]))return true;
  }
  if(st.count(g[0][0])&&st.count(g[1][1])&&st.count(g[2][2]))return true;
  if(st.count(g[0][2])&&st.count(g[1][1])&&st.count(g[2][0]))return true;
  return false;
}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  f(i,0,3)
    f(j,0,3)
      cin>>g[i][j];
    int n;
    cin>>n;
    while(n--){
      int x;
      cin>>x;
      st.insert(x);
    }

    if(check())cout<<"Yes\n";
    else cout<<"No\n";

  return 0;
}


Measured memory_bytes: 764
#define pb push_back
#define ll long long
#include<bits/stdc++.h>
using namespace std;
int n, q;
string cmd;
struct node{
	node *l, *r;
	int key = 0;
	node(int k){
		key = k;
		l = r = NULL;
	}
};
node* insert(node* r, int key){
	if(r == NULL || r->key == key) return new node(key);
	if(r->key > key){
		r->l = insert(r->l, key);
	}else r->r = insert(r->r, key);
	return r;
}
void pre(node* r){
	if(!r) return;
//	if(ff) cout << " ";
	printf(" %d", r->key); 
	pre(r->l);
	pre(r->r);
}
void in(node* r){
	if(!r) return;
	in(r->l);
	printf(" %d", r->key); 
	in(r->r);
}
int cc = 0;
node* root = NULL;
bool search(int key, node* r){
	if(r == NULL) return false;
	if(r->key == key) return true;
	if(r->key > key) return search(key, r->l);
	else return search(key, r->r);
}
void solve(){
	root = NULL;
	cc = 0;
	cin >> q;
	while(q--){
		cin >> cmd;
		if(cmd[0] == 'i'){
			int x; cin >> x;
		//	cout << cmd << " " << x << endl;
			root = insert(root, x);
		}else if(cmd[0] == 'p'){
			in(root); 
			cout << endl;
			pre(root);
			cout << endl;
//			bool ok = false;
//			if(cc != 0) cout << endl, ok = true;
//			cc++;
//			if(q == 0 && ok == false) cout << endl;
		}else{
			int x; cin >> x;
			bool ok = search(x, root);
			if(ok) cout << "yes" << endl;
			else cout << "no" << endl;
		}
	}
	//cout << "root: " << root->key << endl;
}
int main(){
	solve();
	return 0;
}



Measured memory_bytes: 18784
#include<stdio.h>

int main(void){
  long long int a,b,k;
  
  scanf("%lld %lld %lld",&a,&b,&k);
  
  if(a>k){
    printf("%lld %lld",a-k,b);
  }else if(b>k-a){
    printf("0 %lld",b-k+a);
  }else printf("0 0");
  
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

int N, M;
vector<VI> G;
int dp[100010];
int t[200010];//size of subtree
int ans[200010];

void dfs1(int now, int pa) {
	fore(to, G[now]) {
		if (to == pa)continue;
		dfs1(to, now);
	}

	int res0 = 1;

	fore(to, G[now]) {
		if (to == pa)continue;
		res0 *= (dp[to] + 1);
		res0 %= M;
	}
	dp[now] = res0;//それだけが黒い場合を足す
}

void dfs(int now, int pa) {
	
	ans[now] = 1;
	fore(to, G[now]) {
		ans[now] *= dp[to] + 1;
		ans[now] %= M;
	}
	int n = G[now].size();
	VI L(n), R(n);
	REP(i, n)L[i] = R[i] = dp[G[now][i]] + 1;
	FOR(i, 1, n)L[i] = L[i] * L[i - 1] % M;
	for (int i = n - 2; i >= 0; i--)R[i] = R[i] * R[i + 1] % M;

	REP(i, n) {
		if (G[now][i] == pa)continue;
		dp[now] = 1;

		if (i)dp[now] *= L[i - 1];
		if (i + 1 < n)dp[now] *= R[i + 1];
		dp[now] %= M;
		dfs(G[now][i], now);

	}






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

	cin >> N >> M;
	G.resize(N);
	REP(i, N - 1) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs1(0, -1);
	dfs(0, -1);
	REP(i, N)cout << ans[i] << "\n";



	return 0;
}



Measured memory_bytes: 18560
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define lSHN 1e18
using namespace std;
ll n,q,m;
ll d[100010];
vector<PLL> v[100010];
priority_queue<PLL> pq; 
int main()
{
	cin >>n;
	for (int i=0;i<n-1;i++)
	{
		ll x,y,z;
		cin >>x>>y>>z;
		x--,y--;
		v[x].push_back(MP(y,z));
		v[y].push_back(MP(x,z));
	}
	cin >>q>>m;
	m--;
	fill(d,d+n,1e18);
	pq.push(MP(0,m));
	d[m]=0;
	while (!pq.empty())
	{
		ll x=pq.top().S;
		ll y=-pq.top().F;
		pq.pop();
		if (d[x]!=y) continue;
		for (int i=0;i<v[x].size();i++)
		{
			ll xi=v[x][i].F;
			ll yi=v[x][i].S;
			if (d[xi]>y+yi)
			{
				d[xi]=y+yi;
				pq.push(MP(-d[xi],xi));
			}
		}
	}
	for (int i=0;i<q;i++)
	{
		ll x,y;
		cin >>x>>y;
		x--,y--;
		cout <<d[x]+d[y]<<"\n";
	}
	return 0;
} 

Measured memory_bytes: 11120
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
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; }

int gcd(int a,int b) {

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

int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    vector<int>l(n-1),r(n-1);
    rep(i,n-1) {
        if(i==0) {
            l[0] = a[0];
            continue;
        }
        l[i] = gcd(l[i-1],a[i]);
    }
    for(int i = n-1;i>=1;i--) {
        if(i==n-1) {
            r[i] = a[n-1];
            continue;
        }
        r[i] = gcd(r[i+1],a[i]);
    }
    int ans = 0;
    rep(i,n) {
        if(i==0) {
            ans = max(ans,r[1]);
            continue;
        }
        if(i==n-1) {
            ans = max(ans,l[n-2]);
            continue;
        }
        ans = max(ans,gcd(l[i-1],r[i+1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 998244353
using namespace std;

int main() {
    int n, p[100005], ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    for (int i = 1; i <= n-1; i++) {
        if (p[i] == i) {
            ans++;
            swap(p[i], p[i + 1]);
        }
    }
    if (p[n] == n)ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#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<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
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 x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }

vector<int> a;
vector2d<int> children;
vector<int> ans;

void recursive(int i) {
    priority_queue<int> q;
    for(int j : children[i]) {
        recursive(j);
        q.push(ans[j]);
    }
    for(int j = 0; q.size(); j++) {
        ans[i] = max(ans[i], j + 1 + q.top());
        q.pop();
    }
}

int main() {
    int N;
    cin >> N;
    a = vector<int>(N);
    children = vector2d<int>(N);
    ans = vector<int>(N);
    a[0] = -1;
    for(int i = 1; i < N; i++) {
        cin >> a[i];
        a[i]--;
    }
    for(int i = 0; i < N; i++) {
        if(a[i] >= 0) children[a[i]].push_back(i);
    }
    recursive(0);
    cout << ans[0] << endl;
    return 0;
}



Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
vector<int> divs;
void factor(int x){
    for(int i=2;i*i<=x;i++){
        if(x%i==0){
            divs.pb(i);
            if(x/i != i){
                divs.pb(x/i);
            }
        }
    }
}
int32_t main(){
    fastio;
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    factor(v[0]);
    factor(v[1]);
    divs.pb(v[0]);
    divs.pb(v[1]);
    sort(td(divs),greater<int>());
    divs.pb(1);
    for(int x : divs){
        int cnt = 0;
        for(int i=0;i<n;i++){
            if(v[i]%x != 0){
                cnt++;
            }
        }
        if(cnt <= 1){
            cout << x << endl;
            return 0;
        }
    }
} 

Measured memory_bytes: 1024
'use strict'

const main = (INPUT) => {
  const s = Number(INPUT.split('\n')[0])
  const a = [s]
  let ans
  while (true) {
    let tmp = a[a.length - 1]
    let add
    if (tmp % 2 == 0) {
      add = tmp / 2
    } else {
      add = tmp * 3 + 1
    }
    if (a.indexOf(add) >= 0) {
      ans = a.length + 1
      break
    } else {
      a.push(add)
    }
  }
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 21192
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long ll;
const int INF = 1<<30;

int main(){
  int a, b;cin>>a>>b;
  int b_digit=0, c=b;
  while(c!=0){
    c/=10;b_digit++;
  }
  int num=a*pow(10, b_digit)+b;
  double tmp = sqrt(num);
  cout << (tmp-(int)tmp<1e-5?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 300000
#define pg(x) ((x)&1? (x+1)>>1: x/2)
using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,A[N],tree[N<<2][2];
struct node
{
	int l,r,x;
};
inline bool operator <(const node a,const node b)
{
	return A[a.x]>A[b.x];
}
priority_queue <node> q;
inline void pushup(int rt,int tp)
{
	if(A[tree[rt<<1][tp]]<A[tree[rt<<1|1][tp]])
		tree[rt][tp]=tree[rt<<1][tp]; 
	else tree[rt][tp]=tree[rt<<1|1][tp];
}
inline void built(int l,int r,int rt,int tp)
{
	if(l==r){tree[rt][tp]=l*2-tp; return ;}
	int mid=(l+r)>>1; 
	built(l,mid,rt<<1,tp); built(mid+1,r,rt<<1|1,tp);
	pushup(rt,tp);
}
inline int query(int L,int R,int l,int r,int rt,int tp)
{
	if(L>R) return 0;
	if(L<=l&&r<=R) return tree[rt][tp];
	int mid=(l+r)>>1;
	if(mid<L) return query(L,R,mid+1,r,rt<<1|1,tp);
	if(mid>=R) return query(L,R,l,mid,rt<<1,tp);
	int x1=query(L,R,l,mid,rt<<1,tp);
	int x2=query(L,R,mid+1,r,rt<<1|1,tp);
	if(A[x1]<A[x2]) return x1; else return x2;  
}
inline int ks(int l,int r,int tb)
{
	if(l>r) return 0;
	if(tb==1)
	{
		if(l&1) return query((l+1)>>1,r>>1,1,n/2,1,l&1);
		return query(l>>1,r>>1,1,n/2,1,l&1);
	}
	else 
	{
		if(l&1) return query((l+1)>>1,r>>1,1,n/2,1,r&1);
		return query((l>>1)+1,(r+1)>>1,1,n/2,1,r&1);
	}
}
int main()
{
	A[0]=0x3fffffff;
	n=read(); for(int i=1;i<=n;i++) A[i]=read();
	built(1,n/2,1,0); 
	built(1,n/2,1,1);
	q.push((node){1,n,query(1,n/2,1,n/2,1,1)});
	while(!q.empty())
	{
		node lx=q.top(); q.pop();
		if(lx.l>lx.r) continue;
		int td=ks(lx.x,lx.r,0);
		printf("%d %d ",A[lx.x],A[td]);
		q.push((node){lx.l,lx.x-1,ks(lx.l,lx.x-1,1)});
		q.push((node){lx.x+1,td-1,ks(lx.x+1,td-1,1)});
		q.push((node){td+1,lx.r,ks(td+1,lx.r,1)});
	}
	return 0;
}

Measured memory_bytes: 11892
import time
N = int(input())
s = [str(input()) for i in range(N)]

j = 0
ans = 0
for i in range(N):
  s[i] = "".join(sorted(s[i]))
#print(s)

s = sorted(s)
tango = "yeeeh"
x = 0
#print(s)
for i in range(N):
  if s[i] == tango:
    x += 1
  else:
    ans += x * (x + 1) //2
    x = 0
  tango = s[i]
ans += x * (x + 1) //2

print(ans)

Measured memory_bytes: 11476