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

int main()
{
  int a,b;
  cin>>a;
  cin>>b;
  if(a==1)
  {
    if(b==2)
    cout<<3;
    else if(b==3)
      cout<<2;
  }
  if(a==2)
  {
    if(b==1)
      cout<<3;
    else if(b==3)
      cout<<1;
  }
  if(a==3)
  {
    if(b==1)
      cout<<2;
    else if(b==2)
      cout<<1;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
main()
{
    int n, a[1000] = {0}, c = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            for (int k = j + 1; k < n; k++)
            {
                if (a[i] != a[j] && a[j] != a[k] && a[i] != a[k])
                {
                    int x[3] = {0};
                    x[0] = a[i];
                    x[1] = a[j];
                    x[2] = a[k];
                    sort(x, x + 3);
                    if (x[0] + x[1] > x[2])
                        c++;
                }
            }
        }
    }
    cout << c << endl;
}


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


struct Sieve{
  int n;
  vector<int> f,primes;
  Sieve(int n=1):n(n),f(n+1){
    f[0] = f[1] = -1;
    for(ll i = 2; i<=n;++i){
      if(f[i]) continue; //素数でない場合continue
      primes.push_back(i);
      f[i] = i;
      for(ll j=i*i;j<=n;j+=i){
        if(!f[j]) f[j]=i;
      }
    }
  }
  bool isPrime(int x){
    return f[x]==x;
  }
  vector<int> factorList(int x){
    vector<int> res;
    while(x != 1){
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x){
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1,P(fl[0],0));
    for (int p:fl){
      if(res.back().first == p){
        res.back().second++;
      }else{
        res.emplace_back(p,1);
      }
    }
    return res;
  }
};

int main(){
    int n;
    cin >> n;
    Sieve s(10000);
    set<int> number;

    rep(i,n) number.insert(i+1);
    int sum = (n+1)*n/2;
    int p = s.f[sum];
    int R = sum/p;

    vector<vector<int>> res(p);
    int group = 0;
    int temp = 0;
    while(!number.empty()){
        for(int i = n; i>=1;--i){
            if(number.count(i)==1){
                if(temp+i<=R){
                    temp+=i;
                    number.erase(i);
                    res[group].push_back(i);
                }
            }
        }
        temp = 0;
        group++;
    }
    vector<int> kinds(n+1);
    rep(i,p){
        for(auto y:res[i]){
            kinds[y]=i;
        }
    }

    vector<P> ans;
    for(int i=1; i<=n;++i){
        for(int j=i; j<=n;++j){
            if(kinds[i]!=kinds[j]){
                P q(i,j);
                ans.push_back(q);
            }
        }
    }
    
    cout << ans.size() << endl;
    for(auto a:ans){
        cout << a.first << " " << a.second << endl;
    }
    
}

