akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
        #define ll long long
        #define f   first
        #define s   second
        #define pb          push_back
        #define mod        1000000007
        #define mod1       1000000009
        #define hell        998244353
        #define inf         1000000000000000000LL
        #define pi          3.14159265358979323
        #define N           1000005
        using namespace std;
        ll n,k,sum,q,res,m,val,ans;
        ll x,y;
        ll xx[]={1,0,-1,0};
        ll yy[]={0,1,0,-1};
        void solve()    
        {   ll a,b;
            cin>>n>>m>>k;
            vector<string> v(n);
            for(int i=0;i<n;i++)
                cin>>v[i];
            ll ans=0;
            for(int i=0;i<(1LL<<n);i++)
            {
                vector<string> v2=v;
                for(int j=0;j<n;j++)
                {
                    if(i&(1LL<<j))
                    {
                        for(int l=0;l<m;l++)
                            v2[j][l]='.';
                    }
                }

                for(int a=0;a<(1LL<<m);a++)
                {  vector<string> v3=v2;
                    for(int b=0;b<m;b++)
                    {
                        if(a&(1LL<<b))
                        {
                            for(int l=0;l<n;l++)
                                v3[l][b]='.';
                        }
                    }
                    ll res=0;
                for(int x=0;x<n;x++)
                {
                    for(int y=0;y<m;y++)
                        if(v3[x][y]=='#') res++;
                }
                if(res==k) ans++;


                }
                
            }
            cout<<ans;

        }
        int main()
        {   ios_base::sync_with_stdio(false);
            cin.tie(0);cout.tie(0);
            ll t=1;
            //cin>>t;
            while(t--)
                solve();
            

        }            

Measured memory_bytes: 3656
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define int long long
using namespace std;

int a[200010];

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

inline void read(int& a){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

signed main(){
    int n=read(),k=read();
    
    for(int i=1;i<=n;i++)
        a[i]=read();
        
    for(int i=k+1;i<=n;i++)
        if(a[i]>a[i-k])
            puts("Yes");
        else
            puts("No");
            
    return 0;
}

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

int main() {
    int x, y, s;
    while (cin >> x >> y >> s, x | y | s) {
        int max = 0;
        for (int i = 1; i < s; ++i) {
            int p1 = i * (100 + x) / 100;
            for (int j = i; j < s; ++j) {
                int p2 = j * (100 + x) / 100;
                if (p1 + p2 == s) {
                    int t = i * (100 + y) / 100 + j * (100 + y) / 100;
                    if (t > max)
                        max = t;
                }
            }
        }
        cout << max << endl;
    }
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    void Calc()
    {
        cin = new Scanner();

        int n = cin.nextInt();
        int k = cin.nextInt();

        string str = cin.next();

        k--;

        char[] ca = str.ToCharArray();

        switch(ca[k])
        {
            case 'A':
                ca[k] = 'a';
                break;
            case 'B':
                ca[k] = 'b';
                break;
            case 'C':
                ca[k] = 'c';
                break;
        }

        str = new string(ca);

        Console.WriteLine(str);
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  string s;
  cin >> s;
  if (sz(s) < 26) {
    set<char> st;
    for (auto &ch : s) {
      st.insert(ch);
    }
    for (char ch = 'a'; ch <= 'z'; ch++) {
      if (st.find(ch) == st.end()) {
        s += string(1, ch);
        break;
      }
    }
    cout << s << "\n";
  } else if (s == "zyxwvutsrqponmlkjihgfedcba") {
    cout << "-1\n";
  } else {
    for (int i = 25; i >= 0; i--) {
      char sm = 'z' + 1;
      for (int j = i + 1; j < 26; j++) {
        if (s[i] < s[j]) {
          sm = min(sm, s[j]);
        }
      }
      if (sm < 'z' + 1) {
        s[i] = sm;
        cout << s.substr(0, i + 1) << "\n";
        return 0;
      }
    }
    
  }
}



Measured memory_bytes: 256
n,k=map(int,input().split())
A=list(map(int,input().split()))
for i in range(n):
    A[i]+=1

for i in range(n-1):
    A[i+1]+=A[i]

ans=0.0
A.reverse()
A.append(0)
A.reverse()

for i in range(n-k+1):
    now=A[i+k]-A[i]
    if now>ans:
        ans=now

print(ans/2)

Measured memory_bytes: 25060
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber

#include <bits/stdc++.h>

using namespace std;

// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// constants...
const double PI = acos(-1);
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18+5;

// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

// chess moves...
// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1,  1,  1,  2,  2}; ///Knight's Move
// int dy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

// structs...
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

// functions...
ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b)
{
    ll x = max(a-b, b), ans=1;

    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }

    return ans;
}


