akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using lint = long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

constexpr lint INF = 1'010'000'000'000'000'017LL;
constexpr lint MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(lint i = (start); i < end; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }

lint mod(lint val, lint m){ lint res = val % m; if(res < 0) res += m; return res;}
lint modinv(lint a, lint m) { lint b = m, u = 1, v = 0; while (b) { lint t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u;}
lint modpow(lint a, lint n, lint mod) { lint res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
lint gcd(lint a, lint b){ if(a < b) swap(a, b); if(b == 0) return a; return gcd(b, a%b);}
lint lcm(lint a, lint b){ return a * b / gcd(a, b);}


//---------------------------------------------------------------

void Main()
{
    lint N, ans;
    string S;
    cin >> N >> S;
    ans = 1;
    FOR(i, 1, N){
        if(S[i] != S[i-1]){
            ans++;
        }
    }
    cout << ans << endl;
}

//---------------------------------------------------------------
int main()
{
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>

int main(void) {

	int n, m, *t, ans = 0;
	long long int *h, *a, *b;

	t = malloc(sizeof(int) * 100001);
	h = malloc(sizeof(long long int) * 100001);
	a = malloc(sizeof(long long int) * 100001);
	b = malloc(sizeof(long long int) * 100001);

	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &h[i]);
	}
	for (int i = 1; i <= m; i++) {
		scanf("%lld%lld", &a[i], &b[i]);
	}

	for (int i = 1; i <= n; i++) {
		t[i] = 0;
	}

	for (int i = 1; i <= m; i++) {
		if (h[a[i]] < h[b[i]]) t[a[i]] = 1;
		else if (h[a[i]] == h[b[i]]) {
			t[a[i]] = 1;
			t[b[i]] = 1;
		}
		else t[b[i]] = 1;
	}

	for (int i = 1; i <= n; i++) {
		if (t[i] == 0)ans++;
	}

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 4424
#include <bits/stdc++.h>
#define L long long
#define ff first
#define ss second
using namespace std;
int main() {
string x;
cin>>x;
int m=0;
int a=(x[0]-'0')*10+(x[1]-'0');
int b=(x[2]-'0')*10+(x[3]-'0');
if(a>0&&a<=12)m++;
if(b>0&&b<=12)
{
    if(m)cout<<"AMBIGUOUS"<<endl;
    else cout<<"YYMM"<<endl;
}
else if(m)cout<<"MMYY"<<endl;
else cout<<"NA"<<endl;
return 0;
}


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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

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

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

int main()
{
  int n;
  cin >> n;
  
  vi p(n);
  rep(i, n){
    cin >> p[i];
    p[i]--;
  }

  int ans = 0;
  bool flag = false;
  rep(i, n){
    if(p[i] == i and !flag){
      ans++;
      flag = true;
    }else{
      flag = false;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]

ans = 100000000

for i in range(N):
    ax, ay = XY[i]
    
    for j in range(i+1, N):
        bx, by = XY[j]

        dx = (ax+bx)/2
        dy = (ay+by)/2
        r2 = (ax-dx)**2 + (ay-dy)**2

        ok = True
        for x,y in XY:
            if (x-dx)**2 + (y-dy)**2 > r2 + 1e-5:
                ok = False
                break
        if ok:
            ans = min(ans, r2)

        
        for k in range(j+1, N):
            cx, cy = XY[k]

            a = (bx-cx)**2 + (by-cy)**2
            b = (cx-ax)**2 + (cy-ay)**2
            c = (ax-bx)**2 + (ay-by)**2

            aa = a*(b+c-a)
            bb = b*(c+a-b)
            cc = c*(a+b-c)
            delim = aa + bb + cc
            if delim<1e-10: continue
            dx = (ax*aa + bx*bb + cx*cc) / delim
            dy = (ay*aa + by*bb + cy*cc) / delim
            r2 = (ax-dx)**2 + (ay-dy)**2

            ok = True
            for x,y in XY:
                if (x-dx)**2 + (y-dy)**2 > r2 + 1e-5:
                    ok = False
                    break
            if ok:
                ans = min(ans, r2)

print(ans**0.5)

Measured memory_bytes: 3192
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
	if (a < b)swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  if(a == 5 && b == 5 && c == 7)cout << "YES" << endl;
  else if(a == 5 && b == 7 && c == 5)cout << "YES" << endl;
  else if(a == 7 && b == 5 && c == 5)cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main(){
long long N;
  cin >> N;
long long p = 1;  
  
  for(long long i = 1;i <= N;i++){
  p = p * i  % 1000000007;
  }
  
  cout << p << endl;
  return 0;
  
}

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

int main(){
    int N;
    cin >> N;
    vector<pair<string, pair<int, int>>> SP(N);
    for (int i = 0; i < N; i++){
        string S;
        int P;
        cin >> S >> P;
        SP.at(i) = make_pair(S,make_pair(-P, i));
    }
    sort(SP.begin(), SP.end());
    for (int i = 0; i < N; i++){
        cout << SP.at(i).second.second+1 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int maxn=1e6+5;
using namespace std;
const ll INF=1e13+7;
ll n,m;
char str[maxn];
ll dp[maxn];
ll q[maxn];
int pre[maxn];
void TraceBack(int x)
{
    if(pre[x]==-1)
    {
        printf("%d",x);
        return;
    }
    TraceBack(pre[x]);
    printf(" %d",x-pre[x]);
}
int main()
{
    memset(pre,-1,sizeof(pre));
    scanf("%lld%lld",&n,&m);
    scanf("%s",str);
    //数有n+1个
    int s=1,e=0;
    for(int i=0;i<=m;i++)
    {
        if(str[i]=='0')
            dp[i]=1;
        else
            dp[i]=INF;
        while(s<=e&&dp[i]<dp[q[e]]) e--;
        q[++e]=i;
    }
    s++;
    for(int i=m+1; i<=n; i++)
    {
        dp[i]=INF;
        if(str[i]=='0')
        {
            dp[i]=min(dp[q[s]]+1,dp[i]);
            if(!dp[i]!=INF)
                pre[i]=q[s];
        }
        while(s<=e&&dp[i]<dp[q[e]]) e--;
        q[++e]=i;
        while(s<=e&&q[s]<i+1-m)
            s++;
    }
    if(dp[n]==INF) printf("-1\n");
    else TraceBack(n);
    return 0;
}



Measured memory_bytes: 15872
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<algorithm>
#define ll long long int
#define nl "\n"
#define input for(ll i=0;i<n;i++)  cin>>a[i];
#define M 1000000007
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,a,b;
    cin>>n>>a>>b;
    ll s=a+b;
    ll r=n/s;
    ll res=r*a;
    ll rem=n-r*(a+b);
    if(rem>a)
        res=res+a;
    else
        res+=rem;
    cout<<res<<nl;
}


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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=1;i<=(n);++i)
#define ALL(v) v.begin(), v.end()
#define DUMP(x) cout<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

const lint MOD = (lint)1e9 + 7;

void mod_add(lint &a, lint b){
    a = (a+b) % MOD;
}

class DDigitsParade {
public:
	void solve(std::istream& in, std::ostream& out) {
	    string S;
	    in>>S;
	    int N = S.size();
	    vector<vector<lint>> dp(N+1, vector<lint>(13, 0));
	    dp[0][0] = 1;
	    REP(i, N){
	        REP(j, 13){
	            if(S[i]=='?'){
	                REP(k, 10){
	                    mod_add(dp[i+1][(10*j+k)%13], dp[i][j]);
	                }
	            } else {
	                mod_add(dp[i+1][(10*j+(S[i]-'0'))%13], dp[i][j]);
	            }
	        }
	    }
	    out<<dp[N][5]<<endl;
	}
};


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


Measured memory_bytes: 13696
import java.util.*;
import java.lang.*;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int v[] = new int[N];
        for(int i = 0; i < N; i++){
            v[i] = sc.nextInt();
        }
        double vMax = 0;
        Arrays.sort(v);
        vMax += (double)v[0] / Math.pow(2, N-1);
        for(int i = 1; i < N; i++){
            vMax += (double)v[i] / Math.pow(2, N-i);
        }


        System.out.println(vMax);




    }
}





Measured memory_bytes: 21844
using System;
using System.Collections.Generic;

namespace abc168_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var K = CIn.ReadInt();
      var S = CIn.Read();

      var ans = K < S.Length ? S[0..K] + "..." : S;

      Console.WriteLine(ans);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(int n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(int n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(int n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(int n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(int h, int w)
    {
      var array = new char[h, w];
      for (var i = 0; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}

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

int main() {
    
    int e[4];
    for(int i=0;i<4;i++){
        cin>>e[i];
    }
    sort(e,e+4);
    if(e[0] == e[1] && e[2] == e[3]){
        cout << "yes" << endl;
    }
    else{
        cout << "no" << endl;
    }
    return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
typedef long long ll;
typedef long double ld;
//typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef pair<ll,pair<ll,ll> > iii;
#define PI 3.141592653589793
#define mod (ll)(1000*1000*1000+7)
//# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)1e18
# define LN 20  
# define EPS 1e-9
typedef pair<ll,pair<ll,ll> > pii;
# define INF1 (ll)1e10
# define maxn 200005
# define offset 2000005
#define N 100005
const ld eps = 1e-10L;

/*void LPS()
{
	len = s.length();
    lps[0] = 0;
    for(ll i=1;i<len;i++){

        ll j = lps[i-1];
        while(j > 0 && s[j] != s[i])    j = lps[j-1];
        if(s[i] == s[j])    j++;
        lps[i] = j;
    }
}*/

/*************************************************
struct Coupon {
	ll l;
	ll r;
	ll id;

	Coupon(ll l, ll r, ll id): l(l), r(r), id(id) {} // Initialization

	bool operator<(const Coupon& c) { // Sorting
		return l < c.l;    
	}
};

**************************************************/

ll bit[maxn];
ll n;
ll h[maxn],a[maxn];
ll lis[maxn];

ll query(ll x,ll val)
{
	ll ans=0;
	for(ll i=x;i;i-=(i&-i))
	{
		ans=max(ans,val+bit[i]);
	}
	return ans;
}

ll update(ll x,ll val)
{
	for(ll i=x;i<maxn;i+=(i&-i))
		bit[i]=max(bit[i],val);
}

int main()
{
	cin >> n;
	for(ll i=1;i<=n;i++)
		cin >> h[i];
	for(ll i=1;i<=n;i++)
		cin >> a[i];

	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		lis[i]=query(h[i],a[i]);
		ans=max(ans,lis[i]);
		update(h[i],lis[i]);
	}

	cout << ans;
}



Measured memory_bytes: 6528
n = int(input())
a_l = list(map(int, input().split()))
a_l.sort()
b_l = list()

length = len(a_l)
k = 0
for i in range(length):
  if a_l[i] < 0:
    k = i
  else:
    break

b_l = a_l[:k+1]
if len(b_l) != 0:
  min_b = b_l[0]
a_l = a_l[k+1:]
if len(a_l) != 0:
  max_a = a_l[-1]
fu = len(b_l)
sei = len(a_l)
ans_l = list()
ans_n_l = list()
if len(b_l) != 0:
  if len(a_l) != 0:
    for i in range(1, fu):
      ans_l.append([max_a, b_l[i]])
      max_a -= b_l[i]
    for i in range(sei-1):
      ans_l.append([min_b, a_l[i]])
      min_b -= a_l[i]
    
    ans_l.append([max_a, min_b])
    max_a -= min_b
  else:
    max_a = b_l[-1]
    for i in range(1, fu-1):
      ans_l.append([max_a, b_l[i]])
      max_a -= b_l[i]
    ans_l.append([max_a, min_b])
    max_a -= min_b
else:
  min_b = a_l[0]
  for i in range(1, sei-1):
    ans_l.append([min_b, a_l[i]])
    min_b -= a_l[i]
  ans_l.append([max_a, min_b])
  max_a -= min_b
  
print(max_a)
for i in ans_l:
  print(i[0], i[1])
      
    


Measured memory_bytes: 68828
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	n, a := readArr()

	swappedCnt := 0

	for i := 0; i < n; i++ {
		minJ := i
		for j := i; j < n; j++ {
			if a[j] < a[minJ] {
				minJ = j
			}
		}

		if minJ != i {
			tmp := a[i]
			a[i] = a[minJ]
			a[minJ] = tmp
			swappedCnt++
		}
	}

	printArr(a)
	fmt.Println(swappedCnt)
}

func checkErr(e error) {
	if e != nil {
		log.Fatalln(e)
	}
}

func readArr() (int, []int) {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, err := strconv.Atoi(scanner.Text())
	checkErr(err)

	arr := make([]int, n)
	scanner.Scan()
	for i, s := range strings.Split(scanner.Text(), " ") {
		arr[i], err = strconv.Atoi(s)
		checkErr(err)
	}
	return n, arr
}

func printArr(arr []int) {
	s := strings.Trim(fmt.Sprint(arr), "[]")
	fmt.Println(s)
}



Measured memory_bytes: 1200
#pragma region
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define co(x) cout << x << endl
#define ce(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);
#pragma endregion

void solve() {
	string S, T; cin >> S >> T;
	cout << T << S << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}

Measured memory_bytes: 256
/* When Talent doesn't work, Hard work beats Talent*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(13);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define scanstr(s) cin>>ws; getline(cin,s);

#define debug(x) cout << __LINE__ << " " << #x <<"..." << x << endl
#define dev(x) cout << __LINE__ << " " << #x << "..." ; for(auto &it : x) cout<< it << " "; cout << endl;

const double PI = 3.141592653589793;

void solve()
{
	string s;
	cin >> s;
	if(s=="AAA" || s=="BBB") cout << "No\n";
	else cout << "Yes\n";
}

int32_t main()
{
	FastIO;
	Fast_D;
	int T;
	T=1;
	while(T--) solve();
	return 0;
}



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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
#define int long long
using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)3e5 + 7;

int n,m;
int p[N],sz[N];
int eq,up;
int e[1001][1001];
ll x,w,S,d,t[N];

vector <pair<ll,pair<int,int> > > vec;
vector <pair<ll,ll> > g[N];

int get (int v) {
      return (v == p[v] ? v : (p[v] = get(p[v])));
}
void unite (int a,int b) {
      a = get(a);
      b = get(b);

      if (a != b) {
            if (sz[a] < sz[b])
                  swap(a,b);
            p[b] = a;
            sz[a] += sz[b];
      }
}
void dfs (int v,int p = -1) {
      for (auto to : g[v]) {
            if (to.fr != p) {
                  t[to.fr] = max(t[v],to.sc);
                  dfs(to.fr,v);
            }
      }
}
int binpow (int a,int b) {
      int res = 1;
      while (b) {
            if (b & 1)
                  res *= a;
            a *= a;
            b /= 2;
            res %= inf;
            a %= inf;
      }
      return (res % inf);
}
main () {
      cin >> n >> m;
      cin >> x;

      for (int i = 1; i <= m; i ++) {
            int u,v;
            cin >> u >> v >> w;
            vec.pb({w,{u,v}});
      }
      sort (vec.begin(),vec.end());

      for (int i = 1; i <= n; i ++)
            p[i] = i,sz[i] = 1;

      for (int i = 0; i < vec.size(); i ++) {
            int a = vec[i].sc.fr;
            int b = vec[i].sc.sc;
            if (get(a) != get(b)) {
                  unite(a,b);
                  e[a][b] = 1;
                  e[b][a] = 1;
                  g[a].pb(mk(b,vec[i].fr));
                  g[b].pb(mk(a,vec[i].fr));
                  S += vec[i].fr;
            }
      }
      d = x - S;

      if (d < 0) {
            cout << "0";
            return 0;
      }
      for (int i = 0; i < vec.size(); i ++) {
            int u = vec[i].sc.fr;
            int v = vec[i].sc.sc;
            if (e[u][v])
                  continue;

            dfs(u);

            ll o = vec[i].fr - t[v];

            if (o == d)
                  eq ++;
            if (o > d)
                  up ++;

            for (int i = 1; i <= n; i ++)
                  t[i] = 0;
      }
      if (d == 0) {
            cout << (((binpow(2,n - 1) + inf - 2) % inf * 1ll * binpow(2,m - n + 1)) % inf + (((binpow(2,eq + 1) + inf - 2) % inf) * 1ll * binpow(2,up)) % inf) % inf << endl;
      }
      else {
            cout << (((binpow(2,eq + 1) + inf - 2) % inf) * 1ll * binpow(2,up)) % inf << endl;
      }
}


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

int main() {
  double A, B;
  int x, y;
  cin >> A >> B >> x >> y;

  cout << A * B / 2 << endl;

  if(x == A / 2 && y == B / 2) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}

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

int h, w;

string s;
map<char, int> mp;

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

  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    cin >> s;
    for (int j = 0; j < w; ++j) {
      mp[s[j]]++;
    }
  }

  int f, t, o;
  f = t = o = 0;

  for (char c = 'a'; c <= 'z'; ++c) {
    f += (mp[c] / 4) * 4;
    mp[c] %= 4;
    t += (mp[c] / 2) * 2;
    mp[c] %= 2;
    o += mp[c];
  }

  int a = (h / 2) * (w / 2);

  if (f >= a * 4) {
    f -= a * 4;
    t += f;
    //cout << "t = " << t << endl;
    int b = h * w - a * 4;
    if (b % 2 == 1) {
      if (o == 1 and o + t == b) {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }
    else {
      if (o > 0) {
        cout << "No" << endl;
      }
      else {
        cout << "Yes" << endl;
      }
    }
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}


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

using namespace std;

const long long int MOD = 1000000007;

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

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

	cin >> N;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> M;
		while (M % 2 == 0) {
			M /= 2;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
)

// n:S
// m:c
// Scc
func main() {
	n, m := readInt64(), readInt64()

	var cnt int64
	if 2*n <= m {
		cnt = n // add # of S(n)
		m -= 2 * n
		cnt += int64(m / 4)
		fmt.Println(cnt)
		os.Exit(0)
	} else {
		cnt = int64(m / 2)
		fmt.Println(cnt)
		os.Exit(0)
	}
}

func readInt64() int64 {
	var a int64
	fmt.Scan(&a)
	return a
}


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

using namespace std;
using ll = long long;

ll ans = 0;

int main()
{
  ios_base::sync_with_stdio (0);
  cin.tie (0) ;
  int n;
  cin >> n;
  multiset<double>s;
  for (int i = 1; i <= n; i++) {
    double x;
    cin >> x;
    s.insert (x);
  }
  if (n == 1) {
    cout << setprecision (10) << fixed << *s.begin() << '\n';
    return 0;
  }
  double x = *s.begin();
  s.erase (s.begin() );
  double y = *s.begin();
  s.erase (s.begin() );
  double ans = (x + y) / 2.0 ;
  while (!s.empty() ) {
    x = *s.begin();
    s.erase (s.begin() );
    ans = (ans + x) / 2.0;
  }
  cout << setprecision (10) << fixed << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
//17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
#define bolt ios::sync_with_stdio(false)
#define ull unsigned long long
#define ll long long
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
using namespace std;

int main() {

/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
#endif
*/
	bolt;
	cin.tie(nullptr);
	cout.tie(nullptr);
	ll h, w; cin >> h >> w;
	ll x = h * w;
	x = ceil(double(x) / double(2));
	if (h == 1) {
		cout << 1 << endl;
		return 0;
	}
	if (w == 1) {
		cout << 1 << endl;
		return 0;
	}
	cout << x << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)

///////////////////////////
int main() {
  string s;
  cin>>s;
  cout<<min(count(s.begin(),s.end(),'0'),count(s.begin(),s.end(),'1'))*2<<endl;
}
///////////////////////////



Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
int read()
{
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f;

int N,M,n,m;

int main()
{
    scanf("%d%d%d%d",&N,&M,&n,&m);
    if(N%n==0&&M%m==0){printf("No");return 0;}
    printf("Yes\n");
    for(int i=1;i<=N;i++){
    	for(int j=1;j<=M;j++)
    		printf("%d ",i%n||j%m?1100:-1100*(n*m-1)-1);
    	printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
 
using namespace std;
 
// typedef
typedef long long ll;
typedef long double ldbl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
 
// container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
// repetition
#define FOR(i,m,n) for (ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define RFOR(i,m,n) for (ll (i) = ((ll) (m)-1); (i) >= ((ll) n); --(i))
#define REP(i,n) FOR(i,0,n)
 
// i/o
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl
 
// constant
const double PI  = acos(-1.0);
const int    MOD = (int)(1e9 + 7);
// DO NOT set INFTY_XXXs constants. They may bring some BUG! Use MAX_XXXs in climit instead.
 
// clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
// debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

ll n =  1000;
ll pow5[1001];

int main() {
    ll x; cin >> x;
    for (ll i = 0; i <= n; i++) {
        pow5[i] = i*i*i*i*i;
    }

    ll ans_a = 0, ans_b = 0;
    for (ll a = 0; a <= n; a++) {
        for (ll b = 0; b <= n; b++) {
            if (pow5[a]  - pow5[b] == x) {
                ans_a = a;
                ans_b = b;
                goto Lexit;
            } else if (pow5[a]  + pow5[b] == x) {
                ans_a = a;
                ans_b = -b;
                goto Lexit;
            }
        }
    }
    Lexit:
    cout << ans_a << ' ' << ans_b << endl;
    return 0;
}


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

int main() {
  int64_t k, a, b, ans;
  cin >> k >> a >> b;
  if ((b-a <= 2) || (k <= a-1)) {
    ans += k+1;
  } else {
    ans = a;
    k -= a-1;
    ans += (b-a) * (k/2);
    if (k % 2 == 1) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            int iN = int.Parse(Console.ReadLine().Trim());
            string[] sInp = Console.ReadLine().Trim().Split(' ');
            List<int> lstNum = new List<int>();
            for (int i = 0; i < sInp.Length; i++)
            { lstNum.Add(int.Parse(sInp[i])); }

            // 解析
            int iOut = 0;
            for (int i = 0; i < lstNum.Count; i++)
            {
                iOut += lstNum[i] - 1;
            }

            //出力
            Console.WriteLine("{0}", iOut.ToString());

#if DEBUG
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif

    }

}


Measured memory_bytes: 13180
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define all(v) (v).begin(),(v).end()
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using int32 = int32_t; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
#define FASTCIN() cin.tie(0);ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
#define DEBUG_IMPORT(file) vs args(argv, argv+argc);str sample = make_sample(args, file);ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#else
#define DEBUG_IMPORT(file)
#endif
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


int32 main(int32 argc, char* argv[]) {
    FASTCIN();
    DEBUG_IMPORT("sample-1");


    int N,M; cin>>N>>M;
    vi W(N), V(N); REP(i,N) cin>>W[i]>>V[i];

    var dp = vvi(N+1, vi(M+4, 0));
    // dp[i][j] := [0,i) の品から、重さ j 以下で得られる価値の最大値

    REP(i, N) {
        REP(j, M+1) {
            if (W[i] <= j) { // W[i] を取れるなら
                dp[i+1][j] = max(dp[i][j], dp[i][j-W[i]] + V[i]);
            } else {
                dp[i+1][j] = dp[i][j];
            }
        }
    }

    int ans = dp[N][M];
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a%3==0||b%3==0||(a+b)%3==0)
    {
    	cout<<"Possible";
    }
    else
    {
    	cout<<"Impossible";
    }
    return 0;
}

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

map<int, int> mp;

int main(){
	int n;
	scanf("%d", &n);
	f(i, 0, n){
		int t;
		scanf("%d", &t);
		++mp[-t];
	}
	int a = 0, b = 0;
	for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it){
		if (it->second > 1){
			if (a == 0){
				a = it->first;
				if (it->second > 3)b = a;
			}
			else if (b == 0)b = it->first;
		}
	}
	printf("%lld\n", (ll)a * b);
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N, M;
	cin >> N >> M;
	vector<bool> data(N, false);

	for (int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
		if (a == 1)
		{
			if (data[b])
			{
				cout << "POSSIBLE" << endl;
				return;
			}
			else
			{
				data[b] = true;
			}
		}
		else if (b == N)
		{
			if (data[a])
			{
				cout << "POSSIBLE" << endl;
				return;
			}
			else
			{
				data[a] = true;
			}
		}
	}
	cout << "IMPOSSIBLE" << endl;

	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
a,b,c,d = map(int,input().split())
for _ in range(d-b):
  print('U', end='')
for _ in range(c-a):
  print('R', end='')
print('U', end='')
for _ in range(c-a+1):
  print('L', end='')
for _ in range(d-b+1):
  print('D', end='')
print('R', end='')  
for _ in range(c-a):
  print('R', end='')
for _ in range(d-b):
  print('U', end='')
print('R', end='')
for _ in range(d-b+1):
  print('D', end='')
for _ in range(c-a+1):
  print('L', end='')
print('U')

Measured memory_bytes: 4468
#include <stdio.h>
#define TG 2*123456+1
#include <math.h>

int main(void){
    int p[TG]={0};
    int i,j,cnt,n;
    for(i=1;i<TG;i+=2){
        if(i%3 && i%5 && i%7){p[i]=i;}
    }
    p[2]=2;p[3]=3;p[5]=5;p[7]=7;
    for(i=2;i<sqrt(TG);i++){
        if(!p[i]){continue;}
        for(j=i+1;j<TG;j++){
            if(!(p[j]%i)){p[j]=0;}
        }
    }
    while(1){
        scanf("%d",&n);
        if(!n){break;}
        cnt=0; 
        for(i=n+1;i<n*2+1;i++){
            if(p[i]){
                cnt++;
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}



Measured memory_bytes: 2708
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  long long T1,T2,A1,A2,B1,B2;
  cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

  long long d1 = (A1-B1)*T1,d2 = (A2-B2)*T2;

  if(d1 > 0) {
    d1 *= -1;
    d2 *= -1;
  }

  if(d1+d2 < 0) cout << 0 << endl;
  else if(d1+d2 == 0) cout << "infinity" << endl;
  else {
    long long n = -d1 / (d1+d2);
    long long r = -d1 % (d1+d2);
    if(r == 0) cout << n*2 << endl;
    else cout << n*2+1 << endl;
  }
}





Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
			System.out.println("Possible");
		} else {
			System.out.println("Impossible");
		}

	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

/**
 * Created by sotetsuk on 2015/07/31.
 */
public class Main {
    static final int K = 10;
    static int N;
    static int[] balls = new int[10];
    static Scanner sc = new Scanner(System.in);
    static int l, r;

    public static void read() {
        for(int i = 0; i < K; i++) {
            balls[i] = sc.nextInt();
        }
    }

    public static boolean dfs(int i) {
        // stop condition
        if(i == K) return true;

        // recursive
        boolean flag_l = false; boolean flag_r = false;
        if(l == -1 || balls[l] < balls[i]) {
            int tmp_l = l; l = i; flag_l = dfs(i + 1); l = tmp_l;
        }
        if(r == -1 || balls[r] < balls[i]) {
            int tmp_r = r; r = i; flag_r = dfs(i + 1); r = tmp_r;
        }
        return flag_l || flag_r;
    }

    public static void solve() {
        l = -1; r = -1;
        String ans = dfs(0) ? "YES" : "NO";
        System.out.println(ans);
    }

    public static void main(String[] args) {
        N = sc.nextInt();
        for(int i = 0; i < N; i++) {
            read();
            solve();
        }

    }
}

Measured memory_bytes: 16516
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int n,a[200010];
bool check(int x){
    vector<P>v;
    for(int i=1;i<n;i++){
        if(a[i-1]>=a[i]){
            if(x==1)return false;
            while(!v.empty()&&v.back().fi>a[i])v.pop_back();
            int pos=a[i];
            bool updated=false;
            while(!v.empty()){
                if(v.back().fi!=pos){
                    v.pb({pos,1});
                    updated=true;
                    break;
                }
                if(v.back().se+1<x){
                    v.back().se++;
                    updated=true;
                    break;
                }
                pos--;
                v.pop_back();
            }
            if(!updated){
                if(pos==0)return false;
                v.pb({pos,1});
            }
        }
    }
    return true;
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n)cin>>a[i];
    int ok=n,ng=0;
    while(ok-ng>1){
        int mid=(ok+ng)/2;
        if(check(mid))ok=mid;
        else ng=mid;
    }
    cout<<ok<<endl;
    return 0;
}

Measured memory_bytes: 5188
#include <iostream>
#include <utility>

using namespace std;

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

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

  int ans = 0;
  for(int i = 0; i < n; i++) {
    int sum = 0;
    for(int j = 0; j <= i; j++) {
      sum += a[0][j];
    }
    for(int j = i; j < n; j++) {
      sum += a[1][j];
    }
    ans = max(ans, sum);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7
MAX_N = 2 * 10 ** 5

fact = [1] * MAX_N
inverse = [1] * MAX_N
inv_fact = [1] * MAX_N
for i in range(2, MAX_N):
  fact[i] = fact[i-1] * i % MOD
  inverse[i] = -inverse[MOD % i] * (MOD // i) % MOD
  inv_fact[i] = inv_fact[i-1] * inverse[i] % MOD

n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
  a, b = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

stack = [0]
parent = [0] * n
route = []
while stack:
  vertex = stack.pop()
  route.append(vertex)
  for child in edge[vertex]:
    if parent[vertex] != child:
      parent[child] = vertex
      stack.append(child)

dp = [1] * n
size = [1] * n
for vertex in route[:0:-1]:
  pa = parent[vertex]
  sz = size[vertex]
  dp[vertex] = dp[vertex] * fact[sz-1] % MOD
  dp[pa] = dp[pa] * dp[vertex] * inv_fact[sz] % MOD
  size[pa] += sz
dp[0] = dp[0] * fact[n-1] % MOD

for vertex in route[1:]:
  pa = parent[vertex]
  sz = size[vertex]
  tmp = dp[pa] * pow(dp[vertex], MOD - 2, MOD) * sz * inverse[n-sz] % MOD
  dp[vertex] = dp[vertex] * tmp % MOD

for value in dp:
  print(value)

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

int main()
{
	int m,h;
	int i;
	char str[201],head[201],tail[201];

	while(1)
	{
		scanf("%s",str);
		if(!strcmp(str,"-")){break;}
		scanf("%d",&m);
		for(i=0;i<m;i++)
		{
			scanf("%d",&h);
			strncpy(tail,str,h);
			tail[h]='\0';
			strcpy(head,str+h);
			sprintf(str,"%s%s",head,tail);
			
		}

		puts(str);		
				
	}

	return 0;
}

Measured memory_bytes: 624
def gcd(m, n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x %y != 0:
            z = x % y
            x = y
            y = z
        else:
            return z
def lcm(x, y):
    return int((x * y) / gcd(x, y))
a,b,c,d = map(int,input().split())
count = 0
if c == 1 or d == 1:
    print(0)
else:
    lcm = lcm(c,d)
    ans1 = (b // c - (a-1) // c + b // d - (a-1) // d - b // lcm + (a-1) // lcm)
    print(b - a + 1 - ans1)


Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (min, max, numC, numD) = readLine()!!.split(" ").map { it.toLong() }
    val leastCommon = (numC * numD) / gcd(numC, numD)
    val total = 1 + max - min

    print(total - (countSet(min, max, numC) + countSet(min, max, numD) - countSet(min, max, leastCommon)))
}

fun countSet(min: Long, max: Long, num: Long): Long {
    val tempTotal = max / num
    val outside = (min - 1) / num

    return tempTotal - outside
}

fun gcd(a: Long, b: Long): Long {
    return if (a < b) gcd(b, a) else if (b == 0L) a else gcd(b, a % b)
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n;
vll a,b;
vll s,t;
lli ans;

int main(){
  cin >> n;
  a = vll(n);b = vll(n);
  for(lli i = 0;i < n;i++) cin >> a[i];
  for(lli i = 0;i < n;i++) cin >> b[i];
  lli ub = max(*max_element(a.begin(),a.end()),*max_element(b.begin(),b.end()))*2;
  for(lli bit = 1;bit <= ub;bit <<= 1){
    s = a;t = b;
    bit <<= 1;
    for(lli i = 0;i < n;i++) s[i] %= bit,t[i] %= bit;
    bit >>= 1;
    sort(t.begin(),t.end());
    lli c = 0;
    for(lli i = 0;i < n;i++){
      c += lower_bound(t.begin(),t.end(),bit*2-s[i])-lower_bound(t.begin(),t.end(),bit*1-s[i]);
      c += lower_bound(t.begin(),t.end(),bit*4-s[i])-lower_bound(t.begin(),t.end(),bit*3-s[i]);
    }
    ans |= ((c%2)*bit);
  }
  cout << ans << endl;
}


Measured memory_bytes: 6528
#include <iostream>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    int n,k;	cin >> n >> k;  
    int ans = 0;
    rep(i, n){
	int h;	cin >> h;
	if(h >= k)  ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var n = long.Parse(Console.ReadLine());
        //long[] n = Console.ReadLine().Split().Select(long.Parse).ToArray();

        var ans = -1;
        var a = 0L;
        for (int i = 0; i < n; i++)
        {
            a = (a * 10 + 7) % n;
            if(a == 0)
            {
                ans = i + 1;
                break;
            }
        }

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27548
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const double EPS = 1E-10;

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




int main(){
    long long N, K; std::cin >> N >> K;
    long long ans((N+2-K)*(N*N+N+6+K*(N+2) - 2*K*K)/6);
    ans %= MOD;
    if(ans < 0) ans += MOD;
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(){
  int n,i,j,c[20000],t,flag=0;
  
  scanf("%d",&n);

  for(i=0;i<10001;i++){
    c[i] = 0;
  }
  for(i=0;i<n;i++){
    scanf("%d",&t);
    c[t]++;
  }

  for(i=0;i<10001;i++){
    for(j=c[i];0<j;j--){
      if(flag==1){
	printf(" ");
      }
      printf("%d",i);
      flag=1;
    }
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2144
import itertools
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
length = [i+1 for i in range(n)]
permut = list(itertools.permutations(length))
print(max((permut.index(p)) - (permut.index(q)) , (permut.index(q)) - permut.index(p)))


Measured memory_bytes: 8052
A, B, C, D = map(int,input().split())

q1, mod1 = divmod(A, D)
q2, mod2 = divmod(C, B)

if mod1 != 0:
  q1 += 1
if mod2 != 0:
  q2 += 1

if q1 >= q2:
  print("Yes")
else:
  print("No")

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    // start
    vector<char> v1(3), v2(3), v3(3);
    rep(i, 3) cin >> v1.at(i);
    rep(i, 3) cin >> v2.at(i);
    rep(i, 3) cin >> v3.at(i);
    cout << v1.at(0) << v2.at(1) << v3.at(2) << endl;
    // end

    return 0;
}


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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n){
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  int ans = 0;
  rep(i, k){
    ans += p.at(i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int LCS[1010][1010];

void solve(string x, string y)
{
	for (int i = 0; i != x.size(); i++)
	{
		for (int j = 0; j != y.size(); j++)
		{
			if (x[i] == y[j])
			{
				LCS[i + 1][j + 1] = LCS[i][j] + 1;
			}
			else
			{
				LCS[i + 1][j + 1] = max(LCS[i][j + 1], LCS[i + 1][j]);
			}
		}
	}

	cout << LCS[x.size()][y.size()] << endl;
}

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

	for (int i = 0; i < 1000; i++)
	{
		LCS[0][i] = 0;
		LCS[i][0] = 0;
	}

	for (int i = 0; i < q; i++)
	{
		string x, y;
		cin >> x >> y;
		solve(x, y);
	}
	return 0;
}


Measured memory_bytes: 7084