Measured memory_bytes: 384
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
#define srch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,c=0;
    while(cin>>n>>m>>l)
    {
        bool f=0;
        Rep(i,100)
        {
            if((n*i+l)%m==0)
            {
                f=1;
                break;
            }
        }
        if(f) cout<<Y;
        else cout<<N;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
#define SIZE 105
int w[SIZE], v[SIZE];

const long long int Inf = (long long int)1e18;

int main(void) {
        int n,W;
        scanf("%d %d",&n,&W);
        int sum=0;
        for(int i=1; i<=n; i++) {
            scanf("%d %d",&w[i],&v[i]);
            sum += v[i];
        }
        std::vector <long long int> dp(sum+1, Inf);
        dp[0] = 0;
        for(int item=1; item<=n; item++) for(int i=sum-v[item]; i>=0; i--) dp[i+v[item]] = std::min(dp[i+v[item]],dp[i]+w[item]);

        int ans=0;
        for(int i=1; i<=sum; i++) if(dp[i]<=W) ans = std::max(ans,i);

        printf("%d", ans);
        return 0;
}







Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,a;
  string s;
  cin>>n;
  cin>>s;
  cin>>a;
  for(int i=0;i<n;i++){
    if(s[i]!=s[a-1]){
      cout<<"*";
    }
    else{
      cout<<s[i];
    }
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
Q = 10**9+7
def main():
    N, K = map( int, input().split())
    ANS = [0]*(K+1)
    for x in range(K,0,-1):
        ans = pow(K//x,N,Q)
        for i in range(2, K+1):
            if x*i > K:
                break
            ans -= ANS[x*i]
        ANS[x] = ans%Q
    print( sum( [ANS[i]*i%Q for i in range(K+1)])%Q)
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 74904
#include<cstdio>
#include<utility>
#include<algorithm>
int const nax = 2e5 + 5, mod = 998244353;

struct P{
    int x, d;
    P () {}
    P (int x, int d) : x(x), d(d) {}
    bool operator < (const P &a) const {
        return x < a.x;
    }
    void read () {
        scanf("%d %d", &x, &d);
    }
};

inline void add (int &a, int b) {
    if ((a += b) >= mod) a -= mod;
}

int dp[nax];
int n;
std::pair<int, int> st[nax];
int top;
P p[nax];

int main () {
    scanf("%d", &n);
    for (int i = 1 ; i <= n ; ++ i)
        p[i].read();
    std::sort(p + 1, p + 1 + n);
    dp[n + 1] = 1;
    st[top = 1] = std::make_pair(n + 1, (int)2e9 + 1);
    for (int i = n ; i >= 1 ; -- i) {
        while (top > 0 && st[top].second < p[i].x + p[i].d) -- top;
      	dp[i] = dp[i + 1];
      	add(dp[i], dp[st[top].first]);
        st[++ top] = std::make_pair(i, p[i].x);
    }
    printf("%d\n", dp[1]);
}


Measured memory_bytes: 3328
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define int ll
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1;  while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; }
int nCr(int n,int r,int p){
  if(r==0)
    return 1;
  int ml=1;
  for(int i=n;i>=n-r+1;i--){
    ml = (ml%p*i%p)%p;
  }
  int kl=1;
  for(int i=r;i>=1;i--){
    kl = (i%p*kl%p)%p;
  }
 
  int as = po(kl,p-2,p);
  int ans = (ml%p*as%p)%p;

  return ans;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   
    int n,a,b;
    cin>>n>>a>>b;
    int ans  = po(2,n,MOD)-1;
  //  cout<<ans<<"\n";
    int m1 = nCr(n,a,MOD);
     int m2 = nCr(n,b,MOD);
   //  cout<<ans<<"\n";
    //cout<<m1<<"\n";
     //cout<<m2<<"\n";
    ans =(ans-(m1+m2)%MOD + MOD)%MOD;
    cout<<ans<<"\n";   
return 0;
}
  

Measured memory_bytes: 256
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005
ll n,dp[3003][3003][3],a[3003];
ll f(ll i,ll j,ll p,ll c){
	if(i>j)return 0;
	if(dp[i][j][p]!=-hell)return dp[i][j][p];
	ll ans;
	if(!p){
		if(c==0)ans=min(f(i+1,j,p,!c),f(i+1,j,!p,!c))+a[i];
		else ans=max(f(i+1,j,p,!c),f(i+1,j,!p,!c))-a[i];
	}else{	
		if(c==0)ans=min(f(i,j-1,p,!c),f(i,j-1,!p,!c))+a[j];
		else ans=max(f(i,j-1,p,!c),f(i,j-1,!p,!c))-a[j];
	}
	return dp[i][j][p]=ans;
}
int main()
{
	ios
	ll i,j;
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=0;i<3003;i++)for(j=0;j<3003;j++)dp[i][j][0]=dp[i][j][1]=-hell;
	ll ans=max(f(1,n,0,0),f(1,n,1,0));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 211840
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    string s;
    cin >> s;

    vector<ll> v(3);
    for(int i = 0; i < s.size(); i++){
        char c = s[i] - 'a';
        v[c] ++;
    }

    auto a =  *max_element( all(v) );
    auto b =  *min_element( all(v) );
    
    if( a - b <= 1) cout << "YES" << endl;
    else cout << "NO" << endl;

}

Measured memory_bytes: 512
from itertools import groupby

s = input() 
k = int(input())

a = [sum(1 for _ in g) for _, g in groupby(s)]
#print(a)

ans = 0
chan = 0
if len(a) == 1:
  ans = (len(s)*k)//2
  print(ans)
else:
  for i in range (len(a)):
    ans = ans + a[i]//2
  if s[0] == s[-1]:
    chan = (a[0]+a[-1])//2 - a[0]//2 - a[-1]//2
  print(ans*k+chan*(k-1))


Measured memory_bytes: 3064
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

r=gets.to_i
puts 3*r**2

Measured memory_bytes: 1788
//https://atcoder.jp/contests/abc117/tasks/abc117_c
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(int argc, char const *argv[]) {
  int N,M;
  cin >> N>>M;
  int L[100100];
  for(int i=0;i<M;i++){
    cin >>L[i];
  }
  sort(L,L+M);
  int dis[100100];
  for(int i=0;i<M-1;i++){
    dis[i]=L[i+1]-L[i];
  }
  sort(dis,dis+M-1);
  int n=0;
  if(M-N>0){
    for(int i=0;i<M-N;i++){
      n+=dis[i];
    }
    cout << n << endl;
  }
  else cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 200005
lli arr[MAX];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli a,b,c,d;
    cin>>a>>b>>c>>d;
    lli turn = 0;
    while(a*c > 0){
        if(turn%2 == 0){
            c = c-b;
        }
        else{
            a = a-d;
        }
        turn++;
    }
    if(turn%2== 0){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
}   

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for(int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    auto dfs = [&](auto &&dfs, int cur, int pre, int bit) -> int {
        if(bit == (1 << N) - 1) return 1;
        int res = 0;
        for(auto &to : G[cur]) {
            if(pre == to || bit & (1 << to)) continue;
            res += dfs(dfs, to, cur, bit | (1 << to));
        }
        return res;
    };
    cout << dfs(dfs, 0, -1, 1) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
 

int X , Y , a , b , c , k;

int Count(vector<int>A,vector<int>B,vector<int>C,int m ,int a,int b,int c)
{
	for(int i=0;i<c;i++)
	{
		if( i < m ) A.push_back(C[i]);
		else B.push_back(C[i]);
	}
	
	sort(A.rbegin(),A.rend());
	sort(B.rbegin(),B.rend());
	int ans =0;
	for(int i=0;i<min(X,(int)A.size());i++)
	ans+=A[i];
	for(int i=0;i<min(Y,(int)B.size());i++)
	ans+=B[i];
	
	return ans;
}
	
int32_t main()
{
	IOS	
	vector<int>A,B,C;
	cin>>X>>Y>>a>>b>>c;
	for(int i=0;i<a;i++)
	cin>>k,A.push_back(k);
	for(int i=0;i<b;i++)
	cin>>k,B.push_back(k);
	for(int i=0;i<c;i++)
	cin>>k,C.push_back(k);
	
	sort(C.rbegin(),C.rend());
	
	int ans = 0;
	int l = 0 , r = c;
	while( l <= r )
	{
		int m1 = l + (r-l)/3;
		int m2 = r - (r-l)/3;
		int cnt1 = Count(A,B,C,m1,a,b,c);
		int cnt2 = Count(A,B,C,m2,a,b,c);
		if( cnt1 < cnt2 )l=m1+1;
		else r=m2-1;
		ans=max({ans,cnt1,cnt2});
	}
	cout << ans << endl;
	
	
	
}


Measured memory_bytes: 9344
s = input()
n = len(s)
res = [0] * (n + 1)
t = 0
for i in range(n):
	if s[i] == '<':
		t += 1
	else:
		t = 0
	res[i + 1] = t

t = 0
for i in range(n - 1, -1, -1):
	if s[i] == '>':
		t += 1
	else:
		t = 0
	res[i] = max(res[i], t)

print(sum(res))

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

int main(int argc, char const *argv[])
{
	int a, b, c; cin >> a >> b >> c;
	cout << max(0, c - (a - b)) << endl;
	return 0;
}


Measured memory_bytes: 256
fn main() {
    proconio::input! {
        a: i64,
        v: i64,
        b: i64,
        w: i64,
        t: i64,
    }
    let diff = (b - a).abs() as i64;
    let m = (v - w) * t;
    let ans = if diff <= m { "YES" } else { "NO" };
    println!("{}", ans);
}


Measured memory_bytes: 2076
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int s[105];
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>s[i];
		sum+=s[i];
	}
	if(sum%10!=0){
		cout<<sum<<endl;
		return 0;
	}
	int count=0;
	int min=1e4;
    for(int i=0;i<n;i++){
    	if(min>s[i] && s[i]%10!=0){
    		min=s[i];
    		count++;
		}
	}
	if(count==0){
		cout<<"0"<<endl;
	}
	else{
		cout<<sum-min<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int X;
    cin >>X;
    if(X==3){
        cout <<"YES";
    }else if(X==5){
        cout <<"YES";
    }
    else if(X==7){
        cout <<"YES";
    }else{
        cout <<"NO";
    }
    return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    if N % 1000 == 0:
        print(0)
    else:
        print(1000 - N % 1000)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9236
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int n;
i64 a[1010];
i64 result = 0;
vector<int> ans;

int main(){
    cin >> n;
    rep(i,1,n) cin >> a[i];

    int MAX = 1;
    rep(i,2,n) if(a[MAX] < a[i]) MAX = i;

    if(a[MAX] <= 0){
        result = a[MAX];
        int sz = n;
        rep(i,1,MAX - 1){
            ans.push_back(1);
            sz--;
        }
        while(sz > 1){
            ans.push_back(sz);
            sz--;
        }
    }
    else{
        vector<int> select;
        vector<int> odd(n,0);
        vector<int> even(n,0);
        i64 odd_sum = 0;
        i64 even_sum = 0;
        for(int i = 1;i <= n;i+=2){
            if(a[i] > 0){
                odd_sum += a[i];
                odd[i - 1] = 1;
            }
        }
        for(int i = 2;i <= n;i+=2){
            if(a[i] > 0){
                even_sum += a[i];
                even[i - 1] = 1;
            }
        }


        if(odd_sum >= even_sum){
            select = odd;
            result = odd_sum;
        }
        else{
            select = even;
            result = even_sum;
        }

        //first
        while (select.front() == 0)
        {
            select.erase(select.begin());
            ans.push_back(1);
        }
        while(select.back() == 0){
            select.pop_back();
            ans.push_back(select.size() + 1);
        }

        //second
        for(int i = 1;i < select.size() - 1;i++){
            if(select[i - 1] == 0 && select[i] == 0 && select[i + 1] == 0){
                ans.push_back(i + 1);
                select.erase(select.begin() + i - 1);
                select.erase(select.begin() + i - 1);
                i = 0;
            }
        }

        for(int i = 0;i < select.size();i++){
            if(select[i] == 0){
                ans.push_back(2);
            }
        }
    }

    cout << result << endl;
    cout << ans.size() << endl;
    for(int as : ans){
        cout << as << endl;
    }
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n,m;cin>>n>>m;
  vector<int>a(n), b(m);
  rep(i, n)cin>>a[i];
  rep(i, m)cin>>b[i];

  map<int, int>ma, mb;
  for(auto c:a)ma[c]++;
  for(auto p: ma)if(p.second>1) { cout<<0<<endl; return 0; }
  for(auto c:b)mb[c]++;
  for(auto p: mb)if(p.second>1) { cout<<0<<endl; return 0; }

  vector<int> counter_a(n*m+1);
  vector<int> counter_b(n*m+1);
  for(auto c: a)counter_a[c]++;
  for(auto c: b)counter_b[c]++;
  rrep1(i, n*m)counter_a[i-1] += counter_a[i];
  rrep1(i, n*m)counter_b[i-1] += counter_b[i];

  ll result=1;
  rrep1(c, n*m){
    ll cca = counter_a[c];
    ll ccb = counter_b[c];
    ll reduce = (n*m-c);

    if(ma[c]>0 && mb[c]>0);
    else if(ma[c]>0){
      result = result*ccb%MOD;
    }else if(mb[c]>0){
      result = result*cca%MOD;
    }else{
      result = result*(cca*ccb-reduce)%MOD;
    }
  }

  cout<<result<<endl;

  return 0;
}


Measured memory_bytes: 101760
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INFTY LLONG_MAX/1000

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;


static const int MAX = 310;

int d[MAX][MAX];

void floyd(int (&d)[MAX][MAX], const int& n) {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      //  経由地点k, スタートi,  目的地jを, 右から(jから)走破していく.
      if (d[i][k] == INFTY) continue;
      for (int j = 0; j < n; j++) {
        if (d[k][j] == INFTY) continue;
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

// initialization (inside main function)
// for (int i = 0; i < N; i++) {
//   for (int j = 0; j < N; j++) {
//     d[i][j] = (i == j ? 0 : INFTY);
//   }
// }

// for (int i = 0; i < M; i++) {
//   int a, b, t;
//   cin >> a >> b >> t;
//   a--; b--;
//   d[a][b] = t;
//   d[b][a] = t;
// }

signed main() {
  int N, M, R; cin >> N >> M >> R;
  int Stops[R];
  for (int i = 0; i < R; i++) {
    cin >> Stops[i];
    Stops[i]--;
  }
  sort(Stops, Stops + R);

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      d[i][j] = (i == j ? 0 : INFTY);
    }
  }

  for (int i = 0; i < M; i++) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;
    d[a][b] = c;
    d[b][a] = c;
  }

  
  floyd(d, N);
  // for (int i = 0; i < N; i++) {
  //   for (int j = 0; j < N; j++) {
  //     cout << d[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  int ans = INFTY;
  do {
    int temp = 0;
    for (int i = 0; i < R - 1; i++) {
      const int &x = d[Stops[i]][Stops[i+1]];
      if (x == INFTY || x < 0)  continue;
      else {
        temp += x; 
      }
    }
    // for (int i = 0; i < R; i++) {
    //   cout << Stops[i] << " ";
    // }
    // cout << endl;
    // cout << temp << endl;
    ans = min(ans, temp);
  } while(next_permutation(Stops, Stops+R));

  cout << ans << endl;
}


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

vector<int> to[1000005];
const int INF = 100000000; 

int main(){ 
  cout << "Yes" << endl;
  int n,m; cin >> n >> m;

  rep(i,m){
    int a,b; cin >> a >> b;
    a--;
    b--;

    to[a].push_back(b);
    to[b].push_back(a);
    
  }

  queue<int> q;
  vector<int> dist(n,INF);
  vector<int> pre(n);

  dist[0] = 0;
  q.push(0);
  while(!q.empty()) {
    int v = q.front(); q.pop();
    for(int u : to[v]) {
      if(dist[u] != INF) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }

  rep(i,n){
    if(i == 0) continue;
    int ans = i + 1;
    int ans2 = pre[i] + 1;

    cout << ans2 << endl;
  }
}


Measured memory_bytes: 31704
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    for(int i=0; i<N; i++) {
        cin >> V[i];
    }

    int ans = 0;
    for(int i=0; i<=N; i++) {
        for(int j=0; i+j<=N; j++) {
            int cnt = i+j;
            if(cnt > K) continue;
            vector<int> v;
            for(int k=0; k<i; k++) {
                v.push_back(V[k]);
            }
            for(int k=0; k<j; k++) {
                v.push_back(V[N-1-k]);
            }
            sort(v.rbegin(), v.rend());
            while(cnt < K && !v.empty()) {
                if(v.back() < 0) {
                    v.pop_back();
                }
                cnt++;
            }
            int tmp = accumulate(v.begin(), v.end(), 0);
            ans = max(ans, tmp);
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll ans=0,n;
    cin>>n;
    for(int i=1;i<=n;i+=2){
        for(int j=2;j<=n;j+=2){
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}


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

int main () {
    long long A, B, X, i ;
    X = -1 ;
    scanf ( "%lld %lld", &A, &B ) ;
    for ( i = A ; ; i += A ) {
        if  ( i % B == 0 ) {
            break ;
        }
        if ( i % B ) {
            X = i ;
            break ;
        }
    }
    printf ( "%lld\n", X ) ;
    return 0 ;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node
{
    int x,y;
}a[210000];

bool cmp(node t,node v)
{
    if(t.y == v.y)  return t.x>v.x;
    return t.y>v.y;
}

int main()
{
    int n;
    ll sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i].x,&a[i].y);
        sum+=a[i].x;
    }
    //cout<<sum<<endl;
    sort(a,a+n,cmp);
    int i;
    for(i=0;i<n;i++){
        if(sum<=a[i].y) sum-=a[i].x;
        else break;
    }
    if(i==n)    cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

constexpr static int MAXN = 1000;
constexpr static int INF = 1e9;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, -1, 1};

int H, W, K;
string g[MAXN];
int d[MAXN][MAXN];

struct node {
    int i, j;
};

int main() {
    cin >> H >> W >> K;
    for (int i = 0; i < H; i++)
        cin >> g[i];

    int si, sj;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            if (g[i][j] == 'S')
                si = i, sj = j;

    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            d[i][j] = INF;

    vector <node> q;
    q.push_back({si, sj});
    d[si][sj] = 0;
    for (int l = 0; l < q.size(); l++) {
        for (int dir = 0; dir < 4; dir++) {
            int i = q[l].i + dr[dir];
            int j = q[l].j + dc[dir];
            if (i >= 0 && j >= 0 && i < H && j < W && g[i][j] == '.'
                    && d[q[l].i][q[l].j] + 1 < d[i][j]) {
                d[i][j] = d[q[l].i][q[l].j] + 1;
                q.push_back({i, j});
            }
        }
    }

    int minsteps = INF;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (d[i][j] > K)
                continue;
            int mindist = min(min(i, j), min(H - i - 1, W - j - 1));
            int casts = (mindist + K - 1) / K;
            minsteps = min(minsteps, casts + 1);
        }
    }
    cout << minsteps << endl;
}


Measured memory_bytes: 13936
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, d;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> d;
    int ans = 0;
    for(int i = 0 ; i < n ; i++){
        int x, y;
        cin >> x >> y;
        if(1LL * x * x + 1LL * y * y <= 1LL * d * d) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
H, W = map(int, input().split())
S = [input() for i in range(H)]

T = [['' for j in range(W)] for i in range(H)]

for i, Ti in enumerate(T):
    for j, Tij in enumerate(Ti):
        if S[i][j] == '#':
            T[i][j] = '#'
        else:
            num = 0
            for di in [-1, 0, 1]:
                for dj in [-1, 0, 1]:
                    if 0 <= i + di < H and 0 <= j + dj < W:
                        if S[i + di][j + dj] == '#':
                            num += 1
            T[i][j] = str(num)

print('\n'.join([''.join(T[i]) for i in range(H)]))


Measured memory_bytes: 3188
package main

import "fmt"

func main() {
	var input [6002]int
	i := 0
	fmt.Scanf("%d %d", &input[i], &input[i+1])
	for input[i] != 0 || input[i+1] != 0 {
		i += 2
		fmt.Scanf("%d %d", &input[i], &input[i+1])
	}
	for j := 0; j < i; j += 2 {
		if input[j] < input[j+1] {
			fmt.Println(input[j], input[j+1])
		} else {
			fmt.Println(input[j+1], input[j])
		}
	}
}



Measured memory_bytes: 1276
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int D;
    cin >> D;
    vector<int> c(26);
    REP(i, 26) cin >> c[i];
    vector< vector<int> > s(D+1, vector<int>(26));
    REP(i, D) REP(j, 26) cin >> s[i][j];

    vector<int> t(D);
    REP(i, D) cin >> t[i];

    vector<int> last(26, 0);

    int ans = 0;
    FOR(d, 1, D) {
        ans += s[d-1][t[d-1] - 1];
        last[t[d-1] - 1] = d;
        REP(i, 26) {
            ans -= c[i] * (d - last[i]);
        }
        
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3648
s=input()
n=3
for i in range(2**n):
    tmp=[]
    for k in range(n):
        tmp.append(s[k])
        if i>>k & 1:
            tmp.append("+")
        else:
            tmp.append("-")
    tmp.append(s[-1])
    if eval("".join(tmp))==7:
        print("".join(tmp)+"=7")
        exit()



Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N;

    cin >> N;
    vector<int> d(N, 0);
    for(int i = 0; i < N; i++) {
        cin >> d[i];
    }

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

    //cout << d[N/2 - 1] << d[N/2] << endl;
    int left = d[N/2 - 1];
    int right = d[N/2];

    cout << (right - left);


}

Measured memory_bytes: 640
#include<stdio.h>

int main(void) {
	int x , i; 
	for ( i = 1;; i++) 
	{
		
		scanf("%d", &x);
		if (x == 0) {
			return 0;
		}
		printf("Case %d: %d\n", i, x);
	}
	return 0;
}


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

int main(){
  int n;
  cin>>n;
  int a[n][3];
  int dp[n][3];
  for(int i=0;i<n;i++)
    cin>>a[i][0]>>a[i][1]>>a[i][2];
  dp[0][0] = a[0][0];
  dp[0][1] = a[0][1];
  dp[0][2] = a[0][2];
  for(int i=1;i<n;i++){
    dp[i][0] = a[i][0]+max(dp[i-1][1], dp[i-1][2]);
    dp[i][1] = a[i][1]+max(dp[i-1][0], dp[i-1][2]);
    dp[i][2] = a[i][2]+max(dp[i-1][0], dp[i-1][1]);
  }
  int ans = max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
  cout<<ans<<endl;
    
  }

Measured memory_bytes: 2688
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int lli;
int main(){
  lli n, l;
  std::cin >> n >> l;
  vector<lli> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  lli add = 0, pos;
  for (int i = 1; i < n; i++) {
    if(add < a[i] + a[i - 1]){
      add = a[i] + a[i - 1], pos = i;
    }
  }
  if(add < l){
    std::cout << "Impossible" << std::endl;
    return 0;
  }
  std::cout << "Possible" << std::endl;
  for (int i = 1; i < pos; i++) {
    std::cout << i << std::endl;
  }
  for (int i = n - 1; i > pos; i--) {
    std::cout << i << std::endl;
  }
  std::cout << pos << std::endl;
  return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int A,B;
  cin>>A>>B;
  
  if(A%B==0) cout<<-1<<endl;
  else{
    for(int i=1; ++i;){
      if(A*i%B!=0){
        cout<<A*i<<endl;
        break;
      }
    }
  }
  
}


Measured memory_bytes: 256
x = input()
from collections import deque

q = deque()
ans = ""
for i in x:
    if i == "S":
        q.append(i)
    else:
        if q:
            q.popleft()
        else:
            ans += "T"
while q:
    ans += q.popleft()
print(len(ans))


Measured memory_bytes: 4584
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    int count = 0;
    String num = "1";
    for(int i = 0 ; i < 3 ; ++i){
     	String s = line.substring(i,i+1);
      	if(s.equals(num)){
          ++count;
    	}
    }
    System.out.println(count);
  }
  
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
char s[100005];
int main(){
    scanf("%s", s+1);   
    int n = strlen(s+1);
    int cnt = 0;
    for(int i=1;i<=n;i++){
        if(i == 1 || s[i] != s[i-1]) cnt++;
    }
    printf("%d\n", cnt-1);
}

Measured memory_bytes: 3876
import java.util.*;

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

Measured memory_bytes: 22868
import Control.Monad
import Data.Maybe
import Data.List

-- firstBinary :: (Int -> Bool) -> Int -> Int -> Int
firstBinary _ l r | l == r = l
firstBinary f l r = let m = div (l + r) 2 in if f m then firstBinary f l m else firstBinary f (m + 1) r

f :: String -> (Int, Maybe Char)
f "" = (0, Nothing)
f ('1':s) = let (n, c) = f s in (n + 1, c)
f (c:s) = (0, Just c)

main = do
    s  <- getLine
    n  <- read <$> getLine
    let (one, c) = f s
    putStrLn $ if n <= one then "1" else [fromJust c]


Measured memory_bytes: 508
L = int(input())
N = len(bin(L)[2:])
ans = []
for i in range(1, N):
    ans.append((i, i+1, 0))
    ans.append((i, i+1, 1<<(i-1)))
n = 1 << (N-1)
while n < L:
    i = 1
    while (1<<i) - 1 + n < L:
        i += 1
    ans.append((i, N, n))
    n += 1 << (i-1)
print(N, len(ans))
for a in ans:
    print(*a)


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

int main(){
	int L, R, d;
	cin >> L >> R >> d;

    int ans=0;
    for(int i=L; i<=R; i++){
        if( i%d == 0 ){
            ans++;
        }
    }
	cout << ans << endl;
}


Measured memory_bytes: 3588
N = int(input())
a = list(map(int, input().split()))

a_max = max(a)
a_min = min(a)

if a_max >= abs(a_min):
    flag = True
    index = a.index(a_max)
else:
    flag = False
    index = a.index(a_min)

m = 2 * N -2
print (m)

count = 0
for i in range(N):
    if i != index:
        print (index+1, i+1)
        count += 1

if flag: #全て非負の数になっている時
    for i in range(N-1):
        print (i+1, i+2)
        count += 1
else:
    for i in range(N-1,0,-1):
        print (i+1, i)
        count += 1

# print (m == count)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int d[] = new int[N]; //配列数を決定
		
		for(int i = 0; i<N; i++) {
			d[i] = sc.nextInt(); //配列の中身を挿入
		}
		
		int sum = 0;
		for(int i =0; i<N; i++) {
			for(int j = i+1; j<N; j++) {
				sum += d[i]*d[j];
			}
		}
		System.out.println(sum);
	}
	
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int n,m,a[50],b[50],G[50][50] = {},ans = 0;
bool used[50];

void dfs(int v){
	for(int i = 0;i < n;i++){
		if(G[v][i] && !used[i]){
			used[i] = true;
			dfs(i);
		}
	}
}

signed main(){
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		cin >> a[i] >> b[i]; a[i]--;b[i]--;
		G[a[i]][b[i]] = 1;
		G[b[i]][a[i]] = 1;
	}
	for(int i = 0;i < m;i++){
		G[a[i]][b[i]] = 0;
		G[b[i]][a[i]] = 0;
		for(int j = 0;j < n;j++) used[j] = false;
		used[0] = true;
		dfs(0);
		bool flag = true;
		for(int j = 0;j < n;j++) if(!used[j]) flag = false;
		if(!flag) ans++;
		G[a[i]][b[i]] = 1;
		G[b[i]][a[i]] = 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	m := make(mheap, 2000000)
	for {
		s := getNextString(scanner)
		switch s {
		case "insert":
			m.push(getNextInt(scanner))
		case "extract":
			fmt.Fprintln(writer, m.pop())
		case "end":
			return
		}
	}
}

var n int

type mheap []int

func (m *mheap) pop() int {
	n--
	m.swap(0, n)
	m.down(0, n)
	x := (*m)[n]
	return x
}
func (m mheap) push(x int) {
	m[n] = x
	u, d := (n-1)>>1, n
	for d > 0 && m.less(d, u) {
		m.swap(d, u)
		d, u = u, (u-1)>>1
	}
	n++
}
func (m mheap) less(i, j int) bool {
	return m[i] > m[j]
}
func (m mheap) swap(i, j int) {
	m[i], m[j] = m[j], m[i]
}
func (m mheap) down(i, n int) {
	for {
		l := i<<1 + 1
		r := l + 1
		if r < n && m.less(r, l) {
			l = r
		}
		if l < n && m.less(l, i) {
			m.swap(i, l)
			i = l
			continue
		}
		break
	}
}



Measured memory_bytes: 24972
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');
            var a = line[0];
            var b = line[1];
            if (a == "H")
            {
                Console.WriteLine(b == "H" ? "H" : "D");
            }
            else
            {
                Console.WriteLine(b == "H" ? "D" : "H");
            }
        }
    }
}

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

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

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

    int ans = 0;
    for(int i = 1;i < n-1;i++){
        if(a[i-1] < a[i] && a[i] < a[i+1]) ans++;
        else if(a[i-1] > a[i] && a[i] > a[i+1]) ans++;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#include<cmath>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<list>
#include<deque>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<chrono>


/*  auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
pr(duration.count());    */


#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define siz         100009
#define mp          make_pair
#define ll          long long int
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define pi          acos(-1.0)
#define all(x)      x.begin(),x.end()
#define ull		    unsigned long long int
#define m(a)	    memset(a,0,sizeof(a))
#define f(i,n)	    for(ll i=0;i<n;i++)
#define sc(a)	    scanf("%lld",&a)
#define pr(a)	    printf("%lld\n",a)
const ll inf = 5000000000000000;
ll in = 1000000000000000000;
using namespace std;
ll gcd(ll a, ll b)
{
	if (a == 0)
		return b;
	else
		return gcd(b % a, a);
}
int main()
{
	FastIO;
	ll a,b,d, co, t, i, j, k, n,r;
	cin >> n;
	vector<ll>v, dif;
	f(i, n)
	{
		cin >> a;
		v.push_back(a);
	}
	sort(all(v));
	ll ans = v[0];
	for(i=0;i<v.size();i++)
	{
		if (i)
		{
			ans = gcd(ans, v[i]);
			if (ans == 1)
				break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1400
function main(input){
    let nums = input.split(" ");
    let a1 = (nums[0]/nums[1])|0;
    let a2 = (nums[0]%nums[1]);
    let a3 = ((parseInt(Math.round((parseFloat(nums[0])/parseFloat(nums[1]))*10e7)))/10e7);
    if(a3.toString().indexOf("e-")!==-1){
        let digit = a3.toString().split("e-")[1];
        a3 = a3.toFixed(digit);
    }
    console.log(a1+" "+a2+" "+a3);

}

main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 15404
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)
#define myforInv(i,N) for(i=N;i>=0;i--)
#define myforFLInv(i,f,l) for(i=f;i>l;i--)

using namespace std;

int main(){
	int K,A,B,i;
	long dp[100001]={};
	bool ans = false;

	cin >> K >> A >> B;
	myforFL(i,1,B/K+1){
		if(K*i >= A && K*i <=B){
			ans = true;
			break;
		}
	}
	if(ans)cout << "OK" <<endl;
	else cout << "NG" << endl;

	return 0;
}

Measured memory_bytes: 3036
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CXYetAnotherDieGame solver = new CXYetAnotherDieGame();
        solver.solve(1, in, out);
        out.close();
    }

    static class CXYetAnotherDieGame {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long x = in.nextLong();

            out.println(Math.min(2 * ((x + 10) / 11), 2 * ((x - 6 + 10) / 11) + 1));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <stdlib.h>

using namespace std;

int N, M;
int s[100005];

bool check(int x)
{
	if(s[0] >= x + 1) return true;
	
	int cnt = 0, lv = 1;
	while(1){
		cnt++;
		if(lv + x > s[N-1]) break;
		int tmp = 1;
		int *p = upper_bound(s, s+N, lv);
		if(p != s+N && *p < lv + x) tmp = max(tmp, x - abs(lv - *p));
		if(p != s) tmp = max(tmp, x - abs(lv - *(p-1)));
		lv += tmp;
	}
	return cnt >= M;
}

int main(void)
{
	while(1){
		cin >> N >> M;
		if(N == 0 && M == 0) break;
		for(int i = 0; i < N; i++) cin >> s[i];
		
		int lb = -1, ub = 1000005, mid;
		while(ub - lb > 1){
			mid = (lb + ub) / 2;
			if(check(mid)) lb = mid;
			else ub = mid;
		}
		if(s[0] >= lb + 1) lb = -1;
		else if(lb <= 0) lb = -1;
		cout << lb << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3480
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int H, N;
  cin >> H >> N;
  int sum = 0;
  rep(i,N){
    int a;
    cin >> a;
    sum += a;
  }

  if(H > sum) cout << "No" << endl;
  else cout << "Yes" << endl;
  
  return 0;
}



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

namespace std {
	#define u(x, a, b) for(ll x = a; x < b; x++)
	#define d(x, a, b) for(ll x = a; x > b; x--)
}

typedef long long ll;
typedef long double ld;

#define MAXI 100010
#define MOD 1000000007

int main(){
	ll n;
	cin >> n;
	
	ll a[n];
	u(one, 0, n){cin >> a[one];}
	
	sort(a, a+n);
	
	ll cnt = 2;
	ll sum = a[n-1];
	ll cidx = 2;
	while(cnt < n){
		if(n-cnt>1){
			cnt+=2;
			sum+=2*a[n-cidx];
			cidx++;
		}
		else{
			cnt+=1;
			sum+=a[n-cidx];
			cidx++;
		}
	}	
	cout << sum;
}


Measured memory_bytes: 5136
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

struct edge{int to,cost;};
int V;
vector<edge> G[300000]; // MAX_V
int d[300000]; // MAX_V
void dijkstra(int S){
  priority_queue<pint,vector<pint>,greater<pint>> que;
  fill(d,d+V*3,INF);
  d[S]=0;
  que.push(pint(0,S));
  while(!que.empty()){
    pint p=que.top();
    que.pop();
    int v=p.second;
    if(d[v]<p.first) continue;
    rep(i,G[v].size()){
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        que.push(pint(d[e.to],e.to));
      }
    }
  }
}


int main(void){
  int M;
  cin >> V >> M;
  rep(i,M){
    edge in;
    int x;
    cin >> x >> in.to;
    x--,in.to--;
    in.to+=V;
    in.cost=1;
    rep(j,3){
      G[x+j*V].push_back(in);
      in.to=(in.to+V)%(3*V);
    }
  }
  int S,T;
  cin >> S >> T;
  S--,T--;
  dijkstra(S);
  if(d[T]==INF) cout << -1 << endl;
  else cout << d[T]/3 << endl;
}

Measured memory_bytes: 17792