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

using namespace std;

int main()
{
    int N;
    int T, A;
    vector<int> H;
    cin >> N;
    cin >> T;
    cin >> A;
    for (int i = 0; i < N; ++i)
    {
        int h;
        cin >> h;
        H.push_back(h);
    }
    int ans = 0;
    float t = abs(A - T + H[0] * 0.006);
    for (int i = 0; i < N; ++i)
    {
        if (abs(A - T + H[i] * 0.006) < t)
        {
            t = abs(A - T + H[i] * 0.006);
            ans = i;
        }
    }
    cout << ans + 1 << endl;
}

Measured memory_bytes: 3620
import sys
import math

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

#d=list()
#A=list()

sunuke=list()
for i in range(N):
    sunuke.append(0)

for i in range(K):
    #d.append(int(input()))
    #A.append(list(map(int,input().split())))
    d=int(input())
    A=list(map(int,input().split()))

    for j in range(d):
        sunuke[A[j]-1] += 1

n=0
for i in range(N):
    if sunuke[i]==0:
        n+=1

print(n)




Measured memory_bytes: 9196
s=input()
q=int(input())
que=[list(map(str,input().split())) for i in range(q)]
count=0
for i in que:
  if i[0]=="1":
    count+=1
ans=[[],[]]
ak=count
for i in que:
  if i[0]=="1":
    count-=1
  else:
    if i[1]=="1":
      ans[count%2].append(i[2])
    else:
      ans[(count+1)%2].append(i[2])
if ak%2==0:
  print("".join(reversed(ans[0]))+s+"".join(ans[1]))
else:
  print("".join(reversed(ans[0]))+"".join(reversed(list(s)))+"".join(ans[1]))

Measured memory_bytes: 35864
#include <iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