void task()
{
    //code here...
    
    ll n, ans=0;
    cin >> n;
    
    for(int K=1; K<=n; K++){
		for(int L=1; L<=n; L++){
			for(int M=1; M<=n; M++){
				ans += gcd(gcd(K, L), M);
			}
		}
	}
	
	cout << ans << "\n";
}


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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    task();

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

string s;
int ind=0;

//0:m, 1:e, 2:w, 3:cat;
int dfs(){
  //cout<<s[ind]<<endl;
  if(ind==s.size()) return -1;
  if(s[ind]=='e') return 1;
  if(s[ind]=='w') return 2;
  if(s[ind]=='m'){
    //cout<<"create C"<<endl;
    char c[5];
    c[0]=0;
    REP(i,1,5){
      ind++;
      c[i] = dfs();
      if(i==2 && (c[0]==0&&c[1]==1&&c[2]==2)){
        return 3;
      }
      if(i==3 && ((c[0]==0&&c[1]==1&&c[2]==3&&c[3]==2) || (c[0]==0&&c[1]==3&&c[2]==1&&c[3]==2))){
        return 3;
      }
      if(i==4 && (c[0]==0&&c[1]==3&&c[2]==1&&c[3]==3&&c[4]==2)){
        return 3;
      }
    }
  }

  return -1;
}

int main() {
  cin>>s;
  if(dfs() == 3 && ind==s.size()-1) cout<<"Cat"<<endl;
  else cout<<"Rabbit"<<endl;
  return 0;
}

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


int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++){
    string s;
    cin >> s;
    if (s == "Y"){
      cout << "Four" << endl;
      return 0;
    }
  }
    cout << "Three" << endl;
}
      

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

int main()
{
	int n; scanf("%d", &n);
	long long a[n][2];
	long long maxa = -1e18, maxb = -1e18;
	long long mina = 1e18+10, minb = 1e18+10;
	for(int i=0; i<n; ++i){
		cin >> a[i][0] >> a[i][1];
		long long value1 = (a[i][0] - a[i][1]);
		long long value2 = (a[i][0] + a[i][1]);
		maxa = max(maxa, value2);
		maxb = max(maxb, value1);
		mina = min(mina, value1);
		minb = min(minb, value2);
	}
	long long ans = 0;
	ans = max(abs(maxa-minb), abs(maxb-mina));
	printf("%lld\n", max(ans, 0ll));
}


Measured memory_bytes: 6956
// agrawal117
//chahat agarwal
#include<bits/stdc++.h>  
#define mod 1000000007
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
    ll ans=3*n*n;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var sc = NewScanner(os.Stdin, 1000000)

type pair struct {
	p, y int
}

func main() {
	n := sc.ReadInt()
	m := sc.ReadInt()
	ys := make([][]int, n)
	pairs := make([]*pair, m)
	for i := 0; i < m; i++ {
		p := sc.ReadInt()
		y := sc.ReadInt()
		ys[p-1] = append(ys[p-1], y)
		pairs[i] = &pair{p, y}
	}
	for i := 0; i < n; i++ {
		sort.Ints(ys[i])
	}
	for _, pair := range pairs {
		fmt.Printf("%06d%06d\n", pair.p, sort.SearchInts(ys[pair.p-1], pair.y)+1)
	}
}

type Scanner struct {
	*bufio.Scanner
}

func (scn *Scanner) ReadInt() int {
	scn.Scanner.Scan()
	i, _ := strconv.Atoi(scn.Scanner.Text())
	return i
}

func NewScanner(r io.Reader, bufSize int) *Scanner {
	buf := make([]byte, bufSize)
	scn := bufio.NewScanner(r)
	scn.Buffer(buf, bufSize)
	scn.Split(bufio.ScanWords)
	return &Scanner{scn}
}