int main() {
	int a, b, c, ans;
	cin >> a >> b >> c;
	
	if (a == b && b == c) {
		ans = 1;
	}

	else if (a != b && b != c && c != a) {
		ans = 3;
	}
	else {
		ans = 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef int status;
typedef long long ll;
typedef unsigned long long ull;
const ull base = 343;
const int INF = int(1e9);
const ll INF1 = ll(1e18);
const int MAX = 2002;

char a[30];

int main()
{
    cin>>a;
    int len = strlen(a);
    if(len<26){
        int flag = 0;
        int b[40] = {0};
        for(int i = 0; i <len;i++){
            b[a[i]-'a'] = 1;
        }
        for(int i = 0;i < 26;i++)
        if(b[i]==0){
            flag = i;
            break;
        }
        for(int i = 0;i < len;i++)
            cout<<a[i];
        cout<<char('a'+flag)<<endl;
    }else{
        int flag = 0;
        for(int i = 1;i < len;i++)
        if(a[i]>a[i-1]){
            flag = 1;
            break;
        }
        if(!flag){cout<<-1<<endl;return 0;}

        for(int i = len - 2;i >= 0;i--){
            //cout<<a[i]<<" "<<a[i+1]<<endl;
            if(a[i]>a[i+1])continue;
            else {
                //cout<<i<<" **********"<<endl;
                int min1 = 159;
                for(int j = i+1;j<len;j++){
                    if(a[j]>a[i]&&a[j]<min1)min1 = a[j];
                }
               // cout<<char(min1)<<endl;
                a[i] = min1;
                for(int j = 0;j <= i;j++)
                    cout<<a[j];
                cout<<endl;
                return 0;
            }
        }
    }

    return 0;
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,p;cin>>n>>p;
  string s;cin>>s;
  if(p==2||p==5){
    rep(i,0,n){
      ll k=s[i]-'0';
      if(k%p==0)res+=i+1;
    }
    cout<<res<<endl;
    return 0;
  }
  map<ll,ll>mp;
  ll now=0;
  mp[0]++;
  ll tmp=1;
  vector<ll>b(n);
  rrep(i,0,n){
    now+=(s[i]-'0')*tmp;
    b[i]=now%p;
    mp[b[i]]++;
    tmp*=10;
    tmp%=p;
  }
  for(auto z:mp)res+=z.se*(z.se-1)/2;
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 2580
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
ll dp[3001][3001], mod = 1e9 + 7;
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, i, ans = 0, j;
    cin>>n;
    string s;
    cin>>s;
    dp[1][1] = 1;
    for(i = 2; i <= n; i++) {
    	vector<ll> pref(n + 1, 0);
    	pref[0] = dp[i-1][0];
    	for(j = 1; j <= n; j++) {
    		pref[j] = (pref[j-1] + dp[i-1][j])%mod;
    	}
    	for(j = 1; j <= i; j++) {
    		if(s[i-2] == '<') {
    			dp[i][j] = pref[j-1];
    		} else {
    			dp[i][j] = ((pref[n] - pref[j-1])%mod + mod)%mod;
    		}
    	}
    }
    for(i = 1; i <= n; i++) {
    	// cout<<dp[3][i]<<" ";
    	ans = (ans + dp[n][i])%mod;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 68992
#include <bits/stdc++.h>
using namespace std;
int main(){
  int Y, M, D;
  char a, b;
  cin >> Y >> a >> M >> b >> D;
  if(M <= 4){
    cout << "Heisei" << endl;
  }else{
    cout << "TBD" << endl;
  }
  
}

Measured memory_bytes: 256
N = int(input())
D = [0] * 2
count = 0
ans = 0
for i in range(N):
    D = list(map(int, input().split()))
    if D[0] == D[1]:
        count = count + 1
    else:
        count = 0
    if count == 3:
        ans = 1
if ans == 1:
    print("Yes")
    
else:
    print("No")

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll dp[455][455];
ll P[455];

ll sum(int l, int r)
{
	if(l==0) return P[r];
	else return P[r]-P[l-1];
}

ll solve(int l, int r)
{
	if(l>r) return 0;
	if(l==r) return 0;
	if(dp[l][r]!=-1) return dp[l][r];
	ll ans = ll(1e18);
	for(int i=l;i<r;i++)
	{
		ans = min(ans, solve(l,i)+solve(i+1,r)+sum(l,r));
	}
	return (dp[l][r]=ans);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++) cin>>P[i];
	for(int i=1;i<n;i++) P[i]+=P[i-1];
	memset(dp,-1,sizeof(dp));
	cout<<solve(0,n-1)<<'\n';
}


Measured memory_bytes: 1920
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> xs(n), ys(n), hs(n);
    for(int i = 0; i < n; i++){
        cin >> xs[i] >> ys[i] >> hs[i];
    }
    vector<int> is(n);
    iota(is.begin(), is.end(), 0);
    sort(is.begin(), is.end(), [&](int i, int j){ return hs[i] > hs[j]; });
    if(hs[is[0]] == 0){
        return 1;
    }
    for(int cy = 0; cy <= 100; cy++){
        for(int cx = 0; cx <= 100; cx++){
            int h = hs[is[0]] + abs(xs[is[0]] - cx) + abs(ys[is[0]] - cy);
            bool ok = true;
            for(int ii = 1; ii < n; ii++){
                int i = is[ii];
                int h2 = hs[i] + abs(xs[i] - cx) + abs(ys[i] - cy);
                if(hs[i] == 0){
                    if(h > h2){
                        ok = false;
                        break;
                    }
                }else{
                    if(h != h2){
                        ok = false;
                        break;
                    }
                }
            }
            if(ok){
                cout << cx << ' ' << cy << ' ' << h << '\n';
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll N;
ll A[100010], B[100010], C[100010], bcCnt[100010];
std::vector<ll> nB, nC;

int main()
{
  std::cin >> N;
  rep( i, N )
    std::cin >> A[i];
  rep( i, N )
    std::cin >> B[i];
  rep( i, N )
    std::cin >> C[i];

  std::sort( A, A+N );
  std::sort( B, B+N );
  std::sort( C, C+N );

  for( int i = N-1; i >= 0; --i )
  {
    ll cnt = std::upper_bound( C, C+N, B[i] )-C;
    bcCnt[i] = N-cnt+(i+1<N?bcCnt[i+1]:0);
  }

  //rep( i, N )
    //std::cout << bcCnt[i] << std::endl;

  ll ans = 0;

  rep( i, N )
  {
    ll idx = std::upper_bound( B, B+N, A[i] )-B;
    ans += bcCnt[idx];
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 3328
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        x: i32,
        y: i32,
        a: i32,
        b: i32,
    }
    let ans = if a == -1 || b == -1 {
        if x == y {
            "Draw"
        } else if x < y {
            "Alice"
        } else {
            "Bob"
        }
    } else if a == b {
        "Draw"
    } else if a > b {
        "Alice"
    } else {
        "Bob"
    };
    println!("{}", ans);
}

fn main() {
    run();
}



Measured memory_bytes: 5028
#define _USE_MATH_DEFINES
#include <sstream> //string stream its useful!
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector> // vector
#include <algorithm>    // swap,sort,binary_search
#include <functional>   // std::greater
#include <map> //map
#include<set> //set
#include<queue> //queue
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include <iomanip> //cout<<setprecision

typedef long long ll;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

using namespace std;
void omajinai() {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(15);
    //freopen("txt.csv","r",stdin);
}

ll W = 1000000000 + 7;
int main(){
    omajinai();
    int N;
    cin>>N;
    ll*  T = new ll[N+2];
    ll* A = new ll[N+2];
    for_each(T+1,T + N+1, [](ll &i ){cin>>i;});
    for_each(A+1,A + N+1, [](ll &i ){cin>>i;});
    T[0] = 0; A[0] = A[1]; T[N+1] = T[N] ; A[N+1] = 0;
    ll ans = 1LL;
    for(int i = 1 ; i<N+1;i++){
        if(T[i] >T[i-1]){
            if((A[i]== A[i+1]&&A[i] == T[i])||A[i] >= T[i]) ans*= 1;
            else ans*=0;
        }else{
            if(A[i] == A[i+1]) ans *= ((min(A[i],T[i])));
            else if(A[i] <= T[i]) ans*=1;
            else ans = 0;
        }
        ans%=W;
    }
    cout<<ans<<endl;
}

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

int a,b,c,ans,n,r,h[500000],d[500000];
string s,t;

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    r=h[0];
    for(int i=1;i<n;i++){
        c++;
        if(r<h[i])c=0;

        d[i]=c;
        r=h[i];
    }
    for(int i=0;i<n;i++){
        ans=max(ans,d[i]);
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: u16,
        p: u16,
    }
    let s = (3 * a + p) / 2;
    println!("{}", s);
}


Measured memory_bytes: 4352
// ProblemURL : https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_b
// ---------------------------------------------
package main

import "fmt"

func main() {
	var a, b, k int
	fmt.Scan(&a, &b, &k)
	for i := 0; i < k; i++ {
		if i%2 == 0 {
			b += a / 2
			a /= 2
		} else {
			a += b / 2
			b /= 2
		}
	}
	fmt.Println(a, b)
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


ll gcd(ll x, ll y) {
  if (x < y) swap(x, y);
  return y ? gcd(y, x%y) : x;
}


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



  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  a--;
  ll lcm = c * d / gcd(c, d);

  ll bb = b - (b / c + b / d - b / lcm);
  ll aa = a - (a / c + a / d - a / lcm);

  cout << bb - aa << endl;

  

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{		
		int N = GetInt();
		int K = GetInt();
		int X = GetInt();
		int Y = GetInt();
		Console.WriteLine(Math.Min(K, N) * X + Math.Max(0, N-K) * Y);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main() {
  string s;
  cin >> s;

  printf("%c",s[0]);
  printf("%lu",s.size()-2);
  printf("%c\n",s[s.size()-1]);

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
long long mod = 1000000007;
long long f[100010];
long long get_pow(long long x, long long k, long long mod) {
    long long res = 1;
    while (k) {
        if (k & 1) res = (res * x) % mod;
        x = (x * x) % mod;
        k >>= 1;
    }
    return res;
}
void inclusion_exclusion(long long f[], int n, long long mod) {
    int i, j;
    for (i = n; i > 0; i--) {
        for (j = i + i; j <= n; j += i) {
            f[i] = (f[i] - f[j] + mod) % mod;
        }
    }
}
int main() {
    int n, k, i, j;
    long long ans = 0;
    scanf("%d%d", &n, &k);
    for (i = 1; i <= k; i++) {
        f[i] = get_pow(k / i, n, mod);
    }
    inclusion_exclusion(f, k, mod);
    for (i = 1; i <= k; i++) {
        ans = (ans + i * f[i]) % mod;
    }
    printf("%lld\n", ans);
    return 0;
}


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



int main(){
   string s;
   cin>>s;
   int k ;
   cin >> k;
   int n = s.size();
   vector<string> ST;
   for(int i=0;i<=n-1;++i){
       for(int j = 1; j<=5; ++j){
           ST.push_back(s.substr(i,j));
       }
   }
   sort(ST.begin(),ST.end());
   unique(ST.begin(),ST.end());
   cout << ST[k-1] <<endl;
      }

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define REP64(i, s,  n) for(int64 i = s;i < (n);i++)
#define INF 999999999
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

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

int N, X;
int a[100];

signed main(){
	cin >> N >> X;
	REP(i, 0, N)	cin >> a[i];
	
	sort(a, a+N);
	int ans = 0;
	REP(i, 0, N) {
	    if(X >= a[i]) {
	        X -= a[i];
	        ans++;
	    } else {
	        X = 0;
	        break;
	    }
//		cout << "X = " << X << "  ans = " << ans << endl;
	}
	if(X > 0)   ans = max(ans - 1, 0);
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = 0;
		int max = 1000000;

		for (int i = 0; i < M; i++) {

			min = Math.max(min, sc.nextInt());
			max = Math.min(max, sc.nextInt());
		}
		System.out.println(Math.max(max - min + 1, 0));
	}
}

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

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

ll A[2000] = {};
const ull C = 1000000007;
int main()
{
    ll N, K;
    cin >> N >> K;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    
    ll cntpost[2000] = {};
    ll cntpre[2000] = {};
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
            if(A[i] > A[j]){
                if(i < j) ++cntpost[i];
                if(i > j) ++cntpre[i];
            }
        }
    }
    
    ull ans = 0;
  	const ull T = (K-1)*K / 2 % C;
    for(int i = 0; i < N; ++i){
        ans += cntpost[i] * K  + (cntpost[i] + cntpre[i]) * T;
        ans %= C;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    char ch[x][y+1];
    for(int i=0;i<x;i++)
        cin>>ch[i];
    for(int i=1;i<=y+2;i++)
        cout<<"#";
    cout<<endl;
    for(int i=0;i<x;i++)
        cout<<"#"<<ch[i]<<"#"<<endl;
     for(int i=1;i<=y+2;i++)
        cout<<"#";
    cout<<endl;
    return 0;
}



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

using namespace std;
int q_sort(int d[],int left,int right){
	if(left >= right) return 0;
	int pipot = d[(left+right)/2], l = left, r = right, tmp;
	while(l<r){
		while(d[l] < pipot) l++;
		while(d[r] > pipot) r--;
		if( l <=  r){
			tmp = d[l];
			d[l] = d[r];
			d[r] = tmp;
			l++;
			r--;
		}
	}
	q_sort(d,left,r);
	q_sort(d,l,right);
}
int main(void)
{
	int n;
	cin>>n;
	int x[n];
	for(int i = 0; i < n; i++) cin>>x[i];
	
	q_sort(x,0,n-1);
	
	int p;
	int ans;
	long int min = 1000000000;
	for(p = x[0]; p <= x[n-1]; p++){
		long int cost = 0;
		for(int i = 0; i < n; i++){
			cost+=(x[i]-p)*(x[i]-p);
		}
		if(min > cost){
			ans = p;
			min = cost;
		}
	}
	//for(int i = 0; i < n; i++) cout<<x[i]<<endl;
	//cout<<endl;
	cout<<min<<endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
    x=0;char c=getchar();bool f=0;
    while(!isdigit(c)) f|=c=='-',c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
    if(x<0){putchar('-'),write(-x);}
    else{if(x>9)write(x/10);putchar('0'+x%10);}
}

#define int long long
#define pii pair<int,int>
#define x first
#define y second

const int mod=1e9+7,N=1e4+5;
int n,ans,cnt,id[1000005];
vector<pii> ma,p[N];

int fpow(int x,int y){
	int res=1;
	for(;y;y>>=1,x=x*x%mod) if(y&1) res=res*x%mod;
	return res;
}

signed main(){
	read(n);
	for(int i=1,x;i<=n;i++){
		int xx=read(x);
		for(int j=2;j*j<=x;j++){
			int cnt=0;
			while(x%j==0) x/=j,cnt++;
			if(cnt)	p[i].push_back(pii(j,cnt));
		}
		if(x^1) if(xx/x%x) p[i].push_back(pii(x,1)); else p[i][p[i].size()-1].y++;
		for(int j=0;j<p[i].size();j++){
			if(!id[p[i][j].x]) id[p[i][j].x]=++cnt,ma.push_back(pii(p[i][j].x,0));
			ma[id[p[i][j].x]-1].y=max(ma[id[p[i][j].x]-1].y,p[i][j].y);
		}
//		for(int j=0;j<p[i].size();j++) printf("#%lld:: %lld %lld\n",i,p[i][j].x,p[i][j].y);
	}
//	for(int i=0;i<cnt;i++) printf("#%lld %lld\n",ma[i].x,ma[i].y);
	for(int i=1;i<=n;i++){
		vector<pii> now=ma;
		int cur=1;
		for(int j=0;j<p[i].size();j++) now[id[p[i][j].x]-1].y-=p[i][j].y;
		for(int j=0;j<cnt;j++) cur=cur*fpow(now[j].x,now[j].y)%mod;
		ans=(ans+cur)%mod;
//		printf("@%lld %lld\n",i,cur);
	}
	write(ans);
}


Measured memory_bytes: 7424
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n) {return REPS(n).map(i->getInt());}
	static Scanner s=new Scanner(System.in);
	static int getInt(){return Integer.parseInt(s.next());}
	public static void main(String[]$){
		int n=getInt();

		ArrayList<ArrayList<Edge>>edges=new ArrayList<>();
		for(int i=0;i<n;++i)edges.add(new ArrayList<>());
		for(int i=0;i<n-1;++i){
			int a=getInt()-1,b=getInt()-1,c=getInt();
			edges.get(a).add(new Edge(a,b,c));
			edges.get(b).add(new Edge(b,a,c));
		}
		int q=getInt(),k=getInt()-1;
		long[]dist=new long[n];
		{
			PriorityQueue<Edge>p=new PriorityQueue<>(edges.get(k));
			Arrays.fill(dist,Integer.MAX_VALUE);
			dist[k]=0;

			int filled=1;
			while(filled!=n){
				Edge poll=p.poll();
				if(dist[poll.t]==Integer.MAX_VALUE) {
					dist[poll.t]=dist[poll.f]+poll.c;
					p.addAll(edges.get(poll.t));
					++filled;
				}
			}
		}
		for(int i=0;i<q;++i)
			System.out.println(dist[getInt()-1]+dist[getInt()-1]);
	}
	static class Edge implements Comparable<Edge>{
		int f,t;long c;
		public Edge(int from,int to,int cost){f=from;t=to;c=cost;}
		@Override
		public String toString(){return "("+f+","+t+")="+c;}
		@Override
		public int compareTo(Edge o){
			long v=c-o.c;
			return v==0?0:v>0?1:-1;
		}
		@Override
		public int hashCode(){
			final int prime=31;
			int result=prime+(int)(c^(c>>>32));
			result=prime*result+f;
			result=prime*result+t;
			return result;
		}
		@Override
		public boolean equals(Object obj){
			if(this==obj) return true;
			if(obj==null||getClass()!=obj.getClass()) return false;
			Edge other=(Edge)obj;
			if(c!=other.c||f!=other.f||t!=other.t) return false;
			return true;
		}
	}
}

Measured memory_bytes: 117948
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int K = sc.nextInt();
			
			final long MOD = 998244353;
			
			int[] ls = new int[K];
			int[] rs = new int[K];
			for(int i = 0; i < K; i++) {
				ls[i] = sc.nextInt();
				rs[i] = sc.nextInt();
			}
			
			long[] DP = new long[N + 1];
			DP[0] = 1;
			DP[1] = -1;
			
			for(int position = 0; position < N; position++) {
				for(int i = 0; i < K; i++) {
					final int l = Math.min(N, position + ls[i]);
					final int r = Math.min(N, position + rs[i] + 1);
					
					DP[l] = (DP[l] + DP[position] + MOD) % MOD;
					DP[r] = (DP[r] - DP[position] + MOD) % MOD;
				}
				
				DP[position + 1] += DP[position];
				DP[position + 1] %= MOD;
			}
			
			System.out.println(DP[N - 1]);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 35452
// Problem : A - Xor Battle
// Contest : AtCoder - AtCoder Grand Contest 045
// URL : https://atcoder.jp/contests/agc045/tasks/agc045_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int,ll > pil;
typedef pair<ll ,int> pli;
typedef pair<ll ,ll > pll;
typedef vector<int> vi;
typedef vector<ll > vl;
#define pque priority_queue
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
#define bugs(x) cerr<<"    "<<(x);
#define bugx(x) cerr<<"    "<<(#x)<<" = "<<(x);
#define bugl cerr<<"\n";
#define bugt bugx(clock());bugl;
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline bool bmax(IT &a,IT b){if(a<b){a=b;return true;}else return false;}
template<class IT>inline bool bmin(IT &a,IT b){if(a>b){a=b;return true;}else return false;}
const int N=205;
ll A[N],B[64];
char S[N];
inline void ac(){
	memset(B,0,sizeof(B));
	int n,i,k;ll a;
	scanf("%d",&n);
	rep(i,1,n)scanf("%lld",&A[i]);
	scanf("%s",S+1);
	per(i,n,1){
		a=A[i];
		if(S[i]=='0'){
			//Add
			per(k,63,0)if(a>>k&1ll){
				if(B[k])a^=B[k];
				else{B[k]=a;break;}
			}
		}else{
			//Que
			per(k,63,0)if((a>>k&1ll)&&B[k])a^=B[k];
			if(a){printf("1\n");return;}
		}
	}
	printf("0\n");
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	
	int T;
	scanf("%d",&T);
	while(T--)ac();
	return 0;
}
#undef pque
#undef rep
#undef per
#undef REP
#undef PER
#undef mp
#undef pb
#undef pf
#undef pob
#undef pof
#undef fi
#undef se
#undef bugs
#undef bugx
#undef bugl

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,i;
cin>>n;
long long h[n+1],dp[n+1]={0};
h[0]=0;
for(i=1;i<=n;i++)
     cin>>h[i];
 dp[0]=0;
 dp[1]=0;
 for(i=2;i<=n;i++)
 {
  if(i==2)
        dp[2]=abs(h[i]-h[i-1])+dp[i-1];
  else{
    dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
  }

 }
cout<<dp[n]<<endl;

}


Measured memory_bytes: 1792
//start of jonathanirvings' template v3.0.3 (BETA)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int q,h,s,d,n;
LL N;

int main()
{
  scanf("%d %d %d %d",&q,&h,&s,&d);
  scanf("%d",&n);
  N = 4LL * n;
  MIN(h,2*q);
  MIN(s,2*h);
  MIN(d,2*s);
  // debug("%d %d %d %d\n",q,h,s,d);
  LL risan = N / 8 * d;
  N %= 8;
  risan += N / 4 * s;
  N %= 4;
  risan += N / 2 * h;
  N %= 2;
  risan += N * q;
  printf("%lld\n",risan);
  return 0;
}










Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n + 1];
        int[] sum = new int[n + 1];
        for (int i = 1; i <= n; i++) ar[i] = sc.nextInt();
        boolean ok = true;
        int cnt = 0;
        LinkedList<Integer> ans = new LinkedList<>();

        for (int i = n; i > 0; i--) {
            if (sum[i] % 2 != ar[i]) {
                cnt++;
                ans.addFirst(i);
                for (int j = 1; 1L * j * j <= 1L * i; j++) {
                    if (i % j == 0) {
                        sum[j] += 1;
                        if (i / j != j) {
                            sum[i / j] += 1;
                        }
                    }
                }
            }
        }
//        debug(sum);
//        debug(ans);
        PrintWriter out = new PrintWriter(System.out);
        if (ok) {
            out.println(cnt);
            if (cnt != 0) {
                out.print(ans.removeFirst());
                for (int a : ans) out.print(" " + a);
                out.println();
            }
        } else {
            out.println(-1);
        }
        out.flush();
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 83340
#include<iostream>

using namespace std;

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

	if (a==5&&b==7&&c==5)
	{
		cout << "YES" << endl;
	}
	else if (a == 7 && b == 5 && c == 5)
	{
		cout << "YES" << endl;
	}
	else if (a == 5 && b == 5 && c == 7)
	{
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}

	return 0;



}

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

typedef long long ll;
using namespace std;

typedef pair<ll,ll> P;

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

	ll n; cin >> n;
	ll d[200005];
	map<ll,P> mp;

	ll sum = 0;
	ll s[200005];

	mp[0] = P(1,1);
	for (int i = 0;i < n;i++){
		cin >> d[i];
		sum += d[i];
		s[i] = sum;
		P p = mp[sum];
		if(p.first == 0)mp[sum].first = mp[sum].second  =  i+2;
		else mp[sum].second = i+2;
	}

	ll ans = -1;

	for (auto&& var : mp) {
		ll tmp = var.second.second - var.second.first;
		ans = max(ans,tmp);
	}

	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 17100
n, m = input().split()
n = int(n)
m = int(m)

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

ans = 0

if n >= 2:
    ans += cmb(n, 2)
else:
    pass

if m >= 2:
    ans += cmb(m, 2)
else:
    pass

print(ans)


Measured memory_bytes: 3064
import sys
from collections import deque
n, k = [int(i) for i in sys.stdin.readline().split()]
ls = []
graph = {i:[] for i in range(n)}
for i in range(n-1):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    ls.append((a, b))
MOD = 10**9+7
root = 0
que = deque([root])
colors = [-1 for i in range(n)]
parent = [-1 for i in range(n)]
grandpa = [-1 for i in range(n)]
already = {root}
res = k
while len(que) > 0:
    cur = que.popleft()
    cnt = 0
    for _next in graph[cur]:
        if _next == parent[cur]:
            continue
        parent[_next] = cur
        grandpa[_next] = parent[cur]
        que.append(_next)
        if parent[cur] != -1:
            res = res * (k - cnt - 2) % MOD
        else:
            res = res * (k - cnt - 1) % MOD
        cnt += 1
print(res)

Measured memory_bytes: 79844
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()
h=n1()
if n<=k:
    ans=0
else:
    ans=sum(sorted(h)[:n-k])
print(ans)

Measured memory_bytes: 26024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;

public class Main {
	static HashMap<String, Integer> map = new HashMap<String, Integer>();
	static int n,m;
	static int[] v,t;
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		int sum = 0;
		String[] str = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			int num = Integer.parseInt(str[i]);
			a[i] = num;
			sum += num;
		}
		int ave = (int)Math.round(1.0*sum/n);
		int cost = 0;
		for(int i = 0; i < n; i++){
			int c = a[i]-ave;
			cost += c*c;
		}
		sb.append(cost);
		System.out.println(sb);
	}
}

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

int main() {
    auto transvarsemat = [](const auto& a) -> vector<vector<unsigned long>>{
        auto N = a[0].size(), M = a.size();
        vector<vector<unsigned long>> ret(N, vector<unsigned long>(M));
        for(unsigned long i = 0; i != N; ++i)
            for(unsigned long j = 0; j != M; ++j)
                ret[i][j] = a[j][i];
        return ret;
    };
    auto multimat = [&transvarsemat](const auto& a, const auto& b) -> vector<vector<unsigned long>>{
        auto bt = transvarsemat(b);
        auto N = a.size(), M = b[0].size();
        vector<vector<unsigned long>> ret(N, vector<unsigned long>(M));
        for(unsigned long i = 0; i != N; ++i)
            for(unsigned long j = 0; j != M; ++j)
                ret[i][j] = inner_product(a[i].begin(), a[i].end(), bt[j].begin(), 0UL) % 1000000007;
        return ret;
    };
    auto modpowmat = [&multimat](const auto& _a, size_t n) -> vector<vector<unsigned long>>{
        auto N = _a.size();
        vector<vector<unsigned long>> a(_a), ret(N, vector<unsigned long>(N, 0));
        for(unsigned long i = 0; i < N; ++i)ret[i][i] = 1;
        while(n){
            if(n & 1)ret = multimat(ret, a);
            a = multimat(a, a);
            n >>= 1;
        }
        return ret;
    };
    auto modpow = [](unsigned long a, size_t n){
        unsigned long ret{1};
        while(n){
            if(n & 1){
                ret *= a;
                ret %= 1000000007;
            }
            a *= a;
            a %= 1000000007;
            n >>= 1;
        }
        return ret;
    };
    vector<vector<unsigned long>> a({{2,0,1,1,0,0,0,0,0,0},{0,4,0,0,0,0,0,0,0,0},{0,0,1,0,1,1,1,0,0,0},{2,0,0,1,0,0,0,1,0,0},{2,1,1,0,0,0,0,0,0,0},{0,1,0,0,0,0,0,1,1,1},{2,0,1,0,0,0,0,0,1,0},{0,1,1,0,0,1,1,0,0,0},{1,1,0,1,0,0,0,1,0,0},{1,1,1,1,0,0,0,0,0,0}});

    unsigned long N;
    cin >> N;

    cout << (modpow(4, N) + 1000000007 - modpowmat(a, N)[0][1]) % 1000000007 << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)