Measured memory_bytes: 14464
def yakusu(n):
    defyaku = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            defyaku.append(i)
            if i != n // i:
                defyaku.append(n // i)
    return defyaku

N = int(input())
yaku = yakusu(N)
ans = 0
for i in yaku:
    if i == 1: continue
    v, n = divmod(N, i - 1)
    if v == n:
        ans += (i - 1)

print(ans)

Measured memory_bytes: 3264
#include<iostream>
using namespace std;
int main(){
	int n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	if(n%a==0)a=n/a;
	else a=n/a+1;
	b=b*a;
	if(n%c==0)c=n/c;
	else c=n/c+1;
	d=c*d;
	if(b<d)swap(b,d);
	cout<<d<<endl;

	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
const int N=2010;
int d[N],n,k,e[N][2];
vector<int> v[N];
void dfs(int x,int fx){
    for(auto y:v[x]){
        if(y==fx)continue;
        d[y]=d[x]+1;
        dfs(y,x);
    }
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<n;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
        e[i][0]=x; e[i][1]=y;
    }
    int ans=n;
    if(k&1){
        for(int i=1;i<n;i++){
            int x,y,tmp=0;
            x=e[i][0]; y=e[i][1];
            d[x]=d[y]=0;
            dfs(x,y); dfs(y,x);
            for(int i=1;i<=n;i++)if(d[i]>k/2)tmp++;
            ans=min(ans,tmp);
        }
    }
    else{
        for(int i=1;i<=n;i++){
            int tmp=0; 
			d[i]=0;
            dfs(i,0);
            for(int i=1;i<=n;i++)if(d[i]>k/2)tmp++;
            ans=min(ans,tmp);
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    long long int n, k = 0;
    cin >> n >> k;
    vector<unsigned long long> h(n);

    for (unsigned long long i = 0; i < n; i++)
    {
        cin >> h[i];
    }

    sort(h.begin(), h.end());

    unsigned long long min = 0-1;

    for (unsigned long long i = n - 1; i >= k - 1; i--)
    {
        if (min > h[i] - h[i - k + 1])
        {
            min = h[i] - h[i - k + 1];
        }
    }

    cout << min << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
typedef pair<int,int> P;
const ll MO = 1000000007;

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

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll Q;
    cin >> Q;
    bool rev = false;
    string suf = "";
    REP(i, Q) {
        ll T;
        cin >> T;
        if (T == 1) {
            rev = !rev;
            continue;
        }
        ll F;
        cin >> F;
        char C;
        cin >> C;
        if (F == 1) {
            if (rev)
                S.push_back(C);
            else
                suf.push_back(C);
        }
        else {
            if (rev)
                suf.push_back(C);
            else
                S.push_back(C);
        }
    }
    if (rev) {
        reverse(S.begin(), S.end());
        cout << S << suf << endl;
    }
    else {
        reverse(suf.begin(), suf.end());
        cout << suf << S << endl;
    }
    return 0;
}

Measured memory_bytes: 980
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

struct SCC{
	vector<vector<int>>G,rG;
	vector<bool>used;
	vector<int>vs;
	void addEdge(int x,int y){
		G[x].push_back(y);
		rG[y].push_back(x);
	}
	void dfs(int x){
		used[x]=true;
		for(int i:G[x])if(!used[i])dfs(i);
		vs.push_back(x);
	}
	vector<int>cmp;
	void rdfs(int v,int k){
		used[v]=true;
		cmp[v]=k;
		for(int i:rG[v])if(!used[i])rdfs(i,k);
	}
	void scc(){
		fill(all(used),false);
		rep(i,len(G))if(!used[i])dfs(i);
		fill(all(used),false);
		int k=0;
		rev(i,len(vs))if(!used[vs[i]])rdfs(vs[i],k++);
	}
	SCC(int N):G(N),rG(N),used(N),cmp(N){}
};
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N,M;
	cin>>N>>M;
	SCC scc(N);
	rep(i,M){
		int a,b;cin>>a>>b;
		scc.addEdge(a,b);
	}
	scc.scc();
	map<int,vector<int>>mp;
	rep(i,N)mp[scc.cmp[i]].push_back(i);
	cout<<len(mp)<<"\n";
	for(auto i:mp){
		cout<<len(i.second)<<" ";
		for(int j:i.second)cout<<j<<" ";
		cout<<"\n";
	}
}

Measured memory_bytes: 112724
#if __has_include("D:/dhiraj/Programming/debug.h")
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
    #define cerr if(0) cerr
#endif

// Macro --------------------------------------------------------------------

#define ll                  int64_t
#define FOR(i, a, b, s)     for(ll i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define FOR1(b)             FOR(i, 0, b, 1)
#define FOR2(i, b)          FOR(i, 0, b, 1)
#define FOR3(i, a, b)       FOR(i, a, b, (a) <= (b) ? 1 :-1)
#define FOR4(i, a, b, s)    FOR(i, a, b, s)
#define GET5(a, b, c, d, e, ...) e
#define FORC(...)           GET5(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)
#define loop(...)           FORC(__VA_ARGS__)(__VA_ARGS__)
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define endl                '\n'

// Template -----------------------------------------------------------------

// multiple input
template <typename... T> 
inline void inp(T&... args) {
    ((cin>>args), ...);
}
// scan vector
template <typename T> 
inline istream &operator >>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream &operator >>(istream &in, pair<T, U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

void solve(int &T)
{
    string s;
    cin >> s;

    ll ans = 0;
    if(s[0] == 'R' or s[1] == 'R' or s[2] == 'R') ans = 1;
    if(s[0] == 'R' and s[1] == 'R') ans = 2;
    if(s[2] == 'R' and s[1] == 'R') ans = 2;
    if(s[0] == 'R' and s[2] == 'R' and s[1] == 'R') ans = 3;

    // loop(i,3) {
    //     ll x = 0;
    //     loop(j,i,3) {
    //         if(s[j] == 'S') {
    //             ans = max(ans, x);
    //             break;
    //         }
    //         x++;
    //     }
    // }
    cout << ans << endl;
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt", "r", stdin);
        freopen("D:/dhiraj/Programming/o1.txt", "w", stdout);
        // freopen("D:/dhiraj/Programming/e1.txt", "w", stderr);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    for(int i = 1; i <= t; i++) {
        cerr << "Case #" << i << "\n";
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>

int main(int argc, char const* argv[]) {
  using namespace std;

  string s, t;
  cin >> s;
  cin >> t;

  int count =0;
  for(int i=0;i<3;i++)
  {
	  if(s[i] == t[i])
		  count++;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
local floor = math.floor
-- heap
local function Heap(upper_func)
    local floor = math.floor
    local a = {}
    local upper = function(k1, k2)
        --assert(k1 < k2)
        if k1 == 0 then
            return false
        else
            return upper_func(a[k1], a[k2])
        end
    end

    local lower = function(k1, k2)
        return not upper(k1, k2)
    end

    local function count()
        return #a
    end

    local function _swap(k1, k2)
        local old_k1 = a[k1]
        a[k1] = a[k2]
        a[k2] = old_k1
    end

    local function upheap(newk)
        local ku = floor(newk / 2)
        local k = newk
        while ku > 0 and lower(ku, k) do
            _swap(ku, k)
            k = floor(k/2)
            ku = floor(ku/2)
        end
    end
    
    local insert = table.insert
    local function insertq(e)
        insert(a, e)
        upheap(#a)
    end
    
    local function downheap(newk)
        local k = newk
        while k <= floor(#a/2) do
            local kdl = k*2
            local kdr = kdl + 1
            local kd
            if kdr <= #a and lower(kdl, kdr) then
                kd = kdr
            else
                kd = kdl
            end
            if upper(k, kd) then
                break
            end
            _swap(k, kd)
            k = kd
        end
    end
    
    local function top()
        --assert(#a >= 1)
        return a[1]
    end
    
    local remove = table.remove
    local function remove_top()
        --assert(#a >= 1)
        local v = a[1]
        _swap(1, #a)
        remove(a)
        downheap(1)
        return v
    end

    local self = {}
    self.count = count
    self.insertq = insertq
    self.top = top
    self.remove_top = remove_top
    return self
end

---
local N, M = io.read("*n", "*n")
local q = Heap(function (x,y) return x > y end)
local insertq = q.insertq
local remove_top = q.remove_top
for i=1,N do
    insertq(io.read("*n"))
end
for i=1,M do
    local top = remove_top()
    top = top / 2
    insertq(top)
end
local sum = 0
for i=1,N do
    local top = remove_top()
    sum = sum + floor(top)
end
print(sum)

Measured memory_bytes: 1408
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def dfs(v, c):
        for u in edge[v]:
            if color[u] is None:
                color[u] = c
                dfs(u, c ^ 1)
            else:
                if color[u] != c:
                    print(-1)
                    exit()

    n = int(input())
    S = [list(input()) for _ in range(n)]
    edge = [[] for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if S[i][j] == "1":
                edge[i].append(j)
                edge[j].append(i)

    color = [None] * n
    dfs(0, 0)
    for i in range(n):
        for j in range(n):
            if i == j:
                S[i][j] = 0
            else:
                S[i][j] = f_inf if S[i][j] == "0" else 1

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

    res = 0
    for s in S:
        res = max(res, max(s))
    print(res + 1)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 76808
#include <bits/stdc++.h>
#define MAXN 1000
#define pb push_back
using namespace std;

int n, m;
int a, b;
vector <int> path[MAXN+5];
int vis[MAXN+5];
deque <int> arr;
vector <int> ans;
bool tf = 1;

void DFS(int now) {
	vis[now] = 1;
	arr.push_back(now);
	for (int i : path[now]) {
		if (!vis[i]) {
			DFS(i);
		} else if (vis[i] == 1 && !ans.size()) {
			while (arr.size() && i != arr.front()) {
				vis[arr.front()] = -1;
				arr.pop_front();
			}
			while (arr.size()) {
				ans.pb(arr.front());
				arr.pop_front();
			}
			return;
		}
	}
	if (arr.size()) {
		arr.pop_back();
		vis[now] = -1;
	}	
	return;
}

signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		path[a].pb(b);
	}
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) DFS(i);
	}
	if (!ans.size()) cout << -1 << '\n';
	else {
		int s = 0;
		for (int k = 0; k < ans.size(); k++) {
			for (int i = 0; i < ans.size(); i++) {
				if (ans[i] < 0) continue;
				int now = (i+1)%ans.size();
				for (int j : path[ans[i]]) {
					if (vis[j] == 1 && ans[now] != j) {
						while (ans[now] != j) {
							if (ans[now] > 0)
								vis[ans[now]] = -1, ans[now] = -1, s++;
							now = (now+1)%ans.size();
						}
					}
				}
			}
		}
		cout << ans.size()-s << '\n';
		for (int i = 0; i < ans.size(); i++)
			if (ans[i] > 0) cout << ans[i] << '\n';
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

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

    ll int a[n];

    rep(i, n){
        cin >> a[i];
    }
    int g = 0;
    repeatrev(i, n - 1, 1){
        if(a[i] < a[i - 1]){
            if(a[i] - a[i - 1] == -1) a[i - 1] --;
            else g = 1;
        }
    }
    //rep(i, n) cout << a[i] << endl;
    if(g == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
n,m,d = map(int,input().split())	
# abs(a[i]-a[i+1])のsum の平均を求める
# 1..n から構成される長さmの数列 pow(n,m)通りを並び替えた数列に対して平均を求める
# 総和を求めてpow(m,m)でわる
# 同じ数字を何回使っても良いから、それぞれの場所に対して何パターンあるかを計算して、
# それにpow(n,m-2)を欠けたものを足す感じでできる 平均は i,i+1のパターン / n^2
# if d == 1: *n 
# else: (n-d)*2
# 足す箇所はm-1あるので
k = 0
if d == 0: k = n
else: k = (n-d)*2
ans = (m-1)*k/(n**2)
print(ans)

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

typedef long long LL;
typedef unsigned long long ULL;

const int PI = 3.141592653589793;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 200007;

int main(){

        ios_base::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);

        int n, k; cin >> n >> k;
        vector <int> ar(n);
        for (int i = 0; i < n; i++)
                cin >> ar[i];

        auto check = [&] (int x) {
                LL s = 0;
                for (int z: ar) {
                        s += (z + x - 1) / x - 1;
                }
                return s <= k;
        };
        int l = 0, r = *max_element(ar.begin(), ar.end()) + 1;
        while (l < r - 1) {
                int m = (l + r) / 2;
                if (check(m)) r = m;
                else l = m;
        }
        cout << r << "\n";
        return 0;
}


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

using namespace std;

map < int, int > H;
int N, sol, a[100005];

int main() {
    ios_base::sync_with_stdio(false);
    cin >> N;
    
    for (int i = 1; i <= N; ++i) {
        int x; cin >> x;
        if (H[x]) {
            H[x] = 0;
        } else {
            H[x] = 1;
        }
        a[i] = x;
    }
    
    for (std::map<int,int>::iterator it=H.begin(); it!=H.end(); ++it)
        if (it -> second > 0) {
            ++sol;
        }
    
    cout << sol << '\n';
    return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include<cstdlib>

using namespace std;

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
    int n;
    cin >> n;
    int *a = new int[n];
    bool flag = false;

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

    qsort(a, n, sizeof(int), compare_int);
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) {
            cout << "NO" << endl;
            flag = true;
            break;
        }
    }
    if (!flag) {
        cout << "YES" << endl;
    }

    return 0;
}


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            a[num - 1] = i + 1;
        }
        for (int i = 0; i < n; i++) {
            System.out.println(a[i]);
        }
    }
}


Measured memory_bytes: 60296
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
//		String s = sc.next();

		System.out.println(N * A >= B ? B : N*A);


	}

}


Measured memory_bytes: 22612
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<cmath>
#include<vector>
#include<cstring>
#include<queue>
using namespace std;

int main(){
    char a;
    while (cin>>a)
    {
        if(a>='a' && a<'z')
            cout<<(char)(a+1)<<endl;
        else if(a>='A' && a<'Z')
            cout<<(char)(a+1+32)<<endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
int a[300005];
ll suf[300005];

int main(){
    int n;
    scanf("%d",&n);
    int n3 = n+n+n;
    for(int i = 1; i<=n3; i++)
        scanf("%d",&a[i]);
    multiset<ll> aset;
    ll sufsum = 0;
    for(int i = n+n+1; i<=n3; i++){
        sufsum+=a[i];
        aset.insert(a[i]);
    }
    suf[n+n] = sufsum;
    for(int i = n+n; i>n; i--){
        if(a[i]<*aset.rbegin()){
            sufsum-=*aset.rbegin();
            sufsum+=a[i];
            aset.erase(aset.find(*aset.rbegin()));
            aset.insert(a[i]);
        }
        suf[i-1] = sufsum;
    }
    aset.clear();
    ll asum = 0;
    for(int i = 1; i<=n; i++){
        asum+=a[i];
        aset.insert(a[i]);
    }
    ll ans = asum-suf[n];
    for(int i = n+1; i<=n+n; i++){
        if(a[i]>*aset.begin()){
            asum-=*aset.begin();
            asum+=a[i];
            aset.erase(aset.find(*aset.begin()));
            aset.insert(a[i]);
        }
        ans = max(ans,asum-suf[i]);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 6912
#pragma GCC optimize("Ofast")
#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()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    bool ok = false;
    if (S == "KIHBR") ok = true;
    if (S == "AKIHBR") ok = true;
    if (S == "KIHABR") ok = true;
    if (S == "KIHBAR") ok = true;
    if (S == "KIHBRA") ok = true;
    if (S == "AKIHABR") ok = true;
    if (S == "AKIHBAR") ok = true;
    if (S == "AKIHBRA") ok = true;
    if (S == "KIHABAR") ok = true;
    if (S == "KIHABRA") ok = true;
    if (S == "KIHBARA") ok = true;
    if (S == "AKIHABAR") ok = true;
    if (S == "AKIHABRA") ok = true;
    if (S == "AKIHBARA") ok = true;
    if (S == "KIHABARA") ok = true;
    if (S == "AKIHABARA") ok = true;
    cout << (ok ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



signed main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	vector<int>a(N);
	rep(i, N)cin >> a[i];

	vector<int>b(N);
	rep(i, N)b[a[i]]++;

	sort(ALL(a));
	const int maxnum = a[N - 1];
	const int minnum = (maxnum + 1) / 2;
	rep(i, minnum)if (b[i]) {
		cout << "Impossible" << endl;
		return 0;
	}
	for (int i = minnum; i <= maxnum; i++)if (b[i] == 0) {
		cout << "Impossible" << endl;
		return 0;
	}
	if (maxnum % 2 == 1 && b[minnum] != 2) {
		cout << "Impossible" << endl;
		return 0;
	}
	if (maxnum % 2 == 0 && b[minnum] != 1) {
		cout << "Impossible" << endl;
		return 0;
	}
	cout << "Possible" << endl;
}

Measured memory_bytes: 384
#!/usr/bin/ruby
s=Array.new(100002,0)
gets.to_i.times{a,b=gets.split.map(&:to_i);s[a-1]+=1;s[b]-=1}
t=0;p 1.step(100000).reduce(0){|a,i|a=(t+=s[i])<i ?a: i}

Measured memory_bytes: 6900
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){

int N;
cin>>N;
long long K;
cin>>K;
long long A[N];
long long s[N+1];
s[0]=0;
for(int i=0;i<N;i++){
    cin>>A[i];
    s[i+1]=s[i]+A[i];
}

map<int,int>mp;
queue<int>q;

long long ans=0;

for(int i=0;i<=N;i++){
    long long now=(s[i]-i)%K;
    ans+=mp[now];
    mp[now]++;
    q.push(now);
    if(q.size()>=K){
        mp[q.front()]--;
        q.pop();
    }
}
cout<<ans<<endl;



 return 0;
}
/*
5 4
1 4 2 3 5

4


8 4
4 2 4 2 4 2 4 2

7


10 7
14 15 92 65 35 89 79 32 38 46

8
*/

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

int main(void) {
    int n;
    int a;
    int count = 0;
    
    cin >> n;
    for(int i = 0; i < n; ++i) {
        bool check = true;
        cin >> a;
        for(int j = 2; j <= sqrt(a); ++j) {
            if(a % j == 0) {
                check = false;
            }
        }
        if(check)   ++count;
    }
    cout << count << endl;
    
    return 0;
}



Measured memory_bytes: 3088
import java.util.*;
//import java.io.*;


public class Main{

    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());

        int n =sc.nextInt();
        int[] w = new int[n];
        for(int i=0;i<n;i++){
            w[i]=sc.nextInt();
        }
        sc.close();

        int formerPartSum[]= new int[n+1];
        int latterPartSum[]= new int[n+1];

        formerPartSum[0]=0;
        for(int i=0;i<n;i++){
            latterPartSum[0]+=w[i];
        }

        int minAbs=Math.abs(latterPartSum[0]-formerPartSum[0]);

        for(int i=0;i<n;i++){
            latterPartSum[i+1]=latterPartSum[i]-w[i];
            formerPartSum[i+1]=formerPartSum[i]+w[i];
            int minAbsCandidate=Math.abs(latterPartSum[i]-formerPartSum[i]);
            minAbs= minAbs<=minAbsCandidate?minAbs:minAbsCandidate;
        }
        System.out.println(minAbs);
    }


}

Measured memory_bytes: 21332
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
vector<pii> G[MAXN];
int D[MAXN], color[MAXN];
int ans[2 * MAXN];
int A[2 * MAXN], B[2 * MAXN];

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    vector<pii> V;
    for (int i = 1; i <= N; i++) {
        scanf("%d", &D[i]);
        V.push_back(make_pair(D[i], i));
    }
    for (int i = 0; i < M; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        A[i] = a, B[i] = b;
        G[a].push_back(make_pair(i, b));
        G[b].push_back(make_pair(i, a));
    }
    sort(V.begin(), V.end());
    for (int i = 0; i < N; i++) {
        int cur = V[i].second;
        bool OK = false;
        for (auto j : G[cur]) {
            int to = j.second;
            if (D[to] <= D[cur]) OK = true;
        }
        if (!OK) return !printf("-1\n");
    }
    for (int i = 0; i < N; i++) {
        int cur = V[i].second;
        if (color[cur]) continue;
        for (auto j : G[cur]) {
            int to = j.second, idx = j.first;
            if (D[to] > D[cur]) continue;
            if (color[to] == 0) {
                color[to] = 1;
                color[cur] = 2;
            } else if (color[to] == 1) {
                color[cur] = 2;
            } else {
                color[cur] = 1;
            }
            ans[idx] = D[cur];
            break;
        }
    }
    for (int i = 1; i <= N; i++) {
        if (!color[i]) assert(false);
        if (color[i] == 1) printf("B");
        else printf("W");
    }
    puts("");
    for (int i = 0; i < M; i++) {
        if (!ans[i]) ans[i] = (int)1e9;
        printf("%d\n", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 15220
def main():
    h, w = map(int, input().split())
    s_list = [list(input().split()) for _ in range(h)]

    for r in range(h):
        for c in range(w):
            if s_list[r][c] == "snuke":
                print(chr(ord("A") + c) + str(r + 1))
                break


if __name__ == "__main__":
    main()


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

#define inRange(x,a,b) (a <= x && x < b)
int di[8] = {0,0,1,-1,1,1,-1,-1};
int dj[8] = {1,-1,0,0,1,-1,1,-1};

int main(){
    int h, w;
    cin >> h >> w;
    char mat[h][w];
    for(int i = 0; i < h*w; i++)    cin >> mat[i/w][i%w];
    int ret = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(mat[i][j] == '#')    continue;
            vector<vector<int>> d(h, vector<int>(w, 1<<30));
            queue<int> q;
            d[i][j] = 0;
            q.push(i*w+j);
            while(!q.empty()){
                int x = q.front();  q.pop();
                int si = x/w, sj = x%w;
                ret = max(ret, d[si][sj]);
                for(int k = 0; k < 4; k++){
                    int ni = si+di[k], nj = sj+dj[k];
                    if(inRange(ni,0,h)&&inRange(nj,0,w)&&mat[ni][nj]=='.'&&d[ni][nj]>d[si][sj]+1){
                        d[ni][nj] = d[si][sj]+1;
                        q.push(ni*w+nj);
                    }
                }
            }
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq
import sys
input=sys.stdin.readline


def dijkstra(s):
    inf=float("inf")
    color=["white" for _ in range(n)]
    D=[inf for _ in range(n)]

    M=[[] for _ in range(n)]
    for a,b,c in ABC:
        M[a-1].append([b-1,c])
        M[b-1].append([a-1,c])

    D[s]=0

    H=[(0,s)]
    heapq.heapify(H)

    while len(H)>=1:
        u=heapq.heappop(H)[1]
        if color[u]=="black":continue
        color[u]="black"

        V=[(i,j) for i,j in M[u] if color[i]!="black"]
        while len(V)!=0:
            for i,j in V:
                if D[u]+j<D[i]:
                    D[i]=D[u]+j
                    color[i]="gray"
                    heapq.heappush(H,(D[i],i))
            break

    return D


n=int(input())
ABC=[list(map(int,input().split())) for _ in range(n-1)]
q,k=map(int,input().split())
XY=[list(map(int,input().split())) for _ in range(q)]
D=dijkstra(k-1)
for x,y in XY:
    print(D[x-1]+D[y-1])

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

int main(){
    unsigned long long int a, b ,c, mn=pow(10, 18);
    cin >> a >> b >>c;
    if(a%2==0 || b%2==0 || c%2==0 )cout << 0 << endl;
    else{
        mn=a*b;
        mn=min(mn,b*c);
        mn=min(mn,c*a);
        cout << mn << endl;
    }
}

Measured memory_bytes: 256
N = int( input())
s = [ input() for i in range(N)]
M = int(input())
t = [ input() for j in range(M)]

judge = 0
for l in range(N):
  money = s.count(s[l]) - t.count(s[l])
  
  if( judge < money):
    judge = money
  
  else:
    continue
    
print(judge)


Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
    long L[100];
    int Num;
    int i;
    
    L[0] = 2;
    L[1] = 1;
    
    scanf("%d", &Num);
    
    for(i=2; i<=Num; i++){
        L[i] = L[i-2] + L[i-1];
        //printf("%ld %d\n", L[i-2], L[i-1]);
    }
    
    printf("%ld\n", L[Num]);
    
    return 0;
}


Measured memory_bytes: 128
n,m = map(int,input().split())
x = list(map(int,input().split()))

x.sort()
l = []
for i in range(m-1):
	l.append([i,x[i+1] - x[i]])

l = sorted(l,key=lambda x:x[1],reverse=True)

l = l[:n-1]

l.sort()
l.append([m-1,0])
ans = x[l[0][0]] - x[0]

for i in range(len(l)-1):
	ans += x[l[i+1][0]] - x[l[i][0] + 1]
print(ans)


Measured memory_bytes: 22364
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <cstdlib>

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pi;

const ll MOD = 1e9+7;

static long gcd(long a, long b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
/*
long long int facctorialMethod(int k){//階乗
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}*/

long long int tousasum(long long int n){//等差数列
    return n*(n+1)/2;
}

unsigned GetDigit(unsigned num){//桁数
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

bool IsPrime(int num)//素数判定
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

map< ll, ll > prime_factor(ll n) {//素因数分解
    map< ll, ll > ret;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

ll calcNumOfCombination(ll n, ll r){
    ll num = 1;
    for(ll i = 1; i <= r; i++){
        num = num * (n - i + 1) / i;
    }
    return num;
}

int bubblesort(vector<int> array,int size){//バブルソート　転倒数
    int kaisu = 0;
    for(int i = 0; i < size; i++){
        for(int j = i + 1; j < size; j++){
            if(array[i] > array[j]){
                int number = array[i];
                array[i] = array[j];
                array[j] = number;
                kaisu++;
            }
        }
    }
    return kaisu;
}

ll facctorialMethod(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum = (sum * i)%MOD;
    }
    return sum;
}

int main() {

    ll N,M;
    ll result = 0;
    cin >> N >> M;
    ll a[N];

    //priority_queue<pi, vector<pi>, greater<pi> > pq;
    priority_queue<ll> pq;

    for(int i=0;i<N;i++){
        cin >> a[i];
        pq.push(a[i]);
    }

    for(int i=0;i<M;i++){
        ll temp = pq.top();
        pq.pop();
        temp/=2;
        pq.push(temp);

    }

    while(!pq.empty())
    {
        ll temp = pq.top();
        pq.pop();
        result += temp;
    }
    cout << result << endl;


}






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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    ll n,k;
    cin >> n >> k;
    ll A = 0;
    ll ans = 0;
    for(int i = 0; i <= n; i++){ // i+1 個の数字を選ぶということ
        if(i == 0) A = 0;
        else A += i;
        
        if(i < k-1) continue;
        
        ans = ((ans%MOD) + (n*(i+1))%MOD - (2*A)%MOD + 1)%MOD;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3636
from collections import deque
import sys
input = sys.stdin.readline
 
 
def main():
    n, q = map(int, input().split())
    node = [[]for _ in range(n)]
    looked = [1] * n
    for i in range(n - 1):
        a, b = map(int, input().split())
        node[b - 1].append(a - 1)
        node[a - 1].append(b - 1)
    counter = [0] * n
    for i in range(q):
        p, x = map(int, input().split())
        counter[p - 1] += x
    queue = deque([0])
    looked[0] = 0
    while queue:
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
 
main()

Measured memory_bytes: 56648
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace

getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

main = do
  s <- B.getLine
  print $ snd $ B.foldl (\(c,a) x -> (x,a + (if c /= x then 1 else 0))) (B.head s,0) s


Measured memory_bytes: 10108
n,m = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
if m <= n:
  print(0)
else:
  Dif_X = []
  for i in range(m-1):
    Dif_X += [X[i+1]-X[i]]
  Sum_Dif_X = sum(Dif_X)  
  Sorted_Dif_X = sorted(Dif_X, reverse = True)
  count = 0  
  while count < n-1:
    Sum_Dif_X -= Sorted_Dif_X[count]
    count += 1
  print(Sum_Dif_X)

Measured memory_bytes: 13960
#include"bits/stdc++.h"
using namespace std;

int main(){
	string S;
	cin >> S;
	if(S[0] < '2'){
		cout << "Heisei" << endl;
	}else if(S[0] > '2'){
		cout << "TBD" << endl;
	}else if(S[0] == '2'){
		if(S[1] > '0'){
			cout << "TBD" << endl;
		}else if(S[1] == '0'){
			if(S[2] < '1'){
				cout << "Heisei" << endl;
			}else if(S[2] > '1'){
				cout << "TBD" <<endl;
			}else if(S[2] == '1'){
				if(S[3] < '9'){
					cout << "Heisei" << endl;
				}else if(S[3] == '9'){
					if(S[5] > '0'){
						cout << "TBD" << endl;
					}else if(S[5] == '0'){
						if(S[6] <= '4'){
							cout << "Heisei" << endl;
						}else if(S[6] > '4'){
							cout << "TBD" <<endl;
						}
					}
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256