from collections import defaultdict
d = defaultdict(list)

import operator
from functools import reduce


def prod(iterable):
    return reduce(operator.mul, iterable, 1)


# from itertools import combinations
# comb = combinations(range(N), 2)

# 累積和
# from itertools import accumulate
# _list = list(accumulate(a_list)

# from functools import lru_cache
# @lru_cache(maxsize=None)
# def setUp(self):
#     dp.cache_clear()


def dividers(n: int):
    for i in range(1, math.ceil(math.sqrt(n)) + 1):
        if n % i == 0:
            yield i


def prime_factor(n: int):
    res = defaultdict(int)
    res[1] = 1
    for i in range(2, math.ceil(math.sqrt(n))):
        while (n % i == 0):
            res[i] += 1
            n = n // i

    if (n != 1):
        res[n] = 1

    return res


def flatten_key_count(d):
    return sum([[k for _ in range(d[k])] for k in d.keys()], [])


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # h_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    if N == 1:
        print(1)
        return

    _min = 10**10
    for a in dividers(N):
        b = N // a

        if a > b:
            _min = min(_min, len(str(a)))
        else:
            _min = min(_min, len(str(b)))

    print(_min)


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """10000"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1000003"""
        output = """7"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """9876543210"""
        output = """6"""
        self.assertIO(input, output)


Measured memory_bytes: 5988
n,k = map(int,input().split())
li = list(map(int,input().split()))
new_li = [0]
for l in li:
    new_li.append(new_li[-1]+(l+1)/2)
# print(new_li)
# [0, 1.0, 2.5, 4.0, 6.5, 9.5]
tmp_li = []
for i,n in enumerate(new_li):
    if i < k-1:
        continue
    tmp_li.append(new_li[i] - new_li[i-k])
    #print(i,i-k)
print(max(tmp_li))

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
int a[maxn], b[maxn];







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

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


    sort(a,a+n);
    sort(b,b+n);


    if (n%2==1) {
	int res = b[n/2] - a[n/2] + 1;
	out(res);
    }

    int l = (a[n/2-1]+a[n/2]);
    int r = (b[n/2-1]+b[n/2]);

    out(r-l+1);



    return 0;
}


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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
    for (ll i = 2; i<=l; i++){
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
}
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll N; cin >> N;
    prime_factorize(N);
    ll res = 0;
    for (auto mp: prime) { // とりあえず同じ素因数の組で頑張る
        for (int i = 1; ; i++) {
            if (mp.second < i) break;
            mp.second -= i;
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